From 5c56566c0c2ee30e5fbe764d0b4f4776e68c0ae1 Mon Sep 17 00:00:00 2001 From: oussamasic <oussamazerouali42@gmail.com> Date: Wed, 1 Dec 2021 11:38:23 +0100 Subject: [PATCH] correct code review --- .../dto/VitamUiManagementMetadataAction.java | 2 +- .../search/common/dto/VitamUiRuleActions.java | 11 +++---- .../archives/search/common/rest/RestApi.java | 2 +- .../ArchiveSearchExternalRestClient.java | 2 +- .../ArchivesSearchExternalController.java | 2 +- .../ArchivesSearchExternalControllerTest.java | 4 ++- .../client/ArchiveInternalRestClient.java | 2 +- .../rest/ArchiveSearchInternalController.java | 2 +- .../converter/RuleOperationsConverter.java | 4 +-- .../service/ArchiveSearchInternalService.java | 2 +- ...earchAppraisalQueryBuilderServiceTest.java | 32 +++++++++++++++++++ .../queries/vitam_query_with_start_date.txt | 1 + .../search/rest/ArchivesSearchController.java | 2 +- .../appraisal-rule-search.component.html | 3 +- .../archive-search/src/assets/i18n/fr.json | 2 +- 15 files changed, 54 insertions(+), 19 deletions(-) create mode 100644 api/api-archive-search/archive-search-internal/src/test/resources/data/queries/vitam_query_with_start_date.txt diff --git a/api/api-archive-search/archive-search-commons/src/main/java/fr/gouv/vitamui/archives/search/common/dto/VitamUiManagementMetadataAction.java b/api/api-archive-search/archive-search-commons/src/main/java/fr/gouv/vitamui/archives/search/common/dto/VitamUiManagementMetadataAction.java index 5ae6eaa67..afde79b82 100644 --- a/api/api-archive-search/archive-search-commons/src/main/java/fr/gouv/vitamui/archives/search/common/dto/VitamUiManagementMetadataAction.java +++ b/api/api-archive-search/archive-search-commons/src/main/java/fr/gouv/vitamui/archives/search/common/dto/VitamUiManagementMetadataAction.java @@ -54,5 +54,5 @@ import java.io.Serializable; @Getter public class VitamUiManagementMetadataAction implements Serializable { - String archiveUnitProfile; + private String archiveUnitProfile; } diff --git a/api/api-archive-search/archive-search-commons/src/main/java/fr/gouv/vitamui/archives/search/common/dto/VitamUiRuleActions.java b/api/api-archive-search/archive-search-commons/src/main/java/fr/gouv/vitamui/archives/search/common/dto/VitamUiRuleActions.java index ad195e8b1..b8f881d67 100644 --- a/api/api-archive-search/archive-search-commons/src/main/java/fr/gouv/vitamui/archives/search/common/dto/VitamUiRuleActions.java +++ b/api/api-archive-search/archive-search-commons/src/main/java/fr/gouv/vitamui/archives/search/common/dto/VitamUiRuleActions.java @@ -58,15 +58,14 @@ import static com.fasterxml.jackson.annotation.JsonInclude.Include.ALWAYS; @Getter public class VitamUiRuleActions implements Serializable { + private List<Map<String, VitamUiRuleCategoryAction>> add = new ArrayList<>(); - List<Map<String, VitamUiRuleCategoryAction>> add = new ArrayList<>(); - - List<Map<String, VitamUiRuleCategoryAction>> update = new ArrayList<>(); + private List<Map<String, VitamUiRuleCategoryAction>> update = new ArrayList<>(); @JsonInclude(ALWAYS) - List<Map<String, VitamUiRuleCategoryActionDeletion>> delete = new ArrayList<>(); + private List<Map<String, VitamUiRuleCategoryActionDeletion>> delete = new ArrayList<>(); - VitamUiManagementMetadataAction addOrUpdateMetadata; + private VitamUiManagementMetadataAction addOrUpdateMetadata; - VitamUiManagementMetadataAction deleteMetadata; + private VitamUiManagementMetadataAction deleteMetadata; } diff --git a/api/api-archive-search/archive-search-commons/src/main/java/fr/gouv/vitamui/archives/search/common/rest/RestApi.java b/api/api-archive-search/archive-search-commons/src/main/java/fr/gouv/vitamui/archives/search/common/rest/RestApi.java index 444186852..806344875 100644 --- a/api/api-archive-search/archive-search-commons/src/main/java/fr/gouv/vitamui/archives/search/common/rest/RestApi.java +++ b/api/api-archive-search/archive-search-commons/src/main/java/fr/gouv/vitamui/archives/search/common/rest/RestApi.java @@ -40,5 +40,5 @@ public class RestApi { public static final String EXPORT_DIP = "/export-dip"; public static final String ELIMINATION_ANALYSIS = "/elimination/analysis"; public static final String ELIMINATION_ACTION = "/elimination/action"; - public static final String MASSUPDATEUNITSRULES = "/units/rules"; + public static final String MASS_UPDATE_UNITS_RULES = "/units/rules"; } diff --git a/api/api-archive-search/archive-search-external-client/src/main/java/fr/gouv/vitamui/archives/search/external/client/ArchiveSearchExternalRestClient.java b/api/api-archive-search/archive-search-external-client/src/main/java/fr/gouv/vitamui/archives/search/external/client/ArchiveSearchExternalRestClient.java index 9919dd49b..5e08fcf9a 100644 --- a/api/api-archive-search/archive-search-external-client/src/main/java/fr/gouv/vitamui/archives/search/external/client/ArchiveSearchExternalRestClient.java +++ b/api/api-archive-search/archive-search-external-client/src/main/java/fr/gouv/vitamui/archives/search/external/client/ArchiveSearchExternalRestClient.java @@ -190,7 +190,7 @@ public class ArchiveSearchExternalRestClient MultiValueMap<String, String> headers = buildSearchHeaders(context); final HttpEntity<RuleSearchCriteriaDto> request = new HttpEntity<>(ruleSearchCriteriaDto, headers); final ResponseEntity<String> response = - restTemplate.exchange(getUrl() + RestApi.MASSUPDATEUNITSRULES, HttpMethod.POST, + restTemplate.exchange(getUrl() + RestApi.MASS_UPDATE_UNITS_RULES, HttpMethod.POST, request, String.class); return response; } diff --git a/api/api-archive-search/archive-search-external/src/main/java/fr/gouv/vitamui/archives/search/external/server/rest/ArchivesSearchExternalController.java b/api/api-archive-search/archive-search-external/src/main/java/fr/gouv/vitamui/archives/search/external/server/rest/ArchivesSearchExternalController.java index 66feb9406..206142db3 100644 --- a/api/api-archive-search/archive-search-external/src/main/java/fr/gouv/vitamui/archives/search/external/server/rest/ArchivesSearchExternalController.java +++ b/api/api-archive-search/archive-search-external/src/main/java/fr/gouv/vitamui/archives/search/external/server/rest/ArchivesSearchExternalController.java @@ -152,7 +152,7 @@ public class ArchivesSearchExternalController { return archivesSearchExternalService.startEliminationAction(query); } - @PostMapping(RestApi.MASSUPDATEUNITSRULES) + @PostMapping(RestApi.MASS_UPDATE_UNITS_RULES) @Secured(ServicesData.ROLE_UPDATE_MANAGEMENT_RULES) public String updateArchiveUnitsRules(final @RequestBody RuleSearchCriteriaDto ruleSearchCriteriaDto) { LOGGER.info("Calling Update Archive Units Rules By Criteria {} ", ruleSearchCriteriaDto); diff --git a/api/api-archive-search/archive-search-external/src/test/java/fr/gouv/vitamui/archives/search/external/server/rest/ArchivesSearchExternalControllerTest.java b/api/api-archive-search/archive-search-external/src/test/java/fr/gouv/vitamui/archives/search/external/server/rest/ArchivesSearchExternalControllerTest.java index f2042921d..99c63a43b 100644 --- a/api/api-archive-search/archive-search-external/src/test/java/fr/gouv/vitamui/archives/search/external/server/rest/ArchivesSearchExternalControllerTest.java +++ b/api/api-archive-search/archive-search-external/src/test/java/fr/gouv/vitamui/archives/search/external/server/rest/ArchivesSearchExternalControllerTest.java @@ -72,6 +72,8 @@ public class ArchivesSearchExternalControllerTest extends ApiArchiveSearchExtern public final String ARCHIVE_UNITS_RESULTS_CSV = "data/vitam_archive_units_response.csv"; + public final String EXPECTED_RESPONSE = "expected_response"; + @MockBean private ArchivesSearchExternalService archivesSearchExternalService; @@ -199,7 +201,7 @@ public class ArchivesSearchExternalControllerTest extends ApiArchiveSearchExtern public void testArchiveUnitsRulesMassUpdateResultsThanReturnVitamOperationId() { RuleSearchCriteriaDto ruleSearchCriteriaDto = new RuleSearchCriteriaDto(); - String expectedResponse = new String(); + String expectedResponse = EXPECTED_RESPONSE; Mockito .when(archivesSearchExternalService.updateArchiveUnitsRules(Mockito.eq(ruleSearchCriteriaDto))) diff --git a/api/api-archive-search/archive-search-internal-client/src/main/java/fr/gouv/archive/internal/client/ArchiveInternalRestClient.java b/api/api-archive-search/archive-search-internal-client/src/main/java/fr/gouv/archive/internal/client/ArchiveInternalRestClient.java index b9c152425..42fa540a0 100644 --- a/api/api-archive-search/archive-search-internal-client/src/main/java/fr/gouv/archive/internal/client/ArchiveInternalRestClient.java +++ b/api/api-archive-search/archive-search-internal-client/src/main/java/fr/gouv/archive/internal/client/ArchiveInternalRestClient.java @@ -204,7 +204,7 @@ public class ArchiveInternalRestClient MultiValueMap<String, String> headers = buildSearchHeaders(context); final HttpEntity<RuleSearchCriteriaDto> request = new HttpEntity<>(ruleSearchCriteriaDto, headers); final ResponseEntity<String> response = - restTemplate.exchange(getUrl() + RestApi.MASSUPDATEUNITSRULES, HttpMethod.POST, + restTemplate.exchange(getUrl() + RestApi.MASS_UPDATE_UNITS_RULES, HttpMethod.POST, request, String.class); checkResponse(response); return response.getBody(); diff --git a/api/api-archive-search/archive-search-internal/src/main/java/fr/gouv/vitamui/archive/internal/server/rest/ArchiveSearchInternalController.java b/api/api-archive-search/archive-search-internal/src/main/java/fr/gouv/vitamui/archive/internal/server/rest/ArchiveSearchInternalController.java index cb2ba96fb..808688860 100644 --- a/api/api-archive-search/archive-search-internal/src/main/java/fr/gouv/vitamui/archive/internal/server/rest/ArchiveSearchInternalController.java +++ b/api/api-archive-search/archive-search-internal/src/main/java/fr/gouv/vitamui/archive/internal/server/rest/ArchiveSearchInternalController.java @@ -227,7 +227,7 @@ public class ArchiveSearchInternalController { return jsonNode; } - @PostMapping(RestApi.MASSUPDATEUNITSRULES) + @PostMapping(RestApi.MASS_UPDATE_UNITS_RULES) public ResponseEntity<String> updateArchiveUnitsRules( @RequestHeader(value = CommonConstants.X_TENANT_ID_HEADER) final Integer tenantId, @RequestHeader(value = CommonConstants.X_ACCESS_CONTRACT_ID_HEADER) final String accessContractId, diff --git a/api/api-archive-search/archive-search-internal/src/main/java/fr/gouv/vitamui/archive/internal/server/rulesupdate/converter/RuleOperationsConverter.java b/api/api-archive-search/archive-search-internal/src/main/java/fr/gouv/vitamui/archive/internal/server/rulesupdate/converter/RuleOperationsConverter.java index ede2340c0..dee1483e2 100644 --- a/api/api-archive-search/archive-search-internal/src/main/java/fr/gouv/vitamui/archive/internal/server/rulesupdate/converter/RuleOperationsConverter.java +++ b/api/api-archive-search/archive-search-internal/src/main/java/fr/gouv/vitamui/archive/internal/server/rulesupdate/converter/RuleOperationsConverter.java @@ -52,6 +52,7 @@ import fr.gouv.vitamui.archives.search.common.dto.VitamUiRuleCategoryAction; import fr.gouv.vitamui.archives.search.common.dto.VitamUiRuleCategoryActionDeletion; import fr.gouv.vitamui.commons.utils.VitamUIUtils; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.Setter; import java.time.LocalDateTime; @@ -65,10 +66,9 @@ import java.util.Map; */ @Getter @Setter +@NoArgsConstructor public class RuleOperationsConverter { - public RuleOperationsConverter() { - } public ManagementMetadataAction convertToVitamManagementMetadataAction( VitamUiManagementMetadataAction vitamUiManagementMetadataAction) { diff --git a/api/api-archive-search/archive-search-internal/src/main/java/fr/gouv/vitamui/archive/internal/server/service/ArchiveSearchInternalService.java b/api/api-archive-search/archive-search-internal/src/main/java/fr/gouv/vitamui/archive/internal/server/service/ArchiveSearchInternalService.java index a5b72aa81..7edc51def 100644 --- a/api/api-archive-search/archive-search-internal/src/main/java/fr/gouv/vitamui/archive/internal/server/service/ArchiveSearchInternalService.java +++ b/api/api-archive-search/archive-search-internal/src/main/java/fr/gouv/vitamui/archive/internal/server/service/ArchiveSearchInternalService.java @@ -703,7 +703,7 @@ public class ArchiveSearchInternalService { objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); JsonNode updateQuery = objectMapper.convertValue(massUpdateUnitRuleRequest, JsonNode.class); - LOGGER.info("Add Rules to UA final updateQuery : {}", updateQuery); + LOGGER.debug("Add Rules to UA final updateQuery : {}", updateQuery); return massUpdateUnitsRules(vitamContext, updateQuery); } diff --git a/api/api-archive-search/archive-search-internal/src/test/java/fr/gouv/vitamui/archive/internal/server/service/ArchivesSearchAppraisalQueryBuilderServiceTest.java b/api/api-archive-search/archive-search-internal/src/test/java/fr/gouv/vitamui/archive/internal/server/service/ArchivesSearchAppraisalQueryBuilderServiceTest.java index 282df05e0..ac86a0ff0 100644 --- a/api/api-archive-search/archive-search-internal/src/test/java/fr/gouv/vitamui/archive/internal/server/service/ArchivesSearchAppraisalQueryBuilderServiceTest.java +++ b/api/api-archive-search/archive-search-internal/src/test/java/fr/gouv/vitamui/archive/internal/server/service/ArchivesSearchAppraisalQueryBuilderServiceTest.java @@ -31,6 +31,7 @@ import com.fasterxml.jackson.databind.JsonNode; import fr.gouv.vitam.common.PropertiesUtils; import fr.gouv.vitam.common.database.builder.query.BooleanQuery; import fr.gouv.vitam.common.database.builder.request.exception.InvalidCreateOperationException; +import fr.gouv.vitam.common.exception.InvalidParseOperationException; import fr.gouv.vitam.common.json.JsonHandler; import fr.gouv.vitamui.archives.search.common.common.ArchiveSearchConsts; import fr.gouv.vitamui.archives.search.common.dto.CriteriaValue; @@ -38,6 +39,7 @@ import fr.gouv.vitamui.archives.search.common.dto.SearchCriteriaEltDto; import fr.gouv.vitamui.commons.api.logger.VitamUILogger; import fr.gouv.vitamui.commons.api.logger.VitamUILoggerFactory; import fr.gouv.vitamui.commons.test.utils.ServerIdentityConfigurationBuilder; +import org.json.JSONException; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -47,6 +49,7 @@ import org.skyscreamer.jsonassert.JSONAssert; import org.springframework.test.context.junit.jupiter.SpringExtension; import java.io.BufferedReader; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -444,6 +447,35 @@ public class ArchivesSearchAppraisalQueryBuilderServiceTest { JsonNode expectedQuery = JsonHandler.getFromFile(PropertiesUtils.findFile("data/queries/elimination_analysis_search.json")); JSONAssert.assertEquals(expectedQuery.toPrettyString(), JsonHandler.getFromString(query.toString()).toPrettyString(), true); + + } + + @Test + public void testFillQueryFromCriteriaListWhenAppraisalMgtRulesHasStartDateForControlThenReturnTheExactQuery() + throws InvalidCreateOperationException, IOException { + + //Given + List<SearchCriteriaEltDto> criteriaList = new ArrayList<>(); + SearchCriteriaEltDto searchCriteriaEltDto = new SearchCriteriaEltDto(); + searchCriteriaEltDto.setCriteria(ArchiveSearchConsts.APPRAISAL_RULE_START_DATE); + searchCriteriaEltDto.setCategory(ArchiveSearchConsts.CriteriaCategory.FIELDS); + searchCriteriaEltDto.setValues(List.of(new CriteriaValue("2021-11-08T23:00:00.000Z"))); + searchCriteriaEltDto.setOperator(ArchiveSearchConsts.CriteriaOperators.EQ.name()); + criteriaList.add(searchCriteriaEltDto); + + //When + BooleanQuery query = and(); + archivesSearchFieldsQueryBuilderService + .fillQueryFromCriteriaList(query, criteriaList); + + //then + Assertions.assertFalse(query.getQueries().isEmpty()); + Assertions.assertEquals(query.getQueries().size(), 1); + String queryStr = query.getQueries().toString(); + LOGGER.info(queryStr); + String queryFileStr = loadFileContent("vitam_query_with_start_date.txt"); + Assertions.assertEquals(queryStr.trim(), queryFileStr.trim()); + } private String loadFileContent(String filename) throws IOException { diff --git a/api/api-archive-search/archive-search-internal/src/test/resources/data/queries/vitam_query_with_start_date.txt b/api/api-archive-search/archive-search-internal/src/test/resources/data/queries/vitam_query_with_start_date.txt new file mode 100644 index 000000000..d67675269 --- /dev/null +++ b/api/api-archive-search/archive-search-internal/src/test/resources/data/queries/vitam_query_with_start_date.txt @@ -0,0 +1 @@ +[{"$or":[{"$eq":{"#management.AppraisalRule.Rules.StartDate":"2021-11-09"}}]}] diff --git a/ui/ui-archive-search/src/main/java/fr/gouv/vitamui/archives/search/rest/ArchivesSearchController.java b/ui/ui-archive-search/src/main/java/fr/gouv/vitamui/archives/search/rest/ArchivesSearchController.java index b2d49b3d9..36c5abb26 100644 --- a/ui/ui-archive-search/src/main/java/fr/gouv/vitamui/archives/search/rest/ArchivesSearchController.java +++ b/ui/ui-archive-search/src/main/java/fr/gouv/vitamui/archives/search/rest/ArchivesSearchController.java @@ -205,7 +205,7 @@ public class ArchivesSearchController extends AbstractUiRestController { } @ApiOperation(value = "Update Archive Units Rules by criteria") - @PostMapping(RestApi.MASSUPDATEUNITSRULES) + @PostMapping(RestApi.MASS_UPDATE_UNITS_RULES) @ResponseStatus(HttpStatus.OK) public String updateArchiveUnitsRules(@RequestBody final RuleSearchCriteriaDto ruleSearchCriteriaDto) { LOGGER.debug("Update Archive Units Rules with criteria {} ", ruleSearchCriteriaDto); diff --git a/ui/ui-frontend/projects/archive-search/src/app/archive/archive-search/appraisal-rule-search/appraisal-rule-search.component.html b/ui/ui-frontend/projects/archive-search/src/app/archive/archive-search/appraisal-rule-search/appraisal-rule-search.component.html index 16b2002b7..9daa148be 100644 --- a/ui/ui-frontend/projects/archive-search/src/app/archive/archive-search/appraisal-rule-search/appraisal-rule-search.component.html +++ b/ui/ui-frontend/projects/archive-search/src/app/archive/archive-search/appraisal-rule-search/appraisal-rule-search.component.html @@ -53,7 +53,8 @@ >{{ (endDateInterval ? 'ARCHIVE_SEARCH.SEARCH_CRITERIA_FILTER.FIELDS.END_DATE_DUA_BEGIN' - : 'ARCHIVE_SEARCH.SEARCH_CRITERIA_FILTER.FIELDS.END_DATE_DUA_EQUAL') | translate + : 'ARCHIVE_SEARCH.SEARCH_CRITERIA_FILTER.FIELDS.END_DATE_DUA_EQUAL' + ) | translate }}</span > <ng-template #showBeginDtDua diff --git a/ui/ui-frontend/projects/archive-search/src/assets/i18n/fr.json b/ui/ui-frontend/projects/archive-search/src/assets/i18n/fr.json index f2d14c69c..3d91115f2 100644 --- a/ui/ui-frontend/projects/archive-search/src/assets/i18n/fr.json +++ b/ui/ui-frontend/projects/archive-search/src/assets/i18n/fr.json @@ -111,7 +111,7 @@ "END_DATE_DUA_EQUAL": "Date de fin extrême", "END_DATE_DUA_BEGIN": "Entre le ", "END_DATE_DUA_END": "et le ", - "GUID_OPI": "GUID du versement", + "GUID_OPI": "Identifiant technique du versement", "ORIGIN": { "TITLE": "L'unité archivistique", "INHERITE_AT_LEAST_ONE_APPRAISAL_RULE": "Hérite d'au moins une règle DUA", -- GitLab