@@ -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 )
0 commit comments