Example #1
0
	def createSearchObject(self, filter):
		"""
		Method creates object which makes accessible results of a search.
		"""
		try:
			# create request id
			id = random.randint(1, 9999)
			self.l.log(self.l.INFO, "<%d> Search request received." % id)

			# construct SQL query coresponding to filter constraints
			conditions = []
			condvalues = []
			if filter.id != -1:
				conditions.append("files.id = %d")
				condvalues.append(filter.id)
			if filter.name:
				conditions.append("files.name = %s")
				condvalues.append(filter.name)
			if filter.path:
				conditions.append("files.path = %s")
				condvalues.append(filter.path)
			if filter.mimetype:
				conditions.append("files.mimetype = %s")
				condvalues.append(filter.mimetype)
			if filter.filetype != -1:
				if filter.filetype == 0:
					conditions.append("files.filetype IS NULL")
				else:
					conditions.append("files.filetype = %d")
					condvalues.append(filter.filetype)
			fromdate = filter.crdate._from
			if not isInfinite(fromdate):
				conditions.append("files.crdate > '%d-%d-%d %d:%d:%d'" %
						(fromdate.date.year,
						fromdate.date.month,
						fromdate.date.day,
						fromdate.hour,
						fromdate.minute,
						fromdate.second))
			todate = filter.crdate.to
			if not isInfinite(todate):
				conditions.append("files.crdate < '%d-%d-%d %d:%d:%d'" %
						(todate.date.year,
						todate.date.month,
						todate.date.day,
						todate.hour,
						todate.minute,
						todate.second))
			if len(conditions) == 0:
				cond = ""
			else:
				cond = "WHERE (%s)" % conditions[0]
				for condition in conditions[1:]:
					cond += " AND (%s)" % condition
			self.l.log(self.l.DEBUG, "<%d> Search WHERE clause is: %s" %
					(id, cond))

			# connect to database
			conn = self.db.getConn()
			cur = conn.cursor()

			cur.execute("SELECT id, name, path, mimetype, filetype, crdate, "
						"filesize FROM files %s" % cond, condvalues)
			# get meta-info from database
			self.db.releaseConn(conn)

			self.l.log(self.l.DEBUG, "<%d> Number of records in cursor: %d" %
					(id, cur.rowcount))

			# Create an instance of FileSearch_i and an FileSearch object ref
			searchobj = FileSearch_i(id, cur, self.l)
			self.search_objects.put(searchobj)
			searchref = self.corba_refs.rootpoa.servant_to_reference(searchobj)
			return searchref

		except ccReg.FileManager.InternalError, e:
			raise
Example #2
0
    def createSearchObject(self, filter):
        """
	This is universal techcheck archive lookup function. It returns object
	reference which can be used to access data.
		"""
        try:
            id = random.randint(1, 9999)
            self.l.log(self.l.INFO,
                       "<%d> Search create request received." % id)

            # construct SQL query coresponding to filter constraints
            conditions = []
            condvalues = []
            if filter.checkid != -1:
                conditions.append("chn.id = %d")
                condvalues.append(filter.checkid)
            if filter.nsset_hid != -1:
                conditions.append("chn.nsset_hid = %d")
                condvalues.append(filter.nsset_hid)
            if filter.reason != ccReg.CHKR_ANY:
                conditions.append("chn.reason = %d")
                condvalues.append(convFromReason(filter.reason))
            if filter.status != -1:
                conditions.append("chn.overallstatus = %d")
                condvalues.append(filter.status)
            fromdate = filter.checkdate._from
            if not isInfinite(fromdate):
                conditions.append("chn.checkdate > '%d-%d-%d %d:%d:%d'" %
                                  (fromdate.date.year, fromdate.date.month,
                                   fromdate.date.day, fromdate.hour,
                                   fromdate.minute, fromdate.second))
            todate = filter.checkdate.to
            if not isInfinite(todate):
                conditions.append(
                    "chn.checkdate < '%d-%d-%d %d:%d:%d'" %
                    (todate.date.year, todate.date.month, todate.date.day,
                     todate.hour, todate.minute, todate.second))
            if len(conditions) == 0:
                cond = ""
            else:
                cond = "WHERE (%s)" % conditions[0]
                for condition in conditions[1:]:
                    cond += " AND (%s)" % condition

            # connect to database
            conn = self.db.getConn()
            cur = conn.cursor()

            self.l.log(self.l.DEBUG,
                       "<%d> Search WHERE clause is: %s" % (id, cond))
            # execute the query
            cur.execute(
                "SELECT chn.id, chn.nsset_hid, chn.checkdate, "
                "chn.reason, chn.overallstatus, chn.extra_fqdns, "
                "chn.dig, chr.testid, chr.status, chr.note, chr.data "
                "FROM check_nsset chn "
                "LEFT JOIN check_result chr ON (chn.id = chr.checkid) "
                "%s ORDER BY chn.id" % cond, condvalues)
            self.db.releaseConn(conn)
            self.l.log(
                self.l.DEBUG,
                "<%d> Number of records in cursor: %d" % (id, cur.rowcount))

            # Create an instance of MailSearch_i and an MailSearch object ref
            searchobj = TechCheckSearch_i(id, cur, self.l)
            self.search_objects.put(searchobj)
            searchref = self.corba_refs.rootpoa.servant_to_reference(searchobj)
            return searchref

        except pgdb.DatabaseError, e:
            self.l.log(self.l.ERR, "Database error: %s" % e)
            raise ccReg.TechCheck.InternalError("Database error")
Example #3
0
	def createSearchObject(self, filter):
		"""
		This is universal mail archive lookup function. It returns object
		reference which can be used to access data.
		"""
		try:
			id = random.randint(1, 9999)
			self.l.log(self.l.INFO, "<%d> Search create request received." % id)

			# construct SQL query coresponding to filter constraints
			conditions = []
			condvalues = []
			if filter.mailid != -1:
				conditions.append("ma.id = %d")
				condvalues.append(filter.mailid)
			if filter.mailtype != -1:
				conditions.append("ma.mailtype = %d")
				condvalues.append(filter.mailtype)
			if filter.status != -1:
				conditions.append("ma.status = %d")
				condvalues.append(filter.status)
			if filter.handle:
				conditions.append("mh.associd = %s")
				condvalues.append(filter.handle)
			if filter.attachid != -1:
				conditions.append("mt.attachid = %d")
				condvalues.append(filter.attachid)
			fromdate = filter.crdate._from
			if not isInfinite(fromdate):
				conditions.append("ma.crdate > '%d-%d-%d %d:%d:%d'" %
						(fromdate.date.year,
						fromdate.date.month,
						fromdate.date.day,
						fromdate.hour,
						fromdate.minute,
						fromdate.second))
			todate = filter.crdate.to
			if not isInfinite(todate):
				conditions.append("ma.crdate < '%d-%d-%d %d:%d:%d'" %
						(todate.date.year,
						todate.date.month,
						todate.date.day,
						todate.hour,
						todate.minute,
						todate.second))
			if filter.fulltext:
				conditions.append("ma.message LIKE '%%\%s%%'")
				condvalues.append(filter.fulltext[1:-1])
			if len(conditions) == 0:
				cond = ""
			else:
				cond = "WHERE (%s)" % conditions[0]
				for condition in conditions[1:]:
					cond += " AND (%s)" % condition

			# connect to database
			conn = self.db.getConn()
			cur = conn.cursor()

			self.l.log(self.l.DEBUG, "<%d> Search WHERE clause is: %s" %
					(id, cond))
			# execute MEGA GIGA query :(
			cur.execute("SELECT ma.id, ma.mailtype, ma.crdate, ma.moddate, "
						"ma.status, ma.message, mt.attachid, mh.associd "
					"FROM mail_archive ma "
					"LEFT JOIN mail_handles mh ON (ma.id = mh.mailid) "
					"LEFT JOIN mail_attachments mt ON (ma.id = mt.mailid) "
					"%s ORDER BY ma.id" % cond, condvalues)
			self.db.releaseConn(conn)
			self.l.log(self.l.DEBUG, "<%d> Number of records in cursor: %d" %
					(id, cur.rowcount))

			# Create an instance of MailSearch_i and an MailSearch object ref
			searchobj = MailSearch_i(id, cur, self.l)
			self.search_objects.put(searchobj)
			searchref = self.corba_refs.rootpoa.servant_to_reference(searchobj)
			return searchref

		except pgdb.DatabaseError, e:
			self.l.log(self.l.ERR, "<%d> Database error: %s" % (id, e))
			raise ccReg.Mailer.InternalError("Database error")
Example #4
0
	def createSearchObject(self, filter):
		"""
	This is universal techcheck archive lookup function. It returns object
	reference which can be used to access data.
		"""
		try:
			id = random.randint(1, 9999)
			self.l.log(self.l.INFO, "<%d> Search create request received." % id)

			# construct SQL query coresponding to filter constraints
			conditions = []
			condvalues = []
			if filter.checkid != -1:
				conditions.append("chn.id = %d")
				condvalues.append(filter.checkid)
			if filter.nsset_hid != -1:
				conditions.append("chn.nsset_hid = %d")
				condvalues.append(filter.nsset_hid)
			if filter.reason != ccReg.CHKR_ANY:
				conditions.append("chn.reason = %d")
				condvalues.append(convFromReason(filter.reason))
			if filter.status != -1:
				conditions.append("chn.overallstatus = %d")
				condvalues.append(filter.status)
			fromdate = filter.checkdate._from
			if not isInfinite(fromdate):
				conditions.append("chn.checkdate > '%d-%d-%d %d:%d:%d'" %
						(fromdate.date.year,
						fromdate.date.month,
						fromdate.date.day,
						fromdate.hour,
						fromdate.minute,
						fromdate.second))
			todate = filter.checkdate.to
			if not isInfinite(todate):
				conditions.append("chn.checkdate < '%d-%d-%d %d:%d:%d'" %
						(todate.date.year,
						todate.date.month,
						todate.date.day,
						todate.hour,
						todate.minute,
						todate.second))
			if len(conditions) == 0:
				cond = ""
			else:
				cond = "WHERE (%s)" % conditions[0]
				for condition in conditions[1:]:
					cond += " AND (%s)" % condition

			# connect to database
			conn = self.db.getConn()
			cur = conn.cursor()

			self.l.log(self.l.DEBUG, "<%d> Search WHERE clause is: %s" %
					(id, cond))
			# execute the query
			cur.execute("SELECT chn.id, chn.nsset_hid, chn.checkdate, "
						"chn.reason, chn.overallstatus, chn.extra_fqdns, "
						"chn.dig, chr.testid, chr.status, chr.note, chr.data "
					"FROM check_nsset chn "
					"LEFT JOIN check_result chr ON (chn.id = chr.checkid) "
					"%s ORDER BY chn.id" % cond, condvalues)
			self.db.releaseConn(conn)
			self.l.log(self.l.DEBUG, "<%d> Number of records in cursor: %d" %
					(id, cur.rowcount))

			# Create an instance of MailSearch_i and an MailSearch object ref
			searchobj = TechCheckSearch_i(id, cur, self.l)
			self.search_objects.put(searchobj)
			searchref = self.corba_refs.rootpoa.servant_to_reference(searchobj)
			return searchref

		except pgdb.DatabaseError, e:
			self.l.log(self.l.ERR, "Database error: %s" % e)
			raise ccReg.TechCheck.InternalError("Database error")