Skip to content

Commit

Permalink
Rely on API method to reindex new Sample objects
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonski committed Oct 30, 2024
1 parent 3489a99 commit c725d9d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
16 changes: 13 additions & 3 deletions src/bika/lims/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,11 @@ def move_object(obj, destination, check_constraints=True):
return obj


def uncatalog_object(obj):
def uncatalog_object(obj, recursive=False):
"""Un-catalog the object from all catalogs
:param obj: object to un-catalog
:param recursive: recursively uncatalog all child objects
:type obj: ATContentType/DexterityContentType
"""
# un-catalog from registered catalogs
Expand All @@ -399,11 +400,16 @@ def uncatalog_object(obj):
url = "/".join(obj.getPhysicalPath()[2:])
uid_catalog.uncatalog_object(url)

if recursive:
for child in obj.objectValues():
uncatalog_object(child, recursive=recursive)

def catalog_object(obj):

def catalog_object(obj, recursive=False):
"""Re-catalog the object
:param obj: object to un-catalog
:param obj: object to catalog
:param recursive: recursively catalog all child objects
:type obj: ATContentType/DexterityContentType
"""
if is_at_content(obj):
Expand All @@ -416,6 +422,10 @@ def catalog_object(obj):
uc.catalog_object(obj, url)
obj.reindexObject()

if recursive:
for child in obj.objectValues():
catalog_object(child, recursive=recursive)


def delete(obj, check_permissions=True, suppress_events=False):
"""Deletes the given object
Expand Down
18 changes: 1 addition & 17 deletions src/bika/lims/utils/analysisrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def create_analysisrequest(client, request, values, analyses=None,
# unmark the sample as temporary
api.unmark_temporary(ar)
# explicit reindexing after sample finalization
reindex(ar)
api.catalog_object(ar)
# notify object initialization (also creates a snapshot)
event.notify(ObjectInitializedEvent(ar))

Expand All @@ -169,22 +169,6 @@ def create_analysisrequest(client, request, values, analyses=None,
return ar


def reindex(obj, recursive=False):
"""Reindex the object
:param obj: The object to reindex
:param recursive: If true, all child objects are reindexed recursively
"""
# reindex UID
uid_catalog = api.get_tool("uid_catalog")
uid_catalog.catalog_object(obj, obj._getURL())
# reindex object in all other catalogs
obj.reindexObject()
if recursive:
for child in obj.objectValues():
reindex(child)


def receive_sample(sample, check_permission=False, date_received=None):
"""Receive the sample without transition
"""
Expand Down

0 comments on commit c725d9d

Please sign in to comment.