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@169045 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2018-06-12 10:22:58 +00:00
parent 4829fd0ba7
commit 1207bb6570
2 changed files with 11 additions and 7 deletions

View File

@ -34,6 +34,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.Schema
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath; import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPCall.HTTPMETHOD; import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPCall.HTTPMETHOD;
import org.gcube.informationsystem.resourceregistry.context.ContextManagement; import org.gcube.informationsystem.resourceregistry.context.ContextManagement;
import org.gcube.informationsystem.resourceregistry.context.ContextUtility;
import org.gcube.informationsystem.resourceregistry.er.ERManagement; import org.gcube.informationsystem.resourceregistry.er.ERManagement;
import org.gcube.informationsystem.resourceregistry.er.ERManagementUtility; import org.gcube.informationsystem.resourceregistry.er.ERManagementUtility;
import org.gcube.informationsystem.resourceregistry.er.entity.ResourceManagement; import org.gcube.informationsystem.resourceregistry.er.entity.ResourceManagement;
@ -114,17 +115,22 @@ public class Access {
* e.g. GET /access/contexts/c0f314e7-2807-4241-a792-2a6c79ed4fd0 * e.g. GET /access/contexts/c0f314e7-2807-4241-a792-2a6c79ed4fd0
*/ */
@GET @GET
@Path(AccessPath.CONTEXTS_PATH_PART + "{" + AccessPath.UUID_PATH_PARAM + "}") @Path(AccessPath.CONTEXTS_PATH_PART + "/{" + AccessPath.UUID_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 getContext(@PathParam(AccessPath.UUID_PATH_PARAM) String uuid) public String getContext(@PathParam(AccessPath.UUID_PATH_PARAM) String uuid)
throws ContextNotFoundException, ResourceRegistryException { throws ContextNotFoundException, ResourceRegistryException {
ContextManagement contextManagement = new ContextManagement(); if(uuid.compareTo(AccessPath.CURRENT_CONTEXT)==0){
uuid = ContextUtility.getCurrentSecurityContext().getUUID().toString();
}
logger.info("Requested to read {} with id {} ", org.gcube.informationsystem.model.entity.Context.NAME, uuid); logger.info("Requested to read {} with id {} ", org.gcube.informationsystem.model.entity.Context.NAME, uuid);
List<String> pathValues = new ArrayList<>(); List<String> pathValues = new ArrayList<>();
pathValues.add(AccessPath.CONTEXTS_PATH_PART); pathValues.add(AccessPath.CONTEXTS_PATH_PART);
pathValues.add(uuid); pathValues.add(uuid);
setCalledMethodLocal(HTTPMETHOD.GET, pathValues); setCalledMethodLocal(HTTPMETHOD.GET, pathValues);
ContextManagement contextManagement = new ContextManagement();
contextManagement.setUUID(UUID.fromString(uuid)); contextManagement.setUUID(UUID.fromString(uuid));
return contextManagement.read(); return contextManagement.read();
} }

View File

@ -76,15 +76,13 @@ public class ContextManager {
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8) @Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public String read(@PathParam(AccessPath.CONTEXT_UUID_PATH_PARAM) String uuid) public String read(@PathParam(AccessPath.CONTEXT_UUID_PATH_PARAM) String uuid)
throws ContextNotFoundException, ResourceRegistryException { throws ContextNotFoundException, ResourceRegistryException {
logger.info("Requested to read {} with id {} ", Context.NAME, uuid);
setCalledMethod(HTTPMETHOD.GET, uuid);
ContextManagement contextManagement = new ContextManagement();
if(uuid.compareTo(AccessPath.CURRENT_CONTEXT)==0){ if(uuid.compareTo(AccessPath.CURRENT_CONTEXT)==0){
uuid = ContextUtility.getCurrentSecurityContext().getUUID().toString(); uuid = ContextUtility.getCurrentSecurityContext().getUUID().toString();
} }
logger.info("Requested to read {} with id {} ", Context.NAME, uuid);
setCalledMethod(HTTPMETHOD.GET, uuid);
ContextManagement contextManagement = new ContextManagement();
contextManagement.setUUID(UUID.fromString(uuid)); contextManagement.setUUID(UUID.fromString(uuid));
return contextManagement.read(); return contextManagement.read();
} }