@Test public void givenChildUnitsThenCheckChildUnitsFromOtherIngestsReturnsKO() throws Exception { JsonNode unitIds = new RequestResponseOK<JsonNode>().addAllResults(Arrays.asList( JsonHandler.createObjectNode().put(VitamFieldsHelper.id(), "unit1"), JsonHandler.createObjectNode().put(VitamFieldsHelper.id(), "unit2"), JsonHandler.createObjectNode().put(VitamFieldsHelper.id(), "unit3") )).toJsonNode(); JsonNode childUnits1 = new RequestResponseOK<JsonNode>().addAllResults(Collections.singletonList( JsonHandler.createObjectNode().set(VitamFieldsHelper.unitups(), JsonHandler.createArrayNode().add("unit2")) )).toJsonNode(); JsonNode childUnits2 = new RequestResponseOK<JsonNode>().toJsonNode(); when(metaDataClient.selectUnits(any())) .thenReturn(unitIds) .thenReturn(childUnits1) .thenReturn(childUnits2); CleanupReportManager cleanupReportManager = CleanupReportManager.newReport(INGEST_OPERATION_ID); instance.checkChildUnitsFromOtherIngests(INGEST_OPERATION_ID, cleanupReportManager); assertThat(cleanupReportManager.getGlobalStatus()).isEqualTo(StatusCode.KO); assertThat(cleanupReportManager.getCleanupReport().getUnits()).containsOnlyKeys("unit2"); assertThat(cleanupReportManager.getCleanupReport().getUnits().get("unit2").getErrors()).isNotEmpty(); assertThat(cleanupReportManager.getCleanupReport().getUnits().get("unit2").getWarnings()).isNull(); ArgumentCaptor<JsonNode> queryCaptor = ArgumentCaptor.forClass(JsonNode.class); verify(metaDataClient, times(3)).selectUnits(queryCaptor.capture()); checkQueryEquals(queryCaptor.getAllValues().get(0), "IngestCleanup/Eligibility/selectUnitIdsQuery.json"); checkQueryEquals(queryCaptor.getAllValues().get(1), "IngestCleanup/Eligibility/selectChildUnitsQuery.json"); checkQueryEquals(queryCaptor.getAllValues().get(2), "IngestCleanup/Eligibility/selectChildUnitsQueryRemaining.json"); }
public void checkChildUnitsFromOtherIngests(String ingestOperationId, CleanupReportManager cleanupReportManager) throws ProcessingStatusException { try (MetaDataClient client = metaDataClientFactory.getClient()) { SelectMultiQuery query = new SelectMultiQuery(); query.addUsedProjection(VitamFieldsHelper.id()); query.addQueries(eq(VitamFieldsHelper.initialOperation(), ingestOperationId)); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createUnitScrollSplitIterator(client, query, VitamConfiguration.getBatchSize()); try (BufferedConsumer<String> bufferedConsumer = new BufferedConsumer<>(VitamConfiguration.getBatchSize(), ids -> checkChildUnitsFromOtherIngests(ingestOperationId, cleanupReportManager, ids))) { scrollRequest.forEachRemaining( entry -> bufferedConsumer.appendEntry(entry.get(VitamFieldsHelper.id()).asText())); } } catch (InvalidParseOperationException | InvalidCreateOperationException e) { throw new ProcessingStatusException(StatusCode.FATAL, "Could not checks unit updates", e); } }
IngestCleanupEligibilityService { public void checkChildUnitsFromOtherIngests(String ingestOperationId, CleanupReportManager cleanupReportManager) throws ProcessingStatusException { try (MetaDataClient client = metaDataClientFactory.getClient()) { SelectMultiQuery query = new SelectMultiQuery(); query.addUsedProjection(VitamFieldsHelper.id()); query.addQueries(eq(VitamFieldsHelper.initialOperation(), ingestOperationId)); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createUnitScrollSplitIterator(client, query, VitamConfiguration.getBatchSize()); try (BufferedConsumer<String> bufferedConsumer = new BufferedConsumer<>(VitamConfiguration.getBatchSize(), ids -> checkChildUnitsFromOtherIngests(ingestOperationId, cleanupReportManager, ids))) { scrollRequest.forEachRemaining( entry -> bufferedConsumer.appendEntry(entry.get(VitamFieldsHelper.id()).asText())); } } catch (InvalidParseOperationException | InvalidCreateOperationException e) { throw new ProcessingStatusException(StatusCode.FATAL, "Could not checks unit updates", e); } } }
IngestCleanupEligibilityService { public void checkChildUnitsFromOtherIngests(String ingestOperationId, CleanupReportManager cleanupReportManager) throws ProcessingStatusException { try (MetaDataClient client = metaDataClientFactory.getClient()) { SelectMultiQuery query = new SelectMultiQuery(); query.addUsedProjection(VitamFieldsHelper.id()); query.addQueries(eq(VitamFieldsHelper.initialOperation(), ingestOperationId)); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createUnitScrollSplitIterator(client, query, VitamConfiguration.getBatchSize()); try (BufferedConsumer<String> bufferedConsumer = new BufferedConsumer<>(VitamConfiguration.getBatchSize(), ids -> checkChildUnitsFromOtherIngests(ingestOperationId, cleanupReportManager, ids))) { scrollRequest.forEachRemaining( entry -> bufferedConsumer.appendEntry(entry.get(VitamFieldsHelper.id()).asText())); } } catch (InvalidParseOperationException | InvalidCreateOperationException e) { throw new ProcessingStatusException(StatusCode.FATAL, "Could not checks unit updates", e); } } IngestCleanupEligibilityService(MetaDataClientFactory metaDataClientFactory,
        LogbookOperationsClientFactory logbookOperationsClientFactory); }
IngestCleanupEligibilityService { public void checkChildUnitsFromOtherIngests(String ingestOperationId, CleanupReportManager cleanupReportManager) throws ProcessingStatusException { try (MetaDataClient client = metaDataClientFactory.getClient()) { SelectMultiQuery query = new SelectMultiQuery(); query.addUsedProjection(VitamFieldsHelper.id()); query.addQueries(eq(VitamFieldsHelper.initialOperation(), ingestOperationId)); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createUnitScrollSplitIterator(client, query, VitamConfiguration.getBatchSize()); try (BufferedConsumer<String> bufferedConsumer = new BufferedConsumer<>(VitamConfiguration.getBatchSize(), ids -> checkChildUnitsFromOtherIngests(ingestOperationId, cleanupReportManager, ids))) { scrollRequest.forEachRemaining( entry -> bufferedConsumer.appendEntry(entry.get(VitamFieldsHelper.id()).asText())); } } catch (InvalidParseOperationException | InvalidCreateOperationException e) { throw new ProcessingStatusException(StatusCode.FATAL, "Could not checks unit updates", 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 checkChildUnitsFromOtherIngests(String ingestOperationId, CleanupReportManager cleanupReportManager) throws ProcessingStatusException { try (MetaDataClient client = metaDataClientFactory.getClient()) { SelectMultiQuery query = new SelectMultiQuery(); query.addUsedProjection(VitamFieldsHelper.id()); query.addQueries(eq(VitamFieldsHelper.initialOperation(), ingestOperationId)); ScrollSpliterator<JsonNode> scrollRequest = ScrollSpliteratorHelper .createUnitScrollSplitIterator(client, query, VitamConfiguration.getBatchSize()); try (BufferedConsumer<String> bufferedConsumer = new BufferedConsumer<>(VitamConfiguration.getBatchSize(), ids -> checkChildUnitsFromOtherIngests(ingestOperationId, cleanupReportManager, ids))) { scrollRequest.forEachRemaining( entry -> bufferedConsumer.appendEntry(entry.get(VitamFieldsHelper.id()).asText())); } } catch (InvalidParseOperationException | InvalidCreateOperationException e) { throw new ProcessingStatusException(StatusCode.FATAL, "Could not checks unit updates", 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);  }