|
29 | 29 | import org.fhcrc.cpas.exp.xml.*; |
30 | 30 | import org.jetbrains.annotations.NotNull; |
31 | 31 | import org.jetbrains.annotations.Nullable; |
| 32 | +import org.labkey.api.admin.FolderImportContext; |
32 | 33 | import org.labkey.api.assay.AssayProvider; |
33 | 34 | import org.labkey.api.assay.AssayService; |
34 | 35 | import org.labkey.api.collections.LongHashMap; |
@@ -138,7 +139,8 @@ public class XarReader extends AbstractXarImporter |
138 | 139 |
|
139 | 140 | private final Set<String> _experimentLSIDs = new HashSet<>(); |
140 | 141 | private final Map<String, Integer> _propertyIdMap = new HashMap<>(); |
141 | | - private final Map<Long, String> _runWorkflowTaskMap = new LongHashMap<>(); |
| 142 | + private final Map<Long, Long> _runWorkflowTaskMap = new LongHashMap<>(); |
| 143 | + private final FolderImportContext _folderImportContext; |
142 | 144 | /** Retain replacement info so we can wire them up after all runs have been imported */ |
143 | 145 | private final Map<Long, String> _runReplacedByMap = new LongHashMap<>(); |
144 | 146 |
|
@@ -168,9 +170,15 @@ public class XarReader extends AbstractXarImporter |
168 | 170 | private AuditBehaviorType _auditBehaviorType = null; |
169 | 171 |
|
170 | 172 | public XarReader(XarSource source, PipelineJob job) |
| 173 | + { |
| 174 | + this(source, job, null); |
| 175 | + } |
| 176 | + |
| 177 | + public XarReader(XarSource source, PipelineJob job, FolderImportContext ctx) |
171 | 178 | { |
172 | 179 | super(source, job); |
173 | 180 | _fileRootPath = getContainerFileRootPath(job.getContainer()); |
| 181 | + _folderImportContext = ctx; |
174 | 182 | } |
175 | 183 |
|
176 | 184 | public void setReloadExistingRuns(boolean reloadExistingRuns) |
@@ -429,10 +437,8 @@ private void loadDoc() throws ExperimentException |
429 | 437 | } |
430 | 438 | } |
431 | 439 |
|
432 | | - if (!_runWorkflowTaskMap.isEmpty()) |
433 | | - { |
434 | | - saveRunWorkflowTaskIds(); |
435 | | - } |
| 440 | + if (_folderImportContext != null) |
| 441 | + _folderImportContext.setAssayRunWorkflowTaskMap(_runWorkflowTaskMap); |
436 | 442 |
|
437 | 443 | resolveReplacedByRunLSIDs(); |
438 | 444 |
|
@@ -1100,56 +1106,45 @@ private void loadExperimentRun(ExperimentRunType a, List<ExpMaterial> startingMa |
1100 | 1106 | } |
1101 | 1107 | } |
1102 | 1108 |
|
1103 | | - if (run == null) |
1104 | | - { |
1105 | | - ExperimentRun vals = new ExperimentRun(); |
1106 | | - // todo not sure about having roots stored in database |
1107 | | - // todo support substitutions here? |
1108 | 1109 |
|
1109 | | - vals.setLSID(pRunLSID.toString()); |
| 1110 | + ExperimentRun vals = new ExperimentRun(); |
| 1111 | + // todo not sure about having roots stored in database |
| 1112 | + // todo support substitutions here? |
1110 | 1113 |
|
1111 | | - vals.setName(trimString(a.getName())); |
1112 | | - vals.setProtocolLSID(protocol.getLSID()); |
1113 | | - vals.setComments(trimString(a.getComments())); |
| 1114 | + vals.setLSID(pRunLSID.toString()); |
1114 | 1115 |
|
1115 | | - vals.setFilePathRoot(FileUtil.getAbsolutePath(_xarSource.getJobRootPath())); |
1116 | | - vals.setContainer(getContainer()); |
1117 | | - // TODO need to update this for run workflowTaskId support in XAR on workflow job folder export/import is supported |
1118 | | - //String workflowTaskLSID = a.getWorkflowTaskLSID(); |
1119 | | - //if (workflowTaskLSID != null) |
1120 | | - //{ |
1121 | | - // if (!workflowTaskLSID.startsWith("${WorkflowTaskReference}:")) |
1122 | | - // throw new XarFormatException("Invalid WorkflowTaskLSID encountered: " + workflowTaskLSID); |
1123 | | - // |
1124 | | - // workflowTaskLSID = workflowTaskLSID.split(":")[1]; |
1125 | | - //} |
1126 | | - if (_job != null) |
1127 | | - { |
1128 | | - // remember which job created the run so we can show this run on the job details page |
1129 | | - vals.setJobId(PipelineService.get().getJobId(_job.getUser(), _job.getContainer(), _job.getJobGUID())); |
1130 | | - } |
| 1116 | + vals.setName(trimString(a.getName())); |
| 1117 | + vals.setProtocolLSID(protocol.getLSID()); |
| 1118 | + vals.setComments(trimString(a.getComments())); |
1131 | 1119 |
|
1132 | | - ExpRunImpl impl = new ExpRunImpl(vals); |
1133 | | - try |
1134 | | - { |
1135 | | - impl.save(getUser()); |
1136 | | - run = impl.getDataObject(); |
| 1120 | + vals.setFilePathRoot(FileUtil.getAbsolutePath(_xarSource.getJobRootPath())); |
| 1121 | + vals.setContainer(getContainer()); |
1137 | 1122 |
|
1138 | | - //if (workflowTaskLSID != null) |
1139 | | - // _runWorkflowTaskMap.put(run.getRowId(), workflowTaskLSID); |
| 1123 | + if (_job != null) |
| 1124 | + { |
| 1125 | + // remember which job created the run so we can show this run on the job details page |
| 1126 | + vals.setJobId(PipelineService.get().getJobId(_job.getUser(), _job.getContainer(), _job.getJobGUID())); |
| 1127 | + } |
1140 | 1128 |
|
1141 | | - String replacedByLSID = a.getReplacedByRunLSID(); |
1142 | | - if (replacedByLSID != null) |
1143 | | - // Save for later so that we can resolve after everything's been imported |
1144 | | - { |
1145 | | - _runReplacedByMap.put(impl.getRowId(), replacedByLSID); |
1146 | | - } |
1147 | | - } |
1148 | | - catch (BatchValidationException x) |
| 1129 | + ExpRunImpl impl = new ExpRunImpl(vals); |
| 1130 | + try |
| 1131 | + { |
| 1132 | + impl.save(getUser()); |
| 1133 | + run = impl.getDataObject(); |
| 1134 | + String taskIdStr = a.getWorkflowTaskId(); |
| 1135 | + if (taskIdStr != null) |
| 1136 | + _runWorkflowTaskMap.put(run.getRowId(), Long.valueOf(taskIdStr)); |
| 1137 | + String replacedByLSID = a.getReplacedByRunLSID(); |
| 1138 | + if (replacedByLSID != null) |
| 1139 | + // Save for later so that we can resolve after everything's been imported |
1149 | 1140 | { |
1150 | | - throw new ExperimentException(x); |
| 1141 | + _runReplacedByMap.put(impl.getRowId(), replacedByLSID); |
1151 | 1142 | } |
1152 | 1143 | } |
| 1144 | + catch (BatchValidationException x) |
| 1145 | + { |
| 1146 | + throw new ExperimentException(x); |
| 1147 | + } |
1153 | 1148 |
|
1154 | 1149 | if (experimentLSID != null) |
1155 | 1150 | { |
@@ -1208,46 +1203,6 @@ private void loadExperimentRun(ExperimentRunType a, List<ExpMaterial> startingMa |
1208 | 1203 | getLog().debug("Finished loading ExperimentRun with LSID '" + runLSID + "'"); |
1209 | 1204 | } |
1210 | 1205 |
|
1211 | | - /** |
1212 | | - * // TODO need to update this for run workflowTaskId support in XAR |
1213 | | - * This method runs last, and is used to wire up the Workflow Task FK relationship between Exp Runs and |
1214 | | - * Exp ProtocolApplications. This needs to run last because we have no good way to guarantee import order and ensure |
1215 | | - * all the appropriate ProtocolApplications are imported before the Exp Runs. |
1216 | | - */ |
1217 | | - private void saveRunWorkflowTaskIds() throws ExperimentException |
1218 | | - { |
1219 | | - for (ExpRun run : _loadedRuns) |
1220 | | - { |
1221 | | - String objectId = _runWorkflowTaskMap.get(run.getRowId()); |
1222 | | - |
1223 | | - if (objectId != null) |
1224 | | - { |
1225 | | - List<? extends ExpProtocolApplication> protocolApplications = ExperimentService.get().getExpProtocolApplicationsByObjectId(getContainer(), objectId); |
1226 | | - |
1227 | | - if (protocolApplications.size() > 1) |
1228 | | - { |
1229 | | - throw new ExperimentException("Multiple ProtocolApplications found with object id: " + objectId); |
1230 | | - } |
1231 | | - else if (protocolApplications.isEmpty()) |
1232 | | - { |
1233 | | - getLog().warn("Could not find ProtocolApplication with LSID containing object id: " + objectId); |
1234 | | - } |
1235 | | - else |
1236 | | - { |
1237 | | - run.setWorkflowTaskId(protocolApplications.get(0).getRowId()); |
1238 | | - |
1239 | | - try { |
1240 | | - run.save(getUser()); |
1241 | | - } |
1242 | | - catch (BatchValidationException e) |
1243 | | - { |
1244 | | - throw new ExperimentException(e); |
1245 | | - } |
1246 | | - } |
1247 | | - } |
1248 | | - } |
1249 | | - } |
1250 | | - |
1251 | 1206 | public List<String> getProcessedRunsLSIDs() |
1252 | 1207 | { |
1253 | 1208 | return _processedRunsLSIDs; |
@@ -1449,9 +1404,7 @@ private void loadProtocolApplication(ProtocolApplicationBaseType xmlProtocolApp, |
1449 | 1404 | if ((protocolLSID.equals(SAMPLE_ALIQUOT_PROTOCOL_LSID) || protocolLSID.equals(SAMPLE_DERIVATION_PROTOCOL_LSID)) && |
1450 | 1405 | !material.isOperationPermitted(SampleTypeService.SampleOperations.EditLineage)) |
1451 | 1406 | return SampleTypeService.get().getOperationNotPermittedMessage(Collections.singleton(material), SampleTypeService.SampleOperations.EditLineage); |
1452 | | - if ((ExpProtocol.isSampleWorkflowProtocol(protocolLSID)) |
1453 | | - && !material.isOperationPermitted(SampleTypeService.SampleOperations.AddToWorkflow)) |
1454 | | - return SampleTypeService.get().getOperationNotPermittedMessage(Collections.singleton(material), SampleTypeService.SampleOperations.AddToWorkflow); |
| 1407 | + |
1455 | 1408 | return null; |
1456 | 1409 | } |
1457 | 1410 |
|
|
0 commit comments