@Test @RunWithCustomExecutor public void should_rectificate_unit_step() throws Exception { when(defaultWorkerParameters.getObjectName()).thenReturn(OBJECT_NAME); when(defaultWorkerParameters.getContainerName()).thenReturn(CONTAINER_NAME); File file = tempFolder.newFile(); File file2 = tempFolder.newFile(); writeAsFile(getFromString(UNIT_REPORT_EVIDENCE_AUDIT), file); when(handlerIO.getFileFromWorkspace(ALTER)).thenReturn(file); when(handlerIO.getNewLocalFile(OBJECT_NAME)).thenReturn(file2); rawObjectGroup1 = JsonHandler.getFromInputStream(PropertiesUtils.getResourceAsStream(GUID_OG1)); doReturn( new RequestResponseOK<JsonNode>().addResult(rawObjectGroup1) ).when(metaDataClient).getObjectGroupsByIdsRaw(eq(Arrays.asList(GUID_OG1))); ItemStatus execute = dataRectificationStep.execute(defaultWorkerParameters, handlerIO); assertThat(execute.getGlobalStatus()).isEqualTo(StatusCode.OK); JsonNode result = JsonHandler.getFromFile(handlerIO.getNewLocalFile("test")); assertThat(result.get(0).get("Id").asText()).isEqualTo("aebaaaaaaackemvrabfuealm66lqsjqaaaaq"); assertThat(result.get(0).get("Type").asText()).isEqualTo("UNIT"); }
@Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { ItemStatus itemStatus = new ItemStatus(CORRECTIVE_AUDIT); try { List<IdentifierType> identifierTypes = new ArrayList<>(); File file = handler.getFileFromWorkspace(ALTER + File.separator + param.getObjectName()); EvidenceAuditReportLine evidenceAuditReportLine = JsonHandler.getFromFile(file, EvidenceAuditReportLine.class); if (evidenceAuditReportLine.getObjectType().equals(MetadataType.OBJECTGROUP)) { List<IdentifierType> objectGroups = dataRectificationService.correctObjectGroups(evidenceAuditReportLine, param.getContainerName()); identifierTypes.addAll(objectGroups); } Optional<IdentifierType> identifierType = Optional.empty(); if (evidenceAuditReportLine.getObjectType().equals(MetadataType.UNIT)) { identifierType = dataRectificationService.correctUnits(evidenceAuditReportLine, param.getContainerName()); } identifierType.ifPresent(identifierTypes::add); file = handler.getNewLocalFile(param.getObjectName()); if (!identifierTypes.isEmpty()) { JsonHandler.writeAsFile(identifierTypes, file); handler.transferFileToWorkspace(CORRECT + param.getObjectName() + ".report.json", file, true, false); for (IdentifierType type : identifierTypes) { if (type.getType().equals(DataCategory.OBJECTGROUP.name()) || type.getType().equals(DataCategory.OBJECT.name()) ) { storeMetaDataObjectGroupActionPlugin.storeDocumentsWithLfc( param, handler, Collections.singletonList(type.getId()) ); } if (type.getType().equals(DataCategory.UNIT.name())) { storeMetaDataUnitActionPlugin.storeDocumentsWithLfc( param, handler, Collections.singletonList(type.getId())); } } } itemStatus.increment(StatusCode.OK); } catch (IOException | VitamException e) { LOGGER.error(e); return itemStatus.increment(StatusCode.FATAL); } return new ItemStatus(CORRECTIVE_AUDIT) .setItemsStatus(CORRECTIVE_AUDIT, itemStatus); }
DataRectificationStep extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { ItemStatus itemStatus = new ItemStatus(CORRECTIVE_AUDIT); try { List<IdentifierType> identifierTypes = new ArrayList<>(); File file = handler.getFileFromWorkspace(ALTER + File.separator + param.getObjectName()); EvidenceAuditReportLine evidenceAuditReportLine = JsonHandler.getFromFile(file, EvidenceAuditReportLine.class); if (evidenceAuditReportLine.getObjectType().equals(MetadataType.OBJECTGROUP)) { List<IdentifierType> objectGroups = dataRectificationService.correctObjectGroups(evidenceAuditReportLine, param.getContainerName()); identifierTypes.addAll(objectGroups); } Optional<IdentifierType> identifierType = Optional.empty(); if (evidenceAuditReportLine.getObjectType().equals(MetadataType.UNIT)) { identifierType = dataRectificationService.correctUnits(evidenceAuditReportLine, param.getContainerName()); } identifierType.ifPresent(identifierTypes::add); file = handler.getNewLocalFile(param.getObjectName()); if (!identifierTypes.isEmpty()) { JsonHandler.writeAsFile(identifierTypes, file); handler.transferFileToWorkspace(CORRECT + param.getObjectName() + ".report.json", file, true, false); for (IdentifierType type : identifierTypes) { if (type.getType().equals(DataCategory.OBJECTGROUP.name()) || type.getType().equals(DataCategory.OBJECT.name()) ) { storeMetaDataObjectGroupActionPlugin.storeDocumentsWithLfc( param, handler, Collections.singletonList(type.getId()) ); } if (type.getType().equals(DataCategory.UNIT.name())) { storeMetaDataUnitActionPlugin.storeDocumentsWithLfc( param, handler, Collections.singletonList(type.getId())); } } } itemStatus.increment(StatusCode.OK); } catch (IOException | VitamException e) { LOGGER.error(e); return itemStatus.increment(StatusCode.FATAL); } return new ItemStatus(CORRECTIVE_AUDIT) .setItemsStatus(CORRECTIVE_AUDIT, itemStatus); } }
DataRectificationStep extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { ItemStatus itemStatus = new ItemStatus(CORRECTIVE_AUDIT); try { List<IdentifierType> identifierTypes = new ArrayList<>(); File file = handler.getFileFromWorkspace(ALTER + File.separator + param.getObjectName()); EvidenceAuditReportLine evidenceAuditReportLine = JsonHandler.getFromFile(file, EvidenceAuditReportLine.class); if (evidenceAuditReportLine.getObjectType().equals(MetadataType.OBJECTGROUP)) { List<IdentifierType> objectGroups = dataRectificationService.correctObjectGroups(evidenceAuditReportLine, param.getContainerName()); identifierTypes.addAll(objectGroups); } Optional<IdentifierType> identifierType = Optional.empty(); if (evidenceAuditReportLine.getObjectType().equals(MetadataType.UNIT)) { identifierType = dataRectificationService.correctUnits(evidenceAuditReportLine, param.getContainerName()); } identifierType.ifPresent(identifierTypes::add); file = handler.getNewLocalFile(param.getObjectName()); if (!identifierTypes.isEmpty()) { JsonHandler.writeAsFile(identifierTypes, file); handler.transferFileToWorkspace(CORRECT + param.getObjectName() + ".report.json", file, true, false); for (IdentifierType type : identifierTypes) { if (type.getType().equals(DataCategory.OBJECTGROUP.name()) || type.getType().equals(DataCategory.OBJECT.name()) ) { storeMetaDataObjectGroupActionPlugin.storeDocumentsWithLfc( param, handler, Collections.singletonList(type.getId()) ); } if (type.getType().equals(DataCategory.UNIT.name())) { storeMetaDataUnitActionPlugin.storeDocumentsWithLfc( param, handler, Collections.singletonList(type.getId())); } } } itemStatus.increment(StatusCode.OK); } catch (IOException | VitamException e) { LOGGER.error(e); return itemStatus.increment(StatusCode.FATAL); } return new ItemStatus(CORRECTIVE_AUDIT) .setItemsStatus(CORRECTIVE_AUDIT, itemStatus); } @VisibleForTesting  DataRectificationStep(
        DataRectificationService dataRectificationService,
        StoreMetaDataObjectGroupActionPlugin storeMetaDataObjectGroupActionPlugin,
        StoreMetaDataUnitActionPlugin storeMetaDataUnitActionPlugin);  DataRectificationStep(); }
DataRectificationStep extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { ItemStatus itemStatus = new ItemStatus(CORRECTIVE_AUDIT); try { List<IdentifierType> identifierTypes = new ArrayList<>(); File file = handler.getFileFromWorkspace(ALTER + File.separator + param.getObjectName()); EvidenceAuditReportLine evidenceAuditReportLine = JsonHandler.getFromFile(file, EvidenceAuditReportLine.class); if (evidenceAuditReportLine.getObjectType().equals(MetadataType.OBJECTGROUP)) { List<IdentifierType> objectGroups = dataRectificationService.correctObjectGroups(evidenceAuditReportLine, param.getContainerName()); identifierTypes.addAll(objectGroups); } Optional<IdentifierType> identifierType = Optional.empty(); if (evidenceAuditReportLine.getObjectType().equals(MetadataType.UNIT)) { identifierType = dataRectificationService.correctUnits(evidenceAuditReportLine, param.getContainerName()); } identifierType.ifPresent(identifierTypes::add); file = handler.getNewLocalFile(param.getObjectName()); if (!identifierTypes.isEmpty()) { JsonHandler.writeAsFile(identifierTypes, file); handler.transferFileToWorkspace(CORRECT + param.getObjectName() + ".report.json", file, true, false); for (IdentifierType type : identifierTypes) { if (type.getType().equals(DataCategory.OBJECTGROUP.name()) || type.getType().equals(DataCategory.OBJECT.name()) ) { storeMetaDataObjectGroupActionPlugin.storeDocumentsWithLfc( param, handler, Collections.singletonList(type.getId()) ); } if (type.getType().equals(DataCategory.UNIT.name())) { storeMetaDataUnitActionPlugin.storeDocumentsWithLfc( param, handler, Collections.singletonList(type.getId())); } } } itemStatus.increment(StatusCode.OK); } catch (IOException | VitamException e) { LOGGER.error(e); return itemStatus.increment(StatusCode.FATAL); } return new ItemStatus(CORRECTIVE_AUDIT) .setItemsStatus(CORRECTIVE_AUDIT, itemStatus); } @VisibleForTesting  DataRectificationStep(
        DataRectificationService dataRectificationService,
        StoreMetaDataObjectGroupActionPlugin storeMetaDataObjectGroupActionPlugin,
        StoreMetaDataUnitActionPlugin storeMetaDataUnitActionPlugin);  DataRectificationStep(); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler); }
DataRectificationStep extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { ItemStatus itemStatus = new ItemStatus(CORRECTIVE_AUDIT); try { List<IdentifierType> identifierTypes = new ArrayList<>(); File file = handler.getFileFromWorkspace(ALTER + File.separator + param.getObjectName()); EvidenceAuditReportLine evidenceAuditReportLine = JsonHandler.getFromFile(file, EvidenceAuditReportLine.class); if (evidenceAuditReportLine.getObjectType().equals(MetadataType.OBJECTGROUP)) { List<IdentifierType> objectGroups = dataRectificationService.correctObjectGroups(evidenceAuditReportLine, param.getContainerName()); identifierTypes.addAll(objectGroups); } Optional<IdentifierType> identifierType = Optional.empty(); if (evidenceAuditReportLine.getObjectType().equals(MetadataType.UNIT)) { identifierType = dataRectificationService.correctUnits(evidenceAuditReportLine, param.getContainerName()); } identifierType.ifPresent(identifierTypes::add); file = handler.getNewLocalFile(param.getObjectName()); if (!identifierTypes.isEmpty()) { JsonHandler.writeAsFile(identifierTypes, file); handler.transferFileToWorkspace(CORRECT + param.getObjectName() + ".report.json", file, true, false); for (IdentifierType type : identifierTypes) { if (type.getType().equals(DataCategory.OBJECTGROUP.name()) || type.getType().equals(DataCategory.OBJECT.name()) ) { storeMetaDataObjectGroupActionPlugin.storeDocumentsWithLfc( param, handler, Collections.singletonList(type.getId()) ); } if (type.getType().equals(DataCategory.UNIT.name())) { storeMetaDataUnitActionPlugin.storeDocumentsWithLfc( param, handler, Collections.singletonList(type.getId())); } } } itemStatus.increment(StatusCode.OK); } catch (IOException | VitamException e) { LOGGER.error(e); return itemStatus.increment(StatusCode.FATAL); } return new ItemStatus(CORRECTIVE_AUDIT) .setItemsStatus(CORRECTIVE_AUDIT, itemStatus); } @VisibleForTesting  DataRectificationStep(
        DataRectificationService dataRectificationService,
        StoreMetaDataObjectGroupActionPlugin storeMetaDataObjectGroupActionPlugin,
        StoreMetaDataUnitActionPlugin storeMetaDataUnitActionPlugin);  DataRectificationStep(); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler);  }