Migrated code to use utility
This commit is contained in:
parent
40b21420a8
commit
b1153f7283
|
@ -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.entities.ResourceType;
|
||||||
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
|
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
|
||||||
import org.gcube.informationsystem.types.reference.properties.PropertyType;
|
import org.gcube.informationsystem.types.reference.properties.PropertyType;
|
||||||
|
import org.gcube.informationsystem.utils.TypeUtility;
|
||||||
import org.gcube.informationsystem.utils.UUIDManager;
|
import org.gcube.informationsystem.utils.UUIDManager;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -313,7 +314,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(typeName==null && jsonNode!=null) {
|
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) {
|
if(this.typeName == null) {
|
||||||
this.typeName = getClassProperty(jsonNode);
|
this.typeName = TypeUtility.getTypeName(jsonNode);
|
||||||
getOClass();
|
getOClass();
|
||||||
} else {
|
} else {
|
||||||
checkERMatch();
|
checkERMatch();
|
||||||
|
@ -348,7 +349,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
||||||
|
|
||||||
protected void checkERMatch() throws ResourceRegistryException {
|
protected void checkERMatch() throws ResourceRegistryException {
|
||||||
if(jsonNode != null) {
|
if(jsonNode != null) {
|
||||||
String type = getClassProperty(jsonNode);
|
String type = TypeUtility.getTypeName(jsonNode);
|
||||||
if(type != null && type.compareTo(typeName) != 0) {
|
if(type != null && type.compareTo(typeName) != 0) {
|
||||||
String error = String.format("Requested type does not match with json representation %s!=%s",
|
String error = String.format("Requested type does not match with json representation %s!=%s",
|
||||||
typeName, type);
|
typeName, type);
|
||||||
|
@ -887,13 +888,6 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
||||||
return getContextsAsObjectNode(objectMapper);
|
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)
|
public static Object getObjectFromJsonNode(JsonNode value)
|
||||||
throws UnsupportedDataTypeException, ResourceRegistryException {
|
throws UnsupportedDataTypeException, ResourceRegistryException {
|
||||||
JsonNodeType jsonNodeType = value.getNodeType();
|
JsonNodeType jsonNodeType = value.getNodeType();
|
||||||
|
|
|
@ -28,6 +28,7 @@ import org.gcube.informationsystem.resourceregistry.utils.EncryptedOrient;
|
||||||
import org.gcube.informationsystem.resourceregistry.utils.MetadataUtility;
|
import org.gcube.informationsystem.resourceregistry.utils.MetadataUtility;
|
||||||
import org.gcube.informationsystem.resourceregistry.utils.UUIDUtility;
|
import org.gcube.informationsystem.resourceregistry.utils.UUIDUtility;
|
||||||
import org.gcube.informationsystem.types.reference.properties.PropertyType;
|
import org.gcube.informationsystem.types.reference.properties.PropertyType;
|
||||||
|
import org.gcube.informationsystem.utils.TypeUtility;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -65,9 +66,9 @@ public class PropertyElementManagement {
|
||||||
((ObjectNode) jsonNode).remove(Element.SUPERCLASSES_PROPERTY);
|
((ObjectNode) jsonNode).remove(Element.SUPERCLASSES_PROPERTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(jsonNode.has(Element.CLASS_PROPERTY)) {
|
String type = TypeUtility.getTypeName(jsonNode);
|
||||||
|
if(type!=null) {
|
||||||
// Complex type
|
// Complex type
|
||||||
String type = ElementManagement.getClassProperty(jsonNode);
|
|
||||||
OClass oClass = null;
|
OClass oClass = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -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.contexts.security.SecurityContext.PermissionMode;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement;
|
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
|
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
|
||||||
|
import org.gcube.informationsystem.utils.TypeUtility;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -43,7 +44,7 @@ public class ERManagementUtility {
|
||||||
Map<UUID, ElementManagement<?,?>> instancesManagement = new HashMap<>();
|
Map<UUID, ElementManagement<?,?>> instancesManagement = new HashMap<>();
|
||||||
Set<UUID> uuids = expectedInstances.keySet();
|
Set<UUID> uuids = expectedInstances.keySet();
|
||||||
for(UUID uuid : uuids) {
|
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<?,?> elementManagement = ElementManagementUtility.getERManagement(type);
|
||||||
elementManagement.setWorkingContext(adminSecurityContext);
|
elementManagement.setWorkingContext(adminSecurityContext);
|
||||||
elementManagement.setODatabaseDocument(oDatabaseDocument);
|
elementManagement.setODatabaseDocument(oDatabaseDocument);
|
||||||
|
@ -123,7 +124,7 @@ public class ERManagementUtility {
|
||||||
|
|
||||||
Map<UUID, ElementManagement<?,?>> instancesManagement = new HashMap<>();
|
Map<UUID, ElementManagement<?,?>> instancesManagement = new HashMap<>();
|
||||||
for(UUID uuid : expectedInstances.keySet()) {
|
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<?,?> elementManagement = ElementManagementUtility.getERManagement(type);
|
||||||
elementManagement.setWorkingContext(adminSecurityContext);
|
elementManagement.setWorkingContext(adminSecurityContext);
|
||||||
elementManagement.setODatabaseDocument(oDatabaseDocument);
|
elementManagement.setODatabaseDocument(oDatabaseDocument);
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||||
import org.gcube.informationsystem.base.reference.Element;
|
import org.gcube.informationsystem.base.reference.Element;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath.SharingOperation;
|
import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath.SharingOperation;
|
||||||
|
import org.gcube.informationsystem.utils.TypeUtility;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -59,8 +60,8 @@ public class SharingOperationValidator implements OperationValidator {
|
||||||
throw new ResourceRegistryException(errorMessage);
|
throw new ResourceRegistryException(errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
String expectedType = expectedJsonNode.get(Element.CLASS_PROPERTY).asText();
|
String expectedType = TypeUtility.getTypeName(expectedJsonNode);
|
||||||
String affectedType = affectedJsonNode.get(Element.CLASS_PROPERTY).asText();
|
String affectedType = TypeUtility.getTypeName(affectedJsonNode);
|
||||||
if(expectedType.compareTo(affectedType)!=0) {
|
if(expectedType.compareTo(affectedType)!=0) {
|
||||||
StringBuffer stringBuffer = new StringBuffer();
|
StringBuffer stringBuffer = new StringBuffer();
|
||||||
stringBuffer.append("The expected type of the instance with UUID ");
|
stringBuffer.append("The expected type of the instance with UUID ");
|
||||||
|
|
|
@ -9,7 +9,6 @@ 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.ArrayNode;
|
||||||
import org.gcube.informationsystem.base.reference.AccessType;
|
import org.gcube.informationsystem.base.reference.AccessType;
|
||||||
import org.gcube.informationsystem.base.reference.Direction;
|
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.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException;
|
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.CachedType;
|
||||||
import org.gcube.informationsystem.resourceregistry.types.TypesCache;
|
import org.gcube.informationsystem.resourceregistry.types.TypesCache;
|
||||||
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
||||||
|
import org.gcube.informationsystem.utils.TypeUtility;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ public class JsonQuery {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonQueryERElement getJsonQueryERElement(JsonNode jsonQuery) throws SchemaNotFoundException, SchemaException, ResourceRegistryException {
|
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();
|
AccessType accessType = TypesCache.getInstance().getCachedType(type).getAccessType();
|
||||||
|
|
||||||
|
|
|
@ -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.QueryConditionalOperator;
|
||||||
import org.gcube.informationsystem.resourceregistry.queries.operators.QueryLogicalOperator;
|
import org.gcube.informationsystem.resourceregistry.queries.operators.QueryLogicalOperator;
|
||||||
import org.gcube.informationsystem.resourceregistry.types.TypesCache;
|
import org.gcube.informationsystem.resourceregistry.types.TypesCache;
|
||||||
|
import org.gcube.informationsystem.utils.TypeUtility;
|
||||||
|
|
||||||
public abstract class JsonQueryERElement {
|
public abstract class JsonQueryERElement {
|
||||||
|
|
||||||
|
@ -42,14 +43,14 @@ public abstract class JsonQueryERElement {
|
||||||
|
|
||||||
public JsonQueryERElement(JsonNode jsonQuery, AccessType accessType) throws SchemaException, ResourceRegistryException {
|
public JsonQueryERElement(JsonNode jsonQuery, AccessType accessType) throws SchemaException, ResourceRegistryException {
|
||||||
this.objectMapper = new ObjectMapper();
|
this.objectMapper = new ObjectMapper();
|
||||||
this.type = jsonQuery.get(Element.CLASS_PROPERTY).asText();
|
this.type = TypeUtility.getTypeName(jsonQuery);
|
||||||
this.jsonNode = jsonQuery;
|
this.jsonNode = jsonQuery;
|
||||||
this.accessType = accessType;
|
this.accessType = accessType;
|
||||||
this.entryPoint = false;
|
this.entryPoint = false;
|
||||||
|
|
||||||
this.fieldNamesToRemove = new HashSet<>();
|
this.fieldNamesToRemove = new HashSet<>();
|
||||||
fieldNamesToRemove.add(Element.CLASS_PROPERTY);
|
this.fieldNamesToRemove.add(Element.CLASS_PROPERTY);
|
||||||
fieldNamesToRemove.add(Element.SUPERCLASSES_PROPERTY);
|
this.fieldNamesToRemove.add(Element.SUPERCLASSES_PROPERTY);
|
||||||
|
|
||||||
validateType(this.type, this.accessType);
|
validateType(this.type, this.accessType);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.ObjectMapper;
|
||||||
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
import org.gcube.common.authorization.library.provider.CalledMethodProvider;
|
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.contexts.reference.entities.Context;
|
||||||
import org.gcube.informationsystem.resourceregistry.ResourceInitializer;
|
import org.gcube.informationsystem.resourceregistry.ResourceInitializer;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
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.base.ElementManagementUtility;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.model.ERManagement;
|
import org.gcube.informationsystem.resourceregistry.instances.model.ERManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.utils.UUIDUtility;
|
import org.gcube.informationsystem.resourceregistry.utils.UUIDUtility;
|
||||||
|
import org.gcube.informationsystem.utils.TypeUtility;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ public class SharingManager {
|
||||||
|
|
||||||
for(JsonNode node : arrayNode) {
|
for(JsonNode node : arrayNode) {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
String type = node.get(Element.CLASS_PROPERTY).asText();
|
String type = TypeUtility.getTypeName(node);
|
||||||
UUID uuid = UUIDUtility.getUUID(node);
|
UUID uuid = UUIDUtility.getUUID(node);
|
||||||
expectedInstances.put(uuid, node);
|
expectedInstances.put(uuid, node);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.resourceregistry.instances.model.relations.IsRelatedToManagement;
|
||||||
import org.gcube.informationsystem.serialization.ElementMapper;
|
import org.gcube.informationsystem.serialization.ElementMapper;
|
||||||
import org.gcube.informationsystem.types.TypeMapper;
|
import org.gcube.informationsystem.types.TypeMapper;
|
||||||
|
import org.gcube.informationsystem.utils.TypeUtility;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -260,7 +261,7 @@ public class MultiContextTest extends ERManagementTest {
|
||||||
String expectedType = TypeMapper.getType(element.getClass());
|
String expectedType = TypeMapper.getType(element.getClass());
|
||||||
|
|
||||||
JsonNode affectedJsonNode = affectedInstances.get(uuid);
|
JsonNode affectedJsonNode = affectedInstances.get(uuid);
|
||||||
String affectedType = affectedJsonNode.get(Element.CLASS_PROPERTY).asText();
|
String affectedType = TypeUtility.getTypeName(affectedJsonNode);
|
||||||
|
|
||||||
Assert.assertTrue(affectedType.compareTo(expectedType) == 0);
|
Assert.assertTrue(affectedType.compareTo(expectedType) == 0);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue