From 2698384284f7260b31e4581b354fa8d17a3ef6e2 Mon Sep 17 00:00:00 2001
From: felmer <franz-josef.elmer@id.ethz.ch>
Date: Wed, 1 Feb 2023 08:58:10 +0100
Subject: [PATCH] SSDM-12929: introduce dataSetSearchCriteriaExtender functions
 to control by plugins where data sets are shown in the hierarchy. First used
 for  microscopy

---
 .../eln-tree/resolver-plugins/microscopy.py           |  9 +++++++++
 .../1/dss/file-system-plugins/eln-tree/script.py      | 11 ++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/dss/file-system-plugins/eln-tree/resolver-plugins/microscopy.py b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/dss/file-system-plugins/eln-tree/resolver-plugins/microscopy.py
index 43b0700280e..046e8c7975c 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/dss/file-system-plugins/eln-tree/resolver-plugins/microscopy.py
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/dss/file-system-plugins/eln-tree/resolver-plugins/microscopy.py
@@ -1 +1,10 @@
 acceptor.hideDataSetType("MICROSCOPY_IMG_CONTAINER")
+acceptor.hideSampleType("MICROSCOPY_SAMPLE_TYPE")
+
+acceptor.dataSetSearchCriteriaExtender.append(lambda c, id: extendDataSetSearchCriteriaForMicroscopy(c, id))
+
+def extendDataSetSearchCriteriaForMicroscopy(dataSetSearchCriteria, samplePermId):
+    dataSetSearchCriteria.withOrOperator()
+    parentsSearchCriteria = dataSetSearchCriteria.withSample().withParents()
+    parentsSearchCriteria.withType().withCode().thatEquals("MICROSCOPY_EXPERIMENT")
+    parentsSearchCriteria.withPermId().thatEquals(samplePermId)
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/dss/file-system-plugins/eln-tree/script.py b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/dss/file-system-plugins/eln-tree/script.py
index d650c1c68d0..428090b2ecd 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/dss/file-system-plugins/eln-tree/script.py
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/dss/file-system-plugins/eln-tree/script.py
@@ -30,6 +30,7 @@ class Acceptor(object):
         self.hiddenExperimentTypes = {}
         self.hiddenSampleTypes = {}
         self.hiddenDataSetTypes = {}
+        self.dataSetSearchCriteriaExtender = []
 
     def assertValidSection(self, section):
         if section not in self.sections:
@@ -70,7 +71,7 @@ class Acceptor(object):
             showTerm = "show%s" % item
             return mainMenue[showTerm] if showTerm in mainMenue else False
         return False
-    
+
     def _getGroupPrefix(self, code):
         groups = filter(lambda group: code.startswith(group), self.mainMenues.keys())
         return groups[0] if groups else "GENERAL"
@@ -101,6 +102,10 @@ class Acceptor(object):
     def acceptDataSet(self, dataSet):
         return dataSet.getType().getCode() not in self.hiddenDataSetTypes
 
+    def extendDataSetSearchCriteria(self, dataSetSearchCriteria, samplePermId):
+        for extender in self.dataSetSearchCriteriaExtender:
+            extender(dataSetSearchCriteria, samplePermId)
+
 class Settings(object):
     def __init__(self, inventorySpaces, mainMenues, sampleTypeViewAttributes):
         self.inventorySpaces = inventorySpaces
@@ -294,6 +299,8 @@ def addExperimentChildNodes(path, experimentPermId, response, acceptor, context)
 def addSampleChildNodes(path, samplePermId, response, acceptor, context):
     dataSetSearchCriteria = DataSetSearchCriteria()
     dataSetSearchCriteria.withSample().withPermId().thatEquals(samplePermId)
+    acceptor.extendDataSetSearchCriteria(dataSetSearchCriteria, samplePermId)
+
     listDataSets(path, dataSetSearchCriteria, True, response, acceptor, context)
 
     fetchOptions = SampleFetchOptions()
@@ -339,6 +346,8 @@ def listDataSets(path, dataSetSearchCriteria, assignedToSample, response, accept
     fetchOptions.withProperties()
     fetchOptions.withSample()
     dataSets = context.getApi().searchDataSets(context.getSessionToken(), dataSetSearchCriteria, fetchOptions).getObjects()
+    print(">>>> data set search criteria: %s" % dataSetSearchCriteria)
+    print(">>>> data sets: %s" % dataSets)
     entitiesByName = {}
     for dataSet in dataSets:
         sample = dataSet.getSample()
-- 
GitLab