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

fix event special rule for childs metadata

parent 71063604
...@@ -241,12 +241,11 @@ public class PuaPastisValidator { ...@@ -241,12 +241,11 @@ public class PuaPastisValidator {
} }
if (sedaElementType.equals("Simple") && !sedaElement.getType().equals("boolean") && !sedaElement.getType().equals("integer") && 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"))) { (sedaCardinality.equals("0-1") || sedaCardinality.equals("1"))) {
return "string"; return "string";
} }
if ((sedaElement.getElement().equals(COMPLEX) && if ((sedaElement.getElement().equals(COMPLEX) &&
(sedaCardinality.equals("0-1") || sedaCardinality.equals("1"))) || (sedaCardinality.equals("0-1") || sedaCardinality.equals("1")))) {
sedaName.equals("Description")) {
return "object"; return "object";
} }
if (sedaType.equals("boolean") && (sedaCardinality.equals("0-1") || sedaCardinality.equals("1"))) { if (sedaType.equals("boolean") && (sedaCardinality.equals("0-1") || sedaCardinality.equals("1"))) {
...@@ -256,11 +255,7 @@ public class PuaPastisValidator { ...@@ -256,11 +255,7 @@ public class PuaPastisValidator {
return "integer"; return "integer";
} }
if (sedaCardinality.equals("1-N") || sedaCardinality.equals("0-N")) { if (sedaCardinality.equals("1-N") || sedaCardinality.equals("0-N")) {
if (element.getCardinality().equals("1")) { return "array";
return "string";
} else {
return "array";
}
} }
return "undefined"; return "undefined";
} }
...@@ -308,6 +303,7 @@ public class PuaPastisValidator { ...@@ -308,6 +303,7 @@ public class PuaPastisValidator {
"ReuseRule", "ClassificationRule"); "ReuseRule", "ClassificationRule");
for (ElementProperties el : elementsFromTree) { for (ElementProperties el : elementsFromTree) {
setMetadataName(el);
try { try {
if (el.getName().equals(MANAGEMENT)) { if (el.getName().equals(MANAGEMENT)) {
JSONObject management = getJSONFromManagement(el); JSONObject management = getJSONFromManagement(el);
...@@ -477,7 +473,8 @@ public class PuaPastisValidator { ...@@ -477,7 +473,8 @@ public class PuaPastisValidator {
private void putChildrenIntoRules(JSONObject childrenOfRule, JSONObject grandChildrenOfRule, private void putChildrenIntoRules(JSONObject childrenOfRule, JSONObject grandChildrenOfRule,
JSONObject propertiesRules, List<String> requiredChildren) { JSONObject propertiesRules, List<String> requiredChildren) {
if (!grandChildrenOfRule.isEmpty()) { if (!grandChildrenOfRule.isEmpty()) {
JSONObject propretyOfItems = new JSONObject().put(PROPERTIES, grandChildrenOfRule); JSONObject propretyOfItems = new JSONObject().put(ADDITIONAL_PROPERTIES, false);
propretyOfItems.put(PROPERTIES, grandChildrenOfRule);
propretyOfItems.put(REQUIRED, requiredChildren); propretyOfItems.put(REQUIRED, requiredChildren);
childrenOfRule.put("type", "array"); childrenOfRule.put("type", "array");
childrenOfRule.put(ITEMS, propretyOfItems); childrenOfRule.put(ITEMS, propretyOfItems);
...@@ -629,6 +626,7 @@ public class PuaPastisValidator { ...@@ -629,6 +626,7 @@ public class PuaPastisValidator {
throws IOException { throws IOException {
if (!elementProperties.getChildren().isEmpty()) { if (!elementProperties.getChildren().isEmpty()) {
for (ElementProperties el : elementProperties.getChildren()) { for (ElementProperties el : elementProperties.getChildren()) {
setMetadataName(el);
PuaMetadataDetails puaMetadataDetails = new PuaMetadataDetails(); PuaMetadataDetails puaMetadataDetails = new PuaMetadataDetails();
puaMetadataDetails.setType(getPUAMetadataType(el.getName(), elementProperties.getName(), el)); puaMetadataDetails.setType(getPUAMetadataType(el.getName(), elementProperties.getName(), el));
puaMetadataDetails.setDescription(el.getDocumentation()); puaMetadataDetails.setDescription(el.getDocumentation());
...@@ -647,42 +645,42 @@ public class PuaPastisValidator { ...@@ -647,42 +645,42 @@ public class PuaPastisValidator {
} }
} }
private void setChildName(ElementProperties elementProperties, JSONObject json, ElementProperties el, PuaMetadataDetails puaMetadataDetails) throws JsonProcessingException { private void setMetadataName(ElementProperties child) {
if (elementProperties.getName().equals("Event")) { switch (child.getName()) {
switch (el.getName()) { case "EventIdentifier":
case "EventIdentifier": child.setName("evId");
json.put("evId", new JSONObject(puaMetadataDetails.serialiseString())); break;
break; case "EventTypeCode":
case "EventTypeCode": child.setName("evTypeProc");
json.put("evTypeProc", new JSONObject(puaMetadataDetails.serialiseString())); break;
break; case "EventType":
case "EventType": child.setName("evType");
json.put("evType", new JSONObject(puaMetadataDetails.serialiseString())); break;
break; case "EventDateTime":
case "EventDateTime": child.setName("evDateTime");
json.put("evDateTime", new JSONObject(puaMetadataDetails.serialiseString())); break;
break; case "EventDetail":
case "EventDetail": child.setName("evTypeDetail");
json.put("evTypeDetail", new JSONObject(puaMetadataDetails.serialiseString())); break;
break; case "Outcome":
case "Outcome": child.setName("outcome");
json.put("outcome", new JSONObject(puaMetadataDetails.serialiseString())); break;
break; case "OutcomeDetail":
case "OutcomeDetail": child.setName("outDetail");
json.put("outDetail", new JSONObject(puaMetadataDetails.serialiseString())); break;
break; case "OutcomeDetailMessage":
case "OutcomeDetailMessage": child.setName("outMessg");
json.put("outMessg", new JSONObject(puaMetadataDetails.serialiseString())); break;
break; case "EventDetailData":
case "EventDetailData": child.setName("evDetData");
json.put("evDetData", new JSONObject(puaMetadataDetails.serialiseString())); break;
break;
}
} else {
json.put(el.getName(), new JSONObject(puaMetadataDetails.serialiseString()));
} }
} }
private void setChildName(ElementProperties elementProperties, JSONObject json, ElementProperties el, PuaMetadataDetails puaMetadataDetails) throws JsonProcessingException {
json.put(el.getName(), new JSONObject(puaMetadataDetails.serialiseString()));
}
public List<String> getRequiredProperties(ElementProperties elementProperties) { public List<String> getRequiredProperties(ElementProperties elementProperties) {
List<String> listRequired = new ArrayList<>(); List<String> listRequired = new ArrayList<>();
elementProperties.getChildren().forEach(child -> { elementProperties.getChildren().forEach(child -> {
...@@ -690,8 +688,11 @@ public class PuaPastisValidator { ...@@ -690,8 +688,11 @@ public class PuaPastisValidator {
SedaNode sedaElement = getSedaMetadata(child.getName(), null); SedaNode sedaElement = getSedaMetadata(child.getName(), null);
if ((child.getCardinality().equals("1-N") && sedaElement.getCardinality().equals("0-N")) if ((child.getCardinality().equals("1-N") && sedaElement.getCardinality().equals("0-N"))
|| (child.getCardinality().equals("1") && !sedaElement.getCardinality().equals("1")) || (child.getCardinality().equals("1") && !sedaElement.getCardinality().equals("1"))
|| sedaElement.getCardinality().equals("1")) || sedaElement.getCardinality().equals("1")) {
setMetadataName(child);
listRequired.add(child.getName()); listRequired.add(child.getName());
child.setName(sedaElement.getName());
}
} catch (IOException e) { } catch (IOException e) {
LOGGER.debug(e.getMessage()); LOGGER.debug(e.getMessage());
} }
...@@ -742,7 +743,7 @@ public class PuaPastisValidator { ...@@ -742,7 +743,7 @@ public class PuaPastisValidator {
) { ) {
puaMetadataDetails.setAdditionalProperties(el.getPuaData().getAdditionalProperties()); puaMetadataDetails.setAdditionalProperties(el.getPuaData().getAdditionalProperties());
} }
if (el.getCardinality() != null && !sedaElement.getCardinality().equals("1") && !puaMetadataDetails.getType().equals("string")) { if (el.getCardinality() != null && puaMetadataDetails.getType().equals("array")) {
getMinAndMAxItems(el, puaMetadataDetails); getMinAndMAxItems(el, puaMetadataDetails);
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
"lastUpdate": "2020-11-26T14:08:20.987", "lastUpdate": "2020-11-26T14:08:20.987",
"activationDate": "2016-12-10T00:00:00.000", "activationDate": "2016-12-10T00:00:00.000",
"deactivationDate": "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, "tenant": 8,
"version": 1, "version": 1,
"fields": [ "fields": [
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
"lastUpdate": "2020-11-26T14:08:20.987", "lastUpdate": "2020-11-26T14:08:20.987",
"activationDate": "2016-12-10T00:00:00.000", "activationDate": "2016-12-10T00:00:00.000",
"deactivationDate": "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, "tenant": 8,
"version": 1, "version": 1,
"fields": [ "fields": [
......
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