Refs #10244: Expose getSchema() API through Schema port type in addition to Access port type

Task-Url: https://support.d4science.org/issues/10244

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@158261 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-11-07 17:22:29 +00:00
parent d12160248c
commit bc2fdf8afd
1 changed files with 43 additions and 24 deletions

View File

@ -2,10 +2,13 @@ package org.gcube.informationsystem.resourceregistry.rest;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
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 javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
@ -14,6 +17,8 @@ import org.gcube.informationsystem.model.AccessType;
import org.gcube.informationsystem.resourceregistry.ResourceInitializer;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
import org.gcube.informationsystem.resourceregistry.api.rest.SchemaPath;
import org.gcube.informationsystem.resourceregistry.schema.SchemaManagement;
import org.gcube.informationsystem.resourceregistry.schema.SchemaManagementImpl;
@ -28,7 +33,7 @@ public class SchemaManager {
private static Logger logger = LoggerFactory.getLogger(SchemaManager.class);
public static final String TYPE_PATH_PARAM = "type";
/**
* e.g. PUT /resource-registry/schema/{E-R}
*
@ -43,43 +48,57 @@ public class SchemaManager {
@Path("{" + TYPE_PATH_PARAM + "}")
@Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 })
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public Response create(
@PathParam(TYPE_PATH_PARAM) String type,
String json)
public Response create(@PathParam(TYPE_PATH_PARAM) String type, String json)
throws SchemaException, ResourceRegistryException {
logger.info("Requested {} registration with schema {}", type, json);
AccessType accessType = null;
try {
accessType = AccessType.valueOf(type);
switch (accessType) {
case EMBEDDED:
break;
case FACET:
break;
case RESOURCE:
break;
case IS_RELATED_TO:
break;
case CONSISTS_OF:
break;
default:
throw new Exception();
case EMBEDDED:
break;
case FACET:
break;
case RESOURCE:
break;
case IS_RELATED_TO:
break;
case CONSISTS_OF:
break;
default:
throw new Exception();
}
} catch (Exception e) {
String error = String.format("Cannot register %s schema", type);
throw new ResourceRegistryException(error);
}
SchemaManagement schemaManagement = new SchemaManagementImpl();
String ret = schemaManagement.create(json, accessType);
return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8).build();
return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
.build();
}
/*
* e.g. GET /resource-registry/schema/ContactFacet?polymorphic=true
*/
@GET
@Path("{" + TYPE_PATH_PARAM + "}")
@Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 })
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public String read(@PathParam(TYPE_PATH_PARAM) String type,
@QueryParam(AccessPath.POLYMORPHIC_PARAM) @DefaultValue("false") Boolean polymorphic)
throws SchemaNotFoundException, ResourceRegistryException {
logger.info("Requested Schema for type {}", type);
SchemaManagement schemaManagement = new SchemaManagementImpl();
return schemaManagement.read(type, polymorphic);
}
}