From f2757b816d010f422f716b246a261ddf5345d9d3 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Thu, 3 Nov 2016 11:31:43 +0000 Subject: [PATCH] Updated to DataMiner service git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/databases-manager-portlet@133853 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 4 +- .settings/org.eclipse.wst.common.component | 3 + distro/changelog.xml | 4 + pom.xml | 71 +- .../client/DatabasesManager.java | 6 +- .../client/datamodel/Parameter.java | 22 +- .../client/datamodel/SQLDialect.java | 8 +- .../client/panels/GxtBorderLayoutPanel.java | 28 +- .../client/panels/GxtTreePanel.java | 50 +- .../toolbar/GxtToolbarFunctionality.java | 22 +- .../server/GWTdbManagerServiceImpl.java | 1665 ++++++++--------- .../server/util/SessionUtil.java | 156 +- .../shared/AlgorithmsName.java | 67 + .../databasesmanager/shared/Constants.java | 54 + .../shared/ConstantsPortlet.java | 43 - .../computation}/ComputationOutput.java | 34 +- src/test/resources/AlgorithmInstallation.txt | 10 + 17 files changed, 1119 insertions(+), 1128 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/databasesmanager/shared/AlgorithmsName.java create mode 100644 src/main/java/org/gcube/portlets/user/databasesmanager/shared/Constants.java delete mode 100644 src/main/java/org/gcube/portlets/user/databasesmanager/shared/ConstantsPortlet.java rename src/main/java/org/gcube/portlets/user/databasesmanager/{client/datamodel => shared/computation}/ComputationOutput.java (55%) create mode 100644 src/test/resources/AlgorithmInstallation.txt diff --git a/.classpath b/.classpath index b26bb90..c741ba1 100644 --- a/.classpath +++ b/.classpath @@ -1,6 +1,6 @@ - + @@ -25,5 +25,5 @@ - + diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 22f85c8..172deed 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -4,6 +4,9 @@ + + uses + diff --git a/distro/changelog.xml b/distro/changelog.xml index b16229c..2f95ea7 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,4 +1,8 @@ + + Porting to DataMiner service + Updated dependencies diff --git a/pom.xml b/pom.xml index 00ac00b..600d5e8 100644 --- a/pom.xml +++ b/pom.xml @@ -15,14 +15,14 @@ org.gcube.portlets.user databases-manager-portlet war - 1.5.0-SNAPSHOT + 1.6.0-SNAPSHOT DatabasesResourceManagerPortlet Databases Resource Manager Portlet https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/databases-manager-portlet - + Giancarlo Panichi @@ -45,7 +45,7 @@ 3.3.2 3.1.1 2.6.1 - + ${env.KEYS} UTF-8 @@ -66,36 +66,23 @@ gwt-servlet ${gwtVersion} - + com.sencha.gxt gxt2.2.5-gwt2.X ${gxt2Version} - - - - - - + + + + + + javax.portlet @@ -147,7 +134,7 @@ gcube-widgets compile - + org.gcube.portlets.widgets @@ -169,18 +156,19 @@ - + + + + - org.gcube.data.analysis - statistical-manager-cl - [2.0.0-SNAPSHOT,3.0.0-SNAPSHOT) + data-miner-manager-cl + data-miner-manager-cl + 1.0.0-SNAPSHOT - - org.gcube.core - common-fw-clients - - @@ -190,6 +178,8 @@ compile + net.sf.ehcache ehcache @@ -197,6 +187,7 @@ provided + org.gcube.portlets.user @@ -226,7 +217,7 @@ 4.8.1 test - + @@ -248,7 +239,7 @@ - + ${webappDirectory}/WEB-INF/classes diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/DatabasesManager.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/DatabasesManager.java index 3dac070..963e19d 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/client/DatabasesManager.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/DatabasesManager.java @@ -11,7 +11,7 @@ import com.google.gwt.user.client.ui.RootPanel; import org.gcube.portlets.user.databasesmanager.client.panels.GxtBorderLayoutPanel; import org.gcube.portlets.user.databasesmanager.client.resources.Resources; -import org.gcube.portlets.user.databasesmanager.shared.ConstantsPortlet; +import org.gcube.portlets.user.databasesmanager.shared.Constants; import org.gcube.portlets.widgets.sessionchecker.client.CheckSession; /** @@ -49,7 +49,7 @@ public class DatabasesManager implements EntryPoint { try { borderLayout = new GxtBorderLayoutPanel(eventBus, service); - RootPanel.get(ConstantsPortlet.CONTENTDIV).add(borderLayout); + RootPanel.get(Constants.CONTENTDIV).add(borderLayout); Window.addResizeHandler(new ResizeHandler() { @Override @@ -76,7 +76,7 @@ public class DatabasesManager implements EntryPoint { */ public void updateSize() { - RootPanel rootPanel = RootPanel.get(ConstantsPortlet.CONTENTDIV); + RootPanel rootPanel = RootPanel.get(Constants.CONTENTDIV); int topBorder = rootPanel.getAbsoluteTop(); diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/datamodel/Parameter.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/datamodel/Parameter.java index 1f3a4d1..47eb033 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/client/datamodel/Parameter.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/datamodel/Parameter.java @@ -11,15 +11,17 @@ public class Parameter implements Serializable { private String objectType; private String defaultValue; - public Parameter(String paramName, String paramDescription, + public Parameter(String name, String paramDescription, String objectType, String defaultValue) { - this.setName(paramName); - this.setParamDescription(paramDescription); - this.setObjectType(objectType); - this.setDefaultValue(defaultValue); + super(); + this.name=name; + this.paramDescription=paramDescription; + this.objectType=objectType; + this.defaultValue=defaultValue; } public Parameter() { + super(); } public String getValue() { @@ -61,4 +63,14 @@ public class Parameter implements Serializable { public String getDefaultValue() { return defaultValue; } + + @Override + public String toString() { + return "Parameter [value=" + value + ", name=" + name + + ", paramDescription=" + paramDescription + ", objectType=" + + objectType + ", defaultValue=" + defaultValue + "]"; + } + + + } diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/datamodel/SQLDialect.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/datamodel/SQLDialect.java index b69166b..ca6336e 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/client/datamodel/SQLDialect.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/datamodel/SQLDialect.java @@ -3,7 +3,7 @@ package org.gcube.portlets.user.databasesmanager.client.datamodel; import java.util.ArrayList; import java.util.List; -import org.gcube.portlets.user.databasesmanager.shared.ConstantsPortlet; +import org.gcube.portlets.user.databasesmanager.shared.Constants; import com.extjs.gxt.ui.client.data.BaseModelData; @@ -31,9 +31,9 @@ public class SQLDialect extends BaseModelData { public static List loadData() { List dialects = new ArrayList(); - SQLDialect element1 = new SQLDialect(ConstantsPortlet.NONE); - SQLDialect element2 = new SQLDialect(ConstantsPortlet.POSTGRES); - SQLDialect element3 = new SQLDialect(ConstantsPortlet.MYSQL); + SQLDialect element1 = new SQLDialect(Constants.NONE); + SQLDialect element2 = new SQLDialect(Constants.POSTGRES); + SQLDialect element3 = new SQLDialect(Constants.MYSQL); dialects.add(element1); dialects.add(element2); 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 7aae2da..7903049 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 @@ -31,7 +31,7 @@ import org.gcube.portlets.user.databasesmanager.client.events.interfaces.SmartSa import org.gcube.portlets.user.databasesmanager.client.events.interfaces.SubmitQueryEventHandler; import org.gcube.portlets.user.databasesmanager.client.resources.Images; import org.gcube.portlets.user.databasesmanager.client.toolbar.GxtToolbarFunctionality; -import org.gcube.portlets.user.databasesmanager.shared.ConstantsPortlet; +import org.gcube.portlets.user.databasesmanager.shared.Constants; import org.gcube.portlets.user.databasesmanager.shared.SessionExpiredException; import org.gcube.portlets.widgets.sessionchecker.client.CheckSession; @@ -363,7 +363,7 @@ public class GxtBorderLayoutPanel extends ContentPanel { dataInput.put("ResourceName", resource); dataInput.put("DatabaseName", database); dataInput.put("SchemaName", ""); - elementType = ConstantsPortlet.DATABASE; + elementType = Constants.DATABASE; } else { // the selected item is a schema rootLogger.log(Level.INFO, "selected element is a schema "); FileModel db = treePanel.getTreeStore().getParent(element); @@ -374,7 +374,7 @@ public class GxtBorderLayoutPanel extends ContentPanel { dataInput.put("ResourceName", resource); dataInput.put("DatabaseName", database); dataInput.put("SchemaName", schema); - elementType = ConstantsPortlet.SCHEMA; + elementType = Constants.SCHEMA; } // print check @@ -837,13 +837,13 @@ public class GxtBorderLayoutPanel extends ContentPanel { "determined Dialect for smart correction: " + dialect); } } - String language = ConstantsPortlet.NONE; + String language = Constants.NONE; - if (dialect.toUpperCase().contains(ConstantsPortlet.POSTGRES)) { - language = ConstantsPortlet.POSTGRES; + if (dialect.toUpperCase().contains(Constants.POSTGRES)) { + language = Constants.POSTGRES; } - if (dialect.toUpperCase().contains(ConstantsPortlet.MYSQL)) { - language = ConstantsPortlet.MYSQL; + if (dialect.toUpperCase().contains(Constants.MYSQL)) { + language = Constants.MYSQL; } rootLogger.log(Level.INFO, "Dialect used for smart correction: " + language); @@ -1329,7 +1329,7 @@ public class GxtBorderLayoutPanel extends ContentPanel { rootLogger.log(Level.INFO, "SchemaName: " + ""); rootLogger.log(Level.INFO, "TableName: " + currentselectedTable); - elementType = ConstantsPortlet.DATABASE; + elementType = Constants.DATABASE; } else { // the table has a schema because the selected item is a schema schema = selectedItem; @@ -1346,7 +1346,7 @@ public class GxtBorderLayoutPanel extends ContentPanel { rootLogger.log(Level.INFO, "SchemaName: " + schema.getName()); rootLogger.log(Level.INFO, "TableName: " + currentselectedTable); - elementType = ConstantsPortlet.SCHEMA; + elementType = Constants.SCHEMA; } // to mask the entire content panel @@ -1453,7 +1453,7 @@ public class GxtBorderLayoutPanel extends ContentPanel { rootLogger.log(Level.INFO, "DatabaseName: " + database.getName()); rootLogger.log(Level.INFO, "SchemaName: " + ""); rootLogger.log(Level.INFO, "TableName: " + currentselectedTable); - elementType = ConstantsPortlet.DATABASE; + elementType = Constants.DATABASE; } else { // the table has a schema schema = selectedItem; @@ -1469,7 +1469,7 @@ public class GxtBorderLayoutPanel extends ContentPanel { rootLogger.log(Level.INFO, "DatabaseName: " + database.getName()); rootLogger.log(Level.INFO, "SchemaName: " + schema.getName()); rootLogger.log(Level.INFO, "TableName: " + currentselectedTable); - elementType = ConstantsPortlet.SCHEMA; + elementType = Constants.SCHEMA; } // to mask the entire content panel obj.mask("Sampling the table", "x-mask-loading"); @@ -1571,7 +1571,7 @@ public class GxtBorderLayoutPanel extends ContentPanel { rootLogger.log(Level.INFO, "DatabaseName: " + database.getName()); rootLogger.log(Level.INFO, "SchemaName: " + ""); rootLogger.log(Level.INFO, "TableName: " + currentselectedTable); - elementType = ConstantsPortlet.DATABASE; + elementType = Constants.DATABASE; } else { // the table has a schema schema = selectedItem; @@ -1587,7 +1587,7 @@ public class GxtBorderLayoutPanel extends ContentPanel { rootLogger.log(Level.INFO, "DatabaseName: " + database.getName()); rootLogger.log(Level.INFO, "SchemaName: " + schema.getName()); rootLogger.log(Level.INFO, "TableName: " + currentselectedTable); - elementType = ConstantsPortlet.SCHEMA; + elementType = Constants.SCHEMA; } // to mask the entire content panel diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/panels/GxtTreePanel.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/panels/GxtTreePanel.java index 33edad7..6d80113 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/client/panels/GxtTreePanel.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/panels/GxtTreePanel.java @@ -32,7 +32,7 @@ import com.google.gwt.user.client.Event; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.AbstractImagePrototype; import org.gcube.portlets.user.databasesmanager.client.datamodel.GeneralOutputFromServlet; -import org.gcube.portlets.user.databasesmanager.shared.ConstantsPortlet; +import org.gcube.portlets.user.databasesmanager.shared.Constants; import org.gcube.portlets.user.databasesmanager.shared.SessionExpiredException; import org.gcube.portlets.widgets.sessionchecker.client.CheckSession; @@ -291,7 +291,7 @@ public class GxtTreePanel extends LayoutContainer { case 3: // the selected item is a database if (selectedItem.getDatabaseType().equals( - ConstantsPortlet.POSTGRES)) { + Constants.POSTGRES)) { // to mask the tree panel treePanel.mask("Loading", "x-mask-loading"); // load schema @@ -468,13 +468,13 @@ public class GxtTreePanel extends LayoutContainer { DBInfo.add(row); if (driver.toUpperCase().contains( - ConstantsPortlet.POSTGRES)) { - DatabaseType = ConstantsPortlet.POSTGRES; + Constants.POSTGRES)) { + DatabaseType = Constants.POSTGRES; } if (driver.toUpperCase().contains( - ConstantsPortlet.MYSQL)) { - DatabaseType = ConstantsPortlet.MYSQL; + Constants.MYSQL)) { + DatabaseType = Constants.MYSQL; } } @@ -512,14 +512,14 @@ public class GxtTreePanel extends LayoutContainer { child.setDatabaseType(DatabaseType); if (DatabaseType - .equals(ConstantsPortlet.MYSQL)) { - child.setDatabaseType(ConstantsPortlet.MYSQL); + .equals(Constants.MYSQL)) { + child.setDatabaseType(Constants.MYSQL); child.setIsExpanded(false); treePanel.setExpanded(child, false); } if (DatabaseType - .equals(ConstantsPortlet.POSTGRES)) { - child.setDatabaseType(ConstantsPortlet.POSTGRES); + .equals(Constants.POSTGRES)) { + child.setDatabaseType(Constants.POSTGRES); } children.add(child); } @@ -722,16 +722,16 @@ public class GxtTreePanel extends LayoutContainer { String value; if (Depth == 1) { // root tree - elementType = ConstantsPortlet.RESOURCESLIST; - value = ConstantsPortlet.RESOURCESLIST; + elementType = Constants.RESOURCESLIST; + value = Constants.RESOURCESLIST; inputData.put(value, value); } else if (Depth == 2) { // resource - elementType = ConstantsPortlet.RESOURCE; + elementType = Constants.RESOURCE; value = selectedItem.getName(); inputData.put("ResourceName", value); } else if (Depth == 3) { // database - elementType = ConstantsPortlet.DATABASE; + elementType = Constants.DATABASE; String database = selectedItem.getName(); // get the database type // String dbType = selectedItem.getDatabaseType(); @@ -740,7 +740,7 @@ public class GxtTreePanel extends LayoutContainer { if (selectedItem.getDatabaseType() != null && (selectedItem.getDatabaseType() - .equals(ConstantsPortlet.POSTGRES))) { // refresh + .equals(Constants.POSTGRES))) { // refresh // schema // list and // query @@ -750,7 +750,7 @@ public class GxtTreePanel extends LayoutContainer { } if (selectedItem.getDatabaseType() != null && (selectedItem.getDatabaseType() - .equals(ConstantsPortlet.MYSQL))) { // refresh + .equals(Constants.MYSQL))) { // refresh // tables list, // query // executed and @@ -762,7 +762,7 @@ public class GxtTreePanel extends LayoutContainer { } else if (Depth == 4) { // Schema. Refresh tables list, query executed // and samplings - elementType = ConstantsPortlet.SCHEMA; + elementType = Constants.SCHEMA; String schema = selectedItem.getName(); FileModel db = store.getParent(selectedItem); String database = db.getName(); @@ -812,7 +812,7 @@ public class GxtTreePanel extends LayoutContainer { removeChildren(selectedItem); tree.layout(true); - if (elemType.equals(ConstantsPortlet.RESOURCESLIST)) { + if (elemType.equals(Constants.RESOURCESLIST)) { List output = new ArrayList(); output = result.getListOutput(); @@ -828,7 +828,7 @@ public class GxtTreePanel extends LayoutContainer { selectedItem.setIsLoaded(true); - } else if (elemType.equals(ConstantsPortlet.RESOURCE)) { + } else if (elemType.equals(Constants.RESOURCE)) { LinkedHashMap output = new LinkedHashMap(); output = result.getMapOutput(); @@ -898,15 +898,15 @@ public class GxtTreePanel extends LayoutContainer { if (driver .toUpperCase() .contains( - ConstantsPortlet.POSTGRES)) { - DatabaseType = ConstantsPortlet.POSTGRES; + Constants.POSTGRES)) { + DatabaseType = Constants.POSTGRES; } if (driver .toUpperCase() .contains( - ConstantsPortlet.MYSQL)) { - DatabaseType = ConstantsPortlet.MYSQL; + Constants.MYSQL)) { + DatabaseType = Constants.MYSQL; } } @@ -949,7 +949,7 @@ public class GxtTreePanel extends LayoutContainer { child.setDatabaseType(DatabaseType); if (DatabaseType - .equals(ConstantsPortlet.MYSQL)) { + .equals(Constants.MYSQL)) { child.setIsExpanded(false); treePanel.setExpanded(child, false); @@ -971,7 +971,7 @@ public class GxtTreePanel extends LayoutContainer { selectedItem.setIsLoaded(true); - } else if (elemType.equals(ConstantsPortlet.DATABASE)) { + } else if (elemType.equals(Constants.DATABASE)) { List output = new ArrayList(); output = result.getListOutput(); 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 860f2c1..953d550 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 @@ -20,7 +20,7 @@ import org.gcube.portlets.user.databasesmanager.client.events.interfaces.Selecte import org.gcube.portlets.user.databasesmanager.client.events.interfaces.SelectedTableEventHandler; import org.gcube.portlets.user.databasesmanager.client.form.GxtFormSubmitQuery; import org.gcube.portlets.user.databasesmanager.client.utils.UIDGenerator; -import org.gcube.portlets.user.databasesmanager.shared.ConstantsPortlet; +import org.gcube.portlets.user.databasesmanager.shared.Constants; import org.gcube.portlets.user.databasesmanager.shared.SessionExpiredException; import org.gcube.portlets.widgets.sessionchecker.client.CheckSession; @@ -101,7 +101,7 @@ public class GxtToolbarFunctionality { // setLayout(new FlowLayout(10)); // Button for tables list - btnTablesList = new Button(ConstantsPortlet.TABLESLIST); + btnTablesList = new Button(Constants.TABLESLIST); // btnSubmitQuery.setIcon(Resources.ICONS.text()); btnTablesList.setScale(ButtonScale.SMALL); btnTablesList.setArrowAlign(ButtonArrowAlign.BOTTOM); @@ -110,7 +110,7 @@ public class GxtToolbarFunctionality { toolBar.add(btnTablesList); // Button for Submit Query - btnSubmitQuery = new Button(ConstantsPortlet.SUBMITQUERY); + btnSubmitQuery = new Button(Constants.SUBMITQUERY); // btnSubmitQuery.setIcon(Resources.ICONS.text()); btnSubmitQuery.setScale(ButtonScale.SMALL); btnSubmitQuery.setArrowAlign(ButtonArrowAlign.BOTTOM); @@ -119,7 +119,7 @@ public class GxtToolbarFunctionality { toolBar.add(btnSubmitQuery); // Button to get the "show create table" - btnShowCreateTable = new Button(ConstantsPortlet.TABLEDETAILS); + btnShowCreateTable = new Button(Constants.TABLEDETAILS); btnShowCreateTable.setScale(ButtonScale.SMALL); btnShowCreateTable.setArrowAlign(ButtonArrowAlign.BOTTOM); btnShowCreateTable @@ -128,14 +128,14 @@ public class GxtToolbarFunctionality { toolBar.add(new SeparatorToolItem()); // Button for Simple Sample - btnSimpleSample = new Button(ConstantsPortlet.SAMPLING); + btnSimpleSample = new Button(Constants.SAMPLING); btnSimpleSample.setScale(ButtonScale.SMALL); btnSimpleSample.setArrowAlign(ButtonArrowAlign.BOTTOM); btnSimpleSample.setToolTip("retrieves the first 100 rows of the table"); toolBar.add(btnSimpleSample); // Button for Smart Sample - btnSmartSample = new Button(ConstantsPortlet.SMARTSAMPLING); + btnSmartSample = new Button(Constants.SMARTSAMPLING); btnSmartSample.setScale(ButtonScale.SMALL); btnSmartSample.setArrowAlign(ButtonArrowAlign.BOTTOM); btnSmartSample @@ -143,7 +143,7 @@ public class GxtToolbarFunctionality { toolBar.add(btnSmartSample); // button for Random Sample - btnRandomSample = new Button(ConstantsPortlet.RANDOMSAMPLING); + btnRandomSample = new Button(Constants.RANDOMSAMPLING); btnRandomSample.setScale(ButtonScale.SMALL); btnRandomSample.setArrowAlign(ButtonArrowAlign.BOTTOM); btnRandomSample @@ -152,7 +152,7 @@ public class GxtToolbarFunctionality { toolBar.add(new SeparatorToolItem()); // button for Random Sample - btnRefresCachedData = new Button(ConstantsPortlet.REFRESHCACHEDDATA); + btnRefresCachedData = new Button(Constants.REFRESHCACHEDDATA); btnRefresCachedData.setScale(ButtonScale.SMALL); btnRefresCachedData.setArrowAlign(ButtonArrowAlign.BOTTOM); btnRefresCachedData.setToolTip("refreshes data"); @@ -494,7 +494,7 @@ public class GxtToolbarFunctionality { case 3: if ((databaseType != null) - && (databaseType.equals(ConstantsPortlet.MYSQL))) { + && (databaseType.equals(Constants.MYSQL))) { btnTablesList.enable(); btnSubmitQuery.enable(); btnRefresCachedData.enable(); @@ -506,7 +506,7 @@ public class GxtToolbarFunctionality { } if ((databaseType != null) - && (databaseType.equals(ConstantsPortlet.POSTGRES))) { + && (databaseType.equals(Constants.POSTGRES))) { btnTablesList.disable(); btnSubmitQuery.enable(); btnRefresCachedData.enable(); @@ -632,7 +632,7 @@ public class GxtToolbarFunctionality { String query = ""; if (tableInfo.isDatabase()) { - if (tableInfo.getDatabaseType().equals(ConstantsPortlet.MYSQL)) { + if (tableInfo.getDatabaseType().equals(Constants.MYSQL)) { String dbName = tableInfo.getDatabaseName(); // the full name equal to "dbname.tablename" 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 95ca2ef..4a54f46 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,91 +1,72 @@ package org.gcube.portlets.user.databasesmanager.server; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStreamWriter; +import java.net.URL; +import java.net.URLConnection; +import java.net.URLStreamHandler; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.concurrent.ConcurrentLinkedQueue; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.net.URLConnection; -import java.net.URLStreamHandler; -import java.io.OutputStreamWriter; -import java.io.FileOutputStream; import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSession; + import net.sf.ehcache.Cache; import net.sf.ehcache.CacheManager; import net.sf.ehcache.Status; import net.sf.ehcache.config.CacheConfiguration; import net.sf.ehcache.config.MemoryUnit; -import net.sf.ehcache.config.SizeOfPolicyConfiguration; -import net.sf.ehcache.config.SizeOfPolicyConfiguration.MaxDepthExceededBehavior; import net.sf.ehcache.store.MemoryStoreEvictionPolicy; + +import org.apache.log4j.Logger; 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; -import org.gcube.data.analysis.statisticalmanager.proxies.StatisticalManagerFactory; -import org.gcube.data.analysis.statisticalmanager.stubs.types.SMAlgorithm; -import org.gcube.data.analysis.statisticalmanager.stubs.types.SMComputationConfig; -import org.gcube.data.analysis.statisticalmanager.stubs.types.SMComputationRequest; -import org.gcube.data.analysis.statisticalmanager.stubs.types.SMGroupedAlgorithms; -import org.gcube.data.analysis.statisticalmanager.stubs.types.SMListGroupedAlgorithms; -import org.gcube.data.analysis.statisticalmanager.stubs.types.SMOperationStatus; -import org.gcube.data.analysis.statisticalmanager.stubs.types.SMParameter; -import org.gcube.data.analysis.statisticalmanager.stubs.types.SMParameters; -import org.gcube.data.analysis.statisticalmanager.stubs.types.SMResourceType; -import org.gcube.data.analysis.statisticalmanager.stubs.types.SMTypeParameter; -import org.gcube.data.analysis.statisticalmanager.stubs.types.schema.SMAbstractResource; -import org.gcube.data.analysis.statisticalmanager.stubs.types.schema.SMComputation; -import org.gcube.data.analysis.statisticalmanager.stubs.types.schema.SMEntries; -import org.gcube.data.analysis.statisticalmanager.stubs.types.schema.SMFile; -import org.gcube.data.analysis.statisticalmanager.stubs.types.schema.SMInputEntry; -import org.gcube.data.analysis.statisticalmanager.stubs.types.schema.SMObject; -import org.gcube.data.analysis.statisticalmanager.stubs.types.schema.SMOperationInfo; -import org.gcube.data.analysis.statisticalmanager.stubs.types.schema.SMResource; -import org.gcube.data.analysis.statisticalmanager.stubs.types.schema.SMTable; -import org.gcube.data.analysis.statisticalmanager.stubs.types.schema.StatisticalServiceType; -import org.gcube.dataanalysis.ecoengine.datatypes.enumtypes.PrimitiveTypes; +import org.gcube.data.analysis.dataminermanagercl.server.DataMinerService; +import org.gcube.data.analysis.dataminermanagercl.server.dmservice.SClient; +import org.gcube.data.analysis.dataminermanagercl.shared.data.OutputData; +import org.gcube.data.analysis.dataminermanagercl.shared.data.computations.ComputationId; +import org.gcube.data.analysis.dataminermanagercl.shared.data.output.FileResource; +import org.gcube.data.analysis.dataminermanagercl.shared.data.output.MapResource; +import org.gcube.data.analysis.dataminermanagercl.shared.data.output.ObjectResource; +import org.gcube.data.analysis.dataminermanagercl.shared.data.output.Resource; +import org.gcube.data.analysis.dataminermanagercl.shared.parameters.ObjectParameter; +import org.gcube.data.analysis.dataminermanagercl.shared.process.ComputationStatus; +import org.gcube.data.analysis.dataminermanagercl.shared.process.Operator; import org.gcube.portlets.user.databasesmanager.client.GWTdbManagerService; -import org.gcube.portlets.user.databasesmanager.client.datamodel.ComputationOutput; import org.gcube.portlets.user.databasesmanager.client.datamodel.FileModel; import org.gcube.portlets.user.databasesmanager.client.datamodel.GeneralOutputFromServlet; 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.SamplingResultWithFileFromServlet; import org.gcube.portlets.user.databasesmanager.client.datamodel.Row; +import org.gcube.portlets.user.databasesmanager.client.datamodel.SamplingResultWithFileFromServlet; import org.gcube.portlets.user.databasesmanager.client.datamodel.SubmitQueryResultWithFileFromServlet; import org.gcube.portlets.user.databasesmanager.server.util.DataExchangedThroughQueue; import org.gcube.portlets.user.databasesmanager.server.util.SessionUtil; -import org.gcube.portlets.user.databasesmanager.shared.ConstantsPortlet; -import org.gcube.portlets.user.databasesmanager.shared.SessionExpiredException; +import org.gcube.portlets.user.databasesmanager.shared.AlgorithmsName; +import org.gcube.portlets.user.databasesmanager.shared.Constants; import org.gcube.portlets.user.databasesmanager.shared.StatisticalManagerException; -import org.gcube.portlets.user.uriresolvermanager.UriResolverManager; +import org.gcube.portlets.user.databasesmanager.shared.computation.ComputationOutput; -import com.extjs.gxt.ui.client.data.BaseModelData; import com.extjs.gxt.ui.client.data.BasePagingLoadResult; import com.extjs.gxt.ui.client.data.PagingLoadConfig; import com.extjs.gxt.ui.client.data.PagingLoadResult; import com.google.gwt.user.server.rpc.RemoteServiceServlet; -import com.thoughtworks.xstream.XStream; - -import org.apache.log4j.Logger; public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements GWTdbManagerService { + private static final long serialVersionUID = -3132008420258703064L; + // logger private static Logger logger = Logger .getLogger(GWTdbManagerServiceImpl.class); @@ -101,10 +82,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements private static boolean threadExecutionFinished = false; private static ConcurrentLinkedQueue queue = new ConcurrentLinkedQueue(); private static ThreadDataLoader dataLoader; - + private static int smComputationNumber; private static int cacheHitsNumber; - + private static int smComputationQuerySamplingNumber; private static int cacheQuerySamplingHitsNumber; private static final String CACHE_MAX_HEAP_SIZE = "CACHE_MAX_HEAP_SIZE"; @@ -115,13 +96,15 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements @Override public void init() throws ServletException { super.init(); - + try { - + // cache folder String cachePath = System.getenv("CATALINA_TMPDIR") + "/DBManager"; logger.info("dbmanager-> Creating cache in folder: " + cachePath); -// CacheManager cacheManager = CacheManager.create(); + // Configuration cacheManagerConfig = new Configuration() + // .diskStore(new DiskStoreConfiguration() + // .path(cachePath)); cacheManager = CacheManager.create(); if (cacheManager == null) { @@ -154,10 +137,13 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } else { cacheManager.addCache(DBCache); logger.info("dbmanager-> cache added to the cacheManager"); - - logger.info("dbmanager-> ** SIZE OF THE MEMORY STORE: "+ DBCache.calculateInMemorySize()); -// logger.trace("dbmanager-> ** SIZE OF THE OFF HEAP"+ DBCache.calculateOffHeapSize()); - logger.info("dbmanager-> ** SIZE OF THE DISK STORE SIZE: "+ DBCache.calculateOnDiskSize()); + + logger.info("dbmanager-> ** SIZE OF THE MEMORY STORE: " + + DBCache.calculateInMemorySize()); + // logger.trace("dbmanager-> ** SIZE OF THE OFF HEAP"+ + // DBCache.calculateOffHeapSize()); + logger.info("dbmanager-> ** SIZE OF THE DISK STORE SIZE: " + + DBCache.calculateOnDiskSize()); } } @@ -177,10 +163,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // create the thread DataLoader dataLoader = new ThreadDataLoader(); logger.info("dbmanager-> Thread Dataloader created"); - + smComputationNumber = 0; cacheHitsNumber = 0; - + smComputationQuerySamplingNumber = 0; cacheQuerySamplingHitsNumber = 0; } catch (Exception e) { @@ -191,7 +177,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } } - public void createCache(String cachePath) throws Exception { + private void createCache(String cachePath) throws Exception { try { CacheConfiguration config = new CacheConfiguration(); @@ -204,18 +190,19 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements config.diskExpiryThreadIntervalSeconds(120); config.maxBytesLocalDisk(2, MemoryUnit.GIGABYTES); long maxHeapSize = readProperty(); -// config.maxBytesLocalHeap(200, MemoryUnit.MEGABYTES); + // config.maxBytesLocalHeap(200, MemoryUnit.MEGABYTES); config.maxBytesLocalHeap(maxHeapSize, MemoryUnit.MEGABYTES); - logger.info("dbmanager-> Max_Bytes_Local_Heap: "+ config.getMaxBytesLocalHeap()); -// config.maxBytesLocalHeap(2, MemoryUnit.GIGABYTES); + logger.info("dbmanager-> Max_Bytes_Local_Heap: " + + config.getMaxBytesLocalHeap()); + // config.maxBytesLocalHeap(2, MemoryUnit.GIGABYTES); config.diskSpoolBufferSizeMB(30); config.overflowToDisk(true); config.diskPersistent(false); - config.diskStorePath(cachePath); -// SizeOfPolicyConfiguration size = new SizeOfPolicyConfiguration(); -// size.setMaxDepth(1000); -// size.maxDepthExceededBehavior(MaxDepthExceededBehavior.ABORT); -// config.sizeOfPolicy(size); + // config.diskStorePath(cachePath); + // SizeOfPolicyConfiguration size = new SizeOfPolicyConfiguration(); + // size.setMaxDepth(1000); + // size.maxDepthExceededBehavior(MaxDepthExceededBehavior.ABORT); + // config.sizeOfPolicy(size); DBCache = new Cache(config); } catch (Exception e) { // logger.error("dbmanager-> Error while starting the servlet. Failed to create the cache", @@ -225,23 +212,24 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements + e); } } - - private long readProperty() throws IOException{ + + private long readProperty() throws IOException { Properties props = new Properties(); -// HttpServletRequest request = this -// .getThreadLocalRequest(); - + // HttpServletRequest request = this + // .getThreadLocalRequest(); + String contextPath = this.getServletContext().getRealPath(""); - logger.info("dbmanager-> path file config.properties"+ contextPath); - String propertyfile = contextPath + File.separator + "conf" + File.separator + "configs.properties"; + logger.info("dbmanager-> path file config.properties" + contextPath); + String propertyfile = contextPath + File.separator + "conf" + + File.separator + "configs.properties"; File propsFile = new File(propertyfile); FileInputStream fis = new FileInputStream(propsFile); - props.load(fis); - String property = props.getProperty(CACHE_MAX_HEAP_SIZE); - - long value = Long.valueOf(property).longValue(); - return value; -} + props.load(fis); + String property = props.getProperty(CACHE_MAX_HEAP_SIZE); + + long value = Long.valueOf(property).longValue(); + return value; + } @Override public void destroy() { @@ -278,9 +266,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } private void initVariables(ASLSession session) { - + // Hashmap that contains computationId with a uid key - HashMap computationIDMap = new HashMap(); + HashMap computationIDMap = new HashMap(); session.setAttribute("ComputationIDList", computationIDMap); // Hashmap that contains the job status with a uid key @@ -300,31 +288,29 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements HashMap listKeySubmitQueryResult = new HashMap(); session.setAttribute("listKeySubmitQueryResult", listKeySubmitQueryResult); - - //map that contains for each UID the submit query result in order - //to face the cache refreshing if a pagination is used + + // map that contains for each UID the submit query result in order + // to face the cache refreshing if a pagination is used HashMap> listSubmitQueryResult = new HashMap>(); - session.setAttribute("listSubmitQueryResult", - listSubmitQueryResult); - - //print data - logger.info("dbmanager-> CheckInformation: cache hits number " + cacheHitsNumber); - logger.info("dbmanager-> CheckInformation: SM computation number " + smComputationNumber); - logger.info("dbmanager-> CheckInformation: cache Query Sampling hits number " + cacheQuerySamplingHitsNumber); - logger.info("dbmanager-> CheckInformation: SM Query Sampling computation number " + smComputationQuerySamplingNumber); + session.setAttribute("listSubmitQueryResult", listSubmitQueryResult); + + // print data + logger.info("dbmanager-> CheckInformation: cache hits number " + + cacheHitsNumber); + logger.info("dbmanager-> CheckInformation: SM computation number " + + smComputationNumber); + logger.info("dbmanager-> CheckInformation: cache Query Sampling hits number " + + cacheQuerySamplingHitsNumber); + logger.info("dbmanager-> CheckInformation: SM Query Sampling computation number " + + smComputationQuerySamplingNumber); } // to get resources from IS @Override public List getResource() throws Exception { - - // session check - if (isSessionExpired()) - throw new SessionExpiredException(); - try { - ASLSession session = SessionUtil.getAslSession(this + ASLSession session = SessionUtil.getASLSession(this .getThreadLocalRequest().getSession()); // get scope String scope = session.getScope(); @@ -334,7 +320,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements if ((value == null) || (value.booleanValue() == false)) { DataExchangedThroughQueue dataqueue = new DataExchangedThroughQueue( scope); - + queue.offer(dataqueue); Thread t = new Thread(dataLoader); t.start(); @@ -356,13 +342,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements public LinkedHashMap getDBInfo(String resourceName) throws Exception { - // session check - if (isSessionExpired()) - throw new SessionExpiredException(); - try { - ASLSession session = SessionUtil.getAslSession(this + ASLSession session = SessionUtil.getASLSession(this .getThreadLocalRequest().getSession()); // get scope String scope = session.getScope(); @@ -378,13 +360,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements public List getDBSchema(LinkedHashMap dataInput) throws Exception { - // session check - if (isSessionExpired()) - throw new SessionExpiredException(); - try { - ASLSession session = SessionUtil.getAslSession(this + ASLSession session = SessionUtil.getASLSession(this .getThreadLocalRequest().getSession()); // get scope String scope = session.getScope(); @@ -401,7 +379,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements try { - ASLSession session = SessionUtil.getAslSession(this + ASLSession session = SessionUtil.getASLSession(this .getThreadLocalRequest().getSession()); // get scope String scope = session.getScope(); @@ -418,10 +396,6 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements LinkedHashMap dataInput, String elementType, boolean SearchTable, String keyword) throws Exception { - // session check - if (isSessionExpired()) - throw new SessionExpiredException(); - try { List result = new ArrayList<>(); @@ -507,14 +481,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements boolean valueReadOnlyQuery, boolean smartCorrectionQuery, String language, String UID) throws Exception { - // session check - if (isSessionExpired()) - throw new SessionExpiredException(); - try { logger.info("Submit Query Request received. Starting to manage the request."); - ASLSession session = SessionUtil.getAslSession(this + ASLSession session = SessionUtil.getASLSession(this .getThreadLocalRequest().getSession()); // get scope String scope = session.getScope(); @@ -533,7 +503,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // converted query String convertedQuery = ""; - String algorithmId = ConstantsPortlet.ALGID_SUBMITQUERY; + String algorithmId = AlgorithmsName.SUBMITQUERY.name(); // print check String rs = dataDB.get("ResourceName"); @@ -615,7 +585,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements result = (SubmitQueryResultWithFileFromServlet) data; cacheHitsNumber++; - logger.info("dbmanager-> CheckDataInCache: data found in cache. cacheHitsNumber: " + cacheHitsNumber); + logger.info("dbmanager-> CheckDataInCache: data found in cache. cacheHitsNumber: " + + cacheHitsNumber); cacheQuerySamplingHitsNumber++; // set variable to true value if cached data are used and a // computation is not started @@ -623,9 +594,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements updateListSubmitQueryUIDCachedData(UID, val); } else { - + smComputationNumber++; - logger.info("dbmanager-> CheckDataInCache: data not found in cache. Starting the Statistical Computation. smComputationNumber: " + smComputationNumber); + logger.info("dbmanager-> CheckDataInCache: data not found in cache. Starting the Statistical Computation. smComputationNumber: " + + smComputationNumber); smComputationQuerySamplingNumber++; // set variable to false value if cached data are not used and a @@ -635,15 +607,15 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // create data structure ComputationOutput outputData = new ComputationOutput(); - - //file name - String FileName = "QueryResult_" + System.currentTimeMillis() + ".csv"; - + + // file name + String FileName = "QueryResult_" + System.currentTimeMillis() + + ".csv"; + // computation id - String computationId = startComputation(algorithmId, + ComputationId computationId = startComputation(algorithmId, inputParameters, outputData, scope, UID, FileName); - - + // get JobID if (checkJob(UID)) { // if the computation has not been removed // the job uid is present @@ -692,23 +664,24 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements "Error in server while loading data."); } - // remove job with the specified uid removeJob(UID); - - String urlFile=outputData.getUrlFile(); - - int submitQueryTotalRows = outputData.getSubmitQueryTotalRows(); + + String urlFile = outputData.getUrlFile(); + + int submitQueryTotalRows = outputData + .getSubmitQueryTotalRows(); result = new SubmitQueryResultWithFileFromServlet( - listAttributes, convertedQuery, urlFile,submitQueryTotalRows); + listAttributes, convertedQuery, urlFile, + submitQueryTotalRows); // put the two data in cache net.sf.ehcache.Element dataToCache = new net.sf.ehcache.Element( keyData, result); - + insertDataIntoCache(dataToCache); - + // remove the header in order to parse only the result output.remove(0); @@ -737,8 +710,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } if (!(e instanceof StatisticalManagerException)) { // GWT can't serialize all exceptions - throw new Exception( - "Error in server while loading data."); + throw new Exception("Error in server while loading data."); } throw e; } finally { @@ -757,13 +729,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements LinkedHashMap dataInput, String elementType) throws Exception { - // session check - if (isSessionExpired()) - throw new SessionExpiredException(); - try { logger.info("dbmanager-> Sampling on table Request received. Starting to manage the request."); - ASLSession session = SessionUtil.getAslSession(this + ASLSession session = SessionUtil.getASLSession(this .getThreadLocalRequest().getSession()); // get scope String scope = session.getScope(); @@ -774,7 +742,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements List output = new ArrayList(); SamplingResultWithFileFromServlet result; - String algorithmId = ConstantsPortlet.ALGID_SAMPLEONTABLE; + String algorithmId = AlgorithmsName.SAMPLEONTABLE.name(); // print check String rs = dataInput.get("ResourceName"); @@ -788,8 +756,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements logger.info("dbmanager-> SchemaName: " + scm); logger.info("dbmanager-> TableName: " + tab); - if ((elementType != null) - && (elementType.equals(ConstantsPortlet.SCHEMA))) { + if ((elementType != null) && (elementType.equals(Constants.SCHEMA))) { if ((rs == null) || (rs.equals(""))) { throw new Exception("Unable to load data"); } @@ -804,7 +771,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } } if ((elementType != null) - && (elementType.equals(ConstantsPortlet.DATABASE))) { + && (elementType.equals(Constants.DATABASE))) { if ((rs == null) || (rs.equals(""))) { throw new Exception("Unable to load data"); } @@ -850,21 +817,24 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements if (value != null) { result = (SamplingResultWithFileFromServlet) value; cacheHitsNumber++; - logger.info("dbmanager-> CheckDataInCache: data found in cache. cacheHitsNumber: " + cacheHitsNumber); + logger.info("dbmanager-> CheckDataInCache: data found in cache. cacheHitsNumber: " + + cacheHitsNumber); cacheQuerySamplingHitsNumber++; } else { smComputationNumber++; - logger.info("dbmanager-> CheckDataInCache: data not found in cache. Starting the Statistical Computation. smComputationNumber: " + smComputationNumber); + logger.info("dbmanager-> CheckDataInCache: data not found in cache. Starting the Statistical Computation. smComputationNumber: " + + smComputationNumber); smComputationQuerySamplingNumber++; // start computation // create data structure ComputationOutput outputData = new ComputationOutput(); - //file name - String FileName = "Sampling_"+ System.currentTimeMillis() + ".csv"; + // file name + String FileName = "Sampling_" + System.currentTimeMillis() + + ".csv"; // computation id - String computationId = startComputation(algorithmId, + ComputationId computationId = startComputation(algorithmId, inputParameters, outputData, scope, FileName); // print check on retrieving data @@ -881,11 +851,11 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements 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); + + output.add(row); } - - String urlFile=outputData.getUrlFile(); + + String urlFile = outputData.getUrlFile(); result = new SamplingResultWithFileFromServlet(output, urlFile); // put data in cache @@ -911,13 +881,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements LinkedHashMap dataInput, String elementType) throws Exception { - // session check - if (isSessionExpired()) - throw new SessionExpiredException(); - try { logger.info("dbmanager-> Smart Sampling on table Request received. Starting to manage the request."); - ASLSession session = SessionUtil.getAslSession(this + ASLSession session = SessionUtil.getASLSession(this .getThreadLocalRequest().getSession()); // get scope String scope = session.getScope(); @@ -928,7 +894,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements List output = new ArrayList(); SamplingResultWithFileFromServlet result; - String algorithmId = ConstantsPortlet.ALGID_SMARTSAMPLEONTABLE; + String algorithmId = AlgorithmsName.SMARTSAMPLEONTABLE.name(); // print check String rs = dataInput.get("ResourceName"); @@ -942,8 +908,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements logger.info("dbmanager-> SchemaName: " + scm); logger.info("dbmanager-> TableName: " + tab); - if ((elementType != null) - && (elementType.equals(ConstantsPortlet.SCHEMA))) { + if ((elementType != null) && (elementType.equals(Constants.SCHEMA))) { if ((rs == null) || (rs.equals(""))) { throw new Exception("Unable to load data"); } @@ -958,7 +923,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } } if ((elementType != null) - && (elementType.equals(ConstantsPortlet.DATABASE))) { + && (elementType.equals(Constants.DATABASE))) { if ((rs == null) || (rs.equals(""))) { throw new Exception("Unable to load data"); } @@ -1003,19 +968,22 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements if (value != null) { result = (SamplingResultWithFileFromServlet) value; cacheHitsNumber++; - logger.info("dbmanager-> CheckDataInCache: data found in cache. cacheHitsNumber: " + cacheHitsNumber); + logger.info("dbmanager-> CheckDataInCache: data found in cache. cacheHitsNumber: " + + cacheHitsNumber); cacheQuerySamplingHitsNumber++; } else { smComputationNumber++; - logger.info("dbmanager-> CheckDataInCache: data not found in cache. Starting the Statistical Computation. smComputationNumber: " + smComputationNumber); + logger.info("dbmanager-> CheckDataInCache: data not found in cache. Starting the Statistical Computation. smComputationNumber: " + + smComputationNumber); smComputationQuerySamplingNumber++; // create data structure ComputationOutput outputData = new ComputationOutput(); - - //file name - String FileName = "SmartSampling_"+ System.currentTimeMillis() + ".csv"; + + // file name + String FileName = "SmartSampling_" + System.currentTimeMillis() + + ".csv"; // computation id - String computationId = startComputation(algorithmId, + ComputationId computationId = startComputation(algorithmId, inputParameters, outputData, scope, FileName); // print check on retrieving data @@ -1035,7 +1003,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements output.add(row); } - String urlFile=outputData.getUrlFile(); + String urlFile = outputData.getUrlFile(); result = new SamplingResultWithFileFromServlet(output, urlFile); // put data in cache @@ -1062,13 +1030,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements LinkedHashMap dataInput, String elementType) throws Exception { - // session check - if (isSessionExpired()) - throw new SessionExpiredException(); - try { logger.info("dbmanager-> Random Sampling on table Request received. Starting to manage the request."); - ASLSession session = SessionUtil.getAslSession(this + ASLSession session = SessionUtil.getASLSession(this .getThreadLocalRequest().getSession()); // get scope String scope = session.getScope(); @@ -1078,7 +1042,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // output sample result List output = new ArrayList(); - String algorithmId = ConstantsPortlet.ALGID_RANDOMSAMPLEONTABLE; + String algorithmId = AlgorithmsName.RANDOMSAMPLEONTABLE.name(); // print check String rs = dataInput.get("ResourceName"); @@ -1092,8 +1056,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements logger.info("dbmanager-> SchemaName: " + scm); logger.info("dbmanager-> TableName: " + tab); - if ((elementType != null) - && (elementType.equals(ConstantsPortlet.SCHEMA))) { + if ((elementType != null) && (elementType.equals(Constants.SCHEMA))) { if ((rs == null) || (rs.equals(""))) { throw new Exception("Unable to load data"); } @@ -1108,7 +1071,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } } if ((elementType != null) - && (elementType.equals(ConstantsPortlet.DATABASE))) { + && (elementType.equals(Constants.DATABASE))) { if ((rs == null) || (rs.equals(""))) { throw new Exception("Unable to load data"); } @@ -1137,10 +1100,11 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // create data structure ComputationOutput outputData = new ComputationOutput(); - //file name - String FileName = "RandomSampling_"+ System.currentTimeMillis() + ".csv"; + // file name + String FileName = "RandomSampling_" + System.currentTimeMillis() + + ".csv"; // computation id - String computationId = startComputation(algorithmId, + ComputationId computationId = startComputation(algorithmId, inputParameters, outputData, scope, FileName); // print check on retrieving data @@ -1160,8 +1124,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements output.add(row); } - String urlFile=outputData.getUrlFile(); - SamplingResultWithFileFromServlet obj = new SamplingResultWithFileFromServlet(output, urlFile); + String urlFile = outputData.getUrlFile(); + SamplingResultWithFileFromServlet obj = new SamplingResultWithFileFromServlet( + output, urlFile); return obj; } catch (Exception e) { @@ -1179,13 +1144,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements public LinkedHashMap getTableDetails( LinkedHashMap dataInput) throws Exception { - // session check - if (isSessionExpired()) - throw new SessionExpiredException(); - try { logger.info("dbmanager-> Table Details Recovery Request received. Starting to manage the request."); - ASLSession session = SessionUtil.getAslSession(this + ASLSession session = SessionUtil.getASLSession(this .getThreadLocalRequest().getSession()); // get scope String scope = session.getScope(); @@ -1195,7 +1156,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // data ouptut LinkedHashMap outputParameters = new LinkedHashMap(); - String algorithmId = ConstantsPortlet.ALGID_GETTABLEDETAILS; + String algorithmId = AlgorithmsName.GETTABLEDETAILS.name(); // print check String rs = dataInput.get("ResourceName"); @@ -1227,7 +1188,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // create data structure ComputationOutput outputData = new ComputationOutput(); // computation id - String computationId = startComputation(algorithmId, + ComputationId computationId = startComputation(algorithmId, inputParameters, outputData, scope, null); // print check on retrieving data @@ -1263,13 +1224,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } // parse result for Submit query + @Override public PagingLoadResult loadSubmitResult(PagingLoadConfig config, List listAttributes, String UID) throws Exception { - // session check - if (isSessionExpired()) - throw new SessionExpiredException(); - try { // Create a sublist and add data to list according @@ -1296,18 +1254,18 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements if (value != null) { result = (List) value; logger.trace("dbmanager-> Data recovered from cache"); - updateListSubmitQueryResult(UID, result); + updateListSubmitQueryResult(UID, result); } else { - - //get the result bound to session + + // get the result bound to session result = getSubmitQueryResult(UID); logger.trace("dbmanager-> Data recovered from ASL session"); - + } - + data = parseCVSString(result, listAttributes); - if(data!=null){ + if (data != null) { int start = config.getOffset(); int limit = data.size(); @@ -1323,7 +1281,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // System.out.println("start: " + start); // System.out.println("limit: " + limit); // System.out.println("sublist size: " + sublist.size()); - }else{ + } else { logger.error("dbmanager-> Error in server while loading data. object data null"); throw new Exception("Error in server while loading data."); } @@ -1339,7 +1297,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements throw new Exception( "Error in server while loading data. Exception: " + e); } - + } // get attributes list for display the result in a table @@ -1378,80 +1336,77 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements public List parseCVSString(List result, List attrNames) throws Exception { - // session check - if (isSessionExpired()) - throw new SessionExpiredException(); - List rows = null; - try{ - if (result != null) { - rows = new ArrayList(); - for (int i = 0; i < result.size(); i++) { - List attrValues = parse(result.get(i).getValue()); - Row element = new Row(attrNames, attrValues, i); - rows.add(element); + try { + if (result != null) { + rows = new ArrayList(); + for (int i = 0; i < result.size(); i++) { + List attrValues = parse(result.get(i).getValue()); + Row element = new Row(attrNames, attrValues, i); + rows.add(element); + } } + + return rows; + } catch (Exception e) { + logger.error("dbmanager-> ", e); + throw new Exception(e); } - - return rows; - } catch (Exception e) { - logger.error("dbmanager-> ", e); - throw new Exception(e); - } } private List parse(String row) throws Exception { String delimiter = ","; List elements = new ArrayList(); - - try{ - String phrase = row; -// logger.info("row: " + phrase); - int idxdelim = -1; - boolean quot = false; - phrase = phrase.trim(); - - while ((idxdelim = phrase.indexOf(delimiter)) >= 0) { -// logger.info("delimiter: " + idxdelim); - quot = phrase.startsWith("\""); - if (quot) { - phrase = phrase.substring(1); - String quoted = ""; - if (phrase.startsWith("\"")) + + try { + String phrase = row; + // logger.info("row: " + phrase); + int idxdelim = -1; + boolean quot = false; + phrase = phrase.trim(); + + while ((idxdelim = phrase.indexOf(delimiter)) >= 0) { + // logger.info("delimiter: " + idxdelim); + quot = phrase.startsWith("\""); + if (quot) { phrase = phrase.substring(1); - else { - RE regexp = new RE("[^\\\\]\""); - boolean matching = regexp.match(phrase); + String quoted = ""; + if (phrase.startsWith("\"")) + phrase = phrase.substring(1); + else { + RE regexp = new RE("[^\\\\]\""); + boolean matching = regexp.match(phrase); - if (matching) { - int i0 = regexp.getParenStart(0); - quoted = phrase.substring(0, i0 + 1).trim(); - phrase = phrase.substring(i0 + 2).trim(); - } - } - if (phrase.startsWith(delimiter)) - phrase = phrase.substring(1); - - elements.add(quoted); - - } else { - elements.add(phrase.substring(0, idxdelim)); - phrase = phrase.substring(idxdelim + 1).trim(); - } -// logger.info("token: " + phrase); - } - if (phrase.startsWith("\"")){ - phrase = phrase.substring(1); + if (matching) { + int i0 = regexp.getParenStart(0); + quoted = phrase.substring(0, i0 + 1).trim(); + phrase = phrase.substring(i0 + 2).trim(); } + } + if (phrase.startsWith(delimiter)) + phrase = phrase.substring(1); - if (phrase.endsWith("\"")){ - phrase = phrase.substring(0, phrase.length() - 1);} - - elements.add(phrase); -// logger.info("server token: " + phrase); -// logger.info("size: " + elements.size()); - }catch (Exception e) { + elements.add(quoted); + + } else { + elements.add(phrase.substring(0, idxdelim)); + phrase = phrase.substring(idxdelim + 1).trim(); + } + // logger.info("token: " + phrase); + } + if (phrase.startsWith("\"")) { + phrase = phrase.substring(1); + } + + if (phrase.endsWith("\"")) { + phrase = phrase.substring(0, phrase.length() - 1); + } + + elements.add(phrase); + // logger.info("server token: " + phrase); + // logger.info("size: " + elements.size()); + } catch (Exception e) { logger.error("dbmanager-> ", e); throw e; } @@ -1459,10 +1414,11 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } // update job with the related status - private synchronized void updateJobStatus(String jobID, String status) { + private synchronized void updateJobStatus(String jobID, String status) + throws Exception { if (jobID != null) { // add the job status - ASLSession session = SessionUtil.getAslSession(this + ASLSession session = SessionUtil.getASLSession(this .getThreadLocalRequest().getSession()); HashMap JobStatusMap = (HashMap) session .getAttribute("JobStatusList"); @@ -1472,8 +1428,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } // remove job with the related status - private synchronized void removeJobStatus(String jobID) { - ASLSession session = SessionUtil.getAslSession(this + private synchronized void removeJobStatus(String jobID) throws Exception { + ASLSession session = SessionUtil.getASLSession(this .getThreadLocalRequest().getSession()); HashMap JobStatusMap = (HashMap) session .getAttribute("JobStatusList"); @@ -1485,8 +1441,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } // get job status - private synchronized String getJobStatus(String jobID) { - ASLSession session = SessionUtil.getAslSession(this + private synchronized String getJobStatus(String jobID) throws Exception { + ASLSession session = SessionUtil.getASLSession(this .getThreadLocalRequest().getSession()); HashMap JobStatusMap = (HashMap) session .getAttribute("JobStatusList"); @@ -1495,12 +1451,13 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } // update job with the computation id - private synchronized void updateJob(String jobID, String computationId) { + private synchronized void updateJob(String jobID, + ComputationId computationId) throws Exception { if (jobID != null) { // add the computation in the map - ASLSession session = SessionUtil.getAslSession(this + ASLSession session = SessionUtil.getASLSession(this .getThreadLocalRequest().getSession()); - HashMap computationIDMap = (HashMap) session + HashMap computationIDMap = (HashMap) session .getAttribute("ComputationIDList"); computationIDMap.put(jobID, computationId); session.setAttribute("ComputationIDList", computationIDMap); @@ -1508,15 +1465,15 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } // remove job with the computation id - private synchronized String removeJob(String jobID) { + private synchronized ComputationId removeJob(String jobID) throws Exception { if (jobID != null) { // System.out.println("remove jobID " + job); // add the computation in the map - ASLSession session = SessionUtil.getAslSession(this + ASLSession session = SessionUtil.getASLSession(this .getThreadLocalRequest().getSession()); - HashMap computationIDMap = (HashMap) session + HashMap computationIDMap = (HashMap) session .getAttribute("ComputationIDList"); - String computationId = computationIDMap.get(jobID); + ComputationId computationId = computationIDMap.get(jobID); if (computationId != null) { computationIDMap.remove(jobID); session.setAttribute("ComputationIDList", computationIDMap); @@ -1526,12 +1483,12 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements return null; } - private synchronized boolean checkJob(String jobID) { + private synchronized boolean checkJob(String jobID) throws Exception { boolean isContained = false; if (jobID != null) { - ASLSession session = SessionUtil.getAslSession(this + ASLSession session = SessionUtil.getASLSession(this .getThreadLocalRequest().getSession()); - HashMap computationIDMap = (HashMap) session + HashMap computationIDMap = (HashMap) session .getAttribute("ComputationIDList"); if (computationIDMap.containsKey(jobID)) { isContained = true; @@ -1544,8 +1501,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } private synchronized void updateListSubmitQueryUIDCachedData(String UID, - Boolean value) { - ASLSession session = SessionUtil.getAslSession(this + Boolean value) throws Exception { + ASLSession session = SessionUtil.getASLSession(this .getThreadLocalRequest().getSession()); HashMap listSubmitQueryUIDCachedData = (HashMap) session @@ -1556,8 +1513,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } - private synchronized Boolean checkSubmitQueryUIDCachedData(String UID) { - ASLSession session = SessionUtil.getAslSession(this + private synchronized Boolean checkSubmitQueryUIDCachedData(String UID) + throws Exception { + ASLSession session = SessionUtil.getASLSession(this .getThreadLocalRequest().getSession()); HashMap listSubmitQueryUIDCachedData = (HashMap) session @@ -1565,8 +1523,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements return listSubmitQueryUIDCachedData.get(UID); } - private synchronized void removeSubmitQueryUIDCachedData(String UID) { - ASLSession session = SessionUtil.getAslSession(this + private synchronized void removeSubmitQueryUIDCachedData(String UID) + throws Exception { + ASLSession session = SessionUtil.getASLSession(this .getThreadLocalRequest().getSession()); HashMap listSubmitQueryUIDCachedData = (HashMap) session @@ -1579,8 +1538,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } } - private synchronized void removeKeySubmitQueryResult(String UID) { - ASLSession session = SessionUtil.getAslSession(this + private synchronized void removeKeySubmitQueryResult(String UID) + throws Exception { + ASLSession session = SessionUtil.getASLSession(this .getThreadLocalRequest().getSession()); HashMap listKeySubmitQueryResult = (HashMap) session @@ -1594,8 +1554,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } private synchronized void updateListKeySubmitQueryResult(String UID, - String value) { - ASLSession session = SessionUtil.getAslSession(this + String value) throws Exception { + ASLSession session = SessionUtil.getASLSession(this .getThreadLocalRequest().getSession()); HashMap listKeySubmitQueryResult = (HashMap) session @@ -1606,36 +1566,41 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } - private synchronized String getKeySubmitQueryResult(String UID) { - ASLSession session = SessionUtil.getAslSession(this + private synchronized String getKeySubmitQueryResult(String UID) + throws Exception { + ASLSession session = SessionUtil.getASLSession(this .getThreadLocalRequest().getSession()); HashMap listKeySubmitQueryResult = (HashMap) session .getAttribute("listKeySubmitQueryResult"); return listKeySubmitQueryResult.get(UID); } - - private synchronized List getSubmitQueryResult(String UID){ - ASLSession session = SessionUtil.getAslSession(this + + private synchronized List getSubmitQueryResult(String UID) + throws Exception { + ASLSession session = SessionUtil.getASLSession(this .getThreadLocalRequest().getSession()); - - HashMap> listSubmitQueryResult = (HashMap>)session.getAttribute("listSubmitQueryResult"); - return listSubmitQueryResult.get(UID); + + HashMap> listSubmitQueryResult = (HashMap>) session + .getAttribute("listSubmitQueryResult"); + return listSubmitQueryResult.get(UID); } - - private synchronized void updateListSubmitQueryResult(String UID, List value){ - ASLSession session = SessionUtil.getAslSession(this + + private synchronized void updateListSubmitQueryResult(String UID, + List value) throws Exception { + ASLSession session = SessionUtil.getASLSession(this .getThreadLocalRequest().getSession()); - - HashMap> listSubmitQueryResult = (HashMap>)session.getAttribute("listSubmitQueryResult"); + + HashMap> listSubmitQueryResult = (HashMap>) session + .getAttribute("listSubmitQueryResult"); listSubmitQueryResult.put(UID, value); - session.setAttribute("listSubmitQueryResult", - listSubmitQueryResult); - } - - private synchronized void removeSubmitQueryResult(String UID){ - - ASLSession session = SessionUtil.getAslSession(this + session.setAttribute("listSubmitQueryResult", listSubmitQueryResult); + } + + private synchronized void removeSubmitQueryResult(String UID) + throws Exception { + + ASLSession session = SessionUtil.getASLSession(this .getThreadLocalRequest().getSession()); HashMap> listSubmitQueryResult = (HashMap>) session @@ -1643,54 +1608,49 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements if (listSubmitQueryResult.containsKey(UID)) { listSubmitQueryResult.remove(UID); - session.setAttribute("listSubmitQueryResult", - listSubmitQueryResult); + session.setAttribute("listSubmitQueryResult", listSubmitQueryResult); } } - private String startComputation(String algorithmName, + private ComputationId startComputation(String algorithmName, List parameters, ComputationOutput outputData, String scope, String FileName) throws Exception { return startComputation(algorithmName, parameters, outputData, scope, null, FileName); } - private String startComputation(String algorithmName, + private ComputationId startComputation(String algorithmName, List parameters, ComputationOutput outputData, String scopeValue, String jobID, String FileName) throws Exception { - - SMComputationConfig config = new SMComputationConfig(); - SMInputEntry[] list = new SMInputEntry[parameters.size()]; - int i = 0; - - for (Parameter p : parameters) - list[i++] = new SMInputEntry(p.getName(), p.getValue()); - config.parameters(new SMEntries(list)); - config.algorithm(algorithmName); - - // create a computation request - SMComputationRequest request = new SMComputationRequest(); - request.user(getUsername()); - request.config(config); - try { + DataMinerService dataMinerService = new DataMinerService(); + SClient sClient = dataMinerService.getClient(); + Operator operator = sClient.getOperatorById(AlgorithmsName.valueOf( + algorithmName).getFullPackageName()); - StatisticalManagerFactory factory = getFactory(scopeValue); - String computationId = factory.executeComputation(request); + List pars = new ArrayList<>(); + for (Parameter p : parameters) { + ObjectParameter par = new ObjectParameter(); + par.setName(p.getName()); + par.setValue(p.getValue()); + pars.add(par); - float percentage = 0; - String scope = scopeValue; - String username = getUsername(); + } + logger.debug("Parameters: "+pars); + operator.setOperatorParameters(pars); + ComputationId computationId = sClient.startComputation(operator); + + //float percentage = 0; + //String scope = scopeValue; + // String username = getUsername(); updateJobStatus(jobID, "computation started"); updateJob(jobID, computationId); + logger.info("dbmanager-> startComputation: the computation has started!"); - while (percentage < 100) { - percentage = checkComputationStatus(scope, computationId, - username, outputData, FileName); - Thread.sleep(3000); - } + monitoringComputation(computationId, sClient, outputData, jobID); logger.info("dbmanager-> startComputation: the computation has finished!"); + updateJobStatus(jobID, "computation finished"); // removeJob(jobID); @@ -1703,169 +1663,102 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } } - private float checkComputationStatus(String scope, String computationId, - String user, ComputationOutput outputData, String FileName) throws Exception { - // System.out.println("checkComputation " + computationId); - ScopeProvider.instance.set(scope); + private void monitoringComputation(final ComputationId computationId, + final SClient sClient, final ComputationOutput outputData, + final String jobID) throws Exception { + boolean notEnd = true; + while (notEnd) { + ComputationStatus computationStatus = sClient + .getComputationStatus(computationId); + switch (computationStatus.getStatus()) { + case ACCEPTED: + logger.debug("Operation Accepted"); + break; + case CANCELLED: + notEnd = false; + logger.debug("Operation Cancelled"); + logger.info("dbmanager-> startComputation: the computation has finished!"); + updateJobStatus(jobID, "computation finished"); + break; + case COMPLETE: + notEnd = false; + logger.debug("Operation Completed"); + retrieveOutput(computationId, sClient, outputData); + logger.info("dbmanager-> startComputation: the computation has finished!"); + updateJobStatus(jobID, "computation finished"); + break; + case FAILED: + notEnd = false; + logger.error("Operation Failed"); + logger.error(computationStatus.getMessage(), + computationStatus.getError()); + updateJobStatus(jobID, "computation finished"); + StatisticalManagerException e = new StatisticalManagerException( + computationStatus.getMessage()); + logger.error( + "dbmanager-> Exception generated from the Statistical Manager: ", + e); + throw e; - 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("computation COMPLETED"); - // 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, scope, FileName); - - // 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; - } - - private void displayOutput(SMResource smResource, SMResourceType smResType, - ComputationOutput outputData, String scope, String FileName) throws Exception { - - if (smResType.equals(SMResourceType.OBJECT)) { - - SMObject objRes = (SMObject) smResource; - if (objRes.name().contentEquals(PrimitiveTypes.MAP.toString())) { - logger.info("dbmanager-> Output is a map"); - getMap(objRes, outputData, scope, FileName); - - } else if (objRes.name().contentEquals( - PrimitiveTypes.IMAGES.toString())) { - // logger.info("Output are images"); + case RUNNING: + logger.debug("Operation Running: " + + computationStatus.getPercentage()); + break; + default: + break; } - - } - - // StatisticalManager EXCEPTION MANAGEMENT - if (smResType.equals(SMResourceType.ERROR)) { - StatisticalManagerException e = new StatisticalManagerException( - smResource.description()); - // e.printStackTrace(); - logger.error("dbmanager-> Exception generated from the Statistical Manager: ", e); - throw e; + Thread.sleep(2000); } } - // get output result - private void getMap(SMObject objRes, ComputationOutput outputData, String scope, String FileName) - throws Exception { - // output data values - LinkedHashMap mapValues = new LinkedHashMap(); - // output data keys - LinkedHashMap mapKeys = new LinkedHashMap(); + private void retrieveOutput(ComputationId computationId, SClient sClient, + ComputationOutput outputData) { + try { + // output data values + LinkedHashMap mapValues = new LinkedHashMap(); + // output data keys + LinkedHashMap mapKeys = new LinkedHashMap(); -// logger.info("**getStorageInputStream - started"); - InputStream is = getStorageClientInputStream(objRes.url()); - // object serializer - XStream xstream = new XStream(); - xstream.alias( - "org.gcube_system.namespaces.data.analysis.statisticalmanager.types.SMObject", - SMObject.class); - xstream.alias( - "org.gcube_system.namespaces.data.analysis.statisticalmanager.types.SMFile", - SMFile.class); - xstream.alias( - "org.gcube_system.namespaces.data.analysis.statisticalmanager.types.SMResource", - SMResource.class); - xstream.alias( - "org.gcube_system.namespaces.data.analysis.statisticalmanager.types.SMTable", - SMTable.class); - // logger.info("streaming"); + OutputData output = sClient + .getOutputDataByComputationId(computationId); + logger.debug("Output: " + output); + Resource resource = output.getResource(); + if (resource.isMap()) { + MapResource mapResource = (MapResource) resource; + int i = 0; + for (String key : mapResource.getMap().keySet()) { + Resource value = mapResource.getMap().get(key); + logger.debug("Entry: " + key + " = " + value); + if (mapResource.getMap().get(key).isFile()) { + FileResource fileResource = (FileResource) value; - @SuppressWarnings("unchecked") - Map smMap = (Map) (xstream - .fromXML(is)); - is.close(); -// logger.info("**getStorageInputStream - finished"); -// logger.info("**build the resultMap - started"); - - int i = 0; - for (String key : smMap.keySet()) { - - if (key.equals("File")){ - logger.info("dbmanager-> " + "the map contains file"); - SMResource smres = smMap.get("File"); - int resourceTypeIndex = smres.resourceType(); - SMResourceType smsubResType = SMResourceType.values()[resourceTypeIndex]; - -// logger.info("dbmanager-> Output is a file"); - SMFile fileRes = (SMFile) smres; -// logger.info("dbmanager-> **FILE URL " + fileRes.url()); - - //uriResolver to generate an url http - ScopeProvider.instance.set(scope); - UriResolverManager resolver = new UriResolverManager("SMP"); - Map params = new HashMap(); - params.put("smp-uri", fileRes.url()); - params.put("fileName", FileName); - params.put("contentType", "text/plain"); - - String shortLink = resolver.getLink(params, true); - if ((shortLink!=null)&&(!shortLink.equals(""))){ - outputData.setUrlFile(shortLink); - logger.info("dbmanager-> Http link of the generated File: " + shortLink); - }else{ - logger.error("dbmanager-> Error in server while generating the file. Http link null"); - throw new Exception("Error in server while generating the file."); + outputData.setUrlFile(fileResource.getUrl()); + logger.info("dbmanager-> Http link of the generated File: " + + fileResource.getUrl()); + } else { + if (key.compareToIgnoreCase("Total Rows") == 0) { + ObjectResource objectResource = (ObjectResource) value; + outputData.setSubmitQueryTotalRows(Integer + .parseInt(objectResource.getValue())); + } else { + ObjectResource objectResource = (ObjectResource) value; + mapKeys.put(String.valueOf(i), key); + mapValues.put(String.valueOf(i), + objectResource.getValue()); + i++; + } } - - } else if(key.equals("Total Rows")){ - //to recover the total number for the resutl of a submit query operation - SMResource smres = smMap.get(key); - SMObject obje = (SMObject) smres; - String outstring = obje.url(); - outputData.setSubmitQueryTotalRows(Integer.parseInt(outstring)); - }else{ - // add key value - mapKeys.put(String.valueOf(i), key); - SMResource smres = smMap.get(key); - int resourceTypeIndex = smres.resourceType(); - SMResourceType smsubResType = SMResourceType.values()[resourceTypeIndex]; - // logger.info("ResourceType: " + smsubResType); + } + } - 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); - i++; - } - } + outputData.setMapValues(mapValues); + outputData.setmapKeys(mapKeys); + + } catch (Exception e) { + logger.error(e.getLocalizedMessage()); + e.printStackTrace(); } - outputData.setMapValues(mapValues); - outputData.setmapKeys(mapKeys); -// logger.info("**build the resultMap - finished"); + } private InputStream getStorageClientInputStream(String url) @@ -1879,35 +1772,31 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements return u.openConnection().getInputStream(); } - private StatisticalManagerFactory getFactory(String scope) { - // HttpSession httpSession = this.getThreadLocalRequest().getSession(); - return SessionUtil.getFactory(scope); - } + /* + * private StatisticalManagerFactory getFactory(String scope) { // + * HttpSession httpSession = this.getThreadLocalRequest().getSession(); + * return SessionUtil.getFactory(scope); } + */ - private String getUsername() { - // set the username of the user session to value "database.manager" - // HttpSession httpSession = this.getThreadLocalRequest().getSession(); - // return SessionUtil.getUsername(httpSession); - return "database.manager"; - } - - private String getScope() { - HttpSession httpSession = this.getThreadLocalRequest().getSession(); - return SessionUtil.getScope(httpSession); - } + /* + * private String getUsername() { // set the username of the user session to + * value "database.manager" // HttpSession httpSession = + * this.getThreadLocalRequest().getSession(); // return + * SessionUtil.getUsername(httpSession); return "database.manager"; } + * + * private String getScope() { HttpSession httpSession = + * this.getThreadLocalRequest().getSession(); return + * SessionUtil.getScope(httpSession); } + */ // remove the computation + @Override public Boolean removeComputation(String uidSubmitQuery) throws Exception { // System.out.println("server UID: " + uidSubmitQuery); - - // session check - if (isSessionExpired()) - throw new SessionExpiredException(); - try { - + logger.info("dbmanager-> Remove Computation Request received. Starting to manage the request."); - ASLSession session = SessionUtil.getAslSession(this + ASLSession session = SessionUtil.getASLSession(this .getThreadLocalRequest().getSession()); // get scope String scope = session.getScope(); @@ -1921,7 +1810,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // + " data are cached? " + value.booleanValue()); if (!value.booleanValue()) { // remove computation - String computationId = null; + ComputationId computationId = null; if ((uidSubmitQuery != null) && (!(uidSubmitQuery.equals("")))) { @@ -1941,16 +1830,18 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } if (computationId != null) { - StatisticalManagerFactory factory = getFactory(scope); try { - factory.removeComputation(computationId); - logger.info("dbmanager-> Computation with UID: "+ uidSubmitQuery + " removed"); + DataMinerService dataMinerService = new DataMinerService(); + SClient sClient = dataMinerService.getClient(); + sClient.cancelComputation(computationId); + logger.info("dbmanager-> Computation with UID: " + + uidSubmitQuery + " removed"); // remove submit query result refreshDataOnServer(uidSubmitQuery); // System.out.println("computation removed"); isComputationRemoved = true; } catch (Exception e) { -// e.printStackTrace(); + // e.printStackTrace(); logger.info("dbmanager-> Could not remove the computation ID " + computationId + " corresponding to jobID " @@ -1981,11 +1872,11 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // } } + @Override public void refreshDataOnServer(String submitQueryUID) throws Exception { - // session check - if (isSessionExpired()) - throw new SessionExpiredException(); + ASLSession session = SessionUtil.getASLSession(this + .getThreadLocalRequest().getSession()); if ((submitQueryUID != null) && (!submitQueryUID.equals(""))) { removeKeySubmitQueryResult(submitQueryUID); @@ -1997,246 +1888,270 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } } - private synchronized void insertDataIntoCache(net.sf.ehcache.Element data) throws Exception{ - - if(cacheManager.cacheExists("DBCache")){ - logger.info("dbmanager-> disk store path for cache: " + cacheManager.getDiskStorePath() +" Cache Status: "+DBCache.getStatus().toString()); - if (DBCache.getStatus().toString().equals(Status.STATUS_ALIVE.toString())){ + private synchronized void insertDataIntoCache(net.sf.ehcache.Element data) + throws Exception { + + if (cacheManager.cacheExists("DBCache")) { + logger.info("dbmanager-> disk store path for cache: " + " none " + + " Cache Status: " + DBCache.getStatus().toString()); + if (DBCache.getStatus().toString() + .equals(Status.STATUS_ALIVE.toString())) { DBCache.put(data); - if(DBCache.isKeyInCache(data.getKey().toString())){ - logger.trace("dbmanager-> element with key: " + data.getKey().toString()+" added in cache"); + if (DBCache.isKeyInCache(data.getKey().toString())) { + logger.trace("dbmanager-> element with key: " + + data.getKey().toString() + " added in cache"); } - - logger.info("dbmanager-> ** SIZE OF THE MEMORY STORE: "+ DBCache.calculateInMemorySize()); -// logger.trace("dbmanager-> ** SIZE OF THE OFF HEAP"+ DBCache.calculateOffHeapSize()); - logger.info("dbmanager-> ** SIZE OF THE DISK STORE SIZE: "+ DBCache.calculateOnDiskSize()); + + logger.info("dbmanager-> ** SIZE OF THE MEMORY STORE: " + + DBCache.calculateInMemorySize()); + // logger.trace("dbmanager-> ** SIZE OF THE OFF HEAP"+ + // DBCache.calculateOffHeapSize()); + logger.info("dbmanager-> ** SIZE OF THE DISK STORE SIZE: " + + DBCache.calculateOnDiskSize()); + } } - } } - private synchronized net.sf.ehcache.Element getDataFromCache(String key) throws Exception{ + private synchronized net.sf.ehcache.Element getDataFromCache(String key) + throws Exception { net.sf.ehcache.Element data = null; - boolean safe=true; - if(cacheManager.cacheExists("DBCache")){ - logger.info("dbmanager-> disk store path for cache: " + cacheManager.getDiskStorePath() +". Cache Status: "+DBCache.getStatus().toString()); - if (DBCache.getStatus().toString().equals(Status.STATUS_ALIVE.toString())){ + boolean safe = true; + if (cacheManager.cacheExists("DBCache")) { + logger.info("dbmanager-> disk store path for cache: " + " none " + + ". Cache Status: " + DBCache.getStatus().toString()); + if (DBCache.getStatus().toString() + .equals(Status.STATUS_ALIVE.toString())) { data = DBCache.get(key); - if (data!=null){ - logger.trace("dbmanager-> element with key: " + key +" is in cache"); - safe=isSafe(data.getObjectValue()); + if (data != null) { + logger.trace("dbmanager-> element with key: " + key + + " is in cache"); + safe = isSafe(data.getObjectValue()); logger.info("dbmanager-> Safe procedure Status: " + safe); } } } - - - if(safe){ + + if (safe) { return data; - } else{ + } else { return null; - } + } } - - //method that checks if data retrieved from cache are not corrupted.This fixes an ehcache bug if a big object is moved in the heap. - private boolean isSafe(Object obj) throws Exception{ - boolean safe=true; + + // method that checks if data retrieved from cache are not corrupted.This + // fixes an ehcache bug if a big object is moved in the heap. + private boolean isSafe(Object obj) throws Exception { + boolean safe = true; logger.info("dbmanager-> Starting the safe procedure on data..."); - if(obj instanceof SubmitQueryResultWithFileFromServlet){ + if (obj instanceof SubmitQueryResultWithFileFromServlet) { logger.info("dbmanager-> object is a SubmitQueryResultWithFileFromServlet"); SubmitQueryResultWithFileFromServlet elem = new SubmitQueryResultWithFileFromServlet(); - elem = (SubmitQueryResultWithFileFromServlet)obj; - - try{ - if ((elem.getProperties()!=null)&&(elem.getProperties().size()==0)){ - safe=false; + elem = (SubmitQueryResultWithFileFromServlet) obj; + + try { + if ((elem.getProperties() != null) + && (elem.getProperties().size() == 0)) { + safe = false; logger.trace("dbmanager-> data not safe"); -// System.out.println("status variable safe: " + safe); - } - }catch (NullPointerException e) { + // System.out.println("status variable safe: " + safe); + } + } catch (NullPointerException e) { logger.error("dbmanager-> ", e); - safe=false; + safe = false; logger.trace("dbmanager-> data not safe"); } -// if ((elem.getProperties()!=null)&&(elem.getProperties().size()==0)){ -// safe=false; -// logger.trace("data not safe"); -//// System.out.println("status variable safe: " + safe); -// } -// else{ - if(safe==true){ - //check attributes + // if + // ((elem.getProperties()!=null)&&(elem.getProperties().size()==0)){ + // safe=false; + // logger.trace("data not safe"); + // // System.out.println("status variable safe: " + safe); + // } + // else{ + if (safe == true) { + // check attributes List attributes = new ArrayList(); attributes = elem.getListOutput(); - if(attributes.size()!=0){ - - checkAttributes: for(int i=0;i attributes data not safe"); - //System.out.println("status variable safe: " + safe); + // System.out.println("status variable safe: " + + // safe); break checkAttributes; } } - + } - - //check converted query - if(elem.getConvertedQuery()==null){ - safe=false; + + // check converted query + if (elem.getConvertedQuery() == null) { + safe = false; logger.trace("dbmanager-> converted query not safe"); - //System.out.println("status variable safe: " + safe); - }else if(elem.getUrlFile()==null){ - //check url file - safe=false; + // System.out.println("status variable safe: " + safe); + } else if (elem.getUrlFile() == null) { + // check url file + safe = false; logger.trace("dbmanager-> file url not safe"); - //System.out.println("status variable safe: " + safe); + // System.out.println("status variable safe: " + safe); } } -// } - }else if(obj instanceof SamplingResultWithFileFromServlet){ + // } + } else if (obj instanceof SamplingResultWithFileFromServlet) { logger.info("dbmanager-> object is a SamplingResultWithFileFromServlet"); SamplingResultWithFileFromServlet elem = new SamplingResultWithFileFromServlet(); - elem = (SamplingResultWithFileFromServlet)obj; - - try{ - if((elem.getProperties()!=null)&&(elem.getProperties().size()==0)){ - safe=false; + elem = (SamplingResultWithFileFromServlet) obj; + + try { + if ((elem.getProperties() != null) + && (elem.getProperties().size() == 0)) { + safe = false; logger.trace("dbmanager-> data not safe"); - //System.out.println("status variable safe: " + safe); + // System.out.println("status variable safe: " + safe); } - }catch (NullPointerException e) { + } catch (NullPointerException e) { logger.error("dbmanager-> ", e); - safe=false; + safe = false; logger.trace("dbmanager-> data not safe"); } -// else{ - - if (safe==true){ - //check output + // else{ + + if (safe == true) { + // check output List output = new ArrayList(); output = elem.getListOutput(); - if(output.size()!=0){ - checkOutput: for(int i=0;i output not safe"); + // System.out.println("status variable safe: " + + // safe); + break checkOutput; + } + } catch (NullPointerException e) { + logger.error("dbmanager-> ", e); + safe = false; logger.trace("dbmanager-> output not safe"); - //System.out.println("status variable safe: " + safe); + // System.out.println("status variable safe: " + + // safe); break checkOutput; } - }catch (NullPointerException e) { - logger.error("dbmanager-> ", e); - safe=false; - logger.trace("dbmanager-> output not safe"); - //System.out.println("status variable safe: " + safe); - break checkOutput; + } - - } - + } - - //check file name - if(elem.getUrlFile()==null){ - safe=false; - logger.trace("dbmanager-> file name not safe"); - //System.out.println("status variable safe: " + safe); - } - } -// } - - }else if(obj instanceof ArrayList){ - try{ - - List list = new ArrayList(); - list = (ArrayList)obj; - //System.out.println("size: " + list.size()); - checkResult: for (int i = 0; i < list.size(); i++) { - try{ - if ((list.get(i).getProperties()!=null)&&(list.get(i).getProperties().size()==0)){ - safe = false; - logger.trace("dbmanager-> data not safe"); - //System.out.println("status variable safe: " + safe); - break checkResult; - }; - }catch (NullPointerException e1) { - logger.error("dbmanager-> ", e1); + + // check file name + if (elem.getUrlFile() == null) { safe = false; - logger.trace("dbmanager-> data not safe"); - //System.out.println("status variable safe: " + safe); - break checkResult; + logger.trace("dbmanager-> file name not safe"); + // System.out.println("status variable safe: " + safe); } - } - logger.info("dbmanager-> object is a list"); - }catch (java.lang.ClassCastException e) { - List list = new ArrayList(); - list = (ArrayList)obj; - //System.out.println("size: " + list.size()); - checkFileModel: for (int i = 0; i < list.size(); i++) { - try{ - if ((list.get(i).getProperties()!=null)&&(list.get(i).getProperties().size()==0)){ - safe = false; - logger.trace("dbmanager-> data not safe"); - //System.out.println("status variable safe: " + safe); - break checkFileModel; - }; - }catch (NullPointerException excp) { - logger.error("dbmanager-> ", excp); + // } + + } else if (obj instanceof ArrayList) { + try { + + List list = new ArrayList(); + list = (ArrayList) obj; + // System.out.println("size: " + list.size()); + checkResult: for (int i = 0; i < list.size(); i++) { + try { + if ((list.get(i).getProperties() != null) + && (list.get(i).getProperties().size() == 0)) { safe = false; logger.trace("dbmanager-> data not safe"); - //System.out.println("status variable safe: " + safe); + // System.out.println("status variable safe: " + + // safe); + break checkResult; + } + ; + } catch (NullPointerException e1) { + logger.error("dbmanager-> ", e1); + safe = false; + logger.trace("dbmanager-> data not safe"); + // System.out.println("status variable safe: " + safe); + break checkResult; + } + + } + logger.info("dbmanager-> object is a list"); + } catch (java.lang.ClassCastException e) { + List list = new ArrayList(); + list = (ArrayList) obj; + // System.out.println("size: " + list.size()); + checkFileModel: for (int i = 0; i < list.size(); i++) { + try { + if ((list.get(i).getProperties() != null) + && (list.get(i).getProperties().size() == 0)) { + safe = false; + logger.trace("dbmanager-> data not safe"); + // System.out.println("status variable safe: " + + // safe); break checkFileModel; } - + ; + } catch (NullPointerException excp) { + logger.error("dbmanager-> ", excp); + safe = false; + logger.trace("dbmanager-> data not safe"); + // System.out.println("status variable safe: " + safe); + break checkFileModel; } - logger.info("dbmanager-> object is a list"); + + } + logger.info("dbmanager-> object is a list"); } - - }else if(obj instanceof LinkedHashMap){ + + } else if (obj instanceof LinkedHashMap) { logger.info("dbmanager-> object is a LinkedHashMap"); LinkedHashMap map = new LinkedHashMap(); - map = (LinkedHashMap)obj; - //System.out.println("size: " + map.size()); + map = (LinkedHashMap) obj; + // System.out.println("size: " + map.size()); Set keys = map.keySet(); Object[] array = keys.toArray(); - - checkHashMap: for (int i=0;i data not safe"); + // System.out.println("status variable safe: " + safe); + break checkHashMap; + } + } catch (NullPointerException e) { + logger.error("dbmanager-> ", e); safe = false; logger.trace("dbmanager-> data not safe"); - //System.out.println("status variable safe: " + safe); + // System.out.println("status variable safe: " + safe); break checkHashMap; } - }catch (NullPointerException e) { - logger.error("dbmanager-> ", e); - safe = false; - logger.trace("dbmanager-> data not safe"); - //System.out.println("status variable safe: " + safe); - break checkHashMap; - } } } logger.info("dbmanager-> Safe procedure finished."); - return safe; + return safe; } // clear the cache on the user request + @Override public GeneralOutputFromServlet refreshDataTree(String ElementType, LinkedHashMap inputData, FileModel element) throws Exception { - - logger.info("dbmanager-> Refresh data request received from element "+ElementType+". Starting to manage the request."); - - // session check - if (isSessionExpired()) - throw new SessionExpiredException(); + + logger.info("dbmanager-> Refresh data request received from element " + + ElementType + ". Starting to manage the request."); try { - ASLSession session = SessionUtil.getAslSession(this + ASLSession session = SessionUtil.getASLSession(this .getThreadLocalRequest().getSession()); // get scope String scope = session.getScope(); @@ -2256,59 +2171,59 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements String keyUsedForSamplingsRefresh = ""; String keyUsedForSmartSamplingRefresh = ""; String keyUsedForRandomSamplingRefresh = ""; - boolean requestToAddInQueue=false; + boolean requestToAddInQueue = false; if (!ElementType.equals("")) { // build key switch (ElementType) { - case ConstantsPortlet.RESOURCESLIST: - key = scope + inputData.get(ConstantsPortlet.RESOURCESLIST); + case Constants.RESOURCESLIST: + key = scope + inputData.get(Constants.RESOURCESLIST); dataQueue = new DataExchangedThroughQueue(scope); requestToAddInQueue = true; break; - case ConstantsPortlet.RESOURCE: + case Constants.RESOURCE: key = scope + inputData.get("ResourceName"); dataQueue = new DataExchangedThroughQueue(scope, - ConstantsPortlet.RESOURCE, inputData.get("ResourceName"), - null, null, null); + Constants.RESOURCE, + inputData.get("ResourceName"), null, null, null); requestToAddInQueue = true; break; - case ConstantsPortlet.DATABASE: - if (element.getDatabaseType().equals( - ConstantsPortlet.POSTGRES)) { // refresh schema + case Constants.DATABASE: + if (element.getDatabaseType() + .equals(Constants.POSTGRES)) { // refresh schema // list key = inputData.get("ResourceName") + inputData.get("DatabaseName"); // refresh submitted queries keyUsedForQueryRefresh = scope - + ConstantsPortlet.ALGID_SUBMITQUERY + key; + + AlgorithmsName.SUBMITQUERY.name() + key; refreshSubmittedQueryInCache(keyUsedForQueryRefresh); - + dataQueue = new DataExchangedThroughQueue(scope, - ConstantsPortlet.DATABASE, inputData.get("ResourceName"), + Constants.DATABASE, + inputData.get("ResourceName"), inputData.get("DatabaseName"), null, element.getDatabaseType()); requestToAddInQueue = true; key = scope + key; } - if (element.getDatabaseType().equals( - ConstantsPortlet.MYSQL)) { // refresh table - // list + if (element.getDatabaseType().equals(Constants.MYSQL)) { // refresh + // table + // list key = inputData.get("ResourceName") + inputData.get("DatabaseName") + inputData.get("SchemaName"); keyUsedForQueryRefresh = scope - + ConstantsPortlet.ALGID_SUBMITQUERY + key; + + AlgorithmsName.SUBMITQUERY.name() + key; refreshSubmittedQueryInCache(keyUsedForQueryRefresh); keyUsedForSamplingsRefresh = scope - + ConstantsPortlet.ALGID_SAMPLEONTABLE - + key; + + AlgorithmsName.SAMPLEONTABLE.name() + key; keyUsedForSmartSamplingRefresh = scope - + ConstantsPortlet.ALGID_SMARTSAMPLEONTABLE + + AlgorithmsName.SMARTSAMPLEONTABLE.name() + key; key = scope + key; @@ -2320,7 +2235,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } break; - case ConstantsPortlet.SCHEMA: + case Constants.SCHEMA: key = inputData.get("ResourceName") + inputData.get("DatabaseName") @@ -2328,14 +2243,14 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // refresh submitted query and samplings and tables list keyUsedForQueryRefresh = scope - + ConstantsPortlet.ALGID_SUBMITQUERY + + AlgorithmsName.SUBMITQUERY.name() + inputData.get("ResourceName") + inputData.get("DatabaseName"); refreshSubmittedQueryInCache(keyUsedForQueryRefresh); keyUsedForSamplingsRefresh = scope - + ConstantsPortlet.ALGID_SAMPLEONTABLE + key; + + AlgorithmsName.SAMPLEONTABLE.name() + key; keyUsedForSmartSamplingRefresh = scope - + ConstantsPortlet.ALGID_SMARTSAMPLEONTABLE + + AlgorithmsName.SMARTSAMPLEONTABLE.name() + key; key = scope + key; @@ -2348,13 +2263,15 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } } -// logger.trace("dbmanager-> Check if data of the node is present in cache with key: : " + key); + // logger.trace("dbmanager-> Check if data of the node is present in cache with key: : " + // + key); net.sf.ehcache.Element dataFromCache = getDataFromCache(key); if (dataFromCache != null) { -// logger.trace("dbmanager-> Data of the node is in cache"); + // logger.trace("dbmanager-> Data of the node is in cache"); - logger.info("dbmanager-> Starting the data removing process in cache from the node with key: " + key); + logger.info("dbmanager-> Starting the data removing process in cache from the node with key: " + + key); // refresh data in cache. Remove data related to the subtree // with the selected element as root @@ -2363,44 +2280,45 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // recover the refresh data of the item selected if (!ElementType.equals("")) { switch (ElementType) { - case ConstantsPortlet.RESOURCESLIST: + case Constants.RESOURCESLIST: List output1 = getResource(); result = new GeneralOutputFromServlet(output1); // System.out.println("server-> output generated"); break; - case ConstantsPortlet.RESOURCE: + case Constants.RESOURCE: resourceName = inputData.get("ResourceName"); LinkedHashMap output2 = getDBInfo(resourceName); result = new GeneralOutputFromServlet(output2); break; - case ConstantsPortlet.DATABASE: + case Constants.DATABASE: if (element.getDatabaseType() != null && (element.getDatabaseType() - .equals(ConstantsPortlet.POSTGRES))) { // refresh + .equals(Constants.POSTGRES))) { // refresh // schema list List output3 = getDBSchema(inputData); result = new GeneralOutputFromServlet(output3); } if (element.getDatabaseType() != null && element.getDatabaseType().equals( - ConstantsPortlet.MYSQL)) { // refresh + Constants.MYSQL)) { // refresh // table list - getTables(inputData, ConstantsPortlet.DATABASE); + getTables(inputData, Constants.DATABASE); } break; - case ConstantsPortlet.SCHEMA: - getTables(inputData, ConstantsPortlet.SCHEMA); + case Constants.SCHEMA: + getTables(inputData, Constants.SCHEMA); break; } } // check if the thread execution is terminated. If yes, a // new thread is started otherwise no because the thread in - // running state will also serve this request received in the queue. + // running state will also serve this request received in + // the queue. // The thread will run in backgroung to load the data // related to the subtree with the item selected as root. - if(requestToAddInQueue==true){ + if (requestToAddInQueue == true) { if (isThreadExecutionFinished()) { logger.info("dbmanager-> Starting the launch of the Thread DataLoader execution"); queue.offer(dataQueue); @@ -2411,11 +2329,11 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements queue.offer(dataQueue); } } - + } -// else{ -// logger.trace("dbmanager-> Data of the node is not in cache"); -// } + // else{ + // logger.trace("dbmanager-> Data of the node is not in cache"); + // } } return result; @@ -2430,7 +2348,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } } - public void refreshDataInCache(FileModel element, String ElementType, + private void refreshDataInCache(FileModel element, String ElementType, String scope, String key, String DBType) { logger.info("dbmanager-> Refresh Data Request of element " + ElementType + " in Cache with KEY: " + key); @@ -2441,33 +2359,34 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements Object value = null; if (dataFromCache != null) { -// logger.info("dbmanager-> Data is in cache"); + // logger.info("dbmanager-> Data is in cache"); value = dataFromCache.getObjectValue(); if (value != null) { if (!ElementType.equals("")) { switch (ElementType) { - case ConstantsPortlet.RESOURCESLIST: + case Constants.RESOURCESLIST: // refresh resources List resources = (List) value; // refresh cache refreshCache(key); -// logger.trace("dbmanager-> element: " + ElementType -// + " with key: " + key + " removed in cache"); + // logger.trace("dbmanager-> element: " + + // ElementType + // + " with key: " + key + " removed in cache"); // apply the refresh on children for (int i = 0; i < resources.size(); i++) { key = scope + resources.get(i).getName(); - refreshDataInCache(element, ConstantsPortlet.RESOURCE, null, - key, null); + refreshDataInCache(element, Constants.RESOURCE, + null, key, null); } break; - case ConstantsPortlet.RESOURCE: + case Constants.RESOURCE: // refresh databases LinkedHashMap DBdata = (LinkedHashMap) value; // refresh cache refreshCache(key); -// logger.trace("dbmanager-> element " + ElementType -// + " with key: " + key + " removed in cache"); + // logger.trace("dbmanager-> element " + ElementType + // + " with key: " + key + " removed in cache"); // apply the refresh on children HashMap DBlist = new HashMap(); @@ -2497,17 +2416,16 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements .getName(); if (driver.toUpperCase().contains( - ConstantsPortlet.POSTGRES)) { + Constants.POSTGRES)) { - DBlist.put( - DBName, - ConstantsPortlet.POSTGRES); + DBlist.put(DBName, + Constants.POSTGRES); } if (driver.toUpperCase().contains( - ConstantsPortlet.MYSQL)) { + Constants.MYSQL)) { DBlist.put(DBName, - ConstantsPortlet.MYSQL); + Constants.MYSQL); } } } @@ -2521,15 +2439,15 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements String databaseType = DBlist.get(array[i] .toString()); // if (databaseType - // .equals(ConstantsPortlet.POSTGRES)) { + // .equals(Constants.POSTGRES)) { String newkey = key + array[i].toString(); - refreshDataInCache(element, ConstantsPortlet.DATABASE, null, - newkey, databaseType); + refreshDataInCache(element, Constants.DATABASE, + null, newkey, databaseType); // } } break; - case ConstantsPortlet.DATABASE: + case Constants.DATABASE: if (DBType == null) { DBType = element.getDatabaseType(); } @@ -2537,64 +2455,71 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements List schemaList = (List) value; refreshCache(key); // refresh schema -// logger.trace("dbmanager-> element " + ElementType -// + " with key: " + key + " removed in cache"); - if (DBType.equals(ConstantsPortlet.POSTGRES)) { + // logger.trace("dbmanager-> element " + ElementType + // + " with key: " + key + " removed in cache"); + if (DBType.equals(Constants.POSTGRES)) { // SCHEMA for (int i = 0; i < schemaList.size(); i++) { String newkey = key + schemaList.get(i).getName(); - refreshDataInCache(element, ConstantsPortlet.SCHEMA, null, - newkey, null); + refreshDataInCache(element, + Constants.SCHEMA, null, newkey, + null); } } - if (DBType.equals(ConstantsPortlet.MYSQL)) { + if (DBType.equals(Constants.MYSQL)) { // refresh tables key = key + ""; refreshCache(key); // refresh tables -// logger.trace("dbmanager-> element " + ElementType -// + " with key: " + key -// + " removed in cache"); + // logger.trace("dbmanager-> element " + + // ElementType + // + " with key: " + key + // + " removed in cache"); } break; - case ConstantsPortlet.SCHEMA: + case Constants.SCHEMA: // refresh tables (db postgres) refreshCache(key); -// logger.trace("dbmanager-> element " + ElementType -// + " with key: " + key + " removed in cache"); + // logger.trace("dbmanager-> element " + ElementType + // + " with key: " + key + " removed in cache"); break; } } } - } -// else { -// logger.info("dbmanager-> Data not in cache"); -// } + } + // else { + // logger.info("dbmanager-> Data not in cache"); + // } } catch (Exception e) { logger.error("dbmanager-> ", e); } } private synchronized void refreshCache(String key) throws Exception { - if(cacheManager.cacheExists("DBCache")){ - logger.info("dbmanager-> disk store path for cache: " + cacheManager.getDiskStorePath() +"Cache Status: "+DBCache.getStatus().toString()); - if (DBCache.getStatus().toString().equals(Status.STATUS_ALIVE.toString())){ + if (cacheManager.cacheExists("DBCache")) { + logger.info("dbmanager-> disk store path for cache: " + "none" + + "Cache Status: " + DBCache.getStatus().toString()); + if (DBCache.getStatus().toString() + .equals(Status.STATUS_ALIVE.toString())) { DBCache.remove(key); - logger.trace("dbmanager-> element with key: " + key + " removed in cache"); + logger.trace("dbmanager-> element with key: " + key + + " removed in cache"); } } } private synchronized void refreshSubmittedQueryInCache(String key) throws Exception { - - if(cacheManager.cacheExists("DBCache")){ - logger.info("dbmanager-> disk store path for cache: " + cacheManager.getDiskStorePath() +"Cache Status: "+DBCache.getStatus().toString()); - if (DBCache.getStatus().toString().equals(Status.STATUS_ALIVE.toString())){ -// logger.info("dbmanager-> Cache Status:"+ "STATUS_ALIVE"); - + + if (cacheManager.cacheExists("DBCache")) { + logger.info("dbmanager-> disk store path for cache: " + " none " + + "Cache Status: " + DBCache.getStatus().toString()); + if (DBCache.getStatus().toString() + .equals(Status.STATUS_ALIVE.toString())) { + // logger.info("dbmanager-> Cache Status:"+ "STATUS_ALIVE"); + List keysInCache = DBCache.getKeys(); int listSize = keysInCache.size(); List keysToBeRemoved = new ArrayList<>(); @@ -2619,17 +2544,20 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements String keyUsedForSamplingsRefresh, String keyUsedForSmartSamplingRefresh) throws Exception { - if(cacheManager.cacheExists("DBCache")){ - logger.info("dbmanager-> disk store path for cache: " + cacheManager.getDiskStorePath() +"Cache Status: "+DBCache.getStatus().toString()); - if (DBCache.getStatus().toString().equals(Status.STATUS_ALIVE.toString())){ - + if (cacheManager.cacheExists("DBCache")) { + logger.info("dbmanager-> disk store path for cache: " + " none " + + "Cache Status: " + DBCache.getStatus().toString()); + if (DBCache.getStatus().toString() + .equals(Status.STATUS_ALIVE.toString())) { + List keysInCache = DBCache.getKeys(); int listSize = keysInCache.size(); List keysToBeRemoved = new ArrayList<>(); // recover keys list that match the key for (int i = 0; i < listSize; i++) { - if ((keysInCache.get(i).startsWith(keyUsedForSamplingsRefresh)) + if ((keysInCache.get(i) + .startsWith(keyUsedForSamplingsRefresh)) || (keysInCache.get(i) .startsWith(keyUsedForSmartSamplingRefresh))) { keysToBeRemoved.add(keysInCache.get(i)); @@ -2641,8 +2569,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements + keyUsedForSamplingsRefresh + " " + keyUsedForSmartSamplingRefresh); - } - } + } + } } private String storeResultIntoCSVFile(List result, String n) @@ -2691,12 +2619,6 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements return fileName; } - // to check if the session is expired - private boolean isSessionExpired() throws Exception { - return SessionUtil.isSessionExpired(this.getThreadLocalRequest() - .getSession()); - } - // to delete more space occurences in order to have only one space between // two words in a query private String parseQuery(String query) { @@ -2728,14 +2650,14 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements private List recoverResources(String scope) throws Exception { try { - logger.info("dbmanager-> Resources Recovery Request received. Starting to manage the request."); + logger.info("dbmanager-> Resources Recovery Request received. Starting to manage the request."); // data input List inputParameters = new ArrayList(); // data output List outputParameters = new ArrayList(); // get algorithmId - String algorithmId = ConstantsPortlet.ALGID_GETRESOURCE; + String algorithmId = AlgorithmsName.LISTDBNAMES.name(); Parameter maxNumber = new Parameter("MaxNumber", "", "String", "-1"); inputParameters.add(maxNumber); @@ -2747,9 +2669,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // get data from cache // check if data exist considering as key the input parameters // String key = inputParameters.get(0).getDefaultValue(); - String key = scope + ConstantsPortlet.RESOURCESLIST; + String key = scope + Constants.RESOURCESLIST; net.sf.ehcache.Element dataFromCache = getDataFromCache(key); - + Object value = null; if (dataFromCache != null) { value = dataFromCache.getObjectValue(); @@ -2758,19 +2680,21 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements if (value != null) { // System.out.println("***GETTING DATA FROM CACHE"); outputParameters = (List) value; - + cacheHitsNumber++; - logger.info("dbmanager-> CheckDataInCache: data found in cache. cacheHitsNumber: " + cacheHitsNumber); + logger.info("dbmanager-> CheckDataInCache: data found in cache. cacheHitsNumber: " + + cacheHitsNumber); } else { smComputationNumber++; - logger.info("dbmanager-> CheckDataInCache: data not found in cache. Starting the Statistical Computation. smComputationNumber: " + smComputationNumber); - + logger.info("dbmanager-> CheckDataInCache: data not found in cache. Starting the Statistical Computation. smComputationNumber: " + + smComputationNumber); + // start the computation // System.out.println("***STARTING THE COMPUTATION"); // create data structure for data output ComputationOutput outputData = new ComputationOutput(); // computationId - String computationId = startComputation(algorithmId, + ComputationId computationId = startComputation(algorithmId, inputParameters, outputData, scope, null); // print check @@ -2794,7 +2718,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements key, outputParameters); insertDataIntoCache(dataToCache); -// logger.trace("dbmanager-> element added in cache with key: " + key); + // logger.trace("dbmanager-> element added in cache with key: " + // + key); } } return outputParameters; @@ -2815,47 +2740,54 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements String resourceName) throws Exception { try { logger.info("dbmanager-> Databases Recovery Request received. Starting to manage the request."); - // data input - List inputParameters = new ArrayList(); - // data output - LinkedHashMap outputParameters = new LinkedHashMap(); - String algorithmId = ConstantsPortlet.ALGID_GETDBINFO; + String algorithmId = AlgorithmsName.LISTDBINFO.name(); // print check logger.info("dbmanager-> ResourceName: " + resourceName); - if ((resourceName == null) || (resourceName.equals(""))) { - throw new Exception("Unable to load data"); + if (resourceName == null || resourceName.isEmpty()) { + throw new Exception( + "Unable to load data resource name invalid: " + + resourceName); } - Parameter resource = new Parameter("ResourceName", "", "String", ""); - inputParameters.add(resource); - inputParameters.get(0).setValue(resourceName); - // get data from cache // check if data exist considering as key the input parameters - String key = scope + inputParameters.get(0).getValue(); + String key = scope + resourceName; net.sf.ehcache.Element dataFromCache = getDataFromCache(key); - + Object value = null; if (dataFromCache != null) { value = dataFromCache.getObjectValue(); } + + // data output + LinkedHashMap outputParameters = new LinkedHashMap<>(); + if (value != null) { outputParameters = (LinkedHashMap) value; cacheHitsNumber++; - logger.info("dbmanager-> CheckDataInCache: data found in cache. cacheHitsNumber: " + cacheHitsNumber); + logger.info("dbmanager-> CheckDataInCache: data found in cache. cacheHitsNumber: " + + cacheHitsNumber); // System.out.println("***GETTING DATA FROM CACHE"); } else { smComputationNumber++; - logger.info("dbmanager-> CheckDataInCache: data not found in cache. Starting the Statistical Computation. smComputationNumber: " + smComputationNumber); + logger.info("dbmanager-> CheckDataInCache: data not found in cache. Starting the Statistical Computation. smComputationNumber: " + + smComputationNumber); // start the computation // System.out.println("***STARTING THE COMPUTATION"); // create data structure + Parameter resource = new Parameter("ResourceName", "", + "String", ""); + resource.setValue(resourceName); + List inputParameters = new ArrayList(); + inputParameters.add(resource); + logger.debug("InputParameters: "+inputParameters); + ComputationOutput outputData = new ComputationOutput(); // computation id - String computationId = startComputation(algorithmId, + ComputationId computationId = startComputation(algorithmId, inputParameters, outputData, scope, null); // print check @@ -2879,33 +2811,34 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // logger.info("value: " + // mapValues.get(String.valueOf(i))); // logger.info("key: " + -// System.out.println(mapKeys.get(String.valueOf(i))); + // System.out.println(mapKeys.get(String.valueOf(i))); outputParameters.put(mapKeys.get(String.valueOf(i)), obj); } // write data in cache - if (outputParameters != null && outputParameters.size() != 0) { + if (outputParameters.size() > 0) { // put data in cache net.sf.ehcache.Element dataToCache = new net.sf.ehcache.Element( key, outputParameters); insertDataIntoCache(dataToCache); -// logger.trace("dbmanager-> element added in cache with key: " + key); + // logger.trace("dbmanager-> element added in cache with key: " + // + key); } } - //TODO **TO REMOVE -// if (outputParameters!=null){ -//// logger.info("dbmanager-> ***print output "); -// Set keys = outputParameters.keySet(); -// Object[] array = keys.toArray(); -// -// for (int i=0;i *** " + outputParameters -// .get(array[i].toString()) -// .getName()); -// } -// -// } + // TODO **TO REMOVE + // if (outputParameters!=null){ + // // logger.info("dbmanager-> ***print output "); + // Set keys = outputParameters.keySet(); + // Object[] array = keys.toArray(); + // + // for (int i=0;i *** " + outputParameters + // .get(array[i].toString()) + // .getName()); + // } + // + // } return outputParameters; } catch (Exception e) { // e.printStackTrace(); @@ -2931,7 +2864,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // data output List outputParameters = new ArrayList(); - String algorithmId = ConstantsPortlet.ALGID_GETDBSCHEMA; + String algorithmId = AlgorithmsName.LISTDBSCHEMA.name(); // print check String rs = dataInput.get("ResourceName"); String db = dataInput.get("DatabaseName"); @@ -2965,7 +2898,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements String key = scope + inputParameters.get(0).getValue() + inputParameters.get(1).getValue(); net.sf.ehcache.Element dataFromCache = getDataFromCache(key); - + Object value = null; if (dataFromCache != null) { value = dataFromCache.getObjectValue(); @@ -2973,16 +2906,18 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements if (value != null) { outputParameters = (List) value; cacheHitsNumber++; - logger.info("dbmanager-> CheckDataInCache: data found in cache. cacheHitsNumber: " + cacheHitsNumber); + logger.info("dbmanager-> CheckDataInCache: data found in cache. cacheHitsNumber: " + + cacheHitsNumber); } else { smComputationNumber++; - logger.info("dbmanager-> CheckDataInCache: data not found in cache. Starting the Statistical Computation. smComputationNumber: " + smComputationNumber); + logger.info("dbmanager-> CheckDataInCache: data not found in cache. Starting the Statistical Computation. smComputationNumber: " + + smComputationNumber); // start the computation // create data structure ComputationOutput outputData = new ComputationOutput(); // computation id - String computationId = startComputation(algorithmId, + ComputationId computationId = startComputation(algorithmId, inputParameters, outputData, scope, null); // print check @@ -3013,7 +2948,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements key, outputParameters); insertDataIntoCache(dataToCache); -// logger.trace("dbmanager-> element added in cache with key: " + key); + // logger.trace("dbmanager-> element added in cache with key: " + // + key); // DBCache.put(dataToCache); } } @@ -3042,7 +2978,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // data output List outputParameters = new ArrayList(); - String algorithmId = ConstantsPortlet.ALGID_GETTABLES; + String algorithmId = AlgorithmsName.LISTTABLES.name(); String rs = dataInput.get("ResourceName"); String db = dataInput.get("DatabaseName"); @@ -3053,8 +2989,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements logger.info("dbmanager-> DatabaseName: " + db); logger.info("dbmanager-> SchemaName: " + scm); - if ((elementType != null) - && (elementType.equals(ConstantsPortlet.SCHEMA))) { + if ((elementType != null) && (elementType.equals(Constants.SCHEMA))) { if ((rs == null) || (rs.equals(""))) { throw new Exception("Unable to load data"); } @@ -3066,7 +3001,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } } if ((elementType != null) - && (elementType.equals(ConstantsPortlet.DATABASE))) { + && (elementType.equals(Constants.DATABASE))) { if ((rs == null) || (rs.equals(""))) { throw new Exception("Unable to load data"); } @@ -3093,7 +3028,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements + inputParameters.get(1).getValue() + inputParameters.get(2).getValue(); net.sf.ehcache.Element dataFromCache = getDataFromCache(key); - + Object value = null; if (dataFromCache != null) { value = dataFromCache.getObjectValue(); @@ -3102,17 +3037,19 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements if (value != null) { outputParameters = (List) value; cacheHitsNumber++; - logger.info("dbmanager-> CheckDataInCache: data found in cache. cacheHitsNumber: " + cacheHitsNumber); + logger.info("dbmanager-> CheckDataInCache: data found in cache. cacheHitsNumber: " + + cacheHitsNumber); } else { smComputationNumber++; - logger.info("dbmanager-> CheckDataInCache: data not found in cache. Starting the Statistical Computation. smComputationNumber: " + smComputationNumber); + logger.info("dbmanager-> CheckDataInCache: data not found in cache. Starting the Statistical Computation. smComputationNumber: " + + smComputationNumber); // start computation // create data structure ComputationOutput outputData = new ComputationOutput(); // computation id - String computationId = startComputation(algorithmId, + ComputationId computationId = startComputation(algorithmId, inputParameters, outputData, scope, null); // print check on retrieving data @@ -3139,7 +3076,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements key, outputParameters); insertDataIntoCache(dataToCache); -// logger.trace("dbmanager-> element added in cache with key: " + key); + // logger.trace("dbmanager-> element added in cache with key: " + // + key); } } @@ -3204,28 +3142,26 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements logger.info("dbmanager-> Starting the node refreshing process"); switch (elementType) { - case ConstantsPortlet.RESOURCE: + case Constants.RESOURCE: getDatabase(scope, resource); break; - case ConstantsPortlet.DATABASE: + case Constants.DATABASE: String DBType = node.DBType(); String database = node.database(); - if (DBType - .equals(ConstantsPortlet.POSTGRES)) { + if (DBType.equals(Constants.POSTGRES)) { getSchema(scope, resource, database); } - if (DBType.equals(ConstantsPortlet.MYSQL)) { + if (DBType.equals(Constants.MYSQL)) { String schema = node.schema(); getTables(scope, resource, database, - schema, - ConstantsPortlet.DATABASE); + schema, Constants.DATABASE); } break; - case ConstantsPortlet.SCHEMA: + case Constants.SCHEMA: String db = node.database(); String schema = node.schema(); getTables(scope, resource, db, schema, - ConstantsPortlet.SCHEMA); + Constants.SCHEMA); break; } } @@ -3251,7 +3187,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } } catch (Throwable e) { logger.error("dbmanager-> ", e); - }finally{ + } finally { // thread terminates its execution setThreadExecutionFinished(true); logger.info("dbmanager-> Thread DataLoader execution terminated"); @@ -3288,17 +3224,17 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements .getName(); if (driver.toUpperCase().contains( - ConstantsPortlet.POSTGRES)) { + Constants.POSTGRES)) { // get schema List schemaList = getSchema( scope, resourceName, DBName); } if (driver.toUpperCase().contains( - ConstantsPortlet.MYSQL)) { + Constants.MYSQL)) { // get tables getTables(scope, resourceName, DBName, "", - ConstantsPortlet.DATABASE); + Constants.DATABASE); } } j++; @@ -3330,7 +3266,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // schemaList.size(); i++) { String schemaName = schemaList.get(z).getName(); getTables(scope, resourceName, databaseName, - schemaName, ConstantsPortlet.SCHEMA); + schemaName, Constants.SCHEMA); z++; } } @@ -3349,8 +3285,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements dataInputForTables.put("ResourceName", resourceName); dataInputForTables.put("DatabaseName", databaseName); dataInputForTables.put("SchemaName", schemaName); - recoverTables(scope, dataInputForTables, - ConstantsPortlet.DATABASE); + recoverTables(scope, dataInputForTables, Constants.DATABASE); } catch (Exception e) { logger.error("dbmanager-> ", e); } diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/server/util/SessionUtil.java b/src/main/java/org/gcube/portlets/user/databasesmanager/server/util/SessionUtil.java index 3c74a52..d8f43ba 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/server/util/SessionUtil.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/server/util/SessionUtil.java @@ -1,124 +1,72 @@ package org.gcube.portlets.user.databasesmanager.server.util; -import java.util.concurrent.TimeUnit; +import java.util.HashMap; import javax.servlet.http.HttpSession; + import org.apache.log4j.Logger; import org.gcube.application.framework.core.session.ASLSession; import org.gcube.application.framework.core.session.SessionManager; -import org.gcube.common.scope.api.ScopeProvider; -import org.gcube.data.analysis.statisticalmanager.proxies.StatisticalManagerDSL; -import org.gcube.data.analysis.statisticalmanager.proxies.StatisticalManagerDataSpace; -import org.gcube.data.analysis.statisticalmanager.proxies.StatisticalManagerFactory; +import org.gcube.data.analysis.dataminermanagercl.server.DataMinerService; +import org.gcube.data.analysis.dataminermanagercl.server.dmservice.SClient; import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; +import org.gcube.portlets.user.databasesmanager.shared.Constants; +import org.gcube.portlets.user.databasesmanager.shared.SessionExpiredException; public class SessionUtil { - protected static Logger logger = Logger.getLogger(SessionUtil.class); - public static final String TEST_USER = "test.user"; - public static final String USER = "database.manager"; - - - public static ASLSession getAslSession(HttpSession httpSession) { - String sessionID = httpSession.getId(); - String user = (String) httpSession - .getAttribute(ScopeHelper.USERNAME_ATTRIBUTE); - - if (user == null) { - - // user = "loredana.liccardo"; - user = USER; - httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE, user); - ScopeProvider.instance.set("/gcube/devsec/devVRE"); - ASLSession session = SessionManager.getInstance().getASLSession( - sessionID, user); - session.setScope("/gcube/devsec/devVRE"); - - return session; - // return null; - - } else { - logger.trace("user found in session " + user); - } - ASLSession session = SessionManager.getInstance().getASLSession( - sessionID, user); - - return session; - } + private static Logger logger = Logger.getLogger(SessionUtil.class); + //public static final String TEST_USER = "test.user"; + //public static final String USER = "database.manager"; - public static boolean isSessionExpired(HttpSession httpSession) throws Exception { - logger.info("session validating..."); - //reading username from asl session - String userUsername = getAslSession(httpSession).getUsername(); - - /*COMMENT THIS IN DEVELOP ENVIROMENT (UNCOMMENT IN PRODUCTION)*/ - - if(userUsername.compareToIgnoreCase(USER)==0){ - logger.error("session is expired! username is: "+SessionUtil.USER); - return true; //is USER, session is expired - } - - if(userUsername.compareToIgnoreCase(TEST_USER)==0){ - logger.error("session is expired! username is: "+SessionUtil.TEST_USER); - return true; //is TEST_USER, session is expired + + public static ASLSession getASLSession(HttpSession httpSession) + throws Exception { + String username = (String) httpSession + .getAttribute(ScopeHelper.USERNAME_ATTRIBUTE); + ASLSession aslSession; + if (username == null) { + if (Constants.DEBUG_MODE) { + logger.info("no user found in session, use test user"); + + // Remove comment for Test + username = Constants.DEFAULT_USER; + String scope = Constants.DEFAULT_SCOPE; + + httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE, + username); + aslSession = SessionManager.getInstance().getASLSession( + httpSession.getId(), username); + aslSession.setScope(scope); + } else { + logger.info("No user found in session"); + throw new SessionExpiredException(); + + } + } else { + aslSession = SessionManager.getInstance().getASLSession( + httpSession.getId(), username); + } - logger.info("session is valid! current username is: "+userUsername); - - return false; - + logger.info("SessionUtil: aslSession " + aslSession.getUsername() + " " + + aslSession.getScope()); + + return aslSession; } - public static StatisticalManagerFactory getFactory(HttpSession httpSession) { - ASLSession session = getAslSession(httpSession); - return getFactory(session); - } + public static String getToken(ASLSession aslSession) throws Exception { + String token = null; + if (Constants.DEBUG_MODE) { + token = Constants.DEFAULT_TOKEN; + } else { + token = aslSession.getSecurityToken(); + } + logger.info("received token: " + token); + return token; - public static StatisticalManagerFactory getFactory(ASLSession session) { - ScopeProvider.instance.set(session.getScope()); - - return getFactory(session.getScope()); - } - - public static StatisticalManagerFactory getFactory(String scope) { - ScopeProvider.instance.set(scope.toString()); - - return StatisticalManagerDSL.createStateful() - .withTimeout(5, TimeUnit.MINUTES).build(); // IS - - } - - public static StatisticalManagerDataSpace getDataSpaceService( - HttpSession httpSession) { - ASLSession session = getAslSession(httpSession); - return getDataSpaceService(session); - } - - public static StatisticalManagerDataSpace getDataSpaceService( - ASLSession session) { - ScopeProvider.instance.set(getScope(session)); - - return StatisticalManagerDSL.dataSpace() - .withTimeout(5, TimeUnit.MINUTES).build(); - } - - public static String getUsername(HttpSession httpSession) { - ASLSession session = getAslSession(httpSession); - return getUsername(session); - } - - private static String getUsername(ASLSession session) { - return session.getUsername(); - } - - public static String getScope(HttpSession httpSession) { - ASLSession session = getAslSession(httpSession); - return getScope(session); - } - - private static String getScope(ASLSession session) { - return session.getScope().toString(); - } + } + } diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/shared/AlgorithmsName.java b/src/main/java/org/gcube/portlets/user/databasesmanager/shared/AlgorithmsName.java new file mode 100644 index 0000000..f49b822 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/shared/AlgorithmsName.java @@ -0,0 +1,67 @@ +package org.gcube.portlets.user.databasesmanager.shared; + +import java.util.Arrays; +import java.util.List; + +/** + * + * + */ +public enum AlgorithmsName { + LISTDBNAMES("org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.LISTDBNAMES"), + LISTDBINFO("org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.LISTDBINFO"), + LISTDBSCHEMA("org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.LISTDBSCHEMA"), + LISTTABLES("org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.LISTTABLES"), + GETTABLEDETAILS("org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.GETTABLEDETAILS"), + SUBMITQUERY("org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.SUBMITQUERY"), + SAMPLEONTABLE("org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.SAMPLEONTABLE"), + SMARTSAMPLEONTABLE("org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.SMARTSAMPLEONTABLE"), + RANDOMSAMPLEONTABLE("org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers.RANDOMSAMPLEONTABLE"); + + + /** + * @param text + */ + private AlgorithmsName(final String fullPackageName) { + this.fullPackageName = fullPackageName; + } + + private final String fullPackageName; + + @Override + public String toString() { + return fullPackageName; + } + + public String getFullPackageName() { + return fullPackageName; + } + + public String getId() { + return name(); + + } + + /** + * + * @param fullPackageName + * @return + */ + public static AlgorithmsName getFromFullPackageName(String fullPackageName) { + if (fullPackageName == null || fullPackageName.isEmpty()) + return null; + + for (AlgorithmsName type : values()) { + if (type.fullPackageName.compareToIgnoreCase(fullPackageName) == 0) { + return type; + } + } + return null; + } + + public static List asList() { + List list = Arrays.asList(values()); + return list; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/shared/Constants.java b/src/main/java/org/gcube/portlets/user/databasesmanager/shared/Constants.java new file mode 100644 index 0000000..00f832e --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/shared/Constants.java @@ -0,0 +1,54 @@ +package org.gcube.portlets.user.databasesmanager.shared; + +public class Constants { + public static final boolean DEBUG_MODE = false; + public static final boolean TEST_ENABLE = false; + + public static final String DEFAULT_USER = "giancarlo.panichi"; + public final static String DEFAULT_SCOPE = "/gcube/devNext"; + public final static String DEFAULT_TOKEN = "16e65d4f-11e0-4e4a-84b9-351688fccc12-98187548"; + + // SClientMap + public static final String SClientMap = "DataMinerClientMap"; + + // Div Gwt + public static final String CONTENTDIV = "contentDiv"; + + // Toolbar button + public static final String TABLESLIST = "Tables List"; + public static final String SUBMITQUERY = "Submit Query"; + public static final String GETINFO = "Get Info"; + public static final String TABLEDETAILS = "Table Details"; + public static final String SAMPLING = "Sampling"; + public static final String SMARTSAMPLING = "Smart Sampling"; + public static final String RANDOMSAMPLING = "Random Sampling"; + public static final String REFRESHCACHEDDATA = "Refresh Data"; + + // sql Dialects + public static final String POSTGRES = "POSTGRES"; + public static final String MYSQL = "MYSQL"; + public static final String NONE = "NONE"; + + // element types + // public static final String DATABASE="Database"; + // public static final String SCHEMA="Schema"; + + // elements type + public static final String RESOURCESLIST = "ResourcesList"; + public static final String RESOURCE = "resource"; + public static final String DATABASE = "database"; + public static final String SCHEMA = "schema"; + + // algorithmID + /* + public static final String ALGID_GETRESOURCE = "LISTDBNAMES"; + public static final String ALGID_GETDBINFO = "LISTDBINFO"; + public static final String ALGID_GETDBSCHEMA = "LISTDBSCHEMA"; + public static final String ALGID_GETTABLES = "LISTTABLES"; + public static final String ALGID_GETTABLEDETAILS = "GETTABLEDETAILS"; + public static final String ALGID_SUBMITQUERY = "SUBMITQUERY"; + public static final String ALGID_SAMPLEONTABLE = "SAMPLEONTABLE"; + public static final String ALGID_SMARTSAMPLEONTABLE = "SMARTSAMPLEONTABLE"; + public static final String ALGID_RANDOMSAMPLEONTABLE = "RANDOMSAMPLEONTABLE"; + */ +} diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/shared/ConstantsPortlet.java b/src/main/java/org/gcube/portlets/user/databasesmanager/shared/ConstantsPortlet.java deleted file mode 100644 index 274f391..0000000 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/shared/ConstantsPortlet.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.gcube.portlets.user.databasesmanager.shared; - -public class ConstantsPortlet { - - // Div Gwt - public static final String CONTENTDIV = "contentDiv"; - - //Toolbar button - public static final String TABLESLIST = "Tables List"; - public static final String SUBMITQUERY = "Submit Query"; - public static final String GETINFO = "Get Info"; - public static final String TABLEDETAILS = "Table Details"; - public static final String SAMPLING = "Sampling"; - public static final String SMARTSAMPLING = "Smart Sampling"; - public static final String RANDOMSAMPLING = "Random Sampling"; - public static final String REFRESHCACHEDDATA = "Refresh Data"; - - //sql Dialects - public static final String POSTGRES = "POSTGRES"; - public static final String MYSQL = "MYSQL"; - public static final String NONE = "NONE"; - - //element types -// public static final String DATABASE="Database"; -// public static final String SCHEMA="Schema"; - - //algorithmID - public static final String ALGID_GETRESOURCE="LISTDBNAMES"; - public static final String ALGID_GETDBINFO="LISTDBINFO"; - public static final String ALGID_GETDBSCHEMA="LISTDBSCHEMA"; - public static final String ALGID_GETTABLES="LISTTABLES"; - public static final String ALGID_GETTABLEDETAILS="GETTABLEDETAILS"; - public static final String ALGID_SUBMITQUERY="SUBMITQUERY"; - public static final String ALGID_SAMPLEONTABLE="SAMPLEONTABLE"; - public static final String ALGID_SMARTSAMPLEONTABLE="SMARTSAMPLEONTABLE"; - public static final String ALGID_RANDOMSAMPLEONTABLE="RANDOMSAMPLEONTABLE"; - - //elements type - public static final String RESOURCESLIST="ResourcesList"; - public static final String RESOURCE="resource"; - public static final String DATABASE="database"; - public static final String SCHEMA="schema"; -} diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/datamodel/ComputationOutput.java b/src/main/java/org/gcube/portlets/user/databasesmanager/shared/computation/ComputationOutput.java similarity index 55% rename from src/main/java/org/gcube/portlets/user/databasesmanager/client/datamodel/ComputationOutput.java rename to src/main/java/org/gcube/portlets/user/databasesmanager/shared/computation/ComputationOutput.java index b737998..42530e6 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/client/datamodel/ComputationOutput.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/shared/computation/ComputationOutput.java @@ -1,9 +1,11 @@ -package org.gcube.portlets.user.databasesmanager.client.datamodel; +package org.gcube.portlets.user.databasesmanager.shared.computation; +import java.io.Serializable; import java.util.LinkedHashMap; -public class ComputationOutput { +public class ComputationOutput implements Serializable { + private static final long serialVersionUID = -5508917907248426765L; private LinkedHashMap mapValues; private LinkedHashMap mapKeys; private String urlFile; @@ -12,7 +14,7 @@ public class ComputationOutput { public ComputationOutput() { mapKeys = new LinkedHashMap(); mapValues = new LinkedHashMap(); - urlFile=""; + urlFile = ""; } public void setMapValues(LinkedHashMap mapValues) { @@ -30,20 +32,28 @@ public class ComputationOutput { public LinkedHashMap getmapKeys() { return mapKeys; } - - public void setUrlFile(String url){ - this.urlFile=url; + + public void setUrlFile(String url) { + this.urlFile = url; } - - public String getUrlFile(){ + + public String getUrlFile() { return this.urlFile; } - - public void setSubmitQueryTotalRows(int val){ + + public void setSubmitQueryTotalRows(int val) { this.submitQueryTotalRows = val; } - - public int getSubmitQueryTotalRows(){ + + public int getSubmitQueryTotalRows() { return this.submitQueryTotalRows; } + + @Override + public String toString() { + return "ComputationOutput [mapValues=" + mapValues + ", mapKeys=" + + mapKeys + ", urlFile=" + urlFile + ", submitQueryTotalRows=" + + submitQueryTotalRows + "]"; + } + } diff --git a/src/test/resources/AlgorithmInstallation.txt b/src/test/resources/AlgorithmInstallation.txt new file mode 100644 index 0000000..14fb9d7 --- /dev/null +++ b/src/test/resources/AlgorithmInstallation.txt @@ -0,0 +1,10 @@ +./addAlgorithm.sh LISTDBINFO DATABASES org.gcube.dataaccess.algorithms.drmalgorithms.ListDBInfo /gcube/devNext/NextNext transducerers N k "legacy algorithm" +./addAlgorithm.sh LISTDBNAMES DATABASES org.gcube.dataaccess.algorithms.drmalgorithms.ListNames /gcube/devNext/NextNext transducerers N k "legacy algorithm" +./addAlgorithm.sh LISTDBSCHEMA DATABASES org.gcube.dataaccess.algorithms.drmalgorithms.ListSchemas /gcube/devNext/NextNext transducerers N k "legacy algorithm" +./addAlgorithm.sh LISTTABLES DATABASES org.gcube.dataaccess.algorithms.drmalgorithms.ListTables /gcube/devNext/NextNext transducerers N k "legacy algorithm" +./addAlgorithm.sh GETTABLEDETAILS DATABASES org.gcube.dataaccess.algorithms.drmalgorithms.GetTableDetails /gcube/devNext/NextNext transducerers N k "legacy algorithm" +./addAlgorithm.sh SUBMITQUERY DATABASES org.gcube.dataaccess.algorithms.drmalgorithms.SubmitQuery /gcube/devNext/NextNext transducerers N k "legacy algorithm" +./addAlgorithm.sh RANDOMSAMPLEONTABLE DATABASES org.gcube.dataaccess.algorithms.drmalgorithms.RandomSampleOnTable /gcube/devNext/NextNext transducerers N k "legacy algorithm" +./addAlgorithm.sh SAMPLEONTABLE DATABASES org.gcube.dataaccess.algorithms.drmalgorithms.SampleOnTable /gcube/devNext/NextNext transducerers N k "legacy algorithm" +./addAlgorithm.sh SMARTSAMPLEONTABLE DATABASES org.gcube.dataaccess.algorithms.drmalgorithms.SmartSampleOnTable /gcube/devNext/NextNext transducerers N k "legacy algorithm" +