@Test @RunWithCustomExecutor public void shouldFailedValidateGriffinWhenIdentifierIsNullOrEmpty() { GriffinModel griffinModel = new GriffinModel("name", null, "exName", "version"); assertThatThrownBy(() -> griffinService.importGriffin(Collections.singletonList(griffinModel))) .isInstanceOf(ReferentialException.class).hasMessageContaining("Invalid griffin"); griffinModel.setIdentifier(""); assertThatThrownBy(() -> griffinService.importGriffin(Collections.singletonList(griffinModel))) .isInstanceOf(ReferentialException.class).hasMessageContaining("Invalid griffin"); }
public RequestResponse<GriffinModel> importGriffin(@NotNull List<GriffinModel> griffinsFromRequest) throws VitamException, InvalidCreateOperationException { String operationId = getVitamSession().getRequestId(); GUID guid = getGUID(operationId); createLogbook(logbookOperationsClientFactory, guid, GRIFFIN_IMPORT_EVENT); try { validate(griffinsFromRequest); final Set<String> griffinIdsToDelete = new HashSet<>(); final List<GriffinModel> griffinsToUpdate = new ArrayList<>(); final List<GriffinModel> griffinsToInsert = new ArrayList<>(); final ObjectNode finalSelect = new Select().getFinalSelect(); DbRequestResult result = mongoDbAccess.findDocuments(finalSelect, GRIFFIN); final List<GriffinModel> allGriffins = result.getDocuments(Griffin.class, GriffinModel.class); classifyDataInInsertUpdateOrDeleteLists(griffinsFromRequest, griffinsToInsert, griffinsToUpdate, griffinIdsToDelete, allGriffins); checkDeletion(griffinIdsToDelete); List<String> griffinIdsToUpdate= griffinsToUpdate.stream().map(GriffinModel::getIdentifier).collect(Collectors.toList()); Set<String> griffinsToUpdateUsedByScenario = getGriffinIdentifierUsedByScenario(griffinIdsToUpdate); insertGriffins(griffinsToInsert); updateGriffins(griffinsToUpdate); deleteGriffins(griffinIdsToDelete); Set<String> griffinsIdsToInsert = griffinsToInsert.stream().map(GriffinModel::getIdentifier).collect(toSet()); GriffinReport griffinReport = generateReport( allGriffins, griffinsFromRequest, griffinIdsToUpdate, griffinIdsToDelete, griffinsIdsToInsert, griffinsToUpdateUsedByScenario ); functionalBackupService.saveCollectionAndSequence(guid, GRIFFIN_BACKUP_EVENT, GRIFFIN, operationId); saveReport(guid, griffinReport); if (!griffinReport.getWarnings().isEmpty()){ createLogbookEventWarning(logbookOperationsClientFactory, guid, GRIFFIN_IMPORT_EVENT, GriffinReport.onlyWarning(griffinReport)); } else { createLogbookEventSuccess(logbookOperationsClientFactory, guid, GRIFFIN_IMPORT_EVENT); } return new RequestResponseOK<GriffinModel>() .addAllResults(griffinsFromRequest) .setHttpCode(CREATED.getStatusCode()); } catch (InvalidCreateOperationException | VitamException e) { createLogbookEventKo(logbookOperationsClientFactory, guid, GRIFFIN_IMPORT_EVENT, e.getMessage()); throw e; } }
GriffinService { public RequestResponse<GriffinModel> importGriffin(@NotNull List<GriffinModel> griffinsFromRequest) throws VitamException, InvalidCreateOperationException { String operationId = getVitamSession().getRequestId(); GUID guid = getGUID(operationId); createLogbook(logbookOperationsClientFactory, guid, GRIFFIN_IMPORT_EVENT); try { validate(griffinsFromRequest); final Set<String> griffinIdsToDelete = new HashSet<>(); final List<GriffinModel> griffinsToUpdate = new ArrayList<>(); final List<GriffinModel> griffinsToInsert = new ArrayList<>(); final ObjectNode finalSelect = new Select().getFinalSelect(); DbRequestResult result = mongoDbAccess.findDocuments(finalSelect, GRIFFIN); final List<GriffinModel> allGriffins = result.getDocuments(Griffin.class, GriffinModel.class); classifyDataInInsertUpdateOrDeleteLists(griffinsFromRequest, griffinsToInsert, griffinsToUpdate, griffinIdsToDelete, allGriffins); checkDeletion(griffinIdsToDelete); List<String> griffinIdsToUpdate= griffinsToUpdate.stream().map(GriffinModel::getIdentifier).collect(Collectors.toList()); Set<String> griffinsToUpdateUsedByScenario = getGriffinIdentifierUsedByScenario(griffinIdsToUpdate); insertGriffins(griffinsToInsert); updateGriffins(griffinsToUpdate); deleteGriffins(griffinIdsToDelete); Set<String> griffinsIdsToInsert = griffinsToInsert.stream().map(GriffinModel::getIdentifier).collect(toSet()); GriffinReport griffinReport = generateReport( allGriffins, griffinsFromRequest, griffinIdsToUpdate, griffinIdsToDelete, griffinsIdsToInsert, griffinsToUpdateUsedByScenario ); functionalBackupService.saveCollectionAndSequence(guid, GRIFFIN_BACKUP_EVENT, GRIFFIN, operationId); saveReport(guid, griffinReport); if (!griffinReport.getWarnings().isEmpty()){ createLogbookEventWarning(logbookOperationsClientFactory, guid, GRIFFIN_IMPORT_EVENT, GriffinReport.onlyWarning(griffinReport)); } else { createLogbookEventSuccess(logbookOperationsClientFactory, guid, GRIFFIN_IMPORT_EVENT); } return new RequestResponseOK<GriffinModel>() .addAllResults(griffinsFromRequest) .setHttpCode(CREATED.getStatusCode()); } catch (InvalidCreateOperationException | VitamException e) { createLogbookEventKo(logbookOperationsClientFactory, guid, GRIFFIN_IMPORT_EVENT, e.getMessage()); throw e; } } }
GriffinService { public RequestResponse<GriffinModel> importGriffin(@NotNull List<GriffinModel> griffinsFromRequest) throws VitamException, InvalidCreateOperationException { String operationId = getVitamSession().getRequestId(); GUID guid = getGUID(operationId); createLogbook(logbookOperationsClientFactory, guid, GRIFFIN_IMPORT_EVENT); try { validate(griffinsFromRequest); final Set<String> griffinIdsToDelete = new HashSet<>(); final List<GriffinModel> griffinsToUpdate = new ArrayList<>(); final List<GriffinModel> griffinsToInsert = new ArrayList<>(); final ObjectNode finalSelect = new Select().getFinalSelect(); DbRequestResult result = mongoDbAccess.findDocuments(finalSelect, GRIFFIN); final List<GriffinModel> allGriffins = result.getDocuments(Griffin.class, GriffinModel.class); classifyDataInInsertUpdateOrDeleteLists(griffinsFromRequest, griffinsToInsert, griffinsToUpdate, griffinIdsToDelete, allGriffins); checkDeletion(griffinIdsToDelete); List<String> griffinIdsToUpdate= griffinsToUpdate.stream().map(GriffinModel::getIdentifier).collect(Collectors.toList()); Set<String> griffinsToUpdateUsedByScenario = getGriffinIdentifierUsedByScenario(griffinIdsToUpdate); insertGriffins(griffinsToInsert); updateGriffins(griffinsToUpdate); deleteGriffins(griffinIdsToDelete); Set<String> griffinsIdsToInsert = griffinsToInsert.stream().map(GriffinModel::getIdentifier).collect(toSet()); GriffinReport griffinReport = generateReport( allGriffins, griffinsFromRequest, griffinIdsToUpdate, griffinIdsToDelete, griffinsIdsToInsert, griffinsToUpdateUsedByScenario ); functionalBackupService.saveCollectionAndSequence(guid, GRIFFIN_BACKUP_EVENT, GRIFFIN, operationId); saveReport(guid, griffinReport); if (!griffinReport.getWarnings().isEmpty()){ createLogbookEventWarning(logbookOperationsClientFactory, guid, GRIFFIN_IMPORT_EVENT, GriffinReport.onlyWarning(griffinReport)); } else { createLogbookEventSuccess(logbookOperationsClientFactory, guid, GRIFFIN_IMPORT_EVENT); } return new RequestResponseOK<GriffinModel>() .addAllResults(griffinsFromRequest) .setHttpCode(CREATED.getStatusCode()); } catch (InvalidCreateOperationException | VitamException e) { createLogbookEventKo(logbookOperationsClientFactory, guid, GRIFFIN_IMPORT_EVENT, e.getMessage()); throw e; } } @VisibleForTesting  GriffinService(MongoDbAccessReferential mongoDbAccess, FunctionalBackupService functionalBackupService, LogbookOperationsClientFactory logbookOperationsClientFactory, VitamCollection preservationScenarioCollection);  GriffinService(MongoDbAccessAdminImpl mongoAccess, FunctionalBackupService functionalBackupService); }
GriffinService { public RequestResponse<GriffinModel> importGriffin(@NotNull List<GriffinModel> griffinsFromRequest) throws VitamException, InvalidCreateOperationException { String operationId = getVitamSession().getRequestId(); GUID guid = getGUID(operationId); createLogbook(logbookOperationsClientFactory, guid, GRIFFIN_IMPORT_EVENT); try { validate(griffinsFromRequest); final Set<String> griffinIdsToDelete = new HashSet<>(); final List<GriffinModel> griffinsToUpdate = new ArrayList<>(); final List<GriffinModel> griffinsToInsert = new ArrayList<>(); final ObjectNode finalSelect = new Select().getFinalSelect(); DbRequestResult result = mongoDbAccess.findDocuments(finalSelect, GRIFFIN); final List<GriffinModel> allGriffins = result.getDocuments(Griffin.class, GriffinModel.class); classifyDataInInsertUpdateOrDeleteLists(griffinsFromRequest, griffinsToInsert, griffinsToUpdate, griffinIdsToDelete, allGriffins); checkDeletion(griffinIdsToDelete); List<String> griffinIdsToUpdate= griffinsToUpdate.stream().map(GriffinModel::getIdentifier).collect(Collectors.toList()); Set<String> griffinsToUpdateUsedByScenario = getGriffinIdentifierUsedByScenario(griffinIdsToUpdate); insertGriffins(griffinsToInsert); updateGriffins(griffinsToUpdate); deleteGriffins(griffinIdsToDelete); Set<String> griffinsIdsToInsert = griffinsToInsert.stream().map(GriffinModel::getIdentifier).collect(toSet()); GriffinReport griffinReport = generateReport( allGriffins, griffinsFromRequest, griffinIdsToUpdate, griffinIdsToDelete, griffinsIdsToInsert, griffinsToUpdateUsedByScenario ); functionalBackupService.saveCollectionAndSequence(guid, GRIFFIN_BACKUP_EVENT, GRIFFIN, operationId); saveReport(guid, griffinReport); if (!griffinReport.getWarnings().isEmpty()){ createLogbookEventWarning(logbookOperationsClientFactory, guid, GRIFFIN_IMPORT_EVENT, GriffinReport.onlyWarning(griffinReport)); } else { createLogbookEventSuccess(logbookOperationsClientFactory, guid, GRIFFIN_IMPORT_EVENT); } return new RequestResponseOK<GriffinModel>() .addAllResults(griffinsFromRequest) .setHttpCode(CREATED.getStatusCode()); } catch (InvalidCreateOperationException | VitamException e) { createLogbookEventKo(logbookOperationsClientFactory, guid, GRIFFIN_IMPORT_EVENT, e.getMessage()); throw e; } } @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 { public RequestResponse<GriffinModel> importGriffin(@NotNull List<GriffinModel> griffinsFromRequest) throws VitamException, InvalidCreateOperationException { String operationId = getVitamSession().getRequestId(); GUID guid = getGUID(operationId); createLogbook(logbookOperationsClientFactory, guid, GRIFFIN_IMPORT_EVENT); try { validate(griffinsFromRequest); final Set<String> griffinIdsToDelete = new HashSet<>(); final List<GriffinModel> griffinsToUpdate = new ArrayList<>(); final List<GriffinModel> griffinsToInsert = new ArrayList<>(); final ObjectNode finalSelect = new Select().getFinalSelect(); DbRequestResult result = mongoDbAccess.findDocuments(finalSelect, GRIFFIN); final List<GriffinModel> allGriffins = result.getDocuments(Griffin.class, GriffinModel.class); classifyDataInInsertUpdateOrDeleteLists(griffinsFromRequest, griffinsToInsert, griffinsToUpdate, griffinIdsToDelete, allGriffins); checkDeletion(griffinIdsToDelete); List<String> griffinIdsToUpdate= griffinsToUpdate.stream().map(GriffinModel::getIdentifier).collect(Collectors.toList()); Set<String> griffinsToUpdateUsedByScenario = getGriffinIdentifierUsedByScenario(griffinIdsToUpdate); insertGriffins(griffinsToInsert); updateGriffins(griffinsToUpdate); deleteGriffins(griffinIdsToDelete); Set<String> griffinsIdsToInsert = griffinsToInsert.stream().map(GriffinModel::getIdentifier).collect(toSet()); GriffinReport griffinReport = generateReport( allGriffins, griffinsFromRequest, griffinIdsToUpdate, griffinIdsToDelete, griffinsIdsToInsert, griffinsToUpdateUsedByScenario ); functionalBackupService.saveCollectionAndSequence(guid, GRIFFIN_BACKUP_EVENT, GRIFFIN, operationId); saveReport(guid, griffinReport); if (!griffinReport.getWarnings().isEmpty()){ createLogbookEventWarning(logbookOperationsClientFactory, guid, GRIFFIN_IMPORT_EVENT, GriffinReport.onlyWarning(griffinReport)); } else { createLogbookEventSuccess(logbookOperationsClientFactory, guid, GRIFFIN_IMPORT_EVENT); } return new RequestResponseOK<GriffinModel>() .addAllResults(griffinsFromRequest) .setHttpCode(CREATED.getStatusCode()); } catch (InvalidCreateOperationException | VitamException e) { createLogbookEventKo(logbookOperationsClientFactory, guid, GRIFFIN_IMPORT_EVENT, e.getMessage()); throw e; } } @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);  }