Refs #11288: Made resource-registry more RESTful
Task-Url: https://support.d4science.org/issues/11288 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@167868 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
8571ea190e
commit
19fec74668
|
@ -60,10 +60,6 @@ public class ContextManagement extends EntityManagement<Context> {
|
||||||
getWorkingContext();
|
getWorkingContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getUUID() {
|
|
||||||
return uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
if(name == null) {
|
if(name == null) {
|
||||||
if(element == null) {
|
if(element == null) {
|
||||||
|
|
|
@ -85,6 +85,10 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
||||||
protected El element;
|
protected El element;
|
||||||
protected boolean reload;
|
protected boolean reload;
|
||||||
|
|
||||||
|
public UUID getUUID() {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isReload() {
|
public boolean isReload() {
|
||||||
return reload;
|
return reload;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.gcube.informationsystem.resourceregistry.rest;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import javax.mail.Header;
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.DELETE;
|
import javax.ws.rs.DELETE;
|
||||||
import javax.ws.rs.POST;
|
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.model.relation.IsRelatedTo;
|
||||||
import org.gcube.informationsystem.resourceregistry.ResourceInitializer;
|
import org.gcube.informationsystem.resourceregistry.ResourceInitializer;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
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.context.ContextNotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAlreadyPresentException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAlreadyPresentException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException;
|
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";
|
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: {...}
|
* BODY: {...}
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@PUT
|
@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})
|
@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, String json)
|
public Response createFacet(@PathParam(TYPE_PATH_PARAM) String type, String json)
|
||||||
throws FacetAlreadyPresentException, ResourceRegistryException {
|
throws FacetAlreadyPresentException, ResourceRegistryException {
|
||||||
CalledMethodProvider.instance
|
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.info("Requested to create {} of type {}", Facet.NAME, type);
|
||||||
logger.trace("Requested to create {} of type {} defined by {} ", Facet.NAME, type, json);
|
logger.trace("Requested to create {} of type {} defined by {} ", Facet.NAME, type, json);
|
||||||
FacetManagement facetManagement = new FacetManagement();
|
FacetManagement facetManagement = new FacetManagement();
|
||||||
facetManagement.setElementType(type);
|
facetManagement.setElementType(type);
|
||||||
facetManagement.setJSON(json);
|
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();
|
String ret = facetManagement.create();
|
||||||
return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||||
.build();
|
.build();
|
||||||
|
@ -77,13 +89,13 @@ public class ERManager {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@POST
|
@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})
|
@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 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 + "/"
|
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.info("Requested to update {} with id {}", Facet.NAME, uuid);
|
||||||
logger.trace("Requested to update {} with id {} with json {}", Facet.NAME, uuid, json);
|
logger.trace("Requested to update {} with id {} with json {}", Facet.NAME, uuid, json);
|
||||||
FacetManagement facetManagement = new FacetManagement();
|
FacetManagement facetManagement = new FacetManagement();
|
||||||
|
@ -97,11 +109,11 @@ public class ERManager {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@DELETE
|
@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)
|
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 + "/"
|
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);
|
logger.info("Requested to delete {} with id {}", Facet.NAME, uuid);
|
||||||
FacetManagement facetManagement = new FacetManagement();
|
FacetManagement facetManagement = new FacetManagement();
|
||||||
facetManagement.setUUID(UUID.fromString(uuid));
|
facetManagement.setUUID(UUID.fromString(uuid));
|
||||||
|
@ -273,11 +285,11 @@ public class ERManager {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@POST
|
@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)
|
public boolean addFacetToContext(@PathParam(ID_PATH_PARAM) String uuid)
|
||||||
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
||||||
CalledMethodProvider.instance.set(HTTPMETHOD.POST.name() + " /" + ERPath.ER_PATH_PART + "/"
|
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);
|
logger.info("Requested to add {} with UUID {} to current {}", Facet.NAME, uuid, Context.NAME);
|
||||||
FacetManagement facetManagement = new FacetManagement();
|
FacetManagement facetManagement = new FacetManagement();
|
||||||
facetManagement.setUUID(UUID.fromString(uuid));
|
facetManagement.setUUID(UUID.fromString(uuid));
|
||||||
|
@ -307,11 +319,11 @@ public class ERManager {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@POST
|
@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)
|
public boolean removeFacetFromContext(@PathParam(ID_PATH_PARAM) String uuid)
|
||||||
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
||||||
CalledMethodProvider.instance.set(HTTPMETHOD.POST.name() + " /" + ERPath.ER_PATH_PART + "/"
|
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);
|
logger.info("Requested to remove {} with UUID {} from current {}", Facet.NAME, uuid, Context.NAME);
|
||||||
FacetManagement facetManagement = new FacetManagement();
|
FacetManagement facetManagement = new FacetManagement();
|
||||||
facetManagement.setUUID(UUID.fromString(uuid));
|
facetManagement.setUUID(UUID.fromString(uuid));
|
||||||
|
|
Loading…
Reference in New Issue