Implementing possibility to create a relation and target entity with one call
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@148248 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
ea2c1392bd
commit
08db977881
|
@ -325,6 +325,9 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
|||
public abstract JSONObject serializeAsJson()
|
||||
throws ResourceRegistryException;
|
||||
|
||||
public abstract El reallyCreate() throws ERAlreadyPresentException,
|
||||
ResourceRegistryException;
|
||||
|
||||
public abstract El reallyUpdate() throws ERNotFoundException,
|
||||
ResourceRegistryException;
|
||||
|
||||
|
@ -480,6 +483,34 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
|||
}
|
||||
}
|
||||
|
||||
public String create() throws ERAlreadyPresentException, ResourceRegistryException {
|
||||
|
||||
try {
|
||||
orientGraph = ContextUtility.getActualSecurityContextGraph(PermissionMode.WRITER);
|
||||
|
||||
element = reallyCreate();
|
||||
|
||||
orientGraph.commit();
|
||||
|
||||
return serialize();
|
||||
|
||||
} catch (ResourceRegistryException e) {
|
||||
if (orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
}
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
if (orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
}
|
||||
throw new ResourceRegistryException(e);
|
||||
} finally {
|
||||
if (orientGraph != null) {
|
||||
orientGraph.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String read() throws ERNotFoundException,
|
||||
ERAvailableInAnotherContextException, ResourceRegistryException {
|
||||
try {
|
||||
|
|
|
@ -17,7 +17,6 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.Entity
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERAvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.context.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.context.SecurityContextMapper.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.er.ERManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.er.relation.RelationManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.utils.HeaderUtility;
|
||||
|
@ -62,6 +61,10 @@ public abstract class EntityManagement<E extends Entity> extends
|
|||
this(accessType);
|
||||
this.orientGraph = orientGraph;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract Vertex reallyCreate() throws EntityAlreadyPresentException,
|
||||
ResourceRegistryException;
|
||||
|
||||
protected Vertex createVertex() throws EntityAlreadyPresentException,
|
||||
ResourceRegistryException {
|
||||
|
@ -213,39 +216,6 @@ public abstract class EntityManagement<E extends Entity> extends
|
|||
return entityManagement;
|
||||
}
|
||||
|
||||
public abstract Vertex reallyCreate() throws EntityAlreadyPresentException,
|
||||
ResourceRegistryException;
|
||||
|
||||
public String create() throws EntityAlreadyPresentException,
|
||||
ResourceRegistryException {
|
||||
|
||||
try {
|
||||
orientGraph = ContextUtility
|
||||
.getActualSecurityContextGraph(PermissionMode.WRITER);
|
||||
|
||||
element = reallyCreate();
|
||||
|
||||
orientGraph.commit();
|
||||
|
||||
return serialize();
|
||||
|
||||
} catch (ResourceRegistryException e) {
|
||||
if (orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
}
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
if (orientGraph != null) {
|
||||
orientGraph.rollback();
|
||||
}
|
||||
throw new ResourceRegistryException(e);
|
||||
} finally {
|
||||
if (orientGraph != null) {
|
||||
orientGraph.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String reallyGetAll(boolean polymorphic) throws ResourceRegistryException {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
|
|
|
@ -264,6 +264,20 @@ public abstract class RelationManagement<R extends Relation> extends
|
|||
return reallyCreate(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Edge reallyCreate() throws ResourceRegistryException {
|
||||
if(!jsonNode.has(Relation.SOURCE_PROPERTY)){
|
||||
throw new ResourceRegistryException(
|
||||
"Error while creating relation. No source definition found");
|
||||
}
|
||||
|
||||
UUID sourceUUID = org.gcube.informationsystem.impl.utils.Utility
|
||||
.getUUIDFromJsonNode(jsonNode.get(Relation.SOURCE_PROPERTY));
|
||||
|
||||
return reallyCreate(sourceUUID);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Edge reallyUpdate() throws ResourceRegistryException {
|
||||
|
||||
|
@ -625,7 +639,7 @@ public abstract class RelationManagement<R extends Relation> extends
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Collection<JSONObject> serializeEdges(Iterable<Edge> edges,
|
||||
boolean postFilterPolymorphic) throws ResourceRegistryException {
|
||||
|
|
|
@ -17,6 +17,7 @@ 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;
|
||||
|
@ -230,6 +231,35 @@ public class ERManager {
|
|||
return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8).build();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* e.g. PUT /resource-registry/er/consistsOf/IsIdentifiedBy
|
||||
*
|
||||
* BODY: {...}
|
||||
*
|
||||
* @param type
|
||||
* @param definition
|
||||
* @return
|
||||
* @throws ResourceAlreadyPresentException
|
||||
* @throws ResourceRegistryException
|
||||
*/
|
||||
@PUT
|
||||
@Path(ERPath.CONSISTS_OF_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
|
||||
@Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 })
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public Response createConsistsOf(@PathParam(TYPE_PATH_PARAM) String type,
|
||||
String json) throws ResourceAlreadyPresentException, ResourceRegistryException {
|
||||
logger.info(
|
||||
"Requested to create {} {} of type {} : {}",
|
||||
ConsistsOf.NAME, Relation.NAME, type, json);
|
||||
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
|
||||
consistsOfManagement.setElementType(type);
|
||||
consistsOfManagement.setJSON(json);
|
||||
String ret = consistsOfManagement.create();
|
||||
return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8).build();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* e.g. DELETE /resource-registry/er/consistOf/9bff49c8-c0a7-45de-827c-
|
||||
* accb71defbd3
|
||||
|
@ -288,6 +318,34 @@ public class ERManager {
|
|||
String ret = isRelatedToManagement.create(
|
||||
UUID.fromString(sourceResourceUUID),
|
||||
UUID.fromString(targetResourceUUID));
|
||||
|
||||
return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* e.g. PUT /resource-registry/er/isRelatedTo/Hosts
|
||||
*
|
||||
* BODY: {...}
|
||||
*
|
||||
* @param type
|
||||
* @param definition
|
||||
* @return
|
||||
* @throws ResourceAlreadyPresentException
|
||||
* @throws ResourceRegistryException
|
||||
*/
|
||||
@PUT
|
||||
@Path(ERPath.IS_RELATED_TO_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
|
||||
@Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 })
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public Response createIsRelatedTo(@PathParam(TYPE_PATH_PARAM) String type,
|
||||
String json) throws ResourceAlreadyPresentException, ResourceRegistryException {
|
||||
logger.info(
|
||||
"Requested to create {} {} of type {} : {}",
|
||||
IsRelatedTo.NAME, Relation.NAME, type, json);
|
||||
IsRelatedToManagement isRelatedToManagement = new IsRelatedToManagement();
|
||||
isRelatedToManagement.setElementType(type);
|
||||
isRelatedToManagement.setJSON(json);
|
||||
String ret = isRelatedToManagement.create();
|
||||
return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8).build();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue