-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added test base * Moved patches to separate packages * Handle AT catalog multiplexing * Skip portal catalog indexer * reindex UID after sample creation * Patch UID indexing * Test fixture * Added test for Analysis Indexing * Workaround for partition IDs * Added comment * Added more tests * Implemented Workflow Variables Patch * Reduce noise in diff * Added indexing test for batches * README added * Readme added * Readme added * Better comment * Better comment * Changelog updated * Rely on API method to reindex new Sample objects --------- Co-authored-by: Jordi Puiggené <jp@naralabs.com>
- Loading branch information
Showing
24 changed files
with
965 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Archetypes Patches | ||
|
||
This package contains patches for Archetype based content types. | ||
|
||
## Catalog Multiplex | ||
|
||
The module `catalog_multiplex` contains patches for the class | ||
`Products.Archetpyes.CatalogMultiplex.CatalogMultiplex`, which is a mixin for | ||
`BaseContent` and controls how to index, unindex, reindex these content and is | ||
used when e.g. `obj.reindexObject` is called. | ||
|
||
### Patches | ||
|
||
The following methods are patched: | ||
|
||
- `indexObject` | ||
- `unindexObject` | ||
- `reindexObject` | ||
|
||
### Reason | ||
|
||
The patches ensure that temporary objects are not indexed and delegate the | ||
operation to the respective method of the catalog itself. | ||
|
||
Due to the fact that SENAITE catalogs inherit from `Products.CMFPlone.CatalogTool.CatalogTool`, | ||
which is a subclass of `Products.CMFCore.CatalogTool.CatalogTool`, this operation uses the | ||
`IndexQueue` defined in `Products.CMFCore.indexing.IndexQueue` to optimize indexing. | ||
|
||
### Notes | ||
|
||
The index queue always looks up all registered `IIndexQueueProcessor` utilities | ||
to further delegate the operation. | ||
|
||
Since the `PortalCatalogProcessor` utility is registered there as well, a | ||
patching is required to avoid indexing of, e.g. Samples or Analyses there as | ||
they should be only indexed in their primary catalog, e.g. | ||
`seanite_catalog_sample` or `senaite_catalog_analysis`. | ||
|
||
Please see `senaite.core.patches.cmfcore.portal_catalog_processor` for details. | ||
|
||
Furthermore, changes in `senaite.core.catalog.catalog_multiplex_processor.CatalogMultiplexProcessor` | ||
were required to handle AT based contens as well. | ||
|
||
Please see https://github.com/senaite/senaite.core/pull/2632 for details. | ||
|
||
💡 It might make sense to define for each catalog its own `IIndexQueueProcessor`. | ||
A simple check by content type would could decide if a content should be indexed or not. | ||
|
||
|
||
## UID Catalog indexing | ||
|
||
The module `referencable` contains patches for the class `Products.Archetypes.Referencable.Referencable`, | ||
which is a mixin for `BaseObject` and controls AT native referencable behavior | ||
(not used) and the indexing in the UID Catalog (used and needed for UID | ||
references and more). | ||
|
||
### Patches | ||
|
||
The following methods are patched: | ||
|
||
- `_catalogUID_` | ||
- `uncatalogUID` | ||
|
||
### Reason | ||
|
||
The patches ensure that temporary objects are not indexed. | ||
|
||
### Notes | ||
|
||
As soon as we have migrated all contents to Dexterity, we should provide a | ||
custom `senaite_catalog_uid` to keep track of the UIDs and maybe references. | ||
|
||
|
||
## Base Object | ||
|
||
The module `base_objects` contains patches for the class `Products.Archetypes.BaseObject.BaseObject`, | ||
which is the base class for our AT based contents. | ||
|
||
### Patches | ||
|
||
The following methods are patched: | ||
|
||
- `getLabels` | ||
- `isTemporary` | ||
|
||
### Reason | ||
|
||
Provide a similar methods for AT contents as for DX contents. | ||
|
||
**getLabels**: Get SENAITE labels (dynamically extended fields) | ||
|
||
**isTemporary**: Checks if an object contains a temporary ID to avoid further indexing/processing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of SENAITE.CORE. | ||
# | ||
# SENAITE.CORE is free software: you can redistribute it and/or modify it under | ||
# the terms of the GNU General Public License as published by the Free Software | ||
# Foundation, version 2. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# this program; if not, write to the Free Software Foundation, Inc., 51 | ||
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
# | ||
# Copyright 2018-2024 by it's authors. | ||
# Some rights reserved, see README and LICENSE. | ||
|
||
|
||
from bika.lims import api | ||
from Products.Archetypes import utils | ||
|
||
|
||
def isFactoryContained(obj): | ||
"""Are we inside the portal_factory? | ||
""" | ||
return api.is_temporary(obj) | ||
|
||
|
||
# https://pypi.org/project/collective.monkeypatcher/#patching-module-level-functions | ||
utils.isFactoryContained = isFactoryContained |
File renamed without changes.
116 changes: 116 additions & 0 deletions
116
src/senaite/core/patches/archetypes/catalog_multiplex.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of SENAITE.CORE. | ||
# | ||
# SENAITE.CORE is free software: you can redistribute it and/or modify it under | ||
# the terms of the GNU General Public License as published by the Free Software | ||
# Foundation, version 2. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# this program; if not, write to the Free Software Foundation, Inc., 51 | ||
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
# | ||
# Copyright 2018-2024 by it's authors. | ||
# Some rights reserved, see README and LICENSE. | ||
|
||
from bika.lims import api | ||
from Products.Archetypes.Referenceable import Referenceable | ||
from Products.Archetypes.utils import shasattr | ||
from senaite.core.catalog import AUDITLOG_CATALOG | ||
|
||
|
||
def is_auditlog_enabled(): | ||
setup = api.get_senaite_setup() | ||
if not setup: | ||
return False | ||
return setup.getEnableGlobalAuditlog() | ||
|
||
|
||
def indexObject(self): | ||
"""Handle indexing for AT based objects | ||
""" | ||
# Never index temporary AT objects | ||
if api.is_temporary(self): | ||
return | ||
|
||
# get all registered catalogs | ||
catalogs = api.get_catalogs_for(self) | ||
|
||
for catalog in catalogs: | ||
# skip auditlog_catalog if global auditlogging is deactivated | ||
if catalog.id == AUDITLOG_CATALOG and not is_auditlog_enabled(): | ||
continue | ||
# always use catalog tool queuing system | ||
catalog.indexObject(self) | ||
|
||
|
||
def unindexObject(self): | ||
"""Handle unindexing for AT based objects | ||
""" | ||
# Never unindex temporary AT objects | ||
if api.is_temporary(self): | ||
return | ||
|
||
# get all registered catalogs | ||
catalogs = api.get_catalogs_for(self) | ||
|
||
for catalog in catalogs: | ||
# skip auditlog_catalog if global auditlogging is deactivated | ||
if catalog.id == AUDITLOG_CATALOG and not is_auditlog_enabled(): | ||
continue | ||
# always use catalog tool queuing system | ||
catalog.unindexObject(self) | ||
|
||
|
||
def reindexObject(self, idxs=None): | ||
"""Reindex all AT based contents with the catalog queuing system | ||
""" | ||
# Never reindex temporary AT objects | ||
if api.is_temporary(self): | ||
return | ||
|
||
if idxs is None: | ||
idxs = [] | ||
|
||
# Copy (w/o knowig if this is required of not x_X) | ||
if idxs == [] and shasattr(self, "notifyModified"): | ||
# Archetypes default setup has this defined in ExtensibleMetadata | ||
# mixin. note: this refreshes the 'etag ' too. | ||
self.notifyModified() | ||
self.http__refreshEtag() | ||
# /Paste | ||
|
||
catalogs = api.get_catalogs_for(self) | ||
|
||
for catalog in catalogs: | ||
# skip auditlog_catalog if global auditlogging is deactivated | ||
if catalog.id == AUDITLOG_CATALOG and not is_auditlog_enabled(): | ||
continue | ||
# We want the intersection of the catalogs idxs | ||
# and the incoming list. | ||
lst = idxs | ||
indexes = catalog.indexes() | ||
if idxs: | ||
lst = [i for i in idxs if i in indexes] | ||
# use catalog tool queuing system | ||
catalog.reindexObject(self, idxs=lst) | ||
|
||
# Copy (w/o knowig if this is required of not x_X) | ||
# | ||
# We only make this call if idxs is not passed. | ||
# | ||
# manage_afterAdd/manage_beforeDelete from Referenceable take | ||
# care of most of the issues, but some places still expect to | ||
# call reindexObject and have the uid_catalog updated. | ||
# TODO: fix this so we can remove the following lines. | ||
if not idxs: | ||
if isinstance(self, Referenceable): | ||
isCopy = getattr(self, '_v_is_cp', None) | ||
if isCopy is None: | ||
self._catalogUID(self) | ||
# /Paste |
Oops, something went wrong.