From f4b301d5bdeebdfe3c747b1732dfb2c2a475e4b8 Mon Sep 17 00:00:00 2001 From: felmer <franz-josef.elmer@id.ethz.ch> Date: Fri, 31 Mar 2023 09:54:03 +0200 Subject: [PATCH] SSDM-13489: wrapping data sets in hierarchical content: instead of calling AS for each data set only one call for all data sets is invoked --- .../eln-tree/resolver-plugins/flow.py | 14 +++-- .../eln-tree/resolver-plugins/microscopy.py | 7 ++- .../file-system-plugins/eln-tree/script.py | 53 ++++++++++++++++++- 3 files changed, 60 insertions(+), 14 deletions(-) diff --git a/ui-eln-lims/src/core-plugins/eln-lims/1/dss/file-system-plugins/eln-tree/resolver-plugins/flow.py b/ui-eln-lims/src/core-plugins/eln-lims/1/dss/file-system-plugins/eln-tree/resolver-plugins/flow.py index 5e1141655e9..32ffa0c8dae 100644 --- a/ui-eln-lims/src/core-plugins/eln-lims/1/dss/file-system-plugins/eln-tree/resolver-plugins/flow.py +++ b/ui-eln-lims/src/core-plugins/eln-lims/1/dss/file-system-plugins/eln-tree/resolver-plugins/flow.py @@ -2,22 +2,20 @@ import script def addSampleChildNodes(path, samplePermId, sampleType, response, acceptor, context): dataSets = script.getDataSetsOfSampleAndItsChildren(samplePermId, context) + filteredDataSets = [] for dataSet in dataSets: if acceptor.acceptDataSet(dataSet): - dataSetCode = dataSet.getCode() - content = context.getContentProvider().asContent(dataSetCode) - contentNode = content.getRootNode() - script.addDataSetFileNodes(path, dataSetCode, contentNode, response, acceptor, context) + filteredDataSets.append(dataSet) + script.addDataSetFileNodesFor(path, filteredDataSets, response, acceptor, context) def addSampleChildNodesWithPlates(path, samplePermId, sampleType, response, acceptor, context): dataSets = script.getDataSetsOfSampleAndItsChildren(samplePermId, context) + filteredDataSets = [] for dataSet in dataSets: sampleTypeCode = dataSet.getSample().getType().getCode() if not sampleTypeCode.endswith("_WELL"): - dataSetCode = dataSet.getCode() - content = context.getContentProvider().asContent(dataSetCode) - contentNode = content.getRootNode() - script.addDataSetFileNodes(path, dataSetCode, contentNode, response, acceptor, context) + filteredDataSets.append(dataSet) + script.addDataSetFileNodesFor(path, filteredDataSets, response, acceptor, context) script.addSampleSampleChildNodes(path, samplePermId, response, acceptor, context) for t in ["FACS_ARIA", "INFLUX", "MOFLO_XDP", "S3E", "SONY_SH800S", "SONY_MA900"]: diff --git a/ui-eln-lims/src/core-plugins/eln-lims/1/dss/file-system-plugins/eln-tree/resolver-plugins/microscopy.py b/ui-eln-lims/src/core-plugins/eln-lims/1/dss/file-system-plugins/eln-tree/resolver-plugins/microscopy.py index 7429a9d6a6d..272ec466926 100644 --- a/ui-eln-lims/src/core-plugins/eln-lims/1/dss/file-system-plugins/eln-tree/resolver-plugins/microscopy.py +++ b/ui-eln-lims/src/core-plugins/eln-lims/1/dss/file-system-plugins/eln-tree/resolver-plugins/microscopy.py @@ -7,11 +7,10 @@ acceptor.hideDataSetType("MICROSCOPY_IMG_THUMBNAIL") def addSampleChildNodes(path, samplePermId, sampleType, response, acceptor, context): dataSets = script.getDataSetsOfSampleAndItsChildren(samplePermId, context) + filteredDataSets = [] for dataSet in dataSets: if acceptor.acceptDataSet(dataSet): - dataSetCode = dataSet.getCode() - content = context.getContentProvider().asContent(dataSetCode) - contentNode = content.getRootNode() - script.addDataSetFileNodes(path, dataSetCode, contentNode, response, acceptor, context) + filteredDataSets.append(dataSet) + script.addDataSetFileNodesFor(path, filteredDataSets, response, acceptor, context) acceptor.sampleChildrenHandlers["MICROSCOPY_EXPERIMENT"] = addSampleChildNodes diff --git a/ui-eln-lims/src/core-plugins/eln-lims/1/dss/file-system-plugins/eln-tree/script.py b/ui-eln-lims/src/core-plugins/eln-lims/1/dss/file-system-plugins/eln-tree/script.py index c94b6c7577d..fa1a17da033 100644 --- a/ui-eln-lims/src/core-plugins/eln-lims/1/dss/file-system-plugins/eln-tree/script.py +++ b/ui-eln-lims/src/core-plugins/eln-lims/1/dss/file-system-plugins/eln-tree/script.py @@ -15,6 +15,10 @@ from ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.search import SampleSearchC from ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.fetchoptions import SampleFetchOptions from ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.search import DataSetSearchCriteria from ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.fetchoptions import DataSetFetchOptions +from ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.id import DataSetPermId +from ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset import DataSetKind +from ch.systemsx.cisd.openbis.generic.shared.basic.dto import PhysicalDataSet +from ch.systemsx.cisd.openbis.generic.shared.basic.dto import DataStore from ch.systemsx.cisd.openbis.dss.generic.server.ftp import Node class NodeWithEntityType(Node): @@ -233,8 +237,8 @@ def listChildren(subPath, acceptor, context): permId = node.getPermId() if nodeType == "DATASET": response = None - for permId in node.permIds: - dataSetCode, contentNode, content = getContentNode(permId, context) + contentNodes = getContentNodes(node.permIds, context) + for dataSetCode, contentNode, content in contentNodes: if contentNode.isDirectory(): if response is None: response = context.createDirectoryResponse() @@ -352,6 +356,49 @@ def addDataSetFileNodes(path, dataSetCode, contentNode, response, acceptor, cont else: response.addFile(nodeName, childNode) +def addDataSetFileNodesFor(path, dataSets, response, acceptor, context): + contentNodes = asContentNodes(dataSets, context) + for dataSetCode, contentNode, _ in contentNodes: + addDataSetFileNodes(path, dataSetCode, contentNode, response, acceptor, context) + +def getContentNodes(permIds, context): + ids = [] + paths = [] + for permId in permIds: + splittedId = permId.split("::") + ids.append(DataSetPermId(splittedId[0])) + paths.append(splittedId[1] if len(splittedId) > 1 else None) + + fetchOptions = DataSetFetchOptions() + fetchOptions.withDataStore() + fetchOptions.withPhysicalData() + dataSets = context.getApi().getDataSets(context.getSessionToken(), ids, fetchOptions).values() + return asContentNodes(dataSets, context, paths) + +def asContentNodes(dataSets, context, paths=None): + result = [] + contentProvider = context.getContentProvider() + for i in range(len(dataSets)): + dataSet = dataSets[i] + dataSetCode = dataSet.getCode() + dataStore = DataStore() + dataStore.setCode(dataSet.getDataStore().getCode()) + dataStore.setHostUrl(dataSet.getDataStore().getDownloadUrl()) + kind = dataSet.getKind() + if kind == DataSetKind.PHYSICAL: + physicalData = dataSet.getPhysicalData() + physicalDataSet = PhysicalDataSet() + physicalDataSet.setCode(dataSetCode) + physicalDataSet.setLocation(physicalData.getLocation()) + physicalDataSet.setDataStore(dataStore) + physicalDataSet.setShareId(physicalData.getShareId()) + content = contentProvider.asContentWithoutModifyingAccessTimestamp(physicalDataSet) + contentNode = content.getRootNode() if paths is None or paths[i] is None else content.tryGetNode(paths[i]) + result.append((dataSetCode, contentNode, content)) + else: + raise Exception("Not supported data set kind: %s" % kind) + return result + def getContentNode(permId, context): splittedId = permId.split("::") dataSetCode = splittedId[0] @@ -366,6 +413,8 @@ def getDataSetsOfSampleAndItsChildren(samplePermId, context): parentsSearchCriteria = dataSetSearchCriteria.withSample().withParents() parentsSearchCriteria.withPermId().thatEquals(samplePermId) fetchOptions = DataSetFetchOptions() + fetchOptions.withDataStore() + fetchOptions.withPhysicalData() fetchOptions.withType() fetchOptions.withProperties() fetchOptions.withSample().withType() -- GitLab