Redesigning E/R instance definition

This commit is contained in:
Luca Frosini 2023-04-20 08:27:17 +02:00
parent 999bbb1ab1
commit 5893cfd61a
7 changed files with 60 additions and 48 deletions

View File

@ -18,6 +18,7 @@ import org.gcube.informationsystem.resourceregistry.contexts.security.AdminSecur
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode;
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
import org.gcube.informationsystem.resourceregistry.utils.UUIDUtility;
import org.gcube.informationsystem.resourceregistry.utils.Utility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -194,7 +195,7 @@ public class ContextUtility {
OVertex parentVertex = contextVertex.getVertices(ODirection.IN, IsParentOf.NAME).iterator().next();
if(parentVertex != null) {
UUID parentUUID = Utility.getUUID(parentVertex);
UUID parentUUID = UUIDUtility.getUUID(parentVertex);
securityContext.setParentSecurityContext(getSecurityContextByUUID(parentUUID, parentVertex));
}

View File

@ -48,11 +48,13 @@ import org.gcube.informationsystem.resourceregistry.types.CachedType;
import org.gcube.informationsystem.resourceregistry.types.TypesCache;
import org.gcube.informationsystem.resourceregistry.utils.MetadataOrient;
import org.gcube.informationsystem.resourceregistry.utils.MetadataUtility;
import org.gcube.informationsystem.resourceregistry.utils.UUIDUtility;
import org.gcube.informationsystem.resourceregistry.utils.Utility;
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.UUIDManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -433,14 +435,12 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
reallyCreate();
Metadata entityMetadata = MetadataUtility.getMetadata(jsonNode);
if(entityMetadata != null) {
element.setProperty(IdentifiableElement.METADATA_PROPERTY, entityMetadata);
} else {
entityMetadata = MetadataUtility.addMetadata(element);
if(uuid == null) {
uuid = UUIDManager.getInstance().generateValidRandomUUID();
}
element.setProperty(IdentifiableElement.UUID_PROPERTY, uuid.toString());
this.uuid = Utility.getUUID(element, true);
MetadataUtility.addMetadata(element);
getWorkingContext().addElement(element, oDatabaseDocument);
@ -499,7 +499,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
throw new ResourceRegistryException("Trying to set null " + elementClass.getSimpleName() + " in " + this);
}
this.element = element;
this.uuid = Utility.getUUID(element);
this.uuid = UUIDUtility.getUUID(element);
OClass oClass = getOClass();
this.typeName = oClass.getName();
}
@ -1077,6 +1077,11 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
continue;
}
if(key.compareTo(IdentifiableElement.UUID_PROPERTY)==0) {
// We never update the uuid with the value provided
continue;
}
JsonNode value = properties.get(key);
OProperty oProperty = oClass.getProperty(key);

View File

@ -125,6 +125,7 @@ public abstract class EntityElementManagement<E extends EntityElement, ET extend
}
OVertex vertexEntity = oDatabaseDocument.newVertex(typeName);
this.element = vertexEntity;
try {
if(uuid != null) {
@ -150,8 +151,6 @@ public abstract class EntityElementManagement<E extends EntityElement, ET extend
throw e;
}
this.element = vertexEntity;
if(accessType == AccessType.RESOURCE) {
// Facet and relation are created in calling method
} else {

View File

@ -26,7 +26,7 @@ import org.gcube.informationsystem.resourceregistry.types.CachedType;
import org.gcube.informationsystem.resourceregistry.types.TypesCache;
import org.gcube.informationsystem.resourceregistry.utils.EncryptedOrient;
import org.gcube.informationsystem.resourceregistry.utils.MetadataUtility;
import org.gcube.informationsystem.resourceregistry.utils.Utility;
import org.gcube.informationsystem.resourceregistry.utils.UUIDUtility;
import org.gcube.informationsystem.types.reference.properties.PropertyType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -85,7 +85,7 @@ public class PropertyElementManagement {
}
try {
UUID uuid = Utility.getUUID(jsonNode);
UUID uuid = UUIDUtility.getUUID(jsonNode);
if(uuid != null) {
throw new ResourceRegistryException("A property object cannot have an UUID");
}

View File

@ -29,7 +29,7 @@ import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement;
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
import org.gcube.informationsystem.resourceregistry.instances.model.ERManagement;
import org.gcube.informationsystem.resourceregistry.utils.Utility;
import org.gcube.informationsystem.resourceregistry.utils.UUIDUtility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -122,7 +122,7 @@ public class SharingManager {
for(JsonNode node : arrayNode) {
@SuppressWarnings("unused")
String type = node.get(Element.CLASS_PROPERTY).asText();
UUID uuid = Utility.getUUID(node);
UUID uuid = UUIDUtility.getUUID(node);
expectedInstances.put(uuid, node);
}

View File

@ -0,0 +1,41 @@
package org.gcube.informationsystem.resourceregistry.utils;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.utils.UUIDManager;
import com.orientechnologies.orient.core.record.OElement;
public class UUIDUtility {
public static UUID getUUID(JsonNode jsonNode) throws ResourceRegistryException {
if(jsonNode.has(IdentifiableElement.UUID_PROPERTY)) {
String uuidString = jsonNode.get(IdentifiableElement.UUID_PROPERTY).asText();
return getUUID(uuidString);
}
return null;
}
public static UUID getUUID(OElement element) throws ResourceRegistryException {
String uuidString = element.getProperty(IdentifiableElement.UUID_PROPERTY);
UUID uuid = getUUID(uuidString);
return uuid;
}
public static UUID getUUID(String uuidString) throws ResourceRegistryException {
UUIDManager uuidManager = UUIDManager.getInstance();
UUID uuid = null;
if(uuidString != null) {
if(!uuidManager.isReservedUUID(uuidString)) {
uuid = UUID.fromString(uuidString);
}else {
throw new ResourceRegistryException(uuidString + " UUID is reserved. All the following UUID are reserved " + uuidManager.getAllReservedUUIDAsStrings().toString());
}
}
return uuid;
}
}

View File

@ -16,7 +16,6 @@ import org.gcube.informationsystem.resourceregistry.contexts.security.AdminSecur
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode;
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.informationsystem.utils.UUIDManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -135,37 +134,4 @@ public class Utility {
}
}
public static UUID getUUID(JsonNode jsonNode) throws ResourceRegistryException {
if(jsonNode.has(IdentifiableElement.UUID_PROPERTY)) {
String uuidString = jsonNode.get(IdentifiableElement.UUID_PROPERTY).asText();
return getUUID(uuidString, false);
}
return null;
}
public static UUID getUUID(OElement element) throws ResourceRegistryException {
return getUUID(element, false);
}
public static UUID getUUID(OElement element, boolean create) throws ResourceRegistryException {
String uuidString = element.getProperty(IdentifiableElement.UUID_PROPERTY);
return getUUID(uuidString, create);
}
public static UUID getUUID(String uuidString, boolean create) throws ResourceRegistryException {
UUIDManager uuidManager = UUIDManager.getInstance();
UUID uuid = null;
if(uuidString == null) {
if(create) {
uuid = uuidManager.generateValidRandomUUID();
}
}else {
if(!uuidManager.isReservedUUID(uuidString)) {
uuid = UUID.fromString(uuidString);
}else {
uuid = uuidManager.generateValidRandomUUID();
}
}
return uuid;
}
}