Refactoring service to be aligned with IS model refactorign
This commit is contained in:
parent
914f267c29
commit
383887e7d2
|
@ -16,11 +16,11 @@ import org.gcube.common.encryption.SymmetricKey;
|
|||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.base.reference.ISConstants;
|
||||
import org.gcube.informationsystem.base.reference.ISManageable;
|
||||
import org.gcube.informationsystem.resourceregistry.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.AdminSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.ContextSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.SchemaSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.security.AdminSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.security.ContextSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SchemaSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.types.reference.TypeDefinition;
|
||||
import org.gcube.informationsystem.utils.discovery.ISMDiscovery;
|
||||
import org.gcube.informationsystem.utils.discovery.RegistrationProvider;
|
||||
|
@ -212,7 +212,6 @@ public class DatabaseEnvironment {
|
|||
|
||||
List<Package> packages = new ArrayList<Package>();
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
Class<TypeDefinition> tdClz = TypeDefinition.class;
|
||||
packages.add(tdClz.getPackage());
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@ import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
|||
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
||||
import org.gcube.informationsystem.model.reference.relations.Relation;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.schema.SchemaManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.schema.SchemaManagementImpl;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.type.SchemaManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.type.SchemaManagementImpl;
|
||||
import org.gcube.informationsystem.types.TypeBinder;
|
||||
import org.gcube.informationsystem.utils.discovery.SchemaAction;
|
||||
import org.slf4j.Logger;
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
package org.gcube.informationsystem.resourceregistry.er;
|
||||
package org.gcube.informationsystem.resourceregistry.instances.base;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
@ -25,11 +27,12 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundExcep
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
|
||||
import org.gcube.informationsystem.resourceregistry.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
||||
import org.gcube.informationsystem.resourceregistry.schema.SchemaManagementImpl;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.properties.BasePropertyManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.type.SchemaManagementImpl;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.HeaderOrient;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.HeaderUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
||||
|
@ -721,13 +724,9 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
|||
|
||||
switch(jsonNodeType) {
|
||||
case OBJECT:
|
||||
return PropertyManagement.getPropertyDocument(value);
|
||||
return BasePropertyManagement.getPropertyDocument(value);
|
||||
|
||||
case ARRAY:
|
||||
/*
|
||||
* List/Set support is currently disabled due to OrientDB bug see https://github.com/orientechnologies/orientdb/issues/7354
|
||||
*/
|
||||
/*
|
||||
List<Object> list = new ArrayList<Object>();
|
||||
Iterator<JsonNode> arrayElement = value.elements();
|
||||
while(arrayElement.hasNext()) {
|
||||
|
@ -738,10 +737,13 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
|||
}
|
||||
}
|
||||
return list;
|
||||
*/
|
||||
|
||||
/*
|
||||
* List/Set support is currently disabled due to OrientDB bug see https://github.com/orientechnologies/orientdb/issues/7354
|
||||
*
|
||||
throw new UnsupportedDataTypeException(
|
||||
"List/Set support is currently disabled due to OrientDB bug see https://github.com/orientechnologies/orientdb/issues/7354");
|
||||
|
||||
*/
|
||||
case BINARY:
|
||||
break;
|
||||
|
||||
|
@ -870,7 +872,6 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
|||
/*
|
||||
* List/Set support is currently disabled due to OrientDB bug see https://github.com/orientechnologies/orientdb/issues/7354
|
||||
*/
|
||||
/*
|
||||
if(object instanceof Set) {
|
||||
((OrientElement) element).setProperty(key, object, OType.EMBEDDEDSET);
|
||||
set = true;
|
||||
|
@ -879,7 +880,6 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
|||
((OrientElement) element).setProperty(key, object, OType.EMBEDDEDLIST);
|
||||
set = true;
|
||||
}
|
||||
*/
|
||||
|
||||
if(!set) {
|
||||
element.setProperty(key, object);
|
||||
|
@ -938,7 +938,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
|||
|
||||
if(object instanceof ODocument) {
|
||||
ODocument oDocument = (ODocument) object;
|
||||
return PropertyManagement.getJsonNode(oDocument);
|
||||
return BasePropertyManagement.getJsonNode(oDocument);
|
||||
}
|
||||
|
||||
if(object instanceof Date) {
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.informationsystem.resourceregistry.er;
|
||||
package org.gcube.informationsystem.resourceregistry.instances.base;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -12,14 +12,14 @@ import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
|||
import org.gcube.informationsystem.model.reference.relations.Relation;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.er.entity.EntityManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.er.entity.FacetManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.er.entity.ResourceManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.er.relation.ConsistsOfManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.er.relation.IsRelatedToManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.er.relation.RelationManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.schema.SchemaManagementImpl;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.entity.EntityManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.entity.FacetManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.entity.ResourceManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.relation.ConsistsOfManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.relation.IsRelatedToManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.relation.RelationManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.type.SchemaManagementImpl;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -42,6 +42,7 @@ public class ERManagementUtility {
|
|||
private static Logger logger = LoggerFactory.getLogger(EntityManagement.class);
|
||||
|
||||
public static AccessType getBaseAccessType(String type) throws ResourceRegistryException {
|
||||
|
||||
OClass oClass = SchemaManagementImpl.getTypeSchema(type, null);
|
||||
|
||||
if(oClass.isSubClassOf(Resource.NAME)) {
|
|
@ -0,0 +1,173 @@
|
|||
package org.gcube.informationsystem.resourceregistry.instances.base.entities;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.base.reference.entities.BaseEntity;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.EntityAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagementUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.relations.BaseRelationManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
import com.tinkerpop.blueprints.Element;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientVertex;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public abstract class BaseEntityManagement<E extends BaseEntity> extends ERManagement<E,Vertex> {
|
||||
|
||||
/**
|
||||
* Provide a cache edge-internal-id -> RelationManagement
|
||||
* this avoid to recreate the relationManagement of already visited edges
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected Map<String,BaseRelationManagement> relationManagements;
|
||||
|
||||
protected BaseEntityManagement(AccessType accessType) {
|
||||
super(accessType);
|
||||
|
||||
this.ignoreKeys.add(BaseEntity.HEADER_PROPERTY);
|
||||
|
||||
this.ignoreStartWithKeys.add(OrientVertex.CONNECTION_IN_PREFIX.toLowerCase());
|
||||
this.ignoreStartWithKeys.add(OrientVertex.CONNECTION_OUT_PREFIX.toLowerCase());
|
||||
this.ignoreStartWithKeys.add(OrientVertex.CONNECTION_IN_PREFIX.toUpperCase());
|
||||
this.ignoreStartWithKeys.add(OrientVertex.CONNECTION_OUT_PREFIX.toUpperCase());
|
||||
|
||||
this.relationManagements = new HashMap<>();
|
||||
|
||||
}
|
||||
|
||||
protected BaseEntityManagement(AccessType accessType, SecurityContext workingContext, OrientGraph orientGraph) {
|
||||
this(accessType);
|
||||
this.orientGraph = orientGraph;
|
||||
setWorkingContext(workingContext);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
/*
|
||||
* It works perfectly in case of any kind of update. In case of use from create
|
||||
* the cache does not work by using the ID because until commit the edge has a
|
||||
* fake id starting with - (minus) sign. This not imply any collateral effect
|
||||
* but a better solution is a desiderata.
|
||||
*/
|
||||
protected BaseRelationManagement getBaseRelationManagement(Edge edge) throws ResourceRegistryException {
|
||||
String id = edge.getId().toString();
|
||||
BaseRelationManagement relationManagement = relationManagements.get(id);
|
||||
if(relationManagement == null) {
|
||||
relationManagement = ERManagementUtility.getRelationManagement(getWorkingContext(), orientGraph, edge);
|
||||
relationManagements.put(id, relationManagement);
|
||||
}
|
||||
return relationManagement;
|
||||
}
|
||||
|
||||
protected void addToRelationManagement(@SuppressWarnings("rawtypes") BaseRelationManagement baseRelationManagement)
|
||||
throws ResourceRegistryException {
|
||||
Element elem = baseRelationManagement.getElement();
|
||||
String id = elem.getId().toString();
|
||||
if(relationManagements.get(id) != null && relationManagements.get(id) != baseRelationManagement) {
|
||||
StringBuilder errorMessage = new StringBuilder();
|
||||
errorMessage.append("Two different instance of ");
|
||||
errorMessage.append(baseRelationManagement.getClass().getSimpleName());
|
||||
errorMessage.append(" point to the same ");
|
||||
errorMessage.append(elem.getClass().getSimpleName());
|
||||
errorMessage.append(". ");
|
||||
errorMessage.append(Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
throw new ResourceRegistryException(errorMessage.toString());
|
||||
}
|
||||
relationManagements.put(id, baseRelationManagement);
|
||||
}
|
||||
|
||||
protected static JsonNode addRelation(JsonNode sourceResource, JsonNode relation, String arrayKey)
|
||||
throws ResourceRegistryException {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
ArrayNode relationArray = objectMapper.createArrayNode();
|
||||
try {
|
||||
if(sourceResource.has(arrayKey)) {
|
||||
relationArray = (ArrayNode) sourceResource.get(arrayKey);
|
||||
}
|
||||
relationArray.add(relation);
|
||||
|
||||
((ObjectNode) sourceResource).replace(arrayKey, relationArray);
|
||||
} catch(Exception e) {
|
||||
throw new ResourceRegistryException(e);
|
||||
}
|
||||
return sourceResource;
|
||||
}
|
||||
|
||||
protected Vertex createVertex() throws EntityAlreadyPresentException, ResourceRegistryException {
|
||||
|
||||
logger.trace("Going to create {} for {} ({}) using {}", Vertex.class.getSimpleName(), accessType.getName(),
|
||||
elementType, jsonNode);
|
||||
|
||||
try {
|
||||
|
||||
if(oClass.isAbstract()) {
|
||||
String error = String.format(
|
||||
"Trying to create an instance of %s of type %s which is abstract. The operation will be aborted.",
|
||||
accessType.getName(), elementType);
|
||||
throw new ResourceRegistryException(error);
|
||||
}
|
||||
|
||||
Vertex vertexEntity = orientGraph.addVertex("class:" + elementType);
|
||||
|
||||
try {
|
||||
if(uuid != null) {
|
||||
Vertex v = getElement();
|
||||
if(v != null) {
|
||||
String error = String.format("A %s with UUID %s already exist", elementType, uuid.toString());
|
||||
throw getSpecificERAlreadyPresentException(error);
|
||||
}
|
||||
}
|
||||
|
||||
} catch(NotFoundException e) {
|
||||
try {
|
||||
Element el = ERManagementUtility.getAnyElementByUUID(uuid);
|
||||
String error = String.format("UUID %s is already used by another %s. This is not allowed.",
|
||||
uuid.toString(),
|
||||
(el instanceof Vertex) ? org.gcube.informationsystem.model.reference.entities.Entity.NAME :
|
||||
org.gcube.informationsystem.model.reference.relations.Relation.NAME);
|
||||
throw getSpecificERAvailableInAnotherContextException(error);
|
||||
|
||||
} catch(NotFoundException e1) {
|
||||
// OK the UUID is not already used.
|
||||
}
|
||||
} catch(AvailableInAnotherContextException e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
this.element = vertexEntity;
|
||||
|
||||
if(accessType == AccessType.RESOURCE) {
|
||||
// Facet and relation are created in calling method
|
||||
} else {
|
||||
ERManagement.updateProperties(oClass, element, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||
}
|
||||
|
||||
logger.info("Created {} is {}", Vertex.class.getSimpleName(),
|
||||
Utility.toJsonString((OrientVertex) element, true));
|
||||
|
||||
return element;
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
logger.trace("Error while creating {} for {} ({}) using {}", Vertex.class.getSimpleName(),
|
||||
accessType.getName(), elementType, jsonNode, e);
|
||||
throw new ResourceRegistryException("Error Creating " + elementType + " with " + jsonNode, e.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.informationsystem.resourceregistry.er;
|
||||
package org.gcube.informationsystem.resourceregistry.instances.base.properties;
|
||||
|
||||
import java.security.Key;
|
||||
import java.util.HashSet;
|
||||
|
@ -13,7 +13,8 @@ import org.gcube.informationsystem.model.reference.properties.Property;
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
||||
import org.gcube.informationsystem.resourceregistry.schema.SchemaManagementImpl;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.type.SchemaManagementImpl;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.EncryptedOrient;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.HeaderUtility;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -28,9 +29,9 @@ import com.orientechnologies.orient.core.record.impl.ODocument;
|
|||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class PropertyManagement {
|
||||
public class BasePropertyManagement {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(PropertyManagement.class);
|
||||
private static Logger logger = LoggerFactory.getLogger(BasePropertyManagement.class);
|
||||
|
||||
public static final Set<String> PROPERTY_IGNORE_KEYS;
|
||||
public static final Set<String> PROPERTY_IGNORE_START_WITH_KEYS;
|
||||
|
@ -55,7 +56,7 @@ public class PropertyManagement {
|
|||
OClass oClass = null;
|
||||
|
||||
try {
|
||||
oClass = SchemaManagementImpl.getTypeSchema(type, AccessType.PROPERTY);
|
||||
oClass = SchemaManagementImpl.getTypeSchema(type, AccessType.BASE_PROPERTY);
|
||||
} catch(SchemaNotFoundException e) {
|
||||
throw e;
|
||||
}
|
||||
|
@ -86,8 +87,6 @@ public class PropertyManagement {
|
|||
// Decrypting with Context Key (default key)
|
||||
String decryptedValue = EncryptedImpl.decrypt(contextEncryptedValue);
|
||||
|
||||
|
||||
|
||||
encrypted.setDecryptedValue(decryptedValue, false);
|
||||
|
||||
/*
|
|
@ -0,0 +1,219 @@
|
|||
package org.gcube.informationsystem.resourceregistry.instances.base.relations;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.base.reference.entities.BaseEntity;
|
||||
import org.gcube.informationsystem.base.reference.relations.BaseRelation;
|
||||
import org.gcube.informationsystem.model.reference.relations.Relation;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.RelationNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.entities.BaseEntityManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.entity.FacetManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.tinkerpop.blueprints.Direction;
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientBaseGraph;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public abstract class BaseRelationManagement<R extends BaseRelation<S, T>, SEM extends BaseEntityManagement<S>, TEM extends BaseEntityManagement<T>, S extends BaseEntity, T extends BaseEntity>
|
||||
extends ERManagement<R,Edge> {
|
||||
|
||||
protected final Class<S> sourceEntityClass;
|
||||
protected final Class<T> targetEntityClass;
|
||||
|
||||
protected SEM sourceEntityManagement;
|
||||
protected TEM targetEntityManagement;
|
||||
|
||||
protected BaseRelationManagement(AccessType accessType, Class<S> sourceEntityClass, Class<T> targetEntityClass) {
|
||||
super(accessType);
|
||||
|
||||
this.ignoreKeys.add(Relation.HEADER_PROPERTY);
|
||||
this.ignoreKeys.add(Relation.SOURCE_PROPERTY);
|
||||
this.ignoreKeys.add(Relation.TARGET_PROPERTY);
|
||||
this.ignoreKeys.add(OrientBaseGraph.CONNECTION_OUT.toLowerCase());
|
||||
this.ignoreKeys.add(OrientBaseGraph.CONNECTION_IN.toLowerCase());
|
||||
this.ignoreKeys.add(OrientBaseGraph.CONNECTION_OUT.toUpperCase());
|
||||
this.ignoreKeys.add(OrientBaseGraph.CONNECTION_IN.toUpperCase());
|
||||
|
||||
this.sourceEntityClass = sourceEntityClass;
|
||||
this.targetEntityClass = targetEntityClass;
|
||||
|
||||
this.sourceEntityManagement = null;
|
||||
this.targetEntityManagement = null;
|
||||
}
|
||||
|
||||
protected BaseRelationManagement(AccessType accessType, Class<S> sourceEntityClass, Class<T> targetEntityClass, SecurityContext workingContext, OrientGraph orientGraph) {
|
||||
this(accessType, sourceEntityClass, targetEntityClass);
|
||||
this.orientGraph = orientGraph;
|
||||
setWorkingContext(workingContext);
|
||||
}
|
||||
|
||||
public SEM getSourceEntityManagement() throws ResourceRegistryException {
|
||||
if(sourceEntityManagement == null) {
|
||||
Vertex source = getElement().getVertex(Direction.OUT);
|
||||
sourceEntityManagement = newSourceEntityManagement();
|
||||
sourceEntityManagement.setElement(source);
|
||||
}
|
||||
sourceEntityManagement.setReload(reload);
|
||||
return sourceEntityManagement;
|
||||
}
|
||||
|
||||
public TEM getTargetEntityManagement() throws ResourceRegistryException {
|
||||
if(targetEntityManagement == null) {
|
||||
Vertex target = getElement().getVertex(Direction.IN);
|
||||
targetEntityManagement = newTargetEntityManagement();
|
||||
targetEntityManagement.setElement(target);
|
||||
}
|
||||
targetEntityManagement.setReload(reload);
|
||||
return targetEntityManagement;
|
||||
}
|
||||
|
||||
public void setSourceEntityManagement(SEM sourceEntityManagement) {
|
||||
this.sourceEntityManagement = sourceEntityManagement;
|
||||
}
|
||||
|
||||
public void setTargetEntityManagement(TEM targetEntityManagement) {
|
||||
this.targetEntityManagement = targetEntityManagement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize() throws ResourceRegistryException {
|
||||
return serializeAsJson().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonNode serializeAsJson() throws ResourceRegistryException {
|
||||
return serializeAsJson(true, true);
|
||||
}
|
||||
|
||||
public JsonNode serializeAsJson(boolean includeSource, boolean includeTarget) throws ResourceRegistryException {
|
||||
JsonNode relation = serializeSelfOnly();
|
||||
|
||||
try {
|
||||
if(includeSource) {
|
||||
BaseEntityManagement<S> sourceEntityManagement = getSourceEntityManagement();
|
||||
((ObjectNode) relation).replace(Relation.SOURCE_PROPERTY, sourceEntityManagement.serializeSelfOnly());
|
||||
}
|
||||
|
||||
if(includeTarget) {
|
||||
BaseEntityManagement<T> targetEntityManagement = getTargetEntityManagement();
|
||||
((ObjectNode) relation).replace(Relation.TARGET_PROPERTY, targetEntityManagement.serializeAsJson());
|
||||
}
|
||||
|
||||
} catch(ResourceRegistryException e) {
|
||||
logger.error("Unable to correctly serialize {}. {}", element, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE, e);
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
logger.error("Unable to correctly serialize {}. {}", element, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE, e);
|
||||
throw new ResourceRegistryException(e);
|
||||
}
|
||||
|
||||
return relation;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Edge reallyCreate() throws ResourceRegistryException {
|
||||
|
||||
if(sourceEntityManagement == null) {
|
||||
|
||||
if(!jsonNode.has(Relation.SOURCE_PROPERTY)) {
|
||||
throw new ResourceRegistryException("Error while creating relation. No source definition found");
|
||||
}
|
||||
|
||||
UUID sourceUUID = org.gcube.informationsystem.utils.Utility
|
||||
.getUUIDFromJsonNode(jsonNode.get(Relation.SOURCE_PROPERTY));
|
||||
|
||||
sourceEntityManagement = newSourceEntityManagement();
|
||||
sourceEntityManagement.setUUID(sourceUUID);
|
||||
}
|
||||
|
||||
if(targetEntityManagement == null) {
|
||||
targetEntityManagement = newTargetEntityManagement();
|
||||
|
||||
if(!jsonNode.has(Relation.TARGET_PROPERTY)) {
|
||||
throw new ResourceRegistryException(
|
||||
"Error while creating " + elementType + ". No target definition found");
|
||||
}
|
||||
|
||||
try {
|
||||
targetEntityManagement.setJsonNode(jsonNode.get(Relation.TARGET_PROPERTY));
|
||||
} catch(SchemaException e) {
|
||||
StringBuilder errorMessage = new StringBuilder();
|
||||
errorMessage.append("A ");
|
||||
errorMessage.append(elementType);
|
||||
errorMessage.append(" can be only created beetween ");
|
||||
errorMessage.append(sourceEntityManagement.getAccessType().getName());
|
||||
errorMessage.append(" and ");
|
||||
errorMessage.append(targetEntityManagement.getAccessType().getName());
|
||||
throw new ResourceRegistryException(errorMessage.toString(), e);
|
||||
}
|
||||
|
||||
try {
|
||||
targetEntityManagement.getElement();
|
||||
} catch(Exception e) {
|
||||
targetEntityManagement.internalCreate();
|
||||
}
|
||||
}
|
||||
|
||||
logger.trace("Creating {} beetween {} -> {}", elementType, getSourceEntityManagement().serialize(),
|
||||
getTargetEntityManagement().serialize());
|
||||
|
||||
Vertex source = (Vertex) getSourceEntityManagement().getElement();
|
||||
Vertex target = (Vertex) getTargetEntityManagement().getElement();
|
||||
|
||||
element = orientGraph.addEdge(null, source, target, elementType);
|
||||
|
||||
ERManagement.updateProperties(oClass, element, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
protected abstract SEM newSourceEntityManagement() throws ResourceRegistryException;
|
||||
|
||||
protected abstract TEM newTargetEntityManagement() throws ResourceRegistryException;
|
||||
|
||||
@Override
|
||||
protected Edge reallyUpdate() throws ResourceRegistryException {
|
||||
|
||||
logger.debug("Trying to update {} : {}", elementType, jsonNode);
|
||||
|
||||
Edge edge = getElement();
|
||||
ERManagement.updateProperties(oClass, edge, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||
|
||||
if(accessType.compareTo(AccessType.CONSISTS_OF) == 0) {
|
||||
JsonNode target = jsonNode.get(Relation.TARGET_PROPERTY);
|
||||
if(target != null) {
|
||||
FacetManagement fm = new FacetManagement(getWorkingContext(), orientGraph);
|
||||
fm.setJsonNode(target);
|
||||
fm.internalUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("{} {} successfully updated", elementType, jsonNode);
|
||||
|
||||
return edge;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean reallyDelete() throws RelationNotFoundException, ResourceRegistryException {
|
||||
logger.debug("Going to remove {} with UUID {}. Related {}s will be detached.", accessType.getName(), uuid,
|
||||
targetEntityClass.getSimpleName());
|
||||
|
||||
getElement().remove();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.informationsystem.resourceregistry.context;
|
||||
package org.gcube.informationsystem.resourceregistry.instances.context;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
@ -16,10 +16,10 @@ import org.gcube.informationsystem.context.reference.relations.IsParentOf;
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.AdminSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
||||
import org.gcube.informationsystem.resourceregistry.security.AdminSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.informationsystem.resourceregistry.context;
|
||||
package org.gcube.informationsystem.resourceregistry.instances.context.entities;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
|
@ -15,10 +15,12 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.context.Conte
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.EntityAvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
||||
import org.gcube.informationsystem.resourceregistry.er.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.er.entity.EntityManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.entities.BaseEntityManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.context.relations.IsParentOfManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -38,7 +40,7 @@ import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
|||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class ContextManagement extends EntityManagement<Context> {
|
||||
public class ContextManagement extends BaseEntityManagement<Context> {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(ContextManagement.class);
|
||||
|
||||
|
@ -408,4 +410,16 @@ public class ContextManagement extends EntityManagement<Context> {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean reallyAddToContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,22 +1,20 @@
|
|||
package org.gcube.informationsystem.resourceregistry.context;
|
||||
|
||||
import java.util.UUID;
|
||||
package org.gcube.informationsystem.resourceregistry.instances.context.relations;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.context.reference.entities.Context;
|
||||
import org.gcube.informationsystem.context.reference.relations.IsParentOf;
|
||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
|
||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
|
||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
|
||||
import org.gcube.informationsystem.model.reference.relations.Relation;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.RelationAvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isparentof.IsParentOfAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isparentof.IsParentOfNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
||||
import org.gcube.informationsystem.resourceregistry.er.relation.RelationManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.relations.BaseRelationManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.context.entities.ContextManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
@ -28,11 +26,10 @@ import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
|||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class IsParentOfManagement extends RelationManagement<IsParentOf,ContextManagement,ContextManagement> {
|
||||
public class IsParentOfManagement extends BaseRelationManagement<IsParentOf,ContextManagement,ContextManagement, Context, Context> {
|
||||
|
||||
public IsParentOfManagement() {
|
||||
super(AccessType.IS_PARENT_OF, null);
|
||||
super(AccessType.IS_PARENT_OF, Context.class, Context.class);
|
||||
}
|
||||
|
||||
public IsParentOfManagement(OrientGraph orientGraph) throws ResourceRegistryException {
|
||||
|
@ -50,58 +47,11 @@ public class IsParentOfManagement extends RelationManagement<IsParentOf,ContextM
|
|||
return workingContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkJsonNode() throws ResourceRegistryException {
|
||||
super.checkJsonNode();
|
||||
|
||||
// Check propagation constraint.
|
||||
if(jsonNode.has(Relation.PROPAGATION_CONSTRAINT)) {
|
||||
StringBuilder message = null;
|
||||
JsonNode propagationConstraint = jsonNode.get(Relation.PROPAGATION_CONSTRAINT);
|
||||
if(propagationConstraint.has(PropagationConstraint.REMOVE_PROPERTY)) {
|
||||
String removeProperty = propagationConstraint.get(PropagationConstraint.REMOVE_PROPERTY).asText();
|
||||
RemoveConstraint removeConstraint = RemoveConstraint.valueOf(removeProperty);
|
||||
if(removeConstraint != RemoveConstraint.keep) {
|
||||
message = new StringBuilder();
|
||||
message.append(RemoveConstraint.class.getSimpleName());
|
||||
message.append(" can only be ");
|
||||
message.append(RemoveConstraint.keep.name());
|
||||
}
|
||||
}
|
||||
|
||||
if(propagationConstraint.has(PropagationConstraint.ADD_PROPERTY)) {
|
||||
String addProperty = propagationConstraint.get(PropagationConstraint.ADD_PROPERTY).asText();
|
||||
AddConstraint addConstraint = AddConstraint.valueOf(addProperty);
|
||||
if(addConstraint != AddConstraint.unpropagate) {
|
||||
if(message == null) {
|
||||
message = new StringBuilder();
|
||||
} else {
|
||||
message.append(" and ");
|
||||
}
|
||||
message.append(AddConstraint.class.getSimpleName());
|
||||
message.append(" can only be ");
|
||||
message.append(AddConstraint.unpropagate.name());
|
||||
}
|
||||
}
|
||||
|
||||
if(message != null) {
|
||||
throw new ResourceRegistryException(message.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IsParentOfNotFoundException getSpecificElementNotFoundException(NotFoundException e) {
|
||||
return new IsParentOfNotFoundException(e.getMessage(), e.getCause());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RelationAvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(
|
||||
String message) {
|
||||
return new RelationAvailableInAnotherContextException(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IsParentOfAlreadyPresentException getSpecificERAlreadyPresentException(String message) {
|
||||
return new IsParentOfAlreadyPresentException(message);
|
||||
|
@ -141,16 +91,6 @@ public class IsParentOfManagement extends RelationManagement<IsParentOf,ContextM
|
|||
return relation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addToContext(UUID contexUUID) throws NotFoundException, ContextException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFromContext(UUID contexUUID) throws NotFoundException, ContextException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ContextManagement newSourceEntityManagement() throws ResourceRegistryException {
|
||||
return new ContextManagement(orientGraph);
|
||||
|
@ -161,4 +101,26 @@ public class IsParentOfManagement extends RelationManagement<IsParentOf,ContextM
|
|||
return new ContextManagement(orientGraph);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean reallyAddToContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(String message) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String reallyGetAll(boolean polymorphic) throws ResourceRegistryException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.informationsystem.resourceregistry.er.entity;
|
||||
package org.gcube.informationsystem.resourceregistry.instances.model.entity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -20,11 +20,12 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.EntityAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.er.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.er.ERManagementUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.er.relation.RelationManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagementUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.entities.BaseEntityManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.relation.RelationManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
|
@ -46,7 +47,7 @@ import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
|||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public abstract class EntityManagement<E extends BaseEntity> extends ERManagement<E,Vertex> {
|
||||
public abstract class EntityManagement<E extends BaseEntity> extends BaseEntityManagement<E> {
|
||||
|
||||
/**
|
||||
* Provide a cache edge-internal-id -> RelationManagement
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.informationsystem.resourceregistry.er.entity;
|
||||
package org.gcube.informationsystem.resourceregistry.instances.model.entity;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||
|
@ -7,8 +7,8 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.er.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.informationsystem.resourceregistry.er.entity;
|
||||
package org.gcube.informationsystem.resourceregistry.instances.model.entity;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
|
@ -11,11 +11,11 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceAvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.er.relation.ConsistsOfManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.er.relation.IsRelatedToManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.er.relation.RelationManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.relation.ConsistsOfManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.relation.IsRelatedToManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.relation.RelationManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
@ -60,7 +60,6 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
|||
return serializeAsJson().toString();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public JsonNode serializeAsJson() throws ResourceRegistryException {
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
package org.gcube.informationsystem.resourceregistry.er.relation;
|
||||
package org.gcube.informationsystem.resourceregistry.instances.model.relation;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
|
||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
|
||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
|
||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
|
||||
|
@ -11,17 +13,15 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.consistsOf.ConsistsOfAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.consistsOf.ConsistsOfAvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.consistsOf.ConsistsOfNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.er.entity.FacetManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.er.entity.ResourceManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.entity.FacetManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
||||
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class ConsistsOfManagement extends RelationManagement<ConsistsOf,ResourceManagement,FacetManagement> {
|
||||
public class ConsistsOfManagement extends RelationManagement<ConsistsOf<Resource, Facet>, FacetManagement, Facet> {
|
||||
|
||||
public static final PropagationConstraint DEFAULT_CONSISTS_OF_PC;
|
||||
|
||||
|
@ -32,11 +32,11 @@ public class ConsistsOfManagement extends RelationManagement<ConsistsOf,Resource
|
|||
}
|
||||
|
||||
public ConsistsOfManagement() {
|
||||
super(AccessType.CONSISTS_OF, DEFAULT_CONSISTS_OF_PC);
|
||||
super(AccessType.CONSISTS_OF, Facet.class, DEFAULT_CONSISTS_OF_PC);
|
||||
}
|
||||
|
||||
public ConsistsOfManagement(SecurityContext workingContext, OrientGraph orientGraph) {
|
||||
super(AccessType.CONSISTS_OF, workingContext, orientGraph, DEFAULT_CONSISTS_OF_PC);
|
||||
super(AccessType.CONSISTS_OF, Facet.class, workingContext, orientGraph, DEFAULT_CONSISTS_OF_PC);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -55,11 +55,6 @@ public class ConsistsOfManagement extends RelationManagement<ConsistsOf,Resource
|
|||
return new ConsistsOfAlreadyPresentException(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResourceManagement newSourceEntityManagement() throws ResourceRegistryException {
|
||||
return new ResourceManagement(getWorkingContext(), orientGraph);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FacetManagement newTargetEntityManagement() throws ResourceRegistryException {
|
||||
return new FacetManagement(getWorkingContext(), orientGraph);
|
|
@ -1,7 +1,8 @@
|
|||
package org.gcube.informationsystem.resourceregistry.er.relation;
|
||||
package org.gcube.informationsystem.resourceregistry.instances.model.relation;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
|
||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
|
||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
|
||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
|
||||
|
@ -11,16 +12,15 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isrelatedto.IsRelatedToAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isrelatedto.IsRelatedToAvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isrelatedto.IsRelatedToNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.er.entity.ResourceManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.entity.ResourceManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
||||
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class IsRelatedToManagement extends RelationManagement<IsRelatedTo,ResourceManagement,ResourceManagement> {
|
||||
public class IsRelatedToManagement extends RelationManagement<IsRelatedTo<Resource, Resource>, ResourceManagement, Resource> {
|
||||
|
||||
public static final PropagationConstraint DEFAULT_IS_RELATED_TO_PC;
|
||||
|
||||
|
@ -31,11 +31,11 @@ public class IsRelatedToManagement extends RelationManagement<IsRelatedTo,Resour
|
|||
}
|
||||
|
||||
public IsRelatedToManagement() {
|
||||
super(AccessType.IS_RELATED_TO,DEFAULT_IS_RELATED_TO_PC);
|
||||
super(AccessType.IS_RELATED_TO, Resource.class, DEFAULT_IS_RELATED_TO_PC);
|
||||
}
|
||||
|
||||
public IsRelatedToManagement(SecurityContext workingContext, OrientGraph orientGraph) {
|
||||
super(AccessType.IS_RELATED_TO, workingContext, orientGraph, DEFAULT_IS_RELATED_TO_PC);
|
||||
super(AccessType.IS_RELATED_TO, Resource.class, workingContext, orientGraph, DEFAULT_IS_RELATED_TO_PC);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -54,11 +54,6 @@ public class IsRelatedToManagement extends RelationManagement<IsRelatedTo,Resour
|
|||
return new IsRelatedToAlreadyPresentException(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResourceManagement newSourceEntityManagement() throws ResourceRegistryException {
|
||||
return new ResourceManagement(getWorkingContext(), orientGraph);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResourceManagement newTargetEntityManagement() throws ResourceRegistryException {
|
||||
return new ResourceManagement(getWorkingContext(), orientGraph);
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.informationsystem.resourceregistry.er.relation;
|
||||
package org.gcube.informationsystem.resourceregistry.instances.model.relation;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
@ -7,9 +7,7 @@ import java.util.Map;
|
|||
import java.util.UUID;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.base.reference.relations.BaseRelation;
|
||||
import org.gcube.informationsystem.model.reference.entities.Entity;
|
||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
|
||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
|
||||
|
@ -19,16 +17,15 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundExcep
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.RelationNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
|
||||
import org.gcube.informationsystem.resourceregistry.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.context.IsParentOfManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.er.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.er.ERManagementUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.er.entity.EntityManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.er.entity.FacetManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.er.entity.ResourceManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagementUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.relations.BaseRelationManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.entity.EntityManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.entity.FacetManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.entity.ResourceManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.PropagationConstraintOrient;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
||||
import org.gcube.informationsystem.utils.ISMapper;
|
||||
|
@ -42,7 +39,6 @@ import com.orientechnologies.orient.core.record.impl.ODocument;
|
|||
import com.tinkerpop.blueprints.Direction;
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientBaseGraph;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientEdge;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientElement;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||
|
@ -50,50 +46,19 @@ import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
|||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public abstract class RelationManagement<R extends BaseRelation, S extends EntityManagement, T extends EntityManagement>
|
||||
extends ERManagement<R,Edge> {
|
||||
|
||||
protected final Class<? extends Entity> targetEntityClass;
|
||||
|
||||
protected S sourceEntityManagement;
|
||||
protected T targetEntityManagement;
|
||||
public abstract class RelationManagement<R extends Relation<Resource, TE>, T extends EntityManagement<TE>, TE extends Entity>
|
||||
extends BaseRelationManagement<R, ResourceManagement, T, Resource, TE>{
|
||||
|
||||
public final PropagationConstraint defaultPropagationConstraint;
|
||||
|
||||
protected RelationManagement(AccessType accessType, PropagationConstraint defaultPropagationConstraint) {
|
||||
super(accessType);
|
||||
|
||||
this.ignoreKeys.add(Relation.HEADER_PROPERTY);
|
||||
this.ignoreKeys.add(Relation.TARGET_PROPERTY);
|
||||
this.ignoreKeys.add(Relation.SOURCE_PROPERTY);
|
||||
this.ignoreKeys.add(OrientBaseGraph.CONNECTION_IN.toLowerCase());
|
||||
this.ignoreKeys.add(OrientBaseGraph.CONNECTION_OUT.toLowerCase());
|
||||
this.ignoreKeys.add(OrientBaseGraph.CONNECTION_IN.toUpperCase());
|
||||
this.ignoreKeys.add(OrientBaseGraph.CONNECTION_OUT.toUpperCase());
|
||||
|
||||
switch(accessType) {
|
||||
case CONSISTS_OF:
|
||||
this.targetEntityClass = Facet.class;
|
||||
break;
|
||||
|
||||
case IS_RELATED_TO:
|
||||
this.targetEntityClass = Resource.class;
|
||||
break;
|
||||
|
||||
default:
|
||||
this.targetEntityClass = Resource.class;
|
||||
break;
|
||||
}
|
||||
|
||||
this.sourceEntityManagement = null;
|
||||
this.targetEntityManagement = null;
|
||||
protected RelationManagement(AccessType accessType, Class<TE> targetEntityClass, PropagationConstraint defaultPropagationConstraint) {
|
||||
super(accessType, Resource.class, targetEntityClass);
|
||||
this.defaultPropagationConstraint = defaultPropagationConstraint;
|
||||
}
|
||||
|
||||
protected RelationManagement(AccessType accessType, SecurityContext workingContext, OrientGraph orientGraph,
|
||||
protected RelationManagement(AccessType accessType, Class<TE> targetEntityClass, SecurityContext workingContext, OrientGraph orientGraph,
|
||||
PropagationConstraint defaultPropagationConstraint) {
|
||||
this(accessType, defaultPropagationConstraint);
|
||||
this(accessType, targetEntityClass, defaultPropagationConstraint);
|
||||
this.orientGraph = orientGraph;
|
||||
setWorkingContext(workingContext);
|
||||
}
|
||||
|
@ -103,12 +68,11 @@ public abstract class RelationManagement<R extends BaseRelation, S extends Entit
|
|||
* sourceEntityManagement is the same of the instance is creating this
|
||||
* RelationManagement. TODO Look for a workaround
|
||||
*/
|
||||
public S giveMeSourceEntityManagementAsIs() throws ResourceRegistryException {
|
||||
public ResourceManagement giveMeSourceEntityManagementAsIs() throws ResourceRegistryException {
|
||||
return sourceEntityManagement;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public S getSourceEntityManagement() throws ResourceRegistryException {
|
||||
public ResourceManagement getSourceEntityManagement() throws ResourceRegistryException {
|
||||
if(sourceEntityManagement == null) {
|
||||
Vertex source = getElement().getVertex(Direction.OUT);
|
||||
sourceEntityManagement = newSourceEntityManagement();
|
||||
|
@ -118,7 +82,6 @@ public abstract class RelationManagement<R extends BaseRelation, S extends Entit
|
|||
return sourceEntityManagement;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public T getTargetEntityManagement() throws ResourceRegistryException {
|
||||
if(targetEntityManagement == null) {
|
||||
Vertex target = getElement().getVertex(Direction.IN);
|
||||
|
@ -129,8 +92,8 @@ public abstract class RelationManagement<R extends BaseRelation, S extends Entit
|
|||
return targetEntityManagement;
|
||||
}
|
||||
|
||||
public void setSourceEntityManagement(S sourceEntityManagement) {
|
||||
this.sourceEntityManagement = sourceEntityManagement;
|
||||
public void setSourceEntityManagement(ResourceManagement resourceManagement) {
|
||||
this.sourceEntityManagement = resourceManagement;
|
||||
}
|
||||
|
||||
public void setTargetEntityManagement(T targetEntityManagement) {
|
||||
|
@ -152,12 +115,12 @@ public abstract class RelationManagement<R extends BaseRelation, S extends Entit
|
|||
|
||||
try {
|
||||
if(includeSource) {
|
||||
EntityManagement sourceEntityManagement = getSourceEntityManagement();
|
||||
EntityManagement<? extends Resource> sourceEntityManagement = getSourceEntityManagement();
|
||||
((ObjectNode) relation).replace(Relation.SOURCE_PROPERTY, sourceEntityManagement.serializeSelfOnly());
|
||||
}
|
||||
|
||||
if(includeTarget) {
|
||||
EntityManagement targetEntityManagement = getTargetEntityManagement();
|
||||
EntityManagement<TE> targetEntityManagement = getTargetEntityManagement();
|
||||
((ObjectNode) relation).replace(Relation.TARGET_PROPERTY, targetEntityManagement.serializeAsJson());
|
||||
}
|
||||
|
||||
|
@ -261,68 +224,18 @@ public abstract class RelationManagement<R extends BaseRelation, S extends Entit
|
|||
|
||||
@Override
|
||||
protected Edge reallyCreate() throws ResourceRegistryException {
|
||||
element = super.reallyCreate();
|
||||
|
||||
if(sourceEntityManagement == null) {
|
||||
|
||||
if(!jsonNode.has(Relation.SOURCE_PROPERTY)) {
|
||||
throw new ResourceRegistryException("Error while creating relation. No source definition found");
|
||||
}
|
||||
|
||||
UUID sourceUUID = org.gcube.informationsystem.utils.Utility
|
||||
.getUUIDFromJsonNode(jsonNode.get(Relation.SOURCE_PROPERTY));
|
||||
|
||||
sourceEntityManagement = newSourceEntityManagement();
|
||||
sourceEntityManagement.setUUID(sourceUUID);
|
||||
}
|
||||
|
||||
if(targetEntityManagement == null) {
|
||||
targetEntityManagement = newTargetEntityManagement();
|
||||
|
||||
if(!jsonNode.has(Relation.TARGET_PROPERTY)) {
|
||||
throw new ResourceRegistryException(
|
||||
"Error while creating " + elementType + ". No target definition found");
|
||||
}
|
||||
|
||||
try {
|
||||
targetEntityManagement.setJsonNode(jsonNode.get(Relation.TARGET_PROPERTY));
|
||||
} catch(SchemaException e) {
|
||||
StringBuilder errorMessage = new StringBuilder();
|
||||
errorMessage.append("A ");
|
||||
errorMessage.append(elementType);
|
||||
errorMessage.append(" can be only created beetween ");
|
||||
errorMessage.append(sourceEntityManagement.getAccessType().getName());
|
||||
errorMessage.append(" and ");
|
||||
errorMessage.append(targetEntityManagement.getAccessType().getName());
|
||||
throw new ResourceRegistryException(errorMessage.toString(), e);
|
||||
}
|
||||
|
||||
try {
|
||||
targetEntityManagement.getElement();
|
||||
} catch(Exception e) {
|
||||
targetEntityManagement.internalCreate();
|
||||
}
|
||||
}
|
||||
|
||||
logger.trace("Creating {} beetween {} -> {}", elementType, getSourceEntityManagement().serialize(),
|
||||
getTargetEntityManagement().serialize());
|
||||
|
||||
Vertex source = (Vertex) getSourceEntityManagement().getElement();
|
||||
Vertex target = (Vertex) getTargetEntityManagement().getElement();
|
||||
|
||||
element = orientGraph.addEdge(null, source, target, elementType);
|
||||
|
||||
ERManagement.updateProperties(oClass, element, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||
|
||||
if(!(this instanceof IsParentOfManagement)) {
|
||||
checkPropagationConstraint();
|
||||
}
|
||||
|
||||
logger.info("{} successfully created", elementType);
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
protected abstract S newSourceEntityManagement() throws ResourceRegistryException;
|
||||
protected ResourceManagement newSourceEntityManagement() throws ResourceRegistryException {
|
||||
return new ResourceManagement(getWorkingContext(), orientGraph);
|
||||
}
|
||||
|
||||
protected abstract T newTargetEntityManagement() throws ResourceRegistryException;
|
||||
|
||||
|
@ -502,10 +415,9 @@ public abstract class RelationManagement<R extends BaseRelation, S extends Entit
|
|||
|
||||
RemoveConstraint removeConstraint = RemoveConstraint.keep;
|
||||
|
||||
if(! (this instanceof IsParentOfManagement)) {
|
||||
try {
|
||||
PropagationConstraint propagationConstraint = Utility.getPropertyDocument(PropagationConstraint.class, element,
|
||||
Relation.PROPAGATION_CONSTRAINT);
|
||||
PropagationConstraint propagationConstraint = Utility.getPropertyDocument(PropagationConstraint.class,
|
||||
element, Relation.PROPAGATION_CONSTRAINT);
|
||||
if(propagationConstraint.getRemoveConstraint() != null) {
|
||||
removeConstraint = propagationConstraint.getRemoveConstraint();
|
||||
} else {
|
||||
|
@ -519,7 +431,7 @@ public abstract class RelationManagement<R extends BaseRelation, S extends Entit
|
|||
logger.warn("Error while getting {} from {}. Assuming {}. {}", Relation.PROPAGATION_CONSTRAINT,
|
||||
Utility.toJsonString(element, true), removeConstraint, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
Vertex target = (Vertex) getTargetEntityManagement().getElement();
|
||||
element.remove();
|
||||
|
||||
|
@ -558,7 +470,7 @@ public abstract class RelationManagement<R extends BaseRelation, S extends Entit
|
|||
continue;
|
||||
}
|
||||
|
||||
RelationManagement relationManagement = ERManagementUtility.getRelationManagement(getWorkingContext(),
|
||||
RelationManagement<R, T, TE> relationManagement = ERManagementUtility.getRelationManagement(getWorkingContext(),
|
||||
orientGraph, edge);
|
||||
visitedSourceResources = relationManagement.fullSerialize(visitedSourceResources);
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.informationsystem.resourceregistry.schema;
|
||||
package org.gcube.informationsystem.resourceregistry.instances.type;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
|
@ -8,9 +8,9 @@ import org.gcube.informationsystem.base.reference.properties.BaseProperty;
|
|||
import org.gcube.informationsystem.base.reference.relations.BaseRelation;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.AdminSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.security.AdminSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.types.TypeBinder;
|
||||
import org.gcube.informationsystem.types.reference.TypeDefinition;
|
||||
import org.gcube.informationsystem.types.reference.relations.RelationTypeDefinition;
|
||||
|
@ -23,9 +23,9 @@ import com.tinkerpop.blueprints.impls.orient.OrientEdge;
|
|||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientVertex;
|
||||
|
||||
public class SchemaContextManagement implements SchemaManagement {
|
||||
public class SchemaContextManagementOld implements SchemaManagement {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(SchemaContextManagement.class);
|
||||
private static Logger logger = LoggerFactory.getLogger(SchemaContextManagementOld.class);
|
||||
|
||||
public static final String SCHEMA = "__SCHEMA";
|
||||
|
||||
|
@ -62,7 +62,6 @@ public class SchemaContextManagement implements SchemaManagement {
|
|||
AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext();
|
||||
orientGraph = adminSecurityContext.getGraph(PermissionMode.WRITER);
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
TypeDefinition typeDefinition = TypeBinder.deserializeTypeDefinition(json);
|
||||
|
||||
if(BaseEntity.class.isAssignableFrom(baseType.getTypeClass())) {
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.informationsystem.resourceregistry.schema;
|
||||
package org.gcube.informationsystem.resourceregistry.instances.type;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.informationsystem.resourceregistry.schema;
|
||||
package org.gcube.informationsystem.resourceregistry.instances.type;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
@ -29,9 +29,9 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.Schema
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaCreationException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.AdminSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.security.AdminSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.types.Type;
|
||||
import org.gcube.informationsystem.types.TypeBinder;
|
||||
import org.gcube.informationsystem.types.reference.TypeDefinition;
|
||||
|
@ -79,13 +79,13 @@ public class SchemaManagementImpl implements SchemaManagement {
|
|||
}
|
||||
|
||||
public static OClass getTypeSchema(ODatabaseSession oDatabaseSession, String type, AccessType accessType)
|
||||
throws SchemaException {
|
||||
throws SchemaException, SchemaNotFoundException {
|
||||
OMetadata oMetadata = oDatabaseSession.getMetadata();
|
||||
OSchema oSchema = oMetadata.getSchema();
|
||||
return getTypeSchema(oSchema, type, accessType);
|
||||
}
|
||||
|
||||
public static OClass getTypeSchema(OSchema oSchema, String type, AccessType accessType) throws SchemaException {
|
||||
public static OClass getTypeSchema(OSchema oSchema, String type, AccessType accessType) throws SchemaException, SchemaNotFoundException {
|
||||
try {
|
||||
OClass oClass = oSchema.getClass(type);
|
||||
if(oClass == null) {
|
||||
|
@ -139,7 +139,6 @@ public class SchemaManagementImpl implements SchemaManagement {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected static TypeDefinition getTypeDefinition(OClass oClass) throws SchemaException {
|
||||
// TODO OrientSerilizatoin is not acceptable anymore since TypeDefiniton introduction
|
||||
|
||||
|
@ -174,7 +173,6 @@ public class SchemaManagementImpl implements SchemaManagement {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"rawtypes"})
|
||||
protected static String getTypeDefinitionAsString(OClass oClass) throws SchemaException {
|
||||
try {
|
||||
TypeDefinition typeDefinition = getTypeDefinition(oClass);
|
||||
|
@ -184,9 +182,8 @@ public class SchemaManagementImpl implements SchemaManagement {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
protected List<OClass> getSuperclassesAndCheckCompliancy(ODatabaseSession oDatabaseSession,
|
||||
TypeDefinition typeDefinition, String baseType) throws SchemaException {
|
||||
TypeDefinition typeDefinition, String baseType) throws SchemaException, SchemaNotFoundException {
|
||||
|
||||
Set<String> superClasses = typeDefinition.getSuperClasses();
|
||||
if(baseType != null) {
|
||||
|
@ -239,7 +236,6 @@ public class SchemaManagementImpl implements SchemaManagement {
|
|||
|
||||
ODatabaseSession oDatabaseSession = null;
|
||||
try {
|
||||
@SuppressWarnings("rawtypes")
|
||||
TypeDefinition typeDefinition = null;
|
||||
try {
|
||||
typeDefinition = TypeBinder.deserializeTypeDefinition(jsonSchema);
|
||||
|
@ -311,7 +307,6 @@ public class SchemaManagementImpl implements SchemaManagement {
|
|||
oClass.setSuperClasses(oSuperclasses);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Set<PropertyDefinition> propertyDefinitions = typeDefinition.getProperties();
|
||||
if(Resource.class.isAssignableFrom(baseType.getTypeClass())) {
|
||||
if(propertyDefinitions != null && propertyDefinitions.size() > 0) {
|
||||
|
@ -410,8 +405,7 @@ public class SchemaManagementImpl implements SchemaManagement {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected <ISM extends ISManageable> String getSchema(String type, boolean includeSubtypes) throws SchemaNotFoundException, SchemaException {
|
||||
protected String getSchema(String type, boolean includeSubtypes) throws SchemaNotFoundException, SchemaException {
|
||||
ODatabaseSession oDatabaseSession = null;
|
||||
try {
|
||||
AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext();
|
||||
|
@ -421,7 +415,7 @@ public class SchemaManagementImpl implements SchemaManagement {
|
|||
OSchema oSchema = oMetadata.getSchema();
|
||||
OClass baseOClass = getTypeSchema(oSchema, type, null);
|
||||
|
||||
List<TypeDefinition<ISM>> typeDefinitions = new ArrayList<>();
|
||||
List<TypeDefinition> typeDefinitions = new ArrayList<>();
|
||||
typeDefinitions.add(getTypeDefinition(baseOClass));
|
||||
|
||||
if(includeSubtypes) {
|
|
@ -0,0 +1,134 @@
|
|||
package org.gcube.informationsystem.resourceregistry.instances.type.entities;
|
||||
|
||||
import javax.ws.rs.NotAcceptableException;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.base.reference.entities.BaseEntity;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.entities.BaseEntityManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.context.entities.ContextManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
||||
import org.gcube.informationsystem.types.reference.entities.EntityTypeDefinition;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||
|
||||
public class EntityTypeDefinitionManagement<ETD extends EntityTypeDefinition<? extends BaseEntity>> extends BaseEntityManagement<ETD> {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(ContextManagement.class);
|
||||
|
||||
protected String name;
|
||||
|
||||
private void init() {
|
||||
this.elementType = EntityTypeDefinition.NAME;
|
||||
}
|
||||
|
||||
public EntityTypeDefinitionManagement() {
|
||||
super(AccessType.ENTITY_TYPE_DEFINITION);
|
||||
init();
|
||||
}
|
||||
|
||||
public EntityTypeDefinitionManagement(OrientGraph orientGraph) throws ResourceRegistryException {
|
||||
this();
|
||||
this.orientGraph = orientGraph;
|
||||
getWorkingContext();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
if(name == null) {
|
||||
if(element == null) {
|
||||
if(jsonNode != null) {
|
||||
name = jsonNode.get(EntityTypeDefinition.NAME_PROPERTY).asText();
|
||||
}
|
||||
} else {
|
||||
name = element.getProperty(EntityTypeDefinition.NAME_PROPERTY);
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
||||
if(workingContext == null) {
|
||||
workingContext = ContextUtility.getInstance()
|
||||
.getSecurityContextByUUID(DatabaseEnvironment.SCHEMA_SECURITY_CONTEXT_UUID);
|
||||
}
|
||||
return workingContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SchemaNotFoundException getSpecificElementNotFoundException(NotFoundException e) {
|
||||
return new SchemaNotFoundException(e.getMessage(), e.getCause());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(String message) {
|
||||
throw new NotAcceptableException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AlreadyPresentException getSpecificERAlreadyPresentException(String message) {
|
||||
throw new NotAcceptableException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize() throws ResourceRegistryException {
|
||||
return serializeAsJson().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonNode serializeAsJson() throws ResourceRegistryException {
|
||||
return serializeSelfOnly();
|
||||
// For Resources Definition include mandatory and suggested IsRelatedTo and ConsistsOf
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Vertex reallyCreate() throws AlreadyPresentException, ResourceRegistryException {
|
||||
logger.debug("Going to create {} for {}", EntityTypeDefinition.NAME, getName());
|
||||
return createVertex();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Vertex reallyUpdate() throws NotFoundException, ResourceRegistryException {
|
||||
logger.debug("Going to update {} for {}", EntityTypeDefinition.NAME, getName());
|
||||
Vertex entityTypeDefinition = getElement();
|
||||
entityTypeDefinition = (Vertex) ERManagement.updateProperties(oClass, entityTypeDefinition, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||
return entityTypeDefinition;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean reallyDelete() throws NotFoundException, ResourceRegistryException {
|
||||
logger.debug("Going to remove {} for {}", EntityTypeDefinition.NAME, getName());
|
||||
getElement().remove();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String reallyGetAll(boolean polymorphic) throws ResourceRegistryException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean reallyAddToContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,134 @@
|
|||
package org.gcube.informationsystem.resourceregistry.instances.type.relations;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.base.reference.entities.BaseEntity;
|
||||
import org.gcube.informationsystem.model.reference.relations.Relation;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isparentof.IsParentOfAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isparentof.IsParentOfNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.relations.BaseRelationManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.context.entities.ContextManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.type.entities.EntityTypeDefinitionManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
||||
import org.gcube.informationsystem.types.reference.entities.EntityTypeDefinition;
|
||||
import org.gcube.informationsystem.types.reference.relations.RelationTypeDefinition;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.tinkerpop.blueprints.Direction;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||
|
||||
public class RelationTypeDefinitionManagement<R extends RelationTypeDefinition<SETD, TETD, S, T>,
|
||||
SEM extends EntityTypeDefinitionManagement<SETD>, TEM extends EntityTypeDefinitionManagement<TETD>,
|
||||
SETD extends EntityTypeDefinition<S>, TETD extends EntityTypeDefinition<T>,
|
||||
S extends BaseEntity, T extends BaseEntity>
|
||||
|
||||
extends BaseRelationManagement<R, SEM, TEM, SETD, TETD> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public RelationTypeDefinitionManagement() {
|
||||
super(AccessType.RELATION_TYPE_DEFINITION, (Class<SETD>) EntityTypeDefinition.class, (Class<TETD>) EntityTypeDefinition.class);
|
||||
}
|
||||
|
||||
public RelationTypeDefinitionManagement(OrientGraph orientGraph) throws ResourceRegistryException {
|
||||
this();
|
||||
this.orientGraph = orientGraph;
|
||||
getWorkingContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
||||
if(workingContext == null) {
|
||||
this.workingContext = ContextUtility.getInstance()
|
||||
.getSecurityContextByUUID(DatabaseEnvironment.SCHEMA_SECURITY_CONTEXT_UUID);
|
||||
}
|
||||
return workingContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IsParentOfNotFoundException getSpecificElementNotFoundException(NotFoundException e) {
|
||||
return new IsParentOfNotFoundException(e.getMessage(), e.getCause());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IsParentOfAlreadyPresentException getSpecificERAlreadyPresentException(String message) {
|
||||
return new IsParentOfAlreadyPresentException(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonNode serializeAsJson() throws ResourceRegistryException {
|
||||
return serializeAsJson(false, true);
|
||||
}
|
||||
|
||||
public JsonNode serializeAsJson(boolean includeSource, boolean includeTarget) throws ResourceRegistryException {
|
||||
JsonNode relation = serializeSelfOnly();
|
||||
|
||||
try {
|
||||
Vertex source = element.getVertex(Direction.OUT);
|
||||
ContextManagement sourceContextManagement = new ContextManagement(orientGraph);
|
||||
sourceContextManagement.setElement(source);
|
||||
if(includeSource) {
|
||||
((ObjectNode)relation).replace(Relation.SOURCE_PROPERTY, sourceContextManagement.serializeSelfOnly());
|
||||
}
|
||||
|
||||
Vertex target = element.getVertex(Direction.IN);
|
||||
ContextManagement targetContextManagement = new ContextManagement(orientGraph);
|
||||
targetContextManagement.setElement(target);
|
||||
if(includeTarget) {
|
||||
((ObjectNode)relation).replace(Relation.TARGET_PROPERTY, targetContextManagement.serializeSelfOnly());
|
||||
}
|
||||
|
||||
} catch(ResourceRegistryException e) {
|
||||
logger.error("Unable to correctly serialize {}. {}", element, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE, e);
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
logger.error("Unable to correctly serialize {}. {}", element, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE, e);
|
||||
throw new ResourceRegistryException(e);
|
||||
}
|
||||
|
||||
return relation;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SEM newSourceEntityManagement() throws ResourceRegistryException {
|
||||
@SuppressWarnings("unchecked")
|
||||
SEM sem = (SEM) new EntityTypeDefinitionManagement<SETD>(orientGraph);
|
||||
return sem;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TEM newTargetEntityManagement() throws ResourceRegistryException {
|
||||
@SuppressWarnings("unchecked")
|
||||
TEM tem = (TEM) new EntityTypeDefinitionManagement<TETD>(orientGraph);
|
||||
return tem;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean reallyAddToContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
||||
throws ContextException, ResourceRegistryException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(String message) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String reallyGetAll(boolean polymorphic) throws ResourceRegistryException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
|
@ -3,11 +3,11 @@ package org.gcube.informationsystem.resourceregistry.query;
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
|
||||
import org.gcube.informationsystem.resourceregistry.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.er.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.er.ERManagementUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagementUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
|
@ -33,15 +33,15 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.context.Conte
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
|
||||
import org.gcube.informationsystem.resourceregistry.context.ContextManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.er.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.er.ERManagementUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.er.entity.ResourceManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagementUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.context.entities.ContextManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.entity.ResourceManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.type.SchemaManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.type.SchemaManagementImpl;
|
||||
import org.gcube.informationsystem.resourceregistry.query.Query;
|
||||
import org.gcube.informationsystem.resourceregistry.query.QueryImpl;
|
||||
import org.gcube.informationsystem.resourceregistry.schema.SchemaManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.schema.SchemaManagementImpl;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.ContextPath;
|
||||
import org.gcube.informationsystem.resourceregistry.context.ContextManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.context.entities.ContextManagement;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundExcep
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.InstancePath;
|
||||
import org.gcube.informationsystem.resourceregistry.er.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.er.ERManagementUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagementUtility;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
|
@ -27,9 +27,9 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.Schema
|
|||
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.InstancePath;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.TypePath;
|
||||
import org.gcube.informationsystem.resourceregistry.er.ERManagementUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.schema.SchemaManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.schema.SchemaManagementImpl;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagementUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.type.SchemaManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.type.SchemaManagementImpl;
|
||||
import org.gcube.informationsystem.types.TypeBinder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -80,7 +80,6 @@ public class SchemaManager {
|
|||
AccessType accessType = null;
|
||||
String firstGotType = null;
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
Set<String> superClasses = TypeBinder.deserializeTypeDefinition(json).getSuperClasses();
|
||||
if(superClasses.size()==0) {
|
||||
throw new ResourceRegistryException("No superclasses defined");
|
||||
|
|
|
@ -18,8 +18,8 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.context.Conte
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath;
|
||||
import org.gcube.informationsystem.resourceregistry.er.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.er.ERManagementUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagementUtility;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.informationsystem.resourceregistry.context.security;
|
||||
package org.gcube.informationsystem.resourceregistry.security;
|
||||
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.informationsystem.resourceregistry.context.security;
|
||||
package org.gcube.informationsystem.resourceregistry.security;
|
||||
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
|
@ -1,4 +1,4 @@
|
|||
package org.gcube.informationsystem.resourceregistry.context.security;
|
||||
package org.gcube.informationsystem.resourceregistry.security;
|
||||
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.informationsystem.resourceregistry.context.security;
|
||||
package org.gcube.informationsystem.resourceregistry.security;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -17,8 +17,8 @@ import java.util.concurrent.Future;
|
|||
|
||||
import org.gcube.informationsystem.context.reference.entities.Context;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
|
@ -9,9 +9,9 @@ import org.gcube.informationsystem.model.reference.entities.Entity;
|
|||
import org.gcube.informationsystem.model.reference.relations.Relation;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.AdminSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.security.AdminSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.utils.ISMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
|
@ -13,11 +13,13 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.ContextSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext.SecurityType;
|
||||
import org.gcube.informationsystem.resourceregistry.er.entity.FacetManagementTest;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.context.entities.ContextManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.security.ContextSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext.SecurityType;
|
||||
import org.gcube.informationsystem.utils.ISMapper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -439,8 +441,8 @@ public class ContextManagementTest extends ContextTest {
|
|||
List<Context> contexts = getAll();
|
||||
for(Context context : contexts) {
|
||||
logger.trace(ISMapper.marshal(context));
|
||||
List<IsParentOf<Context,Context>> children = context.getChildren();
|
||||
for(IsParentOf<Context,Context> child : children) {
|
||||
List<IsParentOf> children = context.getChildren();
|
||||
for(IsParentOf child : children) {
|
||||
Assert.assertTrue(child.getSource() == context);
|
||||
Context childContext = child.getTarget();
|
||||
Assert.assertTrue(childContext.getParent().getSource() == context);
|
||||
|
|
|
@ -2,8 +2,8 @@ package org.gcube.informationsystem.resourceregistry.dbinitialization;
|
|||
|
||||
import org.gcube.informationsystem.base.reference.ISConstants;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.context.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.security.SecurityContext.PermissionMode;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
|
|
|
@ -34,10 +34,11 @@ import org.gcube.informationsystem.resourceregistry.ContextTest;
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException;
|
||||
import org.gcube.informationsystem.resourceregistry.er.entity.FacetManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.er.entity.ResourceManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.er.relation.ConsistsOfManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.er.relation.IsRelatedToManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagementUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.entity.FacetManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.entity.ResourceManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.relation.ConsistsOfManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.relation.IsRelatedToManagement;
|
||||
import org.gcube.informationsystem.utils.ISMapper;
|
||||
import org.gcube.informationsystem.utils.Utility;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.AccessPointFacetImpl;
|
||||
|
|
|
@ -35,7 +35,7 @@ import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
|||
import org.gcube.informationsystem.model.reference.relations.IsIdentifiedBy;
|
||||
import org.gcube.informationsystem.resourceregistry.ContextTest;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.er.entity.ResourceManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.entity.ResourceManagement;
|
||||
import org.gcube.informationsystem.utils.ISMapper;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.ContainerStateFacetImpl;
|
||||
|
|
|
@ -9,8 +9,9 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.utils.Utility;
|
||||
import org.gcube.informationsystem.resourceregistry.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.er.ERManagementTest;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.entity.FacetManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.HeaderUtility;
|
||||
import org.gcube.informationsystem.utils.ISMapper;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
|
||||
|
|
|
@ -10,8 +10,9 @@ import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
|||
import org.gcube.informationsystem.model.reference.relations.IsIdentifiedBy;
|
||||
import org.gcube.informationsystem.resourceregistry.ContextTest;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.er.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.er.ERManagementUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ERManagementUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.entity.ResourceManagement;
|
||||
import org.gcube.informationsystem.utils.ISMapper;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
|
||||
|
|
|
@ -22,11 +22,11 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceAvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.RelationAvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.er.SmartgearResourcesTest;
|
||||
import org.gcube.informationsystem.resourceregistry.er.entity.FacetManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.er.entity.ResourceManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.er.relation.IsRelatedToManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.entity.FacetManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.entity.ResourceManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.relation.IsRelatedToManagement;
|
||||
import org.gcube.informationsystem.utils.ISMapper;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.AccessPointFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
|
||||
|
|
|
@ -8,8 +8,8 @@ import org.gcube.informationsystem.model.reference.relations.IsIdentifiedBy;
|
|||
import org.gcube.informationsystem.resourceregistry.ContextTest;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.er.entity.FacetManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.er.entity.ResourceManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.entity.FacetManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.entity.ResourceManagement;
|
||||
import org.gcube.informationsystem.utils.ISMapper;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl;
|
||||
|
|
|
@ -15,6 +15,8 @@ import org.gcube.informationsystem.model.reference.properties.Property;
|
|||
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
||||
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
||||
import org.gcube.informationsystem.model.reference.relations.Relation;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.type.SchemaManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.type.SchemaManagementImpl;
|
||||
import org.gcube.informationsystem.types.TypeBinder;
|
||||
import org.gcube.informationsystem.types.reference.TypeDefinition;
|
||||
import org.gcube.informationsystem.utils.ISMapper;
|
||||
|
@ -58,7 +60,6 @@ public class SchemaManagementImplTest {
|
|||
public void getFacetSchema() throws Exception {
|
||||
String json = new SchemaManagementImpl().read(ContactFacet.NAME, false);
|
||||
logger.info(json);
|
||||
@SuppressWarnings("rawtypes")
|
||||
List<TypeDefinition> typeDefinitions = TypeBinder.deserializeTypeDefinitions(json);
|
||||
logger.info("{}", typeDefinitions);
|
||||
|
||||
|
@ -104,7 +105,6 @@ public class SchemaManagementImplTest {
|
|||
String list = schemaManagement.read(BaseProperty.NAME, includeSubTypes);
|
||||
logger.debug("{} list : {}", BaseProperty.NAME, list);
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
List<TypeDefinition> typeDefinitions = ISMapper.unmarshalList(TypeDefinition.class, list);
|
||||
logger.debug("{}", typeDefinitions);
|
||||
|
||||
|
|
Loading…
Reference in New Issue