2018-12-13 11:09:08 +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 ;
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileReader ;
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 KnimeGetResolver .
*
* @author Francesco Mangiacrapa francesco . mangiacrapa @isti.cnr.it
* Dec 13 , 2018
* /
@Path ( " /knime " )
public class KnimeGetResolver {
private static Logger logger = LoggerFactory . getLogger ( KnimeGetResolver . class ) ;
private static String helpURI = " https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#KNIME_Resolver " ;
2018-12-13 12:39:55 +01:00
private static final String ORG_GCUBE_PORTLETS_USER_KNIMEMODELSIMULATION_MANAGER_SERVICE_IMPL =
" org.gcube.portlets.user.model-simulation-configuration.server.KnimeModelSimulationManagerServiceImpl " ;
2018-12-13 11:09:08 +01:00
private static final String APPLICATION_PROFILE = " ApplicationProfile " ;
private static final String KNIME_EXECUTOR_APPLICATION = null ;
/ * *
* Resolve knime url .
*
* @param req the req
* @param vreName the vre name
* @return the response
* /
@GET
@Path ( " /get/{vreName} " )
public Response resolveKnimeURL ( @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 ) ;
ApplicationProfileReader reader = null ;
try {
2018-12-13 12:39:55 +01:00
reader = new ApplicationProfileReader ( fullScope , APPLICATION_PROFILE , ORG_GCUBE_PORTLETS_USER_KNIMEMODELSIMULATION_MANAGER_SERVICE_IMPL , false ) ;
2018-12-13 11:09:08 +01:00
} catch ( Exception e ) {
2018-12-13 12:39:55 +01:00
logger . error ( " Error on reading the " + APPLICATION_PROFILE + " with APPID: " + ORG_GCUBE_PORTLETS_USER_KNIMEMODELSIMULATION_MANAGER_SERVICE_IMPL , e ) ;
2018-12-13 11:09:08 +01:00
ExceptionManager . throwInternalErrorException ( req , " Error on reading the Application Profile for the " + KNIME_EXECUTOR_APPLICATION + " . Please contact the support " , this . getClass ( ) , helpURI ) ;
}
//READ THE KNIME URL PORTLET FROM APPLICATION PROFRILE IN THE SCOPE fullScope
String knimeExecutorEndPoint = reader . getApplicationProfile ( ) . getUrl ( ) ;
//CHECKING THE QUERY STRING
String queryString = req . getQueryString ( ) ! = null ? req . getQueryString ( ) : " " ;
String knimeExecutorURL = String . format ( " %s?%s " , knimeExecutorEndPoint , queryString ) ;
logger . info ( " Resolving the Knime URL with: " + knimeExecutorURL ) ;
return Response . seeOther ( new URI ( knimeExecutorURL ) ) . 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 on resolving Knime URL " , e ) ;
ExceptionManager . throwInternalErrorException ( req , " Error occurred when resolving Knime URL " , this . getClass ( ) , helpURI ) ;
return null ;
}
}
}