supportedQueryLanguages = ['keywords', 'vsql',] supportedResultsFormat = ['RSS', 'Objecti', 'SingleObject'] from zope.interface import implements from OFS.SimpleItem import SimpleItem from interfaces.SQIInterface import ISQIInterface from Exceptions import NoSuchSessionException as NO_SUCH_SESSION from Exceptions import NO_SOURCE_LOCATION, QUERY_LANGUAGE_NOT_SUPPORTED, RESULTS_FORMAT_NOT_SUPPORTED class SQICore: implements(ISQIInterface) def setQueryLanguage(self, targetSessionID, queryLanguageID): """ set query language """ if queryLanguageID in supportedQueryLanguages: sess = self._getSession(targetSessionID) if sess: sess._setQueryLanguage(queryLanguageID) else: raise NO_SUCH_SESSION else: # FIXME: raise not supported raise QUERY_LANGUAGE_NOT_SUPPORTED return 1 def setResultsFormat(self, targetSessionID, resultsFormat): """ set results format """ if resultsFormat in supportedResultsFormat: sess = self._getSession(targetSessionID) if sess: sess._setResultsFormat(resultsFormat) else: raise NO_SUCH_SESSION else: # FIXME: raise not supported raise RESULTS_FORMAT_NOT_SUPPORTED return 1 def setMaxQueryResults(self, targetSessionID, maxQueryResults): """ set maximum query results """ # TODO: int checking sess = self._getSession(targetSessionID) if sess: sess._setMaxQueryResults(maxQueryResults) else: raise NO_SUCH_SESSION return 1 def setMaxDuration(self, targetSessionID, maxDuration): """ set maximum duration. TODO: this method has no effect """ # TODO: int checking? sess = self._getSession(targetSessionID) if sess: sess._setMaxDuration(maxDuration) else: raise NO_SUCH_SESSION return 1 # SYNCHRONOUS QUERY INTERFACE def setResultsSetSize(self, targetSessionID, resultsSetSize): """ maximum number of results, which will be returned by a single results set """ sess = self._getSession(targetSessionID) if sess: sess._setResultsSetSize(resultsSetSize) else: raise NO_SUCH_SESSION return 1 def synchronousQuery(self, targetSessionID, queryStatement, startResult): """ query """ # queryID here is 0. sess = self._getSession(targetSessionID) if not sess: raise NO_SUCH_SESSION sess.addQuery(queryStatement, 0) results = self._processQuery(targetSessionID, 0) startResult = int(startResult) formatted = self._formatResults(targetSessionID, results[startResult:]) return formatted def getTotalResultsCount(self, targetSessionID, queryStatement): """ number of total results """ sess = self._getSession(targetSessionID) if not sess: raise NO_SUCH_SESSION sess.addQuery(queryStatement, 0) self._processQuery(targetSessionID, 0) return len(sess.getResultSet(0)) # ASYNCHRONOUS QUERY INTERFACE def asynchronousQuery(self, targetSessionID, queryStatement, queryID): """ async query """ # TODO: should we do some checking here? # allowed characters in queryID # cannot allow 0 here! sess = self._getSession(targetSessionID) if sess._getSourceLocation() == '': raise NO_SOURCE_LOCATION sess.addQuery(queryStatement, queryID) return 1 def setSourceLocation(self, targetSessionID, sourceLocation): """ set the URL where to return query results """ sess = self._getSession(targetSessionID) if sess: sess._setSourceLocation(sourceLocation) else: raise NO_SUCH_SESSION return 1 # helper methods def _getSession(self, sessionID): """ get session """ sc = self.sessionmanager._getSession(sessionID) return sc def wsdl(self): """ return wsdl file """ from Products.PageTemplates.PageTemplateFile import PageTemplateFile wsdl = PageTemplateFile('sqiTarget.wsdl.pt', globals()) return wsdl.__of__(self)() def _formatResults(self, sessID, results): """ package results as requested by client """ sess = self._getSession(sessID) formatted = None if sess._resultsFormat == 'RSS': from Products.SQICore.Formatters import RSS conf = self.getFormatterConf('RSS') formatted = RSS(self, sessID, results, conf) elif sess._resultsFormat == 'SingleObject': from Products.SQICore.Formatters import SingleObject conf = self.getFormatterConf('SingleObject') formatted = SingleObject(self, sessID, results, conf) elif sess._resultsFormat == 'Objecti': from Products.SQICore.Formatters import Objecti conf = self.getFormatterConf('Objecti') formatted = Objecti(self, sessID, results, conf) return formatted