From 97960d8ed72f643dfd3299eed45b242a9b30da7e Mon Sep 17 00:00:00 2001 From: Kresnadi Budisantoso Date: Tue, 28 Nov 2023 17:33:28 +0100 Subject: [PATCH 1/3] RED-7962 Fixes error 500 that occurred because of the rule file type parameter that was not removed by mistake Also adjusted the audit log message if 'dryRun' was set to `true`. --- .../api/impl/controller/DossierTemplateControllerV2.java | 5 ++--- .../v2/api/external/resource/DossierTemplateResource.java | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/persistence-service-v1/persistence-service-external-api-impl-v2/src/main/java/com/iqser/red/persistence/service/v2/external/api/impl/controller/DossierTemplateControllerV2.java b/persistence-service-v1/persistence-service-external-api-impl-v2/src/main/java/com/iqser/red/persistence/service/v2/external/api/impl/controller/DossierTemplateControllerV2.java index 145bb8012..7a3b3c735 100644 --- a/persistence-service-v1/persistence-service-external-api-impl-v2/src/main/java/com/iqser/red/persistence/service/v2/external/api/impl/controller/DossierTemplateControllerV2.java +++ b/persistence-service-v1/persistence-service-external-api-impl-v2/src/main/java/com/iqser/red/persistence/service/v2/external/api/impl/controller/DossierTemplateControllerV2.java @@ -101,8 +101,7 @@ public class DossierTemplateControllerV2 implements DossierTemplateResource { @PreAuthorize("hasAuthority('" + READ_RULES + "')") - public ResponseEntity downloadComponentRules(@PathVariable(DOSSIER_TEMPLATE_ID_PARAM) String dossierTemplateId, - @PathVariable(RULE_FILE_TYPE_PARAMETER_NAME) RuleFileType ruleFileType) { + public ResponseEntity downloadComponentRules(@PathVariable(DOSSIER_TEMPLATE_ID_PARAM) String dossierTemplateId) { return downloadRules(dossierTemplateId, RuleFileType.COMPONENT); } @@ -166,7 +165,7 @@ public class DossierTemplateControllerV2 implements DossierTemplateResource { .userId(KeycloakSecurity.getUserId()) .objectId(rulesUploadRequest.getDossierTemplateId()) .category(AuditCategory.DOSSIER_TEMPLATE.name()) - .message(String.format("%s Rules have been updated", rulesUploadRequest.getRuleFileType())) + .message(String.format("%s rules have been %s", rulesUploadRequest.getRuleFileType(), dryRun ? "validated" : "updated")) .build()); // TODO Add warning and deprecations to response diff --git a/persistence-service-v1/persistence-service-external-api-v2/src/main/java/com/iqser/red/service/persistence/service/v2/api/external/resource/DossierTemplateResource.java b/persistence-service-v1/persistence-service-external-api-v2/src/main/java/com/iqser/red/service/persistence/service/v2/api/external/resource/DossierTemplateResource.java index 616e76bb1..baf1fbb98 100644 --- a/persistence-service-v1/persistence-service-external-api-v2/src/main/java/com/iqser/red/service/persistence/service/v2/api/external/resource/DossierTemplateResource.java +++ b/persistence-service-v1/persistence-service-external-api-v2/src/main/java/com/iqser/red/service/persistence/service/v2/api/external/resource/DossierTemplateResource.java @@ -67,7 +67,7 @@ public interface DossierTemplateResource { @ResponseBody @ResponseStatus(value = HttpStatus.OK) - @Operation(summary = "Returns file containing the currently used Drools rules.") + @Operation(summary = "Returns file containing the currently used entity rules.") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) @GetMapping(value = PATH + DOSSIER_TEMPLATE_ID_PATH_VARIABLE + ENTITY_RULES_PATH, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) ResponseEntity downloadEntityRules(@PathVariable(DOSSIER_TEMPLATE_ID_PARAM) String dossierTemplateId); @@ -84,10 +84,10 @@ public interface DossierTemplateResource { @ResponseBody @ResponseStatus(value = HttpStatus.OK) - @Operation(summary = "Returns file containing the currently used Drools rules.") + @Operation(summary = "Returns file containing the currently used component rules.") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) @GetMapping(value = PATH + DOSSIER_TEMPLATE_ID_PATH_VARIABLE + COMPONENT_RULES_PATH, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) - ResponseEntity downloadComponentRules(@PathVariable(DOSSIER_TEMPLATE_ID_PARAM) String dossierTemplateId, @PathVariable(RULE_FILE_TYPE_PARAMETER_NAME) RuleFileType ruleFileType); + ResponseEntity downloadComponentRules(@PathVariable(DOSSIER_TEMPLATE_ID_PARAM) String dossierTemplateId); @Operation(summary = "Get the file attribute definitions of a DossierTemplate.", description = "None") @GetMapping(value = PATH + DOSSIER_TEMPLATE_ID_PATH_VARIABLE + FILE_ATTRIBUTE_DEFINITIONS_PATH, produces = MediaType.APPLICATION_JSON_VALUE) From 0013b5d1169b122a2be61c43904269aa06aba459 Mon Sep 17 00:00:00 2001 From: Kresnadi Budisantoso Date: Tue, 28 Nov 2023 21:38:38 +0100 Subject: [PATCH 2/3] RED-7962 Improved response of endpoint to get file attributes Added CSV settings. --- .../DossierTemplateControllerV2.java | 12 ++- .../model/FileAttributeDefinitionList.java | 30 +++++++ .../src/main/resources/api/openapi.yaml | 89 ++++++++++++++----- .../FileAttributesManagementService.java | 8 +- 4 files changed, 110 insertions(+), 29 deletions(-) diff --git a/persistence-service-v1/persistence-service-external-api-impl-v2/src/main/java/com/iqser/red/persistence/service/v2/external/api/impl/controller/DossierTemplateControllerV2.java b/persistence-service-v1/persistence-service-external-api-impl-v2/src/main/java/com/iqser/red/persistence/service/v2/external/api/impl/controller/DossierTemplateControllerV2.java index 7a3b3c735..3acc71331 100644 --- a/persistence-service-v1/persistence-service-external-api-impl-v2/src/main/java/com/iqser/red/persistence/service/v2/external/api/impl/controller/DossierTemplateControllerV2.java +++ b/persistence-service-v1/persistence-service-external-api-impl-v2/src/main/java/com/iqser/red/persistence/service/v2/external/api/impl/controller/DossierTemplateControllerV2.java @@ -111,7 +111,13 @@ public class DossierTemplateControllerV2 implements DossierTemplateResource { var fileAttributeConfigs = fileAttributesController.getFileAttributesConfiguration(dossierTemplateId); - return new FileAttributeDefinitionList(fileAttributeConfigs.getFileAttributeConfigs().stream() + var csvImportSettings = FileAttributeDefinitionList.CsvImportSettings.builder() + .encoding(fileAttributeConfigs.getEncoding()) + .delimiter(fileAttributeConfigs.getDelimiter()) + .filenameMappingCsvColumnHeader(fileAttributeConfigs.getFilenameMappingColumnHeaderName()) + .build(); + + var fileAttributeDefinitions = fileAttributeConfigs.getFileAttributeConfigs().stream() .map(fileAttributeConfig -> FileAttributeDefinition.builder() .id(fileAttributeConfig.getId()) .name(fileAttributeConfig.getLabel()) @@ -125,7 +131,9 @@ public class DossierTemplateControllerV2 implements DossierTemplateResource { .displayedInFileList(fileAttributeConfig.isDisplayedInFileList()) .build()) .build()) - .toList()); + .toList(); + + return new FileAttributeDefinitionList(csvImportSettings, fileAttributeDefinitions); } @SneakyThrows diff --git a/persistence-service-v1/persistence-service-external-api-v2/src/main/java/com/iqser/red/service/persistence/service/v2/api/external/model/FileAttributeDefinitionList.java b/persistence-service-v1/persistence-service-external-api-v2/src/main/java/com/iqser/red/service/persistence/service/v2/api/external/model/FileAttributeDefinitionList.java index 0cb14fc28..c56ee21f9 100644 --- a/persistence-service-v1/persistence-service-external-api-v2/src/main/java/com/iqser/red/service/persistence/service/v2/api/external/model/FileAttributeDefinitionList.java +++ b/persistence-service-v1/persistence-service-external-api-v2/src/main/java/com/iqser/red/service/persistence/service/v2/api/external/model/FileAttributeDefinitionList.java @@ -1,8 +1,13 @@ package com.iqser.red.service.persistence.service.v2.api.external.model; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; +import org.apache.commons.lang3.StringUtils; + +import com.fasterxml.jackson.annotation.JsonProperty; + import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -14,6 +19,31 @@ import lombok.NoArgsConstructor; @AllArgsConstructor public class FileAttributeDefinitionList { + private CsvImportSettings csvImportSettings; + @Builder.Default private List fileAttributeDefinitions = new ArrayList<>(); + + + @Data + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class CsvImportSettings { + + private String filenameMappingCsvColumnHeader; + + @Builder.Default + private String delimiter = ","; + + @Builder.Default + private String encoding = StandardCharsets.UTF_8.name(); + + // TODO: make csvMappingActive a persistent value instead of a transient one when implementing the endpoint to set the csv mapping + @JsonProperty("csvMappingActive") + public boolean isCsvMappingActive() { + return StringUtils.isBlank(filenameMappingCsvColumnHeader); + } + + } } diff --git a/persistence-service-v1/persistence-service-external-api-v2/src/main/resources/api/openapi.yaml b/persistence-service-v1/persistence-service-external-api-v2/src/main/resources/api/openapi.yaml index 6b38199ef..2101e8000 100644 --- a/persistence-service-v1/persistence-service-external-api-v2/src/main/resources/api/openapi.yaml +++ b/persistence-service-v1/persistence-service-external-api-v2/src/main/resources/api/openapi.yaml @@ -1460,25 +1460,25 @@ components: primaryAttribute: type: boolean description: | - If true, the RedactManager and DocuMine user interfaces show the value of the file attribute in the file list below the file name. + If `true`, the RedactManager and DocuMine user interfaces show the value of the file attribute in the file list below the file name. editable: type: boolean description: | - If true, the RedactManager and DocuMine user interfaces allow manual editing of the value. Otherwise only importing and setting by rules would be possible. + If `true`, the RedactManager and DocuMine user interfaces allow manual editing of the value. Otherwise only importing and setting by rules would be possible. filterable: type: boolean description: | - If true, the RedactManager and DocuMine user interfaces add filter options to the file list. + If `true`, the RedactManager and DocuMine user interfaces add filter options to the file list. displayedInFileList: type: boolean description: | - if true, the RedactManager and DocuMine user interfaces show the values in the file list. + if `true`, the RedactManager and DocuMine user interfaces show the values in the file list. required: - primaryAttribute - editable - filterable - displayedInFileList - example: : + example: primaryAttribute: false editable: true filterable: true @@ -1487,30 +1487,71 @@ components: type: object description: A list of file attribute definitions. properties: + csvImportSettings: + $ref: '#/components/schemas/CsvImportSettings' fileAttributeDefinitions: items: $ref: '#/components/schemas/FileAttributeDefinition' type: array example: - - id: "123e4567-e89b-12d3-a456-426614174000" - name: "Document Type" - type: "TEXT" - mappedCsvColumnHeader: "DocumentCategory" - reportingPlaceholder: "{{file.attribute.DocumentType}}" - displaySettings: - primaryAttribute: true - editable: true - filterable: true - displayedInFileList: false - - id: "23e45678-e90b-12d3-a456-765114174321" - name: "Comment" - type: "TEXT" - reportingPlaceholder: "{{file.attribute.Comment}}" - displaySettings: - primaryAttribute: false - editable: true - filterable: false - displayedInFileList: false + csvImportSettings: + csvMappingActive: true + filenameMappingCsvColumnHeader: "Filename" + delimiter: "," + encoding: "UTF-8" + fileAttributeDefinitions: + - id: "123e4567-e89b-12d3-a456-426614174000" + name: "Document Type" + type: "TEXT" + mappedCsvColumnHeader: "DocumentCategory" + reportingPlaceholder: "{{file.attribute.DocumentType}}" + displaySettings: + primaryAttribute: true + editable: true + filterable: true + displayedInFileList: false + - id: "23e45678-e90b-12d3-a456-765114174321" + name: "Comment" + type: "TEXT" + reportingPlaceholder: "{{file.attribute.Comment}}" + displaySettings: + primaryAttribute: false + editable: true + filterable: false + displayedInFileList: false + CsvImportSettings: + type: object + description: | + This object defines the settings for importing data from a CSV file. It includes + information that indicates if the CSV mapping is active, specifies the column header + used for filename matching, sets the delimiter for column separation, and determines + the encoding of the CSV file. These settings are crucial for accurately importing and + mapping file attributes based on the corresponding CSV records. + properties: + csvMappingActive: + type: boolean + description: | + If `true`, the CSV mapping is active. + filenameMappingCsvColumnHeader: + type: string + description: | + The header of a specific column in the CSV file that should contain values + matching the filenames. A matching value identifies the record that is used + to import the mapped file attributes. + delimiter: + type: string + maxLength: 1 + description: | + The delimiter of the CSV file that is used to distinguish different columns. + encoding: + type: string + description: | + The encoding of the CSV file that is expected when uploading for the import of file attributes. + example: + csvMappingActive: true + filenameMappingCsvColumnHeader: "Filename" + delimiter: "," + encoding: "UTF-8" Dossier: type: object description: | diff --git a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/FileAttributesManagementService.java b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/FileAttributesManagementService.java index 492186678..cc7f9f3bb 100644 --- a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/FileAttributesManagementService.java +++ b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/FileAttributesManagementService.java @@ -148,12 +148,14 @@ public class FileAttributesManagementService { } - private Charset parseEncoding(String encoding) { + public static Charset parseEncoding(String encoding) { - if (ASCII_ENCODING.equalsIgnoreCase(encoding)) { + // accept both "ASCII" (historical name) and the actual name "US-ASCII" of the charset + if (ASCII_ENCODING.equalsIgnoreCase(encoding) || StandardCharsets.US_ASCII.name().equalsIgnoreCase(encoding)) { return StandardCharsets.US_ASCII; } - if (ISO_ENCODING.equalsIgnoreCase(encoding)) { + // accept both "ISO" (non-unique name) and the actual name "US-ASCII" of the charset + if (ISO_ENCODING.equalsIgnoreCase(encoding) || StandardCharsets.ISO_8859_1.name().equalsIgnoreCase(encoding)) { return StandardCharsets.ISO_8859_1; } return StandardCharsets.UTF_8; From 06d3b282cc20a4903debaf22ac169e75cf2c6e12 Mon Sep 17 00:00:00 2001 From: Kresnadi Budisantoso Date: Tue, 28 Nov 2023 23:50:38 +0100 Subject: [PATCH 3/3] RED-7962 Updated platform dependency to 2.20.0 --- persistence-service-v1/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistence-service-v1/pom.xml b/persistence-service-v1/pom.xml index 8cae651b1..93c2196eb 100755 --- a/persistence-service-v1/pom.xml +++ b/persistence-service-v1/pom.xml @@ -6,7 +6,7 @@ com.iqser.red platform-dependency - 2.19.0 + 2.20.0