Commit ac13f17e authored by naji's avatar naji
Browse files

Merge branch 'feat/pastis_back'

Conflicts:
	ui/ui-frontend/package-lock.json
parents c41d11e9 cd4fe521
<?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();
}
}
/*
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.controller;
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.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;
import io.swagger.v3.oas.annotations.servers.Server;
import io.swagger.v3.oas.annotations.servers.ServerVariable;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;
@OpenAPIDefinition(tags = { @Tag(name = "pastis") },
info = @Info(title = "Pastis Rest Api", description = ""),
servers = { @Server(url = "localhost" ,
variables = { @ServerVariable(name = "scheme", allowableValues ={"https", "http"}, defaultValue = "http"),
@ServerVariable(name = "port", description = "Api port", defaultValue = "8080")}) })
@RestController
class ProfileController {
private static final Logger LOGGER = LoggerFactory.getLogger(ProfileController.class);
private static final String APPLICATION_JSON_UTF8 = "application/json; charset=utf-8";
@Autowired
private ProfileServiceStandalone profileService;
@Operation(summary = "method for test Api is running",
description = "method for test Api is running",
tags = {"pastis"})
@RequestMapping(value = "/test", method = RequestMethod.GET)
ResponseEntity<String> test() {
if (profileService.test() != null) {
return new ResponseEntity<>(profileService.test(), HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@Operation(summary = "Retrieve RNG representation of the JSON structure",
description = "Retrieve RNG representation of the JSON structure of archive profile",
tags = {"pastis"})
@RequestMapping(value = "/getarchiveprofile", method = RequestMethod.POST, consumes = APPLICATION_JSON_UTF8, produces = MediaType.APPLICATION_XML_VALUE)
ResponseEntity<String> getArchiveProfile(@RequestBody final ElementProperties json) throws IOException {
if (profileService.getArchiveProfile(json) != null) {
return ResponseEntity.ok(profileService.getArchiveProfile(json));
} else {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@Operation(summary = "Retrieve JSON representation of archive unit profile",
description = "Retrieve JSON representation of archive unit profile",
tags = {"pastis"})
@RequestMapping(value = "/getarchiveunitprofile", method = RequestMethod.POST, consumes = APPLICATION_JSON_UTF8, produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<String> getArchiveUnitProfile(@RequestBody final ProfileNotice json) throws IOException {
if (profileService.getArchiveUnitProfile(json) != null) {
return ResponseEntity.ok(profileService.getArchiveUnitProfile(json));
} else {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@RequestMapping (value = "/getfile", method = RequestMethod.GET, produces = "text/plain")
ResponseEntity<String> getFile() {
if (profileService.getFile() != null) {
return new ResponseEntity<>(profileService.getFile(), HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@Operation(summary = "Retrieve JSON representation of the RNG structure",
description = "Retrieve JSON representation of the RNG structure",
tags = {"pastis"})
@RequestMapping (value = "/createprofile", method = RequestMethod.GET)
ResponseEntity<ElementProperties> createProfile() throws URISyntaxException {
if (profileService.createProfile() != null) {
return ResponseEntity.ok(profileService.createProfile());
} else {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@Operation(summary = "Load Profile",
description = "Load profile by Id",
tags = {"pastis"})
@RequestMapping (value = "/edit", method = RequestMethod.POST)
ResponseEntity<ProfileResponse> loadProfile(@RequestParam(name = "id") String id) throws JsonProcessingException {
if (profileService.loadProfile(id) != null) {
return ResponseEntity.ok(profileService.loadProfile(id));
} else {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@Operation(summary = "Upload profile PA or PUA",
description = "Upload profile PA or PUA",
tags = {"pastis"})
@RequestMapping (value = "/profile", method = RequestMethod.POST,
consumes = "multipart/form-data", produces = "application/json")
ResponseEntity<ProfileResponse> loadProfileFromFile(@RequestParam MultipartFile file) {
if (profileService.loadProfileFromFile(file) != null) {
return ResponseEntity.ok(profileService.loadProfileFromFile(file));
} else {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@Operation(summary = "Generate Json Struct from RNG file",
description = "Generate Json Struct from RNG file",
tags = {"pastis"})
@RequestMapping (value = "/createprofilefromfile",
method = RequestMethod.POST,consumes = "multipart/form-data",
produces = "application/json")
ResponseEntity<ElementProperties> createProfileFromFile(@RequestParam MultipartFile file ) {
if (profileService.createProfileFromFile(file) != null) {
return ResponseEntity.ok(profileService.createProfileFromFile(file));
} else {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@Operation(summary = "Retrieve all profiles PA and PUA",
description = "Retrieve all profiles PA and PUA",
tags = {"pastis"})
@RequestMapping (value = "/getprofiles", method = RequestMethod.GET)
ResponseEntity<List<PastisProfile>> getFiles() throws IOException {
if (profileService.getFiles() != null) {
return ResponseEntity.ok(profileService.getFiles());
} else {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}
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
......@@ -15,7 +15,7 @@ spring:
register: false
data:
mongodb:
uri: mongodb://mongod_dbuser_iam:mongod_dbpwd_iam@localhost:27018/iam?connectTimeoutMS=2000
uri: mongodb://mongod_dbuser_iam:mongod_dbpwd_iam@10.100.129.51:27018/iam?connectTimeoutMS=2000
server-identity:
identityName: vitamui-dev
......
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###