Added the capability to get the profile schema in profile collection

This commit is contained in:
Luca Frosini 2019-09-06 16:38:15 +02:00
parent b0017e0558
commit a5bdbc6500
1 changed files with 14 additions and 0 deletions

View File

@ -1,5 +1,6 @@
package org.gcube.gcat.rest; package org.gcube.gcat.rest;
import javax.ws.rs.BadRequestException;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue; import javax.ws.rs.DefaultValue;
@ -18,6 +19,7 @@ import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import org.gcube.datacatalogue.metadatadiscovery.DataCalogueMetadataFormatReader;
import org.gcube.gcat.ResourceInitializer; import org.gcube.gcat.ResourceInitializer;
import org.gcube.gcat.profile.ISProfile; import org.gcube.gcat.profile.ISProfile;
@ -31,6 +33,7 @@ public class Profile extends BaseREST implements org.gcube.gcat.api.interfaces.P
public static final String PROFILE_NAME_PARAMETER = "PROFILE_NAME"; public static final String PROFILE_NAME_PARAMETER = "PROFILE_NAME";
@Context @Context
private UriInfo uriInfo; private UriInfo uriInfo;
@ -58,6 +61,11 @@ public class Profile extends BaseREST implements org.gcube.gcat.api.interfaces.P
@DefaultValue(MediaType.APPLICATION_XML) @HeaderParam("Accept") String accept) { @DefaultValue(MediaType.APPLICATION_XML) @HeaderParam("Accept") String accept) {
setCalledMethod("GET /" + PROFILES + "/{" + PROFILE_NAME_PARAMETER + "}"); setCalledMethod("GET /" + PROFILES + "/{" + PROFILE_NAME_PARAMETER + "}");
try { try {
// If the name is SCHEMA
if(name.compareToIgnoreCase(SCHEMA)==0) {
return DataCalogueMetadataFormatReader.getProfileSchemaString();
}
ISProfile isProfile = new ISProfile(); ISProfile isProfile = new ISProfile();
boolean xml = false; boolean xml = false;
if(accept.startsWith(MediaType.APPLICATION_XML)) { if(accept.startsWith(MediaType.APPLICATION_XML)) {
@ -78,6 +86,9 @@ public class Profile extends BaseREST implements org.gcube.gcat.api.interfaces.P
public Response createOrUpdate(@PathParam(PROFILE_NAME_PARAMETER) String name, String xml) { public Response createOrUpdate(@PathParam(PROFILE_NAME_PARAMETER) String name, String xml) {
setCalledMethod("PUT /" + PROFILES + "/{" + PROFILE_NAME_PARAMETER + "}"); setCalledMethod("PUT /" + PROFILES + "/{" + PROFILE_NAME_PARAMETER + "}");
try { try {
if(name.compareToIgnoreCase(SCHEMA)==0) {
throw new BadRequestException("You cannot manage the profile schema");
}
ISProfile isProfile = new ISProfile(); ISProfile isProfile = new ISProfile();
boolean created = isProfile.createOrUpdate(name, xml); boolean created = isProfile.createOrUpdate(name, xml);
ResponseBuilder responseBuilder = null; ResponseBuilder responseBuilder = null;
@ -101,6 +112,9 @@ public class Profile extends BaseREST implements org.gcube.gcat.api.interfaces.P
public Response delete(@PathParam(PROFILE_NAME_PARAMETER) String name) { public Response delete(@PathParam(PROFILE_NAME_PARAMETER) String name) {
setCalledMethod("DELETE /" + PROFILES + "/{" + PROFILE_NAME_PARAMETER + "}"); setCalledMethod("DELETE /" + PROFILES + "/{" + PROFILE_NAME_PARAMETER + "}");
try { try {
if(name.compareToIgnoreCase(SCHEMA)==0) {
throw new BadRequestException("You cannot manage the profile schema");
}
ISProfile isProfile = new ISProfile(); ISProfile isProfile = new ISProfile();
isProfile.delete(name); isProfile.delete(name);
return Response.status(Status.NO_CONTENT).build(); return Response.status(Status.NO_CONTENT).build();