@Test @RunWithCustomExecutor public void givenGriffinsInDataBaseShouldCollectInsertUpdateAndDeleteList() throws Exception { List<GriffinModel> allGriffinInDatabase = new ArrayList<>(); String modelString1 = "{\"#id\":\"Id1\",\"Name\":\"1\",\"Identifier\":\"IDENTIFIER1\"}"; String modelString2 = "{\"#id\":\"Id2\",\"Name\":\"2\",\"Identifier\":\"IDENTIFIER2\"}"; String modelString3 = "{\"#id\":\"Id3\",\"Name\":\"3\",\"Identifier\":\"IDENTIFIER3\"}"; allGriffinInDatabase.add(getFromString(modelString2, GriffinModel.class)); allGriffinInDatabase.add(getFromString(modelString3, GriffinModel.class)); List<GriffinModel> listToImport = new ArrayList<>(); listToImport.add(getFromString(modelString1, GriffinModel.class)); listToImport.add(getFromString(modelString2, GriffinModel.class)); List<GriffinModel> listToInsert = new ArrayList<>(); List<GriffinModel> listToUpdate = new ArrayList<>(); Set<String> listToDelete = new HashSet<>(); DbRequestResult dbRequestResult = mock(DbRequestResult.class); when(dbRequestResult.getDocuments(Griffin.class, GriffinModel.class)).thenReturn(allGriffinInDatabase); when(mongoDbAccess.findDocuments(any(JsonNode.class), eq(GRIFFIN))).thenReturn(dbRequestResult); griffinService.classifyDataInInsertUpdateOrDeleteLists(listToImport, listToInsert, listToUpdate, listToDelete, allGriffinInDatabase); assertThat(listToDelete.size()).isEqualTo(1); assertThat(listToInsert.size()).isEqualTo(1); assertThat(listToUpdate.size()).isEqualTo(1); }
void classifyDataInInsertUpdateOrDeleteLists(@NotNull List<GriffinModel> listToImport, @NotNull List<GriffinModel> listToInsert, @NotNull List<GriffinModel> listToUpdate, @NotNull Set<String> listToDelete, List<GriffinModel> allGriffinInDatabase) { Set<String> dataBaseIds = allGriffinInDatabase.stream().map( GriffinModel::getIdentifier).collect(toSet()); final HashSet<String> updateIds = new HashSet<>(dataBaseIds); final Set<String> importIds = listToImport.stream().map(GriffinModel::getIdentifier).collect(toSet()); updateIds.retainAll(importIds); final HashSet<String> removeIds = new HashSet<>(dataBaseIds); removeIds.removeAll(updateIds); listToDelete.addAll(removeIds); for (GriffinModel griffinModel : listToImport) { classifyModelToImportIntoInsertOrUpdateList(griffinModel, dataBaseIds, listToInsert, listToUpdate); } }
GriffinService { void classifyDataInInsertUpdateOrDeleteLists(@NotNull List<GriffinModel> listToImport, @NotNull List<GriffinModel> listToInsert, @NotNull List<GriffinModel> listToUpdate, @NotNull Set<String> listToDelete, List<GriffinModel> allGriffinInDatabase) { Set<String> dataBaseIds = allGriffinInDatabase.stream().map( GriffinModel::getIdentifier).collect(toSet()); final HashSet<String> updateIds = new HashSet<>(dataBaseIds); final Set<String> importIds = listToImport.stream().map(GriffinModel::getIdentifier).collect(toSet()); updateIds.retainAll(importIds); final HashSet<String> removeIds = new HashSet<>(dataBaseIds); removeIds.removeAll(updateIds); listToDelete.addAll(removeIds); for (GriffinModel griffinModel : listToImport) { classifyModelToImportIntoInsertOrUpdateList(griffinModel, dataBaseIds, listToInsert, listToUpdate); } } }
GriffinService { void classifyDataInInsertUpdateOrDeleteLists(@NotNull List<GriffinModel> listToImport, @NotNull List<GriffinModel> listToInsert, @NotNull List<GriffinModel> listToUpdate, @NotNull Set<String> listToDelete, List<GriffinModel> allGriffinInDatabase) { Set<String> dataBaseIds = allGriffinInDatabase.stream().map( GriffinModel::getIdentifier).collect(toSet()); final HashSet<String> updateIds = new HashSet<>(dataBaseIds); final Set<String> importIds = listToImport.stream().map(GriffinModel::getIdentifier).collect(toSet()); updateIds.retainAll(importIds); final HashSet<String> removeIds = new HashSet<>(dataBaseIds); removeIds.removeAll(updateIds); listToDelete.addAll(removeIds); for (GriffinModel griffinModel : listToImport) { classifyModelToImportIntoInsertOrUpdateList(griffinModel, dataBaseIds, listToInsert, listToUpdate); } } @VisibleForTesting  GriffinService(MongoDbAccessReferential mongoDbAccess, FunctionalBackupService functionalBackupService, LogbookOperationsClientFactory logbookOperationsClientFactory, VitamCollection preservationScenarioCollection);  GriffinService(MongoDbAccessAdminImpl mongoAccess, FunctionalBackupService functionalBackupService); }
GriffinService { void classifyDataInInsertUpdateOrDeleteLists(@NotNull List<GriffinModel> listToImport, @NotNull List<GriffinModel> listToInsert, @NotNull List<GriffinModel> listToUpdate, @NotNull Set<String> listToDelete, List<GriffinModel> allGriffinInDatabase) { Set<String> dataBaseIds = allGriffinInDatabase.stream().map( GriffinModel::getIdentifier).collect(toSet()); final HashSet<String> updateIds = new HashSet<>(dataBaseIds); final Set<String> importIds = listToImport.stream().map(GriffinModel::getIdentifier).collect(toSet()); updateIds.retainAll(importIds); final HashSet<String> removeIds = new HashSet<>(dataBaseIds); removeIds.removeAll(updateIds); listToDelete.addAll(removeIds); for (GriffinModel griffinModel : listToImport) { classifyModelToImportIntoInsertOrUpdateList(griffinModel, dataBaseIds, listToInsert, listToUpdate); } } @VisibleForTesting  GriffinService(MongoDbAccessReferential mongoDbAccess, FunctionalBackupService functionalBackupService, LogbookOperationsClientFactory logbookOperationsClientFactory, VitamCollection preservationScenarioCollection);  GriffinService(MongoDbAccessAdminImpl mongoAccess, FunctionalBackupService functionalBackupService); RequestResponse<GriffinModel> importGriffin(@NotNull List<GriffinModel> griffinsFromRequest); RequestResponse<GriffinModel> findGriffin(JsonNode queryDsl); }
GriffinService { void classifyDataInInsertUpdateOrDeleteLists(@NotNull List<GriffinModel> listToImport, @NotNull List<GriffinModel> listToInsert, @NotNull List<GriffinModel> listToUpdate, @NotNull Set<String> listToDelete, List<GriffinModel> allGriffinInDatabase) { Set<String> dataBaseIds = allGriffinInDatabase.stream().map( GriffinModel::getIdentifier).collect(toSet()); final HashSet<String> updateIds = new HashSet<>(dataBaseIds); final Set<String> importIds = listToImport.stream().map(GriffinModel::getIdentifier).collect(toSet()); updateIds.retainAll(importIds); final HashSet<String> removeIds = new HashSet<>(dataBaseIds); removeIds.removeAll(updateIds); listToDelete.addAll(removeIds); for (GriffinModel griffinModel : listToImport) { classifyModelToImportIntoInsertOrUpdateList(griffinModel, dataBaseIds, listToInsert, listToUpdate); } } @VisibleForTesting  GriffinService(MongoDbAccessReferential mongoDbAccess, FunctionalBackupService functionalBackupService, LogbookOperationsClientFactory logbookOperationsClientFactory, VitamCollection preservationScenarioCollection);  GriffinService(MongoDbAccessAdminImpl mongoAccess, FunctionalBackupService functionalBackupService); RequestResponse<GriffinModel> importGriffin(@NotNull List<GriffinModel> griffinsFromRequest); RequestResponse<GriffinModel> findGriffin(JsonNode queryDsl);  }