diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/context/ContextManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/context/ContextManagement.java index 5091b7d..811336a 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/context/ContextManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/context/ContextManagement.java @@ -60,10 +60,6 @@ public class ContextManagement extends EntityManagement { getWorkingContext(); } - public UUID getUUID() { - return uuid; - } - public String getName() { if(name == null) { if(element == null) { diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/er/ERManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/er/ERManagement.java index 5b951f8..2ef3cc3 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/er/ERManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/er/ERManagement.java @@ -85,6 +85,10 @@ public abstract class ERManagement { protected El element; protected boolean reload; + public UUID getUUID() { + return uuid; + } + public boolean isReload() { return reload; } 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 f984efb..705471e 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/ERManager.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/ERManager.java @@ -2,6 +2,7 @@ package org.gcube.informationsystem.resourceregistry.rest; import java.util.UUID; +import javax.mail.Header; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.POST; @@ -21,6 +22,7 @@ import org.gcube.informationsystem.model.relation.ConsistsOf; import org.gcube.informationsystem.model.relation.IsRelatedTo; 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.ContextNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException; @@ -47,24 +49,34 @@ public class ERManager { public static final String TYPE_PATH_PARAM = "type"; /** - * e.g. PUT /resource-registry/er/facet/ContactFacet + * e.g. PUT /resource-registry/er/facets/ContactFacet * * BODY: {...} * */ @PUT - @Path(ERPath.FACETS_PATH_PART + "/{" + TYPE_PATH_PARAM + "}") + @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 { CalledMethodProvider.instance - .set(HTTPMETHOD.PUT.name() + " /" + ERPath.ER_PATH_PART + "/" + ERPath.FACETS_PATH_PART + "/" + type); + .set(HTTPMETHOD.PUT.name() + " /" + ERPath.ER_PATH_PART + "/" + ERPath.FACET_PATH_PART + "/" + type); 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); + + UUID uuid = facetManagement.getUUID(); + if(uuid!=null) { + String error = String.format("Could not specify an UUID in % to create a %s using POST. Please use PUT instead and specify the UUID as path argument.", + Header.class.getSimpleName(), Facet.NAME); + logger.info(error); + throw new ContextCreationException(error); + } + + String ret = facetManagement.create(); return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8) .build(); @@ -77,13 +89,13 @@ public class ERManager { * */ @POST - @Path(ERPath.FACETS_PATH_PART + "/{" + ID_PATH_PARAM + "}") + @Path(ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}") @Consumes({MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8}) @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.FACETS_PATH_PART + "/{" + ID_PATH_PARAM + "}"); + + ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}"); 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(); @@ -97,11 +109,11 @@ public class ERManager { * */ @DELETE - @Path(ERPath.FACETS_PATH_PART + "/{" + ID_PATH_PARAM + "}") + @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.FACETS_PATH_PART + "/{" + ID_PATH_PARAM + "}"); + + ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}"); logger.info("Requested to delete {} with id {}", Facet.NAME, uuid); FacetManagement facetManagement = new FacetManagement(); facetManagement.setUUID(UUID.fromString(uuid)); @@ -273,11 +285,11 @@ public class ERManager { * */ @POST - @Path(ERPath.ADD_PATH_PART + "/" + ERPath.FACETS_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 { CalledMethodProvider.instance.set(HTTPMETHOD.POST.name() + " /" + ERPath.ER_PATH_PART + "/" - + ERPath.ADD_PATH_PART + "/" + ERPath.FACETS_PATH_PART + "/{" + ID_PATH_PARAM + "}"); + + ERPath.ADD_PATH_PART + "/" + ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}"); logger.info("Requested to add {} with UUID {} to current {}", Facet.NAME, uuid, Context.NAME); FacetManagement facetManagement = new FacetManagement(); facetManagement.setUUID(UUID.fromString(uuid)); @@ -307,11 +319,11 @@ public class ERManager { * */ @POST - @Path(ERPath.REMOVE_PATH_PART + "/" + ERPath.FACETS_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 { CalledMethodProvider.instance.set(HTTPMETHOD.POST.name() + " /" + ERPath.ER_PATH_PART + "/" - + ERPath.REMOVE_PATH_PART + "/" + ERPath.FACETS_PATH_PART + "/{" + ID_PATH_PARAM + "}"); + + ERPath.REMOVE_PATH_PART + "/" + ERPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}"); logger.info("Requested to remove {} with UUID {} from current {}", Facet.NAME, uuid, Context.NAME); FacetManagement facetManagement = new FacetManagement(); facetManagement.setUUID(UUID.fromString(uuid));