@Test @RunWithCustomExecutor public void when_create_should_return_error_given_identifier_not_present_in_slave_mode() throws VitamException, FileNotFoundException { final File fileContracts = PropertiesUtils.getResourceFile("contracts_management_ok_no_identifiers.json"); final List<ManagementContractModel> contractModelList = JsonHandler.getFromFileAsTypeReference(fileContracts, new TypeReference<List<ManagementContractModel>>() { }); when(vitamCounterService.isSlaveFunctionnalCollectionOnTenant( eq(FunctionalAdminCollections.MANAGEMENT_CONTRACT), eq(TENANT_ID))).thenReturn(true); when(mongoAccess.insertDocuments(any(ArrayNode.class), eq(FunctionalAdminCollections.MANAGEMENT_CONTRACT))) .thenReturn(new DbRequestResult()); when(storageClient.getStorageStrategies()).thenReturn(loadStorageStrategies()); RequestResponse<ManagementContractModel> response = managementContractService .createContracts(contractModelList); assertThat(response.isOk()).isFalse(); assertThat(((VitamError) response).getErrors()).isNotNull(); assertThat(((VitamError) response).getErrors().size()).isEqualTo(5); assertThat(((VitamError) response).getErrors().get(0).getMessage()) .isEqualTo("STP_IMPORT_MANAGEMENT_CONTRACT.EMPTY_REQUIRED_FIELD.KO"); assertThat(((VitamError) response).getErrors().get(0).getDescription()).contains("Identifier") .contains("mandatory"); assertThat(((VitamError) response).getState()).isEqualTo("KO"); assertThat(((VitamError) response).getHttpCode()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode()); verify(logbookOperationsClient, times(1)).create(logbookOperationParametersCaptor.capture()); verify(logbookOperationsClient, times(1)).update(logbookOperationParametersCaptor.capture()); List<LogbookOperationParameters> allLogbookOperationParameters = logbookOperationParametersCaptor .getAllValues(); assertThat(allLogbookOperationParameters.size()).isEqualTo(2); assertThat(allLogbookOperationParameters.get(0).getStatus()).isEqualTo(StatusCode.STARTED); assertThat(allLogbookOperationParameters.get(0).getParameterValue(LogbookParameterName.eventType)) .isEqualTo("STP_IMPORT_MANAGEMENT_CONTRACT"); assertThat(allLogbookOperationParameters.get(1).getStatus()).isEqualTo(StatusCode.KO); assertThat(allLogbookOperationParameters.get(1).getParameterValue(LogbookParameterName.eventType)) .isEqualTo("STP_IMPORT_MANAGEMENT_CONTRACT"); assertThat(allLogbookOperationParameters.get(1).getParameterValue(LogbookParameterName.outcomeDetail)) .isEqualTo("STP_IMPORT_MANAGEMENT_CONTRACT.EMPTY_REQUIRED_FIELD.KO"); }
@Override public RequestResponse<ManagementContractModel> createContracts(List<ManagementContractModel> contractModelList) throws VitamException { ParametersChecker.checkParameter(CONTRACT_IS_MANDATORY_PARAMETER, contractModelList); if (contractModelList.isEmpty()) { return new RequestResponseOK<>(); } boolean slaveMode = vitamCounterService.isSlaveFunctionnalCollectionOnTenant( SequenceType.MANAGEMENT_CONTRACT_SEQUENCE.getCollection(), ParameterHelper.getTenantParameter()); String operationId = VitamThreadUtils.getVitamSession().getRequestId(); GUID eip = GUIDReader.getGUID(operationId); ManagementContractValidationService validationService = new ManagementContractValidationService(storageClient, mongoAccess); ContractLogbookService logbookService = new ContractLogbookService(logbookClient,eip, CONTRACTS_IMPORT_EVENT, CONTRACT_UPDATE_EVENT, CONTRACT_KEY, CONTRACT_CHECK_KEY); logbookService.logStarted(); final VitamError error = getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), "Management contract import error", StatusCode.KO) .setHttpCode(Response.Status.BAD_REQUEST.getStatusCode()); try { for (final ManagementContractModel mcm : contractModelList) { if (null != mcm.getId()) { error.addToErrors(getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), GenericContractValidator.GenericRejectionCause.rejectIdNotAllowedInCreate(mcm.getName()) .getReason(), StatusCode.KO)); continue; } if (validationService.validateContract(mcm, mcm.getName(), error)) { mcm.setId(GUIDFactory.newContractGUID(ParameterHelper.getTenantParameter()).getId()); } if (mcm.getTenant() == null) { mcm.setTenant(ParameterHelper.getTenantParameter()); } if (slaveMode) { final Optional<GenericContractValidator.GenericRejectionCause> result = validationService .checkEmptyIdentifierSlaveModeValidator().validate(mcm, mcm.getIdentifier()); result.ifPresent(t -> error.addToErrors(getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), result.get().getReason(), StatusCode.KO).setMessage(EMPTY_REQUIRED_FIELD))); } } if (null != error.getErrors() && !error.getErrors().isEmpty()) { final String errorsDetails = error.getErrors().stream().map(VitamError::getDescription).distinct() .collect(Collectors.joining(",")); logbookService.logValidationError(errorsDetails, CONTRACTS_IMPORT_EVENT, error.getErrors().get(0).getMessage()); return error; } ArrayNode contractsToPersist = JsonHandler.createArrayNode(); for (final ManagementContractModel mcm : contractModelList) { ContractHelper.setIdentifier(slaveMode, mcm, vitamCounterService, SequenceType.MANAGEMENT_CONTRACT_SEQUENCE); final ObjectNode managementContractNode = (ObjectNode) JsonHandler.toJsonNode(mcm); JsonNode hashId = managementContractNode.remove(VitamFieldsHelper.id()); if (hashId != null) { managementContractNode.set(UND_ID, hashId); } JsonNode hashTenant = managementContractNode.remove(VitamFieldsHelper.tenant()); if (hashTenant != null) { managementContractNode.set(UND_TENANT, hashTenant); } contractsToPersist.add(managementContractNode); } mongoAccess.insertDocuments(contractsToPersist, FunctionalAdminCollections.MANAGEMENT_CONTRACT).close(); functionalBackupService.saveCollectionAndSequence(eip, CONTRACT_BACKUP_EVENT, FunctionalAdminCollections.MANAGEMENT_CONTRACT, eip.toString()); logbookService.logSuccess(); return new RequestResponseOK<ManagementContractModel>().addAllResults(contractModelList) .setHttpCode(Response.Status.CREATED.getStatusCode()); } catch (SchemaValidationException | BadRequestException exp) { LOGGER.error(exp); final String err = new StringBuilder("Import management contracts error > ").append(exp.getMessage()) .toString(); logbookService.logValidationError(err, CONTRACTS_IMPORT_EVENT, CONTRACT_BAD_REQUEST); return getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), exp.getMessage(), StatusCode.KO) .setDescription(err).setHttpCode(Response.Status.BAD_REQUEST.getStatusCode()); } catch (final Exception exp) { LOGGER.error(exp); final String err = new StringBuilder("Import management contracts error > ").append(exp.getMessage()) .toString(); logbookService.logFatalError(err, CONTRACTS_IMPORT_EVENT); return error.setCode(VitamCode.GLOBAL_INTERNAL_SERVER_ERROR.getItem()).setDescription(err) .setHttpCode(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); } }
ManagementContractImpl implements ContractService<ManagementContractModel> { @Override public RequestResponse<ManagementContractModel> createContracts(List<ManagementContractModel> contractModelList) throws VitamException { ParametersChecker.checkParameter(CONTRACT_IS_MANDATORY_PARAMETER, contractModelList); if (contractModelList.isEmpty()) { return new RequestResponseOK<>(); } boolean slaveMode = vitamCounterService.isSlaveFunctionnalCollectionOnTenant( SequenceType.MANAGEMENT_CONTRACT_SEQUENCE.getCollection(), ParameterHelper.getTenantParameter()); String operationId = VitamThreadUtils.getVitamSession().getRequestId(); GUID eip = GUIDReader.getGUID(operationId); ManagementContractValidationService validationService = new ManagementContractValidationService(storageClient, mongoAccess); ContractLogbookService logbookService = new ContractLogbookService(logbookClient,eip, CONTRACTS_IMPORT_EVENT, CONTRACT_UPDATE_EVENT, CONTRACT_KEY, CONTRACT_CHECK_KEY); logbookService.logStarted(); final VitamError error = getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), "Management contract import error", StatusCode.KO) .setHttpCode(Response.Status.BAD_REQUEST.getStatusCode()); try { for (final ManagementContractModel mcm : contractModelList) { if (null != mcm.getId()) { error.addToErrors(getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), GenericContractValidator.GenericRejectionCause.rejectIdNotAllowedInCreate(mcm.getName()) .getReason(), StatusCode.KO)); continue; } if (validationService.validateContract(mcm, mcm.getName(), error)) { mcm.setId(GUIDFactory.newContractGUID(ParameterHelper.getTenantParameter()).getId()); } if (mcm.getTenant() == null) { mcm.setTenant(ParameterHelper.getTenantParameter()); } if (slaveMode) { final Optional<GenericContractValidator.GenericRejectionCause> result = validationService .checkEmptyIdentifierSlaveModeValidator().validate(mcm, mcm.getIdentifier()); result.ifPresent(t -> error.addToErrors(getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), result.get().getReason(), StatusCode.KO).setMessage(EMPTY_REQUIRED_FIELD))); } } if (null != error.getErrors() && !error.getErrors().isEmpty()) { final String errorsDetails = error.getErrors().stream().map(VitamError::getDescription).distinct() .collect(Collectors.joining(",")); logbookService.logValidationError(errorsDetails, CONTRACTS_IMPORT_EVENT, error.getErrors().get(0).getMessage()); return error; } ArrayNode contractsToPersist = JsonHandler.createArrayNode(); for (final ManagementContractModel mcm : contractModelList) { ContractHelper.setIdentifier(slaveMode, mcm, vitamCounterService, SequenceType.MANAGEMENT_CONTRACT_SEQUENCE); final ObjectNode managementContractNode = (ObjectNode) JsonHandler.toJsonNode(mcm); JsonNode hashId = managementContractNode.remove(VitamFieldsHelper.id()); if (hashId != null) { managementContractNode.set(UND_ID, hashId); } JsonNode hashTenant = managementContractNode.remove(VitamFieldsHelper.tenant()); if (hashTenant != null) { managementContractNode.set(UND_TENANT, hashTenant); } contractsToPersist.add(managementContractNode); } mongoAccess.insertDocuments(contractsToPersist, FunctionalAdminCollections.MANAGEMENT_CONTRACT).close(); functionalBackupService.saveCollectionAndSequence(eip, CONTRACT_BACKUP_EVENT, FunctionalAdminCollections.MANAGEMENT_CONTRACT, eip.toString()); logbookService.logSuccess(); return new RequestResponseOK<ManagementContractModel>().addAllResults(contractModelList) .setHttpCode(Response.Status.CREATED.getStatusCode()); } catch (SchemaValidationException | BadRequestException exp) { LOGGER.error(exp); final String err = new StringBuilder("Import management contracts error > ").append(exp.getMessage()) .toString(); logbookService.logValidationError(err, CONTRACTS_IMPORT_EVENT, CONTRACT_BAD_REQUEST); return getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), exp.getMessage(), StatusCode.KO) .setDescription(err).setHttpCode(Response.Status.BAD_REQUEST.getStatusCode()); } catch (final Exception exp) { LOGGER.error(exp); final String err = new StringBuilder("Import management contracts error > ").append(exp.getMessage()) .toString(); logbookService.logFatalError(err, CONTRACTS_IMPORT_EVENT); return error.setCode(VitamCode.GLOBAL_INTERNAL_SERVER_ERROR.getItem()).setDescription(err) .setHttpCode(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); } } }
ManagementContractImpl implements ContractService<ManagementContractModel> { @Override public RequestResponse<ManagementContractModel> createContracts(List<ManagementContractModel> contractModelList) throws VitamException { ParametersChecker.checkParameter(CONTRACT_IS_MANDATORY_PARAMETER, contractModelList); if (contractModelList.isEmpty()) { return new RequestResponseOK<>(); } boolean slaveMode = vitamCounterService.isSlaveFunctionnalCollectionOnTenant( SequenceType.MANAGEMENT_CONTRACT_SEQUENCE.getCollection(), ParameterHelper.getTenantParameter()); String operationId = VitamThreadUtils.getVitamSession().getRequestId(); GUID eip = GUIDReader.getGUID(operationId); ManagementContractValidationService validationService = new ManagementContractValidationService(storageClient, mongoAccess); ContractLogbookService logbookService = new ContractLogbookService(logbookClient,eip, CONTRACTS_IMPORT_EVENT, CONTRACT_UPDATE_EVENT, CONTRACT_KEY, CONTRACT_CHECK_KEY); logbookService.logStarted(); final VitamError error = getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), "Management contract import error", StatusCode.KO) .setHttpCode(Response.Status.BAD_REQUEST.getStatusCode()); try { for (final ManagementContractModel mcm : contractModelList) { if (null != mcm.getId()) { error.addToErrors(getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), GenericContractValidator.GenericRejectionCause.rejectIdNotAllowedInCreate(mcm.getName()) .getReason(), StatusCode.KO)); continue; } if (validationService.validateContract(mcm, mcm.getName(), error)) { mcm.setId(GUIDFactory.newContractGUID(ParameterHelper.getTenantParameter()).getId()); } if (mcm.getTenant() == null) { mcm.setTenant(ParameterHelper.getTenantParameter()); } if (slaveMode) { final Optional<GenericContractValidator.GenericRejectionCause> result = validationService .checkEmptyIdentifierSlaveModeValidator().validate(mcm, mcm.getIdentifier()); result.ifPresent(t -> error.addToErrors(getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), result.get().getReason(), StatusCode.KO).setMessage(EMPTY_REQUIRED_FIELD))); } } if (null != error.getErrors() && !error.getErrors().isEmpty()) { final String errorsDetails = error.getErrors().stream().map(VitamError::getDescription).distinct() .collect(Collectors.joining(",")); logbookService.logValidationError(errorsDetails, CONTRACTS_IMPORT_EVENT, error.getErrors().get(0).getMessage()); return error; } ArrayNode contractsToPersist = JsonHandler.createArrayNode(); for (final ManagementContractModel mcm : contractModelList) { ContractHelper.setIdentifier(slaveMode, mcm, vitamCounterService, SequenceType.MANAGEMENT_CONTRACT_SEQUENCE); final ObjectNode managementContractNode = (ObjectNode) JsonHandler.toJsonNode(mcm); JsonNode hashId = managementContractNode.remove(VitamFieldsHelper.id()); if (hashId != null) { managementContractNode.set(UND_ID, hashId); } JsonNode hashTenant = managementContractNode.remove(VitamFieldsHelper.tenant()); if (hashTenant != null) { managementContractNode.set(UND_TENANT, hashTenant); } contractsToPersist.add(managementContractNode); } mongoAccess.insertDocuments(contractsToPersist, FunctionalAdminCollections.MANAGEMENT_CONTRACT).close(); functionalBackupService.saveCollectionAndSequence(eip, CONTRACT_BACKUP_EVENT, FunctionalAdminCollections.MANAGEMENT_CONTRACT, eip.toString()); logbookService.logSuccess(); return new RequestResponseOK<ManagementContractModel>().addAllResults(contractModelList) .setHttpCode(Response.Status.CREATED.getStatusCode()); } catch (SchemaValidationException | BadRequestException exp) { LOGGER.error(exp); final String err = new StringBuilder("Import management contracts error > ").append(exp.getMessage()) .toString(); logbookService.logValidationError(err, CONTRACTS_IMPORT_EVENT, CONTRACT_BAD_REQUEST); return getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), exp.getMessage(), StatusCode.KO) .setDescription(err).setHttpCode(Response.Status.BAD_REQUEST.getStatusCode()); } catch (final Exception exp) { LOGGER.error(exp); final String err = new StringBuilder("Import management contracts error > ").append(exp.getMessage()) .toString(); logbookService.logFatalError(err, CONTRACTS_IMPORT_EVENT); return error.setCode(VitamCode.GLOBAL_INTERNAL_SERVER_ERROR.getItem()).setDescription(err) .setHttpCode(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); } } ManagementContractImpl(MongoDbAccessAdminImpl mongoAccess, VitamCounterService vitamCounterService);  ManagementContractImpl(MongoDbAccessAdminImpl mongoAccess, VitamCounterService vitamCounterService,
            StorageClient storageClient, LogbookOperationsClient logbookOperationsClient,
            FunctionalBackupService functionalBackupService); }
ManagementContractImpl implements ContractService<ManagementContractModel> { @Override public RequestResponse<ManagementContractModel> createContracts(List<ManagementContractModel> contractModelList) throws VitamException { ParametersChecker.checkParameter(CONTRACT_IS_MANDATORY_PARAMETER, contractModelList); if (contractModelList.isEmpty()) { return new RequestResponseOK<>(); } boolean slaveMode = vitamCounterService.isSlaveFunctionnalCollectionOnTenant( SequenceType.MANAGEMENT_CONTRACT_SEQUENCE.getCollection(), ParameterHelper.getTenantParameter()); String operationId = VitamThreadUtils.getVitamSession().getRequestId(); GUID eip = GUIDReader.getGUID(operationId); ManagementContractValidationService validationService = new ManagementContractValidationService(storageClient, mongoAccess); ContractLogbookService logbookService = new ContractLogbookService(logbookClient,eip, CONTRACTS_IMPORT_EVENT, CONTRACT_UPDATE_EVENT, CONTRACT_KEY, CONTRACT_CHECK_KEY); logbookService.logStarted(); final VitamError error = getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), "Management contract import error", StatusCode.KO) .setHttpCode(Response.Status.BAD_REQUEST.getStatusCode()); try { for (final ManagementContractModel mcm : contractModelList) { if (null != mcm.getId()) { error.addToErrors(getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), GenericContractValidator.GenericRejectionCause.rejectIdNotAllowedInCreate(mcm.getName()) .getReason(), StatusCode.KO)); continue; } if (validationService.validateContract(mcm, mcm.getName(), error)) { mcm.setId(GUIDFactory.newContractGUID(ParameterHelper.getTenantParameter()).getId()); } if (mcm.getTenant() == null) { mcm.setTenant(ParameterHelper.getTenantParameter()); } if (slaveMode) { final Optional<GenericContractValidator.GenericRejectionCause> result = validationService .checkEmptyIdentifierSlaveModeValidator().validate(mcm, mcm.getIdentifier()); result.ifPresent(t -> error.addToErrors(getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), result.get().getReason(), StatusCode.KO).setMessage(EMPTY_REQUIRED_FIELD))); } } if (null != error.getErrors() && !error.getErrors().isEmpty()) { final String errorsDetails = error.getErrors().stream().map(VitamError::getDescription).distinct() .collect(Collectors.joining(",")); logbookService.logValidationError(errorsDetails, CONTRACTS_IMPORT_EVENT, error.getErrors().get(0).getMessage()); return error; } ArrayNode contractsToPersist = JsonHandler.createArrayNode(); for (final ManagementContractModel mcm : contractModelList) { ContractHelper.setIdentifier(slaveMode, mcm, vitamCounterService, SequenceType.MANAGEMENT_CONTRACT_SEQUENCE); final ObjectNode managementContractNode = (ObjectNode) JsonHandler.toJsonNode(mcm); JsonNode hashId = managementContractNode.remove(VitamFieldsHelper.id()); if (hashId != null) { managementContractNode.set(UND_ID, hashId); } JsonNode hashTenant = managementContractNode.remove(VitamFieldsHelper.tenant()); if (hashTenant != null) { managementContractNode.set(UND_TENANT, hashTenant); } contractsToPersist.add(managementContractNode); } mongoAccess.insertDocuments(contractsToPersist, FunctionalAdminCollections.MANAGEMENT_CONTRACT).close(); functionalBackupService.saveCollectionAndSequence(eip, CONTRACT_BACKUP_EVENT, FunctionalAdminCollections.MANAGEMENT_CONTRACT, eip.toString()); logbookService.logSuccess(); return new RequestResponseOK<ManagementContractModel>().addAllResults(contractModelList) .setHttpCode(Response.Status.CREATED.getStatusCode()); } catch (SchemaValidationException | BadRequestException exp) { LOGGER.error(exp); final String err = new StringBuilder("Import management contracts error > ").append(exp.getMessage()) .toString(); logbookService.logValidationError(err, CONTRACTS_IMPORT_EVENT, CONTRACT_BAD_REQUEST); return getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), exp.getMessage(), StatusCode.KO) .setDescription(err).setHttpCode(Response.Status.BAD_REQUEST.getStatusCode()); } catch (final Exception exp) { LOGGER.error(exp); final String err = new StringBuilder("Import management contracts error > ").append(exp.getMessage()) .toString(); logbookService.logFatalError(err, CONTRACTS_IMPORT_EVENT); return error.setCode(VitamCode.GLOBAL_INTERNAL_SERVER_ERROR.getItem()).setDescription(err) .setHttpCode(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); } } ManagementContractImpl(MongoDbAccessAdminImpl mongoAccess, VitamCounterService vitamCounterService);  ManagementContractImpl(MongoDbAccessAdminImpl mongoAccess, VitamCounterService vitamCounterService,
            StorageClient storageClient, LogbookOperationsClient logbookOperationsClient,
            FunctionalBackupService functionalBackupService); @Override RequestResponse<ManagementContractModel> createContracts(List<ManagementContractModel> contractModelList); @Override RequestResponse<ManagementContractModel> updateContract(String identifier, JsonNode queryDsl); @Override ManagementContractModel findByIdentifier(String identifier); @Override RequestResponseOK<ManagementContractModel> findContracts(JsonNode queryDsl); @Override void close(); }
ManagementContractImpl implements ContractService<ManagementContractModel> { @Override public RequestResponse<ManagementContractModel> createContracts(List<ManagementContractModel> contractModelList) throws VitamException { ParametersChecker.checkParameter(CONTRACT_IS_MANDATORY_PARAMETER, contractModelList); if (contractModelList.isEmpty()) { return new RequestResponseOK<>(); } boolean slaveMode = vitamCounterService.isSlaveFunctionnalCollectionOnTenant( SequenceType.MANAGEMENT_CONTRACT_SEQUENCE.getCollection(), ParameterHelper.getTenantParameter()); String operationId = VitamThreadUtils.getVitamSession().getRequestId(); GUID eip = GUIDReader.getGUID(operationId); ManagementContractValidationService validationService = new ManagementContractValidationService(storageClient, mongoAccess); ContractLogbookService logbookService = new ContractLogbookService(logbookClient,eip, CONTRACTS_IMPORT_EVENT, CONTRACT_UPDATE_EVENT, CONTRACT_KEY, CONTRACT_CHECK_KEY); logbookService.logStarted(); final VitamError error = getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), "Management contract import error", StatusCode.KO) .setHttpCode(Response.Status.BAD_REQUEST.getStatusCode()); try { for (final ManagementContractModel mcm : contractModelList) { if (null != mcm.getId()) { error.addToErrors(getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), GenericContractValidator.GenericRejectionCause.rejectIdNotAllowedInCreate(mcm.getName()) .getReason(), StatusCode.KO)); continue; } if (validationService.validateContract(mcm, mcm.getName(), error)) { mcm.setId(GUIDFactory.newContractGUID(ParameterHelper.getTenantParameter()).getId()); } if (mcm.getTenant() == null) { mcm.setTenant(ParameterHelper.getTenantParameter()); } if (slaveMode) { final Optional<GenericContractValidator.GenericRejectionCause> result = validationService .checkEmptyIdentifierSlaveModeValidator().validate(mcm, mcm.getIdentifier()); result.ifPresent(t -> error.addToErrors(getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), result.get().getReason(), StatusCode.KO).setMessage(EMPTY_REQUIRED_FIELD))); } } if (null != error.getErrors() && !error.getErrors().isEmpty()) { final String errorsDetails = error.getErrors().stream().map(VitamError::getDescription).distinct() .collect(Collectors.joining(",")); logbookService.logValidationError(errorsDetails, CONTRACTS_IMPORT_EVENT, error.getErrors().get(0).getMessage()); return error; } ArrayNode contractsToPersist = JsonHandler.createArrayNode(); for (final ManagementContractModel mcm : contractModelList) { ContractHelper.setIdentifier(slaveMode, mcm, vitamCounterService, SequenceType.MANAGEMENT_CONTRACT_SEQUENCE); final ObjectNode managementContractNode = (ObjectNode) JsonHandler.toJsonNode(mcm); JsonNode hashId = managementContractNode.remove(VitamFieldsHelper.id()); if (hashId != null) { managementContractNode.set(UND_ID, hashId); } JsonNode hashTenant = managementContractNode.remove(VitamFieldsHelper.tenant()); if (hashTenant != null) { managementContractNode.set(UND_TENANT, hashTenant); } contractsToPersist.add(managementContractNode); } mongoAccess.insertDocuments(contractsToPersist, FunctionalAdminCollections.MANAGEMENT_CONTRACT).close(); functionalBackupService.saveCollectionAndSequence(eip, CONTRACT_BACKUP_EVENT, FunctionalAdminCollections.MANAGEMENT_CONTRACT, eip.toString()); logbookService.logSuccess(); return new RequestResponseOK<ManagementContractModel>().addAllResults(contractModelList) .setHttpCode(Response.Status.CREATED.getStatusCode()); } catch (SchemaValidationException | BadRequestException exp) { LOGGER.error(exp); final String err = new StringBuilder("Import management contracts error > ").append(exp.getMessage()) .toString(); logbookService.logValidationError(err, CONTRACTS_IMPORT_EVENT, CONTRACT_BAD_REQUEST); return getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), exp.getMessage(), StatusCode.KO) .setDescription(err).setHttpCode(Response.Status.BAD_REQUEST.getStatusCode()); } catch (final Exception exp) { LOGGER.error(exp); final String err = new StringBuilder("Import management contracts error > ").append(exp.getMessage()) .toString(); logbookService.logFatalError(err, CONTRACTS_IMPORT_EVENT); return error.setCode(VitamCode.GLOBAL_INTERNAL_SERVER_ERROR.getItem()).setDescription(err) .setHttpCode(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); } } ManagementContractImpl(MongoDbAccessAdminImpl mongoAccess, VitamCounterService vitamCounterService);  ManagementContractImpl(MongoDbAccessAdminImpl mongoAccess, VitamCounterService vitamCounterService,
            StorageClient storageClient, LogbookOperationsClient logbookOperationsClient,
            FunctionalBackupService functionalBackupService); @Override RequestResponse<ManagementContractModel> createContracts(List<ManagementContractModel> contractModelList); @Override RequestResponse<ManagementContractModel> updateContract(String identifier, JsonNode queryDsl); @Override ManagementContractModel findByIdentifier(String identifier); @Override RequestResponseOK<ManagementContractModel> findContracts(JsonNode queryDsl); @Override void close(); static final String CONTRACT_BACKUP_EVENT; }