@Test public void givenAttachmentsThenCheckObjectAttachmentsToExistingObjectGroupsKO() throws Exception { JsonNode objectGroups = new RequestResponseOK<JsonNode>().addAllResults(Collections.singletonList( JsonHandler.createObjectNode().put(VitamFieldsHelper.id(), "og_updated_1") )).toJsonNode(); when(metaDataClient.selectObjectGroups(any())).thenReturn(objectGroups); CleanupReportManager cleanupReportManager = CleanupReportManager.newReport(INGEST_OPERATION_ID); instance.checkObjectAttachmentsToExistingObjectGroups(INGEST_OPERATION_ID, cleanupReportManager); assertThat(cleanupReportManager.getGlobalStatus()).isEqualTo(StatusCode.KO); assertThat(cleanupReportManager.getCleanupReport().getObjectGroups()).containsOnlyKeys("og_updated_1"); assertThat(cleanupReportManager.getCleanupReport().getObjectGroups().get("og_updated_1").getErrors()).isNotEmpty(); assertThat(cleanupReportManager.getCleanupReport().getObjectGroups().get("og_updated_1").getWarnings()).isNull(); ArgumentCaptor<JsonNode> queryCaptor = ArgumentCaptor.forClass(JsonNode.class); verify(metaDataClient, times(1)).selectObjectGroups(queryCaptor.capture()); checkQueryEquals(queryCaptor.getAllValues().get(0), "IngestCleanup/Eligibility/selectAttachmentToObjectGroupsQuery.json"); }
public void checkObjectAttachmentsToExistingObjectGroups(String ingestOperationId, CleanupReportManager cleanupReportManager) throws ProcessingStatusException { try (MetaDataClient client = metaDataClientFactory.getClient()) { SelectMultiQuery query = new SelectMultiQuery(); query.addUsedProjection(VitamFieldsHelper.id()); query.addQueries(and().add( ne(VitamFieldsHelper.initialOperation(), ingestOperationId), eq(VitamFieldsHelper.operations(), ingestOperationId) )); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createObjectGroupScrollSplitIterator(client, query, VitamConfiguration.getBatchSize()); scrollRequest.forEachRemaining(objectGroup -> { String objectGroupId = objectGroup.get("#id").asText(); cleanupReportManager.reportObjectGroupError(objectGroupId, "Existing object group updated by ingest operation " + ingestOperationId); }); } catch (InvalidParseOperationException | InvalidCreateOperationException e) { throw new ProcessingStatusException(StatusCode.FATAL, "Could not list attachment to existing object groups", e); } }
IngestCleanupEligibilityService { public void checkObjectAttachmentsToExistingObjectGroups(String ingestOperationId, CleanupReportManager cleanupReportManager) throws ProcessingStatusException { try (MetaDataClient client = metaDataClientFactory.getClient()) { SelectMultiQuery query = new SelectMultiQuery(); query.addUsedProjection(VitamFieldsHelper.id()); query.addQueries(and().add( ne(VitamFieldsHelper.initialOperation(), ingestOperationId), eq(VitamFieldsHelper.operations(), ingestOperationId) )); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createObjectGroupScrollSplitIterator(client, query, VitamConfiguration.getBatchSize()); scrollRequest.forEachRemaining(objectGroup -> { String objectGroupId = objectGroup.get("#id").asText(); cleanupReportManager.reportObjectGroupError(objectGroupId, "Existing object group updated by ingest operation " + ingestOperationId); }); } catch (InvalidParseOperationException | InvalidCreateOperationException e) { throw new ProcessingStatusException(StatusCode.FATAL, "Could not list attachment to existing object groups", e); } } }
IngestCleanupEligibilityService { public void checkObjectAttachmentsToExistingObjectGroups(String ingestOperationId, CleanupReportManager cleanupReportManager) throws ProcessingStatusException { try (MetaDataClient client = metaDataClientFactory.getClient()) { SelectMultiQuery query = new SelectMultiQuery(); query.addUsedProjection(VitamFieldsHelper.id()); query.addQueries(and().add( ne(VitamFieldsHelper.initialOperation(), ingestOperationId), eq(VitamFieldsHelper.operations(), ingestOperationId) )); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createObjectGroupScrollSplitIterator(client, query, VitamConfiguration.getBatchSize()); scrollRequest.forEachRemaining(objectGroup -> { String objectGroupId = objectGroup.get("#id").asText(); cleanupReportManager.reportObjectGroupError(objectGroupId, "Existing object group updated by ingest operation " + ingestOperationId); }); } catch (InvalidParseOperationException | InvalidCreateOperationException e) { throw new ProcessingStatusException(StatusCode.FATAL, "Could not list attachment to existing object groups", e); } } IngestCleanupEligibilityService(MetaDataClientFactory metaDataClientFactory,
        LogbookOperationsClientFactory logbookOperationsClientFactory); }
IngestCleanupEligibilityService { public void checkObjectAttachmentsToExistingObjectGroups(String ingestOperationId, CleanupReportManager cleanupReportManager) throws ProcessingStatusException { try (MetaDataClient client = metaDataClientFactory.getClient()) { SelectMultiQuery query = new SelectMultiQuery(); query.addUsedProjection(VitamFieldsHelper.id()); query.addQueries(and().add( ne(VitamFieldsHelper.initialOperation(), ingestOperationId), eq(VitamFieldsHelper.operations(), ingestOperationId) )); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createObjectGroupScrollSplitIterator(client, query, VitamConfiguration.getBatchSize()); scrollRequest.forEachRemaining(objectGroup -> { String objectGroupId = objectGroup.get("#id").asText(); cleanupReportManager.reportObjectGroupError(objectGroupId, "Existing object group updated by ingest operation " + ingestOperationId); }); } catch (InvalidParseOperationException | InvalidCreateOperationException e) { throw new ProcessingStatusException(StatusCode.FATAL, "Could not list attachment to existing 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 checkObjectAttachmentsToExistingObjectGroups(String ingestOperationId, CleanupReportManager cleanupReportManager) throws ProcessingStatusException { try (MetaDataClient client = metaDataClientFactory.getClient()) { SelectMultiQuery query = new SelectMultiQuery(); query.addUsedProjection(VitamFieldsHelper.id()); query.addQueries(and().add( ne(VitamFieldsHelper.initialOperation(), ingestOperationId), eq(VitamFieldsHelper.operations(), ingestOperationId) )); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createObjectGroupScrollSplitIterator(client, query, VitamConfiguration.getBatchSize()); scrollRequest.forEachRemaining(objectGroup -> { String objectGroupId = objectGroup.get("#id").asText(); cleanupReportManager.reportObjectGroupError(objectGroupId, "Existing object group updated by ingest operation " + ingestOperationId); }); } catch (InvalidParseOperationException | InvalidCreateOperationException e) { throw new ProcessingStatusException(StatusCode.FATAL, "Could not list attachment to existing 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);  }