Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catalog-Adapter: Optional #268

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions Products/zms/IZMSCatalogAdapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,30 @@

class IZMSCatalogAdapter(Interface):

def search(self, qs, order, clients=False):
def add_connector(self, id):
"""
Search catalog.
@param qs: the query-string
@type qs: C{str}
@param order: the sort-order
@type order: C{str}
@param clients: flag to process clients recursicely
@type clients: C{boolean=False}
@returns: the list of search-results
@rtype: C{list}
Add connector
"""

def reindex(self, connector, base, recursive=True, fileparsing=True):
"""
Reindex
@param connector: the connector
@param base: the base
@param recursive: recursive
@param fileparsing: fileparsing
"""

def reindex_node(self, node, forced=False):
"""
Reindex node
@param node: the node
@param forced: forced reindex
"""

def unindex_node(self, node, forced=False):
"""
Unindex node
@param node: the node
@param forced: forced unindex
"""
144 changes: 81 additions & 63 deletions Products/zms/_confmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,32 +884,36 @@ def getZMSIndex(self):
###
############################################################################

def getWorkflowManager(self):
manager = getattr(self, 'workflow_manager', None)
return manager

def getWfActivities(self):
workflow_manager = getattr(self, 'workflow_manager', None)
workflow_manager = self.getWorkflowManager()
if workflow_manager is None:
return []
return workflow_manager.getActivities()

def getWfActivitiesIds(self):
workflow_manager = getattr(self, 'workflow_manager', None)
workflow_manager = self.getWorkflowManager()
if workflow_manager is None:
return []
return workflow_manager.getActivityIds()

def getWfActivity(self, id):
workflow_manager = getattr(self, 'workflow_manager', None)
workflow_manager = self.getWorkflowManager()
if workflow_manager is None:
return None
return workflow_manager.getActivity(id)

def getWfTransitions(self):
workflow_manager = getattr(self, 'workflow_manager', None)
workflow_manager = self.getWorkflowManager()
if workflow_manager is None:
return []
return workflow_manager.getTransitions()

def getWfTransition(self, id):
workflow_manager = getattr(self, 'workflow_manager', None)
workflow_manager = self.getWorkflowManager()
if workflow_manager is None:
return None
return workflow_manager.getTransition(id)
Expand All @@ -935,23 +939,23 @@ def getFilterManager(self):
except:
standard.writeError(self, "[getFilterManager]: can't init new %s"%meta_type)
###
manager = [x for x in self.getDocumentElement().objectValues() if isinstance(x,ZMSFilterManager.ZMSFilterManager)]
if len(manager)==0:
class DefaultManager(object):
getFilter__roles__ = None
def getFilter(self, id): return {}
getFilterIds__roles__ = None
def getFilterIds(self, sort=True): return []
getFilterProcesses__roles__ = None
def getFilterProcesses(self, id): return []
getProcess__roles__ = None
def getProcess(self, id): return {}
getProcessIds__roles__ = None
def getProcessIds(self, sort=True): return []
importXml__roles__ = None
def importXml(self, xml): pass
manager = [DefaultManager()]
return manager[0]
for ob in self.objectValues():
if ZMSFilterManager.ZMSFilterManager in list(providedBy(ob)):
return ob
class MockManager(object):
getFilter__roles__ = None
def getFilter(self, id): return {}
getFilterIds__roles__ = None
def getFilterIds(self, sort=True): return []
getFilterProcesses__roles__ = None
def getFilterProcesses(self, id): return []
getProcess__roles__ = None
def getProcess(self, id): return {}
getProcessIds__roles__ = None
def getProcessIds(self, sort=True): return []
importXml__roles__ = None
def importXml(self, xml): pass
return MockManager()


############################################################################
Expand All @@ -962,19 +966,19 @@ def importXml(self, xml): pass

def getMetaobjManager(self):
manager = getattr(self, 'metaobj_manager', None)
if manager is None:
class DefaultMetaobjManager(object):
def importXml(self, xml): pass
def getMetaobjId(self, name): return None
def getMetaobjIds(self, sort=None, excl_ids=[]): return []
def getMetaobj(self, id): return None
def getMetaobjAttrIds(self, meta_id, types=[]): return []
def getMetaobjAttrs(self, meta_id, types=[]): return []
def getMetaobjAttr(self, id, attr_id, sync=True): return None
def getMetaobjAttrIdentifierId(self, meta_id): return None
def notifyMetaobjAttrAboutValue(self, meta_id, key, value): return None
manager = DefaultMetaobjManager()
return manager
if manager:
return manager
class MockManager(object):
def importXml(self, xml): pass
def getMetaobjId(self, name): return None
def getMetaobjIds(self, sort=None, excl_ids=[]): return []
def getMetaobj(self, id): return None
def getMetaobjAttrIds(self, meta_id, types=[]): return []
def getMetaobjAttrs(self, meta_id, types=[]): return []
def getMetaobjAttr(self, id, attr_id, sync=True): return None
def getMetaobjAttrIdentifierId(self, meta_id): return None
def notifyMetaobjAttrAboutValue(self, meta_id, key, value): return None
return MockManager()

def getMetaobjRevision(self, id):
return self.getMetaobjManager().getMetaobjRevision( id)
Expand Down Expand Up @@ -1019,16 +1023,16 @@ def getMetacmdManager(self):
self._setObject( obj.id, obj)
self.delConfProperty('ZMS.custom.commands')
###
metacmd_manager = getattr(self, 'metacmd_manager', None)
if metacmd_manager is None:
class DefaultManager(object):
def importXml(self, xml): pass
def getMetaCmdDescription(self, id): return None
def getMetaCmd(self, id): return None
def getMetaCmdIds(self, sort=True): return []
def getMetaCmds(self, context=None, stereotype='', sort=True): return []
metacmd_manager = DefaultManager()
return metacmd_manager
manager = getattr(self, 'metacmd_manager', None)
if manager:
return manager
class MockManager(object):
def importXml(self, xml): pass
def getMetaCmdDescription(self, id): return None
def getMetaCmd(self, id): return None
def getMetaCmdIds(self, sort=True): return []
def getMetaCmds(self, context=None, stereotype='', sort=True): return []
return MockManager()

def getMetaCmdDescription(self, id):
""" getMetaCmdDescription """
Expand All @@ -1052,18 +1056,18 @@ def getMetaCmds(self, context=None, stereotype='', sort=True):

def getWorkflowManager(self):
manager = getattr(self.getDocumentElement(),'workflow_manager',None)
if manager is None:
class DefaultManager(object):
def importXml(self, xml): pass
def getAutocommit(self): return True
def getActivities(self): return []
def getActivityIds(self): return []
def getActivity(self, id): return None
def getActivityDetails(self, id): return None
def getTransitions(self): return []
def getTransitionIds(self): return []
manager = DefaultManager()
return manager
if manager:
return manager
class MockManager(object):
def importXml(self, xml): pass
def getAutocommit(self): return True
def getActivities(self): return []
def getActivityIds(self): return []
def getActivity(self, id): return None
def getActivityDetails(self, id): return None
def getTransitions(self): return []
def getTransitionIds(self): return []
return MockManager()


############################################################################
Expand Down Expand Up @@ -1094,16 +1098,30 @@ def getCharFormats(self):
###
############################################################################

def getCatalogAdapter(self):
def getCatalogAdapter(self, createIfNotExists=False):
from Products.zms import IZMSCatalogAdapter, ZMSZCatalogAdapter
for ob in self.objectValues():
if IZMSCatalogAdapter.IZMSCatalogAdapter in list(providedBy(ob)):
return ob
adapter = ZMSZCatalogAdapter.ZMSZCatalogAdapter()
self._setObject( adapter.id, adapter)
adapter = getattr(self, adapter.id)
adapter.initialize()
return adapter
master = self.getPortalMaster()
if master:
adapter = master.getCatalogAdapter()
if adapter:
return adapter
if createIfNotExists:
adapter = ZMSZCatalogAdapter.ZMSZCatalogAdapter()
self._setObject( adapter.id, adapter)
adapter = getattr(self, adapter.id)
adapter.initialize()
return adapter
class MockConnector(object):
def manage_init(self): pass
class MockAdapter(object):
def add_connector(self, id): return MockConnector()
def reindex(self, connector, base, recursive=True, fileparsing=True): pass
def reindex_node(self, node, forced=False): pass
def unindex_node(self, node, forced=False): pass
return MockAdapter()


# call this to initialize framework classes, which
Expand Down
10 changes: 0 additions & 10 deletions Products/zms/_zcatalogmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,4 @@ def getCatalogPathObject(self, path):
ob = getattr(ob, id, None)
return ob


# --------------------------------------------------------------------------
# ZCatalogManager.submitCatalogQuery:
#
# Submits query to catalog.
# @deprecated
# --------------------------------------------------------------------------
def submitCatalogQuery(self, search_query, search_order_by, search_meta_types=[], search_clients=False, REQUEST=None):
return self.getCatalogAdapter().search(search_query, search_order_by)

################################################################################
2 changes: 1 addition & 1 deletion Products/zms/zms.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def manage_addZMS(self, lang, manage_lang, REQUEST, RESPONSE):
initContent(obj, 'com.zms.search.content.xml', REQUEST)

# Initialize catalog adapter / connector.
catalog_adapter = obj.getCatalogAdapter()
catalog_adapter = obj.getCatalogAdapter(createIfNotExists=True)
catalog_connector = catalog_adapter.add_connector('zcatalog_connector')
catalog_connector.manage_init()
catalog_adapter.reindex(catalog_connector, obj, recursive=True)
Expand Down
Loading