Overriding calledMethod accounting field. Refs #9020

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@150578 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-06-27 15:22:19 +00:00
parent b2c73a654e
commit 31901d5ce3
4 changed files with 121 additions and 254 deletions

View File

@ -169,7 +169,7 @@ public abstract class RelationManagement<R extends Relation> extends
return visitedSourceResources; return visitedSourceResources;
} }
public Edge reallyCreate(UUID sourceUUID, UUID targetUUID) private Edge reallyCreate(UUID sourceUUID, UUID targetUUID)
throws ResourceRegistryException { throws ResourceRegistryException {
ResourceManagement srmSource = new ResourceManagement(orientGraph); ResourceManagement srmSource = new ResourceManagement(orientGraph);
srmSource.setUUID(sourceUUID); srmSource.setUUID(sourceUUID);
@ -617,7 +617,8 @@ public abstract class RelationManagement<R extends Relation> extends
return true; return true;
} }
public String create(UUID sourceUUID, UUID targetUUID) @SuppressWarnings("unused")
private String create(UUID sourceUUID, UUID targetUUID)
throws ResourceRegistryException { throws ResourceRegistryException {
try { try {
orientGraph = ContextUtility orientGraph = ContextUtility

View File

@ -13,6 +13,7 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status;
import org.gcube.common.authorization.library.provider.CalledMethodProvider;
import org.gcube.informationsystem.model.entity.Facet; import org.gcube.informationsystem.model.entity.Facet;
import org.gcube.informationsystem.model.entity.Resource; import org.gcube.informationsystem.model.entity.Resource;
import org.gcube.informationsystem.model.relation.ConsistsOf; import org.gcube.informationsystem.model.relation.ConsistsOf;
@ -26,6 +27,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceAlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.rest.ERPath; import org.gcube.informationsystem.resourceregistry.api.rest.ERPath;
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPCall.HTTPMETHOD;
import org.gcube.informationsystem.resourceregistry.context.ContextUtility; import org.gcube.informationsystem.resourceregistry.context.ContextUtility;
import org.gcube.informationsystem.resourceregistry.er.entity.FacetManagement; import org.gcube.informationsystem.resourceregistry.er.entity.FacetManagement;
import org.gcube.informationsystem.resourceregistry.er.entity.ResourceManagement; import org.gcube.informationsystem.resourceregistry.er.entity.ResourceManagement;
@ -45,48 +47,41 @@ public class ERManager {
public static final String ID_PATH_PARAM = "id"; public static final String ID_PATH_PARAM = "id";
public static final String TYPE_PATH_PARAM = "type"; public static final String TYPE_PATH_PARAM = "type";
/*
public static final String SOURCE_ID_PATH_PARAM = "sourceId"; public static final String SOURCE_ID_PATH_PARAM = "sourceId";
public static final String TARGET_ID_PATH_PARAM = "targetId"; public static final String TARGET_ID_PATH_PARAM = "targetId";
*/
/* Facets Methods */
/** /**
* e.g. PUT /resource-registry/er/facet/ContactFacet * e.g. PUT /resource-registry/er/facet/ContactFacet
* *
* BODY: {...} * BODY: {...}
* *
* @param type
* @param definition
* @return
* @throws FacetAlreadyPresentException
* @throws ResourceRegistryException
*/ */
@PUT @PUT
@Path(ERPath.FACET_PATH_PART + "/{" + TYPE_PATH_PARAM + "}") @Path(ERPath.FACET_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
@Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 }) @Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 })
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8) @Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public Response createFacet(@PathParam(TYPE_PATH_PARAM) String type, public Response createFacet(@PathParam(TYPE_PATH_PARAM) String type, String json)
String json) throws FacetAlreadyPresentException, ResourceRegistryException { throws FacetAlreadyPresentException, ResourceRegistryException {
CalledMethodProvider.instance.set(
HTTPMETHOD.PUT.name() + "/" + ERPath.ER_PATH_PART +
"/" + ERPath.FACET_PATH_PART + "/" + type);
logger.info("requested facet creation for type {}", type); logger.info("requested facet creation for type {}", type);
logger.trace("requested facet creation for type {} defined by {} ", logger.trace("requested facet creation for type {} defined by {} ", type, json);
type, json);
FacetManagement facetManagement = new FacetManagement(); FacetManagement facetManagement = new FacetManagement();
facetManagement.setElementType(type); facetManagement.setElementType(type);
facetManagement.setJSON(json); facetManagement.setJSON(json);
String ret = facetManagement.create(); String ret = facetManagement.create();
return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8).build(); return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
.build();
} }
/** /**
* e.g. POST /resource-registry/er/facet/4023d5b2-8601-47a5- * e.g. POST /resource-registry/er/facet/4023d5b2-8601-47a5-83ef-49ffcbfc7d86
* 83ef-49ffcbfc7d86
* *
* BODY: {...} * BODY: {...}
* *
* @param uuid
* @param definition
* @return
* @throws FacetNotFoundException
* @throws ResourceRegistryException
*/ */
@POST @POST
@Path(ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}") @Path(ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}")
@ -94,6 +89,9 @@ public class ERManager {
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8) @Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public String updateFacet(@PathParam(ID_PATH_PARAM) String uuid, String json) public String updateFacet(@PathParam(ID_PATH_PARAM) String uuid, String json)
throws FacetNotFoundException, ResourceRegistryException { throws FacetNotFoundException, ResourceRegistryException {
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.info("requested facet update for id {}", uuid);
logger.trace("requested facet update for id {} with {}", uuid, json); logger.trace("requested facet update for id {} with {}", uuid, json);
FacetManagement facetManagement = new FacetManagement(); FacetManagement facetManagement = new FacetManagement();
@ -103,18 +101,16 @@ public class ERManager {
} }
/** /**
* e.g. DELETE * e.g. DELETE /resource-registry/er/facet/4023d5b2-8601-47a5-83ef-49ffcbfc7d86
* /resource-registry/er/facet/4023d5b2-8601-47a5-83ef-49ffcbfc7d86
* *
* @param uuid
* @return
* @throws FacetNotFoundException
* @throws ResourceRegistryException
*/ */
@DELETE @DELETE
@Path(ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}") @Path(ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}")
public boolean deleteFacet(@PathParam(ID_PATH_PARAM) String uuid) public boolean deleteFacet(@PathParam(ID_PATH_PARAM) String uuid)
throws FacetNotFoundException, ResourceRegistryException { throws FacetNotFoundException, ResourceRegistryException {
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 Facet with id {}", uuid);
FacetManagement facetManagement = new FacetManagement(); FacetManagement facetManagement = new FacetManagement();
facetManagement.setUUID(UUID.fromString(uuid)); facetManagement.setUUID(UUID.fromString(uuid));
@ -128,44 +124,41 @@ public class ERManager {
* *
* BODY: {...} * BODY: {...}
* *
* @param type
* @param definition
* @return
* @throws ResourceAlreadyPresentException
* @throws ResourceRegistryException
*/ */
@PUT @PUT
@Path(ERPath.RESOURCE_PATH_PART + "/{" + TYPE_PATH_PARAM + "}") @Path(ERPath.RESOURCE_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
@Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 }) @Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 })
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8) @Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public Response createResource(@PathParam(TYPE_PATH_PARAM) String type, public Response createResource(@PathParam(TYPE_PATH_PARAM) String type, String json)
String json) throws ResourceAlreadyPresentException, ResourceRegistryException { throws ResourceAlreadyPresentException, ResourceRegistryException {
CalledMethodProvider.instance.set(
HTTPMETHOD.PUT.name() + "/" + ERPath.ER_PATH_PART +
"/" + ERPath.RESOURCE_PATH_PART + "/" + type);
logger.info("requested resource creation for type {}", type); logger.info("requested resource creation for type {}", type);
logger.trace("requested resource creation for type {} with json {}", logger.trace("requested resource creation for type {} with json {}", type, json);
type, json);
ResourceManagement resourceManagement = new ResourceManagement(); ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(type); resourceManagement.setElementType(type);
resourceManagement.setJSON(json); resourceManagement.setJSON(json);
String ret = resourceManagement.create(); String ret = resourceManagement.create();
return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8).build(); return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
.build();
} }
/** /**
* e.g. POST /resource-registry/er/resource/67062c11-9c3a-4906-870d-7df6a43408b0 * e.g. POST /resource-registry/er/resource/67062c11-9c3a-4906-870d-7df6a43408b0
* *
* @param uuid * BODY: {...}
* @param json *
* @return
* @throws ResourceNotFoundException
* @throws ResourceRegistryException
*/ */
@POST @POST
@Path(ERPath.RESOURCE_PATH_PART + "/{" + ID_PATH_PARAM + "}") @Path(ERPath.RESOURCE_PATH_PART + "/{" + ID_PATH_PARAM + "}")
@Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 }) @Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 })
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8) @Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public String updateResource(@PathParam(ID_PATH_PARAM) String uuid, public String updateResource(@PathParam(ID_PATH_PARAM) String uuid, String json)
String json) throws ResourceNotFoundException, throws ResourceNotFoundException, ResourceRegistryException {
ResourceRegistryException { 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.info("requested resource update for id {}", uuid);
logger.trace("requested resource update for id {} with {}", uuid, json); logger.trace("requested resource update for id {} with {}", uuid, json);
ResourceManagement resourceManagement = new ResourceManagement(); ResourceManagement resourceManagement = new ResourceManagement();
@ -175,203 +168,97 @@ public class ERManager {
} }
/** /**
* e.g. DELETE * e.g. DELETE /resource-registry/er/resource/67062c11-9c3a-4906-870d-7df6a43408b0
* /resource-registry/er/resource/67062c11-9c3a-4906-870d-7df6a43408b0
* *
* @param uuid
* @return
* @throws ResourceNotFoundException
* @throws Exception
*/ */
@DELETE @DELETE
@Path(ERPath.RESOURCE_PATH_PART + "/{" + ID_PATH_PARAM + "}") @Path(ERPath.RESOURCE_PATH_PART + "/{" + ID_PATH_PARAM + "}")
public boolean deleteResource(@PathParam(ID_PATH_PARAM) String uuid) public boolean deleteResource(@PathParam(ID_PATH_PARAM) String uuid) throws ResourceNotFoundException, Exception {
throws ResourceNotFoundException, Exception { 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 resource deletion for id {}", uuid);
ResourceManagement resourceManagement = new ResourceManagement(); ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(UUID.fromString(uuid)); resourceManagement.setUUID(UUID.fromString(uuid));
return resourceManagement.delete(); return resourceManagement.delete();
} }
/* Relations Methods */
/**
* e.g. PUT
* /resource-registry/er/consistsOf/source/bbf80a93-2284-424a-930c-
* 7ee20021aee1/target/f6931232-c034-4979-9b2f-7193d3fba7df/hasCreator
*
* BODY: {}
*
* @param resourceUUID
* @param facetUUID
* @param type
* @param properties
* @return
* @throws FacetNotFoundException
* @throws ResourceNotFoundException
* @throws ResourceRegistryException
*/
@PUT
@Path(ERPath.CONSISTS_OF_PATH_PART + "/" + ERPath.SOURCE_PATH_PART
+ "/{" + SOURCE_ID_PATH_PARAM + "}/" + ERPath.TARGET_PATH_PART
+ "/{" + TARGET_ID_PATH_PARAM + "}/{" + TYPE_PATH_PARAM + "}")
@Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 })
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public Response attachFacet(
@PathParam(SOURCE_ID_PATH_PARAM) String resourceUUID,
@PathParam(TARGET_ID_PATH_PARAM) String facetUUID,
@PathParam(TYPE_PATH_PARAM) String type, String json)
throws FacetNotFoundException, ResourceNotFoundException,
ResourceRegistryException {
logger.info(
"requested to attach resource {} to facet {} ({} Type {})",
resourceUUID, facetUUID, ConsistsOf.class.getSimpleName(),
type);
logger.trace(
"requested to attach resource {} to facet {} ({} Type {}) with properties {}",
resourceUUID, facetUUID, ConsistsOf.class.getSimpleName(),
type, json);
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
consistsOfManagement.setElementType(type);
consistsOfManagement.setJSON(json);
String ret = consistsOfManagement.create(UUID.fromString(resourceUUID),
UUID.fromString(facetUUID));
return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8).build();
}
/** /**
* e.g. PUT /resource-registry/er/consistsOf/IsIdentifiedBy * e.g. PUT /resource-registry/er/consistsOf/IsIdentifiedBy
* *
* BODY: {...} * BODY: {...}
* *
* @param type
* @param definition
* @return
* @throws ResourceAlreadyPresentException
* @throws ResourceRegistryException
*/ */
@PUT @PUT
@Path(ERPath.CONSISTS_OF_PATH_PART + "/{" + TYPE_PATH_PARAM + "}") @Path(ERPath.CONSISTS_OF_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
@Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 }) @Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 })
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8) @Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public Response createConsistsOf(@PathParam(TYPE_PATH_PARAM) String type, public Response createConsistsOf(@PathParam(TYPE_PATH_PARAM) String type, String json)
String json) throws ResourceAlreadyPresentException, ResourceRegistryException { throws ResourceAlreadyPresentException, ResourceRegistryException {
logger.info( CalledMethodProvider.instance.set(
"Requested to create {} {} of type {}", HTTPMETHOD.PUT.name() + "/" + ERPath.ER_PATH_PART +
ConsistsOf.NAME, Relation.NAME, type); "/" + ERPath.CONSISTS_OF_PATH_PART + "/" + type);
logger.trace( logger.info("Requested to create {} {} of type {}", ConsistsOf.NAME, Relation.NAME, type);
"Requested to create {} {} of type {} : {}", logger.trace("Requested to create {} {} of type {} : {}", ConsistsOf.NAME, Relation.NAME, type, json);
ConsistsOf.NAME, Relation.NAME, type, json);
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement(); ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
consistsOfManagement.setElementType(type); consistsOfManagement.setElementType(type);
consistsOfManagement.setJSON(json); consistsOfManagement.setJSON(json);
String ret = consistsOfManagement.create(); String ret = consistsOfManagement.create();
return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8).build(); return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
.build();
} }
/** /**
* e.g. DELETE /resource-registry/er/consistOf/9bff49c8-c0a7-45de-827c- * e.g. DELETE /resource-registry/er/consistsOf/9bff49c8-c0a7-45de-827c-accb71defbd3
* accb71defbd3
* *
* @param consistOfUUID
* @return
* @throws ResourceRegistryException
*/ */
@DELETE @DELETE
@Path(ERPath.CONSISTS_OF_PATH_PART + "/{" + ID_PATH_PARAM + "}") @Path(ERPath.CONSISTS_OF_PATH_PART + "/{" + ID_PATH_PARAM + "}")
public boolean detachFacet(@PathParam(ID_PATH_PARAM) String consistOfUUID) public boolean detachFacet(@PathParam(ID_PATH_PARAM) String consistOfUUID) throws ResourceRegistryException {
throws ResourceRegistryException { 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 detach {}", consistOfUUID);
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement(); ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
consistsOfManagement.setUUID(UUID.fromString(consistOfUUID)); consistsOfManagement.setUUID(UUID.fromString(consistOfUUID));
return consistsOfManagement.delete(); return consistsOfManagement.delete();
} }
/**
* e.g. PUT
* /resource-registry/er/isRelatedTo/source/4a81008a-6300-4a32-857f
* -cebe3f7b2925/target/985f7cf9-b6fa-463b-86c8-84ab0a77deea/callsFor
*
* BODY: {...}
*
* @param sourceResourceUUID
* @param targetResourceUUID
* @param type
* @param properties
* @return
* @throws ResourceNotFoundException
* @throws ResourceRegistryException
*/
@PUT
@Path(ERPath.IS_RELATED_TO_PATH_PART + "/"
+ ERPath.SOURCE_PATH_PART + "/{" + SOURCE_ID_PATH_PARAM + "}/"
+ ERPath.TARGET_PATH_PART + "/{" + TARGET_ID_PATH_PARAM + "}/{"
+ TYPE_PATH_PARAM + "}")
@Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 })
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public Response attachResource(
@PathParam(SOURCE_ID_PATH_PARAM) String sourceResourceUUID,
@PathParam(TARGET_ID_PATH_PARAM) String targetResourceUUID,
@PathParam(TYPE_PATH_PARAM) String type, String json)
throws ResourceNotFoundException, ResourceRegistryException {
logger.info(
"requested to attach source {} {} and target {} {} ({} Type {}) with properties {}",
Resource.NAME, sourceResourceUUID, Resource.NAME,
targetResourceUUID, IsRelatedTo.class.getSimpleName(), type,
json);
IsRelatedToManagement isRelatedToManagement = new IsRelatedToManagement();
isRelatedToManagement.setElementType(type);
isRelatedToManagement.setJSON(json);
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 * e.g. PUT /resource-registry/er/isRelatedTo/Hosts
* *
* BODY: {...} * BODY: {...}
* *
* @param type
* @param definition
* @return
* @throws ResourceAlreadyPresentException
* @throws ResourceRegistryException
*/ */
@PUT @PUT
@Path(ERPath.IS_RELATED_TO_PATH_PART + "/{" + TYPE_PATH_PARAM + "}") @Path(ERPath.IS_RELATED_TO_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
@Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 }) @Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 })
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8) @Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public Response createIsRelatedTo(@PathParam(TYPE_PATH_PARAM) String type, public Response createIsRelatedTo(@PathParam(TYPE_PATH_PARAM) String type, String json)
String json) throws ResourceAlreadyPresentException, ResourceRegistryException { throws ResourceAlreadyPresentException, ResourceRegistryException {
logger.info( CalledMethodProvider.instance.set(
"Requested to create {} {} of type {} : {}", HTTPMETHOD.PUT.name() + "/" + ERPath.ER_PATH_PART +
IsRelatedTo.NAME, Relation.NAME, type, json); "/" + ERPath.IS_RELATED_TO_PATH_PART + "/" + type);
logger.info("Requested to create {} {} of type {} : {}", IsRelatedTo.NAME, Relation.NAME, type, json);
IsRelatedToManagement isRelatedToManagement = new IsRelatedToManagement(); IsRelatedToManagement isRelatedToManagement = new IsRelatedToManagement();
isRelatedToManagement.setElementType(type); isRelatedToManagement.setElementType(type);
isRelatedToManagement.setJSON(json); isRelatedToManagement.setJSON(json);
String ret = isRelatedToManagement.create(); String ret = isRelatedToManagement.create();
return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8).build(); return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
.build();
} }
/** /**
* e.g. DELETE * e.g. DELETE /resource-registry/er/isRelatedTo/b3982715-a7aa-4530-9a5f-2f60008d256e
* /resource-registry/er/isRelatedTo/b3982715-a7aa-4530-9a5f-2f60008d256e
* *
* @param relatedToUUID
* @return
* @throws ResourceRegistryException
*/ */
@DELETE @DELETE
@Path(ERPath.IS_RELATED_TO_PATH_PART + "/{" + ID_PATH_PARAM + "}") @Path(ERPath.IS_RELATED_TO_PATH_PART + "/{" + ID_PATH_PARAM + "}")
public boolean detachResource(@PathParam(ID_PATH_PARAM) String relatedToUUID) public boolean detachResource(@PathParam(ID_PATH_PARAM) String relatedToUUID) throws ResourceRegistryException {
throws ResourceRegistryException { 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 detach {}", relatedToUUID);
IsRelatedToManagement isRelatedToManagement = new IsRelatedToManagement(); IsRelatedToManagement isRelatedToManagement = new IsRelatedToManagement();
isRelatedToManagement.setUUID(UUID.fromString(relatedToUUID)); isRelatedToManagement.setUUID(UUID.fromString(relatedToUUID));
@ -379,96 +266,75 @@ public class ERManager {
} }
/** /**
* e.g POST * e.g POST /resource-registry/er/add/resource/67062c11-9c3a-4906-870d-7df6a43408b0
* /resource-registry/er/add/resource/67062c11-9c3a-4906-870d-7df6a43408b0
* *
* @param uuid
* @return
* @throws ResourceNotFoundException
* @throws ContextNotFoundException
* @throws ResourceRegistryException
*/ */
@POST @POST
@Path(ERPath.ADD_PATH_PART + "/" + ERPath.RESOURCE_PATH_PART + "/{" @Path(ERPath.ADD_PATH_PART + "/" + ERPath.RESOURCE_PATH_PART + "/{" + ID_PATH_PARAM + "}")
+ ID_PATH_PARAM + "}")
public boolean addResourceToContext(@PathParam(ID_PATH_PARAM) String uuid) public boolean addResourceToContext(@PathParam(ID_PATH_PARAM) String uuid)
throws ResourceNotFoundException, ContextNotFoundException, throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
ResourceRegistryException { CalledMethodProvider.instance.set(
logger.info("requested to add {} with UUID {} to current context {}", HTTPMETHOD.POST.name() + "/" + ERPath.ER_PATH_PART +
Resource.NAME, uuid, ContextUtility.getCurrentContext()); "/" + ERPath.ADD_PATH_PART + "/" + ERPath.RESOURCE_PATH_PART + "/{" + ID_PATH_PARAM + "}");
logger.info("requested to add {} with UUID {} to current context {}", Resource.NAME, uuid,
ContextUtility.getCurrentContext());
ResourceManagement resourceManagement = new ResourceManagement(); ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(UUID.fromString(uuid)); resourceManagement.setUUID(UUID.fromString(uuid));
return resourceManagement.addToContext(); return resourceManagement.addToContext();
} }
/** /**
* e.g POST * e.g POST /resource-registry/er/add/facet/f6931232-c034-4979-9b2f-7193d3fba7df
* /resource-registry/er/add/facet/f6931232-c034-4979-9b2f-7193d3fba7df
* *
* @param uuid
* @return
* @throws FacetNotFoundException
* @throws ContextNotFoundException
* @throws ResourceRegistryException
*/ */
@POST @POST
@Path(ERPath.ADD_PATH_PART + "/" + ERPath.FACET_PATH_PART + "/{" @Path(ERPath.ADD_PATH_PART + "/" + ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}")
+ ID_PATH_PARAM + "}")
public boolean addFacetToContext(@PathParam(ID_PATH_PARAM) String uuid) public boolean addFacetToContext(@PathParam(ID_PATH_PARAM) String uuid)
throws FacetNotFoundException, ContextNotFoundException, throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
ResourceRegistryException { CalledMethodProvider.instance.set(
logger.info("requested to add {} with UUID {} to current context {}", HTTPMETHOD.POST.name() + "/" + ERPath.ER_PATH_PART +
Facet.NAME, uuid, ContextUtility.getCurrentContext()); "/" + ERPath.ADD_PATH_PART + "/" + ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}");
logger.info("requested to add {} with UUID {} to current context {}", Facet.NAME, uuid,
ContextUtility.getCurrentContext());
FacetManagement facetManagement = new FacetManagement(); FacetManagement facetManagement = new FacetManagement();
facetManagement.setUUID(UUID.fromString(uuid)); facetManagement.setUUID(UUID.fromString(uuid));
return facetManagement.addToContext(); return facetManagement.addToContext();
} }
/** /**
* e.g POST * e.g POST /resource-registry/er/remove/resource/67062c11-9c3a-4906-870d-7df6a43408b0
* /resource-registry/er/remove/resource/67062c11-9c3a-4906-870d-7df6a43408b0
* *
* @param uuid
* @return
* @throws ResourceNotFoundException
* @throws ContextNotFoundException
* @throws ResourceRegistryException
*/ */
@POST @POST
@Path(ERPath.REMOVE_PATH_PART + "/" + ERPath.RESOURCE_PATH_PART + "/{" @Path(ERPath.REMOVE_PATH_PART + "/" + ERPath.RESOURCE_PATH_PART + "/{" + ID_PATH_PARAM + "}")
+ ID_PATH_PARAM + "}")
public boolean removeResourceFromContext(@PathParam(ID_PATH_PARAM) String uuid) public boolean removeResourceFromContext(@PathParam(ID_PATH_PARAM) String uuid)
throws ResourceNotFoundException, ContextNotFoundException, throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
ResourceRegistryException { CalledMethodProvider.instance.set(
logger.info("requested to remove {} with UUID {} from current context {}", HTTPMETHOD.POST.name() + "/" + ERPath.ER_PATH_PART +
Resource.NAME, uuid, ContextUtility.getCurrentContext()); "/" + ERPath.REMOVE_PATH_PART + "/" + ERPath.RESOURCE_PATH_PART + "/{" + ID_PATH_PARAM + "}");
logger.info("requested to remove {} with UUID {} from current context {}", Resource.NAME, uuid,
ContextUtility.getCurrentContext());
ResourceManagement resourceManagement = new ResourceManagement(); ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(UUID.fromString(uuid)); resourceManagement.setUUID(UUID.fromString(uuid));
return resourceManagement.removeFromContext(); return resourceManagement.removeFromContext();
} }
/** /**
* e.g POST * e.g POST /resource-registry/er/remove/facet/f6931232-c034-4979-9b2f-7193d3fba7df
* /resource-registry/er/remove/facet/f6931232-c034-4979-9b2f-7193d3fba7df
* *
* @param uuid
* @return
* @throws FacetNotFoundException
* @throws ContextNotFoundException
* @throws ResourceRegistryException
*/ */
@POST @POST
@Path(ERPath.REMOVE_PATH_PART + "/" + ERPath.FACET_PATH_PART + "/{" @Path(ERPath.REMOVE_PATH_PART + "/" + ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}")
+ ID_PATH_PARAM + "}")
public boolean removeFacetFromContext(@PathParam(ID_PATH_PARAM) String uuid) public boolean removeFacetFromContext(@PathParam(ID_PATH_PARAM) String uuid)
throws FacetNotFoundException, ContextNotFoundException, throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
ResourceRegistryException { CalledMethodProvider.instance.set(
logger.info("requested to remove {} with UUID {} from current context {}", HTTPMETHOD.POST.name() + "/" + ERPath.ER_PATH_PART +
Facet.NAME, uuid, ContextUtility.getCurrentContext()); "/" + ERPath.REMOVE_PATH_PART + "/" + ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}");
logger.info("requested to remove {} with UUID {} from current context {}", Facet.NAME, uuid,
ContextUtility.getCurrentContext());
FacetManagement facetManagement = new FacetManagement(); FacetManagement facetManagement = new FacetManagement();
facetManagement.setUUID(UUID.fromString(uuid)); facetManagement.setUUID(UUID.fromString(uuid));
return facetManagement.removeFromContext(); return facetManagement.removeFromContext();
} }
} }

View File

@ -27,6 +27,7 @@ import org.gcube.informationsystem.impl.entity.facet.SoftwareFacetImpl;
import org.gcube.informationsystem.impl.entity.facet.StateFacetImpl; import org.gcube.informationsystem.impl.entity.facet.StateFacetImpl;
import org.gcube.informationsystem.impl.entity.resource.EServiceImpl; import org.gcube.informationsystem.impl.entity.resource.EServiceImpl;
import org.gcube.informationsystem.impl.entity.resource.HostingNodeImpl; import org.gcube.informationsystem.impl.entity.resource.HostingNodeImpl;
import org.gcube.informationsystem.impl.relation.ConsistsOfImpl;
import org.gcube.informationsystem.impl.relation.IsIdentifiedByImpl; import org.gcube.informationsystem.impl.relation.IsIdentifiedByImpl;
import org.gcube.informationsystem.impl.relation.isrelatedto.HostsImpl; import org.gcube.informationsystem.impl.relation.isrelatedto.HostsImpl;
import org.gcube.informationsystem.impl.utils.ISMapper; import org.gcube.informationsystem.impl.utils.ISMapper;
@ -385,14 +386,14 @@ public class ERManagementTest extends ScopedTest {
Facet shared = hostingNode.getConsistsOf().get(0).getTarget(); Facet shared = hostingNode.getConsistsOf().get(0).getTarget();
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement(); ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
consistsOfManagement.setElementType(ConsistsOf.NAME); consistsOfManagement.setElementType(ConsistsOf.NAME);
consistsOfManagement.setJSON("{}"); consistsOfManagement.setJSON("{}");
ConsistsOf<EService, Facet> consistsOf = new ConsistsOfImpl<>(eService, shared, null);
consistsOfManagement.setJSON(ISMapper.marshal(consistsOf));
UUID eServiceUUID = eService.getHeader().getUUID(); String json = consistsOfManagement.create();
UUID sharedFacetUUID = shared.getHeader().getUUID();
String json = consistsOfManagement.create(eServiceUUID, sharedFacetUUID);
logger.debug("Created : {}", json); logger.debug("Created : {}", json);
ResourceManagement resourceManagement = new ResourceManagement(); ResourceManagement resourceManagement = new ResourceManagement();
@ -406,6 +407,7 @@ public class ERManagementTest extends ScopedTest {
Assert.assertTrue(deleted); Assert.assertTrue(deleted);
FacetManagement facetManagement = new FacetManagement(); FacetManagement facetManagement = new FacetManagement();
UUID sharedFacetUUID = shared.getHeader().getUUID();
facetManagement.setUUID(sharedFacetUUID); facetManagement.setUUID(sharedFacetUUID);
try { try {
@ -424,7 +426,8 @@ public class ERManagementTest extends ScopedTest {
resourceManagement.setJSON("{}"); resourceManagement.setJSON("{}");
String json = resourceManagement.create(); String json = resourceManagement.create();
UUID resourceUUID = Utility.getUUIDFromJSONString(json); HostingNode hostingNode = ISMapper.unmarshal(HostingNode.class, json);
UUID resourceUUID = hostingNode.getHeader().getUUID();
CPUFacet cpuFacet = new CPUFacetImpl(); CPUFacet cpuFacet = new CPUFacetImpl();
cpuFacet.setClockSpeed("1 GHz"); cpuFacet.setClockSpeed("1 GHz");
@ -434,16 +437,14 @@ public class ERManagementTest extends ScopedTest {
FacetManagement facetManagement = new FacetManagement(); FacetManagement facetManagement = new FacetManagement();
facetManagement.setJSON(ISMapper.marshal(cpuFacet)); facetManagement.setJSON(ISMapper.marshal(cpuFacet));
facetManagement.setElementType(CPUFacet.NAME); facetManagement.setElementType(CPUFacet.NAME);
json = facetManagement.create(); json = facetManagement.create();
logger.debug("Created : {}", json); CPUFacet createdCPUFacet = ISMapper.unmarshal(CPUFacet.class, json);
UUID facetUUID = Utility.getUUIDFromJSONString(json);
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement(); ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
consistsOfManagement.setElementType(ConsistsOf.NAME); consistsOfManagement.setElementType(ConsistsOf.NAME);
consistsOfManagement.setJSON("{}"); ConsistsOf<HostingNode, CPUFacet> consistsOf = new ConsistsOfImpl<>(hostingNode, createdCPUFacet, null);
consistsOfManagement.setJSON(ISMapper.marshal(consistsOf));
json = consistsOfManagement.create(resourceUUID, facetUUID); json = consistsOfManagement.create();
logger.debug("Facet attached : {}", json); logger.debug("Facet attached : {}", json);

View File

@ -373,8 +373,7 @@ public class BasicTest extends ScopedTest {
isRelatedToManagement.setElementType(Hosts.NAME); isRelatedToManagement.setElementType(Hosts.NAME);
String hostsJson = ISMapper.marshal(hosts); String hostsJson = ISMapper.marshal(hosts);
isRelatedToManagement.setJSON(hostsJson); isRelatedToManagement.setJSON(hostsJson);
String createdHostsJson = isRelatedToManagement.create();
String createdHostsJson = isRelatedToManagement.create(hnUUID, eServiceUUID);
logger.debug("Created : {}", createdHostsJson); logger.debug("Created : {}", createdHostsJson);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")