Fixing REST path

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@131072 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-09-01 15:11:44 +00:00
parent 8891ab4fe4
commit 8096b1cddc
5 changed files with 154 additions and 109 deletions

View File

@ -5,7 +5,6 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import org.gcube.informationsystem.resourceregistry.AccessRESTPath;
import org.gcube.informationsystem.resourceregistry.api.EntityManagement;
import org.gcube.informationsystem.resourceregistry.api.Query;
import org.gcube.informationsystem.resourceregistry.api.SchemaManagement;
@ -14,6 +13,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.FacetNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.ResourceNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
import org.gcube.informationsystem.resourceregistry.resources.impl.EntityManagementImpl;
import org.gcube.informationsystem.resourceregistry.resources.impl.QueryImpl;
import org.gcube.informationsystem.resourceregistry.resources.impl.SchemaManagementImpl;
@ -24,11 +24,14 @@ import org.slf4j.LoggerFactory;
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
* @author Lucio Lelii (lucio.lelii@isti.cnr.it)
*/
@Path(AccessRESTPath.ACCESS_PATH_PART)
@Path(AccessPath.ACCESS_PATH_PART)
public class Access {
private static Logger logger = LoggerFactory.getLogger(Access.class);
public static final String ID_PATH_PARAM = "id";
public static final String TYPE_PATH_PARAM = "type";
protected Query queryManager = new QueryImpl();
protected EntityManagement entityManager = new EntityManagementImpl();
protected SchemaManagement schemaManager = new SchemaManagementImpl();
@ -41,62 +44,64 @@ public class Access {
* @throws InvalidQueryException
*/
@GET
public String query(@QueryParam(AccessRESTPath.QUERY_PARAM) String query,
@QueryParam(AccessRESTPath.FETCH_PLAN_PARAM) String fetchPlan)
public String query(@QueryParam(AccessPath.QUERY_PARAM) String query,
@QueryParam(AccessPath.FETCH_PLAN_PARAM) String fetchPlan)
throws InvalidQueryException {
logger.info("Requested query (fetch plan {}):\n{}", fetchPlan, query);
return queryManager.execute(query, fetchPlan);
}
/**
* e.g. /resource-registry/access/facetInstance/4d28077b-566d-4132-b073-f4edaf61dcb9
* e.g. /resource-registry/access/facet/instance/4d28077b-566d-4132-b073-f4edaf61dcb9
* @param facetId
* @return
* @throws FacetNotFoundException
* @throws ResourceRegistryException
*/
@GET @Path(AccessRESTPath.FACET_INSTANCE_PATH_PART + "/{" + AccessRESTPath.FACET_ID_PATH_PART + "}")
public String getFacet(@PathParam(AccessRESTPath.FACET_ID_PATH_PART) String facetId)
@GET
@Path(AccessPath.FACET_PATH_PART + "/" + AccessPath.INSTANCE_PATH_PART + "/{" + ID_PATH_PARAM + "}")
public String getFacet(@PathParam(ID_PATH_PARAM) String facetId)
throws FacetNotFoundException, ResourceRegistryException {
logger.info("Requested Facet with id {}", facetId);
return entityManager.readFacet(facetId);
}
/**
* e.g. /resource-registry/access/facetSchema/ContactFacet
* e.g. /resource-registry/access/facet/schema/ContactFacet
* @param facetType
* @return
* @throws SchemaNotFoundException
*/
@GET @Path(AccessRESTPath.FACET_SCHEMA_PATH_PART + "/{" + AccessRESTPath.FACET_TYPE_PATH_PART + "}")
public String getFacetSchema(@PathParam(AccessRESTPath.FACET_TYPE_PATH_PART) String facetType)
@GET
@Path(AccessPath.FACET_PATH_PART + "/" + AccessPath.SCHEMA_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
public String getFacetSchema(@PathParam(TYPE_PATH_PARAM) String facetType)
throws SchemaNotFoundException {
logger.info("Requested Facet Schema for type {}", facetType);
return schemaManager.getFacetSchema(facetType);
}
/**
* e.g. /resource-registry/access/resourceInstance/cc132a2c-d0b0-45a8-92fa-7451f6a44b6d
* e.g. /resource-registry/access/resource/instance/cc132a2c-d0b0-45a8-92fa-7451f6a44b6d
* @param resourceId
* @return
* @throws ResourceNotFoundException
* @throws ResourceRegistryException
*/
@GET @Path(AccessRESTPath.RESOURCE_INSTANCE_PATH_PART + "/{" + AccessRESTPath.RESOURCE_ID_PATH_PART + "}")
public String getResource(@PathParam(AccessRESTPath.RESOURCE_ID_PATH_PART) String resourceId)
@GET @Path(AccessPath.RESOURCE_PATH_PART + "/" + AccessPath.INSTANCE_PATH_PART + "/{" + ID_PATH_PARAM + "}")
public String getResource(@PathParam(ID_PATH_PARAM) String resourceId)
throws ResourceNotFoundException, ResourceRegistryException {
logger.info("Requested Resource with id {}", resourceId);
return entityManager.readResource(resourceId);
}
/**
* e.g. /resource-registry/access/resourceSchema/HostingNode
* e.g. /resource-registry/access/resource/schema/HostingNode
* @param resourceType
* @return
* @throws SchemaNotFoundException
*/
@GET @Path(AccessRESTPath.RESOURCE_SCHEMA_PATH_PART + "/{" + AccessRESTPath.RESOURCE_TYPE_PATH_PART + "}")
public String getResourceSchema(@PathParam(AccessRESTPath.RESOURCE_TYPE_PATH_PART) String resourceType)
@GET @Path(AccessPath.RESOURCE_PATH_PART + "/" + AccessPath.SCHEMA_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
public String getResourceSchema(@PathParam(TYPE_PATH_PARAM) String resourceType)
throws SchemaNotFoundException {
logger.info("Requested Resource Schema for type {}", resourceType);
return schemaManager.getResourceSchema(resourceType);

View File

@ -4,6 +4,7 @@
package org.gcube.informationsystem.resourceregistry.resources;
import javax.ws.rs.DELETE;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
@ -12,52 +13,65 @@ import javax.ws.rs.QueryParam;
import org.gcube.informationsystem.resourceregistry.api.ContextManagement;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.rest.ContextPath;
import org.gcube.informationsystem.resourceregistry.resources.impl.ContextManagementImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
* @author Lucio Lelii (lucio.lelii@isti.cnr.it)
* @author Lucio Lelii (lucio.lelii@isti.cnr.it)
*/
@Path("context")
@Path(ContextPath.CONTEXT_PATH_PART)
public class ContextManager {
/**
* Logger
*/
private static Logger logger = LoggerFactory.getLogger(ContextManager.class);
private static Logger logger = LoggerFactory
.getLogger(ContextManager.class);
public static final String ID_PATH_PARAM = "id";
protected ContextManagement contextManager = new ContextManagementImpl();
protected ContextManagement contextManager = new ContextManagementImpl();
@PUT
@Path("create")
public String create(@QueryParam("parentContextId") String parentContextId, @QueryParam("name") String name) throws Exception {
public String create(
@QueryParam(ContextPath.PARENT_CONTEXT_ID_PARAM) String parentUUID,
@QueryParam(ContextPath.NAME_PARAM) String name)
throws Exception {
logger.trace("requested to create context with name : {} ", name);
return contextManager.create(parentContextId, name);
return contextManager.create(parentUUID, name);
}
@PUT
@Path("rename/{contextId}")
public String rename(@PathParam("contextId") String uuid, @QueryParam("name") String name)
throws ContextNotFoundException, ContextException{
@DELETE
@Path("{" + ID_PATH_PARAM + "}")
public String delete(@PathParam(ID_PATH_PARAM) String uuid)
throws ContextException {
logger.trace("requested to delete context with id {} ", uuid);
return contextManager.delete(uuid);
}
@POST
@Path(ContextPath.RENAME_PATH_PART + "/{" + ID_PATH_PARAM + "}")
public String rename(@PathParam(ID_PATH_PARAM) String uuid,
@QueryParam("name") String name) throws ContextNotFoundException,
ContextException {
logger.trace("requested to rename context id {} with {} ", uuid, name);
return contextManager.rename(uuid, name);
}
@PUT
@Path("move/{contextId}")
public String move(@PathParam("contextId") String uuid, @QueryParam("newParentId") String newParentId)
throws ContextNotFoundException , ContextException{
logger.trace("requested to move context id {} with new parend id {} ", uuid, newParentId);
return contextManager.move(newParentId, uuid);
}
@DELETE
@Path("delete/{contextId}")
public String delete(@PathParam("contextId") String uuid) throws ContextException {
logger.trace("requested to delete context with id {} ",uuid);
return contextManager.delete(uuid);
@POST
@Path(ContextPath.MOVE_PATH_PART + "/{" + ID_PATH_PARAM + "}")
public String move(
@PathParam(ID_PATH_PARAM) String uuid,
@QueryParam(ContextPath.PARENT_CONTEXT_ID_PARAM) String newParentUUID)
throws ContextNotFoundException, ContextException {
logger.trace("requested to move context id {} with new parend id {} ",
uuid, newParentUUID);
return contextManager.move(newParentUUID, uuid);
}
}

View File

@ -14,6 +14,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.EntityException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.FacetNotFoundException;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -22,110 +23,130 @@ import org.slf4j.LoggerFactory;
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
* @author Lucio Lelii (lucio.lelii@isti.cnr.it)
*/
@Path("entity")
@Path(EntityPath.ENTITY_PATH_PART)
public class EntityManager {
private static Logger logger = LoggerFactory.getLogger(SchemaManager.class);
public static final String ID_PATH_PARAM = "id";
public static final String TYPE_PATH_PARAM = "type";
public static final String SOURCE_ID_PATH_PARAM = "sourceId";
public static final String TARGET_ID_PATH_PARAM = "targetId";
public static final String TYPE_PARAM = "type";
public static final String PROPERTIES_PARAM = "properties";
protected EntityManagement entityManager = new EntityManagementImpl();
/* Facets Methods */
@Path("facet/{facetType}")
@PUT
public String createFacet(@PathParam("facetType") String facetType,
String jsonRepresentation) throws EntityException,
ResourceRegistryException {
logger.trace("requested facet creation for type {} with json {} ",
facetType, jsonRepresentation);
return entityManager.createFacet(facetType, jsonRepresentation);
@Path(EntityPath.FACET_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
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 {} ",
type, definition);
return entityManager.createFacet(type, definition);
}
@Path("facet/{facetId}")
@POST
public String updateFacet(@PathParam("facetId") String facetId,
String jsonRepresentation) throws FacetNotFoundException,
ResourceRegistryException {
logger.trace("requested facet update for id {} with json", facetId,
jsonRepresentation);
return entityManager.updateFacet(facetId, jsonRepresentation);
@Path(EntityPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}")
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,
definition);
return entityManager.updateFacet(uuid, definition);
}
@Path("facet/{facetId}")
@DELETE
public boolean deleteFacet(@PathParam("facetId") String facetId)
@Path(EntityPath.FACET_PATH_PART + "/{" + ID_PATH_PARAM + "}")
public boolean deleteFacet(@PathParam(ID_PATH_PARAM) String uuid)
throws FacetNotFoundException, ResourceRegistryException {
logger.trace("requested facet deletion for id {}", facetId);
return entityManager.deleteFacet(facetId);
logger.trace("Requested to delete Facet with id {}", uuid);
return entityManager.deleteFacet(uuid);
}
/* Resources Methods */
@Path("resource/{resourceType}")
@PUT
@Path(EntityPath.RESOURCE_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
public String createResource(
@PathParam("resourceType") String resourceType,
String jsonRepresentation) throws FacetNotFoundException,
ResourceRegistryException {
@PathParam(TYPE_PATH_PARAM) String type,
@QueryParam(EntityPath.DEFINITION_PARAM) String definition)
throws FacetNotFoundException, ResourceRegistryException {
logger.trace("requested resource creation for type {} with json {}",
resourceType, jsonRepresentation);
return entityManager.createResource(resourceType, jsonRepresentation);
type, definition);
return entityManager.createResource(type, definition);
}
@Path("resource/{resourceId}")
@DELETE
public boolean deleteResource(@PathParam("resourceId") String resourceId)
@Path(EntityPath.RESOURCE_PATH_PART + "/{" + ID_PATH_PARAM + "}")
public boolean deleteResource(@PathParam(ID_PATH_PARAM) String uuid)
throws ResourceNotFoundException, Exception {
logger.trace("requested resource deletion for id {}", resourceId);
return entityManager.deleteResource(resourceId);
logger.trace("requested resource deletion for id {}", uuid);
return entityManager.deleteResource(uuid);
}
/* Relations Methods */
@Path("consistOf/source/{resourceId}/target/{facetId}")
@PUT
public String attachFacet(@PathParam("resourceId") String resourceUUID,
@PathParam("facetId") String facetUUID,
@QueryParam("consistOfType") String consistOfType,
@QueryParam("jsonProperties") String jsonProperties)
@Path(EntityPath.CONSIST_OF_PATH_PART + "/"
+ EntityPath.SOURCE_PATH_PART + "/{"
+ SOURCE_ID_PATH_PARAM + "}/"
+ EntityPath.TARGET_PATH_PART + "/{"
+ TARGET_ID_PATH_PARAM + "}")
public String attachFacet(
@PathParam(SOURCE_ID_PATH_PARAM) String resourceUUID,
@PathParam(TARGET_ID_PATH_PARAM) String facetUUID,
@QueryParam(TYPE_PARAM) String type,
@QueryParam(PROPERTIES_PARAM) String properties)
throws FacetNotFoundException, ResourceNotFoundException,
ResourceRegistryException {
logger.trace(
"requested to attach resource {} to facet {} ({} Type {}) with properties {}",
resourceUUID, facetUUID, ConsistsOf.class.getSimpleName(),
consistOfType, jsonProperties);
return entityManager.attachFacet(resourceUUID, facetUUID,
consistOfType, jsonProperties);
type, properties);
return entityManager.attachFacet(resourceUUID, facetUUID, type,
properties);
}
@Path("consistOf/{consistOfId}")
@DELETE
public boolean detachFacet(@PathParam("consistOfId") String consistOfUUID)
@Path(EntityPath.CONSIST_OF_PATH_PART + "/{" + ID_PATH_PARAM
+ "}")
public boolean detachFacet(@PathParam(ID_PATH_PARAM) String consistOfUUID)
throws ResourceRegistryException {
logger.trace("requested to detach {}", consistOfUUID);
return entityManager.detachFacet(consistOfUUID);
}
@Path("relatedTo/source/{sourceResourceId}/target/{targetResourceId}")
@PUT
@Path(EntityPath.RELATED_TO_PATH_PART + "/"
+ EntityPath.SOURCE_PATH_PART + "/{"
+ SOURCE_ID_PATH_PARAM + "}/"
+ EntityPath.TARGET_PATH_PART + "/{"
+ TARGET_ID_PATH_PARAM + "}")
public String attachResource(
@PathParam("sourceResourceId") String sourceResourceUuid,
@PathParam("targetResourceId") String targetResourceUuid,
@QueryParam("relatedToType") String relatedToType,
@QueryParam("jsonProperties") String jsonProperties)
@PathParam(SOURCE_ID_PATH_PARAM) String sourceResourceUUID,
@PathParam(TARGET_ID_PATH_PARAM) String targetResourceUUID,
@QueryParam(TYPE_PARAM) String type,
@QueryParam(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(), relatedToType, jsonProperties);
return entityManager.attachResource(sourceResourceUuid,
targetResourceUuid, relatedToType, jsonProperties);
sourceResourceUUID, targetResourceUUID,
IsRelatedTo.class.getSimpleName(), type, properties);
return entityManager.attachResource(sourceResourceUUID,
targetResourceUUID, type, properties);
}
@Path("relatedTo/{relatedToId}")
@DELETE
public boolean detachResource(
@PathParam("relatedToId") String relatedToUUID)
@Path(EntityPath.RELATED_TO_PATH_PART + "/{" + ID_PATH_PARAM
+ "}")
public boolean detachResource(@PathParam(ID_PATH_PARAM) String relatedToUUID)
throws ResourceRegistryException {
logger.trace("requested to detach {}", relatedToUUID);
return entityManager.detachResource(relatedToUUID);

View File

@ -3,9 +3,11 @@ package org.gcube.informationsystem.resourceregistry.resources;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import org.gcube.informationsystem.resourceregistry.api.SchemaManagement;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
import org.gcube.informationsystem.resourceregistry.api.rest.SchemaPath;
import org.gcube.informationsystem.resourceregistry.resources.impl.SchemaManagementImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -14,7 +16,7 @@ import org.slf4j.LoggerFactory;
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
* @author Lucio Lelii (lucio.lelii@isti.cnr.it)
*/
@ApplicationPath("schema")
@ApplicationPath(SchemaPath.SCHEMA_PATH_PART)
public class SchemaManager {
@ -22,37 +24,40 @@ public class SchemaManager {
protected SchemaManagement schemaManager = new SchemaManagementImpl();
@Path("embedded")
@PUT
public String registerEmbeddedTypeSchema(String jsonSchema) throws SchemaException {
logger.trace("Requested Embedded registration with schema {} ",jsonSchema);
@Path(SchemaPath.EMBEDDED_PATH_PART)
public String registerEmbeddedTypeSchema(@QueryParam(SchemaPath.SCHEMA_PARAM) String jsonSchema) throws SchemaException {
logger.trace("Requested Embedded registration with schema {}",jsonSchema);
return schemaManager.registerEmbeddedTypeSchema(jsonSchema);
}
@Path("facet")
@PUT
public String registerFacetSchema(String jsonSchema) throws SchemaException {
logger.trace("Requested Facet registration with schema {} ",jsonSchema);
@Path(SchemaPath.FACET_PATH_PART)
public String registerFacetSchema(@QueryParam(SchemaPath.SCHEMA_PARAM) String jsonSchema) throws SchemaException {
logger.trace("Requested Facet registration with schema {}",jsonSchema);
return schemaManager.registerFacetSchema(jsonSchema);
}
@Path("resource")
@PUT
public String registerResourceSchema(String jsonSchema) throws SchemaException {
logger.trace("Requested Resource registration with schema {} ",jsonSchema);
@Path(SchemaPath.RESOURCE_PATH_PART)
public String registerResourceSchema(@QueryParam(SchemaPath.SCHEMA_PARAM) String jsonSchema) throws SchemaException {
logger.trace("Requested Resource registration with schema {}",jsonSchema);
return schemaManager.registerResourceSchema(jsonSchema);
}
@Path("consistof")
@PUT
public String registerConsistOfSchema(String jsonSchema) throws SchemaException {
@Path(SchemaPath.CONSIST_OF_PATH_PART)
public String registerConsistOfSchema(@QueryParam(SchemaPath.SCHEMA_PARAM) String jsonSchema) throws SchemaException {
logger.trace("Requested ConsistOf registration with schema {} ",jsonSchema);
return schemaManager.registerConsistOfSchema(jsonSchema);
}
@Path("relatedto")
@PUT
public String registerRelatedToSchema(String jsonSchema) throws SchemaException {
@Path(SchemaPath.RELATED_TO_PATH_PART)
public String registerRelatedToSchema(@QueryParam(SchemaPath.SCHEMA_PARAM) String jsonSchema) throws SchemaException {
logger.trace("Requested RelatedTo registration with schema {} ",jsonSchema);
return schemaManager.registerRelatedToSchema(jsonSchema);
}

View File

@ -154,7 +154,7 @@ public class ContextManagementImplTest {
}
@Test
//@Test
public void devContextTest() throws ContextNotFoundException, ContextException {
String gcube = contextManagementImpl.create(null, "gcube");
logger.trace("/gcube : {}", gcube);