Migrated code to use utility

This commit is contained in:
Luca Frosini 2023-04-21 16:41:35 +02:00
parent 40b21420a8
commit b1153f7283
8 changed files with 23 additions and 24 deletions

View File

@ -54,6 +54,7 @@ import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.types.reference.entities.ResourceType;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import org.gcube.informationsystem.types.reference.properties.PropertyType;
import org.gcube.informationsystem.utils.TypeUtility;
import org.gcube.informationsystem.utils.UUIDManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -313,7 +314,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
}
if(typeName==null && jsonNode!=null) {
this.typeName = getClassProperty(jsonNode);
this.typeName = TypeUtility.getTypeName(jsonNode);
}
}
@ -339,7 +340,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
}
if(this.typeName == null) {
this.typeName = getClassProperty(jsonNode);
this.typeName = TypeUtility.getTypeName(jsonNode);
getOClass();
} else {
checkERMatch();
@ -348,7 +349,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
protected void checkERMatch() throws ResourceRegistryException {
if(jsonNode != null) {
String type = getClassProperty(jsonNode);
String type = TypeUtility.getTypeName(jsonNode);
if(type != null && type.compareTo(typeName) != 0) {
String error = String.format("Requested type does not match with json representation %s!=%s",
typeName, type);
@ -887,13 +888,6 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
return getContextsAsObjectNode(objectMapper);
}
public static String getClassProperty(JsonNode jsonNode) {
if(jsonNode.has(Element.CLASS_PROPERTY)) {
return jsonNode.get(Element.CLASS_PROPERTY).asText();
}
return null;
}
public static Object getObjectFromJsonNode(JsonNode value)
throws UnsupportedDataTypeException, ResourceRegistryException {
JsonNodeType jsonNodeType = value.getNodeType();

View File

@ -28,6 +28,7 @@ import org.gcube.informationsystem.resourceregistry.utils.EncryptedOrient;
import org.gcube.informationsystem.resourceregistry.utils.MetadataUtility;
import org.gcube.informationsystem.resourceregistry.utils.UUIDUtility;
import org.gcube.informationsystem.types.reference.properties.PropertyType;
import org.gcube.informationsystem.utils.TypeUtility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -65,9 +66,9 @@ public class PropertyElementManagement {
((ObjectNode) jsonNode).remove(Element.SUPERCLASSES_PROPERTY);
}
if(jsonNode.has(Element.CLASS_PROPERTY)) {
String type = TypeUtility.getTypeName(jsonNode);
if(type!=null) {
// Complex type
String type = ElementManagement.getClassProperty(jsonNode);
OClass oClass = null;
try {

View File

@ -16,6 +16,7 @@ import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityCo
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode;
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement;
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
import org.gcube.informationsystem.utils.TypeUtility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -43,7 +44,7 @@ public class ERManagementUtility {
Map<UUID, ElementManagement<?,?>> instancesManagement = new HashMap<>();
Set<UUID> uuids = expectedInstances.keySet();
for(UUID uuid : uuids) {
String type = expectedInstances.get(uuid).get(Element.CLASS_PROPERTY).asText();
String type = TypeUtility.getTypeName(expectedInstances.get(uuid));
ElementManagement<?,?> elementManagement = ElementManagementUtility.getERManagement(type);
elementManagement.setWorkingContext(adminSecurityContext);
elementManagement.setODatabaseDocument(oDatabaseDocument);
@ -123,7 +124,7 @@ public class ERManagementUtility {
Map<UUID, ElementManagement<?,?>> instancesManagement = new HashMap<>();
for(UUID uuid : expectedInstances.keySet()) {
String type = expectedInstances.get(uuid).get(Element.CLASS_PROPERTY).asText();
String type = TypeUtility.getTypeName(expectedInstances.get(uuid));
ElementManagement<?,?> elementManagement = ElementManagementUtility.getERManagement(type);
elementManagement.setWorkingContext(adminSecurityContext);
elementManagement.setODatabaseDocument(oDatabaseDocument);

View File

@ -9,6 +9,7 @@ import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath.SharingOperation;
import org.gcube.informationsystem.utils.TypeUtility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -59,8 +60,8 @@ public class SharingOperationValidator implements OperationValidator {
throw new ResourceRegistryException(errorMessage);
}
String expectedType = expectedJsonNode.get(Element.CLASS_PROPERTY).asText();
String affectedType = affectedJsonNode.get(Element.CLASS_PROPERTY).asText();
String expectedType = TypeUtility.getTypeName(expectedJsonNode);
String affectedType = TypeUtility.getTypeName(affectedJsonNode);
if(expectedType.compareTo(affectedType)!=0) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("The expected type of the instance with UUID ");

View File

@ -9,7 +9,6 @@ import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.Direction;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException;
@ -27,6 +26,7 @@ import org.gcube.informationsystem.resourceregistry.queries.json.base.relations.
import org.gcube.informationsystem.resourceregistry.types.CachedType;
import org.gcube.informationsystem.resourceregistry.types.TypesCache;
import org.gcube.informationsystem.resourceregistry.utils.Utility;
import org.gcube.informationsystem.utils.TypeUtility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -67,7 +67,7 @@ public class JsonQuery {
}
public static JsonQueryERElement getJsonQueryERElement(JsonNode jsonQuery) throws SchemaNotFoundException, SchemaException, ResourceRegistryException {
String type = jsonQuery.get(Element.CLASS_PROPERTY).asText();
String type = TypeUtility.getTypeName(jsonQuery);
AccessType accessType = TypesCache.getInstance().getCachedType(type).getAccessType();

View File

@ -18,6 +18,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaN
import org.gcube.informationsystem.resourceregistry.queries.operators.QueryConditionalOperator;
import org.gcube.informationsystem.resourceregistry.queries.operators.QueryLogicalOperator;
import org.gcube.informationsystem.resourceregistry.types.TypesCache;
import org.gcube.informationsystem.utils.TypeUtility;
public abstract class JsonQueryERElement {
@ -42,14 +43,14 @@ public abstract class JsonQueryERElement {
public JsonQueryERElement(JsonNode jsonQuery, AccessType accessType) throws SchemaException, ResourceRegistryException {
this.objectMapper = new ObjectMapper();
this.type = jsonQuery.get(Element.CLASS_PROPERTY).asText();
this.type = TypeUtility.getTypeName(jsonQuery);
this.jsonNode = jsonQuery;
this.accessType = accessType;
this.entryPoint = false;
this.fieldNamesToRemove = new HashSet<>();
fieldNamesToRemove.add(Element.CLASS_PROPERTY);
fieldNamesToRemove.add(Element.SUPERCLASSES_PROPERTY);
this.fieldNamesToRemove.add(Element.CLASS_PROPERTY);
this.fieldNamesToRemove.add(Element.SUPERCLASSES_PROPERTY);
validateType(this.type, this.accessType);
}

View File

@ -16,7 +16,6 @@ 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.common.authorization.library.provider.CalledMethodProvider;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.contexts.reference.entities.Context;
import org.gcube.informationsystem.resourceregistry.ResourceInitializer;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
@ -30,6 +29,7 @@ import org.gcube.informationsystem.resourceregistry.instances.base.ElementManage
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
import org.gcube.informationsystem.resourceregistry.instances.model.ERManagement;
import org.gcube.informationsystem.resourceregistry.utils.UUIDUtility;
import org.gcube.informationsystem.utils.TypeUtility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -121,7 +121,7 @@ public class SharingManager {
for(JsonNode node : arrayNode) {
@SuppressWarnings("unused")
String type = node.get(Element.CLASS_PROPERTY).asText();
String type = TypeUtility.getTypeName(node);
UUID uuid = UUIDUtility.getUUID(node);
expectedInstances.put(uuid, node);
}

View File

@ -29,6 +29,7 @@ import org.gcube.informationsystem.resourceregistry.instances.model.entities.Res
import org.gcube.informationsystem.resourceregistry.instances.model.relations.IsRelatedToManagement;
import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.utils.TypeUtility;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -260,7 +261,7 @@ public class MultiContextTest extends ERManagementTest {
String expectedType = TypeMapper.getType(element.getClass());
JsonNode affectedJsonNode = affectedInstances.get(uuid);
String affectedType = affectedJsonNode.get(Element.CLASS_PROPERTY).asText();
String affectedType = TypeUtility.getTypeName(affectedJsonNode);
Assert.assertTrue(affectedType.compareTo(expectedType) == 0);