|
|
|
@ -1,10 +1,12 @@
|
|
|
|
|
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;
|
|
|
|
|
import javax.ws.rs.GET;
|
|
|
|
|
import javax.ws.rs.HeaderParam;
|
|
|
|
|
import javax.ws.rs.HttpMethod;
|
|
|
|
|
import javax.ws.rs.InternalServerErrorException;
|
|
|
|
|
import javax.ws.rs.NotAllowedException;
|
|
|
|
|
import javax.ws.rs.PUT;
|
|
|
|
@ -22,6 +24,7 @@ import javax.ws.rs.core.UriInfo;
|
|
|
|
|
import org.gcube.datacatalogue.metadatadiscovery.DataCalogueMetadataFormatReader;
|
|
|
|
|
import org.gcube.gcat.ResourceInitializer;
|
|
|
|
|
import org.gcube.gcat.profile.ISProfile;
|
|
|
|
|
import org.xml.sax.SAXException;
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
|
|
|
|
|
|
|
|
@ -32,7 +35,18 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
|
|
|
|
|
public class Profile extends BaseREST implements org.gcube.gcat.api.interfaces.Profile<Response,Response> {
|
|
|
|
|
|
|
|
|
|
public static final String PROFILE_NAME_PARAMETER = "PROFILE_NAME";
|
|
|
|
|
public static final String PROFILE_VALIDATION_ERROR;
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
StringBuilder validationError = new StringBuilder();
|
|
|
|
|
validationError.append("The Profile is not valid because of the following error at validation time:\n%s\n\n");
|
|
|
|
|
validationError.append("The XSD used to validate the profile is available at %s\n\n");
|
|
|
|
|
validationError.append(
|
|
|
|
|
"To check your profile you can use a tool such as Oxygen XML Editor or an online service such as the one available at:\n");
|
|
|
|
|
validationError.append("- http://www.utilities-online.info/xsdvalidation/\n");
|
|
|
|
|
validationError.append("- https://www.freeformatter.com/xml-validator-xsd.html\n");
|
|
|
|
|
PROFILE_VALIDATION_ERROR = validationError.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Context
|
|
|
|
|
private UriInfo uriInfo;
|
|
|
|
@ -62,7 +76,7 @@ public class Profile extends BaseREST implements org.gcube.gcat.api.interfaces.P
|
|
|
|
|
setCalledMethod("GET /" + PROFILES + "/{" + PROFILE_NAME_PARAMETER + "}");
|
|
|
|
|
try {
|
|
|
|
|
// If the name is SCHEMA
|
|
|
|
|
if(name.compareToIgnoreCase(SCHEMA)==0) {
|
|
|
|
|
if(name.compareToIgnoreCase(SCHEMA) == 0) {
|
|
|
|
|
return DataCalogueMetadataFormatReader.getProfileSchemaString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -86,8 +100,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 NotAllowedException("You cannot manage the profile schema");
|
|
|
|
|
if(name.compareToIgnoreCase(SCHEMA) == 0) {
|
|
|
|
|
throw new NotAllowedException("You cannot manage the profile schema", new Throwable("You cannot manage the profile schema"),
|
|
|
|
|
HttpMethod.GET.toString(), HttpMethod.HEAD.toString());
|
|
|
|
|
}
|
|
|
|
|
ISProfile isProfile = new ISProfile();
|
|
|
|
|
boolean created = isProfile.createOrUpdate(name, xml);
|
|
|
|
@ -102,6 +117,9 @@ public class Profile extends BaseREST implements org.gcube.gcat.api.interfaces.P
|
|
|
|
|
return responseBuilder.type(MediaType.APPLICATION_XML).build();
|
|
|
|
|
} catch(WebApplicationException e) {
|
|
|
|
|
throw e;
|
|
|
|
|
} catch(SAXException e) {
|
|
|
|
|
String schemaURL = uriInfo.getRequestUri().toString().replace(name, SCHEMA);
|
|
|
|
|
throw new BadRequestException(String.format(PROFILE_VALIDATION_ERROR, e.getMessage(), schemaURL));
|
|
|
|
|
} catch(Exception e) {
|
|
|
|
|
throw new InternalServerErrorException(e);
|
|
|
|
|
}
|
|
|
|
@ -112,8 +130,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 NotAllowedException("You cannot manage the profile schema");
|
|
|
|
|
if(name.compareToIgnoreCase(SCHEMA) == 0) {
|
|
|
|
|
throw new NotAllowedException("You cannot manage the profile schema", new Throwable("You cannot manage the profile schema"),
|
|
|
|
|
HttpMethod.GET.toString(), HttpMethod.HEAD.toString());
|
|
|
|
|
}
|
|
|
|
|
ISProfile isProfile = new ISProfile();
|
|
|
|
|
isProfile.delete(name);
|
|
|
|
|