@Test @RunWithCustomExecutor public void givenAccessContractsTestImportExternalIdentifierKO() throws Exception { VitamThreadUtils.getVitamSession().setTenantId(EXTERNAL_TENANT); final File fileContracts = PropertiesUtils.getResourceFile("contracts_access_ok.json"); final List<AccessContractModel> accessContractModelList = JsonHandler.getFromFileAsTypeReference(fileContracts, new TypeReference<List<AccessContractModel>>() { }); final RequestResponse<AccessContractModel> response = accessContractService.createContracts(accessContractModelList); assertThat(response.isOk()).isFalse(); ArgumentCaptor<LogbookOperationParameters> logbookOperationParametersCaptor = ArgumentCaptor.forClass(LogbookOperationParameters.class); verify(logbookOperationsClientMock, times(1)).create(logbookOperationParametersCaptor.capture()); verify(logbookOperationsClientMock, 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_ACCESS_CONTRACT"); assertThat(allLogbookOperationParameters.get(1).getStatus()).isEqualTo(StatusCode.KO); assertThat(allLogbookOperationParameters.get(1).getParameterValue(LogbookParameterName.eventType)) .isEqualTo("STP_IMPORT_ACCESS_CONTRACT"); assertThat(allLogbookOperationParameters.get(1).getParameterValue(LogbookParameterName.outcomeDetail)) .isEqualTo("STP_IMPORT_ACCESS_CONTRACT.EMPTY_REQUIRED_FIELD.KO"); }
@Override public RequestResponse<AccessContractModel> createContracts(List<AccessContractModel> contractModelList) throws VitamException { ParametersChecker.checkParameter(ACCESS_CONTRACT_IS_MANDATORY_PATAMETER, contractModelList); if (contractModelList.isEmpty()) { return new RequestResponseOK<>(); } boolean slaveMode = vitamCounterService .isSlaveFunctionnalCollectionOnTenant(SequenceType.ACCESS_CONTRACT_SEQUENCE.getCollection(), ParameterHelper.getTenantParameter()); String operationId = VitamThreadUtils.getVitamSession().getRequestId(); GUID eip = GUIDReader.getGUID(operationId); AccessContractValidationService validationService = new AccessContractValidationService(metaDataClient); ContractLogbookService logbookService = new ContractLogbookService(logbookClient,eip, CONTRACTS_IMPORT_EVENT, CONTRACT_UPDATE_EVENT, CONTRACT_KEY, CONTRACT_CHECK_KEY); logbookService.logStarted(); ArrayNode contractsToPersist; final VitamError error = getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), "Access contract import error", StatusCode.KO) .setHttpCode(Response.Status.BAD_REQUEST.getStatusCode()); try { for (final AccessContractModel acm : contractModelList) { if (acm.getId() != null) { error.addToErrors( getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), GenericRejectionCause.rejectIdNotAllowedInCreate(acm.getName()) .getReason(), StatusCode.KO)); continue; } if (validationService.validateContract(acm, acm.getName(), error)) { acm.setId(GUIDFactory.newContractGUID(ParameterHelper.getTenantParameter()).getId()); } if (acm.getTenant() == null) { acm.setTenant(ParameterHelper.getTenantParameter()); } if (slaveMode) { final Optional<GenericRejectionCause> result = validationService.checkEmptyIdentifierSlaveModeValidator().validate(acm, acm.getIdentifier()); result.ifPresent(genericRejectionCause -> error .addToErrors( getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), result.get().getReason(), StatusCode.KO).setMessage(EMPTY_REQUIRED_FIELD))); } } if (error.getErrors() != null && !error.getErrors().isEmpty()) { final String errorsDetails = error.getErrors().stream().map(VitamError::getDescription).collect(Collectors.joining(",")); logbookService.logValidationError(errorsDetails, CONTRACTS_IMPORT_EVENT, error.getErrors().get(0).getMessage()); return error; } contractsToPersist = JsonHandler.createArrayNode(); for (final AccessContractModel acm : contractModelList) { ContractHelper.setIdentifier(slaveMode, acm, vitamCounterService, SequenceType.ACCESS_CONTRACT_SEQUENCE); acm.initializeDefaultValue(); final ObjectNode accessContractNode = (ObjectNode) JsonHandler.toJsonNode(acm); JsonNode hashId = accessContractNode.remove(VitamFieldsHelper.id()); if (hashId != null) { accessContractNode.set(UND_ID, hashId); } JsonNode hashTenant = accessContractNode.remove(VitamFieldsHelper.tenant()); if (hashTenant != null) { accessContractNode.set(UND_TENANT, hashTenant); } contractsToPersist.add(accessContractNode); } mongoAccess.insertDocuments(contractsToPersist, FunctionalAdminCollections.ACCESS_CONTRACT).close(); functionalBackupService.saveCollectionAndSequence( eip, CONTRACT_BACKUP_EVENT, FunctionalAdminCollections.ACCESS_CONTRACT, eip.toString()); logbookService.logSuccess(); return new RequestResponseOK<AccessContractModel>().addAllResults(contractModelList) .setHttpCode(Response.Status.CREATED.getStatusCode()); } catch (SchemaValidationException | BadRequestException exp) { LOGGER.error(exp); final String err = new StringBuilder("Import access 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 access 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()); } }
AccessContractImpl implements ContractService<AccessContractModel> { @Override public RequestResponse<AccessContractModel> createContracts(List<AccessContractModel> contractModelList) throws VitamException { ParametersChecker.checkParameter(ACCESS_CONTRACT_IS_MANDATORY_PATAMETER, contractModelList); if (contractModelList.isEmpty()) { return new RequestResponseOK<>(); } boolean slaveMode = vitamCounterService .isSlaveFunctionnalCollectionOnTenant(SequenceType.ACCESS_CONTRACT_SEQUENCE.getCollection(), ParameterHelper.getTenantParameter()); String operationId = VitamThreadUtils.getVitamSession().getRequestId(); GUID eip = GUIDReader.getGUID(operationId); AccessContractValidationService validationService = new AccessContractValidationService(metaDataClient); ContractLogbookService logbookService = new ContractLogbookService(logbookClient,eip, CONTRACTS_IMPORT_EVENT, CONTRACT_UPDATE_EVENT, CONTRACT_KEY, CONTRACT_CHECK_KEY); logbookService.logStarted(); ArrayNode contractsToPersist; final VitamError error = getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), "Access contract import error", StatusCode.KO) .setHttpCode(Response.Status.BAD_REQUEST.getStatusCode()); try { for (final AccessContractModel acm : contractModelList) { if (acm.getId() != null) { error.addToErrors( getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), GenericRejectionCause.rejectIdNotAllowedInCreate(acm.getName()) .getReason(), StatusCode.KO)); continue; } if (validationService.validateContract(acm, acm.getName(), error)) { acm.setId(GUIDFactory.newContractGUID(ParameterHelper.getTenantParameter()).getId()); } if (acm.getTenant() == null) { acm.setTenant(ParameterHelper.getTenantParameter()); } if (slaveMode) { final Optional<GenericRejectionCause> result = validationService.checkEmptyIdentifierSlaveModeValidator().validate(acm, acm.getIdentifier()); result.ifPresent(genericRejectionCause -> error .addToErrors( getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), result.get().getReason(), StatusCode.KO).setMessage(EMPTY_REQUIRED_FIELD))); } } if (error.getErrors() != null && !error.getErrors().isEmpty()) { final String errorsDetails = error.getErrors().stream().map(VitamError::getDescription).collect(Collectors.joining(",")); logbookService.logValidationError(errorsDetails, CONTRACTS_IMPORT_EVENT, error.getErrors().get(0).getMessage()); return error; } contractsToPersist = JsonHandler.createArrayNode(); for (final AccessContractModel acm : contractModelList) { ContractHelper.setIdentifier(slaveMode, acm, vitamCounterService, SequenceType.ACCESS_CONTRACT_SEQUENCE); acm.initializeDefaultValue(); final ObjectNode accessContractNode = (ObjectNode) JsonHandler.toJsonNode(acm); JsonNode hashId = accessContractNode.remove(VitamFieldsHelper.id()); if (hashId != null) { accessContractNode.set(UND_ID, hashId); } JsonNode hashTenant = accessContractNode.remove(VitamFieldsHelper.tenant()); if (hashTenant != null) { accessContractNode.set(UND_TENANT, hashTenant); } contractsToPersist.add(accessContractNode); } mongoAccess.insertDocuments(contractsToPersist, FunctionalAdminCollections.ACCESS_CONTRACT).close(); functionalBackupService.saveCollectionAndSequence( eip, CONTRACT_BACKUP_EVENT, FunctionalAdminCollections.ACCESS_CONTRACT, eip.toString()); logbookService.logSuccess(); return new RequestResponseOK<AccessContractModel>().addAllResults(contractModelList) .setHttpCode(Response.Status.CREATED.getStatusCode()); } catch (SchemaValidationException | BadRequestException exp) { LOGGER.error(exp); final String err = new StringBuilder("Import access 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 access 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()); } } }
AccessContractImpl implements ContractService<AccessContractModel> { @Override public RequestResponse<AccessContractModel> createContracts(List<AccessContractModel> contractModelList) throws VitamException { ParametersChecker.checkParameter(ACCESS_CONTRACT_IS_MANDATORY_PATAMETER, contractModelList); if (contractModelList.isEmpty()) { return new RequestResponseOK<>(); } boolean slaveMode = vitamCounterService .isSlaveFunctionnalCollectionOnTenant(SequenceType.ACCESS_CONTRACT_SEQUENCE.getCollection(), ParameterHelper.getTenantParameter()); String operationId = VitamThreadUtils.getVitamSession().getRequestId(); GUID eip = GUIDReader.getGUID(operationId); AccessContractValidationService validationService = new AccessContractValidationService(metaDataClient); ContractLogbookService logbookService = new ContractLogbookService(logbookClient,eip, CONTRACTS_IMPORT_EVENT, CONTRACT_UPDATE_EVENT, CONTRACT_KEY, CONTRACT_CHECK_KEY); logbookService.logStarted(); ArrayNode contractsToPersist; final VitamError error = getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), "Access contract import error", StatusCode.KO) .setHttpCode(Response.Status.BAD_REQUEST.getStatusCode()); try { for (final AccessContractModel acm : contractModelList) { if (acm.getId() != null) { error.addToErrors( getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), GenericRejectionCause.rejectIdNotAllowedInCreate(acm.getName()) .getReason(), StatusCode.KO)); continue; } if (validationService.validateContract(acm, acm.getName(), error)) { acm.setId(GUIDFactory.newContractGUID(ParameterHelper.getTenantParameter()).getId()); } if (acm.getTenant() == null) { acm.setTenant(ParameterHelper.getTenantParameter()); } if (slaveMode) { final Optional<GenericRejectionCause> result = validationService.checkEmptyIdentifierSlaveModeValidator().validate(acm, acm.getIdentifier()); result.ifPresent(genericRejectionCause -> error .addToErrors( getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), result.get().getReason(), StatusCode.KO).setMessage(EMPTY_REQUIRED_FIELD))); } } if (error.getErrors() != null && !error.getErrors().isEmpty()) { final String errorsDetails = error.getErrors().stream().map(VitamError::getDescription).collect(Collectors.joining(",")); logbookService.logValidationError(errorsDetails, CONTRACTS_IMPORT_EVENT, error.getErrors().get(0).getMessage()); return error; } contractsToPersist = JsonHandler.createArrayNode(); for (final AccessContractModel acm : contractModelList) { ContractHelper.setIdentifier(slaveMode, acm, vitamCounterService, SequenceType.ACCESS_CONTRACT_SEQUENCE); acm.initializeDefaultValue(); final ObjectNode accessContractNode = (ObjectNode) JsonHandler.toJsonNode(acm); JsonNode hashId = accessContractNode.remove(VitamFieldsHelper.id()); if (hashId != null) { accessContractNode.set(UND_ID, hashId); } JsonNode hashTenant = accessContractNode.remove(VitamFieldsHelper.tenant()); if (hashTenant != null) { accessContractNode.set(UND_TENANT, hashTenant); } contractsToPersist.add(accessContractNode); } mongoAccess.insertDocuments(contractsToPersist, FunctionalAdminCollections.ACCESS_CONTRACT).close(); functionalBackupService.saveCollectionAndSequence( eip, CONTRACT_BACKUP_EVENT, FunctionalAdminCollections.ACCESS_CONTRACT, eip.toString()); logbookService.logSuccess(); return new RequestResponseOK<AccessContractModel>().addAllResults(contractModelList) .setHttpCode(Response.Status.CREATED.getStatusCode()); } catch (SchemaValidationException | BadRequestException exp) { LOGGER.error(exp); final String err = new StringBuilder("Import access 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 access 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()); } } AccessContractImpl(MongoDbAccessAdminImpl mongoAccess, VitamCounterService vitamCounterService); @VisibleForTesting  AccessContractImpl(MongoDbAccessAdminImpl mongoAccess, VitamCounterService vitamCounterService,
        MetaDataClient metaDataClient,
        LogbookOperationsClient logbookClient, 
        FunctionalBackupService functionalBackupService); }
AccessContractImpl implements ContractService<AccessContractModel> { @Override public RequestResponse<AccessContractModel> createContracts(List<AccessContractModel> contractModelList) throws VitamException { ParametersChecker.checkParameter(ACCESS_CONTRACT_IS_MANDATORY_PATAMETER, contractModelList); if (contractModelList.isEmpty()) { return new RequestResponseOK<>(); } boolean slaveMode = vitamCounterService .isSlaveFunctionnalCollectionOnTenant(SequenceType.ACCESS_CONTRACT_SEQUENCE.getCollection(), ParameterHelper.getTenantParameter()); String operationId = VitamThreadUtils.getVitamSession().getRequestId(); GUID eip = GUIDReader.getGUID(operationId); AccessContractValidationService validationService = new AccessContractValidationService(metaDataClient); ContractLogbookService logbookService = new ContractLogbookService(logbookClient,eip, CONTRACTS_IMPORT_EVENT, CONTRACT_UPDATE_EVENT, CONTRACT_KEY, CONTRACT_CHECK_KEY); logbookService.logStarted(); ArrayNode contractsToPersist; final VitamError error = getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), "Access contract import error", StatusCode.KO) .setHttpCode(Response.Status.BAD_REQUEST.getStatusCode()); try { for (final AccessContractModel acm : contractModelList) { if (acm.getId() != null) { error.addToErrors( getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), GenericRejectionCause.rejectIdNotAllowedInCreate(acm.getName()) .getReason(), StatusCode.KO)); continue; } if (validationService.validateContract(acm, acm.getName(), error)) { acm.setId(GUIDFactory.newContractGUID(ParameterHelper.getTenantParameter()).getId()); } if (acm.getTenant() == null) { acm.setTenant(ParameterHelper.getTenantParameter()); } if (slaveMode) { final Optional<GenericRejectionCause> result = validationService.checkEmptyIdentifierSlaveModeValidator().validate(acm, acm.getIdentifier()); result.ifPresent(genericRejectionCause -> error .addToErrors( getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), result.get().getReason(), StatusCode.KO).setMessage(EMPTY_REQUIRED_FIELD))); } } if (error.getErrors() != null && !error.getErrors().isEmpty()) { final String errorsDetails = error.getErrors().stream().map(VitamError::getDescription).collect(Collectors.joining(",")); logbookService.logValidationError(errorsDetails, CONTRACTS_IMPORT_EVENT, error.getErrors().get(0).getMessage()); return error; } contractsToPersist = JsonHandler.createArrayNode(); for (final AccessContractModel acm : contractModelList) { ContractHelper.setIdentifier(slaveMode, acm, vitamCounterService, SequenceType.ACCESS_CONTRACT_SEQUENCE); acm.initializeDefaultValue(); final ObjectNode accessContractNode = (ObjectNode) JsonHandler.toJsonNode(acm); JsonNode hashId = accessContractNode.remove(VitamFieldsHelper.id()); if (hashId != null) { accessContractNode.set(UND_ID, hashId); } JsonNode hashTenant = accessContractNode.remove(VitamFieldsHelper.tenant()); if (hashTenant != null) { accessContractNode.set(UND_TENANT, hashTenant); } contractsToPersist.add(accessContractNode); } mongoAccess.insertDocuments(contractsToPersist, FunctionalAdminCollections.ACCESS_CONTRACT).close(); functionalBackupService.saveCollectionAndSequence( eip, CONTRACT_BACKUP_EVENT, FunctionalAdminCollections.ACCESS_CONTRACT, eip.toString()); logbookService.logSuccess(); return new RequestResponseOK<AccessContractModel>().addAllResults(contractModelList) .setHttpCode(Response.Status.CREATED.getStatusCode()); } catch (SchemaValidationException | BadRequestException exp) { LOGGER.error(exp); final String err = new StringBuilder("Import access 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 access 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()); } } AccessContractImpl(MongoDbAccessAdminImpl mongoAccess, VitamCounterService vitamCounterService); @VisibleForTesting  AccessContractImpl(MongoDbAccessAdminImpl mongoAccess, VitamCounterService vitamCounterService,
        MetaDataClient metaDataClient,
        LogbookOperationsClient logbookClient, 
        FunctionalBackupService functionalBackupService); @Override RequestResponse<AccessContractModel> createContracts(List<AccessContractModel> contractModelList); @Override AccessContractModel findByIdentifier(String identifier); @Override RequestResponseOK<AccessContractModel> findContracts(JsonNode queryDsl); @Override void close(); @Override RequestResponse<AccessContractModel> updateContract(String identifier, JsonNode queryDsl); }
AccessContractImpl implements ContractService<AccessContractModel> { @Override public RequestResponse<AccessContractModel> createContracts(List<AccessContractModel> contractModelList) throws VitamException { ParametersChecker.checkParameter(ACCESS_CONTRACT_IS_MANDATORY_PATAMETER, contractModelList); if (contractModelList.isEmpty()) { return new RequestResponseOK<>(); } boolean slaveMode = vitamCounterService .isSlaveFunctionnalCollectionOnTenant(SequenceType.ACCESS_CONTRACT_SEQUENCE.getCollection(), ParameterHelper.getTenantParameter()); String operationId = VitamThreadUtils.getVitamSession().getRequestId(); GUID eip = GUIDReader.getGUID(operationId); AccessContractValidationService validationService = new AccessContractValidationService(metaDataClient); ContractLogbookService logbookService = new ContractLogbookService(logbookClient,eip, CONTRACTS_IMPORT_EVENT, CONTRACT_UPDATE_EVENT, CONTRACT_KEY, CONTRACT_CHECK_KEY); logbookService.logStarted(); ArrayNode contractsToPersist; final VitamError error = getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), "Access contract import error", StatusCode.KO) .setHttpCode(Response.Status.BAD_REQUEST.getStatusCode()); try { for (final AccessContractModel acm : contractModelList) { if (acm.getId() != null) { error.addToErrors( getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), GenericRejectionCause.rejectIdNotAllowedInCreate(acm.getName()) .getReason(), StatusCode.KO)); continue; } if (validationService.validateContract(acm, acm.getName(), error)) { acm.setId(GUIDFactory.newContractGUID(ParameterHelper.getTenantParameter()).getId()); } if (acm.getTenant() == null) { acm.setTenant(ParameterHelper.getTenantParameter()); } if (slaveMode) { final Optional<GenericRejectionCause> result = validationService.checkEmptyIdentifierSlaveModeValidator().validate(acm, acm.getIdentifier()); result.ifPresent(genericRejectionCause -> error .addToErrors( getVitamError(VitamCode.CONTRACT_VALIDATION_ERROR.getItem(), result.get().getReason(), StatusCode.KO).setMessage(EMPTY_REQUIRED_FIELD))); } } if (error.getErrors() != null && !error.getErrors().isEmpty()) { final String errorsDetails = error.getErrors().stream().map(VitamError::getDescription).collect(Collectors.joining(",")); logbookService.logValidationError(errorsDetails, CONTRACTS_IMPORT_EVENT, error.getErrors().get(0).getMessage()); return error; } contractsToPersist = JsonHandler.createArrayNode(); for (final AccessContractModel acm : contractModelList) { ContractHelper.setIdentifier(slaveMode, acm, vitamCounterService, SequenceType.ACCESS_CONTRACT_SEQUENCE); acm.initializeDefaultValue(); final ObjectNode accessContractNode = (ObjectNode) JsonHandler.toJsonNode(acm); JsonNode hashId = accessContractNode.remove(VitamFieldsHelper.id()); if (hashId != null) { accessContractNode.set(UND_ID, hashId); } JsonNode hashTenant = accessContractNode.remove(VitamFieldsHelper.tenant()); if (hashTenant != null) { accessContractNode.set(UND_TENANT, hashTenant); } contractsToPersist.add(accessContractNode); } mongoAccess.insertDocuments(contractsToPersist, FunctionalAdminCollections.ACCESS_CONTRACT).close(); functionalBackupService.saveCollectionAndSequence( eip, CONTRACT_BACKUP_EVENT, FunctionalAdminCollections.ACCESS_CONTRACT, eip.toString()); logbookService.logSuccess(); return new RequestResponseOK<AccessContractModel>().addAllResults(contractModelList) .setHttpCode(Response.Status.CREATED.getStatusCode()); } catch (SchemaValidationException | BadRequestException exp) { LOGGER.error(exp); final String err = new StringBuilder("Import access 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 access 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()); } } AccessContractImpl(MongoDbAccessAdminImpl mongoAccess, VitamCounterService vitamCounterService); @VisibleForTesting  AccessContractImpl(MongoDbAccessAdminImpl mongoAccess, VitamCounterService vitamCounterService,
        MetaDataClient metaDataClient,
        LogbookOperationsClient logbookClient, 
        FunctionalBackupService functionalBackupService); @Override RequestResponse<AccessContractModel> createContracts(List<AccessContractModel> contractModelList); @Override AccessContractModel findByIdentifier(String identifier); @Override RequestResponseOK<AccessContractModel> findContracts(JsonNode queryDsl); @Override void close(); @Override RequestResponse<AccessContractModel> updateContract(String identifier, JsonNode queryDsl); static final String CONTRACT_BACKUP_EVENT; }