2018-12-05 16:58:44 +01:00
/ * *
*
* /
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 ;
2018-12-12 15:38:44 +01:00
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileReader ;
2018-12-05 16:58:44 +01:00
import org.gcube.datatransfer.resolver.caches.LoadingVREsScopeCache ;
import org.gcube.datatransfer.resolver.services.error.ExceptionManager ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
/ * *
2018-12-13 11:09:08 +01:00
* The Class AnalyticsGetResolver .
2018-12-05 16:58:44 +01:00
*
2018-12-13 11:09:08 +01:00
* @author Francesco Mangiacrapa at ISTI - CNR ( francesco . mangiacrapa @isti.cnr.it )
* Dec 13 , 2018
2018-12-05 16:58:44 +01:00
* /
@Path ( " /analytics " )
public class AnalyticsGetResolver {
private static Logger logger = LoggerFactory . getLogger ( AnalyticsGetResolver . class ) ;
2018-12-12 15:38:44 +01:00
private static final String ORG_GCUBE_PORTLETS_USER_DATAMINERMANAGER_SERVER_DATA_MINER_MANAGER_SERVICE_IMPL =
" org.gcube.portlets.user.dataminermanager.server.DataMinerManagerServiceImpl " ;
private static final String APPLICATION_PROFILE = " ApplicationProfile " ;
2018-12-13 12:39:55 +01:00
private static String helpURI = " https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Analytics_Resolver " ;
2018-12-12 15:38:44 +01:00
private static final String ANALYTICS_EXECUTOR_PORTLET_NAME = " Analytics Executor " ;
2018-12-05 16:58:44 +01:00
/ * *
2018-12-13 11:09:08 +01:00
* Resolve analytics url .
2018-12-05 16:58:44 +01:00
*
* @param req the req
2018-12-12 15:38:44 +01:00
* @param vreName the vre name
2018-12-13 11:09:08 +01:00
* @return the response
2018-12-05 16:58:44 +01:00
* /
@GET
@Path ( " /get/{vreName} " )
2018-12-13 11:09:08 +01:00
public Response resolveAnalyticsURL ( @Context HttpServletRequest req , @PathParam ( " vreName " ) String vreName ) {
2018-12-05 16:58:44 +01:00
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 ) ;
2018-12-12 15:38:44 +01:00
ApplicationProfileReader reader = null ;
try {
reader = new ApplicationProfileReader ( fullScope , APPLICATION_PROFILE , ORG_GCUBE_PORTLETS_USER_DATAMINERMANAGER_SERVER_DATA_MINER_MANAGER_SERVICE_IMPL , false ) ;
} catch ( Exception e ) {
logger . error ( " Error on reading the " + APPLICATION_PROFILE + " with APPID: " + ORG_GCUBE_PORTLETS_USER_DATAMINERMANAGER_SERVER_DATA_MINER_MANAGER_SERVICE_IMPL , e ) ;
ExceptionManager . throwInternalErrorException ( req , " Error on reading the Application Profile for the " + ANALYTICS_EXECUTOR_PORTLET_NAME + " . Please contact the support " , this . getClass ( ) , helpURI ) ;
}
2018-12-05 16:58:44 +01:00
//READ THE DATAMINER URL PORTLET FROM APPLICATION PROFRILE IN THE SCOPE fullScope
2018-12-12 15:56:45 +01:00
String analyticsExecutorEndPoint = reader . getApplicationProfile ( ) . getUrl ( ) ;
2018-12-13 11:09:08 +01:00
//CHECKING THE QUERY STRING
String queryString = req . getQueryString ( ) ! = null ? req . getQueryString ( ) : " " ;
String analitycsExecutorURL = String . format ( " %s?%s " , analyticsExecutorEndPoint , queryString ) ;
logger . info ( " Resolving the request with the " + ANALYTICS_EXECUTOR_PORTLET_NAME + " URL: " + analitycsExecutorURL ) ;
return Response . seeOther ( new URI ( analitycsExecutorURL ) ) . build ( ) ;
2018-12-05 16:58:44 +01:00
} 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 ) {
2018-12-13 11:09:08 +01:00
logger . error ( " Error on resolving Anaylitics URL " , e ) ;
ExceptionManager . throwInternalErrorException ( req , " Error occurred when resolving Anaylitics URL " , this . getClass ( ) , helpURI ) ;
2018-12-05 16:58:44 +01:00
return null ;
}
}
}