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@167869 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2018-06-04 13:42:59 +00:00
parent 19fec74668
commit 9e609c1acf
2 changed files with 27 additions and 12 deletions

View File

@ -15,6 +15,7 @@ import javax.ws.rs.core.Response.Status;
import org.gcube.informationsystem.model.entity.Context;
import org.gcube.informationsystem.resourceregistry.ResourceInitializer;
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextCreationException;
@ -47,7 +48,7 @@ public class ContextManager {
}
/**
* e.g. PUT /resource-registry/context
* e.g. POST /resource-registry/contexts
*
* BODY: {...}
*
@ -71,7 +72,7 @@ public class ContextManager {
}
/**
* e.g. GET /resource-registry/context/c0f314e7-2807-4241-a792-2a6c79ed4fd0
* e.g. GET /resource-registry/contexts/c0f314e7-2807-4241-a792-2a6c79ed4fd0
* @param uuid
* @return
* @throws ContextException
@ -88,7 +89,7 @@ public class ContextManager {
}
/**
* e.g. POST /resource-registry/context
* e.g. PUT /resource-registry/contexts/c0f314e7-2807-4241-a792-2a6c79ed4fd0
*
* BODY: {...}
*
@ -97,16 +98,27 @@ public class ContextManager {
@Path("{" + ID_PATH_PARAM + "}")
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public String update(@PathParam(ID_PATH_PARAM) String uuid, String json)
throws ContextNotFoundException, ResourceRegistryException {
throws ResourceRegistryException {
logger.info("Requested to update {} with json {} ", Context.NAME, json);
ContextManagement contextManagement = new ContextManagement();
contextManagement.setUUID(UUID.fromString(uuid));
boolean create = false;
try {
contextManagement.read();
}catch (NotFoundException e) {
create = true;
}
contextManagement.setJSON(json);
if(create){
return contextManagement.create();
}
return contextManagement.update();
}
/**
* e.g. DELETE /resource-registry/context/c0f314e7-2807-4241-a792-2a6c79ed4fd0
* e.g. DELETE /resource-registry/contexts/c0f314e7-2807-4241-a792-2a6c79ed4fd0
* @param uuid
* @return
* @throws ContextException

View File

@ -49,12 +49,12 @@ public class ERManager {
public static final String TYPE_PATH_PARAM = "type";
/**
* e.g. PUT /resource-registry/er/facets/ContactFacet
* e.g. POST /resource-registry/er/facets/ContactFacet
*
* BODY: {...}
*
*/
@PUT
@POST
@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)
@ -69,26 +69,26 @@ public class ERManager {
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.",
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();
}
/**
* e.g. POST /resource-registry/er/facet/4023d5b2-8601-47a5-83ef-49ffcbfc7d86
* e.g. PUT /resource-registry/er/facet/4023d5b2-8601-47a5-83ef-49ffcbfc7d86
*
* BODY: {...}
*
*/
@POST
@PUT
@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)
@ -101,6 +101,9 @@ public class ERManager {
FacetManagement facetManagement = new FacetManagement();
facetManagement.setUUID(UUID.fromString(uuid));
facetManagement.setJSON(json);
return facetManagement.update();
}