Refs #11288: Made resource-registry more RESTful
Task-Url: https://support.d4science.org/issues/11288 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@168995 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
f8480f0c43
commit
d5d79c14cc
|
@ -3,6 +3,7 @@ package org.gcube.informationsystem.resourceregistry.context;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.codehaus.jettison.json.JSONObject;
|
import org.codehaus.jettison.json.JSONObject;
|
||||||
|
import org.gcube.informationsystem.impl.embedded.PropagationConstraintImpl;
|
||||||
import org.gcube.informationsystem.model.AccessType;
|
import org.gcube.informationsystem.model.AccessType;
|
||||||
import org.gcube.informationsystem.model.embedded.PropagationConstraint;
|
import org.gcube.informationsystem.model.embedded.PropagationConstraint;
|
||||||
import org.gcube.informationsystem.model.embedded.PropagationConstraint.AddConstraint;
|
import org.gcube.informationsystem.model.embedded.PropagationConstraint.AddConstraint;
|
||||||
|
@ -31,8 +32,16 @@ import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public class IsParentOfManagement extends RelationManagement<IsParentOf,ContextManagement,ContextManagement> {
|
public class IsParentOfManagement extends RelationManagement<IsParentOf,ContextManagement,ContextManagement> {
|
||||||
|
|
||||||
|
public static final PropagationConstraint DEFAULT_IS_PARENT_OF_PC;
|
||||||
|
|
||||||
|
static {
|
||||||
|
DEFAULT_IS_PARENT_OF_PC = new PropagationConstraintImpl();
|
||||||
|
DEFAULT_IS_PARENT_OF_PC.setRemoveConstraint(RemoveConstraint.keep);
|
||||||
|
DEFAULT_IS_PARENT_OF_PC.setAddConstraint(AddConstraint.unpropagate);
|
||||||
|
}
|
||||||
|
|
||||||
public IsParentOfManagement() {
|
public IsParentOfManagement() {
|
||||||
super(AccessType.IS_PARENT_OF);
|
super(AccessType.IS_PARENT_OF, DEFAULT_IS_PARENT_OF_PC);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IsParentOfManagement(OrientGraph orientGraph) throws ResourceRegistryException {
|
public IsParentOfManagement(OrientGraph orientGraph) throws ResourceRegistryException {
|
||||||
|
|
|
@ -21,7 +21,6 @@ import org.gcube.informationsystem.model.ER;
|
||||||
import org.gcube.informationsystem.model.ISManageable;
|
import org.gcube.informationsystem.model.ISManageable;
|
||||||
import org.gcube.informationsystem.model.embedded.Header;
|
import org.gcube.informationsystem.model.embedded.Header;
|
||||||
import org.gcube.informationsystem.model.entity.Context;
|
import org.gcube.informationsystem.model.entity.Context;
|
||||||
import org.gcube.informationsystem.model.entity.Entity;
|
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||||
|
@ -251,7 +250,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
||||||
|
|
||||||
Header entityHeader = HeaderUtility.getHeader(jsonNode, true);
|
Header entityHeader = HeaderUtility.getHeader(jsonNode, true);
|
||||||
if(entityHeader != null) {
|
if(entityHeader != null) {
|
||||||
element.setProperty(Entity.HEADER_PROPERTY, entityHeader);
|
element.setProperty(ER.HEADER_PROPERTY, entityHeader);
|
||||||
} else {
|
} else {
|
||||||
entityHeader = HeaderUtility.addHeader(element, null);
|
entityHeader = HeaderUtility.addHeader(element, null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.er.relation;
|
package org.gcube.informationsystem.resourceregistry.er.relation;
|
||||||
|
|
||||||
|
import org.gcube.informationsystem.impl.embedded.PropagationConstraintImpl;
|
||||||
import org.gcube.informationsystem.model.AccessType;
|
import org.gcube.informationsystem.model.AccessType;
|
||||||
|
import org.gcube.informationsystem.model.embedded.PropagationConstraint;
|
||||||
|
import org.gcube.informationsystem.model.embedded.PropagationConstraint.AddConstraint;
|
||||||
|
import org.gcube.informationsystem.model.embedded.PropagationConstraint.RemoveConstraint;
|
||||||
import org.gcube.informationsystem.model.relation.ConsistsOf;
|
import org.gcube.informationsystem.model.relation.ConsistsOf;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
|
@ -19,12 +23,20 @@ import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public class ConsistsOfManagement extends RelationManagement<ConsistsOf,ResourceManagement,FacetManagement> {
|
public class ConsistsOfManagement extends RelationManagement<ConsistsOf,ResourceManagement,FacetManagement> {
|
||||||
|
|
||||||
|
public static final PropagationConstraint DEFAULT_CONSISTS_OF_PC;
|
||||||
|
|
||||||
|
static {
|
||||||
|
DEFAULT_CONSISTS_OF_PC = new PropagationConstraintImpl();
|
||||||
|
DEFAULT_CONSISTS_OF_PC.setRemoveConstraint(RemoveConstraint.cascadeWhenOrphan);
|
||||||
|
DEFAULT_CONSISTS_OF_PC.setAddConstraint(AddConstraint.propagate);
|
||||||
|
}
|
||||||
|
|
||||||
public ConsistsOfManagement() {
|
public ConsistsOfManagement() {
|
||||||
super(AccessType.CONSISTS_OF);
|
super(AccessType.CONSISTS_OF, DEFAULT_CONSISTS_OF_PC);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConsistsOfManagement(SecurityContext workingContext, OrientGraph orientGraph) {
|
public ConsistsOfManagement(SecurityContext workingContext, OrientGraph orientGraph) {
|
||||||
super(AccessType.CONSISTS_OF, workingContext, orientGraph);
|
super(AccessType.CONSISTS_OF, workingContext, orientGraph, DEFAULT_CONSISTS_OF_PC);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.er.relation;
|
package org.gcube.informationsystem.resourceregistry.er.relation;
|
||||||
|
|
||||||
|
import org.gcube.informationsystem.impl.embedded.PropagationConstraintImpl;
|
||||||
import org.gcube.informationsystem.model.AccessType;
|
import org.gcube.informationsystem.model.AccessType;
|
||||||
|
import org.gcube.informationsystem.model.embedded.PropagationConstraint;
|
||||||
|
import org.gcube.informationsystem.model.embedded.PropagationConstraint.AddConstraint;
|
||||||
|
import org.gcube.informationsystem.model.embedded.PropagationConstraint.RemoveConstraint;
|
||||||
import org.gcube.informationsystem.model.relation.IsRelatedTo;
|
import org.gcube.informationsystem.model.relation.IsRelatedTo;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
|
@ -18,12 +22,20 @@ import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public class IsRelatedToManagement extends RelationManagement<IsRelatedTo,ResourceManagement,ResourceManagement> {
|
public class IsRelatedToManagement extends RelationManagement<IsRelatedTo,ResourceManagement,ResourceManagement> {
|
||||||
|
|
||||||
|
public static final PropagationConstraint DEFAULT_IS_RELATED_TO_PC;
|
||||||
|
|
||||||
|
static {
|
||||||
|
DEFAULT_IS_RELATED_TO_PC = new PropagationConstraintImpl();
|
||||||
|
DEFAULT_IS_RELATED_TO_PC.setRemoveConstraint(RemoveConstraint.keep);
|
||||||
|
DEFAULT_IS_RELATED_TO_PC.setAddConstraint(AddConstraint.unpropagate);
|
||||||
|
}
|
||||||
|
|
||||||
public IsRelatedToManagement() {
|
public IsRelatedToManagement() {
|
||||||
super(AccessType.IS_RELATED_TO);
|
super(AccessType.IS_RELATED_TO,DEFAULT_IS_RELATED_TO_PC);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IsRelatedToManagement(SecurityContext workingContext, OrientGraph orientGraph) {
|
public IsRelatedToManagement(SecurityContext workingContext, OrientGraph orientGraph) {
|
||||||
super(AccessType.IS_RELATED_TO, workingContext, orientGraph);
|
super(AccessType.IS_RELATED_TO, workingContext, orientGraph, DEFAULT_IS_RELATED_TO_PC);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -8,6 +8,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
import org.codehaus.jettison.json.JSONArray;
|
import org.codehaus.jettison.json.JSONArray;
|
||||||
import org.codehaus.jettison.json.JSONObject;
|
import org.codehaus.jettison.json.JSONObject;
|
||||||
|
import org.gcube.informationsystem.impl.utils.ISMapper;
|
||||||
import org.gcube.informationsystem.model.AccessType;
|
import org.gcube.informationsystem.model.AccessType;
|
||||||
import org.gcube.informationsystem.model.embedded.PropagationConstraint;
|
import org.gcube.informationsystem.model.embedded.PropagationConstraint;
|
||||||
import org.gcube.informationsystem.model.embedded.PropagationConstraint.AddConstraint;
|
import org.gcube.informationsystem.model.embedded.PropagationConstraint.AddConstraint;
|
||||||
|
@ -29,14 +30,18 @@ import org.gcube.informationsystem.resourceregistry.er.ERManagementUtility;
|
||||||
import org.gcube.informationsystem.resourceregistry.er.entity.EntityManagement;
|
import org.gcube.informationsystem.resourceregistry.er.entity.EntityManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.er.entity.FacetManagement;
|
import org.gcube.informationsystem.resourceregistry.er.entity.FacetManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.er.entity.ResourceManagement;
|
import org.gcube.informationsystem.resourceregistry.er.entity.ResourceManagement;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.utils.PropagationConstraintOrient;
|
||||||
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.orientechnologies.orient.core.metadata.schema.OType;
|
||||||
|
import com.orientechnologies.orient.core.record.impl.ODocument;
|
||||||
import com.tinkerpop.blueprints.Direction;
|
import com.tinkerpop.blueprints.Direction;
|
||||||
import com.tinkerpop.blueprints.Edge;
|
import com.tinkerpop.blueprints.Edge;
|
||||||
import com.tinkerpop.blueprints.Vertex;
|
import com.tinkerpop.blueprints.Vertex;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientBaseGraph;
|
import com.tinkerpop.blueprints.impls.orient.OrientBaseGraph;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientEdge;
|
import com.tinkerpop.blueprints.impls.orient.OrientEdge;
|
||||||
|
import com.tinkerpop.blueprints.impls.orient.OrientElement;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,7 +56,9 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
protected S sourceEntityManagement;
|
protected S sourceEntityManagement;
|
||||||
protected T targetEntityManagement;
|
protected T targetEntityManagement;
|
||||||
|
|
||||||
protected RelationManagement(AccessType accessType) {
|
public final PropagationConstraint defaultPropagationConstraint;
|
||||||
|
|
||||||
|
protected RelationManagement(AccessType accessType, PropagationConstraint defaultPropagationConstraint) {
|
||||||
super(accessType);
|
super(accessType);
|
||||||
|
|
||||||
this.ignoreKeys.add(Relation.HEADER_PROPERTY);
|
this.ignoreKeys.add(Relation.HEADER_PROPERTY);
|
||||||
|
@ -76,13 +83,14 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceEntityManagement = null;
|
this.sourceEntityManagement = null;
|
||||||
targetEntityManagement = null;
|
this.targetEntityManagement = null;
|
||||||
|
this.defaultPropagationConstraint = defaultPropagationConstraint;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected RelationManagement(AccessType accessType, SecurityContext workingContext, OrientGraph orientGraph) {
|
protected RelationManagement(AccessType accessType, SecurityContext workingContext, OrientGraph orientGraph,
|
||||||
this(accessType);
|
PropagationConstraint defaultPropagationConstraint) {
|
||||||
|
this(accessType, defaultPropagationConstraint);
|
||||||
this.orientGraph = orientGraph;
|
this.orientGraph = orientGraph;
|
||||||
setWorkingContext(workingContext);
|
setWorkingContext(workingContext);
|
||||||
}
|
}
|
||||||
|
@ -202,6 +210,52 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
return visitedSourceResources;
|
return visitedSourceResources;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected PropagationConstraintOrient getPropagationConstraint(ODocument oDocument)
|
||||||
|
throws ResourceRegistryException {
|
||||||
|
|
||||||
|
PropagationConstraintOrient propagationConstraintOrient = new PropagationConstraintOrient();
|
||||||
|
|
||||||
|
PropagationConstraint propagationConstraint = null;
|
||||||
|
|
||||||
|
if(oDocument == null) {
|
||||||
|
propagationConstraint = defaultPropagationConstraint;
|
||||||
|
} else if(oDocument instanceof PropagationConstraintOrient) {
|
||||||
|
propagationConstraint = (PropagationConstraint) oDocument;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
propagationConstraint = ISMapper.unmarshal(PropagationConstraint.class, oDocument.toJSON());
|
||||||
|
} catch(Exception e) {
|
||||||
|
logger.warn("Unable to recreate {}. {}", PropagationConstraint.NAME,
|
||||||
|
Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AddConstraint addConstraint = propagationConstraint.getAddConstraint();
|
||||||
|
if(addConstraint == null) {
|
||||||
|
addConstraint = defaultPropagationConstraint.getAddConstraint();
|
||||||
|
logger.warn("Unable to get {}. Default value ({}) will be used", AddConstraint.class.getSimpleName(),
|
||||||
|
addConstraint);
|
||||||
|
}
|
||||||
|
propagationConstraintOrient.setAddConstraint(addConstraint);
|
||||||
|
|
||||||
|
RemoveConstraint removeConstraint = propagationConstraint.getRemoveConstraint();
|
||||||
|
if(removeConstraint == null) {
|
||||||
|
removeConstraint = defaultPropagationConstraint.getRemoveConstraint();
|
||||||
|
logger.warn("Unable to get {}. Default value ({}) will be used", RemoveConstraint.class.getSimpleName(),
|
||||||
|
removeConstraint);
|
||||||
|
}
|
||||||
|
propagationConstraintOrient.setRemoveConstraint(removeConstraint);
|
||||||
|
|
||||||
|
return propagationConstraintOrient;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void checkPropagationConstraint() throws ResourceRegistryException {
|
||||||
|
OrientElement orientElement = (OrientElement) element;
|
||||||
|
Object object = orientElement.getProperty(Relation.PROPAGATION_CONSTRAINT);
|
||||||
|
PropagationConstraintOrient pc = getPropagationConstraint((ODocument) object);
|
||||||
|
orientElement.setProperty(Relation.PROPAGATION_CONSTRAINT, pc, OType.EMBEDDED);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Edge reallyCreate() throws ResourceRegistryException {
|
protected Edge reallyCreate() throws ResourceRegistryException {
|
||||||
|
|
||||||
|
@ -222,7 +276,8 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
targetEntityManagement = newTargetEntityManagement();
|
targetEntityManagement = newTargetEntityManagement();
|
||||||
|
|
||||||
if(!jsonNode.has(Relation.TARGET_PROPERTY)) {
|
if(!jsonNode.has(Relation.TARGET_PROPERTY)) {
|
||||||
throw new ResourceRegistryException("Error while creating " + elementType + ". No target definition found");
|
throw new ResourceRegistryException(
|
||||||
|
"Error while creating " + elementType + ". No target definition found");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -255,6 +310,8 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
|
|
||||||
ERManagement.updateProperties(oClass, element, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
ERManagement.updateProperties(oClass, element, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||||
|
|
||||||
|
checkPropagationConstraint();
|
||||||
|
|
||||||
logger.info("{} successfully created", elementType);
|
logger.info("{} successfully created", elementType);
|
||||||
|
|
||||||
return element;
|
return element;
|
||||||
|
@ -288,7 +345,8 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean reallyAddToContext(SecurityContext targetSecurityContext) throws ContextException, ResourceRegistryException {
|
protected boolean reallyAddToContext(SecurityContext targetSecurityContext)
|
||||||
|
throws ContextException, ResourceRegistryException {
|
||||||
getElement();
|
getElement();
|
||||||
|
|
||||||
AddConstraint addConstraint = AddConstraint.unpropagate;
|
AddConstraint addConstraint = AddConstraint.unpropagate;
|
||||||
|
@ -335,7 +393,8 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean forcedAddToContext(SecurityContext targetSecurityContext) throws ContextException, ResourceRegistryException {
|
public boolean forcedAddToContext(SecurityContext targetSecurityContext)
|
||||||
|
throws ContextException, ResourceRegistryException {
|
||||||
|
|
||||||
getElement();
|
getElement();
|
||||||
|
|
||||||
|
@ -351,7 +410,8 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean reallyRemoveFromContext(SecurityContext targetSecurityContext) throws ContextException, ResourceRegistryException {
|
protected boolean reallyRemoveFromContext(SecurityContext targetSecurityContext)
|
||||||
|
throws ContextException, ResourceRegistryException {
|
||||||
getElement();
|
getElement();
|
||||||
|
|
||||||
RemoveConstraint removeConstraint = RemoveConstraint.keep;
|
RemoveConstraint removeConstraint = RemoveConstraint.keep;
|
||||||
|
@ -564,11 +624,13 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
boolean added = forcedAddToContext(targetSecurityContext);
|
boolean added = forcedAddToContext(targetSecurityContext);
|
||||||
|
|
||||||
orientGraph.commit();
|
orientGraph.commit();
|
||||||
logger.info("{} with UUID {} successfully added to Context with UUID {}", accessType.getName(), uuid, contextUUID);
|
logger.info("{} with UUID {} successfully added to Context with UUID {}", accessType.getName(), uuid,
|
||||||
|
contextUUID);
|
||||||
|
|
||||||
return added;
|
return added;
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
logger.error("Unable to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid, contextUUID, e);
|
logger.error("Unable to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid,
|
||||||
|
contextUUID, e);
|
||||||
if(orientGraph != null) {
|
if(orientGraph != null) {
|
||||||
orientGraph.rollback();
|
orientGraph.rollback();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,8 @@ import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||||
import org.gcube.common.authorization.library.provider.ClientInfo;
|
import org.gcube.common.authorization.library.provider.ClientInfo;
|
||||||
import org.gcube.common.authorization.library.utils.Caller;
|
import org.gcube.common.authorization.library.utils.Caller;
|
||||||
import org.gcube.informationsystem.impl.utils.ISMapper;
|
import org.gcube.informationsystem.impl.utils.ISMapper;
|
||||||
|
import org.gcube.informationsystem.model.ER;
|
||||||
import org.gcube.informationsystem.model.embedded.Header;
|
import org.gcube.informationsystem.model.embedded.Header;
|
||||||
import org.gcube.informationsystem.model.entity.Entity;
|
|
||||||
import org.gcube.informationsystem.model.entity.Resource;
|
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -75,8 +74,8 @@ public class HeaderUtility {
|
||||||
|
|
||||||
public static Header getHeader(JsonNode jsonNode, boolean creation)
|
public static Header getHeader(JsonNode jsonNode, boolean creation)
|
||||||
throws JsonParseException, JsonMappingException, IOException {
|
throws JsonParseException, JsonMappingException, IOException {
|
||||||
if(jsonNode.has(Resource.HEADER_PROPERTY)) {
|
if(jsonNode.has(ER.HEADER_PROPERTY)) {
|
||||||
JsonNode headerNode = jsonNode.get(Resource.HEADER_PROPERTY);
|
JsonNode headerNode = jsonNode.get(ER.HEADER_PROPERTY);
|
||||||
if(headerNode.isNull()) {
|
if(headerNode.isNull()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -117,27 +116,27 @@ public class HeaderUtility {
|
||||||
|
|
||||||
public static Header addHeader(Element element, UUID uuid) {
|
public static Header addHeader(Element element, UUID uuid) {
|
||||||
Header header = createHeader(uuid);
|
Header header = createHeader(uuid);
|
||||||
element.setProperty(Entity.HEADER_PROPERTY, header);
|
element.setProperty(ER.HEADER_PROPERTY, header);
|
||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Header addHeader(Edge edge, UUID uuid) {
|
public static Header addHeader(Edge edge, UUID uuid) {
|
||||||
Header header = createHeader(uuid);
|
Header header = createHeader(uuid);
|
||||||
edge.setProperty(Entity.HEADER_PROPERTY, header);
|
edge.setProperty(ER.HEADER_PROPERTY, header);
|
||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Header getHeader(Element element) throws ResourceRegistryException {
|
public static Header getHeader(Element element) throws ResourceRegistryException {
|
||||||
return Utility.getEmbedded(Header.class, element, Entity.HEADER_PROPERTY);
|
return Utility.getEmbedded(Header.class, element, ER.HEADER_PROPERTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateModifiedByAndLastUpdate(Element element) throws ResourceRegistryException {
|
public static void updateModifiedByAndLastUpdate(Element element) throws ResourceRegistryException {
|
||||||
ODocument oDocument = element.getProperty(Entity.HEADER_PROPERTY);
|
ODocument oDocument = element.getProperty(ER.HEADER_PROPERTY);
|
||||||
String modifiedBy = getUser();
|
String modifiedBy = getUser();
|
||||||
oDocument.field(Header.MODIFIED_BY_PROPERTY, modifiedBy);
|
oDocument.field(Header.MODIFIED_BY_PROPERTY, modifiedBy);
|
||||||
Date lastUpdateTime = Calendar.getInstance().getTime();
|
Date lastUpdateTime = Calendar.getInstance().getTime();
|
||||||
oDocument.field(Header.LAST_UPDATE_TIME_PROPERTY, lastUpdateTime);
|
oDocument.field(Header.LAST_UPDATE_TIME_PROPERTY, lastUpdateTime);
|
||||||
element.setProperty(Entity.HEADER_PROPERTY, oDocument);
|
element.setProperty(ER.HEADER_PROPERTY, oDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package org.gcube.informationsystem.resourceregistry.utils;
|
||||||
|
|
||||||
|
import org.gcube.informationsystem.model.embedded.PropagationConstraint;
|
||||||
|
|
||||||
|
import com.orientechnologies.orient.core.record.impl.ODocument;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
*/
|
||||||
|
public class PropagationConstraintOrient extends ODocument implements org.gcube.informationsystem.model.embedded.PropagationConstraint {
|
||||||
|
|
||||||
|
public PropagationConstraintOrient() {
|
||||||
|
super(PropagationConstraint.NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected PropagationConstraintOrient(String iClassName) {
|
||||||
|
super(iClassName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RemoveConstraint getRemoveConstraint() {
|
||||||
|
return RemoveConstraint.valueOf((String) this.field(PropagationConstraint.REMOVE_PROPERTY));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setRemoveConstraint(RemoveConstraint removeConstraint) {
|
||||||
|
this.field(PropagationConstraint.REMOVE_PROPERTY, removeConstraint.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AddConstraint getAddConstraint() {
|
||||||
|
return AddConstraint.valueOf((String) this.field(PropagationConstraint.ADD_PROPERTY));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setAddConstraint(AddConstraint addConstraint) {
|
||||||
|
this.field(PropagationConstraint.ADD_PROPERTY, addConstraint.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue