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;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.codehaus.jettison.json.JSONException;
|
||||
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.er.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.er.entity.EntityManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.Utility;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.NullNode;
|
||||
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
|
||||
import com.tinkerpop.blueprints.Direction;
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
|
@ -33,6 +35,8 @@ public class ContextManagement extends EntityManagement<Context> {
|
|||
|
||||
private static Logger logger = LoggerFactory.getLogger(ContextManagement.class);
|
||||
|
||||
protected String name;
|
||||
|
||||
private void init() {
|
||||
forceAdmin = true;
|
||||
|
||||
|
@ -51,7 +55,16 @@ public class ContextManagement extends EntityManagement<Context> {
|
|||
}
|
||||
|
||||
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
|
||||
|
@ -69,7 +82,7 @@ public class ContextManagement extends EntityManagement<Context> {
|
|||
return new ContextAlreadyPresentException(message);
|
||||
}
|
||||
|
||||
protected void checkContext(ContextManagement parentContext, ContextManagement childContext) throws ContextNotFoundException,
|
||||
protected void checkContext(ContextManagement parentContext) throws ContextNotFoundException,
|
||||
ContextAlreadyPresentException, ResourceRegistryException {
|
||||
|
||||
if (parentContext != null) {
|
||||
|
@ -78,15 +91,15 @@ public class ContextManagement extends EntityManagement<Context> {
|
|||
// TODO Rewrite using Gremlin
|
||||
String select = "SELECT FROM (TRAVERSE out(" + IsParentOf.NAME
|
||||
+ ") FROM " + parentId + " MAXDEPTH 1) WHERE "
|
||||
+ Context.NAME_PROPERTY + "=\"" + childContext.getName() + "\" AND "
|
||||
+ Context.NAME_PROPERTY + "=\"" + getName() + "\" AND "
|
||||
+ Context.HEADER_PROPERTY + "." + Header.UUID_PROPERTY
|
||||
+ "<>\"" + parentContext.toString() + "\"";
|
||||
+ "<>\"" + parentContext.uuid + "\"";
|
||||
|
||||
logger.trace(select);
|
||||
|
||||
StringWriter message = new StringWriter();
|
||||
message.append("A context with the same name (");
|
||||
message.append(childContext.getName());
|
||||
StringBuilder message = new StringBuilder();
|
||||
message.append("A context with name (");
|
||||
message.append(getName());
|
||||
message.append(") has been already created as child of ");
|
||||
message.append(parentContext.serializeSelfOnly().toString());
|
||||
|
||||
|
@ -105,7 +118,7 @@ public class ContextManagement extends EntityManagement<Context> {
|
|||
// TODO Rewrite using Gremlin
|
||||
String select = "SELECT FROM "
|
||||
+ org.gcube.informationsystem.model.entity.Context.NAME
|
||||
+ " WHERE " + Context.NAME_PROPERTY + " = \"" + childContext.getName()
|
||||
+ " WHERE " + Context.NAME_PROPERTY + " = \"" + getName()
|
||||
+ "\"" + " AND in(\"" + IsParentOf.NAME + "\").size() = 0";
|
||||
|
||||
OSQLSynchQuery<Vertex> osqlSynchQuery = new OSQLSynchQuery<Vertex>(
|
||||
|
@ -115,7 +128,7 @@ public class ContextManagement extends EntityManagement<Context> {
|
|||
|
||||
if (vertexes != null && vertexes.iterator().hasNext()) {
|
||||
throw new ContextAlreadyPresentException(
|
||||
"A root context with the same name (" + childContext.getName()
|
||||
"A root context with the same name (" + this.getName()
|
||||
+ ") already exist");
|
||||
}
|
||||
|
||||
|
@ -146,7 +159,7 @@ public class ContextManagement extends EntityManagement<Context> {
|
|||
JSONObject isParentOf = isParentOfManagement.serializeAsJson(true,false);
|
||||
context.putOpt(Context.PARENT_PROPERTY, isParentOf);
|
||||
} 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("");
|
||||
}
|
||||
}
|
||||
|
@ -161,10 +174,10 @@ public class ContextManagement extends EntityManagement<Context> {
|
|||
JSONObject isParentOf = isParentOfManagement.serializeAsJson();
|
||||
context = addRelation(context, isParentOf, Context.CHILDREN_PROPERTY);
|
||||
}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;
|
||||
}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);
|
||||
}
|
||||
}
|
||||
|
@ -174,41 +187,141 @@ public class ContextManagement extends EntityManagement<Context> {
|
|||
|
||||
@Override
|
||||
protected Vertex reallyCreate() throws ERAlreadyPresentException, ResourceRegistryException {
|
||||
JsonNode isParentOfJsonNode = jsonNode.get(Context.PARENT_PROPERTY);
|
||||
|
||||
|
||||
|
||||
createVertex();
|
||||
|
||||
String propertyName = Context.PARENT_PROPERTY;
|
||||
if (jsonNode.has(propertyName)) {
|
||||
JsonNode isParentOfJsonNode = jsonNode.get(propertyName);
|
||||
if (isParentOfJsonNode!=null && !(isParentOfJsonNode instanceof NullNode)) {
|
||||
|
||||
JsonNode parentJsonNode = isParentOfJsonNode.get(Relation.SOURCE_PROPERTY);
|
||||
ContextManagement contextManagement = new ContextManagement(orientGraph);
|
||||
contextManagement.setJSON(parentJsonNode);
|
||||
ContextManagement parentContext = new ContextManagement(orientGraph);
|
||||
parentContext.setJSON(parentJsonNode);
|
||||
|
||||
checkContext(parentContext);
|
||||
createVertex();
|
||||
|
||||
IsParentOfManagement isParentOfManagement = new IsParentOfManagement(orientGraph);
|
||||
isParentOfManagement.setJSON(isParentOfJsonNode);
|
||||
isParentOfManagement.setSourceEntityManagement(contextManagement);
|
||||
isParentOfManagement.setSourceEntityManagement(parentContext);
|
||||
isParentOfManagement.setTargetEntityManagement(this);
|
||||
|
||||
isParentOfManagement.internalCreate();
|
||||
|
||||
}else {
|
||||
checkContext(null);
|
||||
createVertex();
|
||||
}
|
||||
|
||||
return element;
|
||||
return getElement();
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
context = (Vertex) ERManagement.updateProperties(oClass, context, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||
Iterable<Vertex> iterable = getElement().getVertices(Direction.IN, IsParentOf.NAME);
|
||||
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
|
||||
|
|
|
@ -5,6 +5,9 @@ package org.gcube.informationsystem.resourceregistry.context;
|
|||
|
||||
import org.codehaus.jettison.json.JSONObject;
|
||||
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.Relation;
|
||||
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.IsParentOfNotFoundException;
|
||||
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.Vertex;
|
||||
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
|
||||
|
@ -32,7 +37,48 @@ public class IsParentOfManagement extends RelationManagement<IsParentOf, Context
|
|||
public IsParentOfManagement(OrientGraph 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
|
||||
protected IsParentOfNotFoundException getSpecificElementNotFoundException(ERNotFoundException e) {
|
||||
return new IsParentOfNotFoundException(e.getMessage(), e.getCause());
|
||||
|
@ -73,10 +119,10 @@ public class IsParentOfManagement extends RelationManagement<IsParentOf, Context
|
|||
}
|
||||
|
||||
} 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;
|
||||
} 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,14 +30,12 @@ import com.tinkerpop.blueprints.impls.orient.OrientVertex;
|
|||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class ContextManagementImpl implements OLDContextManagement {
|
||||
public class OLDContextManagementImpl implements OLDContextManagement {
|
||||
|
||||
private static Logger logger = LoggerFactory
|
||||
.getLogger(ContextManagementImpl.class);
|
||||
private static Logger logger = LoggerFactory.getLogger(OLDContextManagementImpl.class);
|
||||
|
||||
protected Vertex checkContext(OrientGraph orientGraph, UUID parentContext,
|
||||
String contextName) throws ContextNotFoundException,
|
||||
ContextException {
|
||||
protected Vertex checkContext(OrientGraph orientGraph, UUID parentContext, String contextName)
|
||||
throws ContextNotFoundException, ContextException {
|
||||
|
||||
Vertex parent = null;
|
||||
|
||||
|
@ -46,26 +44,19 @@ public class ContextManagementImpl implements OLDContextManagement {
|
|||
parent = getContext(orientGraph, parentContext);
|
||||
|
||||
// TODO Rewrite using Gremlin
|
||||
String select = "SELECT FROM (TRAVERSE out(" + IsParentOf.NAME
|
||||
+ ") FROM " + parent.getId() + " MAXDEPTH 1) WHERE "
|
||||
+ Context.NAME_PROPERTY + "=\"" + contextName + "\" AND "
|
||||
+ Context.HEADER_PROPERTY + "." + Header.UUID_PROPERTY
|
||||
+ "<>\"" + parentContext.toString() + "\"";
|
||||
String select = "SELECT FROM (TRAVERSE out(" + IsParentOf.NAME + ") FROM " + parent.getId()
|
||||
+ " MAXDEPTH 1) WHERE " + Context.NAME_PROPERTY + "=\"" + contextName + "\" AND "
|
||||
+ Context.HEADER_PROPERTY + "." + Header.UUID_PROPERTY + "<>\"" + parentContext.toString() + "\"";
|
||||
|
||||
logger.trace(select);
|
||||
|
||||
String message = "A context with the same name (" + contextName
|
||||
+ ") has been already created as child of "
|
||||
+ parentContext.toString() + "(name="
|
||||
+ parent.getProperty(Context.NAME_PROPERTY).toString()
|
||||
+ ")";
|
||||
String message = "A context with the same name (" + contextName + ") has been already created as child of "
|
||||
+ parentContext.toString() + "(name=" + parent.getProperty(Context.NAME_PROPERTY).toString() + ")";
|
||||
|
||||
logger.trace("Checking if {} -> {}", message, select);
|
||||
|
||||
OSQLSynchQuery<Vertex> osqlSynchQuery = new OSQLSynchQuery<Vertex>(
|
||||
select);
|
||||
Iterable<Vertex> vertexes = orientGraph.command(osqlSynchQuery)
|
||||
.execute();
|
||||
OSQLSynchQuery<Vertex> osqlSynchQuery = new OSQLSynchQuery<Vertex>(select);
|
||||
Iterable<Vertex> vertexes = orientGraph.command(osqlSynchQuery).execute();
|
||||
|
||||
if (vertexes != null && vertexes.iterator().hasNext()) {
|
||||
throw new ContextException(message);
|
||||
|
@ -73,20 +64,15 @@ public class ContextManagementImpl implements OLDContextManagement {
|
|||
|
||||
} else {
|
||||
// TODO Rewrite using Gremlin
|
||||
String select = "SELECT FROM "
|
||||
+ org.gcube.informationsystem.model.entity.Context.NAME
|
||||
+ " WHERE " + Context.NAME_PROPERTY + " = \"" + contextName
|
||||
+ "\"" + " AND in(\"" + IsParentOf.NAME + "\").size() = 0";
|
||||
String select = "SELECT FROM " + org.gcube.informationsystem.model.entity.Context.NAME + " WHERE "
|
||||
+ Context.NAME_PROPERTY + " = \"" + contextName + "\"" + " AND in(\"" + IsParentOf.NAME
|
||||
+ "\").size() = 0";
|
||||
|
||||
OSQLSynchQuery<Vertex> osqlSynchQuery = new OSQLSynchQuery<Vertex>(
|
||||
select);
|
||||
Iterable<Vertex> vertexes = orientGraph.command(osqlSynchQuery)
|
||||
.execute();
|
||||
OSQLSynchQuery<Vertex> osqlSynchQuery = new OSQLSynchQuery<Vertex>(select);
|
||||
Iterable<Vertex> vertexes = orientGraph.command(osqlSynchQuery).execute();
|
||||
|
||||
if (vertexes != null && vertexes.iterator().hasNext()) {
|
||||
throw new ContextException(
|
||||
"A root context with the same name (" + contextName
|
||||
+ ") already exist");
|
||||
throw new ContextException("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)
|
||||
throws ContextNotFoundException {
|
||||
public Vertex getContext(OrientGraph orientGraph, UUID context) throws ContextNotFoundException {
|
||||
try {
|
||||
return Utility.getElementByUUID(orientGraph, Context.NAME, context, Vertex.class);
|
||||
} catch (ResourceRegistryException e) {
|
||||
|
@ -105,20 +90,17 @@ public class ContextManagementImpl implements OLDContextManagement {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String create(UUID parentContext, String name)
|
||||
throws ContextCreationException, ResourceRegistryException {
|
||||
public String create(UUID parentContext, String name) throws ContextCreationException, ResourceRegistryException {
|
||||
|
||||
OrientGraph orientGraph = null;
|
||||
UUID uuid = UUID.randomUUID();
|
||||
|
||||
try {
|
||||
logger.info(
|
||||
"Trying to create {} with name {} and parent {} UUID {}",
|
||||
Context.NAME, name, Context.NAME, parentContext);
|
||||
logger.info("Trying to create {} with name {} and parent {} UUID {}", Context.NAME, name, Context.NAME,
|
||||
parentContext);
|
||||
|
||||
orientGraph = SecurityContextMapper.getSecurityContextGraph(
|
||||
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
|
||||
PermissionMode.WRITER);
|
||||
orientGraph = SecurityContextMapper
|
||||
.getSecurityContextGraph(SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID, PermissionMode.WRITER);
|
||||
|
||||
Vertex parent;
|
||||
try {
|
||||
|
@ -129,29 +111,26 @@ public class ContextManagementImpl implements OLDContextManagement {
|
|||
|
||||
SecurityContext.createSecurityContext(orientGraph, uuid);
|
||||
|
||||
OrientVertex context = orientGraph.addVertex("class:"
|
||||
+ Context.NAME);
|
||||
OrientVertex context = orientGraph.addVertex("class:" + Context.NAME);
|
||||
context.setProperty(Context.NAME_PROPERTY, name);
|
||||
context.save();
|
||||
|
||||
HeaderUtility.addHeader(context, uuid);
|
||||
|
||||
if (parentContext != null) {
|
||||
OrientEdge edge = orientGraph.addEdge(null, parent, context,
|
||||
IsParentOf.NAME);
|
||||
OrientEdge edge = orientGraph.addEdge(null, parent, context, IsParentOf.NAME);
|
||||
HeaderUtility.addHeader(edge, null);
|
||||
edge.save();
|
||||
}
|
||||
|
||||
SecurityContext.addToSecurityContext(orientGraph, context, uuid);
|
||||
|
||||
|
||||
logger.trace("Creating {}", Utility.toJsonString(context, true));
|
||||
|
||||
orientGraph.commit();
|
||||
|
||||
Vertex readContext = getContext(orientGraph, uuid);
|
||||
logger.info("Context created {}",
|
||||
Utility.toJsonString((OrientVertex) readContext, true));
|
||||
logger.info("Context created {}", Utility.toJsonString((OrientVertex) readContext, true));
|
||||
return Utility.toJsonString((OrientVertex) readContext, false);
|
||||
|
||||
} catch (ContextCreationException e) {
|
||||
|
@ -171,54 +150,48 @@ public class ContextManagementImpl implements OLDContextManagement {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String read(UUID contextUUID) throws ContextNotFoundException,
|
||||
ContextException {
|
||||
OrientGraph orientGraph = SecurityContextMapper.getSecurityContextGraph(
|
||||
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
|
||||
PermissionMode.READER);
|
||||
public String read(UUID contextUUID) throws ContextNotFoundException, ContextException {
|
||||
OrientGraph orientGraph = SecurityContextMapper
|
||||
.getSecurityContextGraph(SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID, PermissionMode.READER);
|
||||
Vertex context = getContext(orientGraph, contextUUID);
|
||||
return Utility.toJsonString((OrientVertex) context, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String rename(UUID contextUUID, String newName)
|
||||
throws ContextNotFoundException, ContextException {
|
||||
public String rename(UUID contextUUID, String newName) throws ContextNotFoundException, ContextException {
|
||||
|
||||
OrientGraph orientGraph = null;
|
||||
|
||||
try {
|
||||
logger.info("Trying to rename {} with UUID {} to {}", Context.NAME,
|
||||
contextUUID, newName);
|
||||
logger.info("Trying to rename {} with UUID {} to {}", Context.NAME, contextUUID, newName);
|
||||
|
||||
orientGraph = SecurityContextMapper.getSecurityContextGraph(
|
||||
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
|
||||
PermissionMode.WRITER);
|
||||
orientGraph = SecurityContextMapper
|
||||
.getSecurityContextGraph(SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID, PermissionMode.WRITER);
|
||||
|
||||
Vertex context = getContext(orientGraph, contextUUID);
|
||||
|
||||
UUID parentUUID = null;
|
||||
|
||||
Iterable<Edge> edges = context.getEdges(Direction.IN,
|
||||
IsParentOf.NAME);
|
||||
Iterable<Edge> edges = context.getEdges(Direction.IN, IsParentOf.NAME);
|
||||
if (edges != null && edges.iterator().hasNext()) {
|
||||
Iterator<Edge> iteratorEdge = edges.iterator();
|
||||
Edge edge = iteratorEdge.next();
|
||||
|
||||
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);
|
||||
parentUUID = UUID.fromString((String) parent
|
||||
.getProperty(Context.HEADER_PROPERTY + "."
|
||||
+ Header.UUID_PROPERTY));
|
||||
parentUUID = UUID
|
||||
.fromString((String) parent.getProperty(Context.HEADER_PROPERTY + "." + Header.UUID_PROPERTY));
|
||||
}
|
||||
|
||||
checkContext(orientGraph, parentUUID, newName);
|
||||
context.setProperty(Context.NAME_PROPERTY, newName);
|
||||
|
||||
orientGraph.commit();
|
||||
|
||||
|
||||
ContextUtility.invalidContextUUIDCache(contextUUID);
|
||||
|
||||
String contextJsonString = Utility.toJsonString(context, true);
|
||||
|
@ -243,29 +216,23 @@ public class ContextManagementImpl implements OLDContextManagement {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String move(UUID newParentUUID, UUID contextToMoveUUID)
|
||||
throws ContextNotFoundException, ContextException {
|
||||
public String move(UUID newParentUUID, UUID contextToMoveUUID) throws ContextNotFoundException, ContextException {
|
||||
|
||||
OrientGraph orientGraph = null;
|
||||
try {
|
||||
logger.info(
|
||||
"Trying to move {} with UUID {} as child of {} with UUID {}",
|
||||
Context.NAME, contextToMoveUUID, Context.NAME, newParentUUID);
|
||||
logger.info("Trying to move {} with UUID {} as child of {} with UUID {}", Context.NAME, contextToMoveUUID,
|
||||
Context.NAME, newParentUUID);
|
||||
|
||||
orientGraph = SecurityContextMapper.getSecurityContextGraph(
|
||||
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
|
||||
PermissionMode.WRITER);
|
||||
orientGraph = SecurityContextMapper
|
||||
.getSecurityContextGraph(SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID, PermissionMode.WRITER);
|
||||
Vertex context = getContext(orientGraph, contextToMoveUUID);
|
||||
|
||||
logger.trace("Context to move {}",
|
||||
Utility.toJsonString(context, true));
|
||||
logger.trace("Context to move {}", Utility.toJsonString(context, true));
|
||||
|
||||
checkContext(orientGraph, newParentUUID,
|
||||
context.getProperty(Context.NAME_PROPERTY).toString());
|
||||
checkContext(orientGraph, newParentUUID, context.getProperty(Context.NAME_PROPERTY).toString());
|
||||
|
||||
// Removing the old parent relationship if any
|
||||
Iterable<Edge> edges = context.getEdges(Direction.IN,
|
||||
IsParentOf.NAME);
|
||||
Iterable<Edge> edges = context.getEdges(Direction.IN, IsParentOf.NAME);
|
||||
if (edges != null && edges.iterator().hasNext()) {
|
||||
Iterator<Edge> edgeIterator = edges.iterator();
|
||||
Edge edge = edgeIterator.next();
|
||||
|
@ -275,10 +242,8 @@ public class ContextManagementImpl implements OLDContextManagement {
|
|||
|
||||
if (newParentUUID != null) {
|
||||
Vertex parent = getContext(orientGraph, newParentUUID);
|
||||
logger.trace("New Parent Context {}",
|
||||
Utility.toJsonString(parent, true));
|
||||
OrientEdge edge = orientGraph.addEdge(null, parent, context,
|
||||
IsParentOf.NAME);
|
||||
logger.trace("New Parent Context {}", Utility.toJsonString(parent, true));
|
||||
OrientEdge edge = orientGraph.addEdge(null, parent, context, IsParentOf.NAME);
|
||||
HeaderUtility.addHeader(edge, null);
|
||||
edge.save();
|
||||
}
|
||||
|
@ -286,8 +251,7 @@ public class ContextManagementImpl implements OLDContextManagement {
|
|||
orientGraph.commit();
|
||||
|
||||
ContextUtility.invalidContextUUIDCache(contextToMoveUUID);
|
||||
|
||||
|
||||
|
||||
context = getContext(orientGraph, contextToMoveUUID);
|
||||
String contextJsonString = Utility.toJsonString(context, true);
|
||||
logger.info("Context moved {}", contextJsonString);
|
||||
|
@ -312,29 +276,22 @@ public class ContextManagementImpl implements OLDContextManagement {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(UUID uuid) throws ContextNotFoundException,
|
||||
ContextException {
|
||||
public boolean delete(UUID uuid) throws ContextNotFoundException, ContextException {
|
||||
|
||||
OrientGraph orientGraph = null;
|
||||
|
||||
try {
|
||||
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);
|
||||
logger.trace("Context to be delete {}",
|
||||
Utility.toJsonString(context, true));
|
||||
logger.trace("Context to be delete {}", Utility.toJsonString(context, true));
|
||||
|
||||
Iterable<Edge> edges = context.getEdges(Direction.OUT,
|
||||
IsParentOf.NAME);
|
||||
Iterable<Edge> edges = context.getEdges(Direction.OUT, IsParentOf.NAME);
|
||||
if (edges != null && edges.iterator().hasNext()) {
|
||||
throw new ContextException(
|
||||
"Only context with no children can be deleted");
|
||||
throw new ContextException("Only context with no children can be deleted");
|
||||
}
|
||||
|
||||
SecurityContext.deleteSecurityContext(orientGraph, uuid, false);
|
||||
|
@ -343,9 +300,8 @@ public class ContextManagementImpl implements OLDContextManagement {
|
|||
|
||||
orientGraph.commit();
|
||||
ContextUtility.invalidContextUUIDCache(uuid);
|
||||
|
||||
logger.info("{} with UUID {} successfully removed", Context.NAME,
|
||||
uuid);
|
||||
|
||||
logger.info("{} with UUID {} successfully removed", Context.NAME, uuid);
|
||||
return true;
|
||||
|
||||
} catch (ContextException | ContextNotFoundException ce) {
|
|
@ -34,20 +34,6 @@ import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
|||
public class ERManagementUtility {
|
||||
|
||||
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")
|
||||
public static ERManagement getERManagement(String type) throws ResourceRegistryException {
|
||||
|
@ -129,12 +115,12 @@ public class ERManagementUtility {
|
|||
|
||||
if (orientGraph == null) {
|
||||
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) {
|
||||
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;
|
||||
|
@ -142,8 +128,8 @@ public class ERManagementUtility {
|
|||
orientVertexType = ((OrientVertex) vertex).getType();
|
||||
} catch (Exception e) {
|
||||
String error = String.format(
|
||||
"Unable to detect type of %s. This is really strage please contact the administrator.",
|
||||
vertex.toString());
|
||||
"Unable to detect type of %s. %s",
|
||||
vertex.toString(), Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
logger.error(error, e);
|
||||
throw new ResourceRegistryException(error);
|
||||
}
|
||||
|
@ -154,8 +140,8 @@ public class ERManagementUtility {
|
|||
} else if (orientVertexType.isSubClassOf(Facet.NAME)) {
|
||||
entityManagement = new FacetManagement(orientGraph);
|
||||
} else {
|
||||
String error = String.format("{%s is not a %s nor a %s. " + "This is really strange and should not occur. "
|
||||
+ "Please Investigate it.", vertex, Resource.NAME, Facet.NAME);
|
||||
String error = String.format("{%s is not a %s nor a %s. %s",
|
||||
vertex, Resource.NAME, Facet.NAME, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
throw new ResourceRegistryException(error);
|
||||
}
|
||||
entityManagement.setElement(vertex);
|
||||
|
@ -168,12 +154,12 @@ public class ERManagementUtility {
|
|||
|
||||
if (orientGraph == null) {
|
||||
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) {
|
||||
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();
|
||||
|
@ -183,8 +169,8 @@ public class ERManagementUtility {
|
|||
} else if (orientEdgeType.isSubClassOf(IsRelatedTo.NAME)) {
|
||||
relationManagement = new IsRelatedToManagement(orientGraph);
|
||||
} else {
|
||||
String error = String.format("{%s is not a %s nor a %s. " + "This is really strange ad should not occur. "
|
||||
+ "Please Investigate it.", edge, ConsistsOf.NAME, IsRelatedTo.NAME);
|
||||
String error = String.format("{%s is not a %s nor a %s. %s",
|
||||
edge, ConsistsOf.NAME, IsRelatedTo.NAME, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
throw new ResourceRegistryException(error);
|
||||
}
|
||||
relationManagement.setElement(edge);
|
||||
|
|
|
@ -168,18 +168,6 @@ public abstract class EntityManagement<E extends Entity> extends
|
|||
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(),
|
||||
Utility.toJsonString((OrientVertex) element, true));
|
||||
|
||||
|
@ -241,7 +229,8 @@ public abstract class EntityManagement<E extends Entity> extends
|
|||
JSONObject jsonObject = entityManagement.serializeAsJson();
|
||||
jsonArray.put(jsonObject);
|
||||
}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();
|
||||
|
|
|
@ -108,10 +108,10 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
|||
JSONObject consistsOf = relationManagement.serializeAsJson(true, true);
|
||||
sourceResource = addConsistsOf(sourceResource, consistsOf);
|
||||
}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;
|
||||
}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);
|
||||
}
|
||||
|
||||
|
@ -226,11 +226,9 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
|||
} else if (orientEdgeType.isSubClassOf(ConsistsOf.NAME)) {
|
||||
relationManagement = new ConsistsOfManagement(orientGraph);
|
||||
} else {
|
||||
logger.warn("{} is not a {} nor a {}. "
|
||||
+ "This is really strange ad should not occur. "
|
||||
+ "Please Investigate it.",
|
||||
logger.warn("{} is not a {} nor a {}. {}",
|
||||
Utility.toJsonString(edge, true), IsRelatedTo.NAME,
|
||||
ConsistsOf.NAME);
|
||||
ConsistsOf.NAME, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
}
|
||||
if (relationManagement != null) {
|
||||
relationManagement.setElement(edge);
|
||||
|
@ -329,7 +327,8 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
|||
}
|
||||
orientVertexType = ((OrientVertex) orientElement).getType();
|
||||
}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);
|
||||
throw new ResourceRegistryException(error);
|
||||
}
|
||||
|
@ -351,7 +350,8 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
|||
JSONObject jsonObject = entityManagement.serializeAsJson();
|
||||
jsonArray.put(jsonObject);
|
||||
}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) {
|
||||
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;
|
||||
} 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);
|
||||
}
|
||||
|
||||
|
@ -181,9 +181,9 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
|||
sourceResource = resourceManagement.serializeSelfOnly();
|
||||
} else {
|
||||
String error = String.format(
|
||||
"{%s is not a %s nor a %s. " + "This is really strange and should not occur. "
|
||||
+ "Please Investigate it.",
|
||||
this, IsRelatedToManagement.class.getSimpleName(), ConsistsOfManagement.class.getSimpleName());
|
||||
"{%s is not a %s nor a %s. %s",
|
||||
this, IsRelatedToManagement.class.getSimpleName(), ConsistsOfManagement.class.getSimpleName(),
|
||||
Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
throw new ResourceRegistryException(error);
|
||||
}
|
||||
}
|
||||
|
@ -195,9 +195,9 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
|||
sourceResource = ResourceManagement.addConsistsOf(sourceResource, serializeAsJson());
|
||||
} else {
|
||||
String error = String.format(
|
||||
"{%s is not a %s nor a %s. " + "This is really strange and should not occur. "
|
||||
+ "Please Investigate it.",
|
||||
this, IsRelatedToManagement.class.getSimpleName(), ConsistsOfManagement.class.getSimpleName());
|
||||
"{%s is not a %s nor a %s. %s",
|
||||
this, IsRelatedToManagement.class.getSimpleName(), ConsistsOfManagement.class.getSimpleName(),
|
||||
Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
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);
|
||||
|
||||
/*
|
||||
* This code has been moved in ERManagement.internalCreate()
|
||||
* HeaderUtility.addHeader(element, null);
|
||||
* ContextUtility.addToActualContext(orientGraph, element);
|
||||
*
|
||||
* ((OrientEdge) element).save();
|
||||
*/
|
||||
|
||||
logger.info("{} successfully created", erType);
|
||||
|
||||
return element;
|
||||
|
@ -276,18 +268,6 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
|||
|
||||
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
|
||||
protected Edge reallyUpdate() throws ResourceRegistryException {
|
||||
|
||||
|
@ -324,18 +304,17 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
|||
addConstraint = propagationConstraint.getAddConstraint();
|
||||
} else {
|
||||
String error = String.format(
|
||||
"%s.%s in %s is null" + "This is really strange and should not occur. "
|
||||
+ "Please Investigate it.",
|
||||
"%s.%s in %s is null. %s",
|
||||
Relation.PROPAGATION_CONSTRAINT, PropagationConstraint.ADD_PROPERTY,
|
||||
Utility.toJsonString(element, true));
|
||||
Utility.toJsonString(element, true), Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
logger.error(error);
|
||||
throw new ResourceRegistryException(error);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
String error = String.format(
|
||||
"Error while getting %s from %s while performing AddToContext."
|
||||
+ "This is really strange and should not occur. " + "Please Investigate it.",
|
||||
Relation.PROPAGATION_CONSTRAINT, Utility.toJsonString(element, true));
|
||||
"Error while getting %s from %s while performing AddToContext. %s",
|
||||
Relation.PROPAGATION_CONSTRAINT, Utility.toJsonString(element, true),
|
||||
Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
logger.warn(error);
|
||||
throw new ResourceRegistryException(error, e);
|
||||
}
|
||||
|
@ -377,14 +356,6 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
|||
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
|
||||
protected boolean reallyRemoveFromContext() throws ContextException, ResourceRegistryException {
|
||||
getElement();
|
||||
|
@ -398,18 +369,17 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
|||
removeConstraint = propagationConstraint.getRemoveConstraint();
|
||||
} else {
|
||||
String error = String.format(
|
||||
"%s.%s in %s is null" + "This is really strange and should not occur. "
|
||||
+ "Please Investigate it.",
|
||||
"%s.%s in %s is null. %s",
|
||||
Relation.PROPAGATION_CONSTRAINT, PropagationConstraint.REMOVE_PROPERTY,
|
||||
Utility.toJsonString(element, true));
|
||||
Utility.toJsonString(element, true), Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
logger.error(error);
|
||||
throw new ResourceRegistryException(error);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
String error = String.format(
|
||||
"Error while getting %s from %s while performing RemoveFromContext."
|
||||
+ "This is really strange and should not occur. " + "Please Investigate it.",
|
||||
Relation.PROPAGATION_CONSTRAINT, Utility.toJsonString(element, true));
|
||||
"Error while getting %s from %s while performing RemoveFromContext. %s",
|
||||
Relation.PROPAGATION_CONSTRAINT, Utility.toJsonString(element, true),
|
||||
Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
logger.error(error);
|
||||
throw new ResourceRegistryException(error, e);
|
||||
|
||||
|
@ -482,18 +452,17 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
|||
removeConstraint = propagationConstraint.getRemoveConstraint();
|
||||
} else {
|
||||
String error = String.format(
|
||||
"%s.%s in %s is null" + "This is really strange and should not occur. "
|
||||
+ "Please Investigate it.",
|
||||
"%s.%s in %s is null. %s",
|
||||
Relation.PROPAGATION_CONSTRAINT, PropagationConstraint.REMOVE_PROPERTY,
|
||||
Utility.toJsonString(element, true));
|
||||
Utility.toJsonString(element, true), Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
logger.error(error);
|
||||
throw new ResourceRegistryException(error);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.warn(
|
||||
"Error while getting {} from {}. Assuming {}. " + "This is really strange and should not occur. "
|
||||
+ "Please Investigate it.",
|
||||
Relation.PROPAGATION_CONSTRAINT, Utility.toJsonString(element, true), removeConstraint);
|
||||
"Error while getting {} from {}. Assuming {}. {}",
|
||||
Relation.PROPAGATION_CONSTRAINT, Utility.toJsonString(element, true), removeConstraint,
|
||||
Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
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.rest.AccessPath;
|
||||
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.er.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.er.ERManagementUtility;
|
||||
|
@ -299,7 +299,7 @@ public class Access {
|
|||
public String getContext(@PathParam(ID_PATH_PARAM) String uuid)
|
||||
throws ContextNotFoundException, ContextException {
|
||||
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));
|
||||
}
|
||||
|
||||
|
|
|
@ -6,26 +6,23 @@ 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.ContextAlreadyPresentException;
|
||||
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.ContextManagementImpl;
|
||||
import org.gcube.informationsystem.resourceregistry.context.ContextManagement;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -43,28 +40,20 @@ public class ContextManager {
|
|||
|
||||
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
|
||||
* @param parentUUID
|
||||
* @param name
|
||||
* @return
|
||||
* @throws InternalException
|
||||
* @throws Exception
|
||||
* e.g. PUT /resource-registry/context
|
||||
*
|
||||
* BODY: {...}
|
||||
*
|
||||
*/
|
||||
@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);
|
||||
public Response create(String json)
|
||||
throws ContextAlreadyPresentException, ResourceRegistryException {
|
||||
logger.info("Requested to create {} with json {}", Context.NAME, json);
|
||||
ContextManagement contextManagement = new ContextManagement();
|
||||
contextManagement.setJSON(json);
|
||||
String ret = contextManagement.create();
|
||||
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 + "}")
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
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);
|
||||
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 + "}")
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
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);
|
||||
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
|
||||
* @param uuid
|
||||
* @param name
|
||||
* @return
|
||||
* @throws ContextNotFoundException
|
||||
* @throws ContextException
|
||||
* e.g. POST /resource-registry/context
|
||||
*
|
||||
* BODY: {...}
|
||||
*
|
||||
*/
|
||||
@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));
|
||||
public String rename(String json)
|
||||
throws ContextNotFoundException, ResourceRegistryException {
|
||||
logger.info("Requested to update {} with json {} ", Context.NAME, json);
|
||||
ContextManagement contextManagement = new ContextManagement();
|
||||
contextManagement.setJSON(json);
|
||||
return contextManagement.update();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ import org.gcube.informationsystem.model.entity.Facet;
|
|||
import org.gcube.informationsystem.model.entity.Resource;
|
||||
import org.gcube.informationsystem.model.relation.ConsistsOf;
|
||||
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.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
|
||||
|
@ -62,8 +61,8 @@ public class ERManager {
|
|||
CalledMethodProvider.instance.set(
|
||||
HTTPMETHOD.PUT.name() + " /" + ERPath.ER_PATH_PART +
|
||||
"/" + ERPath.FACET_PATH_PART + "/" + type);
|
||||
logger.info("requested facet creation for type {}", type);
|
||||
logger.trace("requested facet creation for type {} defined by {} ", type, json);
|
||||
logger.info("Requested to create {} of type {}", Facet.NAME, type);
|
||||
logger.trace("Requested to create {} of type {} defined by {} ", Facet.NAME, type, json);
|
||||
FacetManagement facetManagement = new FacetManagement();
|
||||
facetManagement.setElementType(type);
|
||||
facetManagement.setJSON(json);
|
||||
|
@ -87,8 +86,8 @@ public class ERManager {
|
|||
CalledMethodProvider.instance.set(
|
||||
HTTPMETHOD.POST.name() + " /" + ERPath.ER_PATH_PART +
|
||||
"/" + ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}");
|
||||
logger.info("requested facet update for id {}", uuid);
|
||||
logger.trace("requested facet update for id {} with {}", uuid, json);
|
||||
logger.info("Requested to update {} with id {}", Facet.NAME, uuid);
|
||||
logger.trace("Requested to update {} with id {} with json {}", Facet.NAME, uuid, json);
|
||||
FacetManagement facetManagement = new FacetManagement();
|
||||
facetManagement.setUUID(UUID.fromString(uuid));
|
||||
facetManagement.setJSON(json);
|
||||
|
@ -106,7 +105,7 @@ public class ERManager {
|
|||
CalledMethodProvider.instance.set(
|
||||
HTTPMETHOD.DELETE.name() + " /" + ERPath.ER_PATH_PART +
|
||||
"/" + 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.setUUID(UUID.fromString(uuid));
|
||||
return facetManagement.delete();
|
||||
|
@ -129,8 +128,8 @@ public class ERManager {
|
|||
CalledMethodProvider.instance.set(
|
||||
HTTPMETHOD.PUT.name() + " /" + ERPath.ER_PATH_PART +
|
||||
"/" + ERPath.RESOURCE_PATH_PART + "/" + type);
|
||||
logger.info("requested resource creation for type {}", type);
|
||||
logger.trace("requested resource creation for type {} with json {}", type, json);
|
||||
logger.info("Requested to create {} of type {}", Resource.NAME, type);
|
||||
logger.trace("Requested to create {} of type {} with json {}", Resource.NAME, type, json);
|
||||
ResourceManagement resourceManagement = new ResourceManagement();
|
||||
resourceManagement.setElementType(type);
|
||||
resourceManagement.setJSON(json);
|
||||
|
@ -154,8 +153,8 @@ public class ERManager {
|
|||
CalledMethodProvider.instance.set(
|
||||
HTTPMETHOD.POST.name() + " /" + ERPath.ER_PATH_PART +
|
||||
"/" + ERPath.RESOURCE_PATH_PART + "/{" + ID_PATH_PARAM + "}");
|
||||
logger.info("requested resource update for id {}", uuid);
|
||||
logger.trace("requested resource update for id {} with {}", uuid, json);
|
||||
logger.info("Requested to update {} with id {}", Resource.NAME, uuid);
|
||||
logger.trace("Requested to update {} with id {} with json {}", Resource.NAME, uuid, json);
|
||||
ResourceManagement resourceManagement = new ResourceManagement();
|
||||
resourceManagement.setUUID(UUID.fromString(uuid));
|
||||
resourceManagement.setJSON(json);
|
||||
|
@ -172,7 +171,7 @@ public class ERManager {
|
|||
CalledMethodProvider.instance.set(
|
||||
HTTPMETHOD.DELETE.name() + " /" + ERPath.ER_PATH_PART +
|
||||
"/" + 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.setUUID(UUID.fromString(uuid));
|
||||
return resourceManagement.delete();
|
||||
|
@ -194,8 +193,8 @@ public class ERManager {
|
|||
CalledMethodProvider.instance.set(
|
||||
HTTPMETHOD.PUT.name() + " /" + ERPath.ER_PATH_PART +
|
||||
"/" + ERPath.CONSISTS_OF_PATH_PART + "/" + type);
|
||||
logger.info("Requested to create {} {} of type {}", ConsistsOf.NAME, Relation.NAME, type);
|
||||
logger.trace("Requested to create {} {} of type {} : {}", ConsistsOf.NAME, Relation.NAME, type, json);
|
||||
logger.info("Requested to create {} of type {}", ConsistsOf.NAME, type);
|
||||
logger.trace("Requested to create {} of type {} with json {}", ConsistsOf.NAME, type, json);
|
||||
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
|
||||
consistsOfManagement.setElementType(type);
|
||||
consistsOfManagement.setJSON(json);
|
||||
|
@ -214,7 +213,7 @@ public class ERManager {
|
|||
CalledMethodProvider.instance.set(
|
||||
HTTPMETHOD.DELETE.name() + " /" + ERPath.ER_PATH_PART +
|
||||
"/" + 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.setUUID(UUID.fromString(consistOfUUID));
|
||||
return consistsOfManagement.delete();
|
||||
|
@ -235,7 +234,7 @@ public class ERManager {
|
|||
CalledMethodProvider.instance.set(
|
||||
HTTPMETHOD.PUT.name() + " /" + ERPath.ER_PATH_PART +
|
||||
"/" + 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.setElementType(type);
|
||||
isRelatedToManagement.setJSON(json);
|
||||
|
@ -254,7 +253,7 @@ public class ERManager {
|
|||
CalledMethodProvider.instance.set(
|
||||
HTTPMETHOD.DELETE.name() + " /" + ERPath.ER_PATH_PART +
|
||||
"/" + 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.setUUID(UUID.fromString(relatedToUUID));
|
||||
return isRelatedToManagement.delete();
|
||||
|
@ -271,7 +270,7 @@ public class ERManager {
|
|||
CalledMethodProvider.instance.set(
|
||||
HTTPMETHOD.POST.name() + " /" + ERPath.ER_PATH_PART +
|
||||
"/" + 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());
|
||||
ResourceManagement resourceManagement = new ResourceManagement();
|
||||
resourceManagement.setUUID(UUID.fromString(uuid));
|
||||
|
@ -289,7 +288,7 @@ public class ERManager {
|
|||
CalledMethodProvider.instance.set(
|
||||
HTTPMETHOD.POST.name() + " /" + ERPath.ER_PATH_PART +
|
||||
"/" + 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());
|
||||
FacetManagement facetManagement = new FacetManagement();
|
||||
facetManagement.setUUID(UUID.fromString(uuid));
|
||||
|
@ -307,7 +306,7 @@ public class ERManager {
|
|||
CalledMethodProvider.instance.set(
|
||||
HTTPMETHOD.POST.name() + " /" + ERPath.ER_PATH_PART +
|
||||
"/" + 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());
|
||||
ResourceManagement resourceManagement = new ResourceManagement();
|
||||
resourceManagement.setUUID(UUID.fromString(uuid));
|
||||
|
@ -325,7 +324,7 @@ public class ERManager {
|
|||
CalledMethodProvider.instance.set(
|
||||
HTTPMETHOD.POST.name() + " /" + ERPath.ER_PATH_PART +
|
||||
"/" + 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());
|
||||
FacetManagement facetManagement = new FacetManagement();
|
||||
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 {
|
||||
|
||||
private static final Logger logger = LoggerFactory
|
||||
.getLogger(HeaderUtility.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(HeaderUtility.class);
|
||||
|
||||
public static String getUser() {
|
||||
String user = org.gcube.informationsystem.model.embedded.Header.UNKNOWN_USER;
|
||||
try {
|
||||
Caller caller = AuthorizationProvider.instance.get();
|
||||
if(caller!=null){
|
||||
if (caller != null) {
|
||||
ClientInfo clientInfo = caller.getClient();
|
||||
String clientId = clientInfo.getId();
|
||||
if (clientId != null && clientId.compareTo("") != 0) {
|
||||
|
@ -53,7 +52,7 @@ public class HeaderUtility {
|
|||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
public static Header createHeader(UUID uuid) {
|
||||
HeaderOrient header = new HeaderOrient();
|
||||
|
||||
|
@ -66,17 +65,17 @@ public class HeaderUtility {
|
|||
String creator = getUser();
|
||||
header.setCreator(creator);
|
||||
header.setModifiedBy(creator);
|
||||
|
||||
|
||||
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));
|
||||
|
||||
|
||||
header.setCreationTime(date);
|
||||
header.setLastUpdateTime(date);
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
|
||||
public static Header getHeader(JsonNode jsonNode, boolean creation)
|
||||
throws JsonParseException, JsonMappingException, IOException {
|
||||
if (jsonNode.has(Resource.HEADER_PROPERTY)) {
|
||||
|
@ -85,12 +84,12 @@ public class HeaderUtility {
|
|||
return null;
|
||||
}
|
||||
HeaderOrient header = null;
|
||||
if(creation){
|
||||
if (creation) {
|
||||
// If an header is provided MUST contains and UUID otherwise is
|
||||
// an invalid request so that let that an exception is raised
|
||||
UUID uuid = UUID.fromString(headerNode.get(Header.UUID_PROPERTY).asText());
|
||||
header = (HeaderOrient) createHeader(uuid);
|
||||
}else{
|
||||
} else {
|
||||
header = new HeaderOrient();
|
||||
header.fromJSON(headerNode.toString());
|
||||
}
|
||||
|
@ -98,11 +97,11 @@ public class HeaderUtility {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static HeaderOrient getHeaderOrient(ODocument oDocument) throws ResourceRegistryException{
|
||||
|
||||
public static HeaderOrient getHeaderOrient(ODocument oDocument) throws ResourceRegistryException {
|
||||
if (oDocument instanceof HeaderOrient) {
|
||||
return (HeaderOrient) oDocument;
|
||||
}else{
|
||||
} else {
|
||||
try {
|
||||
HeaderOrient headerOrient = new HeaderOrient();
|
||||
Header header = ISMapper.unmarshal(Header.class, oDocument.toJSON());
|
||||
|
@ -111,13 +110,14 @@ public class HeaderUtility {
|
|||
headerOrient.setCreationTime(header.getCreationTime());
|
||||
headerOrient.setModifiedBy(header.getModifiedBy());
|
||||
headerOrient.setLastUpdateTime(header.getLastUpdateTime());
|
||||
return headerOrient;
|
||||
return headerOrient;
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Header addHeader(Element element, UUID uuid) {
|
||||
Header header = createHeader(uuid);
|
||||
element.setProperty(Entity.HEADER_PROPERTY, header);
|
||||
|
@ -130,11 +130,10 @@ public class HeaderUtility {
|
|||
return header;
|
||||
}
|
||||
|
||||
public static Header getHeader(Element element)
|
||||
throws ResourceRegistryException {
|
||||
public static Header getHeader(Element element) throws ResourceRegistryException {
|
||||
return Utility.getEmbedded(Header.class, element, Entity.HEADER_PROPERTY);
|
||||
}
|
||||
|
||||
|
||||
public static void updateModifiedByAndLastUpdate(Element element) throws ResourceRegistryException {
|
||||
ODocument oDocument = element.getProperty(Entity.HEADER_PROPERTY);
|
||||
String modifiedBy = getUser();
|
||||
|
@ -143,5 +142,5 @@ public class HeaderUtility {
|
|||
oDocument.field(Header.LAST_UPDATE_TIME_PROPERTY, lastUpdateTime);
|
||||
element.setProperty(Entity.HEADER_PROPERTY, oDocument);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public class Utility {
|
|||
|
||||
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)
|
||||
throws ResourceRegistryException {
|
||||
|
|
|
@ -27,10 +27,10 @@ public class ContextManagementImplTest {
|
|||
private static Logger logger = LoggerFactory
|
||||
.getLogger(ContextManagementImplTest.class);
|
||||
|
||||
protected ContextManagementImpl contextManagementImpl;
|
||||
protected OLDContextManagementImpl contextManagementImpl;
|
||||
|
||||
public ContextManagementImplTest() {
|
||||
contextManagementImpl = new ContextManagementImpl();
|
||||
contextManagementImpl = new OLDContextManagementImpl();
|
||||
}
|
||||
|
||||
public static final String CTX_NAME_A = "A";
|
||||
|
@ -101,7 +101,7 @@ public class ContextManagementImplTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// @Test
|
||||
public void simpleTest() throws Exception {
|
||||
String contextJsonA1 = contextManagementImpl.create(null, CTX_NAME_A);
|
||||
Context createdContexA1 = ISMapper.unmarshal(Context.class,
|
||||
|
@ -181,7 +181,7 @@ public class ContextManagementImplTest {
|
|||
logger.debug("The DB should be now clean");
|
||||
}
|
||||
|
||||
@Test
|
||||
// @Test
|
||||
public void createContext() throws Exception {
|
||||
String name = "test";
|
||||
|
||||
|
@ -303,7 +303,7 @@ public class ContextManagementImplTest {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
// @Test
|
||||
public void readTest() throws Exception {
|
||||
String name = "LLL";
|
||||
String contextJson = contextManagementImpl.create(null, name);
|
||||
|
@ -324,7 +324,7 @@ public class ContextManagementImplTest {
|
|||
Assert.assertTrue(deleted);
|
||||
}
|
||||
|
||||
@Test
|
||||
// @Test
|
||||
public void completeTest() throws Exception {
|
||||
String contextJsonA1 = contextManagementImpl.create(null, CTX_NAME_A);
|
||||
Context createdContexA1 = ISMapper.unmarshal(Context.class,
|
||||
|
@ -484,7 +484,7 @@ public class ContextManagementImplTest {
|
|||
logger.debug("The DB should be now clean");
|
||||
}
|
||||
|
||||
@Test
|
||||
// @Test
|
||||
public void moveToRootTest() throws Exception {
|
||||
String contextJsonA1 = contextManagementImpl.create(null, CTX_NAME_A);
|
||||
Context createdContexA1 = ISMapper.unmarshal(Context.class,
|
||||
|
|
|
@ -1,103 +1,413 @@
|
|||
package org.gcube.informationsystem.resourceregistry.context;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.informationsystem.impl.embedded.HeaderImpl;
|
||||
import org.gcube.informationsystem.impl.entity.ContextImpl;
|
||||
import org.gcube.informationsystem.impl.utils.ISMapper;
|
||||
import org.gcube.informationsystem.model.entity.Context;
|
||||
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.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
|
||||
public class ContextManagementTest {
|
||||
|
||||
private static Logger logger = LoggerFactory
|
||||
.getLogger(ContextManagementTest.class);
|
||||
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(ContextManagementTest.class);
|
||||
|
||||
@Test
|
||||
public void get() throws Exception {
|
||||
// UUID uuid = UUID.fromString("602ce5ea-b263-452a-93e5-ab33db7af979");
|
||||
UUID uuid = UUID.fromString("4e2b121e-ba5a-41e1-bbed-be9b60370aa3");
|
||||
|
||||
|
||||
ContextManagement contextManagement = new ContextManagement();
|
||||
contextManagement.setUUID(uuid);
|
||||
|
||||
|
||||
String string = contextManagement.read();
|
||||
logger.debug(string);
|
||||
|
||||
|
||||
Context context = ISMapper.unmarshal(Context.class, string);
|
||||
|
||||
|
||||
logger.debug("{}", ISMapper.marshal(context));
|
||||
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Context parent = context.getParent().getSource();
|
||||
Context sameOfContext = parent.getChildren().get(0).getTarget();
|
||||
Assert.assertTrue(context==sameOfContext);
|
||||
|
||||
|
||||
Assert.assertTrue(context == sameOfContext);
|
||||
|
||||
List<IsParentOf<Context, Context>> children = context.getChildren();
|
||||
for(IsParentOf<Context, Context> child : children) {
|
||||
Assert.assertTrue(child.getSource()==context);
|
||||
for (IsParentOf<Context, Context> child : children) {
|
||||
Assert.assertTrue(child.getSource() == context);
|
||||
Context childContext = child.getTarget();
|
||||
Assert.assertTrue(childContext.getParent().getSource()==context);
|
||||
Assert.assertTrue(childContext.getParent().getSource() == context);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// @Test
|
||||
public void test() throws Exception {
|
||||
UUID uuid = UUID.fromString("4e2b121e-ba5a-41e1-bbed-be9b60370aa3");
|
||||
|
||||
|
||||
Context myTest = new ContextImpl("myTest");
|
||||
myTest.setParent(uuid);
|
||||
|
||||
|
||||
String contextJsonString = ISMapper.marshal(myTest);
|
||||
logger.debug("myTest : {}", contextJsonString);
|
||||
|
||||
|
||||
ContextManagement contextManagement = new ContextManagement();
|
||||
contextManagement.setJSON(contextJsonString);
|
||||
contextManagement.create();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testJava() throws Exception {
|
||||
Context gcube = new ContextImpl("gcube");
|
||||
logger.debug("gcube : {}", ISMapper.marshal(gcube));
|
||||
|
||||
|
||||
Context devsec = new ContextImpl("devsec");
|
||||
gcube.addChild(devsec);
|
||||
logger.debug("devsec : {}", ISMapper.marshal(devsec));
|
||||
|
||||
|
||||
Context devVRE = new ContextImpl("devVRE");
|
||||
devsec.addChild(devVRE);
|
||||
logger.debug("devVRE : {}", ISMapper.marshal(devVRE));
|
||||
|
||||
|
||||
Context devNext = new ContextImpl("devNext");
|
||||
gcube.addChild(devNext);
|
||||
logger.debug("devNext : {}", ISMapper.marshal(devNext));
|
||||
|
||||
|
||||
Context NextNext = new ContextImpl("NextNext");
|
||||
devNext.addChild(NextNext);
|
||||
logger.debug("NextNext : {}", ISMapper.marshal(NextNext));
|
||||
|
||||
|
||||
|
||||
logger.debug("------------------------------------");
|
||||
|
||||
|
||||
logger.debug("gcube : {}", ISMapper.marshal(gcube));
|
||||
logger.debug("devsec : {}", ISMapper.marshal(devsec));
|
||||
logger.debug("devVRE : {}", ISMapper.marshal(devVRE));
|
||||
logger.debug("devNext : {}", ISMapper.marshal(devNext));
|
||||
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