From 31901d5ce3aeaa6ae805a7bc3ab2c6d050807285 Mon Sep 17 00:00:00 2001 From: "luca.frosini" Date: Tue, 27 Jun 2017 15:22:19 +0000 Subject: [PATCH] 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 --- .../er/relation/RelationManagement.java | 7 +- .../resourceregistry/rest/ERManager.java | 342 ++++++------------ .../resourceregistry/er/ERManagementTest.java | 23 +- .../er/multicontext/BasicTest.java | 3 +- 4 files changed, 121 insertions(+), 254 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/er/relation/RelationManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/er/relation/RelationManagement.java index a0aab8c..dc1cdb7 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/er/relation/RelationManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/er/relation/RelationManagement.java @@ -169,7 +169,7 @@ public abstract class RelationManagement extends return visitedSourceResources; } - public Edge reallyCreate(UUID sourceUUID, UUID targetUUID) + private Edge reallyCreate(UUID sourceUUID, UUID targetUUID) throws ResourceRegistryException { ResourceManagement srmSource = new ResourceManagement(orientGraph); srmSource.setUUID(sourceUUID); @@ -182,7 +182,7 @@ public abstract class RelationManagement extends return reallyCreate(source, target); } - + protected Edge reallyCreate(Vertex source, Vertex target) throws ResourceRegistryException { @@ -617,7 +617,8 @@ public abstract class RelationManagement extends return true; } - public String create(UUID sourceUUID, UUID targetUUID) + @SuppressWarnings("unused") + private String create(UUID sourceUUID, UUID targetUUID) throws ResourceRegistryException { try { orientGraph = ContextUtility diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/ERManager.java b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/ERManager.java index d9e9b96..88aaeab 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/ERManager.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/ERManager.java @@ -13,6 +13,7 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; 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.Resource; 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.ResourceNotFoundException; 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.er.entity.FacetManagement; 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 TYPE_PATH_PARAM = "type"; + /* public static final String SOURCE_ID_PATH_PARAM = "sourceId"; public static final String TARGET_ID_PATH_PARAM = "targetId"; - - /* Facets Methods */ + */ + /** * e.g. PUT /resource-registry/er/facet/ContactFacet * * BODY: {...} * - * @param type - * @param definition - * @return - * @throws FacetAlreadyPresentException - * @throws ResourceRegistryException */ @PUT @Path(ERPath.FACET_PATH_PART + "/{" + TYPE_PATH_PARAM + "}") @Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 }) @Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8) - public Response createFacet(@PathParam(TYPE_PATH_PARAM) String type, - String json) throws FacetAlreadyPresentException, ResourceRegistryException { + public Response createFacet(@PathParam(TYPE_PATH_PARAM) String type, String json) + 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.trace("requested facet creation for type {} defined by {} ", - type, json); + logger.trace("requested facet creation for type {} defined by {} ", type, json); FacetManagement facetManagement = new FacetManagement(); facetManagement.setElementType(type); facetManagement.setJSON(json); 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- - * 83ef-49ffcbfc7d86 + * e.g. POST /resource-registry/er/facet/4023d5b2-8601-47a5-83ef-49ffcbfc7d86 * * BODY: {...} * - * @param uuid - * @param definition - * @return - * @throws FacetNotFoundException - * @throws ResourceRegistryException */ @POST @Path(ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}") @@ -94,6 +89,9 @@ public class ERManager { @Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8) public String updateFacet(@PathParam(ID_PATH_PARAM) String uuid, String json) 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.trace("requested facet update for id {} with {}", uuid, json); FacetManagement facetManagement = new FacetManagement(); @@ -103,18 +101,16 @@ public class ERManager { } /** - * e.g. DELETE - * /resource-registry/er/facet/4023d5b2-8601-47a5-83ef-49ffcbfc7d86 + * e.g. DELETE /resource-registry/er/facet/4023d5b2-8601-47a5-83ef-49ffcbfc7d86 * - * @param uuid - * @return - * @throws FacetNotFoundException - * @throws ResourceRegistryException */ @DELETE @Path(ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}") public boolean deleteFacet(@PathParam(ID_PATH_PARAM) String uuid) 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); FacetManagement facetManagement = new FacetManagement(); facetManagement.setUUID(UUID.fromString(uuid)); @@ -128,44 +124,41 @@ public class ERManager { * * BODY: {...} * - * @param type - * @param definition - * @return - * @throws ResourceAlreadyPresentException - * @throws ResourceRegistryException */ @PUT @Path(ERPath.RESOURCE_PATH_PART + "/{" + TYPE_PATH_PARAM + "}") @Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 }) @Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8) - public Response createResource(@PathParam(TYPE_PATH_PARAM) String type, - String json) throws ResourceAlreadyPresentException, ResourceRegistryException { + public Response createResource(@PathParam(TYPE_PATH_PARAM) String type, String json) + 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.trace("requested resource creation for type {} with json {}", - type, json); + logger.trace("requested resource creation for type {} with json {}", type, json); ResourceManagement resourceManagement = new ResourceManagement(); resourceManagement.setElementType(type); resourceManagement.setJSON(json); 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 * - * @param uuid - * @param json - * @return - * @throws ResourceNotFoundException - * @throws ResourceRegistryException + * BODY: {...} + * */ @POST @Path(ERPath.RESOURCE_PATH_PART + "/{" + ID_PATH_PARAM + "}") @Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 }) @Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8) - public String updateResource(@PathParam(ID_PATH_PARAM) String uuid, - String json) throws ResourceNotFoundException, - ResourceRegistryException { + public String updateResource(@PathParam(ID_PATH_PARAM) String uuid, String json) + throws ResourceNotFoundException, 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.trace("requested resource update for id {} with {}", uuid, json); ResourceManagement resourceManagement = new ResourceManagement(); @@ -175,203 +168,97 @@ public class ERManager { } /** - * e.g. DELETE - * /resource-registry/er/resource/67062c11-9c3a-4906-870d-7df6a43408b0 + * e.g. DELETE /resource-registry/er/resource/67062c11-9c3a-4906-870d-7df6a43408b0 * - * @param uuid - * @return - * @throws ResourceNotFoundException - * @throws Exception */ @DELETE @Path(ERPath.RESOURCE_PATH_PART + "/{" + ID_PATH_PARAM + "}") - public boolean deleteResource(@PathParam(ID_PATH_PARAM) String uuid) - throws ResourceNotFoundException, Exception { + public boolean deleteResource(@PathParam(ID_PATH_PARAM) String uuid) 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); ResourceManagement resourceManagement = new ResourceManagement(); resourceManagement.setUUID(UUID.fromString(uuid)); 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 * * 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); - logger.trace( - "Requested to create {} {} of type {} : {}", - ConsistsOf.NAME, Relation.NAME, type, json); + public Response createConsistsOf(@PathParam(TYPE_PATH_PARAM) String type, String json) + throws ResourceAlreadyPresentException, ResourceRegistryException { + 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); 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(); + 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 + * e.g. DELETE /resource-registry/er/consistsOf/9bff49c8-c0a7-45de-827c-accb71defbd3 * - * @param consistOfUUID - * @return - * @throws ResourceRegistryException */ @DELETE @Path(ERPath.CONSISTS_OF_PATH_PART + "/{" + ID_PATH_PARAM + "}") - public boolean detachFacet(@PathParam(ID_PATH_PARAM) String consistOfUUID) - throws ResourceRegistryException { + public boolean detachFacet(@PathParam(ID_PATH_PARAM) String consistOfUUID) 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); ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement(); consistsOfManagement.setUUID(UUID.fromString(consistOfUUID)); 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 * * 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); + public Response createIsRelatedTo(@PathParam(TYPE_PATH_PARAM) String type, String json) + throws ResourceAlreadyPresentException, ResourceRegistryException { + 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); 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(); + return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8) + .build(); } /** - * e.g. DELETE - * /resource-registry/er/isRelatedTo/b3982715-a7aa-4530-9a5f-2f60008d256e + * e.g. DELETE /resource-registry/er/isRelatedTo/b3982715-a7aa-4530-9a5f-2f60008d256e * - * @param relatedToUUID - * @return - * @throws ResourceRegistryException */ @DELETE @Path(ERPath.IS_RELATED_TO_PATH_PART + "/{" + ID_PATH_PARAM + "}") - public boolean detachResource(@PathParam(ID_PATH_PARAM) String relatedToUUID) - throws ResourceRegistryException { + public boolean detachResource(@PathParam(ID_PATH_PARAM) String relatedToUUID) 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); IsRelatedToManagement isRelatedToManagement = new IsRelatedToManagement(); isRelatedToManagement.setUUID(UUID.fromString(relatedToUUID)); @@ -379,96 +266,75 @@ public class ERManager { } /** - * e.g POST - * /resource-registry/er/add/resource/67062c11-9c3a-4906-870d-7df6a43408b0 + * e.g POST /resource-registry/er/add/resource/67062c11-9c3a-4906-870d-7df6a43408b0 * - * @param uuid - * @return - * @throws ResourceNotFoundException - * @throws ContextNotFoundException - * @throws ResourceRegistryException */ @POST - @Path(ERPath.ADD_PATH_PART + "/" + ERPath.RESOURCE_PATH_PART + "/{" - + ID_PATH_PARAM + "}") + @Path(ERPath.ADD_PATH_PART + "/" + ERPath.RESOURCE_PATH_PART + "/{" + ID_PATH_PARAM + "}") public boolean addResourceToContext(@PathParam(ID_PATH_PARAM) String uuid) - throws ResourceNotFoundException, ContextNotFoundException, - ResourceRegistryException { - logger.info("requested to add {} with UUID {} to current context {}", - Resource.NAME, uuid, ContextUtility.getCurrentContext()); + throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + 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, + ContextUtility.getCurrentContext()); ResourceManagement resourceManagement = new ResourceManagement(); resourceManagement.setUUID(UUID.fromString(uuid)); return resourceManagement.addToContext(); } /** - * e.g POST - * /resource-registry/er/add/facet/f6931232-c034-4979-9b2f-7193d3fba7df + * e.g POST /resource-registry/er/add/facet/f6931232-c034-4979-9b2f-7193d3fba7df * - * @param uuid - * @return - * @throws FacetNotFoundException - * @throws ContextNotFoundException - * @throws ResourceRegistryException */ @POST - @Path(ERPath.ADD_PATH_PART + "/" + ERPath.FACET_PATH_PART + "/{" - + ID_PATH_PARAM + "}") + @Path(ERPath.ADD_PATH_PART + "/" + ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}") public boolean addFacetToContext(@PathParam(ID_PATH_PARAM) String uuid) - throws FacetNotFoundException, ContextNotFoundException, - ResourceRegistryException { - logger.info("requested to add {} with UUID {} to current context {}", - Facet.NAME, uuid, ContextUtility.getCurrentContext()); + throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { + 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, + ContextUtility.getCurrentContext()); FacetManagement facetManagement = new FacetManagement(); facetManagement.setUUID(UUID.fromString(uuid)); - return facetManagement.addToContext(); + return facetManagement.addToContext(); } - + /** - * e.g POST - * /resource-registry/er/remove/resource/67062c11-9c3a-4906-870d-7df6a43408b0 + * e.g POST /resource-registry/er/remove/resource/67062c11-9c3a-4906-870d-7df6a43408b0 * - * @param uuid - * @return - * @throws ResourceNotFoundException - * @throws ContextNotFoundException - * @throws ResourceRegistryException */ @POST - @Path(ERPath.REMOVE_PATH_PART + "/" + ERPath.RESOURCE_PATH_PART + "/{" - + ID_PATH_PARAM + "}") + @Path(ERPath.REMOVE_PATH_PART + "/" + ERPath.RESOURCE_PATH_PART + "/{" + ID_PATH_PARAM + "}") public boolean removeResourceFromContext(@PathParam(ID_PATH_PARAM) String uuid) - throws ResourceNotFoundException, ContextNotFoundException, - ResourceRegistryException { - logger.info("requested to remove {} with UUID {} from current context {}", - Resource.NAME, uuid, ContextUtility.getCurrentContext()); + throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + 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, + ContextUtility.getCurrentContext()); ResourceManagement resourceManagement = new ResourceManagement(); resourceManagement.setUUID(UUID.fromString(uuid)); return resourceManagement.removeFromContext(); } /** - * e.g POST - * /resource-registry/er/remove/facet/f6931232-c034-4979-9b2f-7193d3fba7df + * e.g POST /resource-registry/er/remove/facet/f6931232-c034-4979-9b2f-7193d3fba7df * - * @param uuid - * @return - * @throws FacetNotFoundException - * @throws ContextNotFoundException - * @throws ResourceRegistryException */ @POST - @Path(ERPath.REMOVE_PATH_PART + "/" + ERPath.FACET_PATH_PART + "/{" - + ID_PATH_PARAM + "}") + @Path(ERPath.REMOVE_PATH_PART + "/" + ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}") public boolean removeFacetFromContext(@PathParam(ID_PATH_PARAM) String uuid) - throws FacetNotFoundException, ContextNotFoundException, - ResourceRegistryException { - logger.info("requested to remove {} with UUID {} from current context {}", - Facet.NAME, uuid, ContextUtility.getCurrentContext()); + throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { + 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, + ContextUtility.getCurrentContext()); FacetManagement facetManagement = new FacetManagement(); facetManagement.setUUID(UUID.fromString(uuid)); - return facetManagement.removeFromContext(); + return facetManagement.removeFromContext(); } - } diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/er/ERManagementTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/er/ERManagementTest.java index bc9ea36..909ae29 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/er/ERManagementTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/er/ERManagementTest.java @@ -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.resource.EServiceImpl; 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.isrelatedto.HostsImpl; import org.gcube.informationsystem.impl.utils.ISMapper; @@ -385,14 +386,14 @@ public class ERManagementTest extends ScopedTest { Facet shared = hostingNode.getConsistsOf().get(0).getTarget(); + ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement(); consistsOfManagement.setElementType(ConsistsOf.NAME); consistsOfManagement.setJSON("{}"); + ConsistsOf consistsOf = new ConsistsOfImpl<>(eService, shared, null); + consistsOfManagement.setJSON(ISMapper.marshal(consistsOf)); - UUID eServiceUUID = eService.getHeader().getUUID(); - UUID sharedFacetUUID = shared.getHeader().getUUID(); - - String json = consistsOfManagement.create(eServiceUUID, sharedFacetUUID); + String json = consistsOfManagement.create(); logger.debug("Created : {}", json); ResourceManagement resourceManagement = new ResourceManagement(); @@ -406,6 +407,7 @@ public class ERManagementTest extends ScopedTest { Assert.assertTrue(deleted); FacetManagement facetManagement = new FacetManagement(); + UUID sharedFacetUUID = shared.getHeader().getUUID(); facetManagement.setUUID(sharedFacetUUID); try { @@ -424,7 +426,8 @@ public class ERManagementTest extends ScopedTest { resourceManagement.setJSON("{}"); 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.setClockSpeed("1 GHz"); @@ -434,16 +437,14 @@ public class ERManagementTest extends ScopedTest { FacetManagement facetManagement = new FacetManagement(); facetManagement.setJSON(ISMapper.marshal(cpuFacet)); facetManagement.setElementType(CPUFacet.NAME); - json = facetManagement.create(); - logger.debug("Created : {}", json); - UUID facetUUID = Utility.getUUIDFromJSONString(json); + CPUFacet createdCPUFacet = ISMapper.unmarshal(CPUFacet.class, json); ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement(); consistsOfManagement.setElementType(ConsistsOf.NAME); - consistsOfManagement.setJSON("{}"); - - json = consistsOfManagement.create(resourceUUID, facetUUID); + ConsistsOf consistsOf = new ConsistsOfImpl<>(hostingNode, createdCPUFacet, null); + consistsOfManagement.setJSON(ISMapper.marshal(consistsOf)); + json = consistsOfManagement.create(); logger.debug("Facet attached : {}", json); diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/er/multicontext/BasicTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/er/multicontext/BasicTest.java index d223f53..69a0539 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/er/multicontext/BasicTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/er/multicontext/BasicTest.java @@ -373,8 +373,7 @@ public class BasicTest extends ScopedTest { isRelatedToManagement.setElementType(Hosts.NAME); String hostsJson = ISMapper.marshal(hosts); isRelatedToManagement.setJSON(hostsJson); - - String createdHostsJson = isRelatedToManagement.create(hnUUID, eServiceUUID); + String createdHostsJson = isRelatedToManagement.create(); logger.debug("Created : {}", createdHostsJson); @SuppressWarnings("unchecked")