From 1c43ed6e2a1180e682b0f6e3c7a190a7ed1ceb3d Mon Sep 17 00:00:00 2001 From: Mirhaj Date: Wed, 23 Apr 2025 09:53:20 -0400 Subject: [PATCH 1/3] Retuening plates for a request ID --- .../GetPlatesForAProject.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/main/java/com/velox/sloan/cmo/workflows/workflows/ContainerRetrieval/GetPlatesForAProject.java diff --git a/src/main/java/com/velox/sloan/cmo/workflows/workflows/ContainerRetrieval/GetPlatesForAProject.java b/src/main/java/com/velox/sloan/cmo/workflows/workflows/ContainerRetrieval/GetPlatesForAProject.java new file mode 100644 index 00000000..876783e2 --- /dev/null +++ b/src/main/java/com/velox/sloan/cmo/workflows/workflows/ContainerRetrieval/GetPlatesForAProject.java @@ -0,0 +1,44 @@ +package com.velox.sloan.cmo.workflows.workflows.ContainerRetrieval; + +import com.velox.api.datarecord.DataRecord; +import com.velox.api.plugin.PluginResult; +import com.velox.sapio.commons.exemplar.plugin.PluginOrder; +import com.velox.sapioutils.server.plugin.DefaultGenericPlugin; +import org.apache.commons.lang3.exception.ExceptionUtils; + +import java.rmi.RemoteException; +import java.util.*; + +public class GetPlatesForAProject extends DefaultGenericPlugin { + + public GetPlatesForAProject() { + setTaskEntry(true); + setOrder(PluginOrder.LAST.getOrder()); + } + + @Override + public boolean shouldRun() throws RemoteException { + return activeTask.getTask().getTaskOptions().containsKey("FIND CONTAINERS OF A REQUEST") && + !this.activeTask.getTask().getTaskOptions().containsKey("CONTAINERS RETURNED"); + } + + public PluginResult run() throws Throwable { + try { + String requestId = clientCallback.showInputDialog("Please enter the request ID of the samples to return"); + List requests = dataRecordManager.queryDataRecords("Request", "RequestId = '" + requestId + "'", user); + DataRecord[] relatedSamples = requests.get(0).getChildrenOfType("Sample", user); + Set plates = new HashSet<>(); + for (DataRecord sample: relatedSamples) { + plates.add(Arrays.asList(sample.getParentsOfType("Plate", user).get(0)).get(0)); + } + activeTask.addAttachedDataRecords(plates); + + } catch (Exception e) { + clientCallback.displayError(String.format("An exception occurred while finding plates of the entered project ID:\n%s", ExceptionUtils.getStackTrace(e))); + logError(ExceptionUtils.getStackTrace(e)); + return new PluginResult(false); + } + + return new PluginResult(true); + } +} From dc9b69531f1d1d50a7e4d24432769058cc56340b Mon Sep 17 00:00:00 2001 From: Mirhaj Date: Wed, 23 Apr 2025 16:04:12 -0400 Subject: [PATCH 2/3] Check for empty lists --- .../ContainerRetrieval/GetPlatesForAProject.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/velox/sloan/cmo/workflows/workflows/ContainerRetrieval/GetPlatesForAProject.java b/src/main/java/com/velox/sloan/cmo/workflows/workflows/ContainerRetrieval/GetPlatesForAProject.java index 876783e2..c214a066 100644 --- a/src/main/java/com/velox/sloan/cmo/workflows/workflows/ContainerRetrieval/GetPlatesForAProject.java +++ b/src/main/java/com/velox/sloan/cmo/workflows/workflows/ContainerRetrieval/GetPlatesForAProject.java @@ -28,10 +28,18 @@ public PluginResult run() throws Throwable { List requests = dataRecordManager.queryDataRecords("Request", "RequestId = '" + requestId + "'", user); DataRecord[] relatedSamples = requests.get(0).getChildrenOfType("Sample", user); Set plates = new HashSet<>(); + Set racks = new HashSet<>(); for (DataRecord sample: relatedSamples) { - plates.add(Arrays.asList(sample.getParentsOfType("Plate", user).get(0)).get(0)); + if (sample.getParentsOfType("Plate", user) != null && sample.getParentsOfType("Plate", user).size() > 0) { + plates.add(Arrays.asList(sample.getParentsOfType("Plate", user).get(0)).get(0)); + } + String micronicTubeBarcode = sample.getStringVal("MicronicTubeBarcode", user); + if (sample.getParentsOfType("MicronicRack", user) != null && sample.getParentsOfType("MicronicRack", user).size() > 0) { + racks.add(Arrays.asList(sample.getParentsOfType("MicronicRack", user).get(0)).get(0)); + } } activeTask.addAttachedDataRecords(plates); + activeTask.addAttachedDataRecords(racks); } catch (Exception e) { clientCallback.displayError(String.format("An exception occurred while finding plates of the entered project ID:\n%s", ExceptionUtils.getStackTrace(e))); From f154fb0f25b4cbb24c8e9fba0bfe672f2336bf94 Mon Sep 17 00:00:00 2001 From: Fahimeh Mirhaj Date: Thu, 8 May 2025 16:51:34 -0400 Subject: [PATCH 3/3] different container retreival --- .../GetPlatesForAProject.java | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/velox/sloan/cmo/workflows/workflows/ContainerRetrieval/GetPlatesForAProject.java b/src/main/java/com/velox/sloan/cmo/workflows/workflows/ContainerRetrieval/GetPlatesForAProject.java index c214a066..53c25edb 100644 --- a/src/main/java/com/velox/sloan/cmo/workflows/workflows/ContainerRetrieval/GetPlatesForAProject.java +++ b/src/main/java/com/velox/sloan/cmo/workflows/workflows/ContainerRetrieval/GetPlatesForAProject.java @@ -24,22 +24,32 @@ public boolean shouldRun() throws RemoteException { public PluginResult run() throws Throwable { try { - String requestId = clientCallback.showInputDialog("Please enter the request ID of the samples to return"); - List requests = dataRecordManager.queryDataRecords("Request", "RequestId = '" + requestId + "'", user); - DataRecord[] relatedSamples = requests.get(0).getChildrenOfType("Sample", user); Set plates = new HashSet<>(); Set racks = new HashSet<>(); - for (DataRecord sample: relatedSamples) { - if (sample.getParentsOfType("Plate", user) != null && sample.getParentsOfType("Plate", user).size() > 0) { - plates.add(Arrays.asList(sample.getParentsOfType("Plate", user).get(0)).get(0)); - } - String micronicTubeBarcode = sample.getStringVal("MicronicTubeBarcode", user); - if (sample.getParentsOfType("MicronicRack", user) != null && sample.getParentsOfType("MicronicRack", user).size() > 0) { - racks.add(Arrays.asList(sample.getParentsOfType("MicronicRack", user).get(0)).get(0)); + String requestIds = clientCallback.showInputDialog("Please enter the comma separated request IDs of the samples to return"); + if (requestIds.isEmpty() || requestIds.isBlank()) { + return new PluginResult(true); + } + String[] requestsArr = requestIds.split(","); + for (String eachRequest : requestsArr) { + List requests = dataRecordManager.queryDataRecords("Request", "RequestId = '" + eachRequest.trim() + "'", user); + DataRecord[] relatedSamples = requests.get(0).getChildrenOfType("Sample", user); + for (DataRecord sample: relatedSamples) { + if (sample.getParentsOfType("Plate", user) != null && sample.getParentsOfType("Plate", user).size() > 0) { + plates.add(Arrays.asList(sample.getParentsOfType("Plate", user).get(0)).get(0)); + logInfo("Adding plate: " + Arrays.asList(sample.getParentsOfType("Plate", user).get(0)).get(0).getStringVal("StorageLocationBarcode", user)); + } + String micronicTubeBarcode = sample.getStringVal("StorageLocationBarcode", user); + //String containerType = sample.getStringVal("ContainerType", user); + if (micronicTubeBarcode != null && micronicTubeBarcode.length() > 1 && micronicTubeBarcode.matches("\\d+")) { // storage location barcodes for micronic racks are all digits and the length should be > 1, excluding + List micronicRacks = dataRecordManager.queryDataRecords("StorageUnit", "StorageUnitId = '" + micronicTubeBarcode + "'", user); + logInfo("Adding rack: " + micronicRacks.get(0).getStringVal("StorageUnitId", user)); + racks.add(micronicRacks.get(0)); + } } + activeTask.addAttachedDataRecords(plates); + activeTask.addAttachedDataRecords(racks); } - activeTask.addAttachedDataRecords(plates); - activeTask.addAttachedDataRecords(racks); } catch (Exception e) { clientCallback.displayError(String.format("An exception occurred while finding plates of the entered project ID:\n%s", ExceptionUtils.getStackTrace(e)));