Attributes of a type extending Property now include superclasses

This commit is contained in:
Luca Frosini 2023-02-28 15:14:33 +01:00
parent a896d1fdc0
commit 2dfd6db506
1 changed files with 16 additions and 2 deletions

View File

@ -1,11 +1,13 @@
package org.gcube.informationsystem.resourceregistry.instances.base.properties;
import java.security.Key;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
import org.gcube.common.encryption.encrypter.StringEncrypter;
import org.gcube.informationsystem.base.reference.AccessType;
@ -50,12 +52,18 @@ public class PropertyElementManagement {
}
public static ODocument getPropertyDocument(JsonNode jsonNode) throws ResourceRegistryException {
public static ODocument getPropertyDocument(JsonNode jsonNodeOrig) throws ResourceRegistryException {
ODocument oDocument = null;
if(jsonNode.isNull()) {
if(jsonNodeOrig.isNull()) {
return null;
}
JsonNode jsonNode = jsonNodeOrig.deepCopy();
if(jsonNode.has(Element.SUPERCLASSES_PROPERTY)) {
((ObjectNode) jsonNode).remove(Element.SUPERCLASSES_PROPERTY);
}
if(jsonNode.has(Element.CLASS_PROPERTY)) {
// Complex type
String type = ElementManagement.getClassProperty(jsonNode);
@ -70,6 +78,7 @@ public class PropertyElementManagement {
if(!AccessType.PROPERTY_ELEMENT.getClass().isAssignableFrom(gotAccessType.getClass())) {
throw new SchemaException(type + " is not a " + AccessType.PROPERTY_ELEMENT.getName());
}
} catch(SchemaNotFoundException e) {
throw e;
}
@ -154,6 +163,11 @@ public class PropertyElementManagement {
if(!AccessType.PROPERTY_ELEMENT.getClass().isAssignableFrom(gotAccessType.getClass())) {
throw new SchemaException(type + " is not a " + AccessType.PROPERTY_ELEMENT.getName());
}
Collection<String> superClasses = cachedType.getSuperTypes();
ArrayNode arrayNode = objectMapper.valueToTree(superClasses);
((ObjectNode) jsonNode).replace(Element.SUPERCLASSES_PROPERTY, arrayNode);
/*
* In case it is an Encrypted type the value is encrypted with the DB Key
* Resource Registry must decrypt the value with the DB Key and Encrypt it with Context key.