89 lines
2.7 KiB
Java
89 lines
2.7 KiB
Java
|
/**
|
||
|
*
|
||
|
*/
|
||
|
package org.gcube.datatransfer.resolver.services;
|
||
|
|
||
|
import java.net.URI;
|
||
|
import java.util.concurrent.ExecutionException;
|
||
|
|
||
|
import javax.servlet.http.HttpServletRequest;
|
||
|
import javax.ws.rs.GET;
|
||
|
import javax.ws.rs.Path;
|
||
|
import javax.ws.rs.PathParam;
|
||
|
import javax.ws.rs.core.Context;
|
||
|
import javax.ws.rs.core.Response;
|
||
|
|
||
|
import org.gcube.datatransfer.resolver.caches.LoadingVREsScopeCache;
|
||
|
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
||
|
import org.slf4j.Logger;
|
||
|
import org.slf4j.LoggerFactory;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* The Class DataMinerResolver.
|
||
|
*
|
||
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||
|
* Nov 28, 2018
|
||
|
*/
|
||
|
@Path("/analytics")
|
||
|
public class AnalyticsGetResolver {
|
||
|
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
*/
|
||
|
private static final String UTF_8 = "UTF-8";
|
||
|
private static Logger logger = LoggerFactory.getLogger(AnalyticsGetResolver.class);
|
||
|
private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver";
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Gets the data miner.
|
||
|
*
|
||
|
* @param req the req
|
||
|
* @param provider the provider
|
||
|
* @param path the path
|
||
|
* @param remainPath the remain path
|
||
|
* @return the data miner
|
||
|
*/
|
||
|
@GET
|
||
|
@Path("/get/{vreName}")
|
||
|
public Response getDataMiner(@Context HttpServletRequest req, @PathParam("vreName") String vreName) {
|
||
|
logger.info(this.getClass().getSimpleName()+" GET starts...");
|
||
|
try {
|
||
|
|
||
|
if(vreName==null || vreName.isEmpty()){
|
||
|
logger.error("The path parameter 'vreName' not found or empty in the path");
|
||
|
ExceptionManager.throwBadRequestException(req, "Mandatory path parameter 'vreName' not found or empty", this.getClass(), helpURI);
|
||
|
}
|
||
|
|
||
|
try{
|
||
|
String fullScope = LoadingVREsScopeCache.getCache().get(vreName);
|
||
|
|
||
|
//READ THE DATAMINER URL PORTLET FROM APPLICATION PROFRILE IN THE SCOPE fullScope
|
||
|
String dataminerEndPoint = "https://pre.d4science.org/group/prevre/dataminer-manager";
|
||
|
|
||
|
String queryString = "";
|
||
|
if(req.getQueryString()!=null && !req.getQueryString().isEmpty()){
|
||
|
queryString+="&"+req.getQueryString();
|
||
|
}
|
||
|
|
||
|
String dataMinerResolveURL = String.format("%s?%s", dataminerEndPoint, queryString);
|
||
|
logger.info("Resolving the request as DataMinerURL: "+dataMinerResolveURL);
|
||
|
return Response.seeOther(new URI(dataMinerResolveURL)).build();
|
||
|
|
||
|
}catch (ExecutionException e) {
|
||
|
logger.error("The input VRE Name "+vreName+" not found", e);
|
||
|
ExceptionManager.throwBadRequestException(req, "The input 'VRE Name' "+"+vreName+"+ "not found on Informatiion System. Is it a valid VRE?", this.getClass(), helpURI);
|
||
|
}
|
||
|
|
||
|
return null;
|
||
|
}catch (Exception e) {
|
||
|
logger.error("error resolving catalogue link",e);
|
||
|
ExceptionManager.throwInternalErrorException(req, "Error occurred resolving catalogue link", this.getClass(), helpURI);
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|