Fixing POST and PUT methods in entity manager to be able to manage large content

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@134390 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-11-18 18:10:32 +00:00
parent aa41ffb22c
commit 28e62b7b83
1 changed files with 56 additions and 32 deletions

View File

@ -9,7 +9,6 @@ import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.gcube.informationsystem.model.entity.Facet;
@ -47,7 +46,9 @@ public class EntityManager {
/* Facets Methods */
/**
* e.g. PUT /resource-registry/entity/facet/ContactFacet?definition={...}
* e.g. PUT /resource-registry/entity/facet/ContactFacet
*
* BODY: {...}
*
* @param type
* @param definition
@ -60,16 +61,17 @@ public class EntityManager {
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
@Produces(MediaType.APPLICATION_JSON)
public String createFacet(@PathParam(TYPE_PATH_PARAM) String type,
@QueryParam(EntityPath.DEFINITION_PARAM) String definition)
throws EntityException, ResourceRegistryException {
String json) throws EntityException, ResourceRegistryException {
logger.info("requested facet creation for type {} defined by {} ",
type, definition);
return entityManager.createFacet(type, definition);
type, json);
return entityManager.createFacet(type, json);
}
/**
* e.g. POST /resource-registry/entity/facet/4023d5b2-8601-47a5-
* 83ef-49ffcbfc7d86?definition={...}
* 83ef-49ffcbfc7d86
*
* BODY: {...}
*
* @param uuid
* @param definition
@ -81,12 +83,10 @@ public class EntityManager {
@Path(EntityPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}")
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
@Produces(MediaType.APPLICATION_JSON)
public String updateFacet(@PathParam(ID_PATH_PARAM) String uuid,
@QueryParam(EntityPath.DEFINITION_PARAM) String definition)
public String updateFacet(@PathParam(ID_PATH_PARAM) String uuid, String json)
throws FacetNotFoundException, ResourceRegistryException {
logger.info("requested facet update for id {} with {}", uuid,
definition);
return entityManager.updateFacet(UUID.fromString(uuid), definition);
logger.info("requested facet update for id {} with {}", uuid, json);
return entityManager.updateFacet(UUID.fromString(uuid), json);
}
/**
@ -109,7 +109,9 @@ public class EntityManager {
/* Resources Methods */
/**
* e.g. PUT /resource-registry/entity/resource/HostingNode?definition={...}
* e.g. PUT /resource-registry/entity/resource/HostingNode
*
* BODY: {...}
*
* @param type
* @param definition
@ -122,11 +124,11 @@ public class EntityManager {
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
@Produces(MediaType.APPLICATION_JSON)
public String createResource(@PathParam(TYPE_PATH_PARAM) String type,
@QueryParam(EntityPath.DEFINITION_PARAM) String definition)
throws FacetNotFoundException, ResourceRegistryException {
String json) throws FacetNotFoundException,
ResourceRegistryException {
logger.info("requested resource creation for type {} with json {}",
type, definition);
return entityManager.createResource(type, definition);
type, json);
return entityManager.createResource(type, json);
}
/**
@ -151,8 +153,9 @@ public class EntityManager {
/**
* e.g. PUT
* /resource-registry/entity/consistOf/source/bbf80a93-2284-424a-930c-
* 7ee20021aee1/target/f6931232-c034-4979-9b2f-7193d3fba7df?type=hasCreator&properties={..
* . }
* 7ee20021aee1/target/f6931232-c034-4979-9b2f-7193d3fba7df/hasCreator
*
* BODY: {}
*
* @param resourceUUID
* @param facetUUID
@ -166,21 +169,21 @@ public class EntityManager {
@PUT
@Path(EntityPath.CONSISTS_OF_PATH_PART + "/" + EntityPath.SOURCE_PATH_PART
+ "/{" + SOURCE_ID_PATH_PARAM + "}/" + EntityPath.TARGET_PATH_PART
+ "/{" + TARGET_ID_PATH_PARAM + "}")
+ "/{" + TARGET_ID_PATH_PARAM + "}/{" + EntityPath.TYPE_PATH_PARAM
+ "}")
@Produces(MediaType.APPLICATION_JSON)
public String attachFacet(
@PathParam(SOURCE_ID_PATH_PARAM) String resourceUUID,
@PathParam(TARGET_ID_PATH_PARAM) String facetUUID,
@QueryParam(EntityPath.TYPE_PARAM) String type,
@QueryParam(EntityPath.PROPERTIES_PARAM) String properties)
@PathParam(EntityPath.TYPE_PATH_PARAM) String type, String json)
throws FacetNotFoundException, ResourceNotFoundException,
ResourceRegistryException {
logger.info(
"requested to attach resource {} to facet {} ({} Type {}) with properties {}",
resourceUUID, facetUUID, ConsistsOf.class.getSimpleName(),
type, properties);
type, json);
return entityManager.attachFacet(UUID.fromString(resourceUUID),
UUID.fromString(facetUUID), type, properties);
UUID.fromString(facetUUID), type, json);
}
/**
@ -202,9 +205,9 @@ 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
* ={...}
* -cebe3f7b2925/target/985f7cf9-b6fa-463b-86c8-84ab0a77deea/callsFor
*
* BODY: {...}
*
* @param sourceResourceUUID
* @param targetResourceUUID
@ -217,23 +220,23 @@ 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 + "}")
+ EntityPath.TARGET_PATH_PART + "/{" + TARGET_ID_PATH_PARAM + "}/{"
+ EntityPath.TYPE_PATH_PARAM + "}")
@Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
@Produces(MediaType.APPLICATION_JSON)
public String attachResource(
@PathParam(SOURCE_ID_PATH_PARAM) String sourceResourceUUID,
@PathParam(TARGET_ID_PATH_PARAM) String targetResourceUUID,
@QueryParam(EntityPath.TYPE_PARAM) String type,
@QueryParam(EntityPath.PROPERTIES_PARAM) String properties)
@PathParam(EntityPath.TYPE_PATH_PARAM) String type, String json)
throws ResourceNotFoundException, ResourceRegistryException {
logger.info(
"requested to attach source {} {} and target {} {} ({} Type {}) with properties {}",
Resource.NAME, sourceResourceUUID, Resource.NAME,
targetResourceUUID, IsRelatedTo.class.getSimpleName(), type,
properties);
json);
return entityManager.attachResource(
UUID.fromString(sourceResourceUUID),
UUID.fromString(targetResourceUUID), type, properties);
UUID.fromString(targetResourceUUID), type, json);
}
/**
@ -252,6 +255,16 @@ public class EntityManager {
return entityManager.detachResource(UUID.fromString(relatedToUUID));
}
/**
* e.g POST
* /resource-registry/add/resource/67062c11-9c3a-4906-870d-7df6a43408b0
*
* @param uuid
* @return
* @throws ResourceNotFoundException
* @throws ContextNotFoundException
* @throws ResourceRegistryException
*/
@POST
@Path(EntityPath.ADD_PATH_PART + "/" + EntityPath.RESOURCE_PATH_PART + "/{"
+ ID_PATH_PARAM + "}")
@ -263,6 +276,17 @@ public class EntityManager {
return entityManager.addResourceToContext(UUID.fromString(uuid));
}
/**
* e.g POST
* /resource-registry/add/facet/f6931232-c034-4979-9b2f-7193d3fba7df
*
* @param uuid
* @return
* @throws FacetNotFoundException
* @throws ContextNotFoundException
* @throws ResourceRegistryException
*/
@POST
@Path(EntityPath.ADD_PATH_PART + "/" + EntityPath.FACET_PATH_PART + "/{"
+ ID_PATH_PARAM + "}")