Reorganizing REST interface
This commit is contained in:
parent
34fa045e34
commit
60c96b6a91
|
@ -21,8 +21,11 @@ import org.gcube.informationsystem.resourceregistry.ResourceInitializer;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
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.ContextNotFoundException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
|
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.rest.InstancePath;
|
import org.gcube.informationsystem.resourceregistry.api.rest.InstancePath;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement;
|
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
|
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
|
||||||
|
|
||||||
|
@ -193,4 +196,30 @@ public class InstancesManager extends BaseRest {
|
||||||
return Response.status(Status.NO_CONTENT).build();
|
return Response.status(Status.NO_CONTENT).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GET /instances/{TYPE_NAME}/{UUID}/contexts/ e.g GET
|
||||||
|
* /resource-registry/instances/HostingNode/16032d09-3823-444e-a1ff-a67de4f350a8/contexts
|
||||||
|
*
|
||||||
|
* Where 16032d09-3823-444e-a1ff-a67de4f350a8 is the HostingNode UUID
|
||||||
|
*
|
||||||
|
* Return a list of UUID identifying the context the instance belongs to.
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("{" + AccessPath.TYPE_PATH_PARAM + "}" + "/{" + AccessPath.UUID_PATH_PARAM + "}/"
|
||||||
|
+ SharingPath.CONTEXTS_PATH_PART)
|
||||||
|
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||||
|
public String getInstanceContexts(@PathParam(AccessPath.TYPE_PATH_PARAM) String type,
|
||||||
|
@PathParam(AccessPath.UUID_PATH_PARAM) String instanceId,
|
||||||
|
@PathParam(AccessPath.CONTEXT_UUID_PATH_PARAM) String contextId)
|
||||||
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
||||||
|
logger.info("Requested to get contexts of {} with UUID {}", type, instanceId);
|
||||||
|
CalledMethodProvider.instance.set("getInstanceContexts");
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
ElementManagement erManagement = ElementManagementUtility.getERManagement(type);
|
||||||
|
erManagement.setUUID(UUID.fromString(instanceId));
|
||||||
|
return erManagement.getContexts();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,23 +4,24 @@ import java.util.UUID;
|
||||||
|
|
||||||
import javax.ws.rs.DELETE;
|
import javax.ws.rs.DELETE;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.PUT;
|
import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
import org.gcube.common.authorization.library.provider.CalledMethodProvider;
|
import org.gcube.common.authorization.library.provider.CalledMethodProvider;
|
||||||
import org.gcube.informationsystem.context.reference.entities.Context;
|
import org.gcube.informationsystem.context.reference.entities.Context;
|
||||||
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.ContextNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
|
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath;
|
import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath.SharingOperation;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement;
|
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
|
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.rest.extrahttpmethods.PATCH;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -32,53 +33,124 @@ public class SharingManager {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(SharingManager.class);
|
private static Logger logger = LoggerFactory.getLogger(SharingManager.class);
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* protected void setRESTCalledMethod(HTTPMETHOD httpMethod, String type) {
|
* Add/Remove to/from the context identified by CONTEXT_UUID path parameter the list of instances contained in the body of the request.
|
||||||
* List<String> list = new ArrayList<>();
|
* The the body is the following
|
||||||
* list.add(SharingPath.SHARING_PATH_PART); list.add(type); list.add("{" +
|
|
||||||
* AccessPath.UUID_PATH_PARAM + "}"); list.add(SharingPath.CONTEXTS_PATH_PART);
|
|
||||||
* list.add("{" + AccessPath.CONTEXT_UUID_PATH_PARAM + "}");
|
|
||||||
* Access.setRESTCalledMethod(httpMethod, list, null); }
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* GET /sharing/{TYPE_NAME}/{UUID}/contexts/ e.g GET
|
|
||||||
* /resource-registry/sharing/HostingNode/16032d09-3823-444e-a1ff-a67de4f350a8/
|
|
||||||
* contexts Where 16032d09-3823-444e-a1ff-a67de4f350a8 is the HostingNode UUID
|
|
||||||
*
|
*
|
||||||
* Return a list of UUID identifying the context the instance belongs to.
|
* [
|
||||||
*/
|
* {"@class" : "HostingNode", header : { "uuid" : "16032d09-3823-444e-a1ff-a67de4f350a8"}},
|
||||||
@GET
|
* {"@class" : "Hosts", header : { "uuid" : "97ab8a6b-6b1b-4868-b8fc-ba48d0439ba9"}},
|
||||||
@Path("{" + AccessPath.TYPE_PATH_PARAM + "}" + "/{" + AccessPath.UUID_PATH_PARAM + "}/"
|
* {"@class" : "EService", header : { "uuid" : "d3b1a29b-aa70-4a5a-be83-361a4209dd3e"}}
|
||||||
+ SharingPath.CONTEXTS_PATH_PART)
|
* ]
|
||||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
*
|
||||||
public String getInstanceContexts(@PathParam(AccessPath.TYPE_PATH_PARAM) String type,
|
*
|
||||||
@PathParam(AccessPath.UUID_PATH_PARAM) String instanceId,
|
* Each instance is managed without considering the propagation constraint of relations.
|
||||||
@PathParam(AccessPath.CONTEXT_UUID_PATH_PARAM) String contextId)
|
*
|
||||||
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
* PATCH /sharing/contexts/{CONTEXT_UUID}?operation=(ADD|REMOVE)
|
||||||
logger.info("Requested to get contexts of {} with UUID {}", type, instanceId);
|
*
|
||||||
CalledMethodProvider.instance.set("getInstanceContexts");
|
* e.g
|
||||||
|
* PATCH /resource-registry/contexts/67062c11-9c3a-4906-870d-7df6a43408b0?operation=ADD
|
||||||
@SuppressWarnings("rawtypes")
|
* PATCH /resource-registry/contexts/67062c11-9c3a-4906-870d-7df6a43408b0?operation=REMOVE
|
||||||
ElementManagement erManagement = ElementManagementUtility.getERManagement(type);
|
*
|
||||||
erManagement.setUUID(UUID.fromString(instanceId));
|
* where
|
||||||
return erManagement.getContexts();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* PUT /sharing/{TYPE_NAME}/{UUID}/contexts/{CONTEXT_UUID} e.g PUT
|
|
||||||
* /resource-registry/sharing/HostingNode/16032d09-3823-444e-a1ff-a67de4f350a8/
|
|
||||||
* contexts/67062c11-9c3a-4906-870d-7df6a43408b0 Where
|
|
||||||
* 16032d09-3823-444e-a1ff-a67de4f350a8 is the HostingNode UUID and
|
|
||||||
* 67062c11-9c3a-4906-870d-7df6a43408b0/ is the Context UUID
|
* 67062c11-9c3a-4906-870d-7df6a43408b0/ is the Context UUID
|
||||||
*
|
*
|
||||||
|
* The body contains the list of instances to add/remvoe to/from the context identified by CONTEXT_UUID
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
@PUT
|
@PATCH
|
||||||
@Path("{" + AccessPath.TYPE_PATH_PARAM + "}" + "/{" + AccessPath.UUID_PATH_PARAM + "}/"
|
@Path("{" + SharingPath.CONTEXTS_PATH_PART + "/{" + AccessPath.CONTEXT_UUID_PATH_PARAM + "}")
|
||||||
+ SharingPath.CONTEXTS_PATH_PART + "/{" + AccessPath.CONTEXT_UUID_PATH_PARAM + "}")
|
public boolean addRemoveToFromContextNoPropagationConstraint(
|
||||||
public boolean add(@PathParam(AccessPath.TYPE_PATH_PARAM) String type,
|
@PathParam(AccessPath.CONTEXT_UUID_PATH_PARAM) String contextId,
|
||||||
|
@QueryParam(SharingPath.OPERATION_QUERY_PARAMETER) SharingOperation operation,
|
||||||
|
String body)
|
||||||
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
||||||
|
|
||||||
|
logger.info("Requested to add to {} with UUID {} the following instances {}", Context.NAME, contextId, body);
|
||||||
|
|
||||||
|
if(operation == SharingOperation.ADD) {
|
||||||
|
CalledMethodProvider.instance.set("addToContextNoPropagationConstraint");
|
||||||
|
}else {
|
||||||
|
CalledMethodProvider.instance.set("removeFromContextNoPropagationConstraint");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
boolean success = true;
|
||||||
|
for(any element in body) {
|
||||||
|
String type = ""; // get type
|
||||||
|
UUID instanceUUID = UUID.fromString("");
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
ElementManagement elementManagement = ElementManagementUtility.getERManagement(type);
|
||||||
|
elementManagement.setUUID(instanceUUID);
|
||||||
|
// success = success && return elementManagement.addToContextNoPropagationConstraint(UUID.fromString(contextId), body);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Get the list of instances affected by an add/remove to/from context the target instance identified by UUID path parameter
|
||||||
|
*
|
||||||
|
* GET /sharing/contexts/{CONTEXT_UUID}/{TYPE_NAME}/{UUID}?operation=(ADD|REMOVE)
|
||||||
|
*
|
||||||
|
* e.g
|
||||||
|
* GET /resource-registry/sharing/contexts/67062c11-9c3a-4906-870d-7df6a43408b0/HostingNode/16032d09-3823-444e-a1ff-a67de4f350a8?operation=ADD
|
||||||
|
* GET /resource-registry/sharing/contexts/67062c11-9c3a-4906-870d-7df6a43408b0/HostingNode/16032d09-3823-444e-a1ff-a67de4f350a8?operation=REMOVE
|
||||||
|
*
|
||||||
|
* where
|
||||||
|
* 67062c11-9c3a-4906-870d-7df6a43408b0 is the Context UUID and
|
||||||
|
* 16032d09-3823-444e-a1ff-a67de4f350a8 is the HostingNode UUID
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("{" + SharingPath.CONTEXTS_PATH_PART + "/{" + AccessPath.CONTEXT_UUID_PATH_PARAM + "}/"
|
||||||
|
+ AccessPath.TYPE_PATH_PARAM + "}" + "/{" + AccessPath.UUID_PATH_PARAM + "}")
|
||||||
|
public String checkAddRemove(
|
||||||
|
@PathParam(AccessPath.CONTEXT_UUID_PATH_PARAM) String contextId,
|
||||||
|
@PathParam(AccessPath.TYPE_PATH_PARAM) String type,
|
||||||
@PathParam(AccessPath.UUID_PATH_PARAM) String instanceId,
|
@PathParam(AccessPath.UUID_PATH_PARAM) String instanceId,
|
||||||
@PathParam(AccessPath.CONTEXT_UUID_PATH_PARAM) String contextId)
|
@QueryParam(SharingPath.OPERATION_QUERY_PARAMETER) SharingOperation operation)
|
||||||
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
||||||
|
|
||||||
|
logger.info("Requested to add {} with UUID {} to {} with UUID {}", type, instanceId, Context.NAME, contextId);
|
||||||
|
|
||||||
|
if(operation == SharingOperation.ADD) {
|
||||||
|
CalledMethodProvider.instance.set("dryRunAddToContext");
|
||||||
|
}else {
|
||||||
|
CalledMethodProvider.instance.set("dryRunRemoveFromContext");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
ElementManagement elementManagement = ElementManagementUtility.getERManagement(type);
|
||||||
|
elementManagement.setUUID(UUID.fromString(instanceId));
|
||||||
|
|
||||||
|
if(operation == SharingOperation.ADD) {
|
||||||
|
// elementManagement.dryRunAddToContext(UUID.fromString(contextId));
|
||||||
|
}else {
|
||||||
|
// elementManagement.dryRunRemoveFromContext(UUID.fromString(contextId));
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST /sharing/contexts/{CONTEXT_UUID}/{TYPE_NAME}/{UUID}
|
||||||
|
* e.g
|
||||||
|
* POST /resource-registry/sharing/contexts/67062c11-9c3a-4906-870d-7df6a43408b0/HostingNode/16032d09-3823-444e-a1ff-a67de4f350a8
|
||||||
|
* Where
|
||||||
|
* 67062c11-9c3a-4906-870d-7df6a43408b0 is the Context UUID and
|
||||||
|
* 16032d09-3823-444e-a1ff-a67de4f350a8 is the HostingNode UUID
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path("{" + SharingPath.CONTEXTS_PATH_PART + "/{" + AccessPath.CONTEXT_UUID_PATH_PARAM + "}/"
|
||||||
|
+ AccessPath.TYPE_PATH_PARAM + "}" + "/{" + AccessPath.UUID_PATH_PARAM + "}")
|
||||||
|
public boolean add(
|
||||||
|
@PathParam(AccessPath.CONTEXT_UUID_PATH_PARAM) String contextId,
|
||||||
|
@PathParam(AccessPath.TYPE_PATH_PARAM) String type,
|
||||||
|
@PathParam(AccessPath.UUID_PATH_PARAM) String instanceId)
|
||||||
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
||||||
|
|
||||||
logger.info("Requested to add {} with UUID {} to {} with UUID {}", type, instanceId, Context.NAME, contextId);
|
logger.info("Requested to add {} with UUID {} to {} with UUID {}", type, instanceId, Context.NAME, contextId);
|
||||||
|
@ -92,23 +164,26 @@ public class SharingManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* DELETE /sharing/{TYPE_NAME}/{UUID}/contexts/{CONTEXT_UUID} e.g DELETE
|
* DELETE /sharing/contexts/{CONTEXT_UUID}/{TYPE_NAME}/{UUID}
|
||||||
* /resource-registry/sharing/HostingNode/16032d09-3823-444e-a1ff-a67de4f350a8/
|
* e.g
|
||||||
* contexts/67062c11-9c3a-4906-870d-7df6a43408b0 Where
|
* DELETE /resource-registry/sharing/contexts/67062c11-9c3a-4906-870d-7df6a43408b0/HostingNode/16032d09-3823-444e-a1ff-a67de4f350a8
|
||||||
* 16032d09-3823-444e-a1ff-a67de4f350a8 is the HostingNode UUID and
|
* Where
|
||||||
* 67062c11-9c3a-4906-870d-7df6a43408b0 is the Context UUID
|
* 67062c11-9c3a-4906-870d-7df6a43408b0 is the Context UUID and
|
||||||
|
* 16032d09-3823-444e-a1ff-a67de4f350a8 is the HostingNode UUID
|
||||||
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("{" + AccessPath.TYPE_PATH_PARAM + "}" + "/{" + AccessPath.UUID_PATH_PARAM + "}/"
|
@Path("{" + SharingPath.CONTEXTS_PATH_PART + "/{" + AccessPath.CONTEXT_UUID_PATH_PARAM + "}/"
|
||||||
+ SharingPath.CONTEXTS_PATH_PART + "/{" + AccessPath.CONTEXT_UUID_PATH_PARAM + "}")
|
+ AccessPath.TYPE_PATH_PARAM + "}" + "/{" + AccessPath.UUID_PATH_PARAM + "}")
|
||||||
public Response remove(@PathParam(AccessPath.TYPE_PATH_PARAM) String type,
|
public Response remove(
|
||||||
@PathParam(AccessPath.UUID_PATH_PARAM) String instanceId,
|
@PathParam(AccessPath.CONTEXT_UUID_PATH_PARAM) String contextId,
|
||||||
@PathParam(AccessPath.CONTEXT_UUID_PATH_PARAM) String contextId)
|
@PathParam(AccessPath.TYPE_PATH_PARAM) String type,
|
||||||
|
@PathParam(AccessPath.UUID_PATH_PARAM) String instanceId)
|
||||||
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
|
||||||
logger.info("Requested to remove {} with UUID {} to {} with UUID {}", type, instanceId, Context.NAME,
|
logger.info("Requested to remove {} with UUID {} to {} with UUID {}", type, instanceId, Context.NAME,
|
||||||
contextId);
|
contextId);
|
||||||
// setRESTCalledMethod(HTTPMETHOD.DELETE, type);
|
|
||||||
CalledMethodProvider.instance.set("removeFromContext");
|
CalledMethodProvider.instance.set("removeFromContext");
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package org.gcube.informationsystem.resourceregistry.rest.extrahttpmethods;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
import javax.ws.rs.HttpMethod;
|
||||||
|
|
||||||
|
@Target({ElementType.METHOD})
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@HttpMethod("PATCH")
|
||||||
|
public @interface PATCH {
|
||||||
|
}
|
Loading…
Reference in New Issue