From 9c21766b70bb0d7d5a961bc3bffdd20e59f55d3f Mon Sep 17 00:00:00 2001 From: Loredana Liccardo Date: Fri, 1 Aug 2014 09:27:40 +0000 Subject: [PATCH] add ASLSession object in class GWTdbManagerServiceImpl to manage variables for each user Http session. Classes CancelQueryExecutionEvent, CancelQueryExecutionEventHandler added. Pom file modified to add aslSession adding the related dependency. git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/databases-manager-portlet@99175 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 10 +- pom.xml | 27 +- .../client/GWTdbManagerService.java | 3 + .../client/GWTdbManagerServiceAsync.java | 1 + .../events/CancelQueryExecutionEvent.java | 25 + .../client/events/EventsTypeEnum.java | 3 +- .../CancelQueryExecutionEventHandler.java | 8 + .../client/panels/GxtBorderLayoutPanel.java | 9 +- .../toolbar/GxtToolbarFunctionality.java | 46 +- .../server/GWTdbManagerServiceImpl.java | 426 ++++++++++++++---- .../databasesmanager/server/util/WsUtil.java | 130 ++++++ 11 files changed, 562 insertions(+), 126 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/databasesmanager/client/events/CancelQueryExecutionEvent.java create mode 100644 src/main/java/org/gcube/portlets/user/databasesmanager/client/events/interfaces/CancelQueryExecutionEventHandler.java create mode 100644 src/main/java/org/gcube/portlets/user/databasesmanager/server/util/WsUtil.java diff --git a/.classpath b/.classpath index d790918..59430ab 100644 --- a/.classpath +++ b/.classpath @@ -25,16 +25,16 @@ - - - - - + + + + + diff --git a/pom.xml b/pom.xml index 2388124..6b11c72 100644 --- a/pom.xml +++ b/pom.xml @@ -111,7 +111,12 @@ common-scope-maps [1.0.0-SNAPSHOT, 3.0.0-SNAPSHOT) compile - + + + + org.gcube.applicationsupportlayer + aslcore + provided @@ -135,16 +140,16 @@ - - - - - - - - - - + + + + + + + + + + log4j diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/GWTdbManagerService.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/GWTdbManagerService.java index cd6dd51..80226ba 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/client/GWTdbManagerService.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/GWTdbManagerService.java @@ -2,6 +2,7 @@ package org.gcube.portlets.user.databasesmanager.client; import java.util.LinkedHashMap; import java.util.List; +import java.util.UUID; import org.gcube.portlets.user.databasesmanager.client.datamodel.FileModel; import org.gcube.portlets.user.databasesmanager.client.datamodel.Result; @@ -45,5 +46,7 @@ public interface GWTdbManagerService extends RemoteService { PagingLoadResult LoadTables(PagingLoadConfig config, LinkedHashMap dataInput, boolean SearchTable, String keyword) throws Exception; + + } diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/GWTdbManagerServiceAsync.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/GWTdbManagerServiceAsync.java index 3d2ad6e..247a8f3 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/client/GWTdbManagerServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/GWTdbManagerServiceAsync.java @@ -2,6 +2,7 @@ package org.gcube.portlets.user.databasesmanager.client; import java.util.LinkedHashMap; import java.util.List; +import java.util.UUID; import org.gcube.portlets.user.databasesmanager.client.datamodel.FileModel; import org.gcube.portlets.user.databasesmanager.client.datamodel.Result; diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/CancelQueryExecutionEvent.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/CancelQueryExecutionEvent.java new file mode 100644 index 0000000..c63428c --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/CancelQueryExecutionEvent.java @@ -0,0 +1,25 @@ +package org.gcube.portlets.user.databasesmanager.client.events; + +import org.gcube.portlets.user.databasesmanager.client.events.interfaces.CancelQueryExecutionEventHandler; +import com.google.gwt.event.shared.GwtEvent; + +public class CancelQueryExecutionEvent extends + GwtEvent { + + public static Type TYPE = new Type(); + + @Override + public Type getAssociatedType() { + return TYPE; + } + + @Override + protected void dispatch(CancelQueryExecutionEventHandler handler) { + handler.onCancelQueryExecution(this); + } + + public EventsTypeEnum getKey() { + return EventsTypeEnum.CANCEL_EXECUTION_QUERY; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/EventsTypeEnum.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/EventsTypeEnum.java index 67f26de..e1b0ddd 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/EventsTypeEnum.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/EventsTypeEnum.java @@ -9,6 +9,7 @@ public enum EventsTypeEnum { SMART_SAMPLING_EVENT, RANDOM_SAMPLING_EVENT, LOAD_TABLES_EVENT, - SELECTED_TABLE_EVENT; + SELECTED_TABLE_EVENT, + CANCEL_EXECUTION_QUERY; } \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/interfaces/CancelQueryExecutionEventHandler.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/interfaces/CancelQueryExecutionEventHandler.java new file mode 100644 index 0000000..2a51ff6 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/interfaces/CancelQueryExecutionEventHandler.java @@ -0,0 +1,8 @@ +package org.gcube.portlets.user.databasesmanager.client.events.interfaces; + +import org.gcube.portlets.user.databasesmanager.client.events.CancelQueryExecutionEvent; +import com.google.gwt.event.shared.EventHandler; + +public interface CancelQueryExecutionEventHandler extends EventHandler{ + public void onCancelQueryExecution(CancelQueryExecutionEvent cancelQueryExecutionEvent); +} diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/panels/GxtBorderLayoutPanel.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/panels/GxtBorderLayoutPanel.java index 7714081..05e4af7 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/client/panels/GxtBorderLayoutPanel.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/panels/GxtBorderLayoutPanel.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Set; +import java.util.UUID; import java.util.logging.Level; import java.util.logging.Logger; @@ -114,8 +115,8 @@ public class GxtBorderLayoutPanel extends ContentPanel { west = new ContentPanel(); center = new LayoutContainer(); treePanel = new GxtTreePanel(eventBus, service); - toolbar = new GxtToolbarFunctionality(eventBus); - // toolbar = new GxtToolbarFunctionality(eventBus, RPCservice); +// toolbar = new GxtToolbarFunctionality(eventBus); + toolbar = new GxtToolbarFunctionality(eventBus, RPCservice); this.setHeaderVisible(false); // hide the header of the panel @@ -850,6 +851,10 @@ public class GxtBorderLayoutPanel extends ContentPanel { rootLogger.log(Level.INFO, "Dialect used for smart correction: " + language); + + + + // remote rpc RPCservice.submitQuery(dataForSubmitQuery, dataQuery.getQuery(), true, diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/toolbar/GxtToolbarFunctionality.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/toolbar/GxtToolbarFunctionality.java index 33cb0ec..be0cd1d 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/client/toolbar/GxtToolbarFunctionality.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/toolbar/GxtToolbarFunctionality.java @@ -1,9 +1,11 @@ package org.gcube.portlets.user.databasesmanager.client.toolbar; import java.util.LinkedHashMap; +import java.util.UUID; import java.util.logging.Level; import java.util.logging.Logger; +import org.gcube.portlets.user.databasesmanager.client.GWTdbManagerServiceAsync; import org.gcube.portlets.user.databasesmanager.client.datamodel.SubmitQueryData; import org.gcube.portlets.user.databasesmanager.client.events.LoadTablesEvent; import org.gcube.portlets.user.databasesmanager.client.events.RandomSamplingEvent; @@ -54,28 +56,28 @@ public class GxtToolbarFunctionality { .getLogger("GxtToolbarFunctionality"); // RPC service - // private GWTdbManagerServiceAsync RPCservice = null; + private GWTdbManagerServiceAsync RPCservice = null; // Constructor - public GxtToolbarFunctionality(HandlerManager eBus) { - eventBus = eBus; - toolBar = new ToolBar(); - initToolBar(); - addHandler(); - addSelectionListenersOnToolBar(); - } +// public GxtToolbarFunctionality(HandlerManager eBus) { +// eventBus = eBus; +// toolBar = new ToolBar(); +// initToolBar(); +// addHandler(); +// addSelectionListenersOnToolBar(); +// } // Constructor with GWTdbManagerServiceAsync service parameter - // public GxtToolbarFunctionality(HandlerManager eBus, - // GWTdbManagerServiceAsync service) { - // - // eventBus = eBus; - // RPCservice = service; - // toolBar = new ToolBar(); - // initToolBar(); - // addHandler(); - // addSelectionListenersOnToolBar(); - // } + public GxtToolbarFunctionality(HandlerManager eBus, + GWTdbManagerServiceAsync service) { + + eventBus = eBus; + RPCservice = service; + toolBar = new ToolBar(); + initToolBar(); + addHandler(); + addSelectionListenersOnToolBar(); + } private void initToolBar() { @@ -239,6 +241,11 @@ public class GxtToolbarFunctionality { @Override public void componentSelected(ButtonEvent ce) { + //start computation and get id + + //generate a UUID for this request +// UUID id = UUID.randomUUID(); + // recover info from dialog setInfoOnSubmitQuery(form, dialog, dialogID); @@ -257,6 +264,9 @@ public class GxtToolbarFunctionality { ButtonEvent ce) { rootLogger.log(Level.INFO, "button Cancel event"); + + //remove computation + dialog.hide(); } }); diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/server/GWTdbManagerServiceImpl.java b/src/main/java/org/gcube/portlets/user/databasesmanager/server/GWTdbManagerServiceImpl.java index e122248..4269616 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/server/GWTdbManagerServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/server/GWTdbManagerServiceImpl.java @@ -1,9 +1,11 @@ package org.gcube.portlets.user.databasesmanager.server; import java.util.ArrayList; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.UUID; import java.io.IOException; import java.io.InputStream; import java.net.URL; @@ -12,6 +14,7 @@ import java.net.URLStreamHandler; import javax.servlet.http.HttpSession; import org.apache.regexp.RE; +import org.gcube.application.framework.core.session.ASLSession; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.contentmanager.storageclient.model.protocol.smp.SMPURLConnection; import org.gcube.data.analysis.statisticalmanager.proxies.StatisticalManagerDSL; @@ -44,6 +47,8 @@ import org.gcube.portlets.user.databasesmanager.client.datamodel.Parameter; import org.gcube.portlets.user.databasesmanager.client.datamodel.Result; import org.gcube.portlets.user.databasesmanager.client.datamodel.Row; import org.gcube.portlets.user.databasesmanager.server.util.SessionUtil; +import org.gcube.portlets.user.databasesmanager.server.util.WsUtil; + import com.extjs.gxt.ui.client.data.BasePagingLoadResult; import com.extjs.gxt.ui.client.data.PagingLoadConfig; import com.extjs.gxt.ui.client.data.PagingLoadResult; @@ -54,25 +59,56 @@ import org.apache.log4j.Logger; public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements GWTdbManagerService { - // the result generated in the LoadTables method - private List result = null; +// // the result generated in the LoadTables method +// private List result = null; // information about a database - private String currentDB = ""; - private String previousDB = ""; +// private String currentDB = ""; +// private String previousDB = ""; // information about a schema - private String currentSchema = ""; - private String previousSchema = ""; +// private String currentSchema = ""; +// private String previousSchema = ""; + + //Hashmap that contains computationId +// HashMap computationIDMap = new HashMap(); + // logger private static Logger logger = Logger .getLogger(GWTdbManagerServiceImpl.class); public GWTdbManagerServiceImpl() { + } + + private void initVariables(){ + ASLSession session = WsUtil.getAslSession(this.getThreadLocalRequest().getSession()); + + // the result generated in the LoadTables method + List result = new ArrayList(); + session.setAttribute("TablesResult", result); + + // information about a database + String currentDB = ""; + session.setAttribute("currentDB", currentDB); + String previousDB = ""; + session.setAttribute("previousDB", previousDB); + + // information about a schema + String currentSchema = ""; + session.setAttribute("currentSchema", currentSchema); + String previousSchema = ""; + session.setAttribute("previousSchema", previousSchema); + + } // to get resources from IS + @Override public List getResource() throws Exception { - // data input + + //initialize variables with application startup + initVariables(); + + // data input List inputParameters = new ArrayList(); // data output List outputParameters = new ArrayList(); @@ -201,6 +237,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements @Override public List getDBSchema(LinkedHashMap dataInput) throws Exception { + + // data input List inputParameters = new ArrayList(); // data output @@ -344,27 +382,41 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements public PagingLoadResult LoadTables(PagingLoadConfig config, LinkedHashMap dataInput, boolean SearchTable, String keyword) throws Exception { + + ASLSession session = WsUtil.getAslSession(this.getThreadLocalRequest().getSession()); + List result = (List) session.getAttribute("TablesResult"); // check on a database + String currentDB = ""; currentDB = dataInput.get("DatabaseName"); + String previousDB = (String) session.getAttribute("previousDB"); + if (!currentDB.equals(previousDB)) { - result = null; +// result = null; + result = new ArrayList(); System.gc(); } previousDB = currentDB; + session.setAttribute("previousDB", previousDB); // check on a schema + String currentSchema = ""; currentSchema = dataInput.get("SchemaName"); + String previousSchema = (String) session.getAttribute("previousSchema"); if (!currentSchema.equals(previousSchema)) { - result = null; +// result = null; + result = new ArrayList(); System.gc(); } previousSchema = currentSchema; + session.setAttribute("previousSchema", previousSchema); // get tables - if (result == null) +// if (result == null) +// result = getTables(dataInput); + if (result.size()==0) result = getTables(dataInput); // Create a sublist and add data to list according @@ -418,90 +470,278 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements loadResult = new BasePagingLoadResult(sublist, config.getOffset(), totalNumber); + + session.setAttribute("TablesResult", result); return loadResult; } - // to submit a query - @Override - public List submitQuery(LinkedHashMap dataDB, - String query, boolean valueReadOnlyQuery, - boolean smartCorrectionQuery, String language) throws Exception { + + // to submit a query + @Override + public List submitQuery(LinkedHashMap dataDB, + String query, boolean valueReadOnlyQuery, + boolean smartCorrectionQuery, String language) throws Exception { + + logger.info("Dialect used for smart correction: " + language); + + // data input + List inputParameters = new ArrayList(); + // data output + List output = new ArrayList(); + + // get list of algorithms + List algorithms = new ArrayList(); + algorithms = getDatabaseManagerAlgorithms(); + + // get algorithmId + String algorithmId = null; + + for (int i = 0; i < algorithms.size(); i++) { + if (algorithms.get(i).equals("SUBMITQUERY")) { + algorithmId = algorithms.get(i); + + // print check + // logger.info("algorithmId: " + algorithmId); + } + } + + // get input parameters of the algorithm + inputParameters = getParameters(algorithmId); + + if (inputParameters.size() != 0) { + // print check + logger.info("algorithm input parameters retrieved"); + } + + // print check + // for (int i = 0; i < inputParameters.size(); i++) { + // logger.info(inputParameters.get(i).getName()); + // } + + // print check + logger.info("ResourceName: " + dataDB.get("ResourceName")); + logger.info("DatabaseName: " + dataDB.get("DatabaseName")); + logger.info("Query: " + query); + logger.info("SmartCorrections check: " + smartCorrectionQuery); + + inputParameters.get(0).setValue(dataDB.get("ResourceName")); + inputParameters.get(1).setValue(dataDB.get("DatabaseName")); + inputParameters.get(2).setValue(String.valueOf(valueReadOnlyQuery)); + inputParameters.get(3).setValue(String.valueOf(smartCorrectionQuery)); + inputParameters.get(4).setValue(language); + inputParameters.get(5).setValue(query); + + // create data structure + ComputationOutput outputData = new ComputationOutput(); + // computation id + String computationId = startComputation(algorithmId, inputParameters, + outputData); + +// computationIDMap.put(id, computationId); + + // print check on retrieving data + // logger.info("output data retrieved"); + + // data output values + LinkedHashMap mapValues = new LinkedHashMap(); + // data output keys + LinkedHashMap mapKeys = new LinkedHashMap(); + + mapValues = outputData.getMapValues(); + mapKeys = outputData.getmapKeys(); + + for (int i = 0; i < mapValues.size(); i++) { + Result row = new Result(mapKeys.get(String.valueOf(i)), + mapValues.get(String.valueOf(i))); + output.add(row); + } + + return output; + } - logger.info("Dialect used for smart correction: " + language); +// // to submit a query +// public String startSubmitQueryComputation( +// LinkedHashMap dataDB, String query, +// boolean valueReadOnlyQuery, boolean smartCorrectionQuery, +// String language) { +// +// logger.info("Dialect used for smart correction: " + language); +// +// // data input +// List inputParameters = new ArrayList(); +// // data output +// List output = new ArrayList(); +// +// // get list of algorithms +// List algorithms = new ArrayList(); +// algorithms = getDatabaseManagerAlgorithms(); +// +// // get algorithmId +// String algorithmId = null; +// +// for (int i = 0; i < algorithms.size(); i++) { +// if (algorithms.get(i).equals("SUBMITQUERY")) { +// algorithmId = algorithms.get(i); +// +// // print check +// // logger.info("algorithmId: " + algorithmId); +// } +// } +// +// // get input parameters of the algorithm +// inputParameters = getParameters(algorithmId); +// +// if (inputParameters.size() != 0) { +// // print check +// logger.info("algorithm input parameters retrieved"); +// } +// +// // print check +// // for (int i = 0; i < inputParameters.size(); i++) { +// // logger.info(inputParameters.get(i).getName()); +// // } +// +// // print check +// logger.info("ResourceName: " + dataDB.get("ResourceName")); +// logger.info("DatabaseName: " + dataDB.get("DatabaseName")); +// logger.info("Query: " + query); +// logger.info("SmartCorrections check: " + smartCorrectionQuery); +// +// inputParameters.get(0).setValue(dataDB.get("ResourceName")); +// inputParameters.get(1).setValue(dataDB.get("DatabaseName")); +// inputParameters.get(2).setValue(String.valueOf(valueReadOnlyQuery)); +// inputParameters.get(3).setValue(String.valueOf(smartCorrectionQuery)); +// inputParameters.get(4).setValue(language); +// inputParameters.get(5).setValue(query); +// +// // // create data structure +// // ComputationOutput outputData = new ComputationOutput(); +// +// // get computation id +// +// SMComputationConfig config = new SMComputationConfig(); +// SMInputEntry[] list = new SMInputEntry[inputParameters.size()]; +// int i = 0; +// +// for (Parameter p : inputParameters) +// list[i++] = new SMInputEntry(p.getName(), p.getValue()); +// config.parameters(new SMEntries(list)); +// config.algorithm(algorithmId); +// +// // create a computation request +// SMComputationRequest request = new SMComputationRequest(); +// request.user(getUsername()); +// request.config(config); +// +// // execute computation +// StatisticalManagerFactory factory = getFactory(); +// String computationId = factory.executeComputation(request); +// +// return computationId; +// } - // data input - List inputParameters = new ArrayList(); - // data output - List output = new ArrayList(); +// public float startCheckSubmitQueryComputation(String computationId) { +// +// String scope = getScope(); +// String user = getUsername(); +// +// ScopeProvider.instance.set(scope); +// +// StatisticalManagerFactory factory = StatisticalManagerDSL +// .createStateful().build(); +// +// SMComputation computation = factory.getComputation(computationId); +// +// SMOperationStatus status = SMOperationStatus.values()[computation +// .operationStatus()]; +// +// float percentage = 0; +// +// if (status == SMOperationStatus.RUNNING) { +// +// // logger.info("RUNNING"); +// SMOperationInfo infos = factory.getComputationInfo(computationId, +// user); +// // percentage = Float.parseFloat(infos.percentage()); +// // logger.info("Percentage:" + +// // percentage); +// // computation = factory.getComputation(computationId); +// +// status = SMOperationStatus.values()[computation.operationStatus()]; +// } else if ((status == SMOperationStatus.COMPLETED) +// || (status == SMOperationStatus.FAILED)) { +// +// // logger.info("COMPLETED OR FAILED"); +// +// SMAbstractResource abstractResource = computation +// .abstractResource(); +// SMResource smResource = abstractResource.resource(); +// int resourceTypeIndex = smResource.resourceType(); +// SMResourceType smResType = SMResourceType.values()[resourceTypeIndex]; +// +// // displayOutput(smResource, smResType, outputData); +// +// // print check +// // logger.info("SM resource Name: " + smResource.name()); +// // logger.info("SM resource Name: " + smResource.name()); +// // logger.info("SM resource ID: " + smResource.resourceId()); +// // logger.info("SM resource ID: " + smResource.resourceId()); +// // logger.info("SM resource Description: " + +// // smResource.description()); +// +// percentage = 100; +// } +// return percentage; +// +// } - // get list of algorithms - List algorithms = new ArrayList(); - algorithms = getDatabaseManagerAlgorithms(); - - // get algorithmId - String algorithmId = null; - - for (int i = 0; i < algorithms.size(); i++) { - if (algorithms.get(i).equals("SUBMITQUERY")) { - algorithmId = algorithms.get(i); - - // print check - // logger.info("algorithmId: " + algorithmId); - } - } - - // get input parameters of the algorithm - inputParameters = getParameters(algorithmId); - - if (inputParameters.size() != 0) { - // print check - logger.info("algorithm input parameters retrieved"); - } - - // print check - // for (int i = 0; i < inputParameters.size(); i++) { - // logger.info(inputParameters.get(i).getName()); - // } - - // print check - logger.info("ResourceName: " + dataDB.get("ResourceName")); - logger.info("DatabaseName: " + dataDB.get("DatabaseName")); - logger.info("Query: " + query); - logger.info("SmartCorrections check: " + smartCorrectionQuery); - - inputParameters.get(0).setValue(dataDB.get("ResourceName")); - inputParameters.get(1).setValue(dataDB.get("DatabaseName")); - inputParameters.get(2).setValue(String.valueOf(valueReadOnlyQuery)); - inputParameters.get(3).setValue(String.valueOf(smartCorrectionQuery)); - inputParameters.get(4).setValue(language); - inputParameters.get(5).setValue(query); - - // create data structure - ComputationOutput outputData = new ComputationOutput(); - // computation id - String computationId = startComputation(algorithmId, inputParameters, - outputData); - - // print check on retrieving data - // logger.info("output data retrieved"); - - // data output values - LinkedHashMap mapValues = new LinkedHashMap(); - // data output keys - LinkedHashMap mapKeys = new LinkedHashMap(); - - mapValues = outputData.getMapValues(); - mapKeys = outputData.getmapKeys(); - - for (int i = 0; i < mapValues.size(); i++) { - Result row = new Result(mapKeys.get(String.valueOf(i)), - mapValues.get(String.valueOf(i))); - output.add(row); - } - - return output; - } +// public List getSubmitQueryOutput(String computationId) +// throws Exception { +// +// String scope = getScope(); +// +// ScopeProvider.instance.set(scope); +// +// StatisticalManagerFactory factory = StatisticalManagerDSL +// .createStateful().build(); +// +// SMComputation computation = factory.getComputation(computationId); +// +// SMAbstractResource abstractResource = computation.abstractResource(); +// SMResource smResource = abstractResource.resource(); +// int resourceTypeIndex = smResource.resourceType(); +// SMResourceType smResType = SMResourceType.values()[resourceTypeIndex]; +// +// // create data structure +// ComputationOutput outputData = new ComputationOutput(); +// +// displayOutput(smResource, smResType, outputData); +// +// // print check on retrieving data +// logger.info("output data retrieved"); +// +// // data output +// List output = new ArrayList(); +// +// // data output values +// LinkedHashMap mapValues = new LinkedHashMap(); +// // data output keys +// LinkedHashMap mapKeys = new LinkedHashMap(); +// +// mapValues = outputData.getMapValues(); +// mapKeys = outputData.getmapKeys(); +// +// for (int i = 0; i < mapValues.size(); i++) { +// Result row = new Result(mapKeys.get(String.valueOf(i)), +// mapValues.get(String.valueOf(i))); +// output.add(row); +// } +// +// return output; +// } @Override public List sample(LinkedHashMap dataInput) @@ -799,6 +1039,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } // parse a csv row in a list of values + @Override public List parseCVSString(List result, List attrNames) throws Exception { @@ -1045,7 +1286,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } } - //get output result + // get output result private void getMap(SMObject objRes, ComputationOutput outputData) throws Exception { @@ -1089,7 +1330,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements if (smsubResType == SMResourceType.OBJECT) { SMObject obje = (SMObject) smres; String outstring = obje.url(); - + // logger.info("key: " + smsubResType); // logger.info("object: " + outstring); mapValues.put(String.valueOf(i), outstring); @@ -1129,4 +1370,11 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } + public void removeComputation(String computationId) throws Exception { + StatisticalManagerFactory factory = getFactory(); + factory.removeComputation(computationId); + } + + + } diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/server/util/WsUtil.java b/src/main/java/org/gcube/portlets/user/databasesmanager/server/util/WsUtil.java new file mode 100644 index 0000000..db546b6 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/server/util/WsUtil.java @@ -0,0 +1,130 @@ +package org.gcube.portlets.user.databasesmanager.server.util; + +import javax.servlet.http.HttpSession; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.gcube.application.framework.core.session.ASLSession; +import org.gcube.application.framework.core.session.SessionManager; +//import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager; +//import org.gcube.applicationsupportlayer.social.NotificationsManager; +//import org.gcube.common.homelibrary.home.HomeLibrary; +//import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException; +//import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; +//import org.gcube.common.homelibrary.home.workspace.Workspace; +//import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; +//import org.gcube.portlets.user.workspace.client.model.InfoContactModel; +//import org.gcube.portlets.user.workspace.server.GWTWorkspaceBuilder; +//import org.gcube.portlets.user.workspace.server.notifications.NotificationsProducer; +//import org.gcube.portlets.user.workspace.server.resolver.UriResolverReaderParameter; +//import org.gcube.portlets.user.workspace.server.shortener.UrlShortener; +//import org.gcube.portlets.user.workspace.server.util.resource.PropertySpecialFolderReader; +//import org.gcube.portlets.user.workspace.server.util.scope.ScopeUtilFilter; + + +/** + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * @Feb 18, 2014 + * + */ +public class WsUtil { + + public static final String USERNAME_ATTRIBUTE = ScopeHelper.USERNAME_ATTRIBUTE; +// public static final String FOLDERIMPORTER_ATTRIBUTE = "FOLDER_IMPORTER"; +// public static final String METADATACONVERTER_ATTRIBUTE = "METADATA_CONVERTER"; +// public static final String WORKSPACE_EVENT_COLLECTOR_ATTRIBUTE = "EVENT_COLLECTOR"; +// public static final String WORKSPACEBUILDER_ATTRIBUTE = "WORKSPACEBUILDER"; +// public static final String NOTIFICATION_MANAGER = "NOTIFICATION_MANAGER"; +// public static final String NOTIFICATION_PRODUCER = "NOTIFICATION_PRODUCER"; +// public static final String WS_RUN_IN_TEST_MODE = "WS_RUN_IN_TEST_MODE"; +// public static final String WORKSPACE_SCOPE_UTIL = "WORKSPACE_SCOPE_UTIL"; +// public static final String URL_SHORTENER_SERVICE = "URL_SHORTENER_SERVICE"; +// public static final String URI_RESOLVER_SERVICE = "URI_RESOLVER_SERVICE"; +// public static final String PROPERTY_SPECIAL_FOLDER = "PROPERTY_SPECIAL_FOLDER"; +// public static final String NOTIFICATION_PORTLET_CLASS_ID = "org.gcube.portlets.user.workspace.server.GWTWorkspaceServiceImpl"; //IN DEV + +// public static final String TEST_SCOPE = "/gcube/devsec"; + public static final String TEST_SCOPE = "/gcube/devsec/devVRE"; + + +// public static final String TEST_USER = "pasquale.pagano"; +// public static final String TEST_USER = "federico.defaveri"; +// public static final String TEST_USER = "massimiliano.assante"; +// public static final String TEST_USER = "pasquale.pagano"; +// public static final String TEST_USER = "aureliano.gentile"; +// public static final String TEST_USER = "antonio.gioia"; + + //COMMENT THIS FOR RELEASE +// public static final String TEST_USER = "francesco.mangiacrapa"; +// public static final String TEST_USER_FULL_NAME = "Francesco Mangiacrapa"; + + //UNCOMMENT THIS FOR RELEASE +// public static final String TEST_USER = "test.user"; +// public static final String TEST_USER_FULL_NAME = "Test User"; + + public static final String TEST_USER = "dbmanager"; + public static final String TEST_USER_FULL_NAME = "dbmanager"; + + + protected static Logger logger = Logger.getLogger(WsUtil.class); + + public static boolean withoutPortal = false; + + public static ASLSession getAslSession(HttpSession httpSession) + { + String sessionID = httpSession.getId(); + String user = (String) httpSession.getAttribute(USERNAME_ATTRIBUTE); + ASLSession session; + + if (user == null) { + + /*USE ANOTHER ACCOUNT (OTHERWHISE BY TEST_USER) FOR RUNNING + * COMMENT THIS IN DEVELOP ENVIROMENT (UNCOMMENT IN PRODUCTION)*/ + user=TEST_USER; + + //UNCOMMENT THIS IN DEVELOP ENVIROMENT +// user = "francesco.mangiacrapa"; +// user = "valentina.marioli"; + + logger.warn("WORKSPACE PORTLET STARTING IN TEST MODE - NO USER FOUND - PORTLETS STARTING WITH FOLLOWING SETTINGS:"); + logger.warn("session id: "+sessionID); + logger.warn("TEST_USER: "+user); + logger.warn("TEST_SCOPE: "+TEST_SCOPE); + logger.warn("USERNAME_ATTRIBUTE: "+USERNAME_ATTRIBUTE); + session = SessionManager.getInstance().getASLSession(sessionID, user); + session.setScope(TEST_SCOPE); + + + //MANDATORY FOR SOCIAL LIBRARY + session.setUserAvatarId(user + "Avatar"); + session.setUserFullName(TEST_USER_FULL_NAME); + session.setUserEmailAddress(user + "@mail.test"); + + //SET HTTP SESSION ATTRIBUTE + httpSession.setAttribute(USERNAME_ATTRIBUTE, user); + + withoutPortal = true; + + return session; + + }else if(user.compareToIgnoreCase(TEST_USER)==0){ + + withoutPortal = true; + +//*** COMMENT THIS IN PRODUCTION ENVIROMENT +// }else if(user.compareToIgnoreCase("francesco.mangiacrapa")==0){ +// +// withoutPortal = true; +//*** END UNCOMMENT + }else{ + + withoutPortal = false; + } + + return SessionManager.getInstance().getASLSession(sessionID, user); + } + +}