Commit c1cdd3ab authored by Baptiste Toulemonde's avatar Baptiste Toulemonde
Browse files

fix import et tu

parent 9995d9d5
......@@ -51,7 +51,7 @@ import java.util.stream.Stream;
@NoArgsConstructor
public class ElementProperties {
private String additionalProperties;
private boolean additionalProperties;
private String name;
private String type;
private String cardinality;
......
......@@ -70,7 +70,7 @@ public class PuaFromJSON {
// 2. Add type
controlSchema.put("type", TYPE);
// 3. Add additionProperties
controlSchema.put("additionalProperties", elementProperties.getAdditionalProperties());
controlSchema.put("additionalProperties", elementProperties.isAdditionalProperties());
// 4. Check if tree contains Management metadata
addPatternProperties(elementProperties, controlSchema);
List<ElementProperties> elementsForTree = puaPastisValidator.ignoreMetadata(elementProperties);
......
......@@ -124,16 +124,19 @@ public class PuaPastisValidator {
* @param pua The string containing the JSON file to be validated
* @throws AssertionError
*/
public void validatePUA(JSONObject pua) throws AssertionError {
public void validatePUA(JSONObject pua, boolean standalone) throws AssertionError {
JSONObject profileJson = getProfileJsonExpected();
// Compare list of field at the root level
Set<String> actualFieldList = pua.keySet().stream().collect(toSet());
Set<String> expectedFieldList = profileJson.keySet().stream().collect(Collectors.toSet());
if (!actualFieldList.equals(expectedFieldList)) {
throw new AssertionError("PUA field list does not contains the expected values");
if (!standalone) {
Set<String> actualFieldList = pua.keySet().stream().collect(toSet());
Set<String> expectedFieldList = profileJson.keySet().stream().collect(Collectors.toSet());
if (!actualFieldList.equals(expectedFieldList)) {
throw new AssertionError("PUA field list does not contains the expected values");
}
}
// Next tests are controlling the ControlSchema
String controlSchemaString = pua.getString(CONTROLSCHEMA);
JSONObject controlSchemaActual = new JSONObject(controlSchemaString);
......@@ -147,6 +150,11 @@ public class PuaPastisValidator {
JSONAssert.assertEquals(controlSchemaExpected.getJSONObject(DEFINITIONS),
controlSchemaActual.getJSONObject(DEFINITIONS), JSONCompareMode.STRICT);
// Checking that additionalProperties is present and is boolean
if (controlSchemaActual.has("additionalProperties") &&
!(controlSchemaActual.get("additionalProperties") instanceof Boolean)) {
throw new AssertionError("PUA additionalProperties field does not contains a boolean value");
}
// Checking that #management object is present and at the correct position
if (controlSchemaActual.has("patternProperties")) {
JSONObject patternProperties = controlSchemaActual.getJSONObject("patternProperties");
......@@ -327,7 +335,8 @@ public class PuaPastisValidator {
* @param pua
* @throws IOException
*/
private void retrieveAccumalatedJsonManagaementProperties(ElementProperties element, List<String> rulesMetadata, List<String> childrenToEncapsulate, List<String> rulesFound, JSONObject pua) throws IOException {
private void retrieveAccumalatedJsonManagaementProperties(ElementProperties element, List<String> rulesMetadata,
List<String> childrenToEncapsulate, List<String> rulesFound, JSONObject pua) throws IOException {
for (ElementProperties childElement : element.getChildren()) {
JSONObject childrenOfRule = sortedJSON();
JSONObject grandChildrenOfRule = sortedJSON();
......@@ -338,7 +347,8 @@ public class PuaPastisValidator {
SedaNode sedaElement = getSedaMetadata(childElement.getName());
// 1. Check special cases
if (checkSpecialCases(rulesMetadata, rulesFound, childElement, sedaElement)) continue;
if (checkSpecialCases(rulesMetadata, rulesFound, childElement, sedaElement))
continue;
getMetaDataFromSeda(childElement, ruleTypeMetadataDetails, sedaElement);
Map<String, PuaMetadataDetails> ruleTypeMetadataMap = new HashMap<>();
Map<String, PuaMetadataDetails> nonSpecialChildOfRule = new HashMap<>();
......@@ -350,7 +360,8 @@ public class PuaPastisValidator {
for (ElementProperties grandChild : childElement.getChildren()) {
SedaNode node = getSedaMetadata(grandChild.getName());
if (childrenToEncapsulate.contains(grandChild.getName())) {
childrenContainsGrandChildName(grandChildrenOfRule, ruleTypeMetadataDetails, requiredChildren, grandChild, node);
childrenContainsGrandChildName(grandChildrenOfRule, ruleTypeMetadataDetails, requiredChildren,
grandChild, node);
} else {
getMetaDataFromSeda(grandChild, nonSpecialChildOfRuleDetails, node);
nonSpecialChildOfRule.put(grandChild.getName(), nonSpecialChildOfRuleDetails);
......@@ -388,7 +399,8 @@ public class PuaPastisValidator {
* @param sedaElement
* @return
*/
private boolean checkSpecialCases(List<String> rulesMetadata, List<String> rulesFound, ElementProperties childElement, SedaNode sedaElement) {
private boolean checkSpecialCases(List<String> rulesMetadata, List<String> rulesFound,
ElementProperties childElement, SedaNode sedaElement) {
if (!rulesMetadata.contains(childElement.getName()) || sedaElement == null) {
return true;
}
......@@ -398,25 +410,31 @@ public class PuaPastisValidator {
return false;
}
/** put Required Non Special Children
/**
* put Required Non Special Children
*
* @param childElement
* @param requiredNonSpecialChildren
* @param ruleTypeMetadata
*/
private void putRequiredNonSpecialChildren(ElementProperties childElement, List<String> requiredNonSpecialChildren, JSONObject ruleTypeMetadata) {
private void putRequiredNonSpecialChildren(ElementProperties childElement, List<String> requiredNonSpecialChildren,
JSONObject ruleTypeMetadata) {
if (!requiredNonSpecialChildren.isEmpty()) {
ruleTypeMetadata.getJSONObject(childElement.getName())
.put(REQUIRED, requiredNonSpecialChildren);
}
}
/** Put Children into rules
/**
* Put Children into rules
*
* @param childrenOfRule
* @param grandChildrenOfRule
* @param propertiesRules
* @param requiredChildren
*/
private void putChildrenIntoRules(JSONObject childrenOfRule, JSONObject grandChildrenOfRule, JSONObject propertiesRules, List<String> requiredChildren) {
private void putChildrenIntoRules(JSONObject childrenOfRule, JSONObject grandChildrenOfRule,
JSONObject propertiesRules, List<String> requiredChildren) {
if (!grandChildrenOfRule.isEmpty()) {
JSONObject propretyOfItems = new JSONObject().put(PROPERTIES, grandChildrenOfRule);
propretyOfItems.put(REQUIRED, requiredChildren);
......@@ -435,7 +453,9 @@ public class PuaPastisValidator {
* @param node
* @throws JsonProcessingException
*/
private void childrenContainsGrandChildName(JSONObject grandChildrenOfRule, PuaMetadataDetails ruleTypeMetadataDetails, List<String> requiredChildren, ElementProperties grandChild, SedaNode node) throws JsonProcessingException {
private void childrenContainsGrandChildName(JSONObject grandChildrenOfRule,
PuaMetadataDetails ruleTypeMetadataDetails, List<String> requiredChildren, ElementProperties grandChild,
SedaNode node) throws JsonProcessingException {
PuaMetadataDetails childOfRuleDetails = new PuaMetadataDetails();
getMetaDataFromSeda(grandChild, childOfRuleDetails, node);
if (grandChild.getCardinality().equals("0-1") ||
......@@ -619,12 +639,13 @@ public class PuaPastisValidator {
puaMetadataDetails.setMinItems(0);
puaMetadataDetails.setMaxItems(1);
}
if(!sedaElement.getElement().equals(COMPLEX) && el.getPuaData() != null && el.getPuaData().getPattern() != null){
if (!sedaElement.getElement().equals(COMPLEX) && el.getPuaData() != null &&
el.getPuaData().getPattern() != null) {
puaMetadataDetails.setPattern(el.getPuaData().getPattern());
}
if(el.getPuaData() != null && el.getPuaData().getEnum() != null){
if (el.getPuaData() != null && el.getPuaData().getEnum() != null) {
puaMetadataDetails.setEnums(el.getPuaData().getEnum());
}else{
} else {
if (!sedaElement.getEnumeration().isEmpty() && el.getValue() == null) {
puaMetadataDetails.setEnums(sedaElement.getEnumeration());
}
......
......@@ -8,7 +8,7 @@
"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\":{}}",
"controlSchema": "{\"$schema\":\"http://json-schema.org/draft-04/schema\",\"type\":\"object\",\"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": [
......
......@@ -52,6 +52,6 @@ public class PuaPastisValidatorTest {
InputStream inputStreamPua = getClass().getClassLoader().getResourceAsStream(pathFile);
JSONTokener tokener = new JSONTokener(new InputStreamReader(inputStreamPua));
JSONObject profileJson = new JSONObject(tokener);
puaPastisValidator.validatePUA(profileJson);
puaPastisValidator.validatePUA(profileJson, false);
}
}
{
"additionalProperties": null,
"name": "DescriptiveMetadata",
"type": "element",
"cardinality": null,
"groupOrChoice": null,
"level": 0,
"valueOrData": null,
"dataType": null,
"value": null,
"documentation": null,
"type": "element",
"cardinality": null,
"level": 0,
"id": 0,
"parentId": null,
"valueOrData": null,
"editName": null,
"choices": [],
"children": [
{
"additionalProperties": null,
"name": "ArchiveUnit",
"type": "element",
"cardinality": null,
"groupOrChoice": null,
"level": 1,
"valueOrData": null,
"dataType": null,
"value": null,
"documentation": null,
"type": "element",
"cardinality": null,
"level": 1,
"id": 1,
"parentId": 0,
"valueOrData": null,
"editName": null,
"choices": [],
"children": [
{
"groupOrChoice": null,
"level": 2,
"dataType": "ID",
"documentation": null,
"additionalProperties": null,
"name": "id",
"type": "attribute",
"cardinality": null,
"parentId": 1,
"groupOrChoice": null,
"valueOrData": "data",
"editName": null,
"children": [],
"name": "id",
"additionalProperties": null,
"dataType": "ID",
"value": null,
"documentation": null,
"level": 2,
"id": 2,
"parentId": 1,
"choices": [],
"value": null,
"children": [],
"puaData": null
},
{
"groupOrChoice": null,
"level": 2,
"dataType": "token",
"documentation": "DescriptionLevel : cardinalité 0-1 / valeur au choix",
"additionalProperties": null,
"name": "ArchiveUnitProfile",
"type": "element",
"cardinality": "0-1",
"parentId": 1,
"groupOrChoice": null,
"valueOrData": null,
"editName": null,
"children": [],
"name": "ArchiveUnitProfile",
"additionalProperties": null,
"dataType": "token",
"value": null,
"documentation": "DescriptionLevel : cardinalité 0-1 / valeur au choix",
"level": 2,
"id": 12,
"parentId": 1,
"choices": [],
"value": null,
"children": [],
"puaData": null
},
{
"additionalProperties": null,
"name": "Content",
"type": "element",
"cardinality": null,
"groupOrChoice": null,
"level": 2,
"valueOrData": null,
"dataType": null,
"value": null,
"documentation": null,
"type": "element",
"cardinality": null,
"level": 2,
"id": 3,
"parentId": 1,
"valueOrData": null,
"editName": null,
"choices": [],
"children": [
{
"groupOrChoice": null,
"level": 3,
"dataType": "token",
"documentation": "DescriptionLevel : cardinalité 0-1",
"additionalProperties": null,
"name": "DescriptionLevel",
"type": "element",
"cardinality": "0-1",
"parentId": 3,
"groupOrChoice": null,
"valueOrData": null,
"editName": null,
"children": [],
"name": "DescriptionLevel",
"additionalProperties": null,
"dataType": "token",
"value": null,
"documentation": "DescriptionLevel : cardinalité 0-1",
"level": 3,
"id": 5,
"parentId": 3,
"choices": [],
"value": null,
"children": [],
"puaData": {
"exclusiveMaximum": null,
"maxLenght": null,
"additionalProperties": null,
"pattern": null,
"minLenght": null,
"maxLenght": null,
"minimum": null,
"maximum": null,
"additionalProperties": null,
"exclusiveMinimum": null,
"minimum": null,
"exclusiveMaximum": null,
"enum": [
"Fonds",
"Subfonds",
......@@ -103,179 +113,156 @@
"File",
"Item",
"OtherLevel"
],
"minLenght": null
]
}
},
{
"groupOrChoice": null,
"level": 3,
"dataType": "string",
"documentation": "Title : cardinalité 0-N / valeur au choix",
"additionalProperties": null,
"name": "Title",
"type": "element",
"cardinality": "0-N",
"parentId": 3,
"groupOrChoice": null,
"valueOrData": null,
"editName": null,
"children": [],
"name": "Title",
"additionalProperties": null,
"dataType": "string",
"value": null,
"documentation": "Title : cardinalité 0-N / valeur au choix",
"level": 3,
"id": 4,
"parentId": 3,
"choices": [],
"value": null,
"children": [],
"puaData": null
},
{
"groupOrChoice": null,
"level": 3,
"dataType": "token",
"documentation": "FilePlanPosition : cardinalité 0-N / valeur au choix",
"additionalProperties": null,
"name": "FilePlanPosition",
"type": "element",
"cardinality": "0-N",
"parentId": 3,
"groupOrChoice": null,
"valueOrData": null,
"editName": null,
"children": [],
"name": "FilePlanPosition",
"additionalProperties": null,
"dataType": "token",
"value": null,
"documentation": "FilePlanPosition : cardinalité 0-N / valeur au choix",
"level": 3,
"id": 8,
"parentId": 3,
"choices": [],
"value": null,
"children": [],
"puaData": null
},
{
"groupOrChoice": null,
"level": 3,
"dataType": "token",
"documentation": "Tag : cardinalité 0-N / valeur au choix",
"additionalProperties": null,
"name": "Tag",
"type": "element",
"cardinality": "0-N",
"parentId": 3,
"groupOrChoice": null,
"valueOrData": null,
"editName": null,
"children": [],
"name": "Tag",
"additionalProperties": null,
"dataType": "token",
"value": null,
"documentation": "Tag : cardinalité 0-N / valeur au choix",
"level": 3,
"id": 11,
"parentId": 3,
"choices": [],
"value": null,
"children": [],
"puaData": null
},
{
"additionalProperties": null,
"name": "Keyword",
"type": "element",
"cardinality": "0-1",
"groupOrChoice": null,
"level": 3,
"valueOrData": null,
"dataType": "null",
"value": null,
"documentation": "Keyword : cardinalité 0-N / valeur au choix",
"type": "element",
"cardinality": "0-1",
"level": 3,
"id": 6,
"parentId": 3,
"valueOrData": null,
"editName": null,
"choices": [],
"children": [
{
"groupOrChoice": null,
"level": 4,
"dataType": "string",
"documentation": "Identifier : cardinalité 1 / valeur au choix",
"additionalProperties": null,
"name": "KeywordContent",
"type": "element",
"cardinality": "1",
"parentId": 6,
"groupOrChoice": null,
"valueOrData": null,
"editName": null,
"children": [],
"name": "KeywordContent",
"additionalProperties": null,
"dataType": "string",
"value": null,
"documentation": "Identifier : cardinalité 1 / valeur au choix",
"level": 4,
"id": 7,
"parentId": 6,
"choices": [],
"value": null,
"children": [],
"puaData": null
}
],
"name": "Keyword",
"additionalProperties": null,
"id": 6,
"choices": [],
"value": null,
"puaData": {
"exclusiveMaximum": null,
"maxLenght": null,
"additionalProperties": false,
"pattern": null,
"minLenght": null,
"maxLenght": null,
"minimum": null,
"maximum": null,
"additionalProperties": false,
"exclusiveMinimum": null,
"minimum": null,
"enum": null,
"minLenght": null
"exclusiveMaximum": null,
"enum": null
}
},
{
"additionalProperties": null,
"name": "OriginatingAgency",
"type": "element",
"cardinality": "0-1",
"groupOrChoice": null,
"level": 3,
"valueOrData": null,
"dataType": "null",
"value": null,
"documentation": "OriginatingAgency : cardinalité 0-1 / valeur au choix",
"type": "element",
"cardinality": "0-1",
"level": 3,
"id": 9,
"parentId": 3,
"valueOrData": null,
"editName": null,
"choices": [],
"children": [
{
"groupOrChoice": null,
"level": 4,
"dataType": "string",
"documentation": "Identifier : cardinalité 1-1 / valeur au choix",
"additionalProperties": null,
"name": "Identifier",
"type": "element",
"cardinality": "1",
"parentId": 9,
"groupOrChoice": null,
"valueOrData": null,
"editName": null,
"children": [],
"name": "Identifier",
"additionalProperties": null,
"dataType": "string",
"value": null,
"documentation": "Identifier : cardinalité 1-1 / valeur au choix",
"level": 4,
"id": 10,
"parentId": 9,
"choices": [],
"value": null,
"children": [],
"puaData": null
}
],
"name": "OriginatingAgency",
"additionalProperties": null,
"id": 9,
"choices": [],
"value": null,
"puaData": {