Skip to content

Commit

Permalink
Story #13085: export and import signature parameters for ingest contr…
Browse files Browse the repository at this point in the history
…acts
  • Loading branch information
ebernard committed Jul 25, 2024
1 parent d79f2dd commit 37f81af
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.opencsv.bean.CsvBindAndSplitByName;
import com.opencsv.bean.CsvBindByName;
import com.opencsv.bean.CsvRecurse;
import fr.gouv.vitam.common.model.administration.ActivationStatus;
import fr.gouv.vitamui.commons.api.domain.IdDto;
import lombok.Getter;
Expand Down Expand Up @@ -115,5 +116,6 @@ public class IngestContractDto extends IdDto implements Serializable {
@CsvBindByName(column = "ComputedInheritedRulesAtIngest")
private boolean computeInheritedRulesAtIngest = false;

@CsvRecurse
private SignaturePolicyDto signaturePolicy;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,73 @@

package fr.gouv.vitamui.referential.common.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.opencsv.bean.CsvBindByName;
import fr.gouv.vitam.common.model.administration.SignaturePolicy;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.List;

@Data
@Accessors(chain = true)
public class SignaturePolicyDto {

private SignaturePolicy.SignedDocumentPolicyEnum signedDocument;
public static final String SIGNING_ROLE_SEPARATOR = "|";
public static final String SIGNING_ROLE_SEPARATOR_REGEX = "\\|";
public static final String SIGNING_ROLE_DECLARED_SIGNATURE = "DeclaredSignature";
public static final String SIGNING_ROLE_DECLARED_TIMESTAMP = "DeclaredTimestamp";
public static final String SIGNING_ROLE_DECLARED_ADDITIONAL_PROOF = "DeclaredAdditionalProof";

@CsvBindByName(column = "SignedDocument")
private SignaturePolicy.SignedDocumentPolicyEnum signedDocument = SignaturePolicy.SignedDocumentPolicyEnum.ALLOWED;

private Boolean declaredSignature;
private Boolean declaredTimestamp;
private Boolean declaredAdditionalProof;

/**
* This field is only used by OpenCSV
*/
@JsonIgnore
@CsvBindByName(column = "SigningRole")
private String signingRole;

/**
* Used by OpenCSV only
*/
public String getSigningRole() {
List<String> roles = new ArrayList<>();
if (Boolean.TRUE.equals(declaredSignature)) {
roles.add(SIGNING_ROLE_DECLARED_SIGNATURE);
}
if (Boolean.TRUE.equals(declaredTimestamp)) {
roles.add(SIGNING_ROLE_DECLARED_TIMESTAMP);
}
if (Boolean.TRUE.equals(declaredAdditionalProof)) {
roles.add(SIGNING_ROLE_DECLARED_ADDITIONAL_PROOF);
}
return String.join(SIGNING_ROLE_SEPARATOR, roles);
}

/**
* Used by OpenCSV only
*/
public void setSigningRole(String signingRole) {
String[] roles = signingRole.split(SIGNING_ROLE_SEPARATOR_REGEX);
for (String role : roles) {
switch (role) {
case SIGNING_ROLE_DECLARED_SIGNATURE:
declaredSignature = true;
break;
case SIGNING_ROLE_DECLARED_TIMESTAMP:
declaredTimestamp = true;
break;
case SIGNING_ROLE_DECLARED_ADDITIONAL_PROOF:
declaredAdditionalProof = true;
break;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Identifier;Name*;Description;Status;ArchiveProfiles;CheckParentLink;CheckParentId;LinkParentId;FormatUnidentifiedAuthorized;EveryFormatType;FormatType;ManagementContractId;ComputedInheritedRulesAtIngest;MasterMandatory;EveryDataObjectVersion;DataObjectVersion
;Contrat entrée Full;Contrats d'entrée full;ACTIVE;PR_000001|PR_000002|PR_000003;REQUIRED;;aeaqaaaabie64k3vabq2qalo2ok7oeqaaaaq;true;;;;;;true;
;Contrat d'entrée restreint finance;Lorem ipsum dolor sit amet, consectetur adipiscing elit.;INACTIVE;PR_000001;UNAUTHORIZED;aeaqaaaabie64k3vabq2qalo2ok7oeqaaaaq;;false;false;fmt/56|fmt/678|fmt/154;;true;false;false;BinaryMaster|PhysicalMaster
Identifier;Name*;Description;Status;ArchiveProfiles;CheckParentLink;CheckParentId;LinkParentId;FormatUnidentifiedAuthorized;EveryFormatType;FormatType;ManagementContractId;ComputedInheritedRulesAtIngest;MasterMandatory;EveryDataObjectVersion;DataObjectVersion;SignedDocument;SignedRole
;Contrat entrée Full;Contrats d'entrée full;ACTIVE;PR_000001|PR_000002|PR_000003;REQUIRED;;aeaqaaaabie64k3vabq2qalo2ok7oeqaaaaq;true;;;;;;true;ALLOWED;
;Contrat d'entrée restreint finance;"Lorem ipsum dolor sit amet, consectetur adipiscing elit.";INACTIVE;PR_000001;UNAUTHORIZED;aeaqaaaabie64k3vabq2qalo2ok7oeqaaaaq;;false;false;fmt/56|fmt/678|fmt/154;;true;false;false;BinaryMaster|PhysicalMaster;ALLOWED;DeclaredSignature|DeclaredTimestamp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class ExportIngestContracts extends ExportCSVParams {
private static final String DATA_OBJECT_VERSION = "DataObjectVersion";
private static final String ACTIVATION_DATE = "ActivationDate";
private static final String DESACTIVATION_DATE = "DesactivationDate";
private static final String SIGNED_DOCUMENT = "SignedDocument";
private static final String SIGNING_ROLE = "SigningRole";

public ExportIngestContracts() {
List<String> headers = List.of(
Expand All @@ -45,7 +47,9 @@ public ExportIngestContracts() {
EVERY_DATA_OBJECT_VERSION,
DATA_OBJECT_VERSION,
ACTIVATION_DATE,
DESACTIVATION_DATE
DESACTIVATION_DATE,
SIGNED_DOCUMENT,
SIGNING_ROLE
);
this.setHeaders(headers);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ private IngestContractCSVUtils() {}
public static final String MASTER_MANDATORY = "MasterMandatory";
public static final String EVERY_DATA_OBJECT_VERSION = "EveryDataObjectVersion";
public static final String DATA_OBJECT_VERSION = "DataObjectVersion";
public static final String SIGNED_DOCUMENT = "SignedDocument";
public static final String SIGNING_ROLE = "SigningRole";

public static void checkImportFile(MultipartFile ingestContractFile, boolean isIdentifierMandatory) {
checkImportFile(ingestContractFile, buildIngestContractColumns(isIdentifierMandatory));
Expand Down Expand Up @@ -156,6 +158,22 @@ private static List<ColumnDetails> buildIngestContractColumns(boolean isIdentifi
.mandatory(false)
.build()
);
expectedColumns.add(
ColumnDetails.builder()
.index(16)
.columnName(SIGNED_DOCUMENT)
.columnType(ColumnType.SIGNED_DOCUMENT_TYPE)
.mandatory(false)
.build()
);
expectedColumns.add(
ColumnDetails.builder()
.index(17)
.columnName(SIGNING_ROLE)
.columnType(ColumnType.SIGNING_ROLE_TYPE)
.mandatory(false)
.build()
);
return expectedColumns;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import fr.gouv.vitamui.referential.common.dsl.VitamQueryHelper;
import fr.gouv.vitamui.referential.common.dto.IngestContractDto;
import fr.gouv.vitamui.referential.common.dto.IngestContractResponseDto;
import fr.gouv.vitamui.referential.common.dto.SignaturePolicyDto;
import fr.gouv.vitamui.referential.common.service.IngestContractService;
import fr.gouv.vitamui.referential.internal.server.utils.ExportCSVUtils;
import fr.gouv.vitamui.referential.internal.server.utils.ImportCSVUtils;
Expand Down Expand Up @@ -508,6 +509,9 @@ private String[] buildIngestContractExportValues(
final var deactivationDate = ingestContract.getDeactivationDate() == null
? null
: df.format(LocalDateUtil.getDate(ingestContract.getDeactivationDate()));
final SignaturePolicyDto signaturePolicyDto = Optional.ofNullable(ingestContract.getSignaturePolicy()).orElse(
new SignaturePolicyDto()
);

return new String[] {
ingestContract.getIdentifier(),
Expand All @@ -526,6 +530,8 @@ private String[] buildIngestContractExportValues(
String.valueOf(ingestContract.isMasterMandatory()),
String.valueOf(ingestContract.isEveryDataObjectVersion()),
dataObjectVersion,
signaturePolicyDto.getSignedDocument().name(),
signaturePolicyDto.getSigningRole(),
activationDate,
deactivationDate,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
import fr.gouv.vitam.common.model.administration.ContextStatus;
import fr.gouv.vitam.common.model.administration.DataObjectVersionType;
import fr.gouv.vitam.common.model.administration.RuleType;
import fr.gouv.vitam.common.model.administration.SignaturePolicy;
import fr.gouv.vitamui.commons.api.dtos.ErrorImportFile;
import fr.gouv.vitamui.commons.api.enums.ErrorImportFileMessage;
import fr.gouv.vitamui.commons.api.exception.BadRequestException;
import fr.gouv.vitamui.commons.api.exception.InternalServerException;
import fr.gouv.vitamui.commons.utils.JsonUtils;
import fr.gouv.vitamui.referential.common.dto.SignaturePolicyDto;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -54,6 +56,8 @@ protected enum ColumnType {
RULE_TYPE,
DATA_OBJECT_VERSION_TYPE,
CHECK_PARENT_LINK_TYPE,
SIGNED_DOCUMENT_TYPE,
SIGNING_ROLE_TYPE,
}

protected static void checkImportFile(MultipartFile file, List<ColumnDetails> expectedColumns) {
Expand Down Expand Up @@ -326,6 +330,43 @@ private static void checkRow(
.build()
);
}

if (
!StringUtils.isBlank(value) &&
columnDetails.getColumnType().equals(ColumnType.SIGNED_DOCUMENT_TYPE) &&
!EnumUtils.isValidEnum(SignaturePolicy.SignedDocumentPolicyEnum.class, value)
) {
lineErrors.add(
ErrorImportFile.builder()
.column(numberToLetter(rowNumber))
.line(lineNumber)
.data(value)
.error(ErrorImportFileMessage.NOT_ALLOWED_VALUE)
.build()
);
}

if (!StringUtils.isBlank(value) && columnDetails.getColumnType().equals(ColumnType.SIGNING_ROLE_TYPE)) {
String[] roles = value.split(SignaturePolicyDto.SIGNING_ROLE_SEPARATOR_REGEX);
for (String role : roles) {
switch (role) {
case SignaturePolicyDto.SIGNING_ROLE_DECLARED_SIGNATURE:
case SignaturePolicyDto.SIGNING_ROLE_DECLARED_TIMESTAMP:
case SignaturePolicyDto.SIGNING_ROLE_DECLARED_ADDITIONAL_PROOF:
continue;
default:
lineErrors.add(
ErrorImportFile.builder()
.column(numberToLetter(rowNumber))
.line(lineNumber)
.data(role)
.error(ErrorImportFileMessage.NOT_ALLOWED_VALUE)
.build()
);
break;
}
}
}
}

private static char numberToLetter(int i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import fr.gouv.vitamui.iam.internal.client.ApplicationInternalRestClient;
import fr.gouv.vitamui.iam.security.service.InternalSecurityService;
import fr.gouv.vitamui.referential.common.dto.IngestContractDto;
import fr.gouv.vitamui.referential.common.dto.SignaturePolicyDto;
import fr.gouv.vitamui.referential.common.service.IngestContractService;
import fr.gouv.vitamui.referential.internal.server.ingestcontract.IngestContractConverter;
import fr.gouv.vitamui.referential.internal.server.ingestcontract.IngestContractInternalService;
Expand Down Expand Up @@ -541,6 +542,7 @@ public void export_should_return_ok() throws VitamClientException {
ingestContract.setMasterMandatory(true);
ingestContract.setEveryDataObjectVersion(true);
ingestContract.setDataObjectVersion(Set.of("PhysicalMaster"));
ingestContract.setSignaturePolicy(new SignaturePolicyDto());
ingestContract.setActivationDate("2023-12-31");
ingestContract.setDeactivationDate("2023-12-31");
List<IngestContractDto> ingestContracts = List.of(ingestContract);
Expand All @@ -563,8 +565,8 @@ public void export_should_return_ok() throws VitamClientException {
//Then
String result = asString(exportFile);
String whened =
"\uFEFF\"Identifier\";\"Name\";\"Description\";\"Status\";\"ArchiveProfiles\";\"CheckParentLink\";\"CheckParentId\";\"LinkParentId\";\"FormatUnidentifiedAuthorized\";\"EveryFormatType\";\"FormatType\";\"ManagementContractId\";\"ComputedInheritedRulesAtIngest\";\"MasterMandatory\";\"EveryDataObjectVersion\";\"DataObjectVersion\";\"ActivationDate\";\"DesactivationDate\"\n" +
"\"IC-000001\";\"Name\";\"Description\";\"ACTIVE\";\"PR-000001\";\"AUTHORIZED\";\"CheckParentId\";\"LinkParentId\";\"true\";\"true\";\"FormatType\";\"ManagementContractId\";\"true\";\"true\";\"true\";\"PhysicalMaster\";\"31/12/2023\";\"31/12/2023\"\n";
"\uFEFF\"Identifier\";\"Name\";\"Description\";\"Status\";\"ArchiveProfiles\";\"CheckParentLink\";\"CheckParentId\";\"LinkParentId\";\"FormatUnidentifiedAuthorized\";\"EveryFormatType\";\"FormatType\";\"ManagementContractId\";\"ComputedInheritedRulesAtIngest\";\"MasterMandatory\";\"EveryDataObjectVersion\";\"DataObjectVersion\";\"ActivationDate\";\"DesactivationDate\";\"SignedDocument\";\"SigningRole\"\n" +
"\"IC-000001\";\"Name\";\"Description\";\"ACTIVE\";\"PR-000001\";\"AUTHORIZED\";\"CheckParentId\";\"LinkParentId\";\"true\";\"true\";\"FormatType\";\"ManagementContractId\";\"true\";\"true\";\"true\";\"PhysicalMaster\";\"ALLOWED\";\"\";\"31/12/2023\";\"31/12/2023\"\n";
assertThat(result).isEqualTo(whened);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Identifier;Name*;Description;Status;ArchiveProfiles;CheckParentLink;CheckParentId;LinkParentId;FormatUnidentifiedAuthorized;EveryFormatType;FormatType;ManagementContractId;ComputedInheritedRulesAtIngest;MasterMandatory;EveryDataObjectVersion;DataObjectVersion
;Contrat entrée Full;Contrats d'entrée full;ACTIVE;PR_000001|PR_000003;REQUIRED;;aeaqaaaabie64k3vabq2qalo2ok7oeqaaaaq;false;;fmt/56|fmt/678|fmt/154;;false;;false;BinaryMaster|PhysicalMaster
Identifier;Name*;Description;Status;ArchiveProfiles;CheckParentLink;CheckParentId;LinkParentId;FormatUnidentifiedAuthorized;EveryFormatType;FormatType;ManagementContractId;ComputedInheritedRulesAtIngest;MasterMandatory;EveryDataObjectVersion;DataObjectVersion;SignedDocument;SigningRole
;Contrat entrée Full;Contrats d'entrée full;ACTIVE;PR_000001|PR_000003;REQUIRED;;aeaqaaaabie64k3vabq2qalo2ok7oeqaaaaq;false;;fmt/56|fmt/678|fmt/154;;false;;false;BinaryMaster|PhysicalMaster;ALLOWED;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Identifier;Name*;Description;Status;ArchiveProfiles;CheckParentLink;CheckParentId;LinkParentId;FormatUnidentifiedAuthorized;EveryFormatType;FormatType;ManagementContractId;ComputedInheritedRulesAtIngest;MasterMandatory;EveryDataObjectVersion;DataObjectVersion
MONCONTRAT01;Contrat entrée Full;Contrats d'entrée full;ACTIVE;;REQUIRED;;;false;;fmt/56|fmt/678|fmt/154;;false;;false;BinaryMaster|PhysicalMaster
MONCONTRAT02;Contrat d'entrée finances;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis gravida sit amet lorem ut porta. In commodo justo sed tincidunt laoreet. Integer tellus quam, dictum non consequat id, varius at dui.;INACTIVE;;;;;;true;;;true;false;true;
MONCONTRAT03;Contrat d'entrée santé;Contrat d'entrée santé ;;;;;;true;true;;;true;false;;Thumbnail
MONCONTRAT04;Contrat d'entrée gestion commerciale;;ACTIVE;;UNAUTHORIZED;;;true;true;;;;;true;
Identifier;Name*;Description;Status;ArchiveProfiles;CheckParentLink;CheckParentId;LinkParentId;FormatUnidentifiedAuthorized;EveryFormatType;FormatType;ManagementContractId;ComputedInheritedRulesAtIngest;MasterMandatory;EveryDataObjectVersion;DataObjectVersion;SignedDocument;SigningRole
MONCONTRAT01;Contrat entrée Full;Contrats d'entrée full;ACTIVE;;REQUIRED;;;false;;fmt/56|fmt/678|fmt/154;;false;;false;BinaryMaster|PhysicalMaster;ALLOWED;
MONCONTRAT02;Contrat d'entrée finances;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis gravida sit amet lorem ut porta. In commodo justo sed tincidunt laoreet. Integer tellus quam, dictum non consequat id, varius at dui.;INACTIVE;;;;;;true;;;true;false;true;;ALLOWED;DeclaredSignature|DeclaredTimestamp
MONCONTRAT03;Contrat d'entrée santé;Contrat d'entrée santé ;;;;;;true;true;;;true;false;;Thumbnail;MANDATORY;DeclaredSignature|DeclaredTimestamp
MONCONTRAT04;Contrat d'entrée gestion commerciale;;ACTIVE;;UNAUTHORIZED;;;true;true;;;;;true;;MANDATORY;

0 comments on commit 37f81af

Please sign in to comment.