Exposing AddToContext APi refs #5701
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@134120 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
b40503fa33
commit
afc66c822e
|
@ -12,6 +12,8 @@ import javax.ws.rs.Produces;
|
|||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.gcube.informationsystem.model.entity.Facet;
|
||||
import org.gcube.informationsystem.model.entity.Resource;
|
||||
import org.gcube.informationsystem.model.relation.ConsistsOf;
|
||||
import org.gcube.informationsystem.model.relation.IsRelatedTo;
|
||||
import org.gcube.informationsystem.resourceregistry.api.EntityManagement;
|
||||
|
@ -22,6 +24,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.FacetN
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.ResourceNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.EntityPath;
|
||||
import org.gcube.informationsystem.resourceregistry.resources.impl.EntityManagementImpl;
|
||||
import org.gcube.informationsystem.resourceregistry.resources.utils.ContextUtility;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -40,13 +43,12 @@ public class EntityManager {
|
|||
public static final String SOURCE_ID_PATH_PARAM = "sourceId";
|
||||
public static final String TARGET_ID_PATH_PARAM = "targetId";
|
||||
|
||||
|
||||
|
||||
protected EntityManagement entityManager = new EntityManagementImpl();
|
||||
|
||||
/* Facets Methods */
|
||||
/**
|
||||
* e.g. PUT /resource-registry/entity/facet/ContactFacet?definition={...}
|
||||
*
|
||||
* @param type
|
||||
* @param definition
|
||||
* @return
|
||||
|
@ -55,10 +57,9 @@ public class EntityManager {
|
|||
*/
|
||||
@PUT
|
||||
@Path(EntityPath.FACET_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
|
||||
@Consumes({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
|
||||
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public String createFacet(
|
||||
@PathParam(TYPE_PATH_PARAM) String type,
|
||||
public String createFacet(@PathParam(TYPE_PATH_PARAM) String type,
|
||||
@QueryParam(EntityPath.DEFINITION_PARAM) String definition)
|
||||
throws EntityException, ResourceRegistryException {
|
||||
logger.trace("requested facet creation for type {} defined by {} ",
|
||||
|
@ -67,7 +68,9 @@ public class EntityManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* e.g. POST /resource-registry/entity/facet/4023d5b2-8601-47a5-83ef-49ffcbfc7d86?definition={...}
|
||||
* e.g. POST /resource-registry/entity/facet/4023d5b2-8601-47a5-
|
||||
* 83ef-49ffcbfc7d86?definition={...}
|
||||
*
|
||||
* @param uuid
|
||||
* @param definition
|
||||
* @return
|
||||
|
@ -76,10 +79,9 @@ public class EntityManager {
|
|||
*/
|
||||
@POST
|
||||
@Path(EntityPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}")
|
||||
@Consumes({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
|
||||
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public String updateFacet(
|
||||
@PathParam(ID_PATH_PARAM) String uuid,
|
||||
public String updateFacet(@PathParam(ID_PATH_PARAM) String uuid,
|
||||
@QueryParam(EntityPath.DEFINITION_PARAM) String definition)
|
||||
throws FacetNotFoundException, ResourceRegistryException {
|
||||
logger.trace("requested facet update for id {} with {}", uuid,
|
||||
|
@ -88,7 +90,9 @@ public class EntityManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* e.g. DELETE /resource-registry/entity/facet/4023d5b2-8601-47a5-83ef-49ffcbfc7d86
|
||||
* e.g. DELETE
|
||||
* /resource-registry/entity/facet/4023d5b2-8601-47a5-83ef-49ffcbfc7d86
|
||||
*
|
||||
* @param uuid
|
||||
* @return
|
||||
* @throws FacetNotFoundException
|
||||
|
@ -106,6 +110,7 @@ public class EntityManager {
|
|||
|
||||
/**
|
||||
* e.g. PUT /resource-registry/entity/resource/HostingNode?definition={...}
|
||||
*
|
||||
* @param type
|
||||
* @param definition
|
||||
* @return
|
||||
|
@ -114,10 +119,9 @@ public class EntityManager {
|
|||
*/
|
||||
@PUT
|
||||
@Path(EntityPath.RESOURCE_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
|
||||
@Consumes({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
|
||||
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public String createResource(
|
||||
@PathParam(TYPE_PATH_PARAM) String type,
|
||||
public String createResource(@PathParam(TYPE_PATH_PARAM) String type,
|
||||
@QueryParam(EntityPath.DEFINITION_PARAM) String definition)
|
||||
throws FacetNotFoundException, ResourceRegistryException {
|
||||
logger.trace("requested resource creation for type {} with json {}",
|
||||
|
@ -126,7 +130,9 @@ public class EntityManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* e.g. DELETE /resource-registry/entity/resource/67062c11-9c3a-4906-870d-7df6a43408b0
|
||||
* e.g. DELETE
|
||||
* /resource-registry/entity/resource/67062c11-9c3a-4906-870d-7df6a43408b0
|
||||
*
|
||||
* @param uuid
|
||||
* @return
|
||||
* @throws ResourceNotFoundException
|
||||
|
@ -143,7 +149,11 @@ public class EntityManager {
|
|||
/* Relations Methods */
|
||||
|
||||
/**
|
||||
* e.g. PUT /resource-registry/entity/consistOf/source/bbf80a93-2284-424a-930c-7ee20021aee1/target/f6931232-c034-4979-9b2f-7193d3fba7df?type=hasCreator&properties={...}
|
||||
* e.g. PUT
|
||||
* /resource-registry/entity/consistOf/source/bbf80a93-2284-424a-930c-
|
||||
* 7ee20021aee1/target/f6931232-c034-4979-9b2f-7193d3fba7df?type=hasCreator&properties={..
|
||||
* . }
|
||||
*
|
||||
* @param resourceUUID
|
||||
* @param facetUUID
|
||||
* @param type
|
||||
|
@ -154,11 +164,9 @@ public class EntityManager {
|
|||
* @throws ResourceRegistryException
|
||||
*/
|
||||
@PUT
|
||||
@Path(EntityPath.CONSISTS_OF_PATH_PART + "/"
|
||||
+ EntityPath.SOURCE_PATH_PART + "/{"
|
||||
+ SOURCE_ID_PATH_PARAM + "}/"
|
||||
+ EntityPath.TARGET_PATH_PART + "/{"
|
||||
+ TARGET_ID_PATH_PARAM + "}")
|
||||
@Path(EntityPath.CONSISTS_OF_PATH_PART + "/" + EntityPath.SOURCE_PATH_PART
|
||||
+ "/{" + SOURCE_ID_PATH_PARAM + "}/" + EntityPath.TARGET_PATH_PART
|
||||
+ "/{" + TARGET_ID_PATH_PARAM + "}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public String attachFacet(
|
||||
@PathParam(SOURCE_ID_PATH_PARAM) String resourceUUID,
|
||||
|
@ -171,12 +179,14 @@ public class EntityManager {
|
|||
"requested to attach resource {} to facet {} ({} Type {}) with properties {}",
|
||||
resourceUUID, facetUUID, ConsistsOf.class.getSimpleName(),
|
||||
type, properties);
|
||||
return entityManager.attachFacet(UUID.fromString(resourceUUID), UUID.fromString(facetUUID), type,
|
||||
properties);
|
||||
return entityManager.attachFacet(UUID.fromString(resourceUUID),
|
||||
UUID.fromString(facetUUID), type, properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* e.g. DELETE /resource-registry/entity/consistOf/9bff49c8-c0a7-45de-827c-accb71defbd3
|
||||
* e.g. DELETE /resource-registry/entity/consistOf/9bff49c8-c0a7-45de-827c-
|
||||
* accb71defbd3
|
||||
*
|
||||
* @param consistOfUUID
|
||||
* @return
|
||||
* @throws ResourceRegistryException
|
||||
|
@ -190,7 +200,12 @@ public class EntityManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* e.g. PUT /resource-registry/entity/relatedTo/source/4a81008a-6300-4a32-857f-cebe3f7b2925/target/985f7cf9-b6fa-463b-86c8-84ab0a77deea?type=callsFor&properties={...}
|
||||
* e.g. PUT
|
||||
* /resource-registry/entity/relatedTo/source/4a81008a-6300-4a32-857f
|
||||
* -cebe3f7b2925
|
||||
* /target/985f7cf9-b6fa-463b-86c8-84ab0a77deea?type=callsFor&properties
|
||||
* ={...}
|
||||
*
|
||||
* @param sourceResourceUUID
|
||||
* @param targetResourceUUID
|
||||
* @param type
|
||||
|
@ -201,11 +216,9 @@ public class EntityManager {
|
|||
*/
|
||||
@PUT
|
||||
@Path(EntityPath.IS_RELATED_TO_PATH_PART + "/"
|
||||
+ EntityPath.SOURCE_PATH_PART + "/{"
|
||||
+ SOURCE_ID_PATH_PARAM + "}/"
|
||||
+ EntityPath.TARGET_PATH_PART + "/{"
|
||||
+ TARGET_ID_PATH_PARAM + "}")
|
||||
@Consumes({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
|
||||
+ EntityPath.SOURCE_PATH_PART + "/{" + SOURCE_ID_PATH_PARAM + "}/"
|
||||
+ EntityPath.TARGET_PATH_PART + "/{" + TARGET_ID_PATH_PARAM + "}")
|
||||
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public String attachResource(
|
||||
@PathParam(SOURCE_ID_PATH_PARAM) String sourceResourceUUID,
|
||||
|
@ -214,15 +227,19 @@ public class EntityManager {
|
|||
@QueryParam(EntityPath.PROPERTIES_PARAM) String properties)
|
||||
throws ResourceNotFoundException, ResourceRegistryException {
|
||||
logger.trace(
|
||||
"requested to attach source resource {} and target resource {} ({} Type {}) with properties {}",
|
||||
sourceResourceUUID, targetResourceUUID,
|
||||
IsRelatedTo.class.getSimpleName(), type, properties);
|
||||
return entityManager.attachResource(UUID.fromString(sourceResourceUUID),
|
||||
"requested to attach source {} {} and target {} {} ({} Type {}) with properties {}",
|
||||
Resource.NAME, sourceResourceUUID, Resource.NAME,
|
||||
targetResourceUUID, IsRelatedTo.class.getSimpleName(), type,
|
||||
properties);
|
||||
return entityManager.attachResource(
|
||||
UUID.fromString(sourceResourceUUID),
|
||||
UUID.fromString(targetResourceUUID), type, properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* e.g. DELETE /resource-registry/entity/relatedTo/b3982715-a7aa-4530-9a5f-2f60008d256e
|
||||
* e.g. DELETE
|
||||
* /resource-registry/entity/relatedTo/b3982715-a7aa-4530-9a5f-2f60008d256e
|
||||
*
|
||||
* @param relatedToUUID
|
||||
* @return
|
||||
* @throws ResourceRegistryException
|
||||
|
@ -235,18 +252,25 @@ public class EntityManager {
|
|||
return entityManager.detachResource(UUID.fromString(relatedToUUID));
|
||||
}
|
||||
|
||||
|
||||
@POST
|
||||
@Path(EntityPath.ADD_PATH_PART + "/" + EntityPath.RESOURCE_PATH_PART + "/{" + ID_PATH_PARAM + "}")
|
||||
public boolean addResourceToContext(String uuid) throws ResourceNotFoundException,
|
||||
ContextNotFoundException, ResourceRegistryException {
|
||||
@Path(EntityPath.ADD_PATH_PART + "/" + EntityPath.RESOURCE_PATH_PART + "/{"
|
||||
+ ID_PATH_PARAM + "}")
|
||||
public boolean addResourceToContext(@PathParam(ID_PATH_PARAM) String uuid)
|
||||
throws ResourceNotFoundException, ContextNotFoundException,
|
||||
ResourceRegistryException {
|
||||
logger.trace("requested to add {} with UUID {} to current context {}",
|
||||
Resource.NAME, uuid, ContextUtility.getCurrentContext());
|
||||
return entityManager.addResourceToContext(UUID.fromString(uuid));
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path(EntityPath.ADD_PATH_PART + "/" + EntityPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}")
|
||||
public boolean addFacetToContext(String uuid) throws FacetNotFoundException,
|
||||
ContextNotFoundException, ResourceRegistryException {
|
||||
@Path(EntityPath.ADD_PATH_PART + "/" + EntityPath.FACET_PATH_PART + "/{"
|
||||
+ ID_PATH_PARAM + "}")
|
||||
public boolean addFacetToContext(@PathParam(ID_PATH_PARAM) String uuid)
|
||||
throws FacetNotFoundException, ContextNotFoundException,
|
||||
ResourceRegistryException {
|
||||
logger.trace("requested to add {} with UUID {} to current context {}",
|
||||
Facet.NAME, uuid, ContextUtility.getCurrentContext());
|
||||
return entityManager.addFacetToContext(UUID.fromString(uuid));
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ public class ContextUtility {
|
|||
return UUID.fromString(contextID);
|
||||
}
|
||||
|
||||
private static String getCurrentScope(){
|
||||
public static String getCurrentContext(){
|
||||
String token = SecurityTokenProvider.instance.get();
|
||||
AuthorizationEntry authorizationEntry = null;
|
||||
try {
|
||||
|
@ -92,7 +92,7 @@ public class ContextUtility {
|
|||
OrientGraph orientGraph = null;
|
||||
|
||||
try {
|
||||
String scope = getCurrentScope();
|
||||
String scope = getCurrentContext();
|
||||
if(scope==null){
|
||||
throw new ContextException("Null Token and Scope. Please set your token first.");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue