Commit 901d6079 authored by naji's avatar naji
Browse files

change pastis architecture

parent a79c9e88
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>parent</artifactId>
<groupId>fr.gouv.vitamui</groupId>
<version>4.4.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>api-pastis-external</artifactId>
<name>pastis-standalone</name>
<description>Demo project for Spring Boot</description>
<properties>
<!-- Generic properties -->
<maven.compile.target>11</maven.compile.target>
<maven.compile.source>11</maven.compile.source>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>fr.gouv.vitamui</groupId>
<artifactId>pastis-external</artifactId>
<version>4.4.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>fr.gouv.vitamui</groupId>
<artifactId>referential-commons</artifactId>
</exclusion>
<exclusion>
<groupId>fr.gouv.vitamui.commons</groupId>
<artifactId>commons-api</artifactId>
</exclusion>
<exclusion>
<groupId>fr.gouv.vitamui.commons</groupId>
<artifactId>commons-rest</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<!-- Documentation -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>build-info</id>
<goals>
<goal>build-info</goal>
</goals>
</execution>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>true</executable>
<attach>false</attach> <!-- Need to use the original jar for integration-tests -->
<mainClass>fr.gouv.vitamui.pastis.standalone.PastisStandaloneApplication</mainClass>
<jvmArguments>
-Xms128m -Xmx512m
</jvmArguments>
<arguments>
<!-- use src/main/config/application-dev.yml when using mvn spring-boot:run -->
<!-- See : https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-application-property-files -->
<argument>
--spring.config.additional-location=file:${basedir}/src/main/config/standalone-pastis-application-dev.yml
</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</project>
server:
host: localhost
port: 8080
scheme: http
cors.allowed-origins: http://localhost,http://localhost
package fr.gouv.vitamui.pastis.standalone;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
public class PastisStandaloneApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(PastisStandaloneApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(PastisStandaloneApplication.class, args);
}
}
/*
Copyright © CINES - Centre Informatique National pour l'Enseignement Supérieur (2020)
[dad@cines.fr]
This software is a computer program whose purpose is to provide
a web application to create, edit, import and export archive
profiles based on the french SEDA standard
(https://redirect.francearchives.fr/seda/).
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.pastis.standalone.configuration;
import fr.gouv.vitamui.pastis.external.util.ProfileService;
import fr.gouv.vitamui.pastis.external.util.PuaPastisValidator;
import fr.gouv.vitamui.pastis.external.util.pua.JsonFromPUA;
import fr.gouv.vitamui.pastis.external.util.pua.NoticeFromPUA;
import fr.gouv.vitamui.pastis.external.util.pua.PuaFromJSON;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorViewResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ResourceLoader;
import org.springframework.http.HttpStatus;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.Collections;
@Configuration
public class PastisConfiguration {
private ResourceLoader resourceLoader;
@Value("${cors.allowed-origins}")
private String origins;
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer () {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins(origins.split(","))
.allowCredentials(true);
}
};
}
@Bean
public ErrorViewResolver customErrorViewResolver() {
final ModelAndView redirectToIndexHtml = new ModelAndView("forward:/index.html", Collections.emptyMap(), HttpStatus.OK);
return (request, status, model) -> status == HttpStatus.NOT_FOUND ? redirectToIndexHtml : null;
}
@Bean
public JsonFromPUA jsonFromPUA() {
return new JsonFromPUA();
}
@Bean
public NoticeFromPUA noticeFromPUA() {
return new NoticeFromPUA();
}
@Bean
public PuaFromJSON puaFromJSON() {
return new PuaFromJSON();
}
@Bean
public ProfileService profileService() {
return new ProfileService(this.resourceLoader);
}
@Bean
public PuaPastisValidator puaPastisValidator() {
return new PuaPastisValidator();
}
}
......@@ -36,14 +36,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.pastis.external.controller;
package fr.gouv.vitamui.pastis.standalone.controller;
import com.fasterxml.jackson.core.JsonProcessingException;
import fr.gouv.vitamui.pastis.external.util.ProfileService;
import fr.gouv.vitamui.pastis.external.model.ElementProperties;
import fr.gouv.vitamui.pastis.external.model.profiles.PastisProfile;
import fr.gouv.vitamui.pastis.external.model.profiles.ProfileNotice;
import fr.gouv.vitamui.pastis.external.model.profiles.ProfileResponse;
import fr.gouv.vitamui.pastis.standalone.service.ProfileServiceStandalone;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.info.Info;
......@@ -70,12 +70,9 @@ import java.util.List;
@OpenAPIDefinition(tags = { @Tag(name = "pastis") },
info = @Info(title = "Pastis Rest Api", description = ""),
servers = { @Server(url = "dev.vitamui.com" ,
variables = { @ServerVariable(name = "scheme", allowableValues = {"https", "http"}, defaultValue = "https"),
@ServerVariable(name = "port", description = "Api port",defaultValue = "8051")})
, @Server(url = "localhost" ,
servers = { @Server(url = "localhost" ,
variables = { @ServerVariable(name = "scheme", allowableValues ={"https", "http"}, defaultValue = "http"),
@ServerVariable(name = "port", description = "Api port", defaultValue = "8051")}) })
@ServerVariable(name = "port", description = "Api port", defaultValue = "8080")}) })
@RestController
class ProfileController {
......@@ -84,7 +81,7 @@ class ProfileController {
private static final String APPLICATION_JSON_UTF8 = "application/json; charset=utf-8";
@Autowired
private ProfileService profileService;
private ProfileServiceStandalone profileService;
@Operation(summary = "method for test Api is running",
description = "method for test Api is running",
......
package fr.gouv.vitamui.pastis.standalone.rest;
public class ProfileRestController {
}
package fr.gouv.vitamui.pastis.standalone.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import fr.gouv.vitamui.pastis.external.model.ElementProperties;
import fr.gouv.vitamui.pastis.external.model.profiles.PastisProfile;
import fr.gouv.vitamui.pastis.external.model.profiles.ProfileNotice;
import fr.gouv.vitamui.pastis.external.model.profiles.ProfileResponse;
import fr.gouv.vitamui.pastis.external.util.ProfileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;
@Service
public class ProfileServiceStandalone {
private final ProfileService profileService;
@Autowired
public ProfileServiceStandalone(final ProfileService profileService) {
this.profileService = profileService;
}
public String test() {
return profileService.test();
}
public String getArchiveProfile(final ElementProperties json) throws IOException {
return profileService.getArchiveProfile(json);
}
public String getArchiveUnitProfile(final ProfileNotice json) throws IOException {
return profileService.getArchiveUnitProfile(json);
}
public ElementProperties createProfile() throws URISyntaxException {
return profileService.createProfile();
}
public ProfileResponse loadProfile(String id) throws JsonProcessingException {
return profileService.loadProfile(id);
}
public ProfileResponse loadProfileFromFile(MultipartFile file) {
return profileService.loadProfileFromFile(file);
}
public ElementProperties createProfileFromFile(MultipartFile file ) {
return profileService.createProfileFromFile(file);
}
public String getFile() {
return profileService.getFile();
}
public List<PastisProfile> getFiles() throws IOException {
return profileService.getFiles();
}
}
#Spring
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=11MB
spring.servlet.multipart.enabled=true
#Spring docs swagger
springdoc.api-docs.path=/api-docs
springdoc.swagger-ui.path=/open-api.html
springdoc.model-and-view-allowed=false
# Pastis Rest APi
rng.base.file=rng/Profil_seda_pastis_mvp.rng
json.base.file=rng/ProfileJson.json
pua.definitions.file=pua_validation/ProfileJson.json
#PORT
server.port=8080
#CORS
cors.allowed-origins = https://dev.vitamui.com:4251, https://localhost
......@@ -7,51 +7,34 @@
<artifactId>api-pastis</artifactId>
<version>4.4.0-SNAPSHOT</version>
</parent>
<artifactId>pastis-commons</artifactId>
<name>pastis-commons</name>
<name>VITAMUI Pastis Commons</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!-- VITAMUI -->
<dependency>
<groupId>fr.gouv.vitamui.commons</groupId>
<artifactId>commons-api</artifactId>
</dependency>
<dependency>
<groupId>fr.gouv.vitamui.commons</groupId>
<artifactId>commons-vitam</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
/**
* 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.pastis.commons.dsl;
import com.fasterxml.jackson.databind.JsonNode;
import fr.gouv.vitam.common.database.builder.query.BooleanQuery;
import fr.gouv.vitam.common.database.builder.query.CompareQuery;
import fr.gouv.vitam.common.database.builder.query.QueryHelper;
import fr.gouv.vitam.common.database.builder.request.exception.InvalidCreateOperationException;
import fr.gouv.vitam.common.database.builder.request.single.Select;
import fr.gouv.vitam.common.exception.InvalidParseOperationException;
import fr.gouv.vitamui.commons.api.domain.DirectionDto;
import fr.gouv.vitamui.commons.api.logger.VitamUILogger;
import fr.gouv.vitamui.commons.api.logger.VitamUILoggerFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import static fr.gouv.vitam.common.database.builder.query.QueryHelper.and;
import static fr.gouv.vitam.common.database.builder.query.QueryHelper.eq;
import static fr.gouv.vitam.common.database.builder.query.QueryHelper.gt;
import static fr.gouv.vitam.common.database.builder.query.QueryHelper.in;
import static fr.gouv.vitam.common.database.builder.query.QueryHelper.lt;
import static fr.gouv.vitam.common.database.builder.query.QueryHelper.or;
public class VitamQueryHelper {
private static final VitamUILogger LOGGER = VitamUILoggerFactory.getInstance(VitamQueryHelper.class);
/* Operation types */
public static final String AGENCY_IMPORT_OPERATION_TYPE = "IMPORT_AGENCIES.OK";
public static final String RULE_IMPORT_OPERATION_TYPE = "STP_IMPORT_RULES.OK";
/* Query fields */
private static final String IDENTIFIER = "Identifier";
private static final String ID = "#id";
private static final String NAME = "Name";
private static final String SHORT_NAME = "ShortName";
private static final String PUID = "PUID";
private static final String RULE_VALUE = "RuleValue";
private static final String RULE_TYPE = "RuleType";
private static final String EV_TYPE_PROC = "evTypeProc";
private static final String STATUS = "Status";
private static final String EV_TYPE ="evType";
private static final String EV_DATE_TIME_START = "evDateTime_Start";
private static final String EV_DATE_TIME_END = "evDateTime_End";
/**
* create a valid VITAM DSL Query from a map of criteria
*
* @param searchCriteriaMap the input criteria. Should match pattern Map(FieldName, SearchValue)
* @return The JsonNode required by VITAM external API for a DSL query
* @throws InvalidParseOperationException
* @throws InvalidCreateOperationException
*/
public static JsonNode createQueryDSL(Map<String, Object> searchCriteriaMap, final Integer pageNumber, final Integer size,
final Optional<String> orderBy, final Optional<DirectionDto> direction)
throws InvalidParseOperationException, InvalidCreateOperationException {
final Select select = new Select();
final BooleanQuery query = and();
BooleanQuery queryOr = or();
boolean isEmpty = true;
boolean haveOrParameters = false;
// Manage Filters
if (orderBy.isPresent()) {
if (direction.isPresent() && DirectionDto.DESC.equals(direction.get())) {
select.addOrderByDescFilter(orderBy.get());
} else {
select.addOrderByAscFilter(orderBy.get());
}
}
select.setLimitFilter(pageNumber * size, size);
// Manage Query
if (!searchCriteriaMap.isEmpty()) {
isEmpty = false;
Set<Map.Entry<String, Object>> entrySet = searchCriteriaMap.entrySet();
for (final Map.Entry<String, Object> entry : entrySet) {