@Test public void should_bulk_append_unit_report_and_check_metadata_id_unicity() throws Exception { List<EliminationActionUnitModel> eliminationActionUnitModels = getDocuments("/eliminationUnitModel.json"); repository.bulkAppendReport(eliminationActionUnitModels); Document first = eliminationUnitCollection.find(and(eq(EliminationActionUnitModel.METADATA + "." + "id", "unitId1"), eq(EliminationActionUnitModel.TENANT, 0))).first(); assertThat(first).isNotNull() .containsEntry("processId", "123456789") .containsEntry("_tenant", 0) .containsKeys("_metadata"); Object metadata = first.get("_metadata"); JsonNode metadataNode = JsonHandler.toJsonNode(metadata); JsonNode expected = JsonHandler.getFromString( "{\"id\":\"unitId1\",\"originatingAgency\":\"sp1\",\"opi\":\"opi0\",\"objectGroupId\":\"id2\",\"status\":\"GLOBAL_STATUS_KEEP\"}"); assertThat(metadataNode).isNotNull().isEqualTo(expected); repository.bulkAppendReport(eliminationActionUnitModels); assertThat(eliminationUnitCollection.countDocuments()).isEqualTo(4); }
public void bulkAppendReport(List<EliminationActionUnitModel> reports) { Set<EliminationActionUnitModel> reportsWithoutDuplicate = new HashSet<>(reports); List<Document> eliminationUnitDocument = reportsWithoutDuplicate.stream() .map(ReportCommonRepository::pojoToDocument) .collect(Collectors.toList()); super.bulkAppendReport(eliminationUnitDocument, unitReportCollection); }
EliminationActionUnitRepository extends ReportCommonRepository { public void bulkAppendReport(List<EliminationActionUnitModel> reports) { Set<EliminationActionUnitModel> reportsWithoutDuplicate = new HashSet<>(reports); List<Document> eliminationUnitDocument = reportsWithoutDuplicate.stream() .map(ReportCommonRepository::pojoToDocument) .collect(Collectors.toList()); super.bulkAppendReport(eliminationUnitDocument, unitReportCollection); } }
EliminationActionUnitRepository extends ReportCommonRepository { public void bulkAppendReport(List<EliminationActionUnitModel> reports) { Set<EliminationActionUnitModel> reportsWithoutDuplicate = new HashSet<>(reports); List<Document> eliminationUnitDocument = reportsWithoutDuplicate.stream() .map(ReportCommonRepository::pojoToDocument) .collect(Collectors.toList()); super.bulkAppendReport(eliminationUnitDocument, unitReportCollection); } @VisibleForTesting  EliminationActionUnitRepository(MongoDbAccess mongoDbAccess, String collectionName);  EliminationActionUnitRepository(MongoDbAccess mongoDbAccess); }
EliminationActionUnitRepository extends ReportCommonRepository { public void bulkAppendReport(List<EliminationActionUnitModel> reports) { Set<EliminationActionUnitModel> reportsWithoutDuplicate = new HashSet<>(reports); List<Document> eliminationUnitDocument = reportsWithoutDuplicate.stream() .map(ReportCommonRepository::pojoToDocument) .collect(Collectors.toList()); super.bulkAppendReport(eliminationUnitDocument, unitReportCollection); } @VisibleForTesting  EliminationActionUnitRepository(MongoDbAccess mongoDbAccess, String collectionName);  EliminationActionUnitRepository(MongoDbAccess mongoDbAccess); void bulkAppendReport(List<EliminationActionUnitModel> reports); MongoCursor<Document> findCollectionByProcessIdTenant(String processId, int tenantId); void deleteReportByIdAndTenant(String processId, int tenantId); }
EliminationActionUnitRepository extends ReportCommonRepository { public void bulkAppendReport(List<EliminationActionUnitModel> reports) { Set<EliminationActionUnitModel> reportsWithoutDuplicate = new HashSet<>(reports); List<Document> eliminationUnitDocument = reportsWithoutDuplicate.stream() .map(ReportCommonRepository::pojoToDocument) .collect(Collectors.toList()); super.bulkAppendReport(eliminationUnitDocument, unitReportCollection); } @VisibleForTesting  EliminationActionUnitRepository(MongoDbAccess mongoDbAccess, String collectionName);  EliminationActionUnitRepository(MongoDbAccess mongoDbAccess); void bulkAppendReport(List<EliminationActionUnitModel> reports); MongoCursor<Document> findCollectionByProcessIdTenant(String processId, int tenantId); void deleteReportByIdAndTenant(String processId, int tenantId); static final String ELIMINATION_ACTION_UNIT; }