Improving HTTP Response code to be more standard.
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@146775 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
533a4e128a
commit
4c0e3ef978
|
@ -107,7 +107,7 @@ public class Access {
|
|||
} catch (ERNotFoundException e) {
|
||||
return Response.status(Status.NOT_FOUND).build();
|
||||
} catch (ERAvailableInAnotherContextException e) {
|
||||
return Response.status(Status.CONFLICT).build();
|
||||
return Response.status(Status.FORBIDDEN).build();
|
||||
} catch (ResourceRegistryException e) {
|
||||
throw e;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ 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.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import org.gcube.informationsystem.resourceregistry.ResourceInitializer;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
|
@ -50,12 +52,13 @@ public class ContextManager {
|
|||
*/
|
||||
@PUT
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public String create(
|
||||
public Response create(
|
||||
@QueryParam(ContextPath.PARENT_CONTEXT_ID_PARAM) String parentUUID,
|
||||
@QueryParam(ContextPath.NAME_PARAM) String name)
|
||||
throws ContextCreationException, ResourceRegistryException {
|
||||
logger.trace("requested to create context with name : {} ", name);
|
||||
return contextManager.create(UUID.fromString(parentUUID), name);
|
||||
String ret = contextManager.create(UUID.fromString(parentUUID), name);
|
||||
return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8).build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,6 +10,8 @@ import javax.ws.rs.Path;
|
|||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import org.gcube.informationsystem.model.entity.Facet;
|
||||
import org.gcube.informationsystem.model.entity.Resource;
|
||||
|
@ -61,14 +63,15 @@ public class ERManager {
|
|||
@Path(ERPath.FACET_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
|
||||
@Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 })
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public String createFacet(@PathParam(TYPE_PATH_PARAM) String type,
|
||||
public Response createFacet(@PathParam(TYPE_PATH_PARAM) String type,
|
||||
String json) throws FacetAlreadyPresentException, ResourceRegistryException {
|
||||
logger.info("requested facet creation for type {} defined by {} ",
|
||||
type, json);
|
||||
FacetManagement facetManagement = new FacetManagement();
|
||||
facetManagement.setElementType(type);
|
||||
facetManagement.setJSON(json);
|
||||
return facetManagement.create();
|
||||
String ret = facetManagement.create();
|
||||
return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8).build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -132,14 +135,15 @@ public class ERManager {
|
|||
@Path(ERPath.RESOURCE_PATH_PART + "/{" + TYPE_PATH_PARAM + "}")
|
||||
@Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 })
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public String createResource(@PathParam(TYPE_PATH_PARAM) String type,
|
||||
public Response createResource(@PathParam(TYPE_PATH_PARAM) String type,
|
||||
String json) throws ResourceAlreadyPresentException, ResourceRegistryException {
|
||||
logger.info("requested resource creation for type {} with json {}",
|
||||
type, json);
|
||||
ResourceManagement resourceManagement = new ResourceManagement();
|
||||
resourceManagement.setElementType(type);
|
||||
resourceManagement.setJSON(json);
|
||||
return resourceManagement.create();
|
||||
String ret = resourceManagement.create();
|
||||
return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8).build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -208,7 +212,7 @@ public class ERManager {
|
|||
+ "/{" + TARGET_ID_PATH_PARAM + "}/{" + TYPE_PATH_PARAM + "}")
|
||||
@Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 })
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public String attachFacet(
|
||||
public Response attachFacet(
|
||||
@PathParam(SOURCE_ID_PATH_PARAM) String resourceUUID,
|
||||
@PathParam(TARGET_ID_PATH_PARAM) String facetUUID,
|
||||
@PathParam(TYPE_PATH_PARAM) String type, String json)
|
||||
|
@ -221,8 +225,9 @@ public class ERManager {
|
|||
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
|
||||
consistsOfManagement.setElementType(type);
|
||||
consistsOfManagement.setJSON(json);
|
||||
return consistsOfManagement.create(UUID.fromString(resourceUUID),
|
||||
String ret = consistsOfManagement.create(UUID.fromString(resourceUUID),
|
||||
UUID.fromString(facetUUID));
|
||||
return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8).build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -265,7 +270,7 @@ public class ERManager {
|
|||
+ TYPE_PATH_PARAM + "}")
|
||||
@Consumes({ MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8 })
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public String attachResource(
|
||||
public Response attachResource(
|
||||
@PathParam(SOURCE_ID_PATH_PARAM) String sourceResourceUUID,
|
||||
@PathParam(TARGET_ID_PATH_PARAM) String targetResourceUUID,
|
||||
@PathParam(TYPE_PATH_PARAM) String type, String json)
|
||||
|
@ -280,9 +285,10 @@ public class ERManager {
|
|||
isRelatedToManagement.setElementType(type);
|
||||
isRelatedToManagement.setJSON(json);
|
||||
|
||||
return isRelatedToManagement.create(
|
||||
String ret = isRelatedToManagement.create(
|
||||
UUID.fromString(sourceResourceUUID),
|
||||
UUID.fromString(targetResourceUUID));
|
||||
return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8).build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,7 +27,7 @@ public class ResourceRegistryExceptionMapper implements ExceptionMapper<Resource
|
|||
} else if(ERAlreadyPresentException.class.isAssignableFrom(exception.getClass())){
|
||||
status = Status.CONFLICT;
|
||||
} else if(ERAvailableInAnotherContextException.class.isAssignableFrom(exception.getClass())){
|
||||
status = Status.CONFLICT;
|
||||
status = Status.FORBIDDEN;
|
||||
} else if(exception.getClass() == ResourceRegistryException.class){
|
||||
status = Status.INTERNAL_SERVER_ERROR;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ import javax.ws.rs.Path;
|
|||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import org.gcube.informationsystem.model.AccessType;
|
||||
import org.gcube.informationsystem.resourceregistry.ResourceInitializer;
|
||||
|
@ -41,7 +43,7 @@ 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 String create(
|
||||
public Response create(
|
||||
@PathParam(TYPE_PATH_PARAM) String type,
|
||||
String json)
|
||||
throws SchemaException, ResourceRegistryException {
|
||||
|
@ -76,112 +78,8 @@ public class SchemaManager {
|
|||
}
|
||||
|
||||
SchemaManagement schemaManagement = new SchemaManagementImpl();
|
||||
return schemaManagement.create(json, accessType);
|
||||
String ret = schemaManagement.create(json, accessType);
|
||||
return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8).build();
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * e.g. PUT /resource-registry/schema/embedded
|
||||
// *
|
||||
// * BODY: {...}
|
||||
// *
|
||||
// * @param json
|
||||
// * @return
|
||||
// * @throws SchemaException
|
||||
// */
|
||||
// @PUT
|
||||
// @Path(SchemaPath.EMBEDDED_PATH_PART)
|
||||
// @Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
|
||||
// @Produces(MediaType.APPLICATION_JSON)
|
||||
// public String registerEmbeddedTypeSchema(String json)
|
||||
// throws SchemaException {
|
||||
// logger.trace("Requested {} registration with schema {}", Embedded.NAME,
|
||||
// json);
|
||||
// SchemaManagement schemaManagement = new SchemaManagementImpl();
|
||||
// return schemaManagement.create(json, AccessType.EMBEDDED);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * e.g. PUT /resource-registry/schema/facet
|
||||
// *
|
||||
// * BODY: {...}
|
||||
// *
|
||||
// * @param json
|
||||
// * @return
|
||||
// * @throws SchemaException
|
||||
// */
|
||||
// @PUT
|
||||
// @Path(SchemaPath.FACET_PATH_PART)
|
||||
// @Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
|
||||
// @Produces(MediaType.APPLICATION_JSON)
|
||||
// public String registerFacetSchema(String json) throws SchemaException {
|
||||
// logger.trace("Requested {} registration with schema {}", Facet.NAME,
|
||||
// json);
|
||||
// SchemaManagement schemaManagement = new SchemaManagementImpl();
|
||||
// return schemaManagement.create(json, AccessType.FACET);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * e.g. PUT /resource-registry/schema/resource
|
||||
// *
|
||||
// * BODY: {...}
|
||||
// *
|
||||
// * @param jsonSchema
|
||||
// * @return
|
||||
// * @throws SchemaException
|
||||
// */
|
||||
// @PUT
|
||||
// @Path(SchemaPath.RESOURCE_PATH_PART)
|
||||
// @Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
|
||||
// @Produces(MediaType.APPLICATION_JSON)
|
||||
// public String registerResourceSchema(String json)
|
||||
// throws SchemaException {
|
||||
// logger.trace("Requested {} registration with schema {}", Resource.NAME,
|
||||
// json);
|
||||
// SchemaManagement schemaManagement = new SchemaManagementImpl();
|
||||
// return schemaManagement.create(json, AccessType.RESOURCE);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * e.g. PUT /resource-registry/schema/consistsOf
|
||||
// *
|
||||
// * BODY: {...}
|
||||
// *
|
||||
// * @param jsonSchema
|
||||
// * @return
|
||||
// * @throws SchemaException
|
||||
// */
|
||||
// @PUT
|
||||
// @Path(SchemaPath.CONSISTS_OF_PATH_PART)
|
||||
// @Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
|
||||
// @Produces(MediaType.APPLICATION_JSON)
|
||||
// public String registerConsistsOfSchema(String json)
|
||||
// throws SchemaException {
|
||||
// logger.trace("Requested {} registration with schema {} ",
|
||||
// ConsistsOf.NAME, json);
|
||||
// SchemaManagement schemaManagement = new SchemaManagementImpl();
|
||||
// return schemaManagement.create(json, AccessType.CONSISTS_OF);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * e.g. PUT /resource-registry/schema/isRelatedTo
|
||||
// *
|
||||
// * BODY: {...}
|
||||
// *
|
||||
// * @param jsonSchema
|
||||
// * @return
|
||||
// * @throws SchemaException
|
||||
// */
|
||||
// @PUT
|
||||
// @Path(SchemaPath.IS_RELATED_TO_PATH_PART)
|
||||
// @Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
|
||||
// @Produces(MediaType.APPLICATION_JSON)
|
||||
// public String registerIsRelatedToSchema(String json)
|
||||
// throws SchemaException {
|
||||
// logger.trace("Requested {} registration with schema {} ",
|
||||
// IsRelatedTo.NAME, json);
|
||||
// SchemaManagement schemaManagement = new SchemaManagementImpl();
|
||||
// return schemaManagement.create(json, AccessType.IS_RELATED_TO);
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue