@Test public void should_generate_statistic() { populateDatabase(); PreservationStatsModel stats = repository.stats(processId, TENANT_ID); assertThat(stats.getNbObjectGroups()).isEqualTo(1); assertThat(stats.getNbUnits()).isEqualTo(2); assertThat(stats.getNbActionsExtract()).isEqualTo(0); assertThat(stats.getNbActionsGenerate()).isEqualTo(0); assertThat(stats.getNbActionsIdentify()).isEqualTo(0); assertThat(stats.getNbActionsAnalyse()).isEqualTo(2); assertThat(stats.getNbStatusKos()).isEqualTo(0); assertThat(stats.getAnalyseResults().get("VALID_ALL")).isEqualTo(2); }
public PreservationStatsModel stats(String processId, int tenantId) { Bson eqProcessId = eq(PROCESS_ID, processId); Bson eqTenant = eq(TENANT, tenantId); int nbUnits = getUnitAndObjectGroupStats(and(eqProcessId, eqTenant), UNIT_ID); int nbObjectGroups = getUnitAndObjectGroupStats(and(eqProcessId, eqTenant), OBJECT_GROUP_ID); int nbStatusKos = getStats(and(eqTenant, eqProcessId, eq(STATUS, KO.name())), STATUS); int nbStatusWarning = getStats(and(eqTenant, eqProcessId, eq(STATUS, WARNING.name())), STATUS); int nbActionsAnaylse = getStats(and(eqTenant, eqProcessId, eq(ACTION, ANALYSE.name())), ACTION); int nbActionsGenerate = getStats(and(eqTenant, eqProcessId, eq(ACTION, GENERATE.name())), ACTION); int nbActionsIdentify = getStats(and(eqTenant, eqProcessId, eq(ACTION, IDENTIFY.name())), ACTION); int nbActionsExtract = getStats(and(eqTenant, eqProcessId, eq(ACTION, EXTRACT.name())), ACTION); Spliterator<SimpleEntry<String, Integer>> mapAnalyseResult = nbActionsAnaylse > 0 ? collection.aggregate( Arrays.asList( match(and(eqTenant, eqProcessId)), project(include("analyseResult")), group("$" + ANALYSE_RESULT, sum("count", 1))) ).allowDiskUse(true) .batchSize(VitamConfiguration.getBatchSize()) .map(d -> new SimpleEntry<>(d.getString("_id"), d.get("count", Integer.class))) .spliterator() : Spliterators.emptySpliterator(); Map<String, Integer> analyseResults = StreamSupport.stream(mapAnalyseResult, false) .collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue)); return new PreservationStatsModel( nbUnits, nbObjectGroups, nbStatusKos, nbActionsAnaylse, nbActionsGenerate, nbActionsIdentify, nbActionsExtract, analyseResults, nbStatusWarning); }
PreservationReportRepository { public PreservationStatsModel stats(String processId, int tenantId) { Bson eqProcessId = eq(PROCESS_ID, processId); Bson eqTenant = eq(TENANT, tenantId); int nbUnits = getUnitAndObjectGroupStats(and(eqProcessId, eqTenant), UNIT_ID); int nbObjectGroups = getUnitAndObjectGroupStats(and(eqProcessId, eqTenant), OBJECT_GROUP_ID); int nbStatusKos = getStats(and(eqTenant, eqProcessId, eq(STATUS, KO.name())), STATUS); int nbStatusWarning = getStats(and(eqTenant, eqProcessId, eq(STATUS, WARNING.name())), STATUS); int nbActionsAnaylse = getStats(and(eqTenant, eqProcessId, eq(ACTION, ANALYSE.name())), ACTION); int nbActionsGenerate = getStats(and(eqTenant, eqProcessId, eq(ACTION, GENERATE.name())), ACTION); int nbActionsIdentify = getStats(and(eqTenant, eqProcessId, eq(ACTION, IDENTIFY.name())), ACTION); int nbActionsExtract = getStats(and(eqTenant, eqProcessId, eq(ACTION, EXTRACT.name())), ACTION); Spliterator<SimpleEntry<String, Integer>> mapAnalyseResult = nbActionsAnaylse > 0 ? collection.aggregate( Arrays.asList( match(and(eqTenant, eqProcessId)), project(include("analyseResult")), group("$" + ANALYSE_RESULT, sum("count", 1))) ).allowDiskUse(true) .batchSize(VitamConfiguration.getBatchSize()) .map(d -> new SimpleEntry<>(d.getString("_id"), d.get("count", Integer.class))) .spliterator() : Spliterators.emptySpliterator(); Map<String, Integer> analyseResults = StreamSupport.stream(mapAnalyseResult, false) .collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue)); return new PreservationStatsModel( nbUnits, nbObjectGroups, nbStatusKos, nbActionsAnaylse, nbActionsGenerate, nbActionsIdentify, nbActionsExtract, analyseResults, nbStatusWarning); } }
PreservationReportRepository { public PreservationStatsModel stats(String processId, int tenantId) { Bson eqProcessId = eq(PROCESS_ID, processId); Bson eqTenant = eq(TENANT, tenantId); int nbUnits = getUnitAndObjectGroupStats(and(eqProcessId, eqTenant), UNIT_ID); int nbObjectGroups = getUnitAndObjectGroupStats(and(eqProcessId, eqTenant), OBJECT_GROUP_ID); int nbStatusKos = getStats(and(eqTenant, eqProcessId, eq(STATUS, KO.name())), STATUS); int nbStatusWarning = getStats(and(eqTenant, eqProcessId, eq(STATUS, WARNING.name())), STATUS); int nbActionsAnaylse = getStats(and(eqTenant, eqProcessId, eq(ACTION, ANALYSE.name())), ACTION); int nbActionsGenerate = getStats(and(eqTenant, eqProcessId, eq(ACTION, GENERATE.name())), ACTION); int nbActionsIdentify = getStats(and(eqTenant, eqProcessId, eq(ACTION, IDENTIFY.name())), ACTION); int nbActionsExtract = getStats(and(eqTenant, eqProcessId, eq(ACTION, EXTRACT.name())), ACTION); Spliterator<SimpleEntry<String, Integer>> mapAnalyseResult = nbActionsAnaylse > 0 ? collection.aggregate( Arrays.asList( match(and(eqTenant, eqProcessId)), project(include("analyseResult")), group("$" + ANALYSE_RESULT, sum("count", 1))) ).allowDiskUse(true) .batchSize(VitamConfiguration.getBatchSize()) .map(d -> new SimpleEntry<>(d.getString("_id"), d.get("count", Integer.class))) .spliterator() : Spliterators.emptySpliterator(); Map<String, Integer> analyseResults = StreamSupport.stream(mapAnalyseResult, false) .collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue)); return new PreservationStatsModel( nbUnits, nbObjectGroups, nbStatusKos, nbActionsAnaylse, nbActionsGenerate, nbActionsIdentify, nbActionsExtract, analyseResults, nbStatusWarning); } @VisibleForTesting  PreservationReportRepository(MongoDbAccess mongoDbAccess, String collectionName);  PreservationReportRepository(MongoDbAccess mongoDbAccess); }
PreservationReportRepository { public PreservationStatsModel stats(String processId, int tenantId) { Bson eqProcessId = eq(PROCESS_ID, processId); Bson eqTenant = eq(TENANT, tenantId); int nbUnits = getUnitAndObjectGroupStats(and(eqProcessId, eqTenant), UNIT_ID); int nbObjectGroups = getUnitAndObjectGroupStats(and(eqProcessId, eqTenant), OBJECT_GROUP_ID); int nbStatusKos = getStats(and(eqTenant, eqProcessId, eq(STATUS, KO.name())), STATUS); int nbStatusWarning = getStats(and(eqTenant, eqProcessId, eq(STATUS, WARNING.name())), STATUS); int nbActionsAnaylse = getStats(and(eqTenant, eqProcessId, eq(ACTION, ANALYSE.name())), ACTION); int nbActionsGenerate = getStats(and(eqTenant, eqProcessId, eq(ACTION, GENERATE.name())), ACTION); int nbActionsIdentify = getStats(and(eqTenant, eqProcessId, eq(ACTION, IDENTIFY.name())), ACTION); int nbActionsExtract = getStats(and(eqTenant, eqProcessId, eq(ACTION, EXTRACT.name())), ACTION); Spliterator<SimpleEntry<String, Integer>> mapAnalyseResult = nbActionsAnaylse > 0 ? collection.aggregate( Arrays.asList( match(and(eqTenant, eqProcessId)), project(include("analyseResult")), group("$" + ANALYSE_RESULT, sum("count", 1))) ).allowDiskUse(true) .batchSize(VitamConfiguration.getBatchSize()) .map(d -> new SimpleEntry<>(d.getString("_id"), d.get("count", Integer.class))) .spliterator() : Spliterators.emptySpliterator(); Map<String, Integer> analyseResults = StreamSupport.stream(mapAnalyseResult, false) .collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue)); return new PreservationStatsModel( nbUnits, nbObjectGroups, nbStatusKos, nbActionsAnaylse, nbActionsGenerate, nbActionsIdentify, nbActionsExtract, analyseResults, nbStatusWarning); } @VisibleForTesting  PreservationReportRepository(MongoDbAccess mongoDbAccess, String collectionName);  PreservationReportRepository(MongoDbAccess mongoDbAccess); void bulkAppendReport(List<PreservationReportEntry> reports); MongoCursor<Document> findCollectionByProcessIdTenant(String processId, int tenantId); PreservationStatsModel stats(String processId, int tenantId); void deleteReportByIdAndTenant(String processId, int tenantId); }
PreservationReportRepository { public PreservationStatsModel stats(String processId, int tenantId) { Bson eqProcessId = eq(PROCESS_ID, processId); Bson eqTenant = eq(TENANT, tenantId); int nbUnits = getUnitAndObjectGroupStats(and(eqProcessId, eqTenant), UNIT_ID); int nbObjectGroups = getUnitAndObjectGroupStats(and(eqProcessId, eqTenant), OBJECT_GROUP_ID); int nbStatusKos = getStats(and(eqTenant, eqProcessId, eq(STATUS, KO.name())), STATUS); int nbStatusWarning = getStats(and(eqTenant, eqProcessId, eq(STATUS, WARNING.name())), STATUS); int nbActionsAnaylse = getStats(and(eqTenant, eqProcessId, eq(ACTION, ANALYSE.name())), ACTION); int nbActionsGenerate = getStats(and(eqTenant, eqProcessId, eq(ACTION, GENERATE.name())), ACTION); int nbActionsIdentify = getStats(and(eqTenant, eqProcessId, eq(ACTION, IDENTIFY.name())), ACTION); int nbActionsExtract = getStats(and(eqTenant, eqProcessId, eq(ACTION, EXTRACT.name())), ACTION); Spliterator<SimpleEntry<String, Integer>> mapAnalyseResult = nbActionsAnaylse > 0 ? collection.aggregate( Arrays.asList( match(and(eqTenant, eqProcessId)), project(include("analyseResult")), group("$" + ANALYSE_RESULT, sum("count", 1))) ).allowDiskUse(true) .batchSize(VitamConfiguration.getBatchSize()) .map(d -> new SimpleEntry<>(d.getString("_id"), d.get("count", Integer.class))) .spliterator() : Spliterators.emptySpliterator(); Map<String, Integer> analyseResults = StreamSupport.stream(mapAnalyseResult, false) .collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue)); return new PreservationStatsModel( nbUnits, nbObjectGroups, nbStatusKos, nbActionsAnaylse, nbActionsGenerate, nbActionsIdentify, nbActionsExtract, analyseResults, nbStatusWarning); } @VisibleForTesting  PreservationReportRepository(MongoDbAccess mongoDbAccess, String collectionName);  PreservationReportRepository(MongoDbAccess mongoDbAccess); void bulkAppendReport(List<PreservationReportEntry> reports); MongoCursor<Document> findCollectionByProcessIdTenant(String processId, int tenantId); PreservationStatsModel stats(String processId, int tenantId); void deleteReportByIdAndTenant(String processId, int tenantId); static final String PRESERVATION_REPORT; }