Refs #10238: Refactor Context Port Type
Task-Url: https://support.d4science.org/issues/10238 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@158773 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
635e8b5f6d
commit
33f4264348
|
@ -1,7 +1,7 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.context;
|
package org.gcube.informationsystem.resourceregistry.context;
|
||||||
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.codehaus.jettison.json.JSONException;
|
import org.codehaus.jettison.json.JSONException;
|
||||||
import org.codehaus.jettison.json.JSONObject;
|
import org.codehaus.jettison.json.JSONObject;
|
||||||
|
@ -19,10 +19,12 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERAlreadyP
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERNotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.er.ERManagement;
|
import org.gcube.informationsystem.resourceregistry.er.ERManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.er.entity.EntityManagement;
|
import org.gcube.informationsystem.resourceregistry.er.entity.EntityManagement;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.node.NullNode;
|
||||||
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
|
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
|
||||||
import com.tinkerpop.blueprints.Direction;
|
import com.tinkerpop.blueprints.Direction;
|
||||||
import com.tinkerpop.blueprints.Edge;
|
import com.tinkerpop.blueprints.Edge;
|
||||||
|
@ -33,6 +35,8 @@ public class ContextManagement extends EntityManagement<Context> {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(ContextManagement.class);
|
private static Logger logger = LoggerFactory.getLogger(ContextManagement.class);
|
||||||
|
|
||||||
|
protected String name;
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
forceAdmin = true;
|
forceAdmin = true;
|
||||||
|
|
||||||
|
@ -51,7 +55,16 @@ public class ContextManagement extends EntityManagement<Context> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return jsonNode.get(Context.NAME_PROPERTY).asText();
|
if(name==null) {
|
||||||
|
if(element==null) {
|
||||||
|
if(jsonNode!=null) {
|
||||||
|
name = jsonNode.get(Context.NAME_PROPERTY).asText();
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
name = element.getProperty(Context.NAME_PROPERTY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -69,7 +82,7 @@ public class ContextManagement extends EntityManagement<Context> {
|
||||||
return new ContextAlreadyPresentException(message);
|
return new ContextAlreadyPresentException(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void checkContext(ContextManagement parentContext, ContextManagement childContext) throws ContextNotFoundException,
|
protected void checkContext(ContextManagement parentContext) throws ContextNotFoundException,
|
||||||
ContextAlreadyPresentException, ResourceRegistryException {
|
ContextAlreadyPresentException, ResourceRegistryException {
|
||||||
|
|
||||||
if (parentContext != null) {
|
if (parentContext != null) {
|
||||||
|
@ -78,15 +91,15 @@ public class ContextManagement extends EntityManagement<Context> {
|
||||||
// TODO Rewrite using Gremlin
|
// TODO Rewrite using Gremlin
|
||||||
String select = "SELECT FROM (TRAVERSE out(" + IsParentOf.NAME
|
String select = "SELECT FROM (TRAVERSE out(" + IsParentOf.NAME
|
||||||
+ ") FROM " + parentId + " MAXDEPTH 1) WHERE "
|
+ ") FROM " + parentId + " MAXDEPTH 1) WHERE "
|
||||||
+ Context.NAME_PROPERTY + "=\"" + childContext.getName() + "\" AND "
|
+ Context.NAME_PROPERTY + "=\"" + getName() + "\" AND "
|
||||||
+ Context.HEADER_PROPERTY + "." + Header.UUID_PROPERTY
|
+ Context.HEADER_PROPERTY + "." + Header.UUID_PROPERTY
|
||||||
+ "<>\"" + parentContext.toString() + "\"";
|
+ "<>\"" + parentContext.uuid + "\"";
|
||||||
|
|
||||||
logger.trace(select);
|
logger.trace(select);
|
||||||
|
|
||||||
StringWriter message = new StringWriter();
|
StringBuilder message = new StringBuilder();
|
||||||
message.append("A context with the same name (");
|
message.append("A context with name (");
|
||||||
message.append(childContext.getName());
|
message.append(getName());
|
||||||
message.append(") has been already created as child of ");
|
message.append(") has been already created as child of ");
|
||||||
message.append(parentContext.serializeSelfOnly().toString());
|
message.append(parentContext.serializeSelfOnly().toString());
|
||||||
|
|
||||||
|
@ -105,7 +118,7 @@ public class ContextManagement extends EntityManagement<Context> {
|
||||||
// TODO Rewrite using Gremlin
|
// TODO Rewrite using Gremlin
|
||||||
String select = "SELECT FROM "
|
String select = "SELECT FROM "
|
||||||
+ org.gcube.informationsystem.model.entity.Context.NAME
|
+ org.gcube.informationsystem.model.entity.Context.NAME
|
||||||
+ " WHERE " + Context.NAME_PROPERTY + " = \"" + childContext.getName()
|
+ " WHERE " + Context.NAME_PROPERTY + " = \"" + getName()
|
||||||
+ "\"" + " AND in(\"" + IsParentOf.NAME + "\").size() = 0";
|
+ "\"" + " AND in(\"" + IsParentOf.NAME + "\").size() = 0";
|
||||||
|
|
||||||
OSQLSynchQuery<Vertex> osqlSynchQuery = new OSQLSynchQuery<Vertex>(
|
OSQLSynchQuery<Vertex> osqlSynchQuery = new OSQLSynchQuery<Vertex>(
|
||||||
|
@ -115,7 +128,7 @@ public class ContextManagement extends EntityManagement<Context> {
|
||||||
|
|
||||||
if (vertexes != null && vertexes.iterator().hasNext()) {
|
if (vertexes != null && vertexes.iterator().hasNext()) {
|
||||||
throw new ContextAlreadyPresentException(
|
throw new ContextAlreadyPresentException(
|
||||||
"A root context with the same name (" + childContext.getName()
|
"A root context with the same name (" + this.getName()
|
||||||
+ ") already exist");
|
+ ") already exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +159,7 @@ public class ContextManagement extends EntityManagement<Context> {
|
||||||
JSONObject isParentOf = isParentOfManagement.serializeAsJson(true,false);
|
JSONObject isParentOf = isParentOfManagement.serializeAsJson(true,false);
|
||||||
context.putOpt(Context.PARENT_PROPERTY, isParentOf);
|
context.putOpt(Context.PARENT_PROPERTY, isParentOf);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
logger.error("Unable to correctly serialize {}. This is really strange and should not occur.", edge);
|
logger.error("Unable to correctly serialize {}. {}", edge, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
throw new ContextException("");
|
throw new ContextException("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,10 +174,10 @@ public class ContextManagement extends EntityManagement<Context> {
|
||||||
JSONObject isParentOf = isParentOfManagement.serializeAsJson();
|
JSONObject isParentOf = isParentOfManagement.serializeAsJson();
|
||||||
context = addRelation(context, isParentOf, Context.CHILDREN_PROPERTY);
|
context = addRelation(context, isParentOf, Context.CHILDREN_PROPERTY);
|
||||||
}catch (ResourceRegistryException e) {
|
}catch (ResourceRegistryException e) {
|
||||||
logger.error("Unable to correctly serialize {}. This is really strange and should not occur.", edge);
|
logger.error("Unable to correctly serialize {}. {}", edge, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
throw e;
|
throw e;
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
logger.error("Unable to correctly serialize {}. This is really strange and should not occur.", edge);
|
logger.error("Unable to correctly serialize {}. {}", edge, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
throw new ResourceRegistryException(e);
|
throw new ResourceRegistryException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -174,41 +187,141 @@ public class ContextManagement extends EntityManagement<Context> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Vertex reallyCreate() throws ERAlreadyPresentException, ResourceRegistryException {
|
protected Vertex reallyCreate() throws ERAlreadyPresentException, ResourceRegistryException {
|
||||||
|
JsonNode isParentOfJsonNode = jsonNode.get(Context.PARENT_PROPERTY);
|
||||||
|
|
||||||
|
if (isParentOfJsonNode!=null && !(isParentOfJsonNode instanceof NullNode)) {
|
||||||
|
|
||||||
createVertex();
|
|
||||||
|
|
||||||
String propertyName = Context.PARENT_PROPERTY;
|
|
||||||
if (jsonNode.has(propertyName)) {
|
|
||||||
JsonNode isParentOfJsonNode = jsonNode.get(propertyName);
|
|
||||||
|
|
||||||
JsonNode parentJsonNode = isParentOfJsonNode.get(Relation.SOURCE_PROPERTY);
|
JsonNode parentJsonNode = isParentOfJsonNode.get(Relation.SOURCE_PROPERTY);
|
||||||
ContextManagement contextManagement = new ContextManagement(orientGraph);
|
ContextManagement parentContext = new ContextManagement(orientGraph);
|
||||||
contextManagement.setJSON(parentJsonNode);
|
parentContext.setJSON(parentJsonNode);
|
||||||
|
|
||||||
|
checkContext(parentContext);
|
||||||
|
createVertex();
|
||||||
|
|
||||||
IsParentOfManagement isParentOfManagement = new IsParentOfManagement(orientGraph);
|
IsParentOfManagement isParentOfManagement = new IsParentOfManagement(orientGraph);
|
||||||
isParentOfManagement.setJSON(isParentOfJsonNode);
|
isParentOfManagement.setJSON(isParentOfJsonNode);
|
||||||
isParentOfManagement.setSourceEntityManagement(contextManagement);
|
isParentOfManagement.setSourceEntityManagement(parentContext);
|
||||||
isParentOfManagement.setTargetEntityManagement(this);
|
isParentOfManagement.setTargetEntityManagement(this);
|
||||||
|
|
||||||
isParentOfManagement.internalCreate();
|
isParentOfManagement.internalCreate();
|
||||||
|
|
||||||
|
}else {
|
||||||
|
checkContext(null);
|
||||||
|
createVertex();
|
||||||
}
|
}
|
||||||
|
|
||||||
return element;
|
return getElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Vertex reallyUpdate() throws ERNotFoundException, ResourceRegistryException {
|
protected Vertex reallyUpdate() throws ERNotFoundException, ResourceRegistryException {
|
||||||
|
|
||||||
Vertex context = getElement();
|
boolean parentChanged = false;
|
||||||
|
boolean nameChanged = false;
|
||||||
|
|
||||||
// TODO check if parent changed
|
Vertex parent = null;
|
||||||
|
boolean found = false;
|
||||||
|
|
||||||
// TODO check if name changes and check the feasibility
|
Iterable<Vertex> iterable = getElement().getVertices(Direction.IN, IsParentOf.NAME);
|
||||||
context = (Vertex) ERManagement.updateProperties(oClass, context, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
for(Vertex p : iterable) {
|
||||||
|
if(found){
|
||||||
|
String message = String.format("{} has more than one parent. {}", Context.NAME,
|
||||||
|
Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
|
throw new ResourceRegistryException(message.toString());
|
||||||
|
}
|
||||||
|
parent = p;
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ContextManagement actualParentContextManagement = null;
|
||||||
|
if(parent!=null) {
|
||||||
|
actualParentContextManagement = new ContextManagement(orientGraph);
|
||||||
|
actualParentContextManagement.setElement(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
ContextManagement newParentContextManagement = actualParentContextManagement;
|
||||||
|
|
||||||
|
JsonNode isParentOfJsonNode = jsonNode.get(Context.PARENT_PROPERTY);
|
||||||
|
JsonNode parentContextJsonNode = null;
|
||||||
|
if (isParentOfJsonNode!=null && !(isParentOfJsonNode instanceof NullNode)) {
|
||||||
|
parentContextJsonNode = isParentOfJsonNode.get(Relation.SOURCE_PROPERTY);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(parentContextJsonNode!=null && !(parentContextJsonNode instanceof NullNode)) {
|
||||||
|
UUID parentUUID = org.gcube.informationsystem.impl.utils.Utility.getUUIDFromJsonNode(parentContextJsonNode);
|
||||||
|
if(actualParentContextManagement!=null){
|
||||||
|
if(parentUUID.compareTo(actualParentContextManagement.uuid)!=0) {
|
||||||
|
parentChanged = true;
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
parentChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(parentChanged){
|
||||||
|
newParentContextManagement = new ContextManagement(orientGraph);
|
||||||
|
newParentContextManagement.setJSON(parentContextJsonNode);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if(actualParentContextManagement!=null) {
|
||||||
|
parentChanged = true;
|
||||||
|
newParentContextManagement = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
String oldName = getElement().getProperty(Context.NAME_PROPERTY);
|
||||||
|
String newName = jsonNode.get(Context.NAME_PROPERTY).asText();
|
||||||
|
if(oldName.compareTo(newName)!=0){
|
||||||
|
nameChanged = true;
|
||||||
|
name = newName;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(parentChanged || nameChanged) {
|
||||||
|
checkContext(newParentContextManagement);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(parentChanged) {
|
||||||
|
move(newParentContextManagement, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
element = (Vertex) ERManagement.updateProperties(oClass, getElement(), jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||||
|
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void move(ContextManagement newParentContextManagement, boolean check)
|
||||||
|
throws ContextNotFoundException, ContextAlreadyPresentException, ResourceRegistryException {
|
||||||
|
if(check){
|
||||||
|
checkContext(newParentContextManagement);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Removing the old parent relationship if any
|
||||||
|
Iterable<Edge> edges = getElement().getEdges(Direction.IN, IsParentOf.NAME);
|
||||||
|
if (edges != null && edges.iterator().hasNext()) {
|
||||||
|
Iterator<Edge> edgeIterator = edges.iterator();
|
||||||
|
Edge edge = edgeIterator.next();
|
||||||
|
IsParentOfManagement isParentOfManagement = new IsParentOfManagement();
|
||||||
|
isParentOfManagement.setElement(edge);
|
||||||
|
isParentOfManagement.internalDelete();
|
||||||
|
|
||||||
|
if (edgeIterator.hasNext()) {
|
||||||
|
throw new ContextException("Seems that the Context has more than one Parent. "
|
||||||
|
+ Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(newParentContextManagement!=null){
|
||||||
|
JsonNode isParentOfJsonNode = jsonNode.get(Context.PARENT_PROPERTY);
|
||||||
|
IsParentOfManagement isParentOfManagement = new IsParentOfManagement(orientGraph);
|
||||||
|
isParentOfManagement.setJSON(isParentOfJsonNode);
|
||||||
|
isParentOfManagement.setSourceEntityManagement(newParentContextManagement);
|
||||||
|
isParentOfManagement.setTargetEntityManagement(this);
|
||||||
|
isParentOfManagement.internalCreate();
|
||||||
|
}
|
||||||
|
|
||||||
return context;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -5,6 +5,9 @@ package org.gcube.informationsystem.resourceregistry.context;
|
||||||
|
|
||||||
import org.codehaus.jettison.json.JSONObject;
|
import org.codehaus.jettison.json.JSONObject;
|
||||||
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.IsParentOf;
|
import org.gcube.informationsystem.model.relation.IsParentOf;
|
||||||
import org.gcube.informationsystem.model.relation.Relation;
|
import org.gcube.informationsystem.model.relation.Relation;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
|
@ -14,7 +17,9 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.Rela
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isparentof.IsParentOfAlreadyPresentException;
|
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.api.exceptions.relation.isparentof.IsParentOfNotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.er.relation.RelationManagement;
|
import org.gcube.informationsystem.resourceregistry.er.relation.RelationManagement;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.tinkerpop.blueprints.Direction;
|
import com.tinkerpop.blueprints.Direction;
|
||||||
import com.tinkerpop.blueprints.Vertex;
|
import com.tinkerpop.blueprints.Vertex;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||||
|
@ -33,6 +38,47 @@ public class IsParentOfManagement extends RelationManagement<IsParentOf, Context
|
||||||
super(AccessType.IS_PARENT_OF, orientGraph);
|
super(AccessType.IS_PARENT_OF, orientGraph);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkJSON() throws ResourceRegistryException {
|
||||||
|
super.checkJSON();
|
||||||
|
|
||||||
|
// 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
|
@Override
|
||||||
protected IsParentOfNotFoundException getSpecificElementNotFoundException(ERNotFoundException e) {
|
protected IsParentOfNotFoundException getSpecificElementNotFoundException(ERNotFoundException e) {
|
||||||
return new IsParentOfNotFoundException(e.getMessage(), e.getCause());
|
return new IsParentOfNotFoundException(e.getMessage(), e.getCause());
|
||||||
|
@ -73,10 +119,10 @@ public class IsParentOfManagement extends RelationManagement<IsParentOf, Context
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (ResourceRegistryException e) {
|
} catch (ResourceRegistryException e) {
|
||||||
logger.error("Unable to correctly serialize {}. This is really strange and should not occur.", element, e);
|
logger.error("Unable to correctly serialize {}. {}", element, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE, e);
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Unable to correctly serialize {}. This is really strange and should not occur.", element, e);
|
logger.error("Unable to correctly serialize {}. {}", element, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE, e);
|
||||||
throw new ResourceRegistryException(e);
|
throw new ResourceRegistryException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,14 +30,12 @@ import com.tinkerpop.blueprints.impls.orient.OrientVertex;
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*/
|
*/
|
||||||
public class ContextManagementImpl implements OLDContextManagement {
|
public class OLDContextManagementImpl implements OLDContextManagement {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory
|
private static Logger logger = LoggerFactory.getLogger(OLDContextManagementImpl.class);
|
||||||
.getLogger(ContextManagementImpl.class);
|
|
||||||
|
|
||||||
protected Vertex checkContext(OrientGraph orientGraph, UUID parentContext,
|
protected Vertex checkContext(OrientGraph orientGraph, UUID parentContext, String contextName)
|
||||||
String contextName) throws ContextNotFoundException,
|
throws ContextNotFoundException, ContextException {
|
||||||
ContextException {
|
|
||||||
|
|
||||||
Vertex parent = null;
|
Vertex parent = null;
|
||||||
|
|
||||||
|
@ -46,26 +44,19 @@ public class ContextManagementImpl implements OLDContextManagement {
|
||||||
parent = getContext(orientGraph, parentContext);
|
parent = getContext(orientGraph, parentContext);
|
||||||
|
|
||||||
// TODO Rewrite using Gremlin
|
// TODO Rewrite using Gremlin
|
||||||
String select = "SELECT FROM (TRAVERSE out(" + IsParentOf.NAME
|
String select = "SELECT FROM (TRAVERSE out(" + IsParentOf.NAME + ") FROM " + parent.getId()
|
||||||
+ ") FROM " + parent.getId() + " MAXDEPTH 1) WHERE "
|
+ " MAXDEPTH 1) WHERE " + Context.NAME_PROPERTY + "=\"" + contextName + "\" AND "
|
||||||
+ Context.NAME_PROPERTY + "=\"" + contextName + "\" AND "
|
+ Context.HEADER_PROPERTY + "." + Header.UUID_PROPERTY + "<>\"" + parentContext.toString() + "\"";
|
||||||
+ Context.HEADER_PROPERTY + "." + Header.UUID_PROPERTY
|
|
||||||
+ "<>\"" + parentContext.toString() + "\"";
|
|
||||||
|
|
||||||
logger.trace(select);
|
logger.trace(select);
|
||||||
|
|
||||||
String message = "A context with the same name (" + contextName
|
String message = "A context with the same name (" + contextName + ") has been already created as child of "
|
||||||
+ ") has been already created as child of "
|
+ parentContext.toString() + "(name=" + parent.getProperty(Context.NAME_PROPERTY).toString() + ")";
|
||||||
+ parentContext.toString() + "(name="
|
|
||||||
+ parent.getProperty(Context.NAME_PROPERTY).toString()
|
|
||||||
+ ")";
|
|
||||||
|
|
||||||
logger.trace("Checking if {} -> {}", message, select);
|
logger.trace("Checking if {} -> {}", message, select);
|
||||||
|
|
||||||
OSQLSynchQuery<Vertex> osqlSynchQuery = new OSQLSynchQuery<Vertex>(
|
OSQLSynchQuery<Vertex> osqlSynchQuery = new OSQLSynchQuery<Vertex>(select);
|
||||||
select);
|
Iterable<Vertex> vertexes = orientGraph.command(osqlSynchQuery).execute();
|
||||||
Iterable<Vertex> vertexes = orientGraph.command(osqlSynchQuery)
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
if (vertexes != null && vertexes.iterator().hasNext()) {
|
if (vertexes != null && vertexes.iterator().hasNext()) {
|
||||||
throw new ContextException(message);
|
throw new ContextException(message);
|
||||||
|
@ -73,20 +64,15 @@ public class ContextManagementImpl implements OLDContextManagement {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// TODO Rewrite using Gremlin
|
// TODO Rewrite using Gremlin
|
||||||
String select = "SELECT FROM "
|
String select = "SELECT FROM " + org.gcube.informationsystem.model.entity.Context.NAME + " WHERE "
|
||||||
+ org.gcube.informationsystem.model.entity.Context.NAME
|
+ Context.NAME_PROPERTY + " = \"" + contextName + "\"" + " AND in(\"" + IsParentOf.NAME
|
||||||
+ " WHERE " + Context.NAME_PROPERTY + " = \"" + contextName
|
+ "\").size() = 0";
|
||||||
+ "\"" + " AND in(\"" + IsParentOf.NAME + "\").size() = 0";
|
|
||||||
|
|
||||||
OSQLSynchQuery<Vertex> osqlSynchQuery = new OSQLSynchQuery<Vertex>(
|
OSQLSynchQuery<Vertex> osqlSynchQuery = new OSQLSynchQuery<Vertex>(select);
|
||||||
select);
|
Iterable<Vertex> vertexes = orientGraph.command(osqlSynchQuery).execute();
|
||||||
Iterable<Vertex> vertexes = orientGraph.command(osqlSynchQuery)
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
if (vertexes != null && vertexes.iterator().hasNext()) {
|
if (vertexes != null && vertexes.iterator().hasNext()) {
|
||||||
throw new ContextException(
|
throw new ContextException("A root context with the same name (" + contextName + ") already exist");
|
||||||
"A root context with the same name (" + contextName
|
|
||||||
+ ") already exist");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -95,8 +81,7 @@ public class ContextManagementImpl implements OLDContextManagement {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vertex getContext(OrientGraph orientGraph, UUID context)
|
public Vertex getContext(OrientGraph orientGraph, UUID context) throws ContextNotFoundException {
|
||||||
throws ContextNotFoundException {
|
|
||||||
try {
|
try {
|
||||||
return Utility.getElementByUUID(orientGraph, Context.NAME, context, Vertex.class);
|
return Utility.getElementByUUID(orientGraph, Context.NAME, context, Vertex.class);
|
||||||
} catch (ResourceRegistryException e) {
|
} catch (ResourceRegistryException e) {
|
||||||
|
@ -105,20 +90,17 @@ public class ContextManagementImpl implements OLDContextManagement {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String create(UUID parentContext, String name)
|
public String create(UUID parentContext, String name) throws ContextCreationException, ResourceRegistryException {
|
||||||
throws ContextCreationException, ResourceRegistryException {
|
|
||||||
|
|
||||||
OrientGraph orientGraph = null;
|
OrientGraph orientGraph = null;
|
||||||
UUID uuid = UUID.randomUUID();
|
UUID uuid = UUID.randomUUID();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.info(
|
logger.info("Trying to create {} with name {} and parent {} UUID {}", Context.NAME, name, Context.NAME,
|
||||||
"Trying to create {} with name {} and parent {} UUID {}",
|
parentContext);
|
||||||
Context.NAME, name, Context.NAME, parentContext);
|
|
||||||
|
|
||||||
orientGraph = SecurityContextMapper.getSecurityContextGraph(
|
orientGraph = SecurityContextMapper
|
||||||
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
|
.getSecurityContextGraph(SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID, PermissionMode.WRITER);
|
||||||
PermissionMode.WRITER);
|
|
||||||
|
|
||||||
Vertex parent;
|
Vertex parent;
|
||||||
try {
|
try {
|
||||||
|
@ -129,16 +111,14 @@ public class ContextManagementImpl implements OLDContextManagement {
|
||||||
|
|
||||||
SecurityContext.createSecurityContext(orientGraph, uuid);
|
SecurityContext.createSecurityContext(orientGraph, uuid);
|
||||||
|
|
||||||
OrientVertex context = orientGraph.addVertex("class:"
|
OrientVertex context = orientGraph.addVertex("class:" + Context.NAME);
|
||||||
+ Context.NAME);
|
|
||||||
context.setProperty(Context.NAME_PROPERTY, name);
|
context.setProperty(Context.NAME_PROPERTY, name);
|
||||||
context.save();
|
context.save();
|
||||||
|
|
||||||
HeaderUtility.addHeader(context, uuid);
|
HeaderUtility.addHeader(context, uuid);
|
||||||
|
|
||||||
if (parentContext != null) {
|
if (parentContext != null) {
|
||||||
OrientEdge edge = orientGraph.addEdge(null, parent, context,
|
OrientEdge edge = orientGraph.addEdge(null, parent, context, IsParentOf.NAME);
|
||||||
IsParentOf.NAME);
|
|
||||||
HeaderUtility.addHeader(edge, null);
|
HeaderUtility.addHeader(edge, null);
|
||||||
edge.save();
|
edge.save();
|
||||||
}
|
}
|
||||||
|
@ -150,8 +130,7 @@ public class ContextManagementImpl implements OLDContextManagement {
|
||||||
orientGraph.commit();
|
orientGraph.commit();
|
||||||
|
|
||||||
Vertex readContext = getContext(orientGraph, uuid);
|
Vertex readContext = getContext(orientGraph, uuid);
|
||||||
logger.info("Context created {}",
|
logger.info("Context created {}", Utility.toJsonString((OrientVertex) readContext, true));
|
||||||
Utility.toJsonString((OrientVertex) readContext, true));
|
|
||||||
return Utility.toJsonString((OrientVertex) readContext, false);
|
return Utility.toJsonString((OrientVertex) readContext, false);
|
||||||
|
|
||||||
} catch (ContextCreationException e) {
|
} catch (ContextCreationException e) {
|
||||||
|
@ -171,47 +150,41 @@ public class ContextManagementImpl implements OLDContextManagement {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String read(UUID contextUUID) throws ContextNotFoundException,
|
public String read(UUID contextUUID) throws ContextNotFoundException, ContextException {
|
||||||
ContextException {
|
OrientGraph orientGraph = SecurityContextMapper
|
||||||
OrientGraph orientGraph = SecurityContextMapper.getSecurityContextGraph(
|
.getSecurityContextGraph(SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID, PermissionMode.READER);
|
||||||
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
|
|
||||||
PermissionMode.READER);
|
|
||||||
Vertex context = getContext(orientGraph, contextUUID);
|
Vertex context = getContext(orientGraph, contextUUID);
|
||||||
return Utility.toJsonString((OrientVertex) context, false);
|
return Utility.toJsonString((OrientVertex) context, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String rename(UUID contextUUID, String newName)
|
public String rename(UUID contextUUID, String newName) throws ContextNotFoundException, ContextException {
|
||||||
throws ContextNotFoundException, ContextException {
|
|
||||||
|
|
||||||
OrientGraph orientGraph = null;
|
OrientGraph orientGraph = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.info("Trying to rename {} with UUID {} to {}", Context.NAME,
|
logger.info("Trying to rename {} with UUID {} to {}", Context.NAME, contextUUID, newName);
|
||||||
contextUUID, newName);
|
|
||||||
|
|
||||||
orientGraph = SecurityContextMapper.getSecurityContextGraph(
|
orientGraph = SecurityContextMapper
|
||||||
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
|
.getSecurityContextGraph(SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID, PermissionMode.WRITER);
|
||||||
PermissionMode.WRITER);
|
|
||||||
|
|
||||||
Vertex context = getContext(orientGraph, contextUUID);
|
Vertex context = getContext(orientGraph, contextUUID);
|
||||||
|
|
||||||
UUID parentUUID = null;
|
UUID parentUUID = null;
|
||||||
|
|
||||||
Iterable<Edge> edges = context.getEdges(Direction.IN,
|
Iterable<Edge> edges = context.getEdges(Direction.IN, IsParentOf.NAME);
|
||||||
IsParentOf.NAME);
|
|
||||||
if (edges != null && edges.iterator().hasNext()) {
|
if (edges != null && edges.iterator().hasNext()) {
|
||||||
Iterator<Edge> iteratorEdge = edges.iterator();
|
Iterator<Edge> iteratorEdge = edges.iterator();
|
||||||
Edge edge = iteratorEdge.next();
|
Edge edge = iteratorEdge.next();
|
||||||
|
|
||||||
if (iteratorEdge.hasNext()) {
|
if (iteratorEdge.hasNext()) {
|
||||||
throw new ContextException("Seems that the Context has more than one Parent. THIS IS REALLY STRANGE AND SHOULD NOT OCCUR. PLEASE CONTACT THE ADMINISTRATOR");
|
throw new ContextException("Seems that the Context has more than one Parent. "
|
||||||
|
+ Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vertex parent = edge.getVertex(Direction.OUT);
|
Vertex parent = edge.getVertex(Direction.OUT);
|
||||||
parentUUID = UUID.fromString((String) parent
|
parentUUID = UUID
|
||||||
.getProperty(Context.HEADER_PROPERTY + "."
|
.fromString((String) parent.getProperty(Context.HEADER_PROPERTY + "." + Header.UUID_PROPERTY));
|
||||||
+ Header.UUID_PROPERTY));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
checkContext(orientGraph, parentUUID, newName);
|
checkContext(orientGraph, parentUUID, newName);
|
||||||
|
@ -243,29 +216,23 @@ public class ContextManagementImpl implements OLDContextManagement {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String move(UUID newParentUUID, UUID contextToMoveUUID)
|
public String move(UUID newParentUUID, UUID contextToMoveUUID) throws ContextNotFoundException, ContextException {
|
||||||
throws ContextNotFoundException, ContextException {
|
|
||||||
|
|
||||||
OrientGraph orientGraph = null;
|
OrientGraph orientGraph = null;
|
||||||
try {
|
try {
|
||||||
logger.info(
|
logger.info("Trying to move {} with UUID {} as child of {} with UUID {}", Context.NAME, contextToMoveUUID,
|
||||||
"Trying to move {} with UUID {} as child of {} with UUID {}",
|
Context.NAME, newParentUUID);
|
||||||
Context.NAME, contextToMoveUUID, Context.NAME, newParentUUID);
|
|
||||||
|
|
||||||
orientGraph = SecurityContextMapper.getSecurityContextGraph(
|
orientGraph = SecurityContextMapper
|
||||||
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
|
.getSecurityContextGraph(SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID, PermissionMode.WRITER);
|
||||||
PermissionMode.WRITER);
|
|
||||||
Vertex context = getContext(orientGraph, contextToMoveUUID);
|
Vertex context = getContext(orientGraph, contextToMoveUUID);
|
||||||
|
|
||||||
logger.trace("Context to move {}",
|
logger.trace("Context to move {}", Utility.toJsonString(context, true));
|
||||||
Utility.toJsonString(context, true));
|
|
||||||
|
|
||||||
checkContext(orientGraph, newParentUUID,
|
checkContext(orientGraph, newParentUUID, context.getProperty(Context.NAME_PROPERTY).toString());
|
||||||
context.getProperty(Context.NAME_PROPERTY).toString());
|
|
||||||
|
|
||||||
// Removing the old parent relationship if any
|
// Removing the old parent relationship if any
|
||||||
Iterable<Edge> edges = context.getEdges(Direction.IN,
|
Iterable<Edge> edges = context.getEdges(Direction.IN, IsParentOf.NAME);
|
||||||
IsParentOf.NAME);
|
|
||||||
if (edges != null && edges.iterator().hasNext()) {
|
if (edges != null && edges.iterator().hasNext()) {
|
||||||
Iterator<Edge> edgeIterator = edges.iterator();
|
Iterator<Edge> edgeIterator = edges.iterator();
|
||||||
Edge edge = edgeIterator.next();
|
Edge edge = edgeIterator.next();
|
||||||
|
@ -275,10 +242,8 @@ public class ContextManagementImpl implements OLDContextManagement {
|
||||||
|
|
||||||
if (newParentUUID != null) {
|
if (newParentUUID != null) {
|
||||||
Vertex parent = getContext(orientGraph, newParentUUID);
|
Vertex parent = getContext(orientGraph, newParentUUID);
|
||||||
logger.trace("New Parent Context {}",
|
logger.trace("New Parent Context {}", Utility.toJsonString(parent, true));
|
||||||
Utility.toJsonString(parent, true));
|
OrientEdge edge = orientGraph.addEdge(null, parent, context, IsParentOf.NAME);
|
||||||
OrientEdge edge = orientGraph.addEdge(null, parent, context,
|
|
||||||
IsParentOf.NAME);
|
|
||||||
HeaderUtility.addHeader(edge, null);
|
HeaderUtility.addHeader(edge, null);
|
||||||
edge.save();
|
edge.save();
|
||||||
}
|
}
|
||||||
|
@ -287,7 +252,6 @@ public class ContextManagementImpl implements OLDContextManagement {
|
||||||
|
|
||||||
ContextUtility.invalidContextUUIDCache(contextToMoveUUID);
|
ContextUtility.invalidContextUUIDCache(contextToMoveUUID);
|
||||||
|
|
||||||
|
|
||||||
context = getContext(orientGraph, contextToMoveUUID);
|
context = getContext(orientGraph, contextToMoveUUID);
|
||||||
String contextJsonString = Utility.toJsonString(context, true);
|
String contextJsonString = Utility.toJsonString(context, true);
|
||||||
logger.info("Context moved {}", contextJsonString);
|
logger.info("Context moved {}", contextJsonString);
|
||||||
|
@ -312,29 +276,22 @@ public class ContextManagementImpl implements OLDContextManagement {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean delete(UUID uuid) throws ContextNotFoundException,
|
public boolean delete(UUID uuid) throws ContextNotFoundException, ContextException {
|
||||||
ContextException {
|
|
||||||
|
|
||||||
OrientGraph orientGraph = null;
|
OrientGraph orientGraph = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.info("Trying to remove {} with UUID {}", Context.NAME, uuid);
|
logger.info("Trying to remove {} with UUID {}", Context.NAME, uuid);
|
||||||
|
|
||||||
|
orientGraph = SecurityContextMapper
|
||||||
|
.getSecurityContextGraph(SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID, PermissionMode.WRITER);
|
||||||
orientGraph = SecurityContextMapper.getSecurityContextGraph(
|
|
||||||
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
|
|
||||||
PermissionMode.WRITER);
|
|
||||||
|
|
||||||
Vertex context = getContext(orientGraph, uuid);
|
Vertex context = getContext(orientGraph, uuid);
|
||||||
logger.trace("Context to be delete {}",
|
logger.trace("Context to be delete {}", Utility.toJsonString(context, true));
|
||||||
Utility.toJsonString(context, true));
|
|
||||||
|
|
||||||
Iterable<Edge> edges = context.getEdges(Direction.OUT,
|
Iterable<Edge> edges = context.getEdges(Direction.OUT, IsParentOf.NAME);
|
||||||
IsParentOf.NAME);
|
|
||||||
if (edges != null && edges.iterator().hasNext()) {
|
if (edges != null && edges.iterator().hasNext()) {
|
||||||
throw new ContextException(
|
throw new ContextException("Only context with no children can be deleted");
|
||||||
"Only context with no children can be deleted");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SecurityContext.deleteSecurityContext(orientGraph, uuid, false);
|
SecurityContext.deleteSecurityContext(orientGraph, uuid, false);
|
||||||
|
@ -344,8 +301,7 @@ public class ContextManagementImpl implements OLDContextManagement {
|
||||||
orientGraph.commit();
|
orientGraph.commit();
|
||||||
ContextUtility.invalidContextUUIDCache(uuid);
|
ContextUtility.invalidContextUUIDCache(uuid);
|
||||||
|
|
||||||
logger.info("{} with UUID {} successfully removed", Context.NAME,
|
logger.info("{} with UUID {} successfully removed", Context.NAME, uuid);
|
||||||
uuid);
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} catch (ContextException | ContextNotFoundException ce) {
|
} catch (ContextException | ContextNotFoundException ce) {
|
|
@ -34,20 +34,6 @@ import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
||||||
public class ERManagementUtility {
|
public class ERManagementUtility {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(EntityManagement.class);
|
private static Logger logger = LoggerFactory.getLogger(EntityManagement.class);
|
||||||
/*
|
|
||||||
* @SuppressWarnings("rawtypes") public static ERManagement
|
|
||||||
* getERManagement(AccessType querableType) throws ResourceRegistryException {
|
|
||||||
* switch (querableType) { case FACET: return new FacetManagement();
|
|
||||||
*
|
|
||||||
* case RESOURCE: return new ResourceManagement();
|
|
||||||
*
|
|
||||||
* case IS_RELATED_TO: return new IsRelatedToManagement();
|
|
||||||
*
|
|
||||||
* case CONSISTS_OF: return new ConsistsOfManagement();
|
|
||||||
*
|
|
||||||
* default: throw new ResourceRegistryException(String.format(
|
|
||||||
* "%s is not querable", querableType.toString())); } }
|
|
||||||
*/
|
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public static ERManagement getERManagement(String type) throws ResourceRegistryException {
|
public static ERManagement getERManagement(String type) throws ResourceRegistryException {
|
||||||
|
@ -129,12 +115,12 @@ public class ERManagementUtility {
|
||||||
|
|
||||||
if (orientGraph == null) {
|
if (orientGraph == null) {
|
||||||
throw new ResourceRegistryException(OrientGraph.class.getSimpleName()
|
throw new ResourceRegistryException(OrientGraph.class.getSimpleName()
|
||||||
+ "instance is null. This is really strage please contact the administrator.");
|
+ "instance is null. " + Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vertex == null) {
|
if (vertex == null) {
|
||||||
throw new ResourceRegistryException(Vertex.class.getSimpleName()
|
throw new ResourceRegistryException(Vertex.class.getSimpleName()
|
||||||
+ "instance is null. This is really strage please contact the administrator.");
|
+ "instance is null. " + Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
OrientVertexType orientVertexType = null;
|
OrientVertexType orientVertexType = null;
|
||||||
|
@ -142,8 +128,8 @@ public class ERManagementUtility {
|
||||||
orientVertexType = ((OrientVertex) vertex).getType();
|
orientVertexType = ((OrientVertex) vertex).getType();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String error = String.format(
|
String error = String.format(
|
||||||
"Unable to detect type of %s. This is really strage please contact the administrator.",
|
"Unable to detect type of %s. %s",
|
||||||
vertex.toString());
|
vertex.toString(), Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
logger.error(error, e);
|
logger.error(error, e);
|
||||||
throw new ResourceRegistryException(error);
|
throw new ResourceRegistryException(error);
|
||||||
}
|
}
|
||||||
|
@ -154,8 +140,8 @@ public class ERManagementUtility {
|
||||||
} else if (orientVertexType.isSubClassOf(Facet.NAME)) {
|
} else if (orientVertexType.isSubClassOf(Facet.NAME)) {
|
||||||
entityManagement = new FacetManagement(orientGraph);
|
entityManagement = new FacetManagement(orientGraph);
|
||||||
} else {
|
} else {
|
||||||
String error = String.format("{%s is not a %s nor a %s. " + "This is really strange and should not occur. "
|
String error = String.format("{%s is not a %s nor a %s. %s",
|
||||||
+ "Please Investigate it.", vertex, Resource.NAME, Facet.NAME);
|
vertex, Resource.NAME, Facet.NAME, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
throw new ResourceRegistryException(error);
|
throw new ResourceRegistryException(error);
|
||||||
}
|
}
|
||||||
entityManagement.setElement(vertex);
|
entityManagement.setElement(vertex);
|
||||||
|
@ -168,12 +154,12 @@ public class ERManagementUtility {
|
||||||
|
|
||||||
if (orientGraph == null) {
|
if (orientGraph == null) {
|
||||||
throw new ResourceRegistryException(OrientGraph.class.getSimpleName()
|
throw new ResourceRegistryException(OrientGraph.class.getSimpleName()
|
||||||
+ "instance is null. This is really strage please contact the administrator.");
|
+ "instance is null. " + Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (edge == null) {
|
if (edge == null) {
|
||||||
throw new ResourceRegistryException(Edge.class.getSimpleName()
|
throw new ResourceRegistryException(Edge.class.getSimpleName()
|
||||||
+ "instance is null. This is really strage please contact the administrator.");
|
+ "instance is null. " + Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
OrientEdgeType orientEdgeType = ((OrientEdge) edge).getType();
|
OrientEdgeType orientEdgeType = ((OrientEdge) edge).getType();
|
||||||
|
@ -183,8 +169,8 @@ public class ERManagementUtility {
|
||||||
} else if (orientEdgeType.isSubClassOf(IsRelatedTo.NAME)) {
|
} else if (orientEdgeType.isSubClassOf(IsRelatedTo.NAME)) {
|
||||||
relationManagement = new IsRelatedToManagement(orientGraph);
|
relationManagement = new IsRelatedToManagement(orientGraph);
|
||||||
} else {
|
} else {
|
||||||
String error = String.format("{%s is not a %s nor a %s. " + "This is really strange ad should not occur. "
|
String error = String.format("{%s is not a %s nor a %s. %s",
|
||||||
+ "Please Investigate it.", edge, ConsistsOf.NAME, IsRelatedTo.NAME);
|
edge, ConsistsOf.NAME, IsRelatedTo.NAME, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
throw new ResourceRegistryException(error);
|
throw new ResourceRegistryException(error);
|
||||||
}
|
}
|
||||||
relationManagement.setElement(edge);
|
relationManagement.setElement(edge);
|
||||||
|
|
|
@ -168,18 +168,6 @@ public abstract class EntityManagement<E extends Entity> extends
|
||||||
ignoreStartWithKeys);
|
ignoreStartWithKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This code has been moved in ERManagement.internalCreate()
|
|
||||||
Header entityHeader = HeaderUtility.getHeader(jsonNode, true);
|
|
||||||
if (entityHeader != null) {
|
|
||||||
element.setProperty(Entity.HEADER_PROPERTY, entityHeader);
|
|
||||||
} else {
|
|
||||||
entityHeader = HeaderUtility.addHeader(element, null);
|
|
||||||
}
|
|
||||||
ContextUtility.addToActualContext(orientGraph, element);
|
|
||||||
|
|
||||||
((OrientVertex) element).save();
|
|
||||||
*/
|
|
||||||
|
|
||||||
logger.info("Created {} is {}", Vertex.class.getSimpleName(),
|
logger.info("Created {} is {}", Vertex.class.getSimpleName(),
|
||||||
Utility.toJsonString((OrientVertex) element, true));
|
Utility.toJsonString((OrientVertex) element, true));
|
||||||
|
|
||||||
|
@ -241,7 +229,8 @@ public abstract class EntityManagement<E extends Entity> extends
|
||||||
JSONObject jsonObject = entityManagement.serializeAsJson();
|
JSONObject jsonObject = entityManagement.serializeAsJson();
|
||||||
jsonArray.put(jsonObject);
|
jsonArray.put(jsonObject);
|
||||||
}catch (ResourceRegistryException e) {
|
}catch (ResourceRegistryException e) {
|
||||||
logger.error("Unable to correctly serialize {}. It will be excluded from results. This is really strange and should not occur.", vertex.toString());
|
logger.error("Unable to correctly serialize {}. It will be excluded from results. {}",
|
||||||
|
vertex.toString(), Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return jsonArray.toString();
|
return jsonArray.toString();
|
||||||
|
|
|
@ -108,10 +108,10 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
||||||
JSONObject consistsOf = relationManagement.serializeAsJson(true, true);
|
JSONObject consistsOf = relationManagement.serializeAsJson(true, true);
|
||||||
sourceResource = addConsistsOf(sourceResource, consistsOf);
|
sourceResource = addConsistsOf(sourceResource, consistsOf);
|
||||||
}catch (ResourceRegistryException e) {
|
}catch (ResourceRegistryException e) {
|
||||||
logger.error("Unable to correctly serialize {}. This is really strange and should not occur.", edge);
|
logger.error("Unable to correctly serialize {}. {}", edge, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
throw e;
|
throw e;
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
logger.error("Unable to correctly serialize {}. This is really strange and should not occur.", edge);
|
logger.error("Unable to correctly serialize {}. {}", edge, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
throw new ResourceRegistryException(e);
|
throw new ResourceRegistryException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,11 +226,9 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
||||||
} else if (orientEdgeType.isSubClassOf(ConsistsOf.NAME)) {
|
} else if (orientEdgeType.isSubClassOf(ConsistsOf.NAME)) {
|
||||||
relationManagement = new ConsistsOfManagement(orientGraph);
|
relationManagement = new ConsistsOfManagement(orientGraph);
|
||||||
} else {
|
} else {
|
||||||
logger.warn("{} is not a {} nor a {}. "
|
logger.warn("{} is not a {} nor a {}. {}",
|
||||||
+ "This is really strange ad should not occur. "
|
|
||||||
+ "Please Investigate it.",
|
|
||||||
Utility.toJsonString(edge, true), IsRelatedTo.NAME,
|
Utility.toJsonString(edge, true), IsRelatedTo.NAME,
|
||||||
ConsistsOf.NAME);
|
ConsistsOf.NAME, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
if (relationManagement != null) {
|
if (relationManagement != null) {
|
||||||
relationManagement.setElement(edge);
|
relationManagement.setElement(edge);
|
||||||
|
@ -329,7 +327,8 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
||||||
}
|
}
|
||||||
orientVertexType = ((OrientVertex) orientElement).getType();
|
orientVertexType = ((OrientVertex) orientElement).getType();
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
String error = String.format("Unable to detect type of %s. This is really strage please contact the administrator.", element.toString());
|
String error = String.format("Unable to detect type of %s. %s",
|
||||||
|
element.toString(), Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
logger.error(error, e);
|
logger.error(error, e);
|
||||||
throw new ResourceRegistryException(error);
|
throw new ResourceRegistryException(error);
|
||||||
}
|
}
|
||||||
|
@ -351,7 +350,8 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
||||||
JSONObject jsonObject = entityManagement.serializeAsJson();
|
JSONObject jsonObject = entityManagement.serializeAsJson();
|
||||||
jsonArray.put(jsonObject);
|
jsonArray.put(jsonObject);
|
||||||
}catch (ResourceRegistryException e) {
|
}catch (ResourceRegistryException e) {
|
||||||
logger.error("Unable to correctly serialize {}. It will be excluded from results. This is really strange and should not occur.", vertex.toString());
|
logger.error("Unable to correctly serialize {}. It will be excluded from results. {}",
|
||||||
|
vertex.toString(), Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -153,10 +153,10 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (ResourceRegistryException e) {
|
} catch (ResourceRegistryException e) {
|
||||||
logger.error("Unable to correctly serialize {}. This is really strange and should not occur.", element, e);
|
logger.error("Unable to correctly serialize {}. {}", element, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE, e);
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Unable to correctly serialize {}. This is really strange and should not occur.", element, e);
|
logger.error("Unable to correctly serialize {}. {}", element, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE, e);
|
||||||
throw new ResourceRegistryException(e);
|
throw new ResourceRegistryException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,9 +181,9 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
sourceResource = resourceManagement.serializeSelfOnly();
|
sourceResource = resourceManagement.serializeSelfOnly();
|
||||||
} else {
|
} else {
|
||||||
String error = String.format(
|
String error = String.format(
|
||||||
"{%s is not a %s nor a %s. " + "This is really strange and should not occur. "
|
"{%s is not a %s nor a %s. %s",
|
||||||
+ "Please Investigate it.",
|
this, IsRelatedToManagement.class.getSimpleName(), ConsistsOfManagement.class.getSimpleName(),
|
||||||
this, IsRelatedToManagement.class.getSimpleName(), ConsistsOfManagement.class.getSimpleName());
|
Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
throw new ResourceRegistryException(error);
|
throw new ResourceRegistryException(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -195,9 +195,9 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
sourceResource = ResourceManagement.addConsistsOf(sourceResource, serializeAsJson());
|
sourceResource = ResourceManagement.addConsistsOf(sourceResource, serializeAsJson());
|
||||||
} else {
|
} else {
|
||||||
String error = String.format(
|
String error = String.format(
|
||||||
"{%s is not a %s nor a %s. " + "This is really strange and should not occur. "
|
"{%s is not a %s nor a %s. %s",
|
||||||
+ "Please Investigate it.",
|
this, IsRelatedToManagement.class.getSimpleName(), ConsistsOfManagement.class.getSimpleName(),
|
||||||
this, IsRelatedToManagement.class.getSimpleName(), ConsistsOfManagement.class.getSimpleName());
|
Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
throw new ResourceRegistryException(error);
|
throw new ResourceRegistryException(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,14 +259,6 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
|
|
||||||
ERManagement.updateProperties(oClass, element, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
ERManagement.updateProperties(oClass, element, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||||
|
|
||||||
/*
|
|
||||||
* This code has been moved in ERManagement.internalCreate()
|
|
||||||
* HeaderUtility.addHeader(element, null);
|
|
||||||
* ContextUtility.addToActualContext(orientGraph, element);
|
|
||||||
*
|
|
||||||
* ((OrientEdge) element).save();
|
|
||||||
*/
|
|
||||||
|
|
||||||
logger.info("{} successfully created", erType);
|
logger.info("{} successfully created", erType);
|
||||||
|
|
||||||
return element;
|
return element;
|
||||||
|
@ -276,18 +268,6 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
|
|
||||||
protected abstract T newTargetEntityManagement() throws ResourceRegistryException;
|
protected abstract T newTargetEntityManagement() throws ResourceRegistryException;
|
||||||
|
|
||||||
/*
|
|
||||||
* public void setSourceUUID(UUID sourceUUID) throws ResourceRegistryException {
|
|
||||||
* this.sourceEntityManagemen = newSourceEntityManagement();
|
|
||||||
* this.sourceEntityManagemen.setUUID(sourceUUID); }
|
|
||||||
*
|
|
||||||
* public void setTargetUUID(UUID targetUUID) throws ResourceRegistryException {
|
|
||||||
* this.targetEntityManagemen = newTargetEntityManagement();
|
|
||||||
* this.targetEntityManagemen.setUUID(targetUUID);
|
|
||||||
*
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Edge reallyUpdate() throws ResourceRegistryException {
|
protected Edge reallyUpdate() throws ResourceRegistryException {
|
||||||
|
|
||||||
|
@ -324,18 +304,17 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
addConstraint = propagationConstraint.getAddConstraint();
|
addConstraint = propagationConstraint.getAddConstraint();
|
||||||
} else {
|
} else {
|
||||||
String error = String.format(
|
String error = String.format(
|
||||||
"%s.%s in %s is null" + "This is really strange and should not occur. "
|
"%s.%s in %s is null. %s",
|
||||||
+ "Please Investigate it.",
|
|
||||||
Relation.PROPAGATION_CONSTRAINT, PropagationConstraint.ADD_PROPERTY,
|
Relation.PROPAGATION_CONSTRAINT, PropagationConstraint.ADD_PROPERTY,
|
||||||
Utility.toJsonString(element, true));
|
Utility.toJsonString(element, true), Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
throw new ResourceRegistryException(error);
|
throw new ResourceRegistryException(error);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String error = String.format(
|
String error = String.format(
|
||||||
"Error while getting %s from %s while performing AddToContext."
|
"Error while getting %s from %s while performing AddToContext. %s",
|
||||||
+ "This is really strange and should not occur. " + "Please Investigate it.",
|
Relation.PROPAGATION_CONSTRAINT, Utility.toJsonString(element, true),
|
||||||
Relation.PROPAGATION_CONSTRAINT, Utility.toJsonString(element, true));
|
Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
logger.warn(error);
|
logger.warn(error);
|
||||||
throw new ResourceRegistryException(error, e);
|
throw new ResourceRegistryException(error, e);
|
||||||
}
|
}
|
||||||
|
@ -377,14 +356,6 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* protected boolean removeFromContextTargetVertex(Vertex target) throws
|
|
||||||
* ResourceRegistryException { EntityManagement entityManagement =
|
|
||||||
* EntityManagement.getEntityManagement(orientGraph, target); if
|
|
||||||
* (entityManagement != null) { entityManagement.internalRemoveFromContext();
|
|
||||||
* return true; } else { return false; } }
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean reallyRemoveFromContext() throws ContextException, ResourceRegistryException {
|
protected boolean reallyRemoveFromContext() throws ContextException, ResourceRegistryException {
|
||||||
getElement();
|
getElement();
|
||||||
|
@ -398,18 +369,17 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
removeConstraint = propagationConstraint.getRemoveConstraint();
|
removeConstraint = propagationConstraint.getRemoveConstraint();
|
||||||
} else {
|
} else {
|
||||||
String error = String.format(
|
String error = String.format(
|
||||||
"%s.%s in %s is null" + "This is really strange and should not occur. "
|
"%s.%s in %s is null. %s",
|
||||||
+ "Please Investigate it.",
|
|
||||||
Relation.PROPAGATION_CONSTRAINT, PropagationConstraint.REMOVE_PROPERTY,
|
Relation.PROPAGATION_CONSTRAINT, PropagationConstraint.REMOVE_PROPERTY,
|
||||||
Utility.toJsonString(element, true));
|
Utility.toJsonString(element, true), Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
throw new ResourceRegistryException(error);
|
throw new ResourceRegistryException(error);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String error = String.format(
|
String error = String.format(
|
||||||
"Error while getting %s from %s while performing RemoveFromContext."
|
"Error while getting %s from %s while performing RemoveFromContext. %s",
|
||||||
+ "This is really strange and should not occur. " + "Please Investigate it.",
|
Relation.PROPAGATION_CONSTRAINT, Utility.toJsonString(element, true),
|
||||||
Relation.PROPAGATION_CONSTRAINT, Utility.toJsonString(element, true));
|
Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
throw new ResourceRegistryException(error, e);
|
throw new ResourceRegistryException(error, e);
|
||||||
|
|
||||||
|
@ -482,18 +452,17 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
removeConstraint = propagationConstraint.getRemoveConstraint();
|
removeConstraint = propagationConstraint.getRemoveConstraint();
|
||||||
} else {
|
} else {
|
||||||
String error = String.format(
|
String error = String.format(
|
||||||
"%s.%s in %s is null" + "This is really strange and should not occur. "
|
"%s.%s in %s is null. %s",
|
||||||
+ "Please Investigate it.",
|
|
||||||
Relation.PROPAGATION_CONSTRAINT, PropagationConstraint.REMOVE_PROPERTY,
|
Relation.PROPAGATION_CONSTRAINT, PropagationConstraint.REMOVE_PROPERTY,
|
||||||
Utility.toJsonString(element, true));
|
Utility.toJsonString(element, true), Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
throw new ResourceRegistryException(error);
|
throw new ResourceRegistryException(error);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Error while getting {} from {}. Assuming {}. " + "This is really strange and should not occur. "
|
"Error while getting {} from {}. Assuming {}. {}",
|
||||||
+ "Please Investigate it.",
|
Relation.PROPAGATION_CONSTRAINT, Utility.toJsonString(element, true), removeConstraint,
|
||||||
Relation.PROPAGATION_CONSTRAINT, Utility.toJsonString(element, true), removeConstraint);
|
Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vertex target = (Vertex) getTargetEntityManagement().getElement();
|
Vertex target = (Vertex) getTargetEntityManagement().getElement();
|
||||||
|
|
|
@ -31,7 +31,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.query.Invalid
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
|
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPCall.HTTPMETHOD;
|
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPCall.HTTPMETHOD;
|
||||||
import org.gcube.informationsystem.resourceregistry.context.ContextManagementImpl;
|
import org.gcube.informationsystem.resourceregistry.context.OLDContextManagementImpl;
|
||||||
import org.gcube.informationsystem.resourceregistry.context.OLDContextManagement;
|
import org.gcube.informationsystem.resourceregistry.context.OLDContextManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.er.ERManagement;
|
import org.gcube.informationsystem.resourceregistry.er.ERManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.er.ERManagementUtility;
|
import org.gcube.informationsystem.resourceregistry.er.ERManagementUtility;
|
||||||
|
@ -299,7 +299,7 @@ public class Access {
|
||||||
public String getContext(@PathParam(ID_PATH_PARAM) String uuid)
|
public String getContext(@PathParam(ID_PATH_PARAM) String uuid)
|
||||||
throws ContextNotFoundException, ContextException {
|
throws ContextNotFoundException, ContextException {
|
||||||
logger.info("Requested to read {} with id {} ", org.gcube.informationsystem.model.entity.Context.NAME, uuid);
|
logger.info("Requested to read {} with id {} ", org.gcube.informationsystem.model.entity.Context.NAME, uuid);
|
||||||
OLDContextManagement contextManager = new ContextManagementImpl();
|
OLDContextManagement contextManager = new OLDContextManagementImpl();
|
||||||
return contextManager.read(UUID.fromString(uuid));
|
return contextManager.read(UUID.fromString(uuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,26 +6,23 @@ package org.gcube.informationsystem.resourceregistry.rest;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.ws.rs.DELETE;
|
import javax.ws.rs.DELETE;
|
||||||
import javax.ws.rs.DefaultValue;
|
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.PUT;
|
import javax.ws.rs.PUT;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.QueryParam;
|
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
import org.gcube.informationsystem.model.entity.Context;
|
import org.gcube.informationsystem.model.entity.Context;
|
||||||
import org.gcube.informationsystem.resourceregistry.ResourceInitializer;
|
import org.gcube.informationsystem.resourceregistry.ResourceInitializer;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextCreationException;
|
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.ContextException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.rest.ContextPath;
|
import org.gcube.informationsystem.resourceregistry.api.rest.ContextPath;
|
||||||
import org.gcube.informationsystem.resourceregistry.context.OLDContextManagement;
|
import org.gcube.informationsystem.resourceregistry.context.ContextManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.context.ContextManagementImpl;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -43,28 +40,20 @@ public class ContextManager {
|
||||||
|
|
||||||
public static final String ID_PATH_PARAM = "id";
|
public static final String ID_PATH_PARAM = "id";
|
||||||
|
|
||||||
protected OLDContextManagement contextManager = new ContextManagementImpl();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* e.g. PUT /resource-registry/context?name=myVRE&parentContextId=a2fe0030-7b3d-4617-ba37-532c0e4b778d
|
* e.g. PUT /resource-registry/context
|
||||||
* @param parentUUID
|
*
|
||||||
* @param name
|
* BODY: {...}
|
||||||
* @return
|
*
|
||||||
* @throws InternalException
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
@PUT
|
@PUT
|
||||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||||
public Response create(
|
public Response create(String json)
|
||||||
@QueryParam(ContextPath.PARENT_CONTEXT_ID_PARAM) @DefaultValue("") String parentUUID,
|
throws ContextAlreadyPresentException, ResourceRegistryException {
|
||||||
@QueryParam(ContextPath.NAME_PARAM) String name)
|
logger.info("Requested to create {} with json {}", Context.NAME, json);
|
||||||
throws ContextCreationException, ResourceRegistryException {
|
ContextManagement contextManagement = new ContextManagement();
|
||||||
logger.info("Requested to create {} with name : {} ", Context.NAME, name);
|
contextManagement.setJSON(json);
|
||||||
UUID parent = null;
|
String ret = contextManagement.create();
|
||||||
if(parentUUID!=null && parentUUID.compareTo("")!=0){
|
|
||||||
parent = UUID.fromString(parentUUID);
|
|
||||||
}
|
|
||||||
String ret = contextManager.create(parent, name);
|
|
||||||
return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8).build();
|
return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,9 +67,11 @@ public class ContextManager {
|
||||||
@Path("{" + ID_PATH_PARAM + "}")
|
@Path("{" + ID_PATH_PARAM + "}")
|
||||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||||
public String read(@PathParam(ID_PATH_PARAM) String uuid)
|
public String read(@PathParam(ID_PATH_PARAM) String uuid)
|
||||||
throws ContextNotFoundException, ContextException {
|
throws ContextNotFoundException, ResourceRegistryException {
|
||||||
logger.info("Requested to read {} with id {} ", Context.NAME, uuid);
|
logger.info("Requested to read {} with id {} ", Context.NAME, uuid);
|
||||||
return contextManager.read(UUID.fromString(uuid));
|
ContextManagement contextManagement = new ContextManagement();
|
||||||
|
contextManagement.setUUID(UUID.fromString(uuid));
|
||||||
|
return contextManagement.read();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -93,48 +84,27 @@ public class ContextManager {
|
||||||
@Path("{" + ID_PATH_PARAM + "}")
|
@Path("{" + ID_PATH_PARAM + "}")
|
||||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||||
public boolean delete(@PathParam(ID_PATH_PARAM) String uuid)
|
public boolean delete(@PathParam(ID_PATH_PARAM) String uuid)
|
||||||
throws ContextNotFoundException, ContextException {
|
throws ContextNotFoundException, ResourceRegistryException {
|
||||||
logger.info("Requested to delete {} with id {} ", Context.NAME, uuid);
|
logger.info("Requested to delete {} with id {} ", Context.NAME, uuid);
|
||||||
return contextManager.delete(UUID.fromString(uuid));
|
ContextManagement contextManagement = new ContextManagement();
|
||||||
|
contextManagement.setUUID(UUID.fromString(uuid));
|
||||||
|
return contextManagement.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* e.g. POST /resource-registry/context/rename/c0f314e7-2807-4241-a792-2a6c79ed4fd0?name=newNameVRE
|
* e.g. POST /resource-registry/context
|
||||||
* @param uuid
|
*
|
||||||
* @param name
|
* BODY: {...}
|
||||||
* @return
|
*
|
||||||
* @throws ContextNotFoundException
|
|
||||||
* @throws ContextException
|
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path(ContextPath.RENAME_PATH_PART + "/{" + ID_PATH_PARAM + "}")
|
|
||||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||||
public String rename(@PathParam(ID_PATH_PARAM) String uuid,
|
public String rename(String json)
|
||||||
@QueryParam(ContextPath.NAME_PARAM) String name)
|
throws ContextNotFoundException, ResourceRegistryException {
|
||||||
throws ContextNotFoundException, ContextException {
|
logger.info("Requested to update {} with json {} ", Context.NAME, json);
|
||||||
logger.info("Requested to rename as {} {} with id {} ", name, Context.NAME, uuid);
|
ContextManagement contextManagement = new ContextManagement();
|
||||||
return contextManager.rename(UUID.fromString(uuid), name);
|
contextManagement.setJSON(json);
|
||||||
}
|
return contextManagement.update();
|
||||||
|
|
||||||
/**
|
|
||||||
* e.g. POST /resource-registry/context/move/c0f314e7-2807-4241-a792-2a6c79ed4fd0?parentContextId=68cf247a-b1ed-44cd-9d2e-c16d865bade7
|
|
||||||
* @param uuid
|
|
||||||
* @param newParentUUID
|
|
||||||
* @return
|
|
||||||
* @throws ContextNotFoundException
|
|
||||||
* @throws ContextException
|
|
||||||
*/
|
|
||||||
@POST
|
|
||||||
@Path(ContextPath.MOVE_PATH_PART + "/{" + ID_PATH_PARAM + "}")
|
|
||||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
|
||||||
public String move(
|
|
||||||
@PathParam(ID_PATH_PARAM) String uuid,
|
|
||||||
@QueryParam(ContextPath.PARENT_CONTEXT_ID_PARAM) String newParentUUID)
|
|
||||||
throws ContextNotFoundException, ContextException {
|
|
||||||
logger.info("Requested to move {} with id {} as child of {} having id {} ",
|
|
||||||
Context.NAME, uuid, Context.NAME, newParentUUID);
|
|
||||||
return contextManager.move(UUID.fromString(newParentUUID),
|
|
||||||
UUID.fromString(uuid));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ import org.gcube.informationsystem.model.entity.Facet;
|
||||||
import org.gcube.informationsystem.model.entity.Resource;
|
import org.gcube.informationsystem.model.entity.Resource;
|
||||||
import org.gcube.informationsystem.model.relation.ConsistsOf;
|
import org.gcube.informationsystem.model.relation.ConsistsOf;
|
||||||
import org.gcube.informationsystem.model.relation.IsRelatedTo;
|
import org.gcube.informationsystem.model.relation.IsRelatedTo;
|
||||||
import org.gcube.informationsystem.model.relation.Relation;
|
|
||||||
import org.gcube.informationsystem.resourceregistry.ResourceInitializer;
|
import org.gcube.informationsystem.resourceregistry.ResourceInitializer;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
|
||||||
|
@ -62,8 +61,8 @@ public class ERManager {
|
||||||
CalledMethodProvider.instance.set(
|
CalledMethodProvider.instance.set(
|
||||||
HTTPMETHOD.PUT.name() + " /" + ERPath.ER_PATH_PART +
|
HTTPMETHOD.PUT.name() + " /" + ERPath.ER_PATH_PART +
|
||||||
"/" + ERPath.FACET_PATH_PART + "/" + type);
|
"/" + ERPath.FACET_PATH_PART + "/" + type);
|
||||||
logger.info("requested facet creation for type {}", type);
|
logger.info("Requested to create {} of type {}", Facet.NAME, type);
|
||||||
logger.trace("requested facet creation for type {} defined by {} ", type, json);
|
logger.trace("Requested to create {} of type {} defined by {} ", Facet.NAME, type, json);
|
||||||
FacetManagement facetManagement = new FacetManagement();
|
FacetManagement facetManagement = new FacetManagement();
|
||||||
facetManagement.setElementType(type);
|
facetManagement.setElementType(type);
|
||||||
facetManagement.setJSON(json);
|
facetManagement.setJSON(json);
|
||||||
|
@ -87,8 +86,8 @@ public class ERManager {
|
||||||
CalledMethodProvider.instance.set(
|
CalledMethodProvider.instance.set(
|
||||||
HTTPMETHOD.POST.name() + " /" + ERPath.ER_PATH_PART +
|
HTTPMETHOD.POST.name() + " /" + ERPath.ER_PATH_PART +
|
||||||
"/" + ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}");
|
"/" + ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}");
|
||||||
logger.info("requested facet update for id {}", uuid);
|
logger.info("Requested to update {} with id {}", Facet.NAME, uuid);
|
||||||
logger.trace("requested facet update for id {} with {}", uuid, json);
|
logger.trace("Requested to update {} with id {} with json {}", Facet.NAME, uuid, json);
|
||||||
FacetManagement facetManagement = new FacetManagement();
|
FacetManagement facetManagement = new FacetManagement();
|
||||||
facetManagement.setUUID(UUID.fromString(uuid));
|
facetManagement.setUUID(UUID.fromString(uuid));
|
||||||
facetManagement.setJSON(json);
|
facetManagement.setJSON(json);
|
||||||
|
@ -106,7 +105,7 @@ public class ERManager {
|
||||||
CalledMethodProvider.instance.set(
|
CalledMethodProvider.instance.set(
|
||||||
HTTPMETHOD.DELETE.name() + " /" + ERPath.ER_PATH_PART +
|
HTTPMETHOD.DELETE.name() + " /" + ERPath.ER_PATH_PART +
|
||||||
"/" + ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}");
|
"/" + ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}");
|
||||||
logger.info("Requested to delete Facet with id {}", uuid);
|
logger.info("Requested to delete {} with id {}", Facet.NAME, uuid);
|
||||||
FacetManagement facetManagement = new FacetManagement();
|
FacetManagement facetManagement = new FacetManagement();
|
||||||
facetManagement.setUUID(UUID.fromString(uuid));
|
facetManagement.setUUID(UUID.fromString(uuid));
|
||||||
return facetManagement.delete();
|
return facetManagement.delete();
|
||||||
|
@ -129,8 +128,8 @@ public class ERManager {
|
||||||
CalledMethodProvider.instance.set(
|
CalledMethodProvider.instance.set(
|
||||||
HTTPMETHOD.PUT.name() + " /" + ERPath.ER_PATH_PART +
|
HTTPMETHOD.PUT.name() + " /" + ERPath.ER_PATH_PART +
|
||||||
"/" + ERPath.RESOURCE_PATH_PART + "/" + type);
|
"/" + ERPath.RESOURCE_PATH_PART + "/" + type);
|
||||||
logger.info("requested resource creation for type {}", type);
|
logger.info("Requested to create {} of type {}", Resource.NAME, type);
|
||||||
logger.trace("requested resource creation for type {} with json {}", type, json);
|
logger.trace("Requested to create {} of type {} with json {}", Resource.NAME, type, json);
|
||||||
ResourceManagement resourceManagement = new ResourceManagement();
|
ResourceManagement resourceManagement = new ResourceManagement();
|
||||||
resourceManagement.setElementType(type);
|
resourceManagement.setElementType(type);
|
||||||
resourceManagement.setJSON(json);
|
resourceManagement.setJSON(json);
|
||||||
|
@ -154,8 +153,8 @@ public class ERManager {
|
||||||
CalledMethodProvider.instance.set(
|
CalledMethodProvider.instance.set(
|
||||||
HTTPMETHOD.POST.name() + " /" + ERPath.ER_PATH_PART +
|
HTTPMETHOD.POST.name() + " /" + ERPath.ER_PATH_PART +
|
||||||
"/" + ERPath.RESOURCE_PATH_PART + "/{" + ID_PATH_PARAM + "}");
|
"/" + ERPath.RESOURCE_PATH_PART + "/{" + ID_PATH_PARAM + "}");
|
||||||
logger.info("requested resource update for id {}", uuid);
|
logger.info("Requested to update {} with id {}", Resource.NAME, uuid);
|
||||||
logger.trace("requested resource update for id {} with {}", uuid, json);
|
logger.trace("Requested to update {} with id {} with json {}", Resource.NAME, uuid, json);
|
||||||
ResourceManagement resourceManagement = new ResourceManagement();
|
ResourceManagement resourceManagement = new ResourceManagement();
|
||||||
resourceManagement.setUUID(UUID.fromString(uuid));
|
resourceManagement.setUUID(UUID.fromString(uuid));
|
||||||
resourceManagement.setJSON(json);
|
resourceManagement.setJSON(json);
|
||||||
|
@ -172,7 +171,7 @@ public class ERManager {
|
||||||
CalledMethodProvider.instance.set(
|
CalledMethodProvider.instance.set(
|
||||||
HTTPMETHOD.DELETE.name() + " /" + ERPath.ER_PATH_PART +
|
HTTPMETHOD.DELETE.name() + " /" + ERPath.ER_PATH_PART +
|
||||||
"/" + ERPath.RESOURCE_PATH_PART + "/{" + ID_PATH_PARAM + "}");
|
"/" + ERPath.RESOURCE_PATH_PART + "/{" + ID_PATH_PARAM + "}");
|
||||||
logger.info("requested resource deletion for id {}", uuid);
|
logger.info("Requested to delete {} with id {}", Resource.NAME, uuid);
|
||||||
ResourceManagement resourceManagement = new ResourceManagement();
|
ResourceManagement resourceManagement = new ResourceManagement();
|
||||||
resourceManagement.setUUID(UUID.fromString(uuid));
|
resourceManagement.setUUID(UUID.fromString(uuid));
|
||||||
return resourceManagement.delete();
|
return resourceManagement.delete();
|
||||||
|
@ -194,8 +193,8 @@ public class ERManager {
|
||||||
CalledMethodProvider.instance.set(
|
CalledMethodProvider.instance.set(
|
||||||
HTTPMETHOD.PUT.name() + " /" + ERPath.ER_PATH_PART +
|
HTTPMETHOD.PUT.name() + " /" + ERPath.ER_PATH_PART +
|
||||||
"/" + ERPath.CONSISTS_OF_PATH_PART + "/" + type);
|
"/" + ERPath.CONSISTS_OF_PATH_PART + "/" + type);
|
||||||
logger.info("Requested to create {} {} of type {}", ConsistsOf.NAME, Relation.NAME, type);
|
logger.info("Requested to create {} of type {}", ConsistsOf.NAME, type);
|
||||||
logger.trace("Requested to create {} {} of type {} : {}", ConsistsOf.NAME, Relation.NAME, type, json);
|
logger.trace("Requested to create {} of type {} with json {}", ConsistsOf.NAME, type, json);
|
||||||
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
|
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
|
||||||
consistsOfManagement.setElementType(type);
|
consistsOfManagement.setElementType(type);
|
||||||
consistsOfManagement.setJSON(json);
|
consistsOfManagement.setJSON(json);
|
||||||
|
@ -214,7 +213,7 @@ public class ERManager {
|
||||||
CalledMethodProvider.instance.set(
|
CalledMethodProvider.instance.set(
|
||||||
HTTPMETHOD.DELETE.name() + " /" + ERPath.ER_PATH_PART +
|
HTTPMETHOD.DELETE.name() + " /" + ERPath.ER_PATH_PART +
|
||||||
"/" + ERPath.CONSISTS_OF_PATH_PART + "/{" + ID_PATH_PARAM + "}");
|
"/" + ERPath.CONSISTS_OF_PATH_PART + "/{" + ID_PATH_PARAM + "}");
|
||||||
logger.info("requested to detach {}", consistOfUUID);
|
logger.info("Requested to delete {} with id {}", ConsistsOf.NAME, consistOfUUID);
|
||||||
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
|
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
|
||||||
consistsOfManagement.setUUID(UUID.fromString(consistOfUUID));
|
consistsOfManagement.setUUID(UUID.fromString(consistOfUUID));
|
||||||
return consistsOfManagement.delete();
|
return consistsOfManagement.delete();
|
||||||
|
@ -235,7 +234,7 @@ public class ERManager {
|
||||||
CalledMethodProvider.instance.set(
|
CalledMethodProvider.instance.set(
|
||||||
HTTPMETHOD.PUT.name() + " /" + ERPath.ER_PATH_PART +
|
HTTPMETHOD.PUT.name() + " /" + ERPath.ER_PATH_PART +
|
||||||
"/" + ERPath.IS_RELATED_TO_PATH_PART + "/" + type);
|
"/" + ERPath.IS_RELATED_TO_PATH_PART + "/" + type);
|
||||||
logger.info("Requested to create {} {} of type {} : {}", IsRelatedTo.NAME, Relation.NAME, type, json);
|
logger.info("Requested to create {} of type {} with json {}", IsRelatedTo.NAME, type, json);
|
||||||
IsRelatedToManagement isRelatedToManagement = new IsRelatedToManagement();
|
IsRelatedToManagement isRelatedToManagement = new IsRelatedToManagement();
|
||||||
isRelatedToManagement.setElementType(type);
|
isRelatedToManagement.setElementType(type);
|
||||||
isRelatedToManagement.setJSON(json);
|
isRelatedToManagement.setJSON(json);
|
||||||
|
@ -254,7 +253,7 @@ public class ERManager {
|
||||||
CalledMethodProvider.instance.set(
|
CalledMethodProvider.instance.set(
|
||||||
HTTPMETHOD.DELETE.name() + " /" + ERPath.ER_PATH_PART +
|
HTTPMETHOD.DELETE.name() + " /" + ERPath.ER_PATH_PART +
|
||||||
"/" + ERPath.IS_RELATED_TO_PATH_PART + "/{" + ID_PATH_PARAM + "}");
|
"/" + ERPath.IS_RELATED_TO_PATH_PART + "/{" + ID_PATH_PARAM + "}");
|
||||||
logger.info("requested to detach {}", relatedToUUID);
|
logger.info("Requested to delete {} with id {}", IsRelatedTo.NAME, relatedToUUID);
|
||||||
IsRelatedToManagement isRelatedToManagement = new IsRelatedToManagement();
|
IsRelatedToManagement isRelatedToManagement = new IsRelatedToManagement();
|
||||||
isRelatedToManagement.setUUID(UUID.fromString(relatedToUUID));
|
isRelatedToManagement.setUUID(UUID.fromString(relatedToUUID));
|
||||||
return isRelatedToManagement.delete();
|
return isRelatedToManagement.delete();
|
||||||
|
@ -271,7 +270,7 @@ public class ERManager {
|
||||||
CalledMethodProvider.instance.set(
|
CalledMethodProvider.instance.set(
|
||||||
HTTPMETHOD.POST.name() + " /" + ERPath.ER_PATH_PART +
|
HTTPMETHOD.POST.name() + " /" + ERPath.ER_PATH_PART +
|
||||||
"/" + ERPath.ADD_PATH_PART + "/" + ERPath.RESOURCE_PATH_PART + "/{" + ID_PATH_PARAM + "}");
|
"/" + ERPath.ADD_PATH_PART + "/" + ERPath.RESOURCE_PATH_PART + "/{" + ID_PATH_PARAM + "}");
|
||||||
logger.info("requested to add {} with UUID {} to current context {}", Resource.NAME, uuid,
|
logger.info("Requested to add {} with UUID {} to current context {}", Resource.NAME, uuid,
|
||||||
ContextUtility.getCurrentContext());
|
ContextUtility.getCurrentContext());
|
||||||
ResourceManagement resourceManagement = new ResourceManagement();
|
ResourceManagement resourceManagement = new ResourceManagement();
|
||||||
resourceManagement.setUUID(UUID.fromString(uuid));
|
resourceManagement.setUUID(UUID.fromString(uuid));
|
||||||
|
@ -289,7 +288,7 @@ public class ERManager {
|
||||||
CalledMethodProvider.instance.set(
|
CalledMethodProvider.instance.set(
|
||||||
HTTPMETHOD.POST.name() + " /" + ERPath.ER_PATH_PART +
|
HTTPMETHOD.POST.name() + " /" + ERPath.ER_PATH_PART +
|
||||||
"/" + ERPath.ADD_PATH_PART + "/" + ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}");
|
"/" + ERPath.ADD_PATH_PART + "/" + ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}");
|
||||||
logger.info("requested to add {} with UUID {} to current context {}", Facet.NAME, uuid,
|
logger.info("Requested to add {} with UUID {} to current context {}", Facet.NAME, uuid,
|
||||||
ContextUtility.getCurrentContext());
|
ContextUtility.getCurrentContext());
|
||||||
FacetManagement facetManagement = new FacetManagement();
|
FacetManagement facetManagement = new FacetManagement();
|
||||||
facetManagement.setUUID(UUID.fromString(uuid));
|
facetManagement.setUUID(UUID.fromString(uuid));
|
||||||
|
@ -307,7 +306,7 @@ public class ERManager {
|
||||||
CalledMethodProvider.instance.set(
|
CalledMethodProvider.instance.set(
|
||||||
HTTPMETHOD.POST.name() + " /" + ERPath.ER_PATH_PART +
|
HTTPMETHOD.POST.name() + " /" + ERPath.ER_PATH_PART +
|
||||||
"/" + ERPath.REMOVE_PATH_PART + "/" + ERPath.RESOURCE_PATH_PART + "/{" + ID_PATH_PARAM + "}");
|
"/" + ERPath.REMOVE_PATH_PART + "/" + ERPath.RESOURCE_PATH_PART + "/{" + ID_PATH_PARAM + "}");
|
||||||
logger.info("requested to remove {} with UUID {} from current context {}", Resource.NAME, uuid,
|
logger.info("Requested to remove {} with UUID {} from current context {}", Resource.NAME, uuid,
|
||||||
ContextUtility.getCurrentContext());
|
ContextUtility.getCurrentContext());
|
||||||
ResourceManagement resourceManagement = new ResourceManagement();
|
ResourceManagement resourceManagement = new ResourceManagement();
|
||||||
resourceManagement.setUUID(UUID.fromString(uuid));
|
resourceManagement.setUUID(UUID.fromString(uuid));
|
||||||
|
@ -325,7 +324,7 @@ public class ERManager {
|
||||||
CalledMethodProvider.instance.set(
|
CalledMethodProvider.instance.set(
|
||||||
HTTPMETHOD.POST.name() + " /" + ERPath.ER_PATH_PART +
|
HTTPMETHOD.POST.name() + " /" + ERPath.ER_PATH_PART +
|
||||||
"/" + ERPath.REMOVE_PATH_PART + "/" + ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}");
|
"/" + ERPath.REMOVE_PATH_PART + "/" + ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}");
|
||||||
logger.info("requested to remove {} with UUID {} from current context {}", Facet.NAME, uuid,
|
logger.info("Requested to remove {} with UUID {} from current context {}", Facet.NAME, uuid,
|
||||||
ContextUtility.getCurrentContext());
|
ContextUtility.getCurrentContext());
|
||||||
FacetManagement facetManagement = new FacetManagement();
|
FacetManagement facetManagement = new FacetManagement();
|
||||||
facetManagement.setUUID(UUID.fromString(uuid));
|
facetManagement.setUUID(UUID.fromString(uuid));
|
||||||
|
|
|
@ -0,0 +1,140 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.informationsystem.resourceregistry.rest;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import javax.ws.rs.DELETE;
|
||||||
|
import javax.ws.rs.DefaultValue;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.PUT;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
|
import org.gcube.informationsystem.model.entity.Context;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.ResourceInitializer;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextCreationException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.rest.ContextPath;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.context.OLDContextManagement;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.context.OLDContextManagementImpl;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
*/
|
||||||
|
@Path("OLD"+ContextPath.CONTEXT_PATH_PART)
|
||||||
|
public class OLDContextManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logger
|
||||||
|
*/
|
||||||
|
private static Logger logger = LoggerFactory
|
||||||
|
.getLogger(OLDContextManager.class);
|
||||||
|
|
||||||
|
public static final String ID_PATH_PARAM = "id";
|
||||||
|
|
||||||
|
protected OLDContextManagement contextManager = new OLDContextManagementImpl();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* e.g. PUT /resource-registry/context?name=myVRE&parentContextId=a2fe0030-7b3d-4617-ba37-532c0e4b778d
|
||||||
|
* @param parentUUID
|
||||||
|
* @param name
|
||||||
|
* @return
|
||||||
|
* @throws InternalException
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@PUT
|
||||||
|
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||||
|
public Response create(
|
||||||
|
@QueryParam(ContextPath.PARENT_CONTEXT_ID_PARAM) @DefaultValue("") String parentUUID,
|
||||||
|
@QueryParam(ContextPath.NAME_PARAM) String name)
|
||||||
|
throws ContextCreationException, ResourceRegistryException {
|
||||||
|
logger.info("Requested to create {} with name : {} ", Context.NAME, name);
|
||||||
|
UUID parent = null;
|
||||||
|
if(parentUUID!=null && parentUUID.compareTo("")!=0){
|
||||||
|
parent = UUID.fromString(parentUUID);
|
||||||
|
}
|
||||||
|
String ret = contextManager.create(parent, name);
|
||||||
|
return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* e.g. GET /resource-registry/context/c0f314e7-2807-4241-a792-2a6c79ed4fd0
|
||||||
|
* @param uuid
|
||||||
|
* @return
|
||||||
|
* @throws ContextException
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("{" + ID_PATH_PARAM + "}")
|
||||||
|
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||||
|
public String read(@PathParam(ID_PATH_PARAM) String uuid)
|
||||||
|
throws ContextNotFoundException, ContextException {
|
||||||
|
logger.info("Requested to read {} with id {} ", Context.NAME, uuid);
|
||||||
|
return contextManager.read(UUID.fromString(uuid));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* e.g. DELETE /resource-registry/context/c0f314e7-2807-4241-a792-2a6c79ed4fd0
|
||||||
|
* @param uuid
|
||||||
|
* @return
|
||||||
|
* @throws ContextException
|
||||||
|
*/
|
||||||
|
@DELETE
|
||||||
|
@Path("{" + ID_PATH_PARAM + "}")
|
||||||
|
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||||
|
public boolean delete(@PathParam(ID_PATH_PARAM) String uuid)
|
||||||
|
throws ContextNotFoundException, ContextException {
|
||||||
|
logger.info("Requested to delete {} with id {} ", Context.NAME, uuid);
|
||||||
|
return contextManager.delete(UUID.fromString(uuid));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* e.g. POST /resource-registry/context/rename/c0f314e7-2807-4241-a792-2a6c79ed4fd0?name=newNameVRE
|
||||||
|
* @param uuid
|
||||||
|
* @param name
|
||||||
|
* @return
|
||||||
|
* @throws ContextNotFoundException
|
||||||
|
* @throws ContextException
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path(ContextPath.RENAME_PATH_PART + "/{" + ID_PATH_PARAM + "}")
|
||||||
|
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||||
|
public String rename(@PathParam(ID_PATH_PARAM) String uuid,
|
||||||
|
@QueryParam(ContextPath.NAME_PARAM) String name)
|
||||||
|
throws ContextNotFoundException, ContextException {
|
||||||
|
logger.info("Requested to rename as {} {} with id {} ", name, Context.NAME, uuid);
|
||||||
|
return contextManager.rename(UUID.fromString(uuid), name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* e.g. POST /resource-registry/context/move/c0f314e7-2807-4241-a792-2a6c79ed4fd0?parentContextId=68cf247a-b1ed-44cd-9d2e-c16d865bade7
|
||||||
|
* @param uuid
|
||||||
|
* @param newParentUUID
|
||||||
|
* @return
|
||||||
|
* @throws ContextNotFoundException
|
||||||
|
* @throws ContextException
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path(ContextPath.MOVE_PATH_PART + "/{" + ID_PATH_PARAM + "}")
|
||||||
|
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||||
|
public String move(
|
||||||
|
@PathParam(ID_PATH_PARAM) String uuid,
|
||||||
|
@QueryParam(ContextPath.PARENT_CONTEXT_ID_PARAM) String newParentUUID)
|
||||||
|
throws ContextNotFoundException, ContextException {
|
||||||
|
logger.info("Requested to move {} with id {} as child of {} having id {} ",
|
||||||
|
Context.NAME, uuid, Context.NAME, newParentUUID);
|
||||||
|
return contextManager.move(UUID.fromString(newParentUUID),
|
||||||
|
UUID.fromString(uuid));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -32,14 +32,13 @@ import com.tinkerpop.blueprints.Element;
|
||||||
*/
|
*/
|
||||||
public class HeaderUtility {
|
public class HeaderUtility {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory
|
private static final Logger logger = LoggerFactory.getLogger(HeaderUtility.class);
|
||||||
.getLogger(HeaderUtility.class);
|
|
||||||
|
|
||||||
public static String getUser() {
|
public static String getUser() {
|
||||||
String user = org.gcube.informationsystem.model.embedded.Header.UNKNOWN_USER;
|
String user = org.gcube.informationsystem.model.embedded.Header.UNKNOWN_USER;
|
||||||
try {
|
try {
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
Caller caller = AuthorizationProvider.instance.get();
|
||||||
if(caller!=null){
|
if (caller != null) {
|
||||||
ClientInfo clientInfo = caller.getClient();
|
ClientInfo clientInfo = caller.getClient();
|
||||||
String clientId = clientInfo.getId();
|
String clientId = clientInfo.getId();
|
||||||
if (clientId != null && clientId.compareTo("") != 0) {
|
if (clientId != null && clientId.compareTo("") != 0) {
|
||||||
|
@ -68,7 +67,7 @@ public class HeaderUtility {
|
||||||
header.setModifiedBy(creator);
|
header.setModifiedBy(creator);
|
||||||
|
|
||||||
Date date = Calendar.getInstance().getTime();
|
Date date = Calendar.getInstance().getTime();
|
||||||
SimpleDateFormat ft = new SimpleDateFormat ("E yyyy.MM.dd 'at' hh:mm:ss a zzz");
|
SimpleDateFormat ft = new SimpleDateFormat("E yyyy.MM.dd 'at' hh:mm:ss a zzz");
|
||||||
logger.trace("Setting Last Update and Creation Time to " + ft.format(date));
|
logger.trace("Setting Last Update and Creation Time to " + ft.format(date));
|
||||||
|
|
||||||
header.setCreationTime(date);
|
header.setCreationTime(date);
|
||||||
|
@ -85,12 +84,12 @@ public class HeaderUtility {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
HeaderOrient header = null;
|
HeaderOrient header = null;
|
||||||
if(creation){
|
if (creation) {
|
||||||
// If an header is provided MUST contains and UUID otherwise is
|
// If an header is provided MUST contains and UUID otherwise is
|
||||||
// an invalid request so that let that an exception is raised
|
// an invalid request so that let that an exception is raised
|
||||||
UUID uuid = UUID.fromString(headerNode.get(Header.UUID_PROPERTY).asText());
|
UUID uuid = UUID.fromString(headerNode.get(Header.UUID_PROPERTY).asText());
|
||||||
header = (HeaderOrient) createHeader(uuid);
|
header = (HeaderOrient) createHeader(uuid);
|
||||||
}else{
|
} else {
|
||||||
header = new HeaderOrient();
|
header = new HeaderOrient();
|
||||||
header.fromJSON(headerNode.toString());
|
header.fromJSON(headerNode.toString());
|
||||||
}
|
}
|
||||||
|
@ -99,10 +98,10 @@ public class HeaderUtility {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HeaderOrient getHeaderOrient(ODocument oDocument) throws ResourceRegistryException{
|
public static HeaderOrient getHeaderOrient(ODocument oDocument) throws ResourceRegistryException {
|
||||||
if (oDocument instanceof HeaderOrient) {
|
if (oDocument instanceof HeaderOrient) {
|
||||||
return (HeaderOrient) oDocument;
|
return (HeaderOrient) oDocument;
|
||||||
}else{
|
} else {
|
||||||
try {
|
try {
|
||||||
HeaderOrient headerOrient = new HeaderOrient();
|
HeaderOrient headerOrient = new HeaderOrient();
|
||||||
Header header = ISMapper.unmarshal(Header.class, oDocument.toJSON());
|
Header header = ISMapper.unmarshal(Header.class, oDocument.toJSON());
|
||||||
|
@ -113,7 +112,8 @@ public class HeaderUtility {
|
||||||
headerOrient.setLastUpdateTime(header.getLastUpdateTime());
|
headerOrient.setLastUpdateTime(header.getLastUpdateTime());
|
||||||
return headerOrient;
|
return headerOrient;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ResourceRegistryException("Unable to recreate Header. This should not occur. Please contact Administrator.");
|
throw new ResourceRegistryException(
|
||||||
|
"Unable to recreate Header. " + Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,8 +130,7 @@ public class HeaderUtility {
|
||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Header getHeader(Element element)
|
public static Header getHeader(Element element) throws ResourceRegistryException {
|
||||||
throws ResourceRegistryException {
|
|
||||||
return Utility.getEmbedded(Header.class, element, Entity.HEADER_PROPERTY);
|
return Utility.getEmbedded(Header.class, element, Entity.HEADER_PROPERTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class Utility {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(Utility.class);
|
private static final Logger logger = LoggerFactory.getLogger(Utility.class);
|
||||||
|
|
||||||
public static final String SHOULD_NOT_OCCUR_ERROR_MESSAGE = "This is really strange and should not occur. Please contact the system administrator";
|
public static final String SHOULD_NOT_OCCUR_ERROR_MESSAGE = "This is really strange and should not occur. Please contact the system administrator.";
|
||||||
|
|
||||||
public static JSONObject toJsonObject(OrientElement element, boolean raw)
|
public static JSONObject toJsonObject(OrientElement element, boolean raw)
|
||||||
throws ResourceRegistryException {
|
throws ResourceRegistryException {
|
||||||
|
|
|
@ -27,10 +27,10 @@ public class ContextManagementImplTest {
|
||||||
private static Logger logger = LoggerFactory
|
private static Logger logger = LoggerFactory
|
||||||
.getLogger(ContextManagementImplTest.class);
|
.getLogger(ContextManagementImplTest.class);
|
||||||
|
|
||||||
protected ContextManagementImpl contextManagementImpl;
|
protected OLDContextManagementImpl contextManagementImpl;
|
||||||
|
|
||||||
public ContextManagementImplTest() {
|
public ContextManagementImplTest() {
|
||||||
contextManagementImpl = new ContextManagementImpl();
|
contextManagementImpl = new OLDContextManagementImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String CTX_NAME_A = "A";
|
public static final String CTX_NAME_A = "A";
|
||||||
|
@ -101,7 +101,7 @@ public class ContextManagementImplTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
public void simpleTest() throws Exception {
|
public void simpleTest() throws Exception {
|
||||||
String contextJsonA1 = contextManagementImpl.create(null, CTX_NAME_A);
|
String contextJsonA1 = contextManagementImpl.create(null, CTX_NAME_A);
|
||||||
Context createdContexA1 = ISMapper.unmarshal(Context.class,
|
Context createdContexA1 = ISMapper.unmarshal(Context.class,
|
||||||
|
@ -181,7 +181,7 @@ public class ContextManagementImplTest {
|
||||||
logger.debug("The DB should be now clean");
|
logger.debug("The DB should be now clean");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
public void createContext() throws Exception {
|
public void createContext() throws Exception {
|
||||||
String name = "test";
|
String name = "test";
|
||||||
|
|
||||||
|
@ -303,7 +303,7 @@ public class ContextManagementImplTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
public void readTest() throws Exception {
|
public void readTest() throws Exception {
|
||||||
String name = "LLL";
|
String name = "LLL";
|
||||||
String contextJson = contextManagementImpl.create(null, name);
|
String contextJson = contextManagementImpl.create(null, name);
|
||||||
|
@ -324,7 +324,7 @@ public class ContextManagementImplTest {
|
||||||
Assert.assertTrue(deleted);
|
Assert.assertTrue(deleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
public void completeTest() throws Exception {
|
public void completeTest() throws Exception {
|
||||||
String contextJsonA1 = contextManagementImpl.create(null, CTX_NAME_A);
|
String contextJsonA1 = contextManagementImpl.create(null, CTX_NAME_A);
|
||||||
Context createdContexA1 = ISMapper.unmarshal(Context.class,
|
Context createdContexA1 = ISMapper.unmarshal(Context.class,
|
||||||
|
@ -484,7 +484,7 @@ public class ContextManagementImplTest {
|
||||||
logger.debug("The DB should be now clean");
|
logger.debug("The DB should be now clean");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
public void moveToRootTest() throws Exception {
|
public void moveToRootTest() throws Exception {
|
||||||
String contextJsonA1 = contextManagementImpl.create(null, CTX_NAME_A);
|
String contextJsonA1 = contextManagementImpl.create(null, CTX_NAME_A);
|
||||||
Context createdContexA1 = ISMapper.unmarshal(Context.class,
|
Context createdContexA1 = ISMapper.unmarshal(Context.class,
|
||||||
|
|
|
@ -1,21 +1,29 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.context;
|
package org.gcube.informationsystem.resourceregistry.context;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.gcube.informationsystem.impl.embedded.HeaderImpl;
|
||||||
import org.gcube.informationsystem.impl.entity.ContextImpl;
|
import org.gcube.informationsystem.impl.entity.ContextImpl;
|
||||||
import org.gcube.informationsystem.impl.utils.ISMapper;
|
import org.gcube.informationsystem.impl.utils.ISMapper;
|
||||||
import org.gcube.informationsystem.model.entity.Context;
|
import org.gcube.informationsystem.model.entity.Context;
|
||||||
import org.gcube.informationsystem.model.relation.IsParentOf;
|
import org.gcube.informationsystem.model.relation.IsParentOf;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
|
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.er.entity.FacetManagementTest;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
|
||||||
public class ContextManagementTest {
|
public class ContextManagementTest {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory
|
private static Logger logger = LoggerFactory.getLogger(ContextManagementTest.class);
|
||||||
.getLogger(ContextManagementTest.class);
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void get() throws Exception {
|
public void get() throws Exception {
|
||||||
|
@ -34,21 +42,19 @@ public class ContextManagementTest {
|
||||||
|
|
||||||
logger.debug("Parent : {}", ISMapper.marshal(context.getParent().getSource()));
|
logger.debug("Parent : {}", ISMapper.marshal(context.getParent().getSource()));
|
||||||
|
|
||||||
for(IsParentOf<Context, Context> isParentOf : context.getChildren()){
|
for (IsParentOf<Context, Context> isParentOf : context.getChildren()) {
|
||||||
logger.debug("Children : {}", ISMapper.marshal(isParentOf.getTarget()));
|
logger.debug("Children : {}", ISMapper.marshal(isParentOf.getTarget()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Context parent = context.getParent().getSource();
|
Context parent = context.getParent().getSource();
|
||||||
Context sameOfContext = parent.getChildren().get(0).getTarget();
|
Context sameOfContext = parent.getChildren().get(0).getTarget();
|
||||||
Assert.assertTrue(context==sameOfContext);
|
Assert.assertTrue(context == sameOfContext);
|
||||||
|
|
||||||
|
|
||||||
List<IsParentOf<Context, Context>> children = context.getChildren();
|
List<IsParentOf<Context, Context>> children = context.getChildren();
|
||||||
for(IsParentOf<Context, Context> child : children) {
|
for (IsParentOf<Context, Context> child : children) {
|
||||||
Assert.assertTrue(child.getSource()==context);
|
Assert.assertTrue(child.getSource() == context);
|
||||||
Context childContext = child.getTarget();
|
Context childContext = child.getTarget();
|
||||||
Assert.assertTrue(childContext.getParent().getSource()==context);
|
Assert.assertTrue(childContext.getParent().getSource() == context);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -68,7 +74,6 @@ public class ContextManagementTest {
|
||||||
contextManagement.create();
|
contextManagement.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJava() throws Exception {
|
public void testJava() throws Exception {
|
||||||
Context gcube = new ContextImpl("gcube");
|
Context gcube = new ContextImpl("gcube");
|
||||||
|
@ -90,7 +95,6 @@ public class ContextManagementTest {
|
||||||
devNext.addChild(NextNext);
|
devNext.addChild(NextNext);
|
||||||
logger.debug("NextNext : {}", ISMapper.marshal(NextNext));
|
logger.debug("NextNext : {}", ISMapper.marshal(NextNext));
|
||||||
|
|
||||||
|
|
||||||
logger.debug("------------------------------------");
|
logger.debug("------------------------------------");
|
||||||
|
|
||||||
logger.debug("gcube : {}", ISMapper.marshal(gcube));
|
logger.debug("gcube : {}", ISMapper.marshal(gcube));
|
||||||
|
@ -100,4 +104,310 @@ public class ContextManagementTest {
|
||||||
logger.debug("NextNext : {}", ISMapper.marshal(NextNext));
|
logger.debug("NextNext : {}", ISMapper.marshal(NextNext));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final String CTX_NAME_A = "A";
|
||||||
|
public static final String CTX_NAME_B = "B";
|
||||||
|
public static final String CTX_NAME_C = "C";
|
||||||
|
|
||||||
|
protected void assertions(Context pre, Context post, boolean checkParent, boolean create) {
|
||||||
|
if (checkParent) {
|
||||||
|
if (pre.getHeader() != null) {
|
||||||
|
FacetManagementTest.checkHeader(post, pre.getHeader().getUUID(), create);
|
||||||
|
} else {
|
||||||
|
FacetManagementTest.checkHeader(post, null, create);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.assertTrue(pre.getName().compareTo(post.getName()) == 0);
|
||||||
|
if (checkParent && pre.getParent()!=null && post.getParent()!=null) {
|
||||||
|
Context preParent = pre.getParent().getSource();
|
||||||
|
Context postParent = post.getParent().getSource();
|
||||||
|
assertions(preParent, postParent, false, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Context read(UUID uuid) throws ResourceRegistryException, IOException {
|
||||||
|
ContextManagement contextManagement = new ContextManagement();
|
||||||
|
contextManagement.setUUID(uuid);
|
||||||
|
String contextString = contextManagement.read();
|
||||||
|
logger.debug("Read {}", contextString);
|
||||||
|
return ISMapper.unmarshal(Context.class, contextString);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Context create(Context context) throws ResourceRegistryException, IOException {
|
||||||
|
ContextManagement contextManagement = new ContextManagement();
|
||||||
|
contextManagement.setJSON(ISMapper.marshal(context));
|
||||||
|
String contextString = contextManagement.create();
|
||||||
|
logger.debug("Created {}", contextString);
|
||||||
|
Context c = ISMapper.unmarshal(Context.class, contextString);
|
||||||
|
assertions(context, c, true, true);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Context update(Context context) throws ResourceRegistryException, IOException {
|
||||||
|
ContextManagement contextManagement = new ContextManagement();
|
||||||
|
contextManagement.setJSON(ISMapper.marshal(context));
|
||||||
|
String contextString = contextManagement.update();
|
||||||
|
logger.debug("Updated {}", contextString);
|
||||||
|
Context c = ISMapper.unmarshal(Context.class, contextString);
|
||||||
|
assertions(context, c, true, false);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean delete(UUID uuid) throws ResourceRegistryException {
|
||||||
|
ContextManagement contextManagement = new ContextManagement();
|
||||||
|
contextManagement.setUUID(uuid);
|
||||||
|
boolean deleted = contextManagement.delete();
|
||||||
|
Assert.assertTrue(deleted);
|
||||||
|
logger.debug("Deleted {} with UUID {}", Context.NAME, uuid);
|
||||||
|
return deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean delete(Context context) throws ResourceRegistryException {
|
||||||
|
return delete(context.getHeader().getUUID());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void invalidCreate(Context context) throws ResourceRegistryException, IOException {
|
||||||
|
try {
|
||||||
|
Context c = create(context);
|
||||||
|
throw new RuntimeException(ISMapper.marshal(c) + " was created successfully. This is not what we expected");
|
||||||
|
} catch (ContextAlreadyPresentException e) {
|
||||||
|
logger.debug("As expected {} cannot be created.", ISMapper.marshal(context));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void invalidUpdate(Context context) throws ResourceRegistryException, IOException {
|
||||||
|
try {
|
||||||
|
Context c = update(context);
|
||||||
|
throw new RuntimeException(ISMapper.marshal(c) + " was updated successfully. This is not what we expected");
|
||||||
|
} catch (ContextAlreadyPresentException e) {
|
||||||
|
logger.debug("As expected {} cannot be updated.", ISMapper.marshal(context));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void invalidDelete(Context context) throws ResourceRegistryException, JsonProcessingException {
|
||||||
|
String contextString = ISMapper.marshal(context);
|
||||||
|
try {
|
||||||
|
delete(context);
|
||||||
|
throw new RuntimeException(contextString + " was deleted successfully. This is not what we expected");
|
||||||
|
} catch (ContextException e) {
|
||||||
|
logger.debug("As expected {} cannot be deleted.", contextString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void completeTest() throws Exception {
|
||||||
|
Context contextA1 = new ContextImpl(CTX_NAME_A);
|
||||||
|
contextA1 = create(contextA1);
|
||||||
|
// ________A1________
|
||||||
|
|
||||||
|
Context contextA2 = new ContextImpl(CTX_NAME_A);
|
||||||
|
contextA2.setParent(contextA1);
|
||||||
|
contextA2 = create(contextA2);
|
||||||
|
// ________A1________
|
||||||
|
// ___A2
|
||||||
|
|
||||||
|
Context contextB3 = new ContextImpl(CTX_NAME_B);
|
||||||
|
contextB3.setParent(contextA2);
|
||||||
|
contextB3 = create(contextB3);
|
||||||
|
// ________A1________
|
||||||
|
// ___A2
|
||||||
|
// B3
|
||||||
|
|
||||||
|
Context contextB4 = new ContextImpl(CTX_NAME_B);
|
||||||
|
contextB4.setParent(contextA1);
|
||||||
|
contextB4 = create(contextB4);
|
||||||
|
// ________A1________
|
||||||
|
// ___A2_______B4____
|
||||||
|
// B3
|
||||||
|
|
||||||
|
Context contextA5 = new ContextImpl(CTX_NAME_A);
|
||||||
|
contextA5.setParent(contextB4);
|
||||||
|
contextA5 = create(contextA5);
|
||||||
|
// ________A1________
|
||||||
|
// ___A2_______B4____
|
||||||
|
// B3______________A5
|
||||||
|
|
||||||
|
invalidCreate(contextA1); // Trying to recreate A1. Fails
|
||||||
|
invalidCreate(contextA2); // Trying to recreate A2. Fails
|
||||||
|
invalidCreate(contextB3); // Trying to recreate B3. Fails
|
||||||
|
invalidCreate(contextB4); // Trying to recreate B4. Fails
|
||||||
|
invalidCreate(contextA5); // Trying to recreate A5. Fails
|
||||||
|
|
||||||
|
// Trying to move A5 as child of A1. It fails due to A2.
|
||||||
|
Context nullContext = null;
|
||||||
|
contextA5.setParent(nullContext);
|
||||||
|
invalidUpdate(contextA5);
|
||||||
|
contextA5.setParent(contextB4);
|
||||||
|
// ________A1________
|
||||||
|
// ___A2_______B4____
|
||||||
|
// B3______________A5
|
||||||
|
|
||||||
|
|
||||||
|
nullContext = null;
|
||||||
|
contextB4.setParent(nullContext);
|
||||||
|
update(contextB4);
|
||||||
|
// _____A1____B4_____
|
||||||
|
// __A2__________A5__
|
||||||
|
// B3
|
||||||
|
|
||||||
|
|
||||||
|
contextB4.setParent(contextA1);
|
||||||
|
update(contextB4);
|
||||||
|
// ________A1________
|
||||||
|
// ___A2_______B4____
|
||||||
|
// B3______________A5
|
||||||
|
|
||||||
|
|
||||||
|
// Trying to rename with the new name A. It fails due to A5.
|
||||||
|
contextB3.setName(CTX_NAME_A);
|
||||||
|
update(contextB3);
|
||||||
|
// ________A1________
|
||||||
|
// ___A2_______B4____
|
||||||
|
// A3______________A5
|
||||||
|
|
||||||
|
// After Restoring name B, trying to move B3 as child of A1. It fails due to B4.
|
||||||
|
contextB3.setName(CTX_NAME_B);
|
||||||
|
contextB3.setParent(contextA1);
|
||||||
|
invalidUpdate(contextB3);
|
||||||
|
// ________A1________
|
||||||
|
// ___A2_______B4____
|
||||||
|
// A3______________A5
|
||||||
|
|
||||||
|
// Restoring A3 (was B3) as B3 and with parent A2.OK.
|
||||||
|
contextB3.setName(CTX_NAME_B);
|
||||||
|
contextB3.setParent(contextA2);
|
||||||
|
update(contextB3);
|
||||||
|
// ________A1________
|
||||||
|
// ___A2_______B4____
|
||||||
|
// B3______________A5
|
||||||
|
|
||||||
|
// This update should not has eny effects except updating the lastUpdateTime.
|
||||||
|
contextB3.setName(CTX_NAME_B);
|
||||||
|
contextB3.setParent(contextA2);
|
||||||
|
update(contextB3);
|
||||||
|
|
||||||
|
// Trying to move A5 as child of A1. It fails due to A2.
|
||||||
|
contextA5.setParent(contextA1);
|
||||||
|
invalidUpdate(contextA5);
|
||||||
|
// Restoring A5
|
||||||
|
contextA5.setParent(contextB4);
|
||||||
|
// ________A1________
|
||||||
|
// ___A2_______B4____
|
||||||
|
// B3______________A5
|
||||||
|
|
||||||
|
// Moving B3 as child of B4. OK.
|
||||||
|
contextB3.setParent(contextB4);
|
||||||
|
update(contextB3);
|
||||||
|
// ________A1________
|
||||||
|
// ___A2_______B4____
|
||||||
|
// ________B3______A5
|
||||||
|
|
||||||
|
// Restoring the initial situation by moving B3 as child of A2. OK.
|
||||||
|
contextB3.setParent(contextA2);
|
||||||
|
update(contextB3);
|
||||||
|
// ________A1________
|
||||||
|
// ___A2_______B4____
|
||||||
|
// B3______________A5
|
||||||
|
|
||||||
|
// Renaming B3 as C3. OK.
|
||||||
|
contextB3.setName(CTX_NAME_C);
|
||||||
|
update(contextB3);
|
||||||
|
// ________A1________
|
||||||
|
// ___A2_______B4____
|
||||||
|
// C3______________A5
|
||||||
|
|
||||||
|
// Moving C3 (was B3) as child of A1. Now it is possible. OK.
|
||||||
|
contextB3.setParent(contextA1);
|
||||||
|
update(contextB3);
|
||||||
|
// ________A1________
|
||||||
|
// ___A2___C3___B4___
|
||||||
|
// ________________A5
|
||||||
|
|
||||||
|
// Trying to rename C3 (was B3) newly to B3. Fails due to B4.
|
||||||
|
contextB3.setName(CTX_NAME_B);
|
||||||
|
invalidUpdate(contextB3);
|
||||||
|
// ________A1________
|
||||||
|
// ___A2___C3___B4___
|
||||||
|
// ________________A5
|
||||||
|
|
||||||
|
// Moving back C3 (was B3) as child of A2. OK.
|
||||||
|
contextB3.setParent(contextA2);
|
||||||
|
update(contextB3);
|
||||||
|
// ________A1________
|
||||||
|
// ___A2_______B4____
|
||||||
|
// C3______________A5
|
||||||
|
|
||||||
|
// Renaming C3 (was B3) to B3. OK.
|
||||||
|
contextB3.setName(CTX_NAME_B);
|
||||||
|
update(contextB3);
|
||||||
|
// ________A1________
|
||||||
|
// ___A2_______B4____
|
||||||
|
// B3______________A5
|
||||||
|
|
||||||
|
// The following delete are not allowed because they are not child contexts
|
||||||
|
invalidDelete(contextA1);
|
||||||
|
invalidDelete(contextA2);
|
||||||
|
invalidDelete(contextB4);
|
||||||
|
|
||||||
|
delete(contextA5);
|
||||||
|
// ________A1________
|
||||||
|
// ___A2_______B4____
|
||||||
|
// B3
|
||||||
|
|
||||||
|
try {
|
||||||
|
delete(contextA5);
|
||||||
|
} catch (ContextNotFoundException e) {
|
||||||
|
logger.debug("The context with uuid {} was not found. (Was already deleted)",
|
||||||
|
contextA5.getHeader().getUUID());
|
||||||
|
}
|
||||||
|
|
||||||
|
delete(contextB3);
|
||||||
|
// ________A1________
|
||||||
|
// ___A2_______B4____
|
||||||
|
|
||||||
|
delete(contextB4);
|
||||||
|
// ________A1________
|
||||||
|
// ___A2
|
||||||
|
|
||||||
|
delete(contextA2);
|
||||||
|
// ________A1________
|
||||||
|
|
||||||
|
Context contextC = new ContextImpl(CTX_NAME_C);
|
||||||
|
contextC.setHeader(new HeaderImpl(contextA1.getHeader().getUUID()));
|
||||||
|
invalidCreate(contextC);
|
||||||
|
|
||||||
|
delete(contextA1);
|
||||||
|
logger.debug("The DB should be now clean");
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Test
|
||||||
|
public void createDevContext() throws Exception {
|
||||||
|
Context gcube = new ContextImpl("gcube");
|
||||||
|
gcube = create(gcube);
|
||||||
|
|
||||||
|
Context devsec = new ContextImpl("devsec");
|
||||||
|
devsec.setParent(gcube);
|
||||||
|
devsec = create(devsec);
|
||||||
|
|
||||||
|
Context devVRE = new ContextImpl("devVRE");
|
||||||
|
devVRE.setParent(devsec);
|
||||||
|
devVRE = create(devVRE);
|
||||||
|
|
||||||
|
Context devNext = new ContextImpl("devNext");
|
||||||
|
devNext.setParent(gcube);
|
||||||
|
devNext = create(devNext);
|
||||||
|
|
||||||
|
Context nextNext = new ContextImpl("NextNext");
|
||||||
|
nextNext.setParent(devNext);
|
||||||
|
nextNext = create(nextNext);
|
||||||
|
|
||||||
|
Context preprod = new ContextImpl("preprod");
|
||||||
|
preprod.setParent(gcube);
|
||||||
|
preprod = create(preprod);
|
||||||
|
|
||||||
|
Context preVRE = new ContextImpl("preVRE");
|
||||||
|
preVRE.setParent(preprod);
|
||||||
|
preVRE = create(preVRE);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue