64 lines
1.8 KiB
Java
64 lines
1.8 KiB
Java
/**
|
|
*
|
|
*/
|
|
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;
|
|
import javax.ws.rs.Path;
|
|
import javax.ws.rs.QueryParam;
|
|
import javax.ws.rs.core.Context;
|
|
import javax.ws.rs.core.Response;
|
|
import javax.ws.rs.core.Response.Status;
|
|
|
|
import org.gcube.datatransfer.resolver.services.exceptions.BadRequestException;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
/**
|
|
*
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
* Oct 22, 2018
|
|
*/
|
|
@Path("/")
|
|
public class SMPResolver {
|
|
|
|
private static final String SMP_URI = "smp-uri";
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(SMPResolver.class);
|
|
|
|
/**
|
|
* Gets the smpid.
|
|
*
|
|
* @param smpURI the smp id
|
|
* @param fileName the file name
|
|
* @param contentType the content type
|
|
* @param validation the validation
|
|
* @return the smpid
|
|
*/
|
|
@GET
|
|
@Path("smp")
|
|
public Response getSMPURI(@Context HttpServletRequest httpRequest, @QueryParam(SMP_URI) @Nullable String smpURI, @QueryParam(ConstantsResolver.FILE_NAME) String fileName, @QueryParam(ConstantsResolver.CONTENT_TYPE) String contentType, @QueryParam(ConstantsResolver.VALIDATION) Boolean validation){
|
|
logger.info("resolve smp-uri called");
|
|
|
|
//Checking mandatory parameter smpURI
|
|
if(smpURI==null || smpURI.isEmpty()){
|
|
logger.error(SMP_URI+" not found");
|
|
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 StorageIDResolver.resolveStorageId(httpRequest, smpURI, fileName, contentType, validation);
|
|
|
|
}
|
|
}
|