Commit 2bc9bd9c authored by descamps's avatar descamps
Browse files

KDE - Fix pua vitam

parent e00a4ec9
......@@ -77,8 +77,8 @@ public class PuaFromJSON {
controlSchema.put("required", puaPastisValidator.getHeadRequired(elementsForTree));
// 5. Add definitions
JSONObject definitionsFromBasePua = puaPastisValidator.getDefinitionsFromExpectedProfile();
controlSchema.put("definitions", definitionsFromBasePua);
JSONObject definitionsFromBasePua = puaPastisValidator.getDefinitionsFromExpectedProfile();
controlSchema.put("definitions", definitionsFromBasePua);
// 6. Add ArchiveUnitProfile and the rest of the tree
JSONArray allElements = puaPastisValidator.getJSONObjectFromAllTree(elementsForTree);
......
......@@ -60,7 +60,6 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.util.*;
import java.util.stream.Collectors;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toSet;
......@@ -82,13 +81,17 @@ public class PuaPastisValidator {
private static final String CONTENT = "Content";
private static final String COMPLEX = "Complex";
private static final String REQUIRED = "required";
private static final String ID = "id";
private static final String SCHEMA = "$schema";
private JSONObject getProfileJsonExpected() {
private JSONObject getProfileJsonExpected(boolean standalone) {
if (profileJsonExpected == null) {
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("pua_validation/valid_pua.json");
InputStream inputStream;
if(standalone)
inputStream = getClass().getClassLoader().getResourceAsStream("pua_validation/valid_pua.json");
else{
inputStream = getClass().getClassLoader().getResourceAsStream("pua_validation/valid_pua_vitam.json");
}
assert inputStream != null;
JSONTokener tokener = new JSONTokener(new InputStreamReader(inputStream));
setProfileJsonExpected(new JSONObject(tokener));
......@@ -127,7 +130,7 @@ public class PuaPastisValidator {
* @throws AssertionError
*/
public void validatePUA(JSONObject pua, boolean standalone) throws AssertionError {
JSONObject profileJson = getProfileJsonExpected();
JSONObject profileJson = getProfileJsonExpected(standalone);
// Compare list of field at the root level
if (!standalone) {
......@@ -143,6 +146,8 @@ public class PuaPastisValidator {
JSONObject controlSchemaActual = new JSONObject(controlSchemaString);
controlSchemaString = profileJson.getString(CONTROLSCHEMA);
JSONObject controlSchemaExpected = new JSONObject(controlSchemaString);
LOGGER.error(controlSchemaActual.toString() + " control shema actuelle");
LOGGER.error(controlSchemaExpected.toString() + " control shema Expected");
if(standalone) {
// Checking that the whole structure is respected. Doesn't care that the pua contains extended fields.
JSONAssert.assertEquals(controlSchemaExpected, controlSchemaActual, JSONCompareMode.LENIENT);
......@@ -173,9 +178,6 @@ public class PuaPastisValidator {
}
}
else{
if (!controlSchemaActual.has(ID)) {
throw new AssertionError("Missing 'id' key in 'controlSchema' object");
}
if (!controlSchemaActual.has(SCHEMA)) {
throw new AssertionError("Missing '$schema' key in controlSchema' object");
}
......@@ -184,8 +186,9 @@ public class PuaPastisValidator {
public JSONObject getDefinitionsFromExpectedProfile() {
JSONObject baseProfile = getProfileJsonExpected();
JSONObject baseProfile = getProfileJsonExpected(true);
String controlSchema = baseProfile.get(CONTROLSCHEMA).toString();
LOGGER.error(controlSchema + " control shema");
JSONObject controlSchemaAsJSON = new JSONObject(controlSchema);
return controlSchemaAsJSON.getJSONObject(DEFINITIONS);
......
{
"id": "aegaaaaabafbmai5aa2d2alwatqvahqaaaaq",
"identifier": "AUP-000007",
"name": "AUP default PASTIS",
"description": "Import d'un AUP default pour PASTIS",
"status": "ACTIVE",
"creationDate": "2000-09-01T00:00:00.000",
"lastUpdate": "2020-11-26T14:08:20.987",
"activationDate": "2016-12-10T00:00:00.000",
"deactivationDate": "2016-12-10T00:00:00.000",
"controlSchema": "{\"$schema\":\"http://json-schema.org/draft-04/schema\",\"type\":\"object\",\"additionalProperties\":false,\"definitions\":{\"pattern-simple-date\":{\"type\":\"string\",\"pattern\":\"[0-9]{4}-[0-9]{2}-[0-9]{2}\"},\"pattern-date\":{\"type\":\"string\",\"pattern\":\"^([0-8][0-9]{3}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01]))$\"}},\"properties\":{}}",
"tenant": 8,
"version": 1,
"fields": [
],
"type":"PUA"
}
{
"id": "aegaaaaabafbmai5aa2d2alwatqvahqaaaaq",
"identifier": "AUP-000007",
"name": "AUP default PASTIS",
"description": "Import d'un AUP default pour PASTIS",
"status": "ACTIVE",
"creationDate": "2000-09-01T00:00:00.000",
"lastUpdate": "2020-11-26T14:08:20.987",
"activationDate": "2016-12-10T00:00:00.000",
"deactivationDate": "2016-12-10T00:00:00.000",
"controlSchema": "{\"$schema\":\"http://json-schema.org/draft-04/schema\",\"type\":\"object\",\"additionalProperties\":false,\"patternProperties\":{\"#management\":{}},\"required\":[\"ArchiveUnitProfile\",\"DescriptionLevel\",\"Title_\"],\"definitions\":{\"pattern-simple-date\":{\"type\":\"string\",\"pattern\":\"[0-9]{4}-[0-9]{2}-[0-9]{2}\"},\"pattern-date\":{\"type\":\"string\",\"pattern\":\"^([0-8][0-9]{3}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01]))$\"}},\"properties\":{\"ArchiveUnitProfile\":{\"type\":\"string\",\"description\":\"Identifiant du PUA : cardinalité 1\"},\"DescriptionLevel\":{\"type\":\"string\",\"description\":\"Niveau de description : cardinalité 1\"},\"Title_\":{\"type\":\"object\",\"description\":\"Titre de la ressource : cardinalité 1-N\"}}}",
"tenant": 8,
"version": 1,
"fields": [
"ArchiveUnitProfile",
"DescriptionLevel",
"Title"
]
}
......@@ -138,7 +138,7 @@ class PastisController {
@Secured({ServicesData.ROLE_CREATE_ARCHIVE_PROFILES, ServicesData.ROLE_CREATE_PROFILES})
@GetMapping(value = RestApi.PASTIS_CREATE_PROFILE)
ResponseEntity<ProfileResponse> createProfile(@RequestParam(name = "type") String profileType) throws NoSuchAlgorithmException, TechnicalException {
ProfileResponse profileResponse = profileService.createProfile(profileType);
ProfileResponse profileResponse = profileService.createProfile(profileType, false);
if (profileResponse != null) {
return ResponseEntity.ok(profileResponse);
} else {
......
......@@ -61,7 +61,6 @@ import org.json.JSONTokener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.ResourcePatternUtils;
......@@ -94,8 +93,10 @@ public class PastisService {
private final ResourceLoader resourceLoader;
@Value("${rng.base.file}")
private String rngFile;
@Value("${json.template.file}")
private String jsonFile;
@Value("${json.template.fileStandalone}")
private String jsonFileStandalone;
@Value("${json.template.fileVitam}")
private String jsonFileVitam;
@Value("${rng.base.directory}")
private String rngLocation;
private final PuaPastisValidator puaPastisValidator;
......@@ -172,7 +173,7 @@ public class PastisService {
return new ClassPathResource(rngLocation + filename + ".rng");
}
public ProfileResponse createProfile(String type) throws TechnicalException, NoSuchAlgorithmException {
public ProfileResponse createProfile(String type, boolean standalone) throws TechnicalException, NoSuchAlgorithmException {
Resource resource;
ProfileResponse profileResponse = null;
if (type != null && !type.isEmpty()) {
......@@ -180,7 +181,11 @@ public class PastisService {
if (type.equals(ProfileType.PA.getType())) {
resource = new ClassPathResource(rngFile);
} else {
resource = new ClassPathResource(jsonFile);
if(standalone)
resource = new ClassPathResource(jsonFileStandalone);
else{
resource = new ClassPathResource(jsonFileVitam);
}
}
profileResponse = createProfileByType(resource, profileType);
}
......
......@@ -8,7 +8,8 @@ json:
base:
file: rng/ProfileJson.json
template:
file: rng/AUP_default_PASTIS.json
fileStandalone: rng/AUP_default_PASTIS.json
fileVitam: rng/AUP_default_VITAM.json
pua:
definitions:
file: pua_validation/ProfileJson.json
......
{
"id": "aegaaaaabafbmai5aa2d2alwatqvahqaaaaq",
"identifier": "AUP-000007",
"name": "AUP default PASTIS",
"description": "Import d'un AUP default pour PASTIS",
"status": "ACTIVE",
"creationDate": "2000-09-01T00:00:00.000",
"lastUpdate": "2020-11-26T14:08:20.987",
"activationDate": "2016-12-10T00:00:00.000",
"deactivationDate": "2016-12-10T00:00:00.000",
"controlSchema": "{\"$schema\":\"http://json-schema.org/draft-04/schema\",\"type\":\"object\",\"additionalProperties\":false,\"definitions\":{\"pattern-simple-date\":{\"type\":\"string\",\"pattern\":\"[0-9]{4}-[0-9]{2}-[0-9]{2}\"},\"pattern-date\":{\"type\":\"string\",\"pattern\":\"^([0-8][0-9]{3}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01]))$\"}},\"properties\":{}}",
"tenant": 8,
"version": 1,
"fields": [
],
"type":"PUA"
}
......@@ -41,7 +41,7 @@
</dependency>
<dependency>
<groupId>fr.gouv.vitamui</groupId>
<artifactId>pastis</artifactId>
<artifactId>pastis-external</artifactId>
<exclusions>
<exclusion>
<groupId>fr.gouv.vitamui</groupId>
......
......@@ -112,7 +112,7 @@ class PastisController {
tags = {"pastis"})
@GetMapping(value = RestApi.PASTIS_CREATE_PROFILE)
ResponseEntity<ProfileResponse> createProfile(@RequestParam(name = "type") String profileType) throws NoSuchAlgorithmException, TechnicalException {
ProfileResponse profileResponse = profileService.createProfile(profileType);
ProfileResponse profileResponse = profileService.createProfile(profileType, true);
if (profileResponse != null) {
return ResponseEntity.ok(profileResponse);
} else {
......@@ -149,7 +149,8 @@ class PastisController {
@PostMapping(value = RestApi.PASTIS_UPLOAD_PROFILE,
consumes = "multipart/form-data", produces = "application/json")
ResponseEntity<ProfileResponse> loadProfileFromFile(@RequestParam MultipartFile file) throws NoSuchAlgorithmException, TechnicalException {
ProfileResponse profileResponse = profileService.loadProfileFromFile(file, true);
String originalFileName = file.getOriginalFilename();
ProfileResponse profileResponse = profileService.loadProfileFromFile(file, originalFileName,true);
if (profileResponse != null) {
return ResponseEntity.ok(profileResponse);
} else {
......
......@@ -33,7 +33,8 @@ rng.base.file: rng/Profil_seda_pastis_mvp.rng
rng.base.directory: rng/
json.base.file: rng/ProfileJson.json
pua.definitions.file: pua_validation/ProfileJson.json
json.template.file: rng/AUP_default_PASTIS.json
json.template.fileStandalone: rng/AUP_default_PASTIS.json
json.template.fileVitam: rng/AUP_default_VITAM.json
#PORT
server.port: 8096
......
......@@ -17,9 +17,9 @@
<module>pastis-commons</module>
<module>pastis-client</module>
<module>pastis-external</module>
<!--
<module>pastis-standalone</module>
-->
</modules>
</project>
......@@ -435,7 +435,7 @@
</dependency>
<dependency>
<groupId>fr.gouv.vitamui</groupId>
<artifactId>pastis</artifactId>
<artifactId>pastis-external</artifactId>
<version>${project.version}</version>
</dependency>
......
Supports Markdown
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