@Test @RunWithCustomExecutor public void KO_scenario_absent_value_griffinByFormat_actionDetail() throws Exception { List<PreservationScenarioModel> scenarios = getPreservationScenarioModels( "preservationScenarios/KO_scenario_absent_value_griffinByFormat_actionDetail.json"); assertThatThrownBy( () -> preservationScenarioService.importScenarios(scenarios)) .isInstanceOf(ReferentialException.class).hasMessageContaining("Invalid scenario"); }
public RequestResponse<PreservationScenarioModel> importScenarios( @NotNull List<PreservationScenarioModel> listToImport) throws VitamException { String operationId = getVitamSession().getRequestId(); GUID guid = getGUID(operationId); createLogbook(logbookOperationsClientFactory, guid, SCENARIO_IMPORT_EVENT); try { validate(listToImport); final ObjectNode finalSelect = new Select().getFinalSelect(); DbRequestResult result = mongoDbAccess.findDocuments(finalSelect, PRESERVATION_SCENARIO); final List<PreservationScenarioModel> allScenariosInDatabase = result.getDocuments(PreservationScenario.class, PreservationScenarioModel.class); Set<String> newIdentifiers = listToImport.stream().map(PreservationScenarioModel::getIdentifier).collect(toSet()); Set<String> oldIdentifiers = allScenariosInDatabase.stream().map(PreservationScenarioModel::getIdentifier).collect(toSet()); Set<String> updatedIdentifiers = SetUtils.intersection(newIdentifiers, oldIdentifiers); if (!updatedIdentifiers.isEmpty()) { updateScenarios(listToImport, updatedIdentifiers); } Set<String> identifierToDelete = SetUtils.difference(oldIdentifiers, newIdentifiers); if (!identifierToDelete.isEmpty()) { deleteScenarios(identifierToDelete); } Set<String> identifierToAdd = SetUtils.difference(newIdentifiers, oldIdentifiers); if (!identifierToAdd.isEmpty()) { insertScenarios(listToImport, identifierToAdd); } functionalBackupService .saveCollectionAndSequence(guid, SCENARIO_BACKUP_EVENT, PRESERVATION_SCENARIO, operationId); PreservationScenarioReport preservationScenarioReport = generateReport(allScenariosInDatabase, listToImport, updatedIdentifiers, identifierToDelete, identifierToAdd); saveReport(guid, preservationScenarioReport); } catch (VitamException e) { createLogbookEventKo(logbookOperationsClientFactory, guid, SCENARIO_IMPORT_EVENT, e.getMessage()); throw e; } createLogbookEventSuccess(logbookOperationsClientFactory, guid, SCENARIO_IMPORT_EVENT); return new RequestResponseOK<PreservationScenarioModel>().addAllResults(listToImport) .setHttpCode(Response.Status.CREATED.getStatusCode()); }
PreservationScenarioService { public RequestResponse<PreservationScenarioModel> importScenarios( @NotNull List<PreservationScenarioModel> listToImport) throws VitamException { String operationId = getVitamSession().getRequestId(); GUID guid = getGUID(operationId); createLogbook(logbookOperationsClientFactory, guid, SCENARIO_IMPORT_EVENT); try { validate(listToImport); final ObjectNode finalSelect = new Select().getFinalSelect(); DbRequestResult result = mongoDbAccess.findDocuments(finalSelect, PRESERVATION_SCENARIO); final List<PreservationScenarioModel> allScenariosInDatabase = result.getDocuments(PreservationScenario.class, PreservationScenarioModel.class); Set<String> newIdentifiers = listToImport.stream().map(PreservationScenarioModel::getIdentifier).collect(toSet()); Set<String> oldIdentifiers = allScenariosInDatabase.stream().map(PreservationScenarioModel::getIdentifier).collect(toSet()); Set<String> updatedIdentifiers = SetUtils.intersection(newIdentifiers, oldIdentifiers); if (!updatedIdentifiers.isEmpty()) { updateScenarios(listToImport, updatedIdentifiers); } Set<String> identifierToDelete = SetUtils.difference(oldIdentifiers, newIdentifiers); if (!identifierToDelete.isEmpty()) { deleteScenarios(identifierToDelete); } Set<String> identifierToAdd = SetUtils.difference(newIdentifiers, oldIdentifiers); if (!identifierToAdd.isEmpty()) { insertScenarios(listToImport, identifierToAdd); } functionalBackupService .saveCollectionAndSequence(guid, SCENARIO_BACKUP_EVENT, PRESERVATION_SCENARIO, operationId); PreservationScenarioReport preservationScenarioReport = generateReport(allScenariosInDatabase, listToImport, updatedIdentifiers, identifierToDelete, identifierToAdd); saveReport(guid, preservationScenarioReport); } catch (VitamException e) { createLogbookEventKo(logbookOperationsClientFactory, guid, SCENARIO_IMPORT_EVENT, e.getMessage()); throw e; } createLogbookEventSuccess(logbookOperationsClientFactory, guid, SCENARIO_IMPORT_EVENT); return new RequestResponseOK<PreservationScenarioModel>().addAllResults(listToImport) .setHttpCode(Response.Status.CREATED.getStatusCode()); } }
PreservationScenarioService { public RequestResponse<PreservationScenarioModel> importScenarios( @NotNull List<PreservationScenarioModel> listToImport) throws VitamException { String operationId = getVitamSession().getRequestId(); GUID guid = getGUID(operationId); createLogbook(logbookOperationsClientFactory, guid, SCENARIO_IMPORT_EVENT); try { validate(listToImport); final ObjectNode finalSelect = new Select().getFinalSelect(); DbRequestResult result = mongoDbAccess.findDocuments(finalSelect, PRESERVATION_SCENARIO); final List<PreservationScenarioModel> allScenariosInDatabase = result.getDocuments(PreservationScenario.class, PreservationScenarioModel.class); Set<String> newIdentifiers = listToImport.stream().map(PreservationScenarioModel::getIdentifier).collect(toSet()); Set<String> oldIdentifiers = allScenariosInDatabase.stream().map(PreservationScenarioModel::getIdentifier).collect(toSet()); Set<String> updatedIdentifiers = SetUtils.intersection(newIdentifiers, oldIdentifiers); if (!updatedIdentifiers.isEmpty()) { updateScenarios(listToImport, updatedIdentifiers); } Set<String> identifierToDelete = SetUtils.difference(oldIdentifiers, newIdentifiers); if (!identifierToDelete.isEmpty()) { deleteScenarios(identifierToDelete); } Set<String> identifierToAdd = SetUtils.difference(newIdentifiers, oldIdentifiers); if (!identifierToAdd.isEmpty()) { insertScenarios(listToImport, identifierToAdd); } functionalBackupService .saveCollectionAndSequence(guid, SCENARIO_BACKUP_EVENT, PRESERVATION_SCENARIO, operationId); PreservationScenarioReport preservationScenarioReport = generateReport(allScenariosInDatabase, listToImport, updatedIdentifiers, identifierToDelete, identifierToAdd); saveReport(guid, preservationScenarioReport); } catch (VitamException e) { createLogbookEventKo(logbookOperationsClientFactory, guid, SCENARIO_IMPORT_EVENT, e.getMessage()); throw e; } createLogbookEventSuccess(logbookOperationsClientFactory, guid, SCENARIO_IMPORT_EVENT); return new RequestResponseOK<PreservationScenarioModel>().addAllResults(listToImport) .setHttpCode(Response.Status.CREATED.getStatusCode()); } PreservationScenarioService(MongoDbAccessReferential mongoDbAccess,
        FunctionalBackupService functionalBackupService,
        LogbookOperationsClientFactory logbookOperationsClientFactory);  PreservationScenarioService(MongoDbAccessAdminImpl mongoAccess,
        FunctionalBackupService functionalBackupService); }
PreservationScenarioService { public RequestResponse<PreservationScenarioModel> importScenarios( @NotNull List<PreservationScenarioModel> listToImport) throws VitamException { String operationId = getVitamSession().getRequestId(); GUID guid = getGUID(operationId); createLogbook(logbookOperationsClientFactory, guid, SCENARIO_IMPORT_EVENT); try { validate(listToImport); final ObjectNode finalSelect = new Select().getFinalSelect(); DbRequestResult result = mongoDbAccess.findDocuments(finalSelect, PRESERVATION_SCENARIO); final List<PreservationScenarioModel> allScenariosInDatabase = result.getDocuments(PreservationScenario.class, PreservationScenarioModel.class); Set<String> newIdentifiers = listToImport.stream().map(PreservationScenarioModel::getIdentifier).collect(toSet()); Set<String> oldIdentifiers = allScenariosInDatabase.stream().map(PreservationScenarioModel::getIdentifier).collect(toSet()); Set<String> updatedIdentifiers = SetUtils.intersection(newIdentifiers, oldIdentifiers); if (!updatedIdentifiers.isEmpty()) { updateScenarios(listToImport, updatedIdentifiers); } Set<String> identifierToDelete = SetUtils.difference(oldIdentifiers, newIdentifiers); if (!identifierToDelete.isEmpty()) { deleteScenarios(identifierToDelete); } Set<String> identifierToAdd = SetUtils.difference(newIdentifiers, oldIdentifiers); if (!identifierToAdd.isEmpty()) { insertScenarios(listToImport, identifierToAdd); } functionalBackupService .saveCollectionAndSequence(guid, SCENARIO_BACKUP_EVENT, PRESERVATION_SCENARIO, operationId); PreservationScenarioReport preservationScenarioReport = generateReport(allScenariosInDatabase, listToImport, updatedIdentifiers, identifierToDelete, identifierToAdd); saveReport(guid, preservationScenarioReport); } catch (VitamException e) { createLogbookEventKo(logbookOperationsClientFactory, guid, SCENARIO_IMPORT_EVENT, e.getMessage()); throw e; } createLogbookEventSuccess(logbookOperationsClientFactory, guid, SCENARIO_IMPORT_EVENT); return new RequestResponseOK<PreservationScenarioModel>().addAllResults(listToImport) .setHttpCode(Response.Status.CREATED.getStatusCode()); } PreservationScenarioService(MongoDbAccessReferential mongoDbAccess,
        FunctionalBackupService functionalBackupService,
        LogbookOperationsClientFactory logbookOperationsClientFactory);  PreservationScenarioService(MongoDbAccessAdminImpl mongoAccess,
        FunctionalBackupService functionalBackupService); RequestResponse<PreservationScenarioModel> importScenarios(
        @NotNull List<PreservationScenarioModel> listToImport); RequestResponse<PreservationScenarioModel> findPreservationScenario(JsonNode queryDsl); }
PreservationScenarioService { public RequestResponse<PreservationScenarioModel> importScenarios( @NotNull List<PreservationScenarioModel> listToImport) throws VitamException { String operationId = getVitamSession().getRequestId(); GUID guid = getGUID(operationId); createLogbook(logbookOperationsClientFactory, guid, SCENARIO_IMPORT_EVENT); try { validate(listToImport); final ObjectNode finalSelect = new Select().getFinalSelect(); DbRequestResult result = mongoDbAccess.findDocuments(finalSelect, PRESERVATION_SCENARIO); final List<PreservationScenarioModel> allScenariosInDatabase = result.getDocuments(PreservationScenario.class, PreservationScenarioModel.class); Set<String> newIdentifiers = listToImport.stream().map(PreservationScenarioModel::getIdentifier).collect(toSet()); Set<String> oldIdentifiers = allScenariosInDatabase.stream().map(PreservationScenarioModel::getIdentifier).collect(toSet()); Set<String> updatedIdentifiers = SetUtils.intersection(newIdentifiers, oldIdentifiers); if (!updatedIdentifiers.isEmpty()) { updateScenarios(listToImport, updatedIdentifiers); } Set<String> identifierToDelete = SetUtils.difference(oldIdentifiers, newIdentifiers); if (!identifierToDelete.isEmpty()) { deleteScenarios(identifierToDelete); } Set<String> identifierToAdd = SetUtils.difference(newIdentifiers, oldIdentifiers); if (!identifierToAdd.isEmpty()) { insertScenarios(listToImport, identifierToAdd); } functionalBackupService .saveCollectionAndSequence(guid, SCENARIO_BACKUP_EVENT, PRESERVATION_SCENARIO, operationId); PreservationScenarioReport preservationScenarioReport = generateReport(allScenariosInDatabase, listToImport, updatedIdentifiers, identifierToDelete, identifierToAdd); saveReport(guid, preservationScenarioReport); } catch (VitamException e) { createLogbookEventKo(logbookOperationsClientFactory, guid, SCENARIO_IMPORT_EVENT, e.getMessage()); throw e; } createLogbookEventSuccess(logbookOperationsClientFactory, guid, SCENARIO_IMPORT_EVENT); return new RequestResponseOK<PreservationScenarioModel>().addAllResults(listToImport) .setHttpCode(Response.Status.CREATED.getStatusCode()); } PreservationScenarioService(MongoDbAccessReferential mongoDbAccess,
        FunctionalBackupService functionalBackupService,
        LogbookOperationsClientFactory logbookOperationsClientFactory);  PreservationScenarioService(MongoDbAccessAdminImpl mongoAccess,
        FunctionalBackupService functionalBackupService); RequestResponse<PreservationScenarioModel> importScenarios(
        @NotNull List<PreservationScenarioModel> listToImport); RequestResponse<PreservationScenarioModel> findPreservationScenario(JsonNode queryDsl);  }