@Test public void should_generate_vitamResults() throws InvalidParseOperationException { populateDatabase(auditReportEntryKO, auditReportEntryOK, auditReportEntryWARNING); ReportResults reportResult = repository.computeVitamResults(processId, TENANT_ID); assertThat(reportResult.getNbOk()).isEqualTo(1); assertThat(reportResult.getNbWarning()).isEqualTo(1); assertThat(reportResult.getNbKo()).isEqualTo(1); }
public ReportResults computeVitamResults(String processId, Integer tenantId) { ReportResults reportResult = new ReportResults(0,0,0,0); Bson eqProcessId = eq(AuditObjectGroupModel.PROCESS_ID, processId); Bson eqTenant = eq(AuditObjectGroupModel.TENANT, tenantId); Bson groupOnSp = group("$_metadata.status", sum("result", 1)); MongoCursor<Document> objectGroupsStatusCountResult = getListStats(Aggregates.match(and(eqProcessId, eqTenant)), groupOnSp); while (objectGroupsStatusCountResult.hasNext()) { Document result = objectGroupsStatusCountResult.next(); String status = result.getString("_id"); Integer count = result.getInteger("result"); switch (status) { case "OK": reportResult.setNbOk(count); break; case "WARNING": reportResult.setNbWarning(count); break; case "KO": reportResult.setNbKo(count); break; default: break; } } reportResult.setTotal(reportResult.getNbKo() + reportResult.getNbOk() + reportResult.getNbWarning()); return reportResult; }
AuditReportRepository extends ReportCommonRepository { public ReportResults computeVitamResults(String processId, Integer tenantId) { ReportResults reportResult = new ReportResults(0,0,0,0); Bson eqProcessId = eq(AuditObjectGroupModel.PROCESS_ID, processId); Bson eqTenant = eq(AuditObjectGroupModel.TENANT, tenantId); Bson groupOnSp = group("$_metadata.status", sum("result", 1)); MongoCursor<Document> objectGroupsStatusCountResult = getListStats(Aggregates.match(and(eqProcessId, eqTenant)), groupOnSp); while (objectGroupsStatusCountResult.hasNext()) { Document result = objectGroupsStatusCountResult.next(); String status = result.getString("_id"); Integer count = result.getInteger("result"); switch (status) { case "OK": reportResult.setNbOk(count); break; case "WARNING": reportResult.setNbWarning(count); break; case "KO": reportResult.setNbKo(count); break; default: break; } } reportResult.setTotal(reportResult.getNbKo() + reportResult.getNbOk() + reportResult.getNbWarning()); return reportResult; } }
AuditReportRepository extends ReportCommonRepository { public ReportResults computeVitamResults(String processId, Integer tenantId) { ReportResults reportResult = new ReportResults(0,0,0,0); Bson eqProcessId = eq(AuditObjectGroupModel.PROCESS_ID, processId); Bson eqTenant = eq(AuditObjectGroupModel.TENANT, tenantId); Bson groupOnSp = group("$_metadata.status", sum("result", 1)); MongoCursor<Document> objectGroupsStatusCountResult = getListStats(Aggregates.match(and(eqProcessId, eqTenant)), groupOnSp); while (objectGroupsStatusCountResult.hasNext()) { Document result = objectGroupsStatusCountResult.next(); String status = result.getString("_id"); Integer count = result.getInteger("result"); switch (status) { case "OK": reportResult.setNbOk(count); break; case "WARNING": reportResult.setNbWarning(count); break; case "KO": reportResult.setNbKo(count); break; default: break; } } reportResult.setTotal(reportResult.getNbKo() + reportResult.getNbOk() + reportResult.getNbWarning()); return reportResult; } @VisibleForTesting  AuditReportRepository(MongoDbAccess mongoDbAccess, String collectionName);  AuditReportRepository(MongoDbAccess mongoDbAccess); }
AuditReportRepository extends ReportCommonRepository { public ReportResults computeVitamResults(String processId, Integer tenantId) { ReportResults reportResult = new ReportResults(0,0,0,0); Bson eqProcessId = eq(AuditObjectGroupModel.PROCESS_ID, processId); Bson eqTenant = eq(AuditObjectGroupModel.TENANT, tenantId); Bson groupOnSp = group("$_metadata.status", sum("result", 1)); MongoCursor<Document> objectGroupsStatusCountResult = getListStats(Aggregates.match(and(eqProcessId, eqTenant)), groupOnSp); while (objectGroupsStatusCountResult.hasNext()) { Document result = objectGroupsStatusCountResult.next(); String status = result.getString("_id"); Integer count = result.getInteger("result"); switch (status) { case "OK": reportResult.setNbOk(count); break; case "WARNING": reportResult.setNbWarning(count); break; case "KO": reportResult.setNbKo(count); break; default: break; } } reportResult.setTotal(reportResult.getNbKo() + reportResult.getNbOk() + reportResult.getNbWarning()); return reportResult; } @VisibleForTesting  AuditReportRepository(MongoDbAccess mongoDbAccess, String collectionName);  AuditReportRepository(MongoDbAccess mongoDbAccess); void bulkAppendReport(List<AuditObjectGroupModel> reports); void deleteReportByIdAndTenant(String processId, int tenantId); ReportResults computeVitamResults(String processId, Integer tenantId); MongoCursor<Document> findCollectionByProcessIdTenantAndStatus(String processId, int tenantId,
            String... status); MongoCursor<Document> findCollectionByProcessIdTenant(String processId, int tenantId); AuditStatsModel stats(String processId, int tenantId); }
AuditReportRepository extends ReportCommonRepository { public ReportResults computeVitamResults(String processId, Integer tenantId) { ReportResults reportResult = new ReportResults(0,0,0,0); Bson eqProcessId = eq(AuditObjectGroupModel.PROCESS_ID, processId); Bson eqTenant = eq(AuditObjectGroupModel.TENANT, tenantId); Bson groupOnSp = group("$_metadata.status", sum("result", 1)); MongoCursor<Document> objectGroupsStatusCountResult = getListStats(Aggregates.match(and(eqProcessId, eqTenant)), groupOnSp); while (objectGroupsStatusCountResult.hasNext()) { Document result = objectGroupsStatusCountResult.next(); String status = result.getString("_id"); Integer count = result.getInteger("result"); switch (status) { case "OK": reportResult.setNbOk(count); break; case "WARNING": reportResult.setNbWarning(count); break; case "KO": reportResult.setNbKo(count); break; default: break; } } reportResult.setTotal(reportResult.getNbKo() + reportResult.getNbOk() + reportResult.getNbWarning()); return reportResult; } @VisibleForTesting  AuditReportRepository(MongoDbAccess mongoDbAccess, String collectionName);  AuditReportRepository(MongoDbAccess mongoDbAccess); void bulkAppendReport(List<AuditObjectGroupModel> reports); void deleteReportByIdAndTenant(String processId, int tenantId); ReportResults computeVitamResults(String processId, Integer tenantId); MongoCursor<Document> findCollectionByProcessIdTenantAndStatus(String processId, int tenantId,
            String... status); MongoCursor<Document> findCollectionByProcessIdTenant(String processId, int tenantId); AuditStatsModel stats(String processId, int tenantId); static final String AUDIT_OBJECT_GROUP; }