diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GisResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GisResolver.java index b6f0a51..d2a2c0c 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GisResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GisResolver.java @@ -1,14 +1,79 @@ package org.gcube.datatransfer.resolver.services; +import java.net.URI; +import java.net.URISyntaxException; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.GET; +import javax.ws.rs.POST; import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response.Status; import org.gcube.datatransfer.resolver.Constants; +import org.gcube.datatransfer.resolver.GeonetworkRequestFilterParameters.MODE; +import org.gcube.datatransfer.resolver.GeonetworkRequestFilterParameters.VISIBILITY; +import org.gcube.datatransfer.resolver.services.exceptions.BadRequestException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @Path(Constants.SERVLET_GEONETWORK) public class GisResolver { - public void resolveGeoserver() { - + private static Logger logger = LoggerFactory.getLogger(GisResolver.class); + + private String help = "https://wiki.gcube-system.org/gcube/URI_Resolver#GIS_Resolver"; + + @GET + public void submitGet(@Context HttpServletRequest req, @PathParam("mode") MODE mode, @PathParam("scope") String scope, @PathParam("visibility") VISIBILITY visibility, @PathParam("owner") String owner) { + +// MODE mode = null; +// String theScope = null; +// VISIBILITY visibility = null; +// String owner = null; + + + //Checking mandatory parameter id + if(mode==null){ + logger.error("Path Parameter 'mode' not found"); + try { + throw new BadRequestException(req, Status.NOT_ACCEPTABLE, "Missing mandatory path parameter MODE", StorageHub.class, new URI(help)); + } + catch (URISyntaxException e) { + //silent + } + } + + if(scope==null || scope.isEmpty()){ + logger.error("Path Parameter 'scope' not found"); + try { + throw new BadRequestException(req, Status.NOT_ACCEPTABLE, "Missing mandatory path parameter MODE", StorageHub.class, new URI(help)); + } + catch (URISyntaxException e) { + //silent + } + } + + + if(visibility==null){ + logger.error("Path Parameter 'visibility' not found"); + try { + throw new BadRequestException(req, Status.NOT_ACCEPTABLE, "Missing mandatory path parameter MODE", StorageHub.class, new URI(help)); + } + catch (URISyntaxException e) { + //silent + } + } + + + + } - + + @POST + public void submitPost(){ + + } + } diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/SMPIDResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/SMPIDResolver.java index eb651db..75d9a48 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/SMPIDResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/SMPIDResolver.java @@ -3,6 +3,9 @@ */ package org.gcube.datatransfer.resolver.services; +import java.net.URI; +import java.net.URISyntaxException; + import javax.annotation.Nullable; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.GET; @@ -45,7 +48,12 @@ public class SMPIDResolver { //Checking mandatory parameter smpId if(smpId==null || smpId.isEmpty()){ logger.error(SMP_ID+" not found"); - throw new BadRequestException(httpRequest, Status.NOT_ACCEPTABLE, "Missing mandatory parameter "+SMP_ID, SMPIDResolver.class); + try { + throw new BadRequestException(httpRequest, Status.NOT_ACCEPTABLE, "Missing mandatory parameter "+SMP_ID, SMPIDResolver.class, new URI("https://wiki.gcube-system.org/gcube/URI_Resolver#SMP-ID_Resolver")); + } + catch (URISyntaxException e) { + //silent + } } return StorageManager.resolveStorageId(httpRequest, smpId, fileName, contentType, validation); diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/SMPResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/SMPResolver.java index 756d291..708160e 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/SMPResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/SMPResolver.java @@ -3,6 +3,9 @@ */ package org.gcube.datatransfer.resolver.services; +import java.net.URI; +import java.net.URISyntaxException; + import javax.annotation.Nullable; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.GET; @@ -46,7 +49,12 @@ public class SMPResolver { //Checking mandatory parameter smpURI if(smpURI==null || smpURI.isEmpty()){ logger.error(SMP_URI+" not found"); - throw new BadRequestException(httpRequest, Status.NOT_ACCEPTABLE, "Missing mandatory parameter "+SMP_URI, SMPResolver.class); + try { + throw new BadRequestException(httpRequest, Status.NOT_ACCEPTABLE, "Missing mandatory parameter "+SMP_URI, SMPResolver.class, new URI("https://wiki.gcube-system.org/gcube/URI_Resolver#SMP_Resolver")); + } + catch (URISyntaxException e) { + //silent + } } return StorageManager.resolveStorageId(httpRequest, smpURI, fileName, contentType, validation); diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/StorageHub.java b/src/main/java/org/gcube/datatransfer/resolver/services/StorageHub.java index 2532b85..442f07a 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/StorageHub.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/StorageHub.java @@ -1,5 +1,8 @@ package org.gcube.datatransfer.resolver.services; +import java.net.URI; +import java.net.URISyntaxException; + import javax.enterprise.context.RequestScoped; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.GET; @@ -25,6 +28,8 @@ public class StorageHub { private static Logger logger = LoggerFactory.getLogger(StorageHub.class); + private String help = "https://wiki.gcube-system.org/gcube/URI_Resolver"; + @RequestScoped @PathParam(STORAGE_HUB_ID) String id; @@ -37,7 +42,12 @@ public class StorageHub { //Checking mandatory parameter id if(id==null || id.isEmpty()){ logger.error("Path Parameter "+STORAGE_HUB_ID+" not found"); - throw new BadRequestException(httpRequest, Status.NOT_ACCEPTABLE, "Missing mandatory path parameter "+STORAGE_HUB_ID, StorageHub.class); + try { + throw new BadRequestException(httpRequest, Status.NOT_ACCEPTABLE, "Missing mandatory path parameter "+STORAGE_HUB_ID, StorageHub.class, new URI(help)); + } + catch (URISyntaxException e) { + //silent + } } StreamDescriptor descriptor = shc.open(id).asFile().download(); @@ -55,13 +65,23 @@ public class StorageHub { //Checking mandatory parameter id if(id==null || id.isEmpty()){ logger.error("Path Parameter "+STORAGE_HUB_ID+" not found"); - throw new BadRequestException(httpRequest, Status.NOT_ACCEPTABLE, "Missing mandatory path parameter "+STORAGE_HUB_ID, StorageHub.class); + try { + throw new BadRequestException(httpRequest, Status.NOT_ACCEPTABLE, "Missing mandatory path parameter "+STORAGE_HUB_ID, StorageHub.class, new URI(help)); + } + catch (URISyntaxException e) { + //silent + } } //Checking mandatory parameter id if(version==null || version.isEmpty()){ logger.error("Parameter 'version' not found"); - throw new BadRequestException(httpRequest, Status.NOT_ACCEPTABLE, "Missing mandatory parameter 'version'", StorageHub.class); + try { + throw new BadRequestException(httpRequest, Status.NOT_ACCEPTABLE, "Missing mandatory parameter 'version'", StorageHub.class, new URI(help)); + } + catch (URISyntaxException e) { + //silent + } } StreamDescriptor descriptor = shc.open(id).asFile().downloadSpecificVersion(version); diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/StorageManager.java b/src/main/java/org/gcube/datatransfer/resolver/services/StorageManager.java index a8dab07..bd7e0e5 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/StorageManager.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/StorageManager.java @@ -1,6 +1,8 @@ package org.gcube.datatransfer.resolver.services; import java.io.InputStream; +import java.net.URI; +import java.net.URISyntaxException; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.GET; @@ -45,6 +47,8 @@ public class StorageManager { private static Logger logger = LoggerFactory.getLogger(StorageManager.class); + private static String help = "https://wiki.gcube-system.org/gcube/URI_Resolver#STORAGE-ID_Resolver"; + /** * Gets the storage id. @@ -63,7 +67,12 @@ public class StorageManager { //Checking mandatory parameter storageId if(storageId==null || storageId.isEmpty()){ logger.error(STORAGE_ID+" not found"); - throw new BadRequestException(httpRequest, Status.NOT_ACCEPTABLE, "Missing mandatory path parameter "+STORAGE_ID, StorageManager.class); + try { + throw new BadRequestException(httpRequest, Status.NOT_ACCEPTABLE, "Missing mandatory path parameter "+STORAGE_ID, StorageManager.class, new URI(help)); + } + catch (URISyntaxException e) { + //silent + } } return resolveStorageId(httpRequest, storageId, fileName, contentType, validation); } @@ -86,7 +95,12 @@ public class StorageManager { //Checking mandatory parameter storageId if (storageId == null || storageId.isEmpty()) { logger.warn("storageId not found"); - throw new BadRequestException(httpRequest, Status.NOT_ACCEPTABLE, "Missing mandatory path parameter "+STORAGE_ID, StorageManager.class); + try { + throw new BadRequestException(httpRequest, Status.NOT_ACCEPTABLE, "Missing mandatory path parameter "+STORAGE_ID, StorageManager.class, new URI(help)); + } + catch (URISyntaxException e) { + //silent + } } /* @@ -104,12 +118,22 @@ public class StorageManager { logger.info("Decoded ID"+" = "+ toSEID); }catch(Exception e){ logger.error("Storage Client Exception when getting file from storage: ", e); - throw new InternalServerException(httpRequest, Status.INTERNAL_SERVER_ERROR, "Storage Client Exception when getting file from storage with id: "+storageId, StorageManager.class); + try { + throw new InternalServerException(httpRequest, Status.INTERNAL_SERVER_ERROR, "Storage Client Exception when getting file from storage with id: "+storageId, StorageManager.class, new URI(help)); + } + catch (URISyntaxException e1) { + //silent + } } if(toSEID==null || toSEID.isEmpty()){ logger.error("Decrypted id for storageId: "+storageId +" is null or empty!"); - throw new WrongParameterException(httpRequest, Status.BAD_REQUEST, "Error on decrypting the "+STORAGE_ID+ " '"+storageId+"'. Is it a valid id?", StorageManager.class); + try { + throw new WrongParameterException(httpRequest, Status.BAD_REQUEST, "Error on decrypting the "+STORAGE_ID+ " '"+storageId+"'. Is it a valid id?", StorageManager.class, new URI(help)); + } + catch (URISyntaxException e) { + //silent + } } long size = iClient.getSize().RFileById(toSEID); diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/error/ErrorReport.java b/src/main/java/org/gcube/datatransfer/resolver/services/error/ErrorReport.java index 6b5d106..355e97d 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/error/ErrorReport.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/error/ErrorReport.java @@ -11,6 +11,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.experimental.Builder; @XmlRootElement(name="error") @@ -18,6 +19,7 @@ import lombok.Setter; @NoArgsConstructor @Getter @Setter +@Builder public class ErrorReport implements Serializable{ /** diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/error/ExceptionReport.java b/src/main/java/org/gcube/datatransfer/resolver/services/error/ExceptionReport.java index b47c95a..36479e4 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/error/ExceptionReport.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/error/ExceptionReport.java @@ -4,6 +4,7 @@ package org.gcube.datatransfer.resolver.services.error; import java.io.Serializable; +import java.net.URI; import javax.xml.bind.annotation.XmlRootElement; @@ -11,6 +12,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.experimental.Builder; /** @@ -23,6 +25,7 @@ import lombok.Setter; @NoArgsConstructor @Getter @Setter +@Builder public class ExceptionReport implements Serializable{ /** @@ -33,5 +36,6 @@ public class ExceptionReport implements Serializable{ String request; String method; boolean success; + URI help; ErrorReport error; } diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/BadParameterException.java b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/BadParameterException.java index 00d42de..12e17b9 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/BadParameterException.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/BadParameterException.java @@ -4,6 +4,8 @@ package org.gcube.datatransfer.resolver.services.exceptions; +import java.net.URI; + import javax.servlet.http.HttpServletRequest; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.MediaType; @@ -29,6 +31,7 @@ public class BadParameterException extends WebApplicationException { */ private static final long serialVersionUID = -7600028435121268528L; + /** * Instantiates a new bad parameter exception. * @@ -37,8 +40,23 @@ public class BadParameterException extends WebApplicationException { * @param message the message * @param reportedBySource the reported by source */ - public BadParameterException(HttpServletRequest request, Status httpReturnStatus, String message, Class reportedBySource) { - super(Response.status(httpReturnStatus).entity(new ExceptionReport(Util.getFullURL(request), request.getMethod(), false, new ErrorReport(Status.BAD_REQUEST.getStatusCode(), Status.BAD_REQUEST.name(), message, reportedBySource.getName()))).type(MediaType.APPLICATION_XML).build()); + public BadParameterException(HttpServletRequest request, Status httpReturnStatus, String message, Class reportedBySource, URI help) { + + super(Response.status(httpReturnStatus).entity( + ExceptionReport.builder(). + request(Util.getFullURL(request)). + method(request.getMethod()). + success(false). + help(help). + error( + ErrorReport.builder(). + httpErrorCode(Status.BAD_REQUEST.getStatusCode()). + name(Status.BAD_REQUEST.name()) + .message(message). + reportedBy(reportedBySource.getName()).build()) + .build()) + .type(MediaType.APPLICATION_XML).build()); } + } \ No newline at end of file diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/BadRequestException.java b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/BadRequestException.java index acdc625..c01bedf 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/BadRequestException.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/BadRequestException.java @@ -4,6 +4,8 @@ package org.gcube.datatransfer.resolver.services.exceptions; +import java.net.URI; + import javax.servlet.http.HttpServletRequest; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.MediaType; @@ -37,8 +39,21 @@ public class BadRequestException extends WebApplicationException { * @param message the message * @param reportedBySource the reported by source */ - public BadRequestException(HttpServletRequest request, Status httpReturnStatus, String message, Class reportedBySource) { - super(Response.status(httpReturnStatus).entity(new ExceptionReport(Util.getFullURL(request), request.getMethod(), false, new ErrorReport(Status.BAD_REQUEST.getStatusCode(), Status.BAD_REQUEST.name(), message, reportedBySource.getName()))).type(MediaType.APPLICATION_XML).build()); + public BadRequestException(HttpServletRequest request, Status httpReturnStatus, String message, Class reportedBySource, URI help) { + super(Response.status(httpReturnStatus).entity( + ExceptionReport.builder(). + request(Util.getFullURL(request)). + method(request.getMethod()). + success(false). + help(help). + error( + ErrorReport.builder(). + httpErrorCode(Status.BAD_REQUEST.getStatusCode()). + name(Status.BAD_REQUEST.name()) + .message(message). + reportedBy(reportedBySource.getName()).build()) + .build()) + .type(MediaType.APPLICATION_XML).build()); } } \ No newline at end of file diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/InternalServerException.java b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/InternalServerException.java index be61aad..cd883b4 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/InternalServerException.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/InternalServerException.java @@ -4,6 +4,8 @@ package org.gcube.datatransfer.resolver.services.exceptions; +import java.net.URI; + import javax.servlet.http.HttpServletRequest; import javax.ws.rs.InternalServerErrorException; import javax.ws.rs.core.MediaType; @@ -37,8 +39,21 @@ public class InternalServerException extends InternalServerErrorException { * @param message the message * @param reportedBySource the reported by source */ - public InternalServerException(HttpServletRequest request, Status httpReturnStatus, String message, Class reportedBySource) { - super(Response.status(httpReturnStatus).entity(new ExceptionReport(Util.getFullURL(request), request.getMethod(), false, new ErrorReport(Status.INTERNAL_SERVER_ERROR.getStatusCode(), Status.INTERNAL_SERVER_ERROR.name(), message, reportedBySource.getName()))).type(MediaType.APPLICATION_XML).build()); + public InternalServerException(HttpServletRequest request, Status httpReturnStatus, String message, Class reportedBySource, URI help) { + super(Response.status(httpReturnStatus).entity( + ExceptionReport.builder(). + request(Util.getFullURL(request)). + method(request.getMethod()). + success(false). + help(help). + error( + ErrorReport.builder(). + httpErrorCode(Status.INTERNAL_SERVER_ERROR.getStatusCode()). + name(Status.INTERNAL_SERVER_ERROR.name()) + .message(message). + reportedBy(reportedBySource.getName()).build()) + .build()) + .type(MediaType.APPLICATION_XML).build()); } } \ No newline at end of file diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/WrongParameterException.java b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/WrongParameterException.java index 724021a..d2ea01c 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/WrongParameterException.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/WrongParameterException.java @@ -4,6 +4,8 @@ package org.gcube.datatransfer.resolver.services.exceptions; +import java.net.URI; + import javax.servlet.http.HttpServletRequest; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.MediaType; @@ -38,8 +40,21 @@ public class WrongParameterException extends WebApplicationException { * @param message the message * @param reportedBySource the reported by source */ - public WrongParameterException(HttpServletRequest request, Status httpReturnStatus, String message, Class reportedBySource) { - super(Response.status(httpReturnStatus).entity(new ExceptionReport(Util.getFullURL(request), request.getMethod(), false, new ErrorReport(Status.BAD_REQUEST.getStatusCode(), Status.BAD_REQUEST.name(), message, reportedBySource.getName()))).type(MediaType.APPLICATION_XML).build()); + public WrongParameterException(HttpServletRequest request, Status httpReturnStatus, String message, Class reportedBySource, URI help) { + super(Response.status(httpReturnStatus).entity( + ExceptionReport.builder(). + request(Util.getFullURL(request)). + method(request.getMethod()). + success(false). + help(help). + error( + ErrorReport.builder(). + httpErrorCode(Status.BAD_REQUEST.getStatusCode()). + name(Status.BAD_REQUEST.name()) + .message(message). + reportedBy(reportedBySource.getName()).build()) + .build()) + .type(MediaType.APPLICATION_XML).build()); } } \ No newline at end of file