diff --git a/api/api-referential/referential-commons/src/main/java/fr/gouv/vitamui/referential/common/dto/IngestContractDto.java b/api/api-referential/referential-commons/src/main/java/fr/gouv/vitamui/referential/common/dto/IngestContractDto.java index ef42d478539..f8b380b5d01 100644 --- a/api/api-referential/referential-commons/src/main/java/fr/gouv/vitamui/referential/common/dto/IngestContractDto.java +++ b/api/api-referential/referential-commons/src/main/java/fr/gouv/vitamui/referential/common/dto/IngestContractDto.java @@ -38,7 +38,6 @@ import com.fasterxml.jackson.annotation.JsonInclude; import fr.gouv.vitam.common.model.administration.ActivationStatus; -import fr.gouv.vitam.common.model.administration.SignaturePolicy; import fr.gouv.vitamui.commons.api.domain.IdDto; import lombok.Getter; import lombok.Setter; @@ -98,5 +97,5 @@ public class IngestContractDto extends IdDto implements Serializable { private boolean computeInheritedRulesAtIngest; - private SignaturePolicy signaturePolicy; + private SignaturePolicyDto signaturePolicy; } diff --git a/api/api-referential/referential-commons/src/main/java/fr/gouv/vitamui/referential/common/dto/SignaturePolicyDto.java b/api/api-referential/referential-commons/src/main/java/fr/gouv/vitamui/referential/common/dto/SignaturePolicyDto.java new file mode 100644 index 00000000000..a642161b1bb --- /dev/null +++ b/api/api-referential/referential-commons/src/main/java/fr/gouv/vitamui/referential/common/dto/SignaturePolicyDto.java @@ -0,0 +1,42 @@ +/* + * Copyright French Prime minister Office/SGMAP/DINSIC/Vitam Program (2015-2022) + * + * contact.vitam@culture.gouv.fr + * + * This software is a computer program whose purpose is to implement a digital archiving back-office system managing + * high volumetry securely and efficiently. + * + * This software is governed by the CeCILL 2.1 license under French law and abiding by the rules of distribution of free + * software. You can use, modify and/ or redistribute the software under the terms of the CeCILL 2.1 license as + * circulated by CEA, CNRS and INRIA at the following URL "https://cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, + * users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the + * successive licensors have only limited liability. + * + * In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or + * developing or reproducing the software by the user in light of its specific status of free software, that may mean + * that it is complicated to manipulate, and that also therefore means that it is reserved for developers and + * experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the + * software's suitability as regards their requirements in conditions enabling the security of their systems and/or data + * to be ensured and, more generally, to use and operate it in the same conditions as regards security. + * + * The fact that you are presently reading this means that you have had knowledge of the CeCILL 2.1 license and that you + * accept its terms. + * + */ + +package fr.gouv.vitamui.referential.common.dto; + +import fr.gouv.vitam.common.model.administration.SignaturePolicy; +import lombok.Data; +import lombok.experimental.Accessors; + +@Data +@Accessors(chain = true) +public class SignaturePolicyDto { + private SignaturePolicy.SignedDocumentPolicyEnum signedDocument; + private boolean needSignature; + private boolean needTimestamp; + private boolean needAdditionalProof; +} diff --git a/api/api-referential/referential-commons/src/main/java/fr/gouv/vitamui/referential/common/service/IngestContractService.java b/api/api-referential/referential-commons/src/main/java/fr/gouv/vitamui/referential/common/service/IngestContractService.java index b7a9a128a2d..2e9415946b8 100644 --- a/api/api-referential/referential-commons/src/main/java/fr/gouv/vitamui/referential/common/service/IngestContractService.java +++ b/api/api-referential/referential-commons/src/main/java/fr/gouv/vitamui/referential/common/service/IngestContractService.java @@ -85,14 +85,15 @@ public IngestContractService(final AdminExternalClient adminExternalClient) { this.adminExternalClient = adminExternalClient; } - public RequestResponse patchIngestContract(VitamContext vitamContext, String id, ObjectNode jsonNode) throws InvalidParseOperationException, AccessExternalClientException { + public RequestResponse patchIngestContract(VitamContext vitamContext, String id, ObjectNode jsonNode) + throws InvalidParseOperationException, AccessExternalClientException { LOGGER.debug("patch: {}, {}", id, jsonNode); - LOGGER.info("Patch Ingest Contract EvIdAppSession : {} " , vitamContext.getApplicationSessionId()); + LOGGER.info("Patch Ingest Contract EvIdAppSession : {} ", vitamContext.getApplicationSessionId()); return adminExternalClient.updateIngestContract(vitamContext, id, jsonNode); } public RequestResponse findIngestContractById(final VitamContext vitamContext, - final String contractId) throws VitamClientException { + final String contractId) throws VitamClientException { RequestResponse jsonResponse = adminExternalClient.findIngestContractById(vitamContext, contractId); @@ -101,7 +102,7 @@ public RequestResponse findIngestContractById(final VitamCo } public RequestResponse findIngestContracts(final VitamContext vitamContext, - final JsonNode query) throws VitamClientException { + final JsonNode query) throws VitamClientException { RequestResponse jsonResponse = adminExternalClient.findIngestContracts(vitamContext, query); @@ -110,7 +111,8 @@ public RequestResponse findIngestContracts(final VitamConte } //TODO: Add attribute to fr.gouv.vitamui.commons.api.domain.IngestContractVitamDto - private List convertIngestContractsToModelOfCreation(final List ingestContractModels) { + private List convertIngestContractsToModelOfCreation( + final List ingestContractModels) { final List listOfAC = new ArrayList<>(); for (final IngestContractModel acModel : ingestContractModels) { final IngestContractModel ac = new IngestContractModel(); @@ -129,11 +131,11 @@ private List convertIngestContractsToModelOfCreation(final ac.setEveryDataObjectVersion(acModel.isEveryDataObjectVersion()); ac.setComputeInheritedRulesAtIngest(acModel.isComputeInheritedRulesAtIngest()); - if(acModel.getActivationdate() != null ) { + if (acModel.getActivationdate() != null) { ac.setActivationdate(LocalDateUtil.getFormattedDateForMongo(acModel.getActivationdate())); } - if(acModel.getDeactivationdate() != null ) { + if (acModel.getDeactivationdate() != null) { ac.setDeactivationdate(LocalDateUtil.getFormattedDateForMongo(acModel.getDeactivationdate())); } @@ -145,7 +147,8 @@ private List convertIngestContractsToModelOfCreation(final return listOfAC; } - private ByteArrayInputStream serializeIngestContracts(final List ingestContractModels) throws IOException { + private ByteArrayInputStream serializeIngestContracts(final List ingestContractModels) + throws IOException { final List listOfAC = convertIngestContractsToModelOfCreation(ingestContractModels); final ObjectMapper mapper = new ObjectMapper(); final JsonNode node = mapper.convertValue(listOfAC, JsonNode.class); @@ -158,20 +161,27 @@ private ByteArrayInputStream serializeIngestContracts(final List createIngestContracts(final VitamContext vitamContext, final List ingestContracts) throws InvalidParseOperationException, AccessExternalClientException, IOException { + public RequestResponse createIngestContracts(final VitamContext vitamContext, + final List ingestContracts) + throws InvalidParseOperationException, AccessExternalClientException, IOException { try (ByteArrayInputStream byteArrayInputStream = serializeIngestContracts(ingestContracts)) { - LOGGER.info("Create Ingest Contract EvIdAppSession : {} " , vitamContext.getApplicationSessionId()); - return adminExternalClient.createIngestContracts(vitamContext, byteArrayInputStream); + LOGGER.info("Create Ingest Contract EvIdAppSession : {} ", vitamContext.getApplicationSessionId()); + RequestResponse jsonResponse = + adminExternalClient.createIngestContracts(vitamContext, byteArrayInputStream); + VitamRestUtils.checkResponse(jsonResponse); + return jsonResponse; } } - public Integer checkAbilityToCreateIngestContractInVitam(List ingestContracts, String applicationSessionId) { + public Integer checkAbilityToCreateIngestContractInVitam(List ingestContracts, + String applicationSessionId) { if (ingestContracts != null && !ingestContracts.isEmpty()) { // check if tenant is ok in the request body final Optional ingestContract = ingestContracts.stream().findFirst(); final Integer tenantIdentifier = ingestContract.isPresent() ? ingestContract.get().getTenant() : null; if (tenantIdentifier != null) { - final boolean sameTenant = ingestContracts.stream().allMatch(ac -> tenantIdentifier.equals(ac.getTenant())); + final boolean sameTenant = + ingestContracts.stream().allMatch(ac -> tenantIdentifier.equals(ac.getTenant())); if (!sameTenant) { final String msg = "All the ingest contracts must have the same tenant identifier"; LOGGER.error(msg); @@ -185,22 +195,26 @@ public Integer checkAbilityToCreateIngestContractInVitam(List response = findIngestContracts(vitamContext, select); if (response.getStatus() == HttpStatus.UNAUTHORIZED.value()) { - final String msg = "Can't create ingest contracts for the tenant : " + tenantIdentifier + " not found in Vitam"; + final String msg = + "Can't create ingest contracts for the tenant : " + tenantIdentifier + " not found in Vitam"; LOGGER.error(msg); throw new PreconditionFailedException(msg); } else if (response.getStatus() != HttpStatus.OK.value()) { - final String msg = "Can't create ingest contracts for this tenant, Vitam response code : " + response.getStatus(); + final String msg = + "Can't create ingest contracts for this tenant, Vitam response code : " + response.getStatus(); LOGGER.error(msg); throw new UnavailableServiceException(msg); } verifyIngestContractExistence(ingestContracts, response); } catch (final VitamClientException e) { - final String msg = "Can't create ingest contracts for this tenant, error while calling Vitam : " + e.getMessage(); + final String msg = + "Can't create ingest contracts for this tenant, error while calling Vitam : " + e.getMessage(); LOGGER.error(msg); throw new UnavailableServiceException(msg); } @@ -217,27 +231,33 @@ public Integer checkAbilityToCreateIngestContractInVitam(List ingestContracts, final RequestResponse response) { + private void verifyIngestContractExistence(final List ingestContracts, + final RequestResponse response) { try { final ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - final IngestContractResponseDto ingestContractResponseDto = objectMapper.treeToValue(response.toJsonNode(), IngestContractResponseDto.class); + final IngestContractResponseDto ingestContractResponseDto = + objectMapper.treeToValue(response.toJsonNode(), IngestContractResponseDto.class); final List ingestContractsNames = ingestContracts.stream().map(AbstractContractModel::getName) .filter(Objects::nonNull).map(String::strip) .collect(Collectors.toList()); - boolean alreadyCreated = ingestContractResponseDto.getResults().stream().anyMatch(ac -> ingestContractsNames.contains(ac.getName())); + boolean alreadyCreated = ingestContractResponseDto.getResults().stream() + .anyMatch(ac -> ingestContractsNames.contains(ac.getName())); if (alreadyCreated) { final String msg = "Can't create ingest contract, a contract with the same name already exist in Vitam"; LOGGER.error(msg); throw new ConflictException(msg); } - final List ingestContractsIdentifiers = ingestContracts.stream().map(AbstractContractModel::getIdentifier) - .filter(Objects::nonNull).map(String::strip) - .collect(Collectors.toList()); - alreadyCreated = ingestContractResponseDto.getResults().stream().anyMatch(ac -> ingestContractsIdentifiers.contains(ac.getIdentifier())); + final List ingestContractsIdentifiers = + ingestContracts.stream().map(AbstractContractModel::getIdentifier) + .filter(Objects::nonNull).map(String::strip) + .collect(Collectors.toList()); + alreadyCreated = ingestContractResponseDto.getResults().stream() + .anyMatch(ac -> ingestContractsIdentifiers.contains(ac.getIdentifier())); if (alreadyCreated) { - final String msg = "Can't create ingest contract, a contract with the same identifier already exist in Vitam"; + final String msg = + "Can't create ingest contract, a contract with the same identifier already exist in Vitam"; LOGGER.error(msg); throw new ConflictException(msg); } diff --git a/api/api-referential/referential-internal/src/main/java/fr/gouv/vitamui/referential/internal/server/ingestcontract/IngestContractConverter.java b/api/api-referential/referential-internal/src/main/java/fr/gouv/vitamui/referential/internal/server/ingestcontract/IngestContractConverter.java index dd3fc951084..1595e9e75f7 100644 --- a/api/api-referential/referential-internal/src/main/java/fr/gouv/vitamui/referential/internal/server/ingestcontract/IngestContractConverter.java +++ b/api/api-referential/referential-internal/src/main/java/fr/gouv/vitamui/referential/internal/server/ingestcontract/IngestContractConverter.java @@ -38,13 +38,16 @@ import fr.gouv.vitam.common.model.administration.IngestContractCheckState; import fr.gouv.vitam.common.model.administration.IngestContractModel; +import fr.gouv.vitam.common.model.administration.SignaturePolicy; import fr.gouv.vitamui.commons.api.logger.VitamUILogger; import fr.gouv.vitamui.commons.api.logger.VitamUILoggerFactory; import fr.gouv.vitamui.commons.utils.VitamUIUtils; import fr.gouv.vitamui.referential.common.dto.IngestContractDto; +import fr.gouv.vitamui.referential.common.dto.SignaturePolicyDto; import java.util.HashSet; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; public class IngestContractConverter { @@ -65,7 +68,7 @@ public IngestContractModel convertDtoToVitam(final IngestContractDto dto) { ingestContract.setActivationdate(dto.getActivationdate()); ingestContract.setDeactivationdate(dto.getDeactivationdate()); ingestContract.setComputeInheritedRulesAtIngest(dto.isComputeInheritedRulesAtIngest()); - ingestContract.setSignaturePolicy(dto.getSignaturePolicy()); + ingestContract.setSignaturePolicy(convertDtoToVitam(dto.getSignaturePolicy())); return ingestContract; } @@ -86,11 +89,34 @@ public IngestContractDto convertVitamToDto(final IngestContractModel ingestContr dto.setLastupdate(ingestContract.getLastupdate()); dto.setActivationdate(ingestContract.getActivationdate()); dto.setDeactivationdate(ingestContract.getDeactivationdate()); - dto.setSignaturePolicy(ingestContract.getSignaturePolicy()); + dto.setSignaturePolicy(convertVitamToDto(ingestContract.getSignaturePolicy())); return dto; } + public SignaturePolicyDto convertVitamToDto(final SignaturePolicy vitam) { + if (Objects.isNull(vitam)) { + return null; + } + return new SignaturePolicyDto() + .setSignedDocument(vitam.getSignedDocument()) + .setNeedSignature(vitam.isNeedSignature()) + .setNeedTimestamp(vitam.isNeedTimestamp()) + .setNeedAdditionalProof(vitam.isNeedAdditionalProof()); + } + + public SignaturePolicy convertDtoToVitam(final SignaturePolicyDto dto) { + if (Objects.isNull(dto)) { + return null; + } + SignaturePolicy signaturePolicy = new SignaturePolicy(); + signaturePolicy.setSignedDocument(dto.getSignedDocument()); + signaturePolicy.setNeedSignature(dto.isNeedSignature()); + signaturePolicy.setNeedTimestamp(dto.isNeedTimestamp()); + signaturePolicy.setNeedAdditionalProof(dto.isNeedAdditionalProof()); + return signaturePolicy; + } + public List convertDtosToVitams(final List dtos) { return dtos.stream().map(this::convertDtoToVitam).collect(Collectors.toList()); } diff --git a/ui/ui-frontend/projects/referential/src/app/ingest-contract/ingest-contract-create/ingest-contract-create.component.html b/ui/ui-frontend/projects/referential/src/app/ingest-contract/ingest-contract-create/ingest-contract-create.component.html index fe9f17f74c4..5212e6a06a4 100644 --- a/ui/ui-frontend/projects/referential/src/app/ingest-contract/ingest-contract-create/ingest-contract-create.component.html +++ b/ui/ui-frontend/projects/referential/src/app/ingest-contract/ingest-contract-create/ingest-contract-create.component.html @@ -5,6 +5,139 @@
+ + +
+

{{ 'INGEST_CONTRACT.MODAL_CREATE.TITLE' | translate }}

+

{{ 'INGEST_CONTRACT.MODAL_CREATE.INFORMATIONS.TITLE' | translate }}

+
+
+
+
+ Contrat d'entrée actif + +
+
+
+
+ + + Champ requis + + Nom déjà utilisé + + + +
+ +
+ + + Champ requis + + Identifiant déjà utilisé + + + +
+ +
+ + + + {{ 'COMMON.REQUIRED' | translate }} + + + +
+
+
+
+
+
+ + +
+
+
+
+ + + +
+

{{ 'INGEST_CONTRACT.MODAL_CREATE.TITLE' | translate }}

+

{{ 'INGEST_CONTRACT.MODAL_CREATE.INFORMATIONS.TITLE' | translate }}

+
+
+
+
+ + + {{ profiles.name }} + +
+ keyboard_arrow_up + keyboard_arrow_down +
+
+
+
+
+
+ + + {{ managementContract.name }} + + +
+ keyboard_arrow_up + keyboard_arrow_down +
+
+
+
+
+
+
+
+ + +
+ +
+
+
+ @@ -218,24 +351,22 @@

{{ 'INGEST_CONTRACT.MODAL_CREATE.ATTACHMENT_CONTROLS.TITLE' | translate }}
- - - - - - - - + + + {{ 'Autorisé' | translate }} + + + {{ 'Obligatoire' | translate }} + + + {{ 'Interdit' | translate }} + +
@@ -318,14 +449,6 @@

{{ 'INGEST_CONTRACT.MODAL_CREATE.SIGNING_POLICY.TITLE' | translate }}

-
- -