Added the possibility to download the XSD which validate the profile
schema
This commit is contained in:
parent
a7f35422c9
commit
8d7e88ff72
|
@ -4,7 +4,6 @@ import java.io.StringWriter;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.BadRequestException;
|
||||
import javax.ws.rs.InternalServerErrorException;
|
||||
import javax.ws.rs.NotFoundException;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
|
@ -156,7 +155,7 @@ public class ISProfile {
|
|||
}
|
||||
|
||||
|
||||
public boolean createOrUpdate(String name, String xml) {
|
||||
public boolean createOrUpdate(String name, String xml) throws SAXException {
|
||||
try {
|
||||
MetadataUtility metadataUtility = new MetadataUtility();
|
||||
metadataUtility.validateProfile(xml);
|
||||
|
@ -170,7 +169,7 @@ public class ISProfile {
|
|||
} catch(WebApplicationException e) {
|
||||
throw e;
|
||||
} catch (SAXException e) {
|
||||
throw new BadRequestException(e);
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
throw new InternalServerErrorException(e);
|
||||
} finally {
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
package org.gcube.gcat.profile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.gcube.datacatalogue.metadatadiscovery.DataCalogueMetadataFormatReader;
|
||||
import org.gcube.datacatalogue.metadatadiscovery.bean.MetadataProfile;
|
||||
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataFormat;
|
||||
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.NamespaceCategory;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class MetadataUtility {
|
||||
|
||||
|
@ -23,7 +27,7 @@ public class MetadataUtility {
|
|||
dataCalogueMetadataFormatReader = new DataCalogueMetadataFormatReader();
|
||||
}
|
||||
|
||||
public void validateProfile(String xmlProfile) throws Exception {
|
||||
public void validateProfile(String xmlProfile) throws ParserConfigurationException, SAXException, IOException {
|
||||
dataCalogueMetadataFormatReader.validateProfile(xmlProfile);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue