package org.gcube.portlets.user.dataminermanager.server; import java.util.List; import java.util.Map; import javax.servlet.ServletException; import javax.servlet.http.HttpSession; import org.gcube.application.framework.accesslogger.library.impl.AccessLogger; import org.gcube.application.framework.core.session.ASLSession; import org.gcube.portlets.user.dataminermanager.client.bean.ComputationStatus; import org.gcube.portlets.user.dataminermanager.client.bean.Operator; import org.gcube.portlets.user.dataminermanager.client.bean.OperatorsClassification; import org.gcube.portlets.user.dataminermanager.client.rpc.DataMinerPortletService; import org.gcube.portlets.user.dataminermanager.server.smservice.SClient; import org.gcube.portlets.user.dataminermanager.server.storage.StorageUtil; import org.gcube.portlets.user.dataminermanager.server.util.DataMinerWorkAreaManager; import org.gcube.portlets.user.dataminermanager.server.util.TableReader; import org.gcube.portlets.user.dataminermanager.shared.data.OutputData; import org.gcube.portlets.user.dataminermanager.shared.data.TableItemSimple; import org.gcube.portlets.user.dataminermanager.shared.data.computations.ComputationData; import org.gcube.portlets.user.dataminermanager.shared.data.computations.ComputationId; import org.gcube.portlets.user.dataminermanager.shared.exception.ServiceException; import org.gcube.portlets.user.dataminermanager.shared.parameters.Parameter; import org.gcube.portlets.user.dataminermanager.shared.session.UserInfo; import org.gcube.portlets.user.dataminermanager.shared.workspace.DataMinerWorkArea; import org.gcube.portlets.user.dataminermanager.shared.workspace.ItemDescription; //import org.gcube.portlets.user.tdw.server.datasource.DataSourceFactoryRegistry; //import org.gcube.portlets.widgets.file_dw_import_wizard.server.file.TargetRegistry; import org.gcube.portlets.widgets.wsexplorer.shared.Item; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.allen_sauer.gwt.log.client.Log; import com.google.gwt.user.server.rpc.RemoteServiceServlet; /** * * @author Giancarlo Panichi * email: g.panichi@isti.cnr.it * */ @SuppressWarnings("serial") public class DataMinerManagerServiceImpl extends RemoteServiceServlet implements DataMinerPortletService { public static AccessLogger accountinglog = AccessLogger.getAccessLogger(); private static Logger logger = LoggerFactory .getLogger(DataMinerManagerServiceImpl.class); /** * {@inheritDoc} */ @Override public void init() throws ServletException { super.init(); logger.info("DataMinerManager started!"); } /** * * {@inheritDoc} * */ @Override public UserInfo hello() throws ServiceException { try { HttpSession session = this.getThreadLocalRequest().getSession(); ASLSession aslSession = SessionUtil.getASLSession(session); UserInfo userInfo = new UserInfo(aslSession.getUsername(), aslSession.getGroupId(), aslSession.getGroupName(), aslSession.getScope(), aslSession.getScopeName(), aslSession.getUserEmailAddress(), aslSession.getUserFullName()); logger.debug("UserInfo: " + userInfo); return userInfo; } catch (ServiceException e) { e.printStackTrace(); throw e; } catch (Throwable e) { e.printStackTrace(); logger.error("Hello(): " + e.getLocalizedMessage(), e); throw new ServiceException(e.getLocalizedMessage(), e); } } @Override public List getOperatorsClassifications() throws ServiceException { try { HttpSession session = this.getThreadLocalRequest().getSession(); ASLSession aslSession = SessionUtil.getASLSession(session); SClient smClient = SessionUtil.getSClient(aslSession); List list= smClient.getOperatorsClassifications(); //SessionUtil.putSClient(session, smClient); return list; } catch (ServiceException e) { logger.error(e.getLocalizedMessage()); throw e; } catch (Throwable e) { logger.error( "An error occurred getting the OperatorsClassifications list: " + e.getLocalizedMessage(), e); e.printStackTrace(); // return null; throw new ServiceException(e.getLocalizedMessage(), e); } } @Override public List getParameters(Operator operator) throws ServiceException { try { HttpSession session = this.getThreadLocalRequest().getSession(); ASLSession aslSession = SessionUtil.getASLSession(session); SClient smClient = SessionUtil.getSClient(aslSession); List list=smClient.getInputParameters(operator); //SessionUtil.putSClient(session, smClient); return list; } catch (ServiceException e) { logger.error(e.getLocalizedMessage()); throw e; } catch (Throwable e) { logger.error("Error retrieving parameters: " + e.getLocalizedMessage()); e.printStackTrace(); throw new ServiceException(e.getLocalizedMessage(), e); } } @Override public ComputationId startComputation(Operator operator) throws ServiceException { try { HttpSession session = this.getThreadLocalRequest().getSession(); ASLSession aslSession = SessionUtil.getASLSession(session); logger.debug("StartComputation(): [ operator=" + operator + "]"); SClient smClient = SessionUtil.getSClient(aslSession); ComputationId computationId= smClient.startComputation(operator); //SessionUtil.putSClient(session, smClient); return computationId; } catch (ServiceException e) { logger.error(e.getLocalizedMessage()); throw e; } catch (Throwable e) { logger.error("Error in start computation: " + e.getLocalizedMessage()); e.printStackTrace(); throw new ServiceException(e.getLocalizedMessage(), e); } } @Override public ComputationId resubmit(ItemDescription itemDescription) throws ServiceException { try { HttpSession session = this.getThreadLocalRequest().getSession(); ASLSession aslSession = SessionUtil.getASLSession(session); logger.debug("Resubmit(): " + itemDescription); Map properties = StorageUtil.getProperties( aslSession.getUsername(), itemDescription.getId()); logger.debug("Properties: " + properties); SClient smClient = SessionUtil.getSClient(aslSession); ComputationId computationId= smClient.resubmitComputation(properties); //SessionUtil.putSClient(session, smClient); return computationId; } catch (ServiceException e) { logger.error(e.getLocalizedMessage()); throw e; } catch (Throwable e) { logger.error("Error in resubmit computation: " + e.getLocalizedMessage()); e.printStackTrace(); throw new ServiceException(e.getLocalizedMessage()); } } @Override public ComputationStatus getComputationStatus(ComputationId computationId) throws ServiceException { try { HttpSession session = this.getThreadLocalRequest().getSession(); ASLSession aslSession = SessionUtil.getASLSession(session); SClient smClient = SessionUtil.getSClient(aslSession); ComputationStatus computationStatus= smClient.getComputationStatus(computationId); //SessionUtil.putSClient(session, smClient); return computationStatus; } catch (ServiceException e) { logger.error(e.getLocalizedMessage()); throw e; } catch (Throwable e) { logger.error("Error in getComputationStatus: " + e.getLocalizedMessage()); e.printStackTrace(); throw new ServiceException(e.getLocalizedMessage(), e); } } @Override public void deleteItem(ItemDescription itemDescription) throws ServiceException { try { HttpSession session = this.getThreadLocalRequest().getSession(); ASLSession aslSession = SessionUtil.getASLSession(session); logger.debug("DeleteItem(): " + itemDescription); StorageUtil.deleteItem(aslSession.getUsername(), itemDescription.getId()); return; } catch (ServiceException e) { logger.error(e.getLocalizedMessage()); throw e; } catch (Throwable e) { logger.error(e.getLocalizedMessage(), e); e.printStackTrace(); throw new ServiceException(e.getLocalizedMessage(), e); } } @Override public TableItemSimple retrieveTableInformation(Item item) throws ServiceException { try { HttpSession session = this.getThreadLocalRequest().getSession(); ASLSession aslSession = SessionUtil.getASLSession(session); logger.debug("retrieveTableInformation(): " + item); TableReader tableReader = new TableReader(aslSession, item); TableItemSimple tableItemSimple = tableReader.getTableItemSimple(); return tableItemSimple; } catch (ServiceException e) { logger.error(e.getLocalizedMessage()); throw e; } catch (Throwable e) { logger.error(e.getLocalizedMessage(), e); e.printStackTrace(); throw new ServiceException(e.getLocalizedMessage(), e); } } @Override public DataMinerWorkArea getDataMinerWorkArea() throws ServiceException { try { HttpSession session = this.getThreadLocalRequest().getSession(); ASLSession aslSession = SessionUtil.getASLSession(session); logger.debug("getDataMinerWorkArea()"); DataMinerWorkAreaManager dataMinerWorkAreaManager = new DataMinerWorkAreaManager( aslSession); return dataMinerWorkAreaManager.getDataMinerWorkArea(); } catch (ServiceException e) { logger.error(e.getLocalizedMessage()); throw e; } catch (Throwable e) { logger.error(e.getLocalizedMessage(), e); e.printStackTrace(); throw new ServiceException(e.getLocalizedMessage(), e); } } @Override public String getPublicLink(ItemDescription itemDescription) throws ServiceException { try { HttpSession session = this.getThreadLocalRequest().getSession(); ASLSession aslSession = SessionUtil.getASLSession(session); logger.debug("GetPublicLink(): " + itemDescription); String link = StorageUtil.getPublicLink(aslSession.getUsername(), itemDescription.getId()); return link; } catch (ServiceException e) { logger.error(e.getLocalizedMessage()); throw e; } catch (Throwable e) { logger.error(e.getLocalizedMessage(), e); e.printStackTrace(); throw new ServiceException(e.getLocalizedMessage(), e); } } @Override public String cancelComputation(ComputationId computationId) throws ServiceException { try { HttpSession session = this.getThreadLocalRequest().getSession(); ASLSession aslSession = SessionUtil.getASLSession(session); logger.debug("CancelComputation(): " + computationId); SClient smClient = SessionUtil.getSClient(aslSession); String result = smClient.cancelComputation(computationId); //SessionUtil.putSClient(session, smClient); return result; } catch (ServiceException e) { logger.error(e.getLocalizedMessage()); throw e; } catch (Throwable e) { logger.error(e.getLocalizedMessage(), e); e.printStackTrace(); throw new ServiceException(e.getLocalizedMessage(), e); } } @Override public OutputData getOutputDataByComputationId(ComputationId computationId) throws ServiceException { try { Log.debug("getOutputDataByComputationId: " + computationId); HttpSession session = this.getThreadLocalRequest().getSession(); ASLSession aslSession = SessionUtil.getASLSession(session); SClient smClient = SessionUtil.getSClient(aslSession); OutputData outputData = smClient .getOutputDataByComputationId(computationId); //SessionUtil.putSClient(session, smClient); Log.debug("OutputData: " + outputData); return outputData; } catch (ServiceException e) { logger.error(e.getLocalizedMessage()); throw e; } catch (Throwable e) { logger.error("Error retrieving output by computation id: " + e.getLocalizedMessage()); e.printStackTrace(); throw new ServiceException(e.getLocalizedMessage(), e); } } @Override public ComputationData getComputationData(ItemDescription itemDescription) throws ServiceException { try { HttpSession session = this.getThreadLocalRequest().getSession(); ASLSession aslSession = SessionUtil.getASLSession(session); logger.debug("OutputDataByComputationItemt(): " + itemDescription); Map properties = StorageUtil.getProperties( aslSession.getUsername(), itemDescription.getId()); logger.debug("Properties: " + properties); SClient smClient = SessionUtil.getSClient(aslSession); ComputationData computationData= smClient.getComputationDataByComputationProperties(properties); //SessionUtil.putSClient(session, smClient); return computationData; } catch (ServiceException e) { logger.error(e.getLocalizedMessage()); throw e; } catch (Throwable e) { logger.error("Error retrieving output by item: " + e.getLocalizedMessage()); e.printStackTrace(); throw new ServiceException(e.getLocalizedMessage()); } } }