Skip to content
Snippets Groups Projects
Commit 5254b827 authored by Baptiste Toulemonde's avatar Baptiste Toulemonde
Browse files

Merge branch 'feature/integration-pastis-app' of...

Merge branch 'feature/integration-pastis-app' of https://dci-gitlab.cines.fr/dad/integration-pastis into feature/intégration-librairie-css
parents e7b6f9d1 7bed0c87
No related branches found
No related tags found
5 merge requests!58compare branch,!54Comparaison de merge vers vitam-ui,!53Comparaison de merge vers vitam-ui,!52Voir difference entre les deux verion,!41MAJ: compare to vitam-ui
Showing
with 2678 additions and 20144 deletions
This diff is collapsed.
# Created by https://www.gitignore.io/api/eclipse
# Edit at https://www.gitignore.io/?templates=eclipse
#PASTIS
#test generated file"
generated_test.xml
logs/*.*
### Eclipse ###
.metadata
bin/fe
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# PyDev specific (Python IDE for Eclipse)
*.pydevproject
# CDT-specific (C/C++ Development Tooling)
.cproject
# CDT- autotools
.autotools
# Java annotation processor (APT)
.factorypath
# PDT-specific (PHP Development Tools)
.buildpath
# sbteclipse plugin
.target
# Tern plugin
.tern-project
# TeXlipse plugin
.texlipse
# STS (Spring Tool Suite)
.springBeans
# Code Recommenders
.recommenders/
# Annotation Processing
.apt_generated/
# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet
### Eclipse Patch ###
# Eclipse Core
.project
# JDT-specific (Eclipse Java Development Tools)
.classpath
# Annotation Processing
.apt_generated
.sts4-cache/
# End of https://www.gitignore.io/api/eclipse
/target/
### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
.DS_Store
.idea/
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
.idea/modules.xml
.idea/*.iml
.idea/modules
*.iml
*.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr
# Sonarlint plugin
.idea/**/sonarlint/
# SonarQube Plugin
.idea/**/sonarIssues.xml
# Markdown Navigator plugin
.idea/**/markdown-navigator.xml
.idea/**/markdown-navigator/
# End of https://www.gitignore.io/api/intellij
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: rest-api;singleton:=true
Automatic-Module-Name: rest-api
Bundle-Version: 1.0.0.qualifier
Bundle-ClassPath: .
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.emf.ecore;visibility:=reexport
Bundle-ActivationPolicy: lazy
#
bin.includes = .,\
model/,\
META-INF/,\
plugin.xml,\
plugin.properties
jars.compile.order = .
source.. = src/
output.. = bin/
#
pluginName = Vitam Model
providerName = www.example.org
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<!--
-->
<plugin>
</plugin>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<url>http://maven.apache.org</url>
<artifactId>ui-pastis</artifactId>
<name>PASTIS-API</name>
<parent>
<groupId>fr.gouv.vitamui</groupId>
<artifactId>ui-parent</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<properties>
<!-- Generic properties -->
<maven.compile.target>1.8</maven.compile.target>
<maven.compile.source>1.8</maven.compile.source>
<java.version>11</java.version>
</properties>
<dependencies>
<!--Start of Jaxb API and it's implementation and dependencies- Java11-->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.istack</groupId>
<artifactId>istack-commons-runtime</artifactId>
<version>4.0.0-M2</version>
</dependency>
<!--End of Jaxb API and it's implementation and dependencies- Java11-->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180813</version>
</dependency>
<dependency>
<groupId>javax.xml.parsers</groupId>
<artifactId>jaxp-api</artifactId>
<version>1.4.5</version>
</dependency>
<!-- Start of SpringBoot starter web (Tomcat by default) and starter test-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>2.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<version>2.2.6.RELEASE</version>
<exclusions>
<exclusion>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- End of SpringBoot starter web and starter test-->
<dependency>
<groupId>com.fasterxml</groupId>
<artifactId>jackson-xml-databind</artifactId>
<version>0.6.2</version>
</dependency>
<dependency>
<groupId>com.thaiopensource</groupId>
<artifactId>jing</artifactId>
<version>20091111</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
<exclusion>
<groupId>net.sf.saxon</groupId>
<artifactId>saxon</artifactId>
</exclusion>
<exclusion>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.thaiopensource</groupId>
<artifactId>trang</artifactId>
<version>20091111</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
<exclusion>
<groupId>net.sf.saxon</groupId>
<artifactId>saxon</artifactId>
</exclusion>
<exclusion>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.opengis.cite.xerces</groupId>
<artifactId>xercesImpl-xsd11</artifactId>
<version>2.12-beta-r1667115</version>
</dependency>
<dependency>
<groupId>xml-resolver</groupId>
<artifactId>xml-resolver</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
</dependencies>
<!-- Start of profiles -->
<profiles>
<!-- Profile 1 - Production -->
<profile>
<id>prod</id>
<!-- Start of production plugins -->
<build>
<plugins>
<!-- SpringBoot maven plugin-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<configuration>
<mainClass>fr.gouv.vitamui.pastis.PastisRestApplication</mainClass>
</configuration>
</execution>
</executions>
</plugin>
<!-- Read the application.properties files with the properties plug-in -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${project.basedir}/src/main/resources/application.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<!-- Tests -->
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
<finalName>PastisApi</finalName>
</build>
</profile>
<!-- End of Prod profile -->
<!-- Start of Dev profile -->
<profile>
<id>dev</id>
<build>
<!-- Start of dev profile plugins -->
<plugins>
<!-- SpringBoot maven plugin-->
<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>
<id>spring-boot-repackage</id>
<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.PastisRestApplication</mainClass>
<jvmArguments>-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/application.yml</argument>
</arguments>
</configuration>
</plugin>
<!-- Read the application.properties files with the properties plug-in -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${project.basedir}/src/main/resources/application.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<!-- Tests -->
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
</build>
</profile>
<!-- End of Dev profile -->
</profiles>
</project>
This diff is collapsed.
#!/bin/bash
#retrieve version
version="$(grep -oP '(?<=>).*?(?=</version>)' pom.xml | grep -v 'version')"
java -jar target/ui-pastis-$(echo $version).jar -Xms128m -Xmx512m --spring.config.additional-location=file:src/main/config/ui-pastis-application-dev.yml
server:
host: dev.vitamui.com
port: 9051
scheme: https
ssl:
key-store: src/main/config/ui-pastis.jks
key-store-password: jkspasswd
key-password: jkspasswd
logging:
level:
fr.gouv.vitamui: DEBUG
org.springframework.web: INFO
management.endpoints.web.exposure.include: "*"
# Uncomment if you want to use you specific logback config.
#logging:
config: src/main/config/logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- Send debug messages to System.out -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- By default, encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
<encoder>
<pattern>%d{ISO8601} [[%thread]] [%X{X-Request-Id}] %-5level %logger - %replace(%caller{1..2}){'Caller\+1 at |\n',''} : %msg %rootException%n</pattern>
</encoder>
</appender>
<!-- <appender name="FILE" class="ch.qos.logback.core.FileAppender"> -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>/tmp/vitamui/ui-pastis.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
<maxHistory>30</maxHistory>
<totalSizeCap>5GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%d{ISO8601} [[%thread]] [%X{X-Request-Id}] %-5level %logger - %replace(%caller{1..2}){'Caller\+1 at |\n',''} : %msg %rootException%n</pattern>
</encoder>
</appender>
<appender name="SYSLOG" class="ch.qos.logback.classic.net.SyslogAppender">
<syslogHost>localhost</syslogHost>
<facility>local0</facility>
<port>5140</port>
<suffixPattern>vitamui-ui-pastis: %d{ISO8601} [[%thread]] [%X{X-Request-Id}] %-5level %logger - %replace(%caller{1..2}){'Caller\+1 at |\n',''} : %msg %rootException%n</suffixPattern>
</appender>
<!-- By default, the level of the root level is set to TRACE -->
<root level="INFO">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
<appender-ref ref="SYSLOG" />
</root>
<logger name="org.springframework.web" level="INFO"/>
<logger name="fr.gouv.vitamui.pastis" level="INFO"/>
</configuration>
ui/ui-pastis/src/main/config/logo.png

13.4 KiB

File added
File added
/*
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;
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 PastisRestApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(PastisRestApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(PastisRestApplication.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.configuration;
import fr.gouv.vitamui.pastis.model.profiles.PastisProfile;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.ArrayList;
import java.util.List;
@Configuration
public class PastisConfiguration {
@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);
}
};
}
}
/*
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.controller;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import fr.gouv.vitamui.pastis.model.ElementProperties;
import fr.gouv.vitamui.pastis.model.jaxb.*;
import fr.gouv.vitamui.pastis.model.profiles.PastisProfile;
import fr.gouv.vitamui.pastis.model.profiles.Notice;
import fr.gouv.vitamui.pastis.model.profiles.ProfileNotice;
import fr.gouv.vitamui.pastis.util.pua.JsonFromPUA;
import fr.gouv.vitamui.pastis.util.PastisCustomCharacterEscapeHandler;
import fr.gouv.vitamui.pastis.util.PastisGetXmlJsonTree;
import fr.gouv.vitamui.pastis.util.PastisSAX2Handler;
import fr.gouv.vitamui.pastis.util.PuaPastisValidator;
import fr.gouv.vitamui.pastis.util.pua.NoticeFromPUA;
import fr.gouv.vitamui.pastis.util.pua.PuaFromJSON;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.ResourcePatternUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import java.io.*;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
@RestController
class ProfileController {
private static final Logger LOGGER = LoggerFactory.getLogger(ProfileController.class);
private static final String APPLICATION_JSON_UTF8 = "application/json; charset=utf-8";
@Value("${rng.base.file}")
private String rngFile;
private final ResourceLoader resourceLoader;
@Autowired
private PuaPastisValidator puaPastisValidator;
@Autowired
private JsonFromPUA jsonFromPUA;
@Autowired
private NoticeFromPUA noticeFromPUA;
@Autowired
private PuaFromJSON puaFromJSON;
@Autowired
public ProfileController(ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
}
private List<PastisProfile> pastisProfiles = new ArrayList<>();
@RequestMapping(value = "/test", method = RequestMethod.GET)
String test() {
return "Pastis API is listening...";
}
@RequestMapping(value = "/getarchiveprofile", method = RequestMethod.POST, consumes = APPLICATION_JSON_UTF8, produces = MediaType.APPLICATION_XML_VALUE)
String getArchiveProfile(@RequestBody final ElementProperties json) throws IOException {
// Recover a statically generated BaliseXML by buildBaliseXMLTree
json.initTree(json);
BaliseXML.buildBaliseXMLTree(json,0, null);
// Add Recip struct to xml balises tree
BaliseXML.addRecipTags();
BaliseXML eparentRng = BaliseXML.baliseXMLStatic;
String response = null;
Writer writer = null;
try {
JAXBContext contextObj = JAXBContext.newInstance(AttributeXML.class, ElementXML.class, DataXML.class,
ValueXML.class, OptionalXML.class, OneOrMoreXML.class,
ZeroOrMoreXML.class, AnnotationXML.class, DocumentationXML.class,
StartXML.class, GrammarXML.class,ChoiceXml.class,AnyNameXML.class,ExceptXML.class,NsNameXML.class);
Marshaller marshallerObj = contextObj.createMarshaller();
marshallerObj.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshallerObj.setProperty("com.sun.xml.bind.marshaller.CharacterEscapeHandler",
new PastisCustomCharacterEscapeHandler());
ByteArrayOutputStream os = new ByteArrayOutputStream();
writer = new OutputStreamWriter(os, "UTF-8");
marshallerObj.marshal(eparentRng, writer);
response = new String (os.toByteArray(), "UTF-8");
} catch (IOException e1) {
e1.printStackTrace();
} catch (JAXBException e1) {
e1.printStackTrace();
}
finally {
writer.close();
}
LOGGER.info("RNG profile generated successfully");
return response;
}
@RequestMapping(value = "/getarchiveunitprofile", method = RequestMethod.POST, consumes = APPLICATION_JSON_UTF8, produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<String> getArchiveUnitProfile(@RequestBody final ProfileNotice json) throws IOException {
Notice notice = new Notice();
if(json.getNotice() != null){
notice = json.getNotice();
}else { notice.set_id("12133411121213"); }
String controlSchema = puaFromJSON.getControlSchemaFromElementProperties(json.getElementProperties());
notice.setControlSchema(controlSchema);
ObjectMapper objectMapper = new ObjectMapper();
String noticeAsString = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(notice);
return ResponseEntity.ok(noticeAsString);
}
@RequestMapping (value = "/getfile", method = RequestMethod.GET, produces = "text/plain")
ResponseEntity<String> getFile() {
InputStream rngFile = getClass().getClassLoader().getResourceAsStream("profile3.rng");
if (rngFile != null) {
return new ResponseEntity<>(rngFile.toString(), HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@RequestMapping (value = "/createprofile", method = RequestMethod.GET)
ResponseEntity<String> createprofile() throws URISyntaxException {
PastisSAX2Handler handler = new PastisSAX2Handler();
PastisGetXmlJsonTree getJson = new PastisGetXmlJsonTree();
try {
XMLReader xmlReader = XMLReaderFactory.createXMLReader();
xmlReader.setContentHandler(handler);
LOGGER.info("Starting rng edition profile with base file : {}", this.rngFile);
InputStream inputStream = getClass().getClassLoader().getResourceAsStream(this.rngFile);
InputSource inputSource = new InputSource(inputStream);
xmlReader.parse(inputSource);
} catch (SAXException | IOException e ) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
return ResponseEntity.ok(getJson.getJsonParsedTree(handler.elementRNGRoot));
}
@RequestMapping (value = "/edit", method = RequestMethod.POST)
ResponseEntity<String> loadProfile(@RequestParam(name = "id") String id) throws JsonProcessingException {
PastisSAX2Handler handler = new PastisSAX2Handler();
PastisGetXmlJsonTree getJson = new PastisGetXmlJsonTree();
PastisProfile profileToEdit;
String notice = null;
String parsedProfile = null;
ObjectMapper mapper = new ObjectMapper();
try {
profileToEdit = pastisProfiles.stream()
.filter(p -> Long.toString(p.getId()).equals(id))
.collect(Collectors.toList()).get(0);
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("rng/" +
profileToEdit.getFileName());
InputSource inputSource = new InputSource(inputStream);
if (profileToEdit.getType().equals("PA")) {
XMLReader xmlReader = XMLReaderFactory.createXMLReader();
xmlReader.setContentHandler(handler);
xmlReader.parse(inputSource);
parsedProfile = getJson.getJsonParsedTree(handler.elementRNGRoot);
LOGGER.info("Starting editing Archive Profile with id : {}", id);
} else if (profileToEdit.getType().equals("PUA")) {
JSONTokener tokener = new JSONTokener(new InputStreamReader(inputStream));
JSONObject profileJson = new JSONObject(tokener);
puaPastisValidator.validatePUA(profileJson);
ElementProperties profile = jsonFromPUA.getProfileFromPUA(profileJson);
parsedProfile = "[" + mapper.writeValueAsString(profile) + "]";
Notice noticeObject = noticeFromPUA.getNoticeFromPUA(profileJson);
notice = mapper.writeValueAsString(noticeObject);
LOGGER.info("Starting editing Archive Unit Profile with id : {}", id);
}
} catch (SAXException | IOException e ) {
LOGGER.error("Failed to load profile with id : {}", id);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} catch (AssertionError ae) {
LOGGER.error("Failed to load pua with id {} and error message {}", id, ae.getMessage());
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
JSONObject response = new JSONObject();
response.put("id", profileToEdit.getId());
response.put("profile", parsedProfile);
response.put("notice", notice);
return ResponseEntity.ok(response.toString());
}
@RequestMapping (value = "/new", method = RequestMethod.POST,
consumes = "multipart/form-data", produces = "application/json")
ResponseEntity<String> loadProfileFromFile(@RequestParam MultipartFile file) {
PastisSAX2Handler handler = new PastisSAX2Handler();
PastisGetXmlJsonTree getJson = new PastisGetXmlJsonTree();
PastisProfile profileToEdit;
String notice = null;
String parsedProfile = null;
ObjectMapper mapper = new ObjectMapper();
try {
String fileExtension = file.getOriginalFilename().split("\\.")[1];
InputStream fileInputStream = file.getInputStream();
InputSource inputSource = new InputSource(file.getInputStream());
if (fileExtension.equals("rng")) {
XMLReader xmlReader = XMLReaderFactory.createXMLReader();
xmlReader.setContentHandler(handler);
xmlReader.parse(inputSource);
parsedProfile = getJson.getJsonParsedTree(handler.elementRNGRoot);
LOGGER.info("Starting editing Archive Profile from file : {}",file.getOriginalFilename());
} else if (fileExtension.equals("json")) {
JSONTokener tokener = new JSONTokener(new InputStreamReader(fileInputStream));
JSONObject profileJson = new JSONObject(tokener);
puaPastisValidator.validatePUA(profileJson);
ElementProperties profile = jsonFromPUA.getProfileFromPUA(profileJson);
parsedProfile = "[" + mapper.writeValueAsString(profile) + "]";
Notice noticeObject = noticeFromPUA.getNoticeFromPUA(profileJson);
notice = mapper.writeValueAsString(noticeObject);
LOGGER.info("Starting editing Archive Unit Profile with name : {}", file.getOriginalFilename());
}
} catch (SAXException | IOException e ) {
LOGGER.error("Failed to load profile '{}' : " + e.getMessage(), file.getOriginalFilename());
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} catch (AssertionError ae) {
LOGGER.error("Failed to load pua : {}", ae.getMessage());
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
JSONObject response = new JSONObject();
response.put("id", Math.abs(new Random().nextLong()) / 1000);
response.put("profile", parsedProfile);
response.put("notice", notice);
return ResponseEntity.ok(response.toString());
}
@RequestMapping (value = "/createprofilefromfile",
method = RequestMethod.POST,consumes = "multipart/form-data",
produces = "application/json")
ResponseEntity<String> createprofilefromfile(@RequestParam MultipartFile file ) {
PastisSAX2Handler handler = new PastisSAX2Handler();
PastisGetXmlJsonTree getJson = new PastisGetXmlJsonTree();
try {
XMLReader xmlReader = XMLReaderFactory.createXMLReader();
xmlReader.setContentHandler(handler);
xmlReader.parse(new InputSource(file.getInputStream()));
} catch (IOException e) {
return new ResponseEntity<>("Error while processing file : ", HttpStatus.INTERNAL_SERVER_ERROR);
} catch (SAXException e) {
if (e instanceof SAXParseException) {
return new ResponseEntity<>("Erreur lors du chargement du profil, ligne " + ((SAXParseException) e).getLineNumber() + " colonne " + ((SAXParseException) e).getColumnNumber() + ": " + e.getMessage() , HttpStatus.INTERNAL_SERVER_ERROR);
} else {
return new ResponseEntity<>("Error while processing file : ", HttpStatus.INTERNAL_SERVER_ERROR);
}
}
return ResponseEntity.ok(getJson.getJsonParsedTree(handler.elementRNGRoot));
}
@RequestMapping (value = "/getprofiles", method = RequestMethod.GET)
ResponseEntity<List<PastisProfile>> getFiles() throws IOException {
Resource[] resources = ResourcePatternUtils
.getResourcePatternResolver(resourceLoader)
.getResources("classpath*:rng/*.*");
try {
if (pastisProfiles.isEmpty()) {
for (Resource r : resources) {
pastisProfiles.add(new PastisProfile(r.getFilename(), "active", r.lastModified()));
}
}
return ResponseEntity.ok(pastisProfiles);
} catch (Exception e) {
e.printStackTrace();
}
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
/*
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.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import fr.gouv.vitamui.pastis.util.RNGConstants;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
public class ElementProperties implements Serializable {
private static final long serialVersionUID = -5093112183496503253L;
public ElementProperties() {
super();
}
String name;
String type;
String cardinality;
String groupOrChoice;
String valueOrData;
String dataType;
String value;
String documentation;
@JsonIgnore
Object sedaData;
int level;
Long id;
Long parentId;
@JsonIgnore
ElementProperties parent;
List<ElementProperties> choices = new ArrayList<ElementProperties>();
List<ElementProperties> children = new ArrayList<ElementProperties>();
PuaData puaData;
public List<ElementProperties> getChildren() {
return this.children;
}
public void setChildren(List<ElementProperties> children) {
this.children = children;
}
public List<ElementProperties> getChoices() {
return choices;
}
public void setChoices(List<ElementProperties> choices) {
this.choices = choices;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return this.type;
}
public void setType(String type) {
this.type = type;
}
public String getValueOrData() {
return this.valueOrData;
}
public void setValueOrData(String dataType) {
this.valueOrData = dataType;
}
public String getCardinality() {
return this.cardinality;
}
public void setCardinality(String cardinality) {
if(null != RNGConstants.CardinalityMap.get(cardinality)) {
this.cardinality = RNGConstants.CardinalityMap.get(cardinality);
}else {
this.cardinality = cardinality;
}
}
public String getGroupOrChoice() {
return groupOrChoice;
}
public void setGroupOrChoice(String groupOrChoice) {
if(null != RNGConstants.GroupOrChoiceMap.get(groupOrChoice)) {
this.groupOrChoice = RNGConstants.GroupOrChoiceMap.get(groupOrChoice);
}else {
this.groupOrChoice = groupOrChoice;
}
}
public String getValue() {
return this.value;
}
public void setValue(String value) {
this.value = value;
}
public int getLevel() {
return this.level;
}
public void setLevel(int level) {
this.level = level;
}
public String getDataType() {
return this.dataType;
}
public void setDataType(String dataType) {
this.dataType = dataType;
}
public String getDocumentation() {
return this.documentation;
}
public void setDocumentation(String documentation) {
this.documentation = documentation;
}
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public Long getParentId() {
return this.parentId;
}
public void setParentId(Long parentId) {
this.parentId = parentId;
}
@JsonIgnore
public Object getSedaData() {
return sedaData;
}
@JsonIgnore
public void setSedaData(Object sedaData) {
this.sedaData = sedaData;
}
@JsonIgnore
public ElementProperties getParent() {
return parent;
}
@JsonIgnore
public void setParent(ElementProperties parent) {
this.parent = parent;
}
public PuaData getPuaData() {
return puaData;
}
public void setPuaData(PuaData puaData) {
this.puaData = puaData;
}
public void init() {
this.setName("");
this.setCardinality("");
this.setValueOrData("");
this.setGroupOrChoice("");
this.setValue("");
this.setType("");
this.setDataType("");
}
public void initTree(ElementProperties json) {
for(ElementProperties child : json.getChildren()) {
child.setParent(json);
initTree(child);
}
}
public Stream<ElementProperties> flattened() {
return Stream.concat(
Stream.of(this),
children.stream().flatMap(ElementProperties::flattened));
}
}
/*
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.model;
import fr.gouv.vitamui.pastis.util.RNGConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.xml.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import static fr.gouv.vitamui.pastis.util.RNGConstants.TypesMap;
/**
* @author Paulo Pimenta <pimenta@cines.fr>
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class ElementRNG {
public ElementRNG() {
}
String name;
String type;
String dataType;
String value;
ElementRNG parent;
private static Logger LOGGER = LoggerFactory.getLogger(ElementRNG.class);
public static ElementProperties elementStatic = new ElementProperties();
public static ElementProperties elementStaticRoot = new ElementProperties();
private static long idCounter = 0;
List<ElementRNG> children = new ArrayList<ElementRNG>();
@XmlAttribute
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@XmlElement
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@XmlAttribute (name="type")
public String getDataType() {
return dataType;
}
public void setDataType(String dataType) {
this.dataType = dataType;
}
@XmlElement(name="rng:value")
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@XmlTransient
public ElementRNG getParent() {
return parent;
}
public void setParent(ElementRNG parent) {
this.parent = parent;
}
@XmlAnyElement
public List<ElementRNG> getChildren() {
return children;
}
public void setChildren(List<ElementRNG> children) {
this.children = children;
}
public static void setDataForParentElementOrAttribute (ElementProperties parentNode, ElementRNG node) {
if(null != parentNode.getType() && (RNGConstants.MetadaDataType.element.toString().equals(parentNode.getType())
|| RNGConstants.MetadaDataType.attribute.toString().equals(parentNode.getType()))) {
parentNode.setValueOrData(node.getType());
if (TypesMap.containsKey(parentNode.getName())) {
parentNode.setDataType(TypesMap.get(parentNode.getName()).getLabel());
}
parentNode.setValue(node.getValue());
}else {
setDataForParentElementOrAttribute(parentNode.getParent(), node);
}
}
public static void setDocumentationForParentElement (ElementProperties parentNode, ElementRNG node) {
if(null != parentNode.getType() && RNGConstants.MetadaDataType.element.toString().equals(parentNode.getType())) {
parentNode.setDocumentation(node.getValue());
}else {
setDocumentationForParentElement(parentNode.getParent(), node);
}
}
public static void setElementsForGroupOrChoice(ElementProperties parentNode, ElementRNG node) {
if(null != parentNode.getType() && (RNGConstants.GroupOrChoice.group.toString().equals(parentNode.getType())
|| RNGConstants.GroupOrChoice.choice.toString().equals(parentNode.getType()))) {
parentNode.setGroupOrChoice(node.getType());
}else {
setElementsForGroupOrChoice(parentNode.getParent(), node);
}
}
// Build the a tree of properties given :
// a node
//the level of the node
//the parent of the node
public static ElementProperties buildElementPropertiesTree( ElementRNG node, int profondeur, ElementProperties parentNode ){
ElementProperties local = new ElementProperties();
LOGGER.info("Generating JSON element {}", node.getName());
if(null != node.getType() && RNGConstants.MetadaDataType.element.toString().equals(node.getType())
|| RNGConstants.MetadaDataType.attribute.toString().equals(node.getType())) {
local.setCardinality(elementStatic.getCardinality());
local.setGroupOrChoice(elementStatic.getGroupOrChoice());
local.setName(node.getName());
local.setType(node.getType());
local.setLevel(profondeur);
local.setValue(node.getValue());
elementStatic = new ElementProperties();
if(null != parentNode) {
local.setParent(parentNode);
local.setParentId(parentNode.getId());
local.setId(ElementRNG.idCounter++);
parentNode.getChildren().add(local);
}else {
local.setId(ElementRNG.idCounter++);
local.setParentId(null);
elementStaticRoot = local;
}
}
else {
if(RNGConstants.isValueOrData(node.getType())) {
setDataForParentElementOrAttribute(parentNode, node);
}else if(RNGConstants.isCardinality(node.getType())) {
elementStatic.setCardinality(node.getType());
}else if(RNGConstants.hasGroupOrChoice(node.getType())) {
elementStatic.setGroupOrChoice(node.getType());
}
else if("documentation".equals(node.getType())) {
if(null != node.getValue()) {
setDocumentationForParentElement(parentNode, node);
}
}
local = parentNode;
}
for( ElementRNG next : node.getChildren() ) {
if(null != next.getType() && (RNGConstants.MetadaDataType.element.toString().equals(next.getType())
|| RNGConstants.MetadaDataType.attribute.toString().equals(next.getType()))) {
buildElementPropertiesTree( next, profondeur + 1, local );
}else {
buildElementPropertiesTree( next, profondeur, local );
}
}
return local;
}
}
/*
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.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import fr.gouv.vitamui.pastis.util.RNGConstants;
import java.util.ArrayList;
import java.util.List;
public class JsonFromRng {
String name;
String type;
String cardinality;
String valuleOrData;
String dataType;
String value;
String documentation;
int level;
Long id;
Long parentId;
@JsonIgnore
ElementProperties parent;
List<ElementProperties> children = new ArrayList<ElementProperties>();
public List<ElementProperties> getChildren() {
return this.children;
}
public void setChildren(List<ElementProperties> children) {
this.children = children;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return this.type;
}
public void setType(String type) {
this.type = type;
}
public String getValuleOrData() {
return this.valuleOrData;
}
public void setValuleOrData(String dataType) {
this.valuleOrData = dataType;
}
public String getCardinality() {
return this.cardinality;
}
public void setCardinality(String cardinality) {
if(null != RNGConstants.CardinalityMap.get(cardinality)) {
this.cardinality = RNGConstants.CardinalityMap.get(cardinality);
}else {
this.cardinality = cardinality;
}
}
public String getValue() {
return this.value;
}
public void setValue(String value) {
this.value = value;
}
public int getLevel() {
return this.level;
}
public void setLevel(int level) {
this.level = level;
}
public String getDataType() {
return this.dataType;
}
public void setDataType(String dataType) {
this.dataType = dataType;
}
public String getDocumentation() {
return this.documentation;
}
public void setDocumentation(String documentation) {
this.documentation = documentation;
}
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public Long getParentId() {
return this.parentId;
}
public void setParentId(Long parentId) {
this.parentId = parentId;
}
//@JsonIgnore
public ElementProperties getParent() {
return this.parent;
}
//@JsonIgnore
public void setParent(ElementProperties parent) {
this.parent = parent;
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment