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:
parent
19fec74668
commit
9e609c1acf
|
@ -15,6 +15,7 @@ import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
import org.gcube.informationsystem.model.entity.Context;
|
import org.gcube.informationsystem.model.entity.Context;
|
||||||
import org.gcube.informationsystem.resourceregistry.ResourceInitializer;
|
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.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextAlreadyPresentException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextAlreadyPresentException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextCreationException;
|
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: {...}
|
* 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
|
* @param uuid
|
||||||
* @return
|
* @return
|
||||||
* @throws ContextException
|
* @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: {...}
|
* BODY: {...}
|
||||||
*
|
*
|
||||||
|
@ -97,16 +98,27 @@ public class ContextManager {
|
||||||
@Path("{" + ID_PATH_PARAM + "}")
|
@Path("{" + ID_PATH_PARAM + "}")
|
||||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||||
public String update(@PathParam(ID_PATH_PARAM) String uuid, String json)
|
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);
|
logger.info("Requested to update {} with json {} ", Context.NAME, json);
|
||||||
ContextManagement contextManagement = new ContextManagement();
|
ContextManagement contextManagement = new ContextManagement();
|
||||||
contextManagement.setUUID(UUID.fromString(uuid));
|
contextManagement.setUUID(UUID.fromString(uuid));
|
||||||
|
boolean create = false;
|
||||||
|
try {
|
||||||
|
contextManagement.read();
|
||||||
|
}catch (NotFoundException e) {
|
||||||
|
create = true;
|
||||||
|
}
|
||||||
|
|
||||||
contextManagement.setJSON(json);
|
contextManagement.setJSON(json);
|
||||||
|
if(create){
|
||||||
|
return contextManagement.create();
|
||||||
|
}
|
||||||
|
|
||||||
return contextManagement.update();
|
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
|
* @param uuid
|
||||||
* @return
|
* @return
|
||||||
* @throws ContextException
|
* @throws ContextException
|
||||||
|
|
|
@ -49,12 +49,12 @@ 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/facets/ContactFacet
|
* e.g. POST /resource-registry/er/facets/ContactFacet
|
||||||
*
|
*
|
||||||
* BODY: {...}
|
* BODY: {...}
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@PUT
|
@POST
|
||||||
@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)
|
||||||
|
@ -69,26 +69,26 @@ public class ERManager {
|
||||||
facetManagement.setJSON(json);
|
facetManagement.setJSON(json);
|
||||||
|
|
||||||
UUID uuid = facetManagement.getUUID();
|
UUID uuid = facetManagement.getUUID();
|
||||||
if(uuid!=null) {
|
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.",
|
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);
|
Header.class.getSimpleName(), Facet.NAME);
|
||||||
logger.info(error);
|
logger.info(error);
|
||||||
throw new ContextCreationException(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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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: {...}
|
* BODY: {...}
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@POST
|
@PUT
|
||||||
@Path(ERPath.FACET_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)
|
||||||
|
@ -101,6 +101,9 @@ public class ERManager {
|
||||||
FacetManagement facetManagement = new FacetManagement();
|
FacetManagement facetManagement = new FacetManagement();
|
||||||
facetManagement.setUUID(UUID.fromString(uuid));
|
facetManagement.setUUID(UUID.fromString(uuid));
|
||||||
facetManagement.setJSON(json);
|
facetManagement.setJSON(json);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return facetManagement.update();
|
return facetManagement.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue