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

fix management child metadata order and issue with required metadata

parent e1abd0e2
......@@ -242,12 +242,17 @@ public class JsonFromPUA {
JSONObject childPua = propertiesNew.getJSONObject(childName);
SedaNode childrenSedaNode = getChildrenSedaNode(sedaNode, childName);
ElementProperties childrenParent;
// In a PUA the Content node in ArchiveUnit node is omitted.
// So if we are in the ArchiveUnit Node, then we must check for the children in Content Node as well
if (childrenSedaNode == null && parent.getName().equals("ArchiveUnit")) {
childrenSedaNode = getChildrenSedaNode(getChildrenSedaNode(sedaNode, CONTENT), childName);
if (childPua.optString("type").equals("string") && null !=childrenSedaNode && childrenSedaNode.getCardinality().equals("0-N")) {
childPua.put("minItems", 1);
childPua.put("maxItems", 1);
}
ElementProperties content =
parent.getChildren().stream().filter(c -> c.getName().equals(CONTENT)).findAny()
.orElse(null);
......
......@@ -209,10 +209,10 @@ public class PuaPastisValidator {
* @param name
* @return the seda type of an element
*/
private String getPUAMetadataType(String elementName, String name) throws IOException {
private String getPUAMetadataType(String elementName, String name, ElementProperties elementProperties) throws IOException {
SedaNode sedaElement = getSedaMetadata(elementName, name);
return sedaElement != null ?
resolvePuaType(sedaElement) :
resolvePuaType(sedaElement, elementProperties) :
"undefined";
}
......@@ -222,7 +222,7 @@ public class PuaPastisValidator {
* @param sedaElement the seda element type of the metadata
* @return The type of a pua element
*/
private String resolvePuaType(SedaNode sedaElement) {
private String resolvePuaType(SedaNode sedaElement, ElementProperties element) {
String sedaType = sedaElement.getType();
String sedaElementType = sedaElement.getElement();
String sedaName = sedaElement.getName();
......@@ -232,6 +232,14 @@ public class PuaPastisValidator {
return "string";
}
if(sedaName.equals("Title") || sedaName.equals("Description")) {
if (element.getCardinality().equals("1")) {
return "string";
} else {
return "array";
}
}
if (sedaElementType.equals("Simple") && !sedaElement.getType().equals("boolean") && !sedaElement.getType().equals("integer") &&
(sedaCardinality.equals("0-1") || sedaCardinality.equals("1") || sedaName.equals("Title") || sedaName.equals("Description"))) {
return "string";
......@@ -248,7 +256,11 @@ public class PuaPastisValidator {
return "integer";
}
if (sedaCardinality.equals("1-N") || sedaCardinality.equals("0-N")) {
return "array";
if (element.getCardinality().equals("1")) {
return "string";
} else {
return "array";
}
}
return "undefined";
}
......@@ -271,7 +283,7 @@ public class PuaPastisValidator {
if (elementFound != null && sedaElement != null) {
PuaMetadataDetails puaMetadataDetails = new PuaMetadataDetails();
// get pua type
puaMetadataDetails.setType(resolvePuaType(sedaElement));
puaMetadataDetails.setType(resolvePuaType(sedaElement, elementProperties));
puaMetadataDetails.setDescription((elementFound.getDocumentation()));
// Create a Map<PuaElementName,PuaElementDetails>
Map<String, String> puaMap = new HashMap<>();
......@@ -335,6 +347,7 @@ public class PuaPastisValidator {
List<String> rulesFound = new ArrayList<>();
JSONObject pua = sortedJSON();
pua.put(ADDITIONAL_PROPERTIES, element.isAdditionalProperties());
if (element.getChildren().isEmpty()) {
return retrieveAccumulatedJsonManagementProperties(pua);
}
......@@ -390,7 +403,8 @@ public class PuaPastisValidator {
getMetaDataFromSeda(grandChild, nonSpecialChildOfRuleDetails, node);
nonSpecialChildOfRule.put(grandChild.getName(), nonSpecialChildOfRuleDetails);
//Required field
requiredNonSpecialChildren.add(grandChild.getName());
if (grandChild.getCardinality().equals("1"))
requiredNonSpecialChildren.add(grandChild.getName());
}
ruleTypeMetadataMap.put(childElement.getName(), ruleTypeMetadataDetails);
}
......@@ -401,17 +415,17 @@ public class PuaPastisValidator {
// 4. Convert to jsonobject via map and update its property
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new AfterburnerModule());
JSONObject ruleTypeMetadata = new JSONObject(mapper.writeValueAsString(ruleTypeMetadataMap));
JSONObject ruleTypeMetadata = new JSONObject(ruleTypeMetadataMap);
ruleTypeMetadata.getJSONObject(childElement.getName()).put(PROPERTIES, propertiesRules);
putRequiredNonSpecialChildren(childElement, requiredNonSpecialChildren, ruleTypeMetadata);
nonSpecialChildOfRule.keySet().forEach(e -> {
Object details = nonSpecialChildOfRule.get(e);
ruleTypeMetadata.getJSONObject(childElement.getName()).getJSONObject("properties")
.put(e.toString(), details);
.put(e.toString(), new JSONObject(details));
});
// 5. We retrieve parent properties and add more elements to root element properties
pua.accumulate(PROPERTIES, ruleTypeMetadata.toMap());
pua.accumulate(PROPERTIES, ruleTypeMetadata);
if (!rulesFound.isEmpty())
pua.put(REQUIRED, rulesFound);
}
......@@ -486,8 +500,7 @@ public class PuaPastisValidator {
SedaNode node) throws JsonProcessingException {
PuaMetadataDetails childOfRuleDetails = new PuaMetadataDetails();
getMetaDataFromSeda(grandChild, childOfRuleDetails, node);
if (grandChild.getCardinality().equals("0-1") ||
grandChild.getCardinality().equals("1"))
if (grandChild.getCardinality().equals("1"))
requiredChildren.add(grandChild.getName());
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
......@@ -617,7 +630,7 @@ public class PuaPastisValidator {
if (!elementProperties.getChildren().isEmpty()) {
for (ElementProperties el : elementProperties.getChildren()) {
PuaMetadataDetails puaMetadataDetails = new PuaMetadataDetails();
puaMetadataDetails.setType(getPUAMetadataType(el.getName(), elementProperties.getName()));
puaMetadataDetails.setType(getPUAMetadataType(el.getName(), elementProperties.getName(), el));
puaMetadataDetails.setDescription(el.getDocumentation());
if (null != el.getPuaData() && null != el.getPuaData().getEnum()) {
puaMetadataDetails.setEnums(el.getPuaData().getEnum());
......@@ -639,22 +652,31 @@ public class PuaPastisValidator {
switch (el.getName()) {
case "EventIdentifier":
json.put("evId", new JSONObject(puaMetadataDetails.serialiseString()));
break;
case "EventTypeCode":
json.put("evTypeProc", new JSONObject(puaMetadataDetails.serialiseString()));
break;
case "EventType":
json.put("evType", new JSONObject(puaMetadataDetails.serialiseString()));
break;
case "EventDateTime":
json.put("evDateTime", new JSONObject(puaMetadataDetails.serialiseString()));
break;
case "EventDetail":
json.put("evTypeDetail", new JSONObject(puaMetadataDetails.serialiseString()));
break;
case "Outcome":
json.put("outcome", new JSONObject(puaMetadataDetails.serialiseString()));
break;
case "OutcomeDetail":
json.put("outDetail", new JSONObject(puaMetadataDetails.serialiseString()));
break;
case "OutcomeDetailMessage":
json.put("outMessg", new JSONObject(puaMetadataDetails.serialiseString()));
break;
case "EventDetailData":
json.put("evDetData", new JSONObject(puaMetadataDetails.serialiseString()));
break;
}
} else {
json.put(el.getName(), new JSONObject(puaMetadataDetails.serialiseString()));
......@@ -712,7 +734,7 @@ public class PuaPastisValidator {
public void getMetaDataFromSeda(ElementProperties el, PuaMetadataDetails puaMetadataDetails, SedaNode sedaElement) {
// get pua type
puaMetadataDetails.setType(resolvePuaType(sedaElement));
puaMetadataDetails.setType(resolvePuaType(sedaElement, el));
puaMetadataDetails.setDescription((el.getDocumentation()));
if (sedaElement.getElement().equals(COMPLEX)
&& el.getPuaData() != null
......@@ -720,7 +742,7 @@ public class PuaPastisValidator {
) {
puaMetadataDetails.setAdditionalProperties(el.getPuaData().getAdditionalProperties());
}
if ((el.getCardinality() != null && sedaElement.getCardinality().equals("0-N"))) {
if (el.getCardinality() != null && !sedaElement.getCardinality().equals("1") && !puaMetadataDetails.getType().equals("string")) {
getMinAndMAxItems(el, puaMetadataDetails);
}
......
......@@ -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,\"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\"}}}",
"controlSchema": "{\"$schema\":\"http://json-schema.org/draft-04/schema\",\"type\":\"object\",\"additionalProperties\":false,\"patternProperties\":{\"#management\":{}},\"required\":[\"ArchiveUnitProfile\",\"DescriptionLevel\",\"Title_\",\"#management\"],\"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\":{\"#management\":{\"additionalProperties\": false},\"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": [
......
......@@ -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,\"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\"}}}",
"controlSchema": "{\"$schema\":\"http://json-schema.org/draft-04/schema\",\"type\":\"object\",\"additionalProperties\":false,\"patternProperties\":{\"#management\":{}},\"required\":[\"ArchiveUnitProfile\",\"DescriptionLevel\",\"Title_\",\"#management\"],\"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\":{\"#management\":{\"additionalProperties\": false},\"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": [
......
......@@ -1008,7 +1008,7 @@ export class FileTreeMetadataComponent {
isElementNameNotContentManagement(nomDuChamp: string) {
return !(nomDuChamp === 'Content' || nomDuChamp === 'Management');
return !(nomDuChamp === 'Content' );
}
changeAutorisation($event: MatCheckboxChange, element: any) {
......
......@@ -307,7 +307,7 @@ export class FileTreeComponent implements OnDestroy {
newNode.parent = parent;
newNode.children = [];
newNode.sedaData = sedaChild;
if (this.isElementComplex(newNode)) {
if (this.isElementComplex(newNode) || newNode.name === "Management") {
newNode.puaData = new PUA()
newNode.puaData.additionalProperties = false;
}
......
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