Skip to content

Commit 4a0ec2a

Browse files
committed
Extract assay template container-scoping into a shared helper
Replace the duplicated workbook-resolution snippet in DefaultAssayParser.saveTemplate, DefaultAssayParser.getTemplateRowMap, and AssayHelper.saveTemplate with a single DefaultAssayParser.getTemplateContainerIds(Container) helper, so the container-scoping rule for assay_run_templates lookups lives in one place. Pure refactor; no behavior change.
1 parent 8ac6b0e commit 4a0ec2a

2 files changed

Lines changed: 19 additions & 20 deletions

File tree

laboratory/api-src/org/labkey/api/laboratory/assay/DefaultAssayParser.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -463,21 +463,29 @@ protected void validateRows(List<Map<String, Object>> rows, ImportContext contex
463463
errors.confirmNoErrors();
464464
}
465465

466+
/**
467+
* Returns the set of container ids in which an assay run template for a request in the given container may
468+
* legitimately live: the container itself, plus its parent when the request runs in a workbook (mirroring the
469+
* run-template picker, which sources templates from Laboratory.Utils.getQueryContainerPath). Used to scope
470+
* assay_run_templates lookups to the request's folder tree without reaching an unrelated container.
471+
*/
472+
public static List<String> getTemplateContainerIds(Container c)
473+
{
474+
List<String> ids = new ArrayList<>();
475+
ids.add(c.getId());
476+
if (c.isWorkbook())
477+
ids.add(c.getParent().getId());
478+
return ids;
479+
}
480+
466481
protected void saveTemplate(ViewContext ctx, int templateId, int runId) throws BatchValidationException
467482
{
468483
try
469484
{
470-
// The template may live in this container, or its parent when importing from a workbook
471-
// (the picker sources templates from getQueryContainerPath). Scope to that set, never beyond it.
472-
List<String> templateContainers = new ArrayList<>();
473-
templateContainers.add(_container.getId());
474-
if (_container.isWorkbook())
475-
templateContainers.add(_container.getParent().getId());
476-
477485
//validate the template exists in (or above) this container
478486
TableInfo ti = DbSchema.get("laboratory").getTable("assay_run_templates");
479487
SimpleFilter filter = new SimpleFilter(FieldKey.fromString("rowid"), templateId);
480-
filter.addCondition(FieldKey.fromString("container"), templateContainers, CompareType.IN);
488+
filter.addCondition(FieldKey.fromString("container"), getTemplateContainerIds(_container), CompareType.IN);
481489
TableSelector ts = new TableSelector(ti, filter, null);
482490
if (ts.getRowCount() == 0)
483491
{
@@ -594,15 +602,10 @@ protected Map<String, Map<String, Object>> getTemplateRowMap(ImportContext conte
594602
if (templateId == null)
595603
return ret;
596604

597-
List<String> templateContainers = new ArrayList<>();
598-
templateContainers.add(_container.getId());
599-
if (_container.isWorkbook())
600-
templateContainers.add(_container.getParent().getId());
601-
602605
TableInfo ti = DbSchema.get("laboratory").getTable("assay_run_templates");
603606

604607
SimpleFilter filter = new SimpleFilter(FieldKey.fromString("rowid"), templateId);
605-
filter.addCondition(FieldKey.fromString("container"), templateContainers, CompareType.IN);
608+
filter.addCondition(FieldKey.fromString("container"), getTemplateContainerIds(_container), CompareType.IN);
606609
TableSelector ts = new TableSelector(ti, filter, null);
607610
Map<String, Object>[] maps = ts.getMapArray();
608611
if (maps.length == 0)

laboratory/src/org/labkey/laboratory/assay/AssayHelper.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.labkey.api.laboratory.LaboratoryService;
5353
import org.labkey.api.laboratory.assay.AssayDataProvider;
5454
import org.labkey.api.laboratory.assay.AssayImportMethod;
55+
import org.labkey.api.laboratory.assay.DefaultAssayParser;
5556
import org.labkey.api.query.BatchValidationException;
5657
import org.labkey.api.query.FieldKey;
5758
import org.labkey.api.query.ValidationException;
@@ -144,13 +145,8 @@ public Map<String, Object> saveTemplate(User u, Container c, ExpProtocol protoco
144145
{
145146
// Table.update operates by global PK; verify the template is reachable from this container
146147
// (here, or the parent when in a workbook) before updating, and leave its container unchanged.
147-
List<String> templateContainers = new ArrayList<>();
148-
templateContainers.add(c.getId());
149-
if (c.isWorkbook())
150-
templateContainers.add(c.getParent().getId());
151-
152148
SimpleFilter filter = new SimpleFilter(FieldKey.fromString("rowid"), templateId);
153-
filter.addCondition(FieldKey.fromString("container"), templateContainers, CompareType.IN);
149+
filter.addCondition(FieldKey.fromString("container"), DefaultAssayParser.getTemplateContainerIds(c), CompareType.IN);
154150
if (!new TableSelector(ti, filter, null).exists())
155151
{
156152
errors.addRowError(new ValidationException("Unknown template: " + templateId));

0 commit comments

Comments
 (0)