@Test public void givenNoObjectGroupUpdatesThenCheckObjectGroupUpdatesFromOtherOperationsOK() throws Exception { JsonNode objectGroups = new RequestResponseOK<JsonNode>().addAllResults(Arrays.asList( JsonHandler.createObjectNode() .put(VitamFieldsHelper.id(), "og1") .set(VitamFieldsHelper.operations(), JsonHandler.createArrayNode().add(INGEST_OPERATION_ID)), JsonHandler.createObjectNode() .put(VitamFieldsHelper.id(), "og1") .set(VitamFieldsHelper.operations(), JsonHandler.createArrayNode().add(INGEST_OPERATION_ID)) )).toJsonNode(); when(metaDataClient.selectObjectGroups(any())).thenReturn(objectGroups); CleanupReportManager cleanupReportManager = CleanupReportManager.newReport(INGEST_OPERATION_ID); instance.checkObjectGroupUpdatesFromOtherOperations(INGEST_OPERATION_ID, cleanupReportManager); assertThat(cleanupReportManager.getGlobalStatus()).isEqualTo(StatusCode.OK); ArgumentCaptor<JsonNode> queryCaptor = ArgumentCaptor.forClass(JsonNode.class); verify(metaDataClient, times(1)).selectObjectGroups(queryCaptor.capture()); checkQueryEquals(queryCaptor.getAllValues().get(0), "IngestCleanup/Eligibility/selectObjectGroupOperationsQuery.json"); verifyZeroInteractions(logbookOperationsClient); }
public void checkObjectGroupUpdatesFromOtherOperations(String ingestOperationId, CleanupReportManager cleanupReportManager) throws ProcessingStatusException { try (MetaDataClient client = metaDataClientFactory.getClient()) { SelectMultiQuery query = new SelectMultiQuery(); query.addQueries(eq(VitamFieldsHelper.initialOperation(), ingestOperationId)); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createObjectGroupScrollSplitIterator(client, query, VitamConfiguration.getBatchSize()); MultiValuedMap<String, String> updatedObjectGroupsByOpi = new ArrayListValuedHashMap<>(); scrollRequest.forEachRemaining(objectGroupNode -> { try { List<String> ops = JsonHandler .getFromJsonNode(objectGroupNode.get(VitamFieldsHelper.operations()), STRING_LIST_TYPE_REFERENCE); for (String op : ops) { if (!op.equals(ingestOperationId)) { String id = objectGroupNode.get(VitamFieldsHelper.id()).asText(); updatedObjectGroupsByOpi.put(op, id); } } } catch (InvalidParseOperationException e) { throw new RuntimeException(e); } }); if (!updatedObjectGroupsByOpi.isEmpty()) { Set<String> ingestOperations = checkIngestOperations(updatedObjectGroupsByOpi.keySet()); Set<String> nonIngestOperations = SetUtils.difference(updatedObjectGroupsByOpi.keySet(), ingestOperations); for (String nonIngestOperation : nonIngestOperations) { for (String objectGroupId : updatedObjectGroupsByOpi.get(nonIngestOperation)) { cleanupReportManager.reportObjectGroupWarning(objectGroupId, "Updates occurred to object group by operation " + nonIngestOperations); } } for (String nonIngestOperation : ingestOperations) { for (String objectGroupId : updatedObjectGroupsByOpi.get(nonIngestOperation)) { cleanupReportManager.reportObjectGroupError(objectGroupId, "Updates occurred to object group by ingest operation " + nonIngestOperations); } } } } catch (InvalidCreateOperationException | InvalidParseOperationException | LogbookClientException e) { throw new ProcessingStatusException(StatusCode.FATAL, "Could not checks updated object groups", e); } }
IngestCleanupEligibilityService { public void checkObjectGroupUpdatesFromOtherOperations(String ingestOperationId, CleanupReportManager cleanupReportManager) throws ProcessingStatusException { try (MetaDataClient client = metaDataClientFactory.getClient()) { SelectMultiQuery query = new SelectMultiQuery(); query.addQueries(eq(VitamFieldsHelper.initialOperation(), ingestOperationId)); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createObjectGroupScrollSplitIterator(client, query, VitamConfiguration.getBatchSize()); MultiValuedMap<String, String> updatedObjectGroupsByOpi = new ArrayListValuedHashMap<>(); scrollRequest.forEachRemaining(objectGroupNode -> { try { List<String> ops = JsonHandler .getFromJsonNode(objectGroupNode.get(VitamFieldsHelper.operations()), STRING_LIST_TYPE_REFERENCE); for (String op : ops) { if (!op.equals(ingestOperationId)) { String id = objectGroupNode.get(VitamFieldsHelper.id()).asText(); updatedObjectGroupsByOpi.put(op, id); } } } catch (InvalidParseOperationException e) { throw new RuntimeException(e); } }); if (!updatedObjectGroupsByOpi.isEmpty()) { Set<String> ingestOperations = checkIngestOperations(updatedObjectGroupsByOpi.keySet()); Set<String> nonIngestOperations = SetUtils.difference(updatedObjectGroupsByOpi.keySet(), ingestOperations); for (String nonIngestOperation : nonIngestOperations) { for (String objectGroupId : updatedObjectGroupsByOpi.get(nonIngestOperation)) { cleanupReportManager.reportObjectGroupWarning(objectGroupId, "Updates occurred to object group by operation " + nonIngestOperations); } } for (String nonIngestOperation : ingestOperations) { for (String objectGroupId : updatedObjectGroupsByOpi.get(nonIngestOperation)) { cleanupReportManager.reportObjectGroupError(objectGroupId, "Updates occurred to object group by ingest operation " + nonIngestOperations); } } } } catch (InvalidCreateOperationException | InvalidParseOperationException | LogbookClientException e) { throw new ProcessingStatusException(StatusCode.FATAL, "Could not checks updated object groups", e); } } }
IngestCleanupEligibilityService { public void checkObjectGroupUpdatesFromOtherOperations(String ingestOperationId, CleanupReportManager cleanupReportManager) throws ProcessingStatusException { try (MetaDataClient client = metaDataClientFactory.getClient()) { SelectMultiQuery query = new SelectMultiQuery(); query.addQueries(eq(VitamFieldsHelper.initialOperation(), ingestOperationId)); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createObjectGroupScrollSplitIterator(client, query, VitamConfiguration.getBatchSize()); MultiValuedMap<String, String> updatedObjectGroupsByOpi = new ArrayListValuedHashMap<>(); scrollRequest.forEachRemaining(objectGroupNode -> { try { List<String> ops = JsonHandler .getFromJsonNode(objectGroupNode.get(VitamFieldsHelper.operations()), STRING_LIST_TYPE_REFERENCE); for (String op : ops) { if (!op.equals(ingestOperationId)) { String id = objectGroupNode.get(VitamFieldsHelper.id()).asText(); updatedObjectGroupsByOpi.put(op, id); } } } catch (InvalidParseOperationException e) { throw new RuntimeException(e); } }); if (!updatedObjectGroupsByOpi.isEmpty()) { Set<String> ingestOperations = checkIngestOperations(updatedObjectGroupsByOpi.keySet()); Set<String> nonIngestOperations = SetUtils.difference(updatedObjectGroupsByOpi.keySet(), ingestOperations); for (String nonIngestOperation : nonIngestOperations) { for (String objectGroupId : updatedObjectGroupsByOpi.get(nonIngestOperation)) { cleanupReportManager.reportObjectGroupWarning(objectGroupId, "Updates occurred to object group by operation " + nonIngestOperations); } } for (String nonIngestOperation : ingestOperations) { for (String objectGroupId : updatedObjectGroupsByOpi.get(nonIngestOperation)) { cleanupReportManager.reportObjectGroupError(objectGroupId, "Updates occurred to object group by ingest operation " + nonIngestOperations); } } } } catch (InvalidCreateOperationException | InvalidParseOperationException | LogbookClientException e) { throw new ProcessingStatusException(StatusCode.FATAL, "Could not checks updated object groups", e); } } IngestCleanupEligibilityService(MetaDataClientFactory metaDataClientFactory,
        LogbookOperationsClientFactory logbookOperationsClientFactory); }
IngestCleanupEligibilityService { public void checkObjectGroupUpdatesFromOtherOperations(String ingestOperationId, CleanupReportManager cleanupReportManager) throws ProcessingStatusException { try (MetaDataClient client = metaDataClientFactory.getClient()) { SelectMultiQuery query = new SelectMultiQuery(); query.addQueries(eq(VitamFieldsHelper.initialOperation(), ingestOperationId)); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createObjectGroupScrollSplitIterator(client, query, VitamConfiguration.getBatchSize()); MultiValuedMap<String, String> updatedObjectGroupsByOpi = new ArrayListValuedHashMap<>(); scrollRequest.forEachRemaining(objectGroupNode -> { try { List<String> ops = JsonHandler .getFromJsonNode(objectGroupNode.get(VitamFieldsHelper.operations()), STRING_LIST_TYPE_REFERENCE); for (String op : ops) { if (!op.equals(ingestOperationId)) { String id = objectGroupNode.get(VitamFieldsHelper.id()).asText(); updatedObjectGroupsByOpi.put(op, id); } } } catch (InvalidParseOperationException e) { throw new RuntimeException(e); } }); if (!updatedObjectGroupsByOpi.isEmpty()) { Set<String> ingestOperations = checkIngestOperations(updatedObjectGroupsByOpi.keySet()); Set<String> nonIngestOperations = SetUtils.difference(updatedObjectGroupsByOpi.keySet(), ingestOperations); for (String nonIngestOperation : nonIngestOperations) { for (String objectGroupId : updatedObjectGroupsByOpi.get(nonIngestOperation)) { cleanupReportManager.reportObjectGroupWarning(objectGroupId, "Updates occurred to object group by operation " + nonIngestOperations); } } for (String nonIngestOperation : ingestOperations) { for (String objectGroupId : updatedObjectGroupsByOpi.get(nonIngestOperation)) { cleanupReportManager.reportObjectGroupError(objectGroupId, "Updates occurred to object group by ingest operation " + nonIngestOperations); } } } } catch (InvalidCreateOperationException | InvalidParseOperationException | LogbookClientException e) { throw new ProcessingStatusException(StatusCode.FATAL, "Could not checks updated object groups", 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 checkObjectGroupUpdatesFromOtherOperations(String ingestOperationId, CleanupReportManager cleanupReportManager) throws ProcessingStatusException { try (MetaDataClient client = metaDataClientFactory.getClient()) { SelectMultiQuery query = new SelectMultiQuery(); query.addQueries(eq(VitamFieldsHelper.initialOperation(), ingestOperationId)); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createObjectGroupScrollSplitIterator(client, query, VitamConfiguration.getBatchSize()); MultiValuedMap<String, String> updatedObjectGroupsByOpi = new ArrayListValuedHashMap<>(); scrollRequest.forEachRemaining(objectGroupNode -> { try { List<String> ops = JsonHandler .getFromJsonNode(objectGroupNode.get(VitamFieldsHelper.operations()), STRING_LIST_TYPE_REFERENCE); for (String op : ops) { if (!op.equals(ingestOperationId)) { String id = objectGroupNode.get(VitamFieldsHelper.id()).asText(); updatedObjectGroupsByOpi.put(op, id); } } } catch (InvalidParseOperationException e) { throw new RuntimeException(e); } }); if (!updatedObjectGroupsByOpi.isEmpty()) { Set<String> ingestOperations = checkIngestOperations(updatedObjectGroupsByOpi.keySet()); Set<String> nonIngestOperations = SetUtils.difference(updatedObjectGroupsByOpi.keySet(), ingestOperations); for (String nonIngestOperation : nonIngestOperations) { for (String objectGroupId : updatedObjectGroupsByOpi.get(nonIngestOperation)) { cleanupReportManager.reportObjectGroupWarning(objectGroupId, "Updates occurred to object group by operation " + nonIngestOperations); } } for (String nonIngestOperation : ingestOperations) { for (String objectGroupId : updatedObjectGroupsByOpi.get(nonIngestOperation)) { cleanupReportManager.reportObjectGroupError(objectGroupId, "Updates occurred to object group by ingest operation " + nonIngestOperations); } } } } catch (InvalidCreateOperationException | InvalidParseOperationException | LogbookClientException e) { throw new ProcessingStatusException(StatusCode.FATAL, "Could not checks updated object groups", 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);  }