Unverified Commit cd95dd1d authored by EL HAJJIOUI Nabil's avatar EL HAJJIOUI Nabil Committed by GitHub
Browse files

[VAS] Item 8585 Check rules for archive search (#516)

parent 9a831232
......@@ -36,28 +36,17 @@
*/
package fr.gouv.vitamui.iam.external.server.config;
import fr.gouv.vitamui.commons.rest.client.accesscontract.AccessContractInternalRestClient;
import fr.gouv.vitamui.iam.internal.client.ExternalParamProfileInternalRestClient;
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.multipart.support.MultipartFilter;
import org.springframework.web.reactive.function.client.WebClient;
import fr.gouv.vitamui.commons.api.application.AbstractContextConfiguration;
import fr.gouv.vitamui.commons.rest.RestExceptionHandler;
import fr.gouv.vitamui.commons.rest.client.InternalHttpContext;
import fr.gouv.vitamui.commons.rest.client.accesscontract.AccessContractInternalRestClient;
import fr.gouv.vitamui.commons.rest.client.logbook.LogbookInternalRestClient;
import fr.gouv.vitamui.commons.rest.configuration.SwaggerConfiguration;
import fr.gouv.vitamui.iam.internal.client.ApplicationInternalRestClient;
import fr.gouv.vitamui.iam.internal.client.CasInternalRestClient;
import fr.gouv.vitamui.iam.internal.client.CustomerInternalRestClient;
import fr.gouv.vitamui.iam.internal.client.CustomerInternalWebClient;
import fr.gouv.vitamui.iam.internal.client.ExternalParamProfileInternalRestClient;
import fr.gouv.vitamui.iam.internal.client.ExternalParametersInternalRestClient;
import fr.gouv.vitamui.iam.internal.client.GroupInternalRestClient;
import fr.gouv.vitamui.iam.internal.client.IamInternalRestClientFactory;
......@@ -73,6 +62,16 @@ import fr.gouv.vitamui.iam.security.service.ExternalAuthentificationService;
import fr.gouv.vitamui.iam.security.service.ExternalSecurityService;
import fr.gouv.vitamui.security.client.ContextRestClient;
import fr.gouv.vitamui.security.client.SecurityRestClientFactory;
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.multipart.support.MultipartFilter;
import org.springframework.web.reactive.function.client.WebClient;
@Configuration
@Import({ RestExceptionHandler.class, SwaggerConfiguration.class, HttpMessageConvertersAutoConfiguration.class })
......
......@@ -122,5 +122,4 @@ public class IamInternalRestClientFactory extends BaseRestClientFactory {
public AccessContractInternalRestClient<InternalHttpContext> getAccessContractInternalRestClient() {
return new AccessContractInternalRestClient<>(getRestTemplate(), getBaseUrl());
}
}
......@@ -36,12 +36,17 @@
*/
package fr.gouv.vitamui.referential.common.utils;
import java.util.HashSet;
import java.util.Set;
import fr.gouv.vitam.common.model.administration.ActivationStatus;
import fr.gouv.vitam.common.model.administration.ContextStatus;
import fr.gouv.vitamui.referential.common.dto.*;
import fr.gouv.vitamui.commons.rest.dto.RuleDto;
import fr.gouv.vitamui.referential.common.dto.AccessContractDto;
import fr.gouv.vitamui.referential.common.dto.ContextDto;
import fr.gouv.vitamui.referential.common.dto.IngestContractDto;
import fr.gouv.vitamui.referential.common.dto.PermissionDto;
import fr.gouv.vitamui.referential.common.dto.SecurityProfileDto;
import java.util.HashSet;
import java.util.Set;
public class ReferentialDtoBuilder {
......
......@@ -36,12 +36,15 @@
*/
package fr.gouv.vitamui.referential.external.client;
import java.util.List;
import java.util.Map;
import fr.gouv.vitamui.common.security.SanityChecker;
import fr.gouv.vitamui.commons.api.CommonConstants;
import fr.gouv.vitamui.commons.api.domain.PaginatedValuesDto;
import fr.gouv.vitamui.commons.api.logger.VitamUILogger;
import fr.gouv.vitamui.commons.api.logger.VitamUILoggerFactory;
import fr.gouv.vitamui.commons.rest.client.BasePaginatingAndSortingRestClient;
import fr.gouv.vitamui.commons.rest.client.ExternalHttpContext;
import fr.gouv.vitamui.commons.rest.dto.RuleDto;
import fr.gouv.vitamui.referential.common.rest.RestApi;
import org.apache.commons.lang3.StringUtils;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.io.Resource;
......@@ -51,20 +54,13 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.Assert;
import org.springframework.web.client.RestTemplate;
import fr.gouv.vitamui.commons.api.domain.PaginatedValuesDto;
import fr.gouv.vitamui.commons.api.logger.VitamUILogger;
import fr.gouv.vitamui.commons.api.logger.VitamUILoggerFactory;
import fr.gouv.vitamui.commons.api.utils.ApiUtils;
import fr.gouv.vitamui.commons.rest.client.BasePaginatingAndSortingRestClient;
import fr.gouv.vitamui.commons.rest.client.ExternalHttpContext;
import fr.gouv.vitamui.referential.common.dto.RuleDto;
import fr.gouv.vitamui.referential.common.rest.RestApi;
import org.springframework.web.util.UriComponentsBuilder;
import java.util.List;
import java.util.Map;
public class RuleExternalRestClient extends BasePaginatingAndSortingRestClient<RuleDto, ExternalHttpContext> {
private static final VitamUILogger LOGGER = VitamUILoggerFactory.getInstance(RuleExternalRestClient.class);
public RuleExternalRestClient(final RestTemplate restTemplate, final String baseUrl) {
......@@ -96,11 +92,11 @@ public class RuleExternalRestClient extends BasePaginatingAndSortingRestClient<R
request, Boolean.class);
return response.getStatusCode() == HttpStatus.OK;
}
public boolean createRule(final ExternalHttpContext context, final RuleDto dto) {
LOGGER.debug("Create {}", dto);
final HttpEntity<RuleDto> request = new HttpEntity<>(dto, buildHeaders(context));
final ResponseEntity<Boolean> response = restTemplate.exchange(getUrl(), HttpMethod.POST, request, Boolean.class);
checkResponse(response, 200, 201, 202, 204);
return response.getStatusCode() == HttpStatus.OK | response.getStatusCode() == HttpStatus.CREATED;
......@@ -110,16 +106,16 @@ public class RuleExternalRestClient extends BasePaginatingAndSortingRestClient<R
LOGGER.debug("Patch {}", partialDto);
SanityChecker.check(id);
Assert.isTrue(StringUtils.equals(id, (String) partialDto.get("id")), "The DTO identifier must match the path identifier for patch.");
final UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromHttpUrl(getUrl());
uriBuilder.path(CommonConstants.PATH_ID);
final HttpEntity<Map<String, Object>> request = new HttpEntity<>(partialDto, buildHeaders(context));
final ResponseEntity<Boolean> response = restTemplate.exchange(uriBuilder.build(id), HttpMethod.PATCH, request, Boolean.class);
final ResponseEntity<Boolean> response = restTemplate.exchange(uriBuilder.build(id), HttpMethod.PATCH, request, Boolean.class);
checkResponse(response, 200, 201, 202, 204);
return response.getStatusCode() == HttpStatus.OK;
}
public boolean deleteRule(ExternalHttpContext context, String id) {
LOGGER.debug("Delete {}", id);
SanityChecker.check(id);
......
......@@ -44,7 +44,6 @@ import fr.gouv.vitamui.referential.internal.server.ingestcontract.IngestContract
import fr.gouv.vitamui.referential.internal.server.managementcontract.ManagementContractConverter;
import fr.gouv.vitamui.referential.internal.server.ontology.OntologyConverter;
import fr.gouv.vitamui.referential.internal.server.profile.ProfileConverter;
import fr.gouv.vitamui.referential.internal.server.rule.RuleConverter;
import fr.gouv.vitamui.referential.internal.server.securityprofile.SecurityProfileConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -96,10 +95,4 @@ public class ConverterConfig {
public ProfileConverter profileConverter() {
return new ProfileConverter();
}
@Bean
public RuleConverter ruleConverter() {
return new RuleConverter();
}
}
......@@ -36,43 +36,50 @@
*/
package fr.gouv.vitamui.referential.internal.server.rest;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;
import com.fasterxml.jackson.databind.JsonNode;
import fr.gouv.vitam.common.client.VitamContext;
import fr.gouv.vitam.common.exception.VitamClientException;
import fr.gouv.vitamui.commons.api.CommonConstants;
import fr.gouv.vitamui.commons.api.ParameterChecker;
import fr.gouv.vitamui.referential.common.dto.RuleDto;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import fr.gouv.vitam.common.client.VitamContext;
import fr.gouv.vitamui.commons.api.domain.DirectionDto;
import fr.gouv.vitamui.commons.api.domain.PaginatedValuesDto;
import fr.gouv.vitamui.commons.api.logger.VitamUILogger;
import fr.gouv.vitamui.commons.api.logger.VitamUILoggerFactory;
import fr.gouv.vitamui.commons.rest.dto.RuleDto;
import fr.gouv.vitamui.commons.rest.util.RestUtils;
import fr.gouv.vitamui.iam.security.service.InternalSecurityService;
import fr.gouv.vitamui.referential.common.rest.RestApi;
import fr.gouv.vitamui.referential.internal.server.rule.RuleInternalService;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.Valid;
import javax.ws.rs.core.Response;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;
@RestController
@RequestMapping(RestApi.RULES_URL)
......@@ -167,11 +174,11 @@ public class RuleInternalController {
}
return null;
}
@PostMapping(CommonConstants.PATH_IMPORT)
public JsonNode importAgencies(@RequestParam("fileName") String fileName, @RequestParam("file") MultipartFile file) {
LOGGER.debug("import rule file {}", fileName);
final VitamContext vitamContext = securityService.buildVitamContext(securityService.getTenantIdentifier());
final VitamContext vitamContext = securityService.buildVitamContext(securityService.getTenantIdentifier());
return ruleInternalService.importRules(vitamContext, fileName, file);
}
}
......@@ -36,31 +36,10 @@
*/
package fr.gouv.vitamui.referential.internal.server.rule;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.ws.rs.core.Response;
import javax.xml.bind.JAXBException;
import fr.gouv.vitamui.commons.vitam.api.dto.RuleNodeResponseDto;
import org.apache.commons.beanutils.BeanUtilsBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import fr.gouv.vitam.access.external.api.AdminCollections;
import fr.gouv.vitam.access.external.common.exception.AccessExternalClientException;
import fr.gouv.vitam.common.client.VitamContext;
import fr.gouv.vitam.common.database.builder.request.exception.InvalidCreateOperationException;
......@@ -76,10 +55,26 @@ import fr.gouv.vitamui.commons.api.exception.InternalServerException;
import fr.gouv.vitamui.commons.api.exception.VitamUIException;
import fr.gouv.vitamui.commons.api.logger.VitamUILogger;
import fr.gouv.vitamui.commons.api.logger.VitamUILoggerFactory;
import fr.gouv.vitamui.commons.rest.dto.RuleDto;
import fr.gouv.vitamui.commons.vitam.api.access.LogbookService;
import fr.gouv.vitamui.commons.vitam.api.config.converter.RuleConverter;
import fr.gouv.vitamui.commons.vitam.api.dto.RuleNodeResponseDto;
import fr.gouv.vitamui.referential.common.dsl.VitamQueryHelper;
import fr.gouv.vitamui.referential.common.dto.RuleDto;
import fr.gouv.vitamui.referential.common.service.VitamRuleService;
import org.apache.commons.beanutils.BeanUtilsBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.ws.rs.core.Response;
import javax.xml.bind.JAXBException;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@Service
public class RuleInternalService {
......@@ -247,7 +242,7 @@ public class RuleInternalService {
throw new InternalServerException("Unable to fetch history", e);
}
}
public JsonNode importRules(VitamContext context, String fileName, MultipartFile file) {
try {
return ruleService.importRules(context, fileName, file).toJsonNode();
......
......@@ -53,8 +53,8 @@ import fr.gouv.vitamui.commons.vitam.api.administration.AgencyService;
import fr.gouv.vitamui.referential.common.dsl.VitamQueryHelper;
import fr.gouv.vitamui.referential.common.dto.AccessionRegisterDetailResponseDto;
import fr.gouv.vitamui.referential.internal.server.accessionregister.details.AccessionRegisterDetailInternalService;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
......@@ -99,8 +99,9 @@ class AccessionRegisterDetailInternalServiceTest {
doNothing().when(vitamUILogger).info(any());
}
@Test
void should_call_appropriate_api_once_when_get_paginated_is_invoked() throws IOException, InvalidCreateOperationException, InvalidParseOperationException, VitamClientException {
@Test
void should_call_appropriate_api_once_when_get_paginated_is_invoked() throws IOException,
InvalidCreateOperationException, InvalidParseOperationException, VitamClientException {
//Given
VitamContext vitamContext = new VitamContext(0);
Map<String, Object> vitamCriteria = new HashMap<>();
......
......@@ -34,34 +34,39 @@
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*/
package fr.gouv.vitamui.commons.vitam.api.dto;
import com.fasterxml.jackson.annotation.JsonProperty;
package fr.gouv.vitamui.commons.rest.dto;
import com.fasterxml.jackson.annotation.JsonInclude;
import fr.gouv.vitamui.commons.api.domain.IdDto;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.io.Serializable;
@ToString
@JsonInclude(JsonInclude.Include.NON_NULL)
@Getter
@Setter
@ToString
public class RuleDto {
public class RuleDto extends IdDto implements Serializable {
private Integer tenant;
private Integer version;
private String creationDate;
private String updateDate;
private String ruleId;
private String ruleType;
private String ruleValue;
/**
* Rule id
*/
@JsonProperty("Rule")
private String rule;
private String ruleDescription;
/**
* Start date
*/
@JsonProperty("StartDate")
private String startDate;
private String ruleDuration;
/**
* End date
*/
@JsonProperty("EndDate")
private String endDate;
private String ruleMeasurement;
}
......@@ -36,6 +36,7 @@
*/
package fr.gouv.vitamui.commons.vitam.api.config;
import fr.gouv.vitamui.commons.vitam.api.config.converter.RuleConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -78,4 +79,9 @@ public class VitamAdministrationConfig extends VitamClientConfig {
public IngestContractService geIngestContractService() {
return new IngestContractService(adminExternalClient());
}
@Bean
public RuleConverter rulesConverter() {
return new RuleConverter();
}
}
......@@ -34,14 +34,14 @@
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*/
package fr.gouv.vitamui.referential.internal.server.rule;
import java.util.List;
import java.util.stream.Collectors;
package fr.gouv.vitamui.commons.vitam.api.config.converter;
import fr.gouv.vitam.common.model.administration.FileRulesModel;
import fr.gouv.vitamui.commons.rest.dto.RuleDto;
import fr.gouv.vitamui.commons.utils.VitamUIUtils;
import fr.gouv.vitamui.referential.common.dto.RuleDto;
import java.util.List;
import java.util.stream.Collectors;
public class RuleConverter {
......
......@@ -36,22 +36,21 @@
*/
package fr.gouv.vitamui.commons.vitam.api.dto;
import java.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.util.ArrayList;
import java.util.List;
@Getter
@Setter
@ToString
public class InheritedRuleCategoryDto {
@JsonProperty("Rules")
private List<RuleDto> rules = new ArrayList<>();
private List<UnitRuleDto> rules = new ArrayList<>();
@JsonProperty("Properties")
private List<InheritedPropertyDto> properties = new ArrayList<>();
......
......@@ -36,22 +36,21 @@
*/
package fr.gouv.vitamui.commons.vitam.api.dto;
import java.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.util.ArrayList;
import java.util.List;
@Getter
@Setter
@ToString
public class RuleCategoryDto {
@JsonProperty("Rules")
private List<RuleDto> rules = new ArrayList<>();
private List<UnitRuleDto> rules = new ArrayList<>();
@JsonProperty("FinalAction")
private String finalAction;
......
/**
* Copyright French Prime minister Office/SGMAP/DINSIC/Vitam Program (2019-2020)
* and the signatories of the "VITAM - Accord du Contributeur" agreement.
*
* contact@programmevitam.fr
*
* This software is a computer program whose purpose is to implement
* implement a digital archiving front-office system for the secure and
* efficient high volumetry VITAM solution.
*
* This software is governed by the CeCILL-C 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-C
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.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-C license and that you accept its terms.
*/
package fr.gouv.vitamui.commons.vitam.api.dto;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter