From a5bdbc65006a352d8b2e93734c2a6ee717889725 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 6 Sep 2019 16:38:15 +0200 Subject: [PATCH] Added the capability to get the profile schema in profile collection --- src/main/java/org/gcube/gcat/rest/Profile.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/org/gcube/gcat/rest/Profile.java b/src/main/java/org/gcube/gcat/rest/Profile.java index 1404845..aad7ab6 100644 --- a/src/main/java/org/gcube/gcat/rest/Profile.java +++ b/src/main/java/org/gcube/gcat/rest/Profile.java @@ -1,5 +1,6 @@ package org.gcube.gcat.rest; +import javax.ws.rs.BadRequestException; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; 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.UriInfo; +import org.gcube.datacatalogue.metadatadiscovery.DataCalogueMetadataFormatReader; import org.gcube.gcat.ResourceInitializer; 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"; + @Context 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) { setCalledMethod("GET /" + PROFILES + "/{" + PROFILE_NAME_PARAMETER + "}"); try { + // If the name is SCHEMA + if(name.compareToIgnoreCase(SCHEMA)==0) { + return DataCalogueMetadataFormatReader.getProfileSchemaString(); + } + ISProfile isProfile = new ISProfile(); boolean xml = false; 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) { setCalledMethod("PUT /" + PROFILES + "/{" + PROFILE_NAME_PARAMETER + "}"); try { + if(name.compareToIgnoreCase(SCHEMA)==0) { + throw new BadRequestException("You cannot manage the profile schema"); + } ISProfile isProfile = new ISProfile(); boolean created = isProfile.createOrUpdate(name, xml); 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) { setCalledMethod("DELETE /" + PROFILES + "/{" + PROFILE_NAME_PARAMETER + "}"); try { + if(name.compareToIgnoreCase(SCHEMA)==0) { + throw new BadRequestException("You cannot manage the profile schema"); + } ISProfile isProfile = new ISProfile(); isProfile.delete(name); return Response.status(Status.NO_CONTENT).build();