@Test public void givenNoUnitUpdatesThenCheckUnitUpdatesFromOtherOperationsOK() throws Exception { JsonNode unitIds = new RequestResponseOK<JsonNode>().addAllResults(Arrays.asList( JsonHandler.createObjectNode() .put(VitamFieldsHelper.id(), "unit1") .set(VitamFieldsHelper.operations(), JsonHandler.createArrayNode().add(INGEST_OPERATION_ID)), JsonHandler.createObjectNode() .put(VitamFieldsHelper.id(), "unit2") .set(VitamFieldsHelper.operations(), JsonHandler.createArrayNode().add(INGEST_OPERATION_ID)) )).toJsonNode(); when(metaDataClient.selectUnits(any())).thenReturn(unitIds); CleanupReportManager cleanupReportManager = CleanupReportManager.newReport(INGEST_OPERATION_ID); instance.checkUnitUpdatesFromOtherOperations(INGEST_OPERATION_ID, cleanupReportManager); assertThat(cleanupReportManager.getGlobalStatus()).isEqualTo(StatusCode.OK); ArgumentCaptor<JsonNode> queryCaptor = ArgumentCaptor.forClass(JsonNode.class); verify(metaDataClient, times(1)).selectUnits(queryCaptor.capture()); checkQueryEquals(queryCaptor.getAllValues().get(0), "IngestCleanup/Eligibility/selectUnitOperationsQuery.json"); }
public void checkUnitUpdatesFromOtherOperations(String ingestOperationId, CleanupReportManager cleanupReportManager) throws ProcessingStatusException { try (MetaDataClient client = metaDataClientFactory.getClient()) { SelectMultiQuery query = new SelectMultiQuery(); query.addUsedProjection( VitamFieldsHelper.id(), VitamFieldsHelper.operations()); query.addQueries(eq(VitamFieldsHelper.initialOperation(), ingestOperationId)); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createUnitScrollSplitIterator(client, query, VitamConfiguration.getBatchSize()); scrollRequest.forEachRemaining(unitNode -> { try { List<String> ops = JsonHandler .getFromJsonNode(unitNode.get(VitamFieldsHelper.operations()), STRING_LIST_TYPE_REFERENCE); if (ops.size() != 1) { List<String> otherOperations = ops.stream().filter(op -> !op.equals(ingestOperationId)) .collect(Collectors.toList()); String id = unitNode.get(VitamFieldsHelper.id()).asText(); cleanupReportManager .reportUnitWarning(id, "Updates occurred to unit by operations " + otherOperations); } } catch (InvalidParseOperationException e) { throw new RuntimeException(e); } }); } catch (InvalidParseOperationException | InvalidCreateOperationException e) { throw new ProcessingStatusException(StatusCode.FATAL, "Could not checks updated units", e); } }
IngestCleanupEligibilityService { public void checkUnitUpdatesFromOtherOperations(String ingestOperationId, CleanupReportManager cleanupReportManager) throws ProcessingStatusException { try (MetaDataClient client = metaDataClientFactory.getClient()) { SelectMultiQuery query = new SelectMultiQuery(); query.addUsedProjection( VitamFieldsHelper.id(), VitamFieldsHelper.operations()); query.addQueries(eq(VitamFieldsHelper.initialOperation(), ingestOperationId)); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createUnitScrollSplitIterator(client, query, VitamConfiguration.getBatchSize()); scrollRequest.forEachRemaining(unitNode -> { try { List<String> ops = JsonHandler .getFromJsonNode(unitNode.get(VitamFieldsHelper.operations()), STRING_LIST_TYPE_REFERENCE); if (ops.size() != 1) { List<String> otherOperations = ops.stream().filter(op -> !op.equals(ingestOperationId)) .collect(Collectors.toList()); String id = unitNode.get(VitamFieldsHelper.id()).asText(); cleanupReportManager .reportUnitWarning(id, "Updates occurred to unit by operations " + otherOperations); } } catch (InvalidParseOperationException e) { throw new RuntimeException(e); } }); } catch (InvalidParseOperationException | InvalidCreateOperationException e) { throw new ProcessingStatusException(StatusCode.FATAL, "Could not checks updated units", e); } } }
IngestCleanupEligibilityService { public void checkUnitUpdatesFromOtherOperations(String ingestOperationId, CleanupReportManager cleanupReportManager) throws ProcessingStatusException { try (MetaDataClient client = metaDataClientFactory.getClient()) { SelectMultiQuery query = new SelectMultiQuery(); query.addUsedProjection( VitamFieldsHelper.id(), VitamFieldsHelper.operations()); query.addQueries(eq(VitamFieldsHelper.initialOperation(), ingestOperationId)); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createUnitScrollSplitIterator(client, query, VitamConfiguration.getBatchSize()); scrollRequest.forEachRemaining(unitNode -> { try { List<String> ops = JsonHandler .getFromJsonNode(unitNode.get(VitamFieldsHelper.operations()), STRING_LIST_TYPE_REFERENCE); if (ops.size() != 1) { List<String> otherOperations = ops.stream().filter(op -> !op.equals(ingestOperationId)) .collect(Collectors.toList()); String id = unitNode.get(VitamFieldsHelper.id()).asText(); cleanupReportManager .reportUnitWarning(id, "Updates occurred to unit by operations " + otherOperations); } } catch (InvalidParseOperationException e) { throw new RuntimeException(e); } }); } catch (InvalidParseOperationException | InvalidCreateOperationException e) { throw new ProcessingStatusException(StatusCode.FATAL, "Could not checks updated units", e); } } IngestCleanupEligibilityService(MetaDataClientFactory metaDataClientFactory,
        LogbookOperationsClientFactory logbookOperationsClientFactory); }
IngestCleanupEligibilityService { public void checkUnitUpdatesFromOtherOperations(String ingestOperationId, CleanupReportManager cleanupReportManager) throws ProcessingStatusException { try (MetaDataClient client = metaDataClientFactory.getClient()) { SelectMultiQuery query = new SelectMultiQuery(); query.addUsedProjection( VitamFieldsHelper.id(), VitamFieldsHelper.operations()); query.addQueries(eq(VitamFieldsHelper.initialOperation(), ingestOperationId)); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createUnitScrollSplitIterator(client, query, VitamConfiguration.getBatchSize()); scrollRequest.forEachRemaining(unitNode -> { try { List<String> ops = JsonHandler .getFromJsonNode(unitNode.get(VitamFieldsHelper.operations()), STRING_LIST_TYPE_REFERENCE); if (ops.size() != 1) { List<String> otherOperations = ops.stream().filter(op -> !op.equals(ingestOperationId)) .collect(Collectors.toList()); String id = unitNode.get(VitamFieldsHelper.id()).asText(); cleanupReportManager .reportUnitWarning(id, "Updates occurred to unit by operations " + otherOperations); } } catch (InvalidParseOperationException e) { throw new RuntimeException(e); } }); } catch (InvalidParseOperationException | InvalidCreateOperationException e) { throw new ProcessingStatusException(StatusCode.FATAL, "Could not checks updated units", e); } } IngestCleanupEligibilityService(MetaDataClientFactory metaDataClientFactory,
        LogbookOperationsClientFactory logbookOperationsClientFactory); void checkChildUnitsFromOtherIngests(String ingestOperationId, CleanupReportManager cleanupReportManager); void checkUnitUpdatesFromOtherOperations(String ingestOperationId,
        CleanupReportManager cleanupReportManager); void checkObjectGroupUpdatesFromOtherOperations(String ingestOperationId,
        CleanupReportManager cleanupReportManager); void checkObjectAttachmentsToExistingObjectGroups(String ingestOperationId,
        CleanupReportManager cleanupReportManager); }
IngestCleanupEligibilityService { public void checkUnitUpdatesFromOtherOperations(String ingestOperationId, CleanupReportManager cleanupReportManager) throws ProcessingStatusException { try (MetaDataClient client = metaDataClientFactory.getClient()) { SelectMultiQuery query = new SelectMultiQuery(); query.addUsedProjection( VitamFieldsHelper.id(), VitamFieldsHelper.operations()); query.addQueries(eq(VitamFieldsHelper.initialOperation(), ingestOperationId)); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createUnitScrollSplitIterator(client, query, VitamConfiguration.getBatchSize()); scrollRequest.forEachRemaining(unitNode -> { try { List<String> ops = JsonHandler .getFromJsonNode(unitNode.get(VitamFieldsHelper.operations()), STRING_LIST_TYPE_REFERENCE); if (ops.size() != 1) { List<String> otherOperations = ops.stream().filter(op -> !op.equals(ingestOperationId)) .collect(Collectors.toList()); String id = unitNode.get(VitamFieldsHelper.id()).asText(); cleanupReportManager .reportUnitWarning(id, "Updates occurred to unit by operations " + otherOperations); } } catch (InvalidParseOperationException e) { throw new RuntimeException(e); } }); } catch (InvalidParseOperationException | InvalidCreateOperationException e) { throw new ProcessingStatusException(StatusCode.FATAL, "Could not checks updated units", e); } } IngestCleanupEligibilityService(MetaDataClientFactory metaDataClientFactory,
        LogbookOperationsClientFactory logbookOperationsClientFactory); void checkChildUnitsFromOtherIngests(String ingestOperationId, CleanupReportManager cleanupReportManager); void checkUnitUpdatesFromOtherOperations(String ingestOperationId,
        CleanupReportManager cleanupReportManager); void checkObjectGroupUpdatesFromOtherOperations(String ingestOperationId,
        CleanupReportManager cleanupReportManager); void checkObjectAttachmentsToExistingObjectGroups(String ingestOperationId,
        CleanupReportManager cleanupReportManager);  }