2018-10-22 12:56:04 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.datatransfer.resolver.services;
|
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.ws.rs.GET;
|
|
|
|
import javax.ws.rs.Path;
|
|
|
|
import javax.ws.rs.QueryParam;
|
2018-12-14 11:53:50 +01:00
|
|
|
import javax.ws.rs.WebApplicationException;
|
2018-10-22 12:56:04 +02:00
|
|
|
import javax.ws.rs.core.Context;
|
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
|
2018-11-15 16:21:31 +01:00
|
|
|
import org.gcube.datatransfer.resolver.ConstantsResolver;
|
2019-10-02 12:43:35 +02:00
|
|
|
import org.gcube.datatransfer.resolver.ConstantsResolver.CONTENT_DISPOSITION_VALUE;
|
2018-10-23 11:27:04 +02:00
|
|
|
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
2019-10-02 12:43:35 +02:00
|
|
|
import org.gcube.datatransfer.resolver.util.ValidateContentDisposition;
|
2018-10-22 12:56:04 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2018-12-14 11:53:50 +01:00
|
|
|
* The Class SMPResolver.
|
2018-10-22 12:56:04 +02:00
|
|
|
*
|
2018-12-14 14:26:37 +01:00
|
|
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
|
|
|
* Dec 14, 2018
|
2018-10-22 12:56:04 +02:00
|
|
|
*/
|
2019-02-19 15:18:19 +01:00
|
|
|
@Path("smp")
|
2018-10-22 12:56:04 +02:00
|
|
|
public class SMPResolver {
|
|
|
|
|
2018-10-23 11:27:04 +02:00
|
|
|
/**
|
2018-10-23 15:02:50 +02:00
|
|
|
*
|
2018-10-23 11:27:04 +02:00
|
|
|
*/
|
2018-12-14 11:53:50 +01:00
|
|
|
private static final String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver#SMP_Resolver";
|
2018-10-23 11:27:04 +02:00
|
|
|
|
2018-10-22 12:56:04 +02:00
|
|
|
private static final String SMP_URI = "smp-uri";
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(SMPResolver.class);
|
|
|
|
|
|
|
|
/**
|
2018-12-14 11:53:50 +01:00
|
|
|
* Gets the smpuri.
|
2018-10-22 12:56:04 +02:00
|
|
|
*
|
2018-12-14 11:53:50 +01:00
|
|
|
* @param req the req
|
|
|
|
* @param smpURI the smp uri
|
2018-10-22 12:56:04 +02:00
|
|
|
* @param fileName the file name
|
|
|
|
* @param contentType the content type
|
|
|
|
* @param validation the validation
|
2018-12-14 11:53:50 +01:00
|
|
|
* @return the smpuri
|
|
|
|
* @throws WebApplicationException the web application exception
|
2018-10-22 12:56:04 +02:00
|
|
|
*/
|
|
|
|
@GET
|
2019-02-19 15:18:19 +01:00
|
|
|
@Path("")
|
2018-12-14 11:53:50 +01:00
|
|
|
public Response getSMPURI(@Context HttpServletRequest req,
|
|
|
|
@QueryParam(SMP_URI) @Nullable
|
|
|
|
String smpURI,
|
|
|
|
@QueryParam(ConstantsResolver.QUERY_PARAM_FILE_NAME) String fileName,
|
|
|
|
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENT_TYPE) String contentType,
|
2019-10-02 12:43:35 +02:00
|
|
|
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION) String contentDisposition,
|
|
|
|
@QueryParam(ConstantsResolver.QUERY_PARAM_VALIDATION) boolean validation) throws WebApplicationException{
|
2018-12-14 11:53:50 +01:00
|
|
|
|
2018-10-23 15:02:50 +02:00
|
|
|
logger.info(this.getClass().getSimpleName()+" GET starts...");
|
2018-10-22 12:56:04 +02:00
|
|
|
|
2018-12-14 11:53:50 +01:00
|
|
|
try{
|
|
|
|
//Checking mandatory parameter smpURI
|
|
|
|
if(smpURI==null || smpURI.isEmpty()){
|
|
|
|
logger.error(SMP_URI+" not found");
|
2018-12-14 14:26:37 +01:00
|
|
|
throw ExceptionManager.badRequestException(req, "Missing mandatory parameter "+SMP_URI, SMPResolver.class, helpURI);
|
2018-12-14 11:53:50 +01:00
|
|
|
}
|
2019-10-02 12:43:35 +02:00
|
|
|
|
|
|
|
//Checking the optional parameter "Content-Disposition"
|
|
|
|
CONTENT_DISPOSITION_VALUE dispositionValue = CONTENT_DISPOSITION_VALUE.attachment;
|
|
|
|
//Validating the Content-Disposition value
|
|
|
|
dispositionValue = ValidateContentDisposition.validValue(req, this.getClass(), helpURI, contentDisposition);
|
2018-10-22 12:56:04 +02:00
|
|
|
|
2019-10-02 12:43:35 +02:00
|
|
|
return StorageIDResolver.resolveStorageId(req, smpURI, fileName, contentType, dispositionValue, validation);
|
2018-12-14 11:53:50 +01:00
|
|
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
|
|
|
if(!(e instanceof WebApplicationException)){
|
|
|
|
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
|
|
|
String error = "Error occurred on resolving the smpURI "+smpURI+". Please, contact the support!";
|
2018-12-14 14:26:37 +01:00
|
|
|
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
2018-12-14 11:53:50 +01:00
|
|
|
}
|
|
|
|
//ALREADY MANAGED AS WebApplicationException
|
|
|
|
logger.error("Exception:", e);
|
|
|
|
throw (WebApplicationException) e;
|
|
|
|
}
|
2018-10-22 12:56:04 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|