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 ae70f4b..3c463dd 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 @@ -69,6 +69,7 @@ import org.gcube.portlets.user.databasesmanager.client.datamodel.SubmitQueryResu import org.gcube.portlets.user.databasesmanager.client.utils.ConstantsPortlet; import org.gcube.portlets.user.databasesmanager.server.util.SessionUtil; import org.gcube.portlets.user.databasesmanager.shared.SessionExpiredException; +import org.gcube.portlets.user.databasesmanager.shared.StatisticalManagerException; import com.extjs.gxt.ui.client.data.BasePagingLoadResult; import com.extjs.gxt.ui.client.data.PagingLoadConfig; @@ -82,7 +83,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // // the result generated in the LoadTables method // private List result = null; - + // logger private static Logger logger = Logger .getLogger(GWTdbManagerServiceImpl.class); @@ -109,9 +110,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements CacheManager cacheManager = CacheManager.create(); if (cacheManager == null) { - logger.error("dbmanager-> Failed to get the cacheManager. cacheManager null"); + logger.error("dbmanager-> Error while starting the servlet. Failed to get the cacheManager. cacheManager null"); throw new ServletException( - "Failed to get the cacheManager. cacheManager null"); + "Error while starting the servlet. Failed to get the cacheManager. cacheManager null"); } if (cacheManager != null) { @@ -133,9 +134,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements createCache(cachePath); if (employeeCache == null) { - logger.error("dbmanager-> Failed to get the cache. cache null"); + logger.error("dbmanager-> Error while starting the servlet. Failed to get the cache. cache null"); throw new ServletException( - "Failed to get the cache. cache null"); + "Error while starting the servlet. Failed to get the cache. cache null"); } else { cacheManager.addCache(employeeCache); logger.info("dbmanager-> cache added to the cacheManager"); @@ -158,12 +159,14 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } catch (Exception e) { // TODO: handle exception logger.error("dbmanager-> ", e); - throw e; + + throw new ServletException( + "Error while starting the servlet. Exception: " + e); } } - public void createCache(String cachePath) throws ServletException { + public void createCache(String cachePath) throws Exception { try { @@ -186,11 +189,13 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } catch (Exception e) { // TODO: handle exception - logger.error("dbmanager-> Failed to create the cache", e); +// logger.error("dbmanager-> Error while starting the servlet. Failed to create the cache", e); + throw new Exception("Error while starting the servlet. Failed to create the cache. Exception: " +e); } } + @Override public void destroy() { super.destroy(); @@ -210,16 +215,19 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements cacheManager.shutdown(); } else { - logger.error("dbmanager-> Failed to get the cacheManager. cacheManager null"); + logger.error("dbmanager-> Error while destroying the servlet. Failed to get the cacheManager. cacheManager null"); throw new Exception( - "Failed to get the cacheManager. cacheManager null"); + "Error while destroying the servlet. Failed to get the cacheManager. cacheManager null"); } } catch (Exception e) { // TODO: handle exception - logger.error("dbmanager-> Failed to destroy the cache", e); + logger.error( + "dbmanager-> Error while destroying the servlet. Exception:", + e); // e.printStackTrace(); + } } @@ -266,31 +274,31 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // to get resources from IS @Override public List getResource() throws Exception { - - //session check - if(isSessionExpired()) + + // session check + if (isSessionExpired()) throw new SessionExpiredException(); - // initialize variables with application startup - initVariables(); - - // data input - List inputParameters = new ArrayList(); - // data output - List outputParameters = new ArrayList(); - - // get algorithmId - String algorithmId = "LISTDBNAMES"; - - Parameter maxNumber = new Parameter("MaxNumber", "", "String", "-1"); - inputParameters.add(maxNumber); - - // check if the value is in cache. If data does not exist in cache - // the computation is started otherwise data are retrieved from - // cache. - try { + // initialize variables with application startup + initVariables(); + + // data input + List inputParameters = new ArrayList(); + // data output + List outputParameters = new ArrayList(); + + // get algorithmId + String algorithmId = "LISTDBNAMES"; + + Parameter maxNumber = new Parameter("MaxNumber", "", "String", "-1"); + inputParameters.add(maxNumber); + + // check if the value is in cache. If data does not exist in cache + // the computation is started otherwise data are retrieved from + // cache. + // get data from cache // check if data exist considering as key the input parameters // String key = inputParameters.get(0).getDefaultValue(); @@ -345,44 +353,52 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } + return outputParameters; + } catch (Exception e) { // TODO: handle exception // e.printStackTrace(); // throw new Exception("Failed to load data. " + e); logger.error("dbmanager-> ", e); + if (!(e instanceof StatisticalManagerException)) { + // GWT can't serialize all exceptions + throw new Exception( + "Error in server while loading data. Exception: " + e); + } throw e; } // } - return outputParameters; + } // to get information about databases of a resource @Override public LinkedHashMap getDBInfo(String resourceName) throws Exception { - - //session check - if(isSessionExpired()) - throw new SessionExpiredException(); - // data input - List inputParameters = new ArrayList(); - // data output - LinkedHashMap outputParameters = new LinkedHashMap(); - String algorithmId = "LISTDBINFO"; - - // print check - logger.info("dbmanager-> ResourceName: " + resourceName); - - if ((resourceName == null) || (resourceName.equals(""))) { - throw new Exception("Unable to load data"); - } - - Parameter resource = new Parameter("ResourceName", "", "String", ""); - inputParameters.add(resource); - inputParameters.get(0).setValue(resourceName); + // session check + if (isSessionExpired()) + throw new SessionExpiredException(); try { + // data input + List inputParameters = new ArrayList(); + // data output + LinkedHashMap outputParameters = new LinkedHashMap(); + + String algorithmId = "LISTDBINFO"; + + // print check + logger.info("dbmanager-> ResourceName: " + resourceName); + + if ((resourceName == null) || (resourceName.equals(""))) { + throw new Exception("Unable to load data"); + } + + 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 = inputParameters.get(0).getValue(); @@ -447,61 +463,70 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } + return outputParameters; + } catch (Exception e) { // TODO: handle exception // e.printStackTrace(); // throw new Exception("Failed to load data " + ); logger.error("dbmanager-> ", e); + + if (!(e instanceof StatisticalManagerException)) { + // GWT can't serialize all exceptions + throw new Exception( + "Error in server while loading data. Exception: " + e); + } + throw e; } - return outputParameters; } // to get schema for a database @Override public List getDBSchema(LinkedHashMap dataInput) throws Exception { - - //session check - if(isSessionExpired()) - throw new SessionExpiredException(); - // data input - List inputParameters = new ArrayList(); - // data output - List outputParameters = new ArrayList(); - - String algorithmId = "LISTDBSCHEMA"; - // print check - String rs = dataInput.get("ResourceName"); - String db = dataInput.get("DatabaseName"); - - logger.info("dbmanager-> ResourceName: " + rs); - logger.info("dbmanager-> DatabaseName: " + db); - - if ((rs == null) || (rs.equals(""))) { - throw new Exception("Unable to load data"); - } - if ((db == null) || (db.equals(""))) { - throw new Exception("Unable to load data"); - } - - // set input parameters - Parameter resource = new Parameter("ResourceName", "", "String", ""); - Parameter database = new Parameter("DatabaseName", "", "String", ""); - inputParameters.add(resource); - inputParameters.add(database); - - inputParameters.get(0).setValue(rs); - inputParameters.get(1).setValue(db); - - // print check algorithm input parameters - // for (int i = 0; i < inputParameters.size(); i++) { - // logger.info(inputParameters.get(i).getName()); - // } + // session check + if (isSessionExpired()) + throw new SessionExpiredException(); try { + + // data input + List inputParameters = new ArrayList(); + // data output + List outputParameters = new ArrayList(); + + String algorithmId = "LISTDBSCHEMA"; + // print check + String rs = dataInput.get("ResourceName"); + String db = dataInput.get("DatabaseName"); + + logger.info("dbmanager-> ResourceName: " + rs); + logger.info("dbmanager-> DatabaseName: " + db); + + if ((rs == null) || (rs.equals(""))) { + throw new Exception("Unable to load data"); + } + if ((db == null) || (db.equals(""))) { + throw new Exception("Unable to load data"); + } + + // set input parameters + Parameter resource = new Parameter("ResourceName", "", "String", ""); + Parameter database = new Parameter("DatabaseName", "", "String", ""); + inputParameters.add(resource); + inputParameters.add(database); + + inputParameters.get(0).setValue(rs); + inputParameters.get(1).setValue(db); + + // print check algorithm input parameters + // for (int i = 0; i < inputParameters.size(); i++) { + // logger.info(inputParameters.get(i).getName()); + // } + // get data from cache // check if data exist considering as key the input parameters String key = inputParameters.get(0).getValue() @@ -560,72 +585,80 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } + return outputParameters; + } catch (Exception e) { // TODO: handle exception // e.printStackTrace(); // throw new Exception("Failed to load data. " + e); logger.error("dbmanager-> ", e); + if (!(e instanceof StatisticalManagerException)) { + // GWT can't serialize all exceptions + throw new Exception( + "Error in server while loading data. Exception: " + e); + } throw e; } - return outputParameters; } // to get tables private List getTables(LinkedHashMap dataInput, String elementType) throws Exception { - // data input - List inputParameters = new ArrayList(); - // data output - List outputParameters = new ArrayList(); - - String algorithmId = "LISTTABLES"; - - String rs = dataInput.get("ResourceName"); - String db = dataInput.get("DatabaseName"); - String scm = dataInput.get("SchemaName"); - - // print check - logger.info("dbmanager-> ResourceName: " + rs); - logger.info("dbmanager-> DatabaseName: " + db); - logger.info("dbmanager-> SchemaName: " + scm); - - if ((elementType != null) - && (elementType.equals(ConstantsPortlet.SCHEMA))) { - if ((rs == null) || (rs.equals(""))) { - throw new Exception("Unable to load data"); - } - if ((db == null) || (db.equals(""))) { - throw new Exception("Unable to load data"); - } - if ((scm == null) || (scm.equals(""))) { - throw new Exception("Unable to load data"); - } - } - if ((elementType != null) - && (elementType.equals(ConstantsPortlet.DATABASE))) { - if ((rs == null) || (rs.equals(""))) { - throw new Exception("Unable to load data"); - } - if ((db == null) || (db.equals(""))) { - throw new Exception("Unable to load data"); - } - } - - // set input parameters - Parameter resource = new Parameter("ResourceName", "", "String", ""); - Parameter database = new Parameter("DatabaseName", "", "String", ""); - Parameter schema = new Parameter("SchemaName", "", "String", ""); - inputParameters.add(resource); - inputParameters.add(database); - inputParameters.add(schema); - - inputParameters.get(0).setValue(rs); - inputParameters.get(1).setValue(db); - inputParameters.get(2).setValue(scm); try { + + // data input + List inputParameters = new ArrayList(); + // data output + List outputParameters = new ArrayList(); + + String algorithmId = "LISTTABLES"; + + String rs = dataInput.get("ResourceName"); + String db = dataInput.get("DatabaseName"); + String scm = dataInput.get("SchemaName"); + + // print check + logger.info("dbmanager-> ResourceName: " + rs); + logger.info("dbmanager-> DatabaseName: " + db); + logger.info("dbmanager-> SchemaName: " + scm); + + if ((elementType != null) + && (elementType.equals(ConstantsPortlet.SCHEMA))) { + if ((rs == null) || (rs.equals(""))) { + throw new Exception("Unable to load data"); + } + if ((db == null) || (db.equals(""))) { + throw new Exception("Unable to load data"); + } + if ((scm == null) || (scm.equals(""))) { + throw new Exception("Unable to load data"); + } + } + if ((elementType != null) + && (elementType.equals(ConstantsPortlet.DATABASE))) { + if ((rs == null) || (rs.equals(""))) { + throw new Exception("Unable to load data"); + } + if ((db == null) || (db.equals(""))) { + throw new Exception("Unable to load data"); + } + } + + // set input parameters + Parameter resource = new Parameter("ResourceName", "", "String", ""); + Parameter database = new Parameter("DatabaseName", "", "String", ""); + Parameter schema = new Parameter("SchemaName", "", "String", ""); + inputParameters.add(resource); + inputParameters.add(database); + inputParameters.add(schema); + + inputParameters.get(0).setValue(rs); + inputParameters.get(1).setValue(db); + inputParameters.get(2).setValue(scm); + // get data from cache // check if data exist considering as key the input parameters String key = inputParameters.get(0).getValue() @@ -683,11 +716,19 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } } + return outputParameters; } catch (Exception e) { // e.printStackTrace(); // throw new Exception("Failed to load data. " + e); - logger.error("dbmanager-> ", e); +// logger.error("dbmanager-> ", e); + + if (!(e instanceof StatisticalManagerException)) { + // GWT can't serialize all exceptions + throw new Exception( + "Error in server while loading data. Exception: " + e); + } + throw e; } @@ -716,7 +757,6 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // outputParameters.add(row); // } - return outputParameters; } // to load tables @@ -758,72 +798,89 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // // previousSchema = currentSchema; // session.setAttribute("previousSchema", previousSchema); - - //session check - if(isSessionExpired()) - throw new SessionExpiredException(); - List result = new ArrayList<>(); + // session check + if (isSessionExpired()) + throw new SessionExpiredException(); - // get tables - // if (result == null) - // result = getTables(dataInput); - if (result.size() == 0) - result = getTables(dataInput, elementType); + try { - // Create a sublist and add data to list according - // to the limit and offset value of the config - List sublist = new ArrayList(); - BasePagingLoadResult loadResult = null; + List result = new ArrayList<>(); - // print check on the search - // logger.info("Searching in the table: " + SearchTable); - // logger.info("Keyword to search: " + keyword); + // get tables + // if (result == null) + // result = getTables(dataInput); + if (result.size() == 0) + result = getTables(dataInput, elementType); - int start = config.getOffset(); - int limit = result.size(); + // Create a sublist and add data to list according + // to the limit and offset value of the config + List sublist = new ArrayList(); + BasePagingLoadResult loadResult = null; - if (config.getLimit() > 0) { - limit = Math.min(start + config.getLimit(), limit); - } + // print check on the search + // logger.info("Searching in the table: " + SearchTable); + // logger.info("Keyword to search: " + keyword); - int totalNumber = result.size(); + int start = config.getOffset(); + int limit = result.size(); - if ((SearchTable == false) || keyword == null || keyword.length() == 0) { - sublist = new ArrayList(result.subList(start, limit)); - } else { - // print check - // logger.info("searching the table"); + if (config.getLimit() > 0) { + limit = Math.min(start + config.getLimit(), limit); + } - // search the table - for (int i = 0; i < result.size(); i++) { - if ((result.get(i).getValue().toLowerCase()).startsWith(keyword - .toLowerCase())) { - sublist.add(result.get(i)); + int totalNumber = result.size(); + + if ((SearchTable == false) || keyword == null + || keyword.length() == 0) { + sublist = new ArrayList(result.subList(start, limit)); + } else { + // print check + // logger.info("searching the table"); + + // search the table + for (int i = 0; i < result.size(); i++) { + if ((result.get(i).getValue().toLowerCase()) + .startsWith(keyword.toLowerCase())) { + sublist.add(result.get(i)); + } + } + + limit = sublist.size(); + int sublen = sublist.size(); + totalNumber = sublen; + + if (start < sublen - 1) { + limit = Math.min(sublen, limit); + totalNumber = sublist.size(); + sublist = new ArrayList(sublist.subList(start, + limit)); } } - limit = sublist.size(); - int sublen = sublist.size(); - totalNumber = sublen; + // print check + // logger.info("result size: " + totalNumber); + // logger.info("limit: " + limit); + // logger.info("offset: " + config.getOffset()); + // logger.info("start: " + start); - if (start < sublen - 1) { - limit = Math.min(sublen, limit); - totalNumber = sublist.size(); - sublist = new ArrayList(sublist.subList(start, limit)); + loadResult = new BasePagingLoadResult(sublist, + config.getOffset(), totalNumber); + // session.setAttribute("TablesResult", result); + return loadResult; + + } catch (Exception e) { + + logger.error("dbmanager-> ", e); + + if (!(e instanceof StatisticalManagerException)) { + // GWT can't serialize all exceptions + throw new Exception( + "Error in server while loading data. Exception: " + e); } + + throw e; } - - // print check - // logger.info("result size: " + totalNumber); - // logger.info("limit: " + limit); - // logger.info("offset: " + config.getOffset()); - // logger.info("start: " + start); - - loadResult = new BasePagingLoadResult(sublist, - config.getOffset(), totalNumber); - // session.setAttribute("TablesResult", result); - return loadResult; } // to submit a query @@ -832,77 +889,80 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements LinkedHashMap dataDB, String query, boolean valueReadOnlyQuery, boolean smartCorrectionQuery, String language, String UID) throws Exception { - - //session check - if(isSessionExpired()) - throw new SessionExpiredException(); - logger.info("dbmanager-> Dialect used for smart correction: " - + language); + // session check + if (isSessionExpired()) + throw new SessionExpiredException(); - // data input - List inputParameters = new ArrayList(); - // data output - // List output = new ArrayList(); - List output = null; - - // list that contains table attributes - List listAttributes = null; - - // converted query - String convertedQuery = ""; - - String algorithmId = "SUBMITQUERY"; - - // print check - String rs = dataDB.get("ResourceName"); - String db = dataDB.get("DatabaseName"); - - // print check - logger.info("dbmanager-> ResourceName: " + rs); - logger.info("dbmanager-> DatabaseName: " + db); - - logger.info("dbmanager-> Query: " + query); - logger.info("dbmanager-> SmartCorrections check: " - + smartCorrectionQuery); - - if ((rs == null) || (rs.equals(""))) { - throw new Exception("Unable to load data"); - } - if ((db == null) || (db.equals(""))) { - throw new Exception("Unable to load data"); - } - if ((query == null) || (query.equals(""))) { - throw new Exception("Unable to load data"); - } - - // set input parameters - Parameter resource = new Parameter("ResourceName", "", "String", ""); - Parameter database = new Parameter("DatabaseName", "", "String", ""); - Parameter readOnlyQuery = new Parameter("Read-Only Query", "", - "Boolean", "true"); - Parameter applySmartCorrection = new Parameter( - "Apply Smart Correction", "", "Boolean", "true"); - Parameter lng = new Parameter("Language", "", "NONE", "NONE"); - Parameter q = new Parameter("Query", "", "String", ""); - - inputParameters.add(resource); - inputParameters.add(database); - inputParameters.add(readOnlyQuery); - inputParameters.add(applySmartCorrection); - inputParameters.add(lng); - inputParameters.add(q); - - inputParameters.get(0).setValue(rs); - inputParameters.get(1).setValue(db); - inputParameters.get(2).setValue(String.valueOf(valueReadOnlyQuery)); - inputParameters.get(3).setValue(String.valueOf(smartCorrectionQuery)); - inputParameters.get(4).setValue(language); - inputParameters.get(5).setValue(query); - - // create data structure - ComputationOutput outputData = new ComputationOutput(); try { + + logger.info("dbmanager-> Dialect used for smart correction: " + + language); + + // data input + List inputParameters = new ArrayList(); + // data output + // List output = new ArrayList(); + List output = null; + + // list that contains table attributes + List listAttributes = null; + + // converted query + String convertedQuery = ""; + + String algorithmId = "SUBMITQUERY"; + + // print check + String rs = dataDB.get("ResourceName"); + String db = dataDB.get("DatabaseName"); + + // print check + logger.info("dbmanager-> ResourceName: " + rs); + logger.info("dbmanager-> DatabaseName: " + db); + + logger.info("dbmanager-> Query: " + query); + logger.info("dbmanager-> SmartCorrections check: " + + smartCorrectionQuery); + + if ((rs == null) || (rs.equals(""))) { + throw new Exception("Unable to load data"); + } + if ((db == null) || (db.equals(""))) { + throw new Exception("Unable to load data"); + } + if ((query == null) || (query.equals(""))) { + throw new Exception("Unable to load data"); + } + + // set input parameters + Parameter resource = new Parameter("ResourceName", "", "String", ""); + Parameter database = new Parameter("DatabaseName", "", "String", ""); + Parameter readOnlyQuery = new Parameter("Read-Only Query", "", + "Boolean", "true"); + Parameter applySmartCorrection = new Parameter( + "Apply Smart Correction", "", "Boolean", "true"); + Parameter lng = new Parameter("Language", "", "NONE", "NONE"); + Parameter q = new Parameter("Query", "", "String", ""); + + inputParameters.add(resource); + inputParameters.add(database); + inputParameters.add(readOnlyQuery); + inputParameters.add(applySmartCorrection); + inputParameters.add(lng); + inputParameters.add(q); + + inputParameters.get(0).setValue(rs); + inputParameters.get(1).setValue(db); + inputParameters.get(2).setValue(String.valueOf(valueReadOnlyQuery)); + inputParameters.get(3).setValue( + String.valueOf(smartCorrectionQuery)); + inputParameters.get(4).setValue(language); + inputParameters.get(5).setValue(query); + + // create data structure + ComputationOutput outputData = new ComputationOutput(); + // computation id String computationId = startComputation(algorithmId, inputParameters, outputData, UID); @@ -956,477 +1016,538 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } else { listAttributes = null; } + + // generate the file csv output + String name = "SubmitQuery"; + String fileName = storeResultIntoCSVFile(output, name); + // get the web application path + HttpServletRequest request = this.getThreadLocalRequest(); + String applicationPath = request.getContextPath(); + // logger.info("dbmanager-> Application Path: " + applicationPath); + String partialPathFile = applicationPath + "/computationResult/" + + fileName; + + SubmitQueryResultWithFileFromServlet obj = new SubmitQueryResultWithFileFromServlet( + listAttributes, convertedQuery, partialPathFile); + + return obj; + } catch (Exception e) { // e.printStackTrace(); + logger.error("dbmanager-> ", e); // TODO TO REMOVE. Exception Statistical management to remove a // computation if (e.getMessage() .contains( "javax.xml.ws.soap.SOAPFaultException: java.lang.IndexOutOfBoundsException")) { - e = new Exception("ServerException"); + throw new Exception("ServerException"); } - logger.error("dbmanager-> ", e); + if (!(e instanceof StatisticalManagerException)) { + // GWT can't serialize all exceptions + throw new Exception( + "Error in server while loading data. Exception: " + e); + } + throw e; } - // generate the file csv output - String name = "SubmitQuery"; - String fileName = storeResultIntoCSVFile(output, name); - // get the web application path - HttpServletRequest request = this.getThreadLocalRequest(); - String applicationPath = request.getContextPath(); - // logger.info("dbmanager-> Application Path: " + applicationPath); - String partialPathFile = applicationPath + "/computationResult/" - + fileName; - - SubmitQueryResultWithFileFromServlet obj = new SubmitQueryResultWithFileFromServlet( - listAttributes, convertedQuery, partialPathFile); - - return obj; } @Override public SamplingResultWithFileFromServlet sample( LinkedHashMap dataInput, String elementType) throws Exception { - - //session check - if(isSessionExpired()) - throw new SessionExpiredException(); - // data input - List inputParameters = new ArrayList(); - // output sample result - List output = new ArrayList(); - String algorithmId = "SAMPLEONTABLE"; + // session check + if (isSessionExpired()) + throw new SessionExpiredException(); - // print check - String rs = dataInput.get("ResourceName"); - String db = dataInput.get("DatabaseName"); - String scm = dataInput.get("SchemaName"); - String tab = dataInput.get("TableName"); + try { + // data input + List inputParameters = new ArrayList(); + // output sample result + List output = new ArrayList(); - // print check - logger.info("dbmanager-> ResourceName: " + rs); - logger.info("dbmanager-> DatabaseName: " + db); - logger.info("dbmanager-> SchemaName: " + scm); - logger.info("dbmanager-> TableName: " + tab); + String algorithmId = "SAMPLEONTABLE"; - if ((elementType != null) - && (elementType.equals(ConstantsPortlet.SCHEMA))) { - if ((rs == null) || (rs.equals(""))) { - throw new Exception("Unable to load data"); + // print check + String rs = dataInput.get("ResourceName"); + String db = dataInput.get("DatabaseName"); + String scm = dataInput.get("SchemaName"); + String tab = dataInput.get("TableName"); + + // print check + logger.info("dbmanager-> ResourceName: " + rs); + logger.info("dbmanager-> DatabaseName: " + db); + logger.info("dbmanager-> SchemaName: " + scm); + logger.info("dbmanager-> TableName: " + tab); + + if ((elementType != null) + && (elementType.equals(ConstantsPortlet.SCHEMA))) { + if ((rs == null) || (rs.equals(""))) { + throw new Exception("Unable to load data"); + } + if ((db == null) || (db.equals(""))) { + throw new Exception("Unable to load data"); + } + if ((scm == null) || (scm.equals(""))) { + throw new Exception("Unable to load data"); + } + if ((tab == null) || (tab.equals(""))) { + throw new Exception("Unable to load data"); + } } - if ((db == null) || (db.equals(""))) { - throw new Exception("Unable to load data"); + if ((elementType != null) + && (elementType.equals(ConstantsPortlet.DATABASE))) { + if ((rs == null) || (rs.equals(""))) { + throw new Exception("Unable to load data"); + } + if ((db == null) || (db.equals(""))) { + throw new Exception("Unable to load data"); + } + if ((tab == null) || (tab.equals(""))) { + throw new Exception("Unable to load data"); + } } - if ((scm == null) || (scm.equals(""))) { - throw new Exception("Unable to load data"); + + // set input parameters + Parameter resource = new Parameter("ResourceName", "", "String", ""); + Parameter database = new Parameter("DatabaseName", "", "String", ""); + Parameter schema = new Parameter("SchemaName", "", "String", ""); + Parameter table = new Parameter("TableName", "", "String", ""); + inputParameters.add(resource); + inputParameters.add(database); + inputParameters.add(schema); + inputParameters.add(table); + + inputParameters.get(0).setValue(rs); + inputParameters.get(1).setValue(db); + inputParameters.get(2).setValue(scm); + inputParameters.get(3).setValue(tab); + + // create data structure + ComputationOutput outputData = new ComputationOutput(); + // computation id + String computationId = startComputation(algorithmId, + inputParameters, outputData); + + // print check on retrieving data + // logger.info("output data retrieved"); + + // data output values + LinkedHashMap mapValues = new LinkedHashMap(); + // data output keys + LinkedHashMap mapKeys = new LinkedHashMap(); + + mapValues = outputData.getMapValues(); + mapKeys = outputData.getmapKeys(); + + for (int i = 0; i < mapValues.size(); i++) { + Result row = new Result(mapKeys.get(String.valueOf(i)), + mapValues.get(String.valueOf(i))); + output.add(row); } - if ((tab == null) || (tab.equals(""))) { - throw new Exception("Unable to load data"); + + String name = "Sampling" + "_" + tab; + String fileName = storeResultIntoCSVFile(output, name); + + HttpServletRequest request = this.getThreadLocalRequest(); + String applicationPath = request.getContextPath(); + // logger.info("dbmanager-> Application Path: " + applicationPath); + String partialPathFile = applicationPath + "/computationResult/" + + fileName; + SamplingResultWithFileFromServlet obj = new SamplingResultWithFileFromServlet( + output, partialPathFile); + + return obj; + + } catch (Exception e) { + logger.error("dbmanager-> ", e); + if (!(e instanceof StatisticalManagerException)) { + // GWT can't serialize all exceptions + throw new Exception( + "Error in server while loading data. Exception: " + e); } + throw e; } - if ((elementType != null) - && (elementType.equals(ConstantsPortlet.DATABASE))) { - if ((rs == null) || (rs.equals(""))) { - throw new Exception("Unable to load data"); - } - if ((db == null) || (db.equals(""))) { - throw new Exception("Unable to load data"); - } - if ((tab == null) || (tab.equals(""))) { - throw new Exception("Unable to load data"); - } - } - - // set input parameters - Parameter resource = new Parameter("ResourceName", "", "String", ""); - Parameter database = new Parameter("DatabaseName", "", "String", ""); - Parameter schema = new Parameter("SchemaName", "", "String", ""); - Parameter table = new Parameter("TableName", "", "String", ""); - inputParameters.add(resource); - inputParameters.add(database); - inputParameters.add(schema); - inputParameters.add(table); - - inputParameters.get(0).setValue(rs); - inputParameters.get(1).setValue(db); - inputParameters.get(2).setValue(scm); - inputParameters.get(3).setValue(tab); - - // create data structure - ComputationOutput outputData = new ComputationOutput(); - // computation id - String computationId = startComputation(algorithmId, inputParameters, - outputData); - - // print check on retrieving data - // logger.info("output data retrieved"); - - // data output values - LinkedHashMap mapValues = new LinkedHashMap(); - // data output keys - LinkedHashMap mapKeys = new LinkedHashMap(); - - mapValues = outputData.getMapValues(); - mapKeys = outputData.getmapKeys(); - - for (int i = 0; i < mapValues.size(); i++) { - Result row = new Result(mapKeys.get(String.valueOf(i)), - mapValues.get(String.valueOf(i))); - output.add(row); - } - - String name = "Sampling" + "_" + tab; - String fileName = storeResultIntoCSVFile(output, name); - - HttpServletRequest request = this.getThreadLocalRequest(); - String applicationPath = request.getContextPath(); - // logger.info("dbmanager-> Application Path: " + applicationPath); - String partialPathFile = applicationPath + "/computationResult/" - + fileName; - SamplingResultWithFileFromServlet obj = new SamplingResultWithFileFromServlet( - output, partialPathFile); - - return obj; } @Override public SamplingResultWithFileFromServlet smartSample( LinkedHashMap dataInput, String elementType) throws Exception { - - //session check - if(isSessionExpired()) - throw new SessionExpiredException(); - // data input - List inputParameters = new ArrayList(); - // output sample result - List output = new ArrayList(); - String algorithmId = "SMARTSAMPLEONTABLE"; + // session check + if (isSessionExpired()) + throw new SessionExpiredException(); - // print check - String rs = dataInput.get("ResourceName"); - String db = dataInput.get("DatabaseName"); - String scm = dataInput.get("SchemaName"); - String tab = dataInput.get("TableName"); + try { + // data input + List inputParameters = new ArrayList(); + // output sample result + List output = new ArrayList(); - // print check - logger.info("dbmanager-> ResourceName: " + rs); - logger.info("dbmanager-> DatabaseName: " + db); - logger.info("dbmanager-> SchemaName: " + scm); - logger.info("dbmanager-> TableName: " + tab); + String algorithmId = "SMARTSAMPLEONTABLE"; - if ((elementType != null) - && (elementType.equals(ConstantsPortlet.SCHEMA))) { - if ((rs == null) || (rs.equals(""))) { - throw new Exception("Unable to load data"); + // print check + String rs = dataInput.get("ResourceName"); + String db = dataInput.get("DatabaseName"); + String scm = dataInput.get("SchemaName"); + String tab = dataInput.get("TableName"); + + // print check + logger.info("dbmanager-> ResourceName: " + rs); + logger.info("dbmanager-> DatabaseName: " + db); + logger.info("dbmanager-> SchemaName: " + scm); + logger.info("dbmanager-> TableName: " + tab); + + if ((elementType != null) + && (elementType.equals(ConstantsPortlet.SCHEMA))) { + if ((rs == null) || (rs.equals(""))) { + throw new Exception("Unable to load data"); + } + if ((db == null) || (db.equals(""))) { + throw new Exception("Unable to load data"); + } + if ((scm == null) || (scm.equals(""))) { + throw new Exception("Unable to load data"); + } + if ((tab == null) || (tab.equals(""))) { + throw new Exception("Unable to load data"); + } } - if ((db == null) || (db.equals(""))) { - throw new Exception("Unable to load data"); + if ((elementType != null) + && (elementType.equals(ConstantsPortlet.DATABASE))) { + if ((rs == null) || (rs.equals(""))) { + throw new Exception("Unable to load data"); + } + if ((db == null) || (db.equals(""))) { + throw new Exception("Unable to load data"); + } + if ((tab == null) || (tab.equals(""))) { + throw new Exception("Unable to load data"); + } } - if ((scm == null) || (scm.equals(""))) { - throw new Exception("Unable to load data"); + + // set input parameters + Parameter resource = new Parameter("ResourceName", "", "String", ""); + Parameter database = new Parameter("DatabaseName", "", "String", ""); + Parameter schema = new Parameter("SchemaName", "", "String", ""); + Parameter table = new Parameter("TableName", "", "String", ""); + inputParameters.add(resource); + inputParameters.add(database); + inputParameters.add(schema); + inputParameters.add(table); + + inputParameters.get(0).setValue(rs); + inputParameters.get(1).setValue(db); + inputParameters.get(2).setValue(scm); + inputParameters.get(3).setValue(tab); + + // create data structure + ComputationOutput outputData = new ComputationOutput(); + // computation id + String computationId = startComputation(algorithmId, + inputParameters, outputData); + + // print check on retrieving data + // logger.info("dbmanager-> output data retrieved"); + + // data output values + LinkedHashMap mapValues = new LinkedHashMap(); + // data output keys + LinkedHashMap mapKeys = new LinkedHashMap(); + + mapValues = outputData.getMapValues(); + mapKeys = outputData.getmapKeys(); + + for (int i = 0; i < mapValues.size(); i++) { + Result row = new Result(mapKeys.get(String.valueOf(i)), + mapValues.get(String.valueOf(i))); + output.add(row); } - if ((tab == null) || (tab.equals(""))) { - throw new Exception("Unable to load data"); + + String name = "SmartSampling" + "_" + tab; + String fileName = storeResultIntoCSVFile(output, name); + + HttpServletRequest request = this.getThreadLocalRequest(); + String applicationPath = request.getContextPath(); + // logger.info("dbmanager-> Application Path: " + applicationPath); + String partialPathFile = applicationPath + "/computationResult/" + + fileName; + SamplingResultWithFileFromServlet obj = new SamplingResultWithFileFromServlet( + output, partialPathFile); + + return obj; + + } catch (Exception e) { + logger.error("dbmanager-> ", e); + if (!(e instanceof StatisticalManagerException)) { + // GWT can't serialize all exceptions + throw new Exception( + "Error in server while loading data. Exception: " + e); } + throw e; } - if ((elementType != null) - && (elementType.equals(ConstantsPortlet.DATABASE))) { - if ((rs == null) || (rs.equals(""))) { - throw new Exception("Unable to load data"); - } - if ((db == null) || (db.equals(""))) { - throw new Exception("Unable to load data"); - } - if ((tab == null) || (tab.equals(""))) { - throw new Exception("Unable to load data"); - } - } - - // set input parameters - Parameter resource = new Parameter("ResourceName", "", "String", ""); - Parameter database = new Parameter("DatabaseName", "", "String", ""); - Parameter schema = new Parameter("SchemaName", "", "String", ""); - Parameter table = new Parameter("TableName", "", "String", ""); - inputParameters.add(resource); - inputParameters.add(database); - inputParameters.add(schema); - inputParameters.add(table); - - inputParameters.get(0).setValue(rs); - inputParameters.get(1).setValue(db); - inputParameters.get(2).setValue(scm); - inputParameters.get(3).setValue(tab); - - // create data structure - ComputationOutput outputData = new ComputationOutput(); - // computation id - String computationId = startComputation(algorithmId, inputParameters, - outputData); - - // print check on retrieving data - // logger.info("dbmanager-> output data retrieved"); - - // data output values - LinkedHashMap mapValues = new LinkedHashMap(); - // data output keys - LinkedHashMap mapKeys = new LinkedHashMap(); - - mapValues = outputData.getMapValues(); - mapKeys = outputData.getmapKeys(); - - for (int i = 0; i < mapValues.size(); i++) { - Result row = new Result(mapKeys.get(String.valueOf(i)), - mapValues.get(String.valueOf(i))); - output.add(row); - } - - String name = "SmartSampling" + "_" + tab; - String fileName = storeResultIntoCSVFile(output, name); - - HttpServletRequest request = this.getThreadLocalRequest(); - String applicationPath = request.getContextPath(); - // logger.info("dbmanager-> Application Path: " + applicationPath); - String partialPathFile = applicationPath + "/computationResult/" - + fileName; - SamplingResultWithFileFromServlet obj = new SamplingResultWithFileFromServlet( - output, partialPathFile); - - return obj; } @Override public SamplingResultWithFileFromServlet randomSample( LinkedHashMap dataInput, String elementType) throws Exception { - - //session check - if(isSessionExpired()) - throw new SessionExpiredException(); - // data input - List inputParameters = new ArrayList(); - // output sample result - List output = new ArrayList(); + // session check + if (isSessionExpired()) + throw new SessionExpiredException(); - String algorithmId = "RANDOMSAMPLEONTABLE"; + try { + // data input + List inputParameters = new ArrayList(); + // output sample result + List output = new ArrayList(); - // print check - String rs = dataInput.get("ResourceName"); - String db = dataInput.get("DatabaseName"); - String scm = dataInput.get("SchemaName"); - String tab = dataInput.get("TableName"); + String algorithmId = "RANDOMSAMPLEONTABLE"; - // print check - logger.info("dbmanager-> ResourceName: " + rs); - logger.info("dbmanager-> DatabaseName: " + db); - logger.info("dbmanager-> SchemaName: " + scm); - logger.info("dbmanager-> TableName: " + tab); + // print check + String rs = dataInput.get("ResourceName"); + String db = dataInput.get("DatabaseName"); + String scm = dataInput.get("SchemaName"); + String tab = dataInput.get("TableName"); - if ((elementType != null) - && (elementType.equals(ConstantsPortlet.SCHEMA))) { - if ((rs == null) || (rs.equals(""))) { - throw new Exception("Unable to load data"); + // print check + logger.info("dbmanager-> ResourceName: " + rs); + logger.info("dbmanager-> DatabaseName: " + db); + logger.info("dbmanager-> SchemaName: " + scm); + logger.info("dbmanager-> TableName: " + tab); + + if ((elementType != null) + && (elementType.equals(ConstantsPortlet.SCHEMA))) { + if ((rs == null) || (rs.equals(""))) { + throw new Exception("Unable to load data"); + } + if ((db == null) || (db.equals(""))) { + throw new Exception("Unable to load data"); + } + if ((scm == null) || (scm.equals(""))) { + throw new Exception("Unable to load data"); + } + if ((tab == null) || (tab.equals(""))) { + throw new Exception("Unable to load data"); + } } - if ((db == null) || (db.equals(""))) { - throw new Exception("Unable to load data"); + if ((elementType != null) + && (elementType.equals(ConstantsPortlet.DATABASE))) { + if ((rs == null) || (rs.equals(""))) { + throw new Exception("Unable to load data"); + } + if ((db == null) || (db.equals(""))) { + throw new Exception("Unable to load data"); + } + if ((tab == null) || (tab.equals(""))) { + throw new Exception("Unable to load data"); + } } - if ((scm == null) || (scm.equals(""))) { - throw new Exception("Unable to load data"); + + // set input parameters + Parameter resource = new Parameter("ResourceName", "", "String", ""); + Parameter database = new Parameter("DatabaseName", "", "String", ""); + Parameter schema = new Parameter("SchemaName", "", "String", ""); + Parameter table = new Parameter("TableName", "", "String", ""); + inputParameters.add(resource); + inputParameters.add(database); + inputParameters.add(schema); + inputParameters.add(table); + + inputParameters.get(0).setValue(rs); + inputParameters.get(1).setValue(db); + inputParameters.get(2).setValue(scm); + inputParameters.get(3).setValue(tab); + + // create data structure + ComputationOutput outputData = new ComputationOutput(); + // computation id + String computationId = startComputation(algorithmId, + inputParameters, outputData); + + // print check on retrieving data + // logger.info("dbmanager-> output data retrieved"); + + // data output values + LinkedHashMap mapValues = new LinkedHashMap(); + // data output keys + LinkedHashMap mapKeys = new LinkedHashMap(); + + mapValues = outputData.getMapValues(); + mapKeys = outputData.getmapKeys(); + + for (int i = 0; i < mapValues.size(); i++) { + Result row = new Result(mapKeys.get(String.valueOf(i)), + mapValues.get(String.valueOf(i))); + output.add(row); } - if ((tab == null) || (tab.equals(""))) { - throw new Exception("Unable to load data"); + + String name = "RandomSampling" + "_" + tab; + String fileName = storeResultIntoCSVFile(output, name); + + HttpServletRequest request = this.getThreadLocalRequest(); + String applicationPath = request.getContextPath(); + // logger.info("dbmanager-> Application Path: " + applicationPath); + String partialPathFile = applicationPath + "/computationResult/" + + fileName; + SamplingResultWithFileFromServlet obj = new SamplingResultWithFileFromServlet( + output, partialPathFile); + + return obj; + + } catch (Exception e) { + logger.error("dbmanager-> ", e); + if (!(e instanceof StatisticalManagerException)) { + // GWT can't serialize all exceptions + throw new Exception( + "Error in server while loading data. Exception: " + e); } + throw e; } - if ((elementType != null) - && (elementType.equals(ConstantsPortlet.DATABASE))) { - if ((rs == null) || (rs.equals(""))) { - throw new Exception("Unable to load data"); - } - if ((db == null) || (db.equals(""))) { - throw new Exception("Unable to load data"); - } - if ((tab == null) || (tab.equals(""))) { - throw new Exception("Unable to load data"); - } - } - - // set input parameters - Parameter resource = new Parameter("ResourceName", "", "String", ""); - Parameter database = new Parameter("DatabaseName", "", "String", ""); - Parameter schema = new Parameter("SchemaName", "", "String", ""); - Parameter table = new Parameter("TableName", "", "String", ""); - inputParameters.add(resource); - inputParameters.add(database); - inputParameters.add(schema); - inputParameters.add(table); - - inputParameters.get(0).setValue(rs); - inputParameters.get(1).setValue(db); - inputParameters.get(2).setValue(scm); - inputParameters.get(3).setValue(tab); - - // create data structure - ComputationOutput outputData = new ComputationOutput(); - // computation id - String computationId = startComputation(algorithmId, inputParameters, - outputData); - - // print check on retrieving data - // logger.info("dbmanager-> output data retrieved"); - - // data output values - LinkedHashMap mapValues = new LinkedHashMap(); - // data output keys - LinkedHashMap mapKeys = new LinkedHashMap(); - - mapValues = outputData.getMapValues(); - mapKeys = outputData.getmapKeys(); - - for (int i = 0; i < mapValues.size(); i++) { - Result row = new Result(mapKeys.get(String.valueOf(i)), - mapValues.get(String.valueOf(i))); - output.add(row); - } - - String name = "RandomSampling" + "_" + tab; - String fileName = storeResultIntoCSVFile(output, name); - - HttpServletRequest request = this.getThreadLocalRequest(); - String applicationPath = request.getContextPath(); - // logger.info("dbmanager-> Application Path: " + applicationPath); - String partialPathFile = applicationPath + "/computationResult/" - + fileName; - SamplingResultWithFileFromServlet obj = new SamplingResultWithFileFromServlet( - output, partialPathFile); - - return obj; } @Override public LinkedHashMap getTableDetails( LinkedHashMap dataInput) throws Exception { - - //session check - if(isSessionExpired()) - throw new SessionExpiredException(); - - // data input - List inputParameters = new ArrayList(); - // data ouptut - LinkedHashMap outputParameters = new LinkedHashMap(); - String algorithmId = "GETTABLEDETAILS"; + // session check + if (isSessionExpired()) + throw new SessionExpiredException(); - // print check - String rs = dataInput.get("ResourceName"); - String db = dataInput.get("DatabaseName"); - String scm = dataInput.get("SchemaName"); - String tab = dataInput.get("TableName"); + try { - // print check - logger.info("dbmanager-> ResourceName: " + rs); - logger.info("dbmanager-> DatabaseName: " + db); - logger.info("dbmanager-> SchemaName: " + scm); - logger.info("dbmanager-> TableName: " + tab); + // data input + List inputParameters = new ArrayList(); + // data ouptut + LinkedHashMap outputParameters = new LinkedHashMap(); - // set input parameters - Parameter resource = new Parameter("ResourceName", "", "String", ""); - Parameter database = new Parameter("DatabaseName", "", "String", ""); - Parameter schema = new Parameter("SchemaName", "", "String", ""); - Parameter table = new Parameter("TableName", "", "String", ""); - inputParameters.add(resource); - inputParameters.add(database); - inputParameters.add(schema); - inputParameters.add(table); + String algorithmId = "GETTABLEDETAILS"; - inputParameters.get(0).setValue(rs); - inputParameters.get(1).setValue(db); - inputParameters.get(2).setValue(scm); - inputParameters.get(3).setValue(tab); - - // create data structure - ComputationOutput outputData = new ComputationOutput(); - // computation id - String computationId = startComputation(algorithmId, inputParameters, - outputData); - - // print check on retrieving data - // logger.info("output data retrieved"); - - // output data values - LinkedHashMap mapValues = new LinkedHashMap(); - // output data keys - LinkedHashMap mapKeys = new LinkedHashMap(); - - mapValues = outputData.getMapValues(); - mapKeys = outputData.getmapKeys(); - - for (int i = 0; i < mapValues.size(); i++) { - FileModel obj = new FileModel(mapValues.get(String.valueOf(i))); - // obj.setIsLoaded(true); - outputParameters.put(mapKeys.get(String.valueOf(i)), obj); // print check - // logger.info("value: " + outputMap.get(String.valueOf(i))); - // logger.info("key: " + outputKey.get(String.valueOf(i))); - } + String rs = dataInput.get("ResourceName"); + String db = dataInput.get("DatabaseName"); + String scm = dataInput.get("SchemaName"); + String tab = dataInput.get("TableName"); - return outputParameters; + // print check + logger.info("dbmanager-> ResourceName: " + rs); + logger.info("dbmanager-> DatabaseName: " + db); + logger.info("dbmanager-> SchemaName: " + scm); + logger.info("dbmanager-> TableName: " + tab); + + // set input parameters + Parameter resource = new Parameter("ResourceName", "", "String", ""); + Parameter database = new Parameter("DatabaseName", "", "String", ""); + Parameter schema = new Parameter("SchemaName", "", "String", ""); + Parameter table = new Parameter("TableName", "", "String", ""); + inputParameters.add(resource); + inputParameters.add(database); + inputParameters.add(schema); + inputParameters.add(table); + + inputParameters.get(0).setValue(rs); + inputParameters.get(1).setValue(db); + inputParameters.get(2).setValue(scm); + inputParameters.get(3).setValue(tab); + + // create data structure + ComputationOutput outputData = new ComputationOutput(); + // computation id + String computationId = startComputation(algorithmId, + inputParameters, outputData); + + // print check on retrieving data + // logger.info("output data retrieved"); + + // output data values + LinkedHashMap mapValues = new LinkedHashMap(); + // output data keys + LinkedHashMap mapKeys = new LinkedHashMap(); + + mapValues = outputData.getMapValues(); + mapKeys = outputData.getmapKeys(); + + for (int i = 0; i < mapValues.size(); i++) { + FileModel obj = new FileModel(mapValues.get(String.valueOf(i))); + // obj.setIsLoaded(true); + outputParameters.put(mapKeys.get(String.valueOf(i)), obj); + // print check + // logger.info("value: " + outputMap.get(String.valueOf(i))); + // logger.info("key: " + outputKey.get(String.valueOf(i))); + } + + return outputParameters; + } catch (Exception e) { + logger.error("dbmanager-> ", e); + if (!(e instanceof StatisticalManagerException)) { + // GWT can't serialize all exceptions + throw new Exception( + "Error in server while loading data. Exception: " + e); + } + throw e; + } } // parse result for Submit query public PagingLoadResult loadSubmitResult(PagingLoadConfig config, List listAttributes, String UID) throws Exception { - - //session check - if(isSessionExpired()) - throw new SessionExpiredException(); - - // System.out.println("Server - loadSubmitResultMethod"); - // data parsed - List data = new ArrayList(); - // submit query result - List result = new ArrayList(); - // get parsed data - data = getSubmitQueryResultParsed(UID); - if ((data == null)) { - // parse the submit query result - result = getSubmitQueryResult(UID); + // session check + if (isSessionExpired()) + throw new SessionExpiredException(); - if ((result != null) && (result.size() != 0)) { - data = parseCVSString(result, listAttributes); - updateSubmitQueryResultParsed(UID, data); + try { + // System.out.println("Server - loadSubmitResultMethod"); + // data parsed + List data = new ArrayList(); + // submit query result + List result = new ArrayList(); + // get parsed data + data = getSubmitQueryResultParsed(UID); + + if ((data == null)) { + // parse the submit query result + result = getSubmitQueryResult(UID); + + if ((result != null) && (result.size() != 0)) { + data = parseCVSString(result, listAttributes); + updateSubmitQueryResultParsed(UID, data); + } } + + // Create a sublist and add data to list according + // to the limit and offset value of the config + List sublist = new ArrayList(); + BasePagingLoadResult loadResult = null; + + int start = config.getOffset(); + int limit = data.size(); + + if (config.getLimit() > 0) { + limit = Math.min(start + config.getLimit(), limit); + } + + int totalNumber = data.size(); + sublist = new ArrayList(data.subList(start, limit)); + loadResult = new BasePagingLoadResult(sublist, + config.getOffset(), totalNumber); + + // System.out.println("start: " + start); + // System.out.println("limit: " + limit); + // System.out.println("sublist size: " + sublist.size()); + + return loadResult; + } catch (Exception e) { + logger.error("dbmanager-> ", e); + throw new Exception( + "Error in server while loading data. Exception: " + e); + } - - // Create a sublist and add data to list according - // to the limit and offset value of the config - List sublist = new ArrayList(); - BasePagingLoadResult loadResult = null; - - int start = config.getOffset(); - int limit = data.size(); - - if (config.getLimit() > 0) { - limit = Math.min(start + config.getLimit(), limit); - } - - int totalNumber = data.size(); - sublist = new ArrayList(data.subList(start, limit)); - loadResult = new BasePagingLoadResult(sublist, config.getOffset(), - totalNumber); - - // System.out.println("start: " + start); - // System.out.println("limit: " + limit); - // System.out.println("sublist size: " + sublist.size()); - - return loadResult; } // get attributes list for display the result in a table @@ -1464,9 +1585,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements @Override public List parseCVSString(List result, List attrNames) throws Exception { - - //session check - if(isSessionExpired()) + + // session check + if (isSessionExpired()) throw new SessionExpiredException(); List rows = new ArrayList(); @@ -1794,7 +1915,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } catch (Exception e) { logger.info("dbmanager-> startComputation: the job submit has failed!"); // e.printStackTrace(); - logger.error("dbmanager-> ", e); +// logger.error("dbmanager-> ", e); throw e; } } @@ -1868,11 +1989,12 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // rootLogger.log(Level.SEVERE, "Output is other"); } - // EXCEPTION MANAGEMENT + // StatisticalManager EXCEPTION MANAGEMENT if (smResType.equals(SMResourceType.ERROR)) { - Exception e = new Exception(smResource.description()); + StatisticalManagerException e = new StatisticalManagerException( + smResource.description()); // e.printStackTrace(); - logger.error("dbmanager-> ", e); +// logger.error("dbmanager-> ", e); throw e; } } @@ -1963,62 +2085,72 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // remove the computation public Boolean removeComputation(String uidSubmitQuery) throws Exception { // System.out.println("server UID: " + uidSubmitQuery); - - //session check - if(isSessionExpired()) + + // session check + if (isSessionExpired()) throw new SessionExpiredException(); - - String computationId = null; - if ((uidSubmitQuery != null) && (!(uidSubmitQuery.equals("")))) { - // get job status - // ASLSession session = WsUtil.getAslSession(this - // .getThreadLocalRequest().getSession()); - // HashMap JobStatusMap = (HashMap) - // session - // .getAttribute("JobStatusList"); - // String status = JobStatusMap.get(uidSubmitQuery); - String status = getJobStatus(uidSubmitQuery); + try { + String computationId = null; - if (status == null) { - // the computation has not started - while (computationId == null) { + if ((uidSubmitQuery != null) && (!(uidSubmitQuery.equals("")))) { + // get job status + // ASLSession session = WsUtil.getAslSession(this + // .getThreadLocalRequest().getSession()); + // HashMap JobStatusMap = (HashMap) + // session + // .getAttribute("JobStatusList"); + // String status = JobStatusMap.get(uidSubmitQuery); + String status = getJobStatus(uidSubmitQuery); + + if (status == null) { + // the computation has not started + while (computationId == null) { + computationId = removeJob(uidSubmitQuery); + } + } else if (status.equals("computation started")) { + // System.out.println("check status: computation started"); + // the computation has started computationId = removeJob(uidSubmitQuery); } - } else if (status.equals("computation started")) { - // System.out.println("check status: computation started"); - // the computation has started - computationId = removeJob(uidSubmitQuery); } - } - if (computationId != null) { - StatisticalManagerFactory factory = getFactory(); - try { - factory.removeComputation(computationId); - // remove submit query result - refreshDataOnServer(uidSubmitQuery); - // System.out.println("computation removed"); - } catch (Exception e) { - e.printStackTrace(); + if (computationId != null) { + StatisticalManagerFactory factory = getFactory(); + try { + factory.removeComputation(computationId); + // remove submit query result + refreshDataOnServer(uidSubmitQuery); + // System.out.println("computation removed"); + } catch (Exception e) { + e.printStackTrace(); - logger.info("dbmanager-> Could not remove the computation ID " - + computationId + " corresponding to jobID " - + uidSubmitQuery); - logger.error("dbmanager-> ", e); + logger.info("dbmanager-> Could not remove the computation ID " + + computationId + + " corresponding to jobID " + + uidSubmitQuery); + logger.error("dbmanager-> ", e); + } } + // remove job status + removeJobStatus(uidSubmitQuery); + return (new Boolean(true)); + + } catch (Exception e) { + logger.error("dbmanager-> ", e); + throw new Exception( + "Error in server while loading data. Exception: " + e); + } - // remove job status - removeJobStatus(uidSubmitQuery); - return (new Boolean(true)); } - public void refreshDataOnServer(String submitQueryUID) throws Exception{ - - //session check - if(isSessionExpired()) + public void refreshDataOnServer(String submitQueryUID) throws Exception { + + // session check + if (isSessionExpired()) throw new SessionExpiredException(); - + if ((submitQueryUID != null) && (!submitQueryUID.equals(""))) { removeResultParsed(submitQueryUID); removeResult(submitQueryUID); @@ -2039,109 +2171,121 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements public GeneralOutputFromServlet refreshDataTree(String ElementType, LinkedHashMap inputData, FileModel element) throws Exception { - - //session check - if(isSessionExpired()) - throw new SessionExpiredException(); - // // call the method related to the element selected - // - String resourceName = ""; - String databaseName = ""; + // session check + if (isSessionExpired()) + throw new SessionExpiredException(); - GeneralOutputFromServlet result = null; + try { - if (inputData != null && inputData.size() != 0) { - // System.out.println("server-> input size not null"); - String key = ""; + // // call the method related to the element selected + // + String resourceName = ""; + String databaseName = ""; - if (!ElementType.equals("")) { - // System.out.println("server-> element type not null"); - switch (ElementType) { - case "listResources": - key = inputData.get("listResources"); - break; - case "resource": - key = inputData.get("ResourceName"); - break; - case "database": - if (element.getDatabaseType().equals( - ConstantsPortlet.POSTGRES)) { // refresh schema list - key = inputData.get("ResourceName") - + inputData.get("DatabaseName"); - } - if (element.getDatabaseType() - .equals(ConstantsPortlet.MYSQL)) { // refresh table - // list - key = inputData.get("ResourceName") - + inputData.get("DatabaseName") - + inputData.get("SchemaName"); - } - break; + GeneralOutputFromServlet result = null; - case "schema": - key = inputData.get("ResourceName") - + inputData.get("DatabaseName") - + inputData.get("SchemaName"); - break; - } - } - - // System.out.println("server->KEY: " + key); - net.sf.ehcache.Element dataFromCache = getDataFromCache(key); - - if (dataFromCache != null) { - // System.out.println("server-> data in cache with key: " + - // key); - refreshCache(key); - // System.out.println("server-> data removed from cache with key: " - // + key); + if (inputData != null && inputData.size() != 0) { + // System.out.println("server-> input size not null"); + String key = ""; if (!ElementType.equals("")) { // System.out.println("server-> element type not null"); switch (ElementType) { case "listResources": - List output1 = getResource(); - result = new GeneralOutputFromServlet(output1); - // System.out.println("server-> output generated"); + key = inputData.get("listResources"); break; case "resource": - resourceName = inputData.get("ResourceName"); - LinkedHashMap output2 = getDBInfo(resourceName); - result = new GeneralOutputFromServlet(output2); + key = inputData.get("ResourceName"); break; case "database": - if (element.getDatabaseType() != null - && (element.getDatabaseType() - .equals(ConstantsPortlet.POSTGRES))) { // refresh - // schema - // list - List output3 = getDBSchema(inputData); - result = new GeneralOutputFromServlet(output3); + if (element.getDatabaseType().equals( + ConstantsPortlet.POSTGRES)) { // refresh schema + // list + key = inputData.get("ResourceName") + + inputData.get("DatabaseName"); } - if (element.getDatabaseType() != null - && element.getDatabaseType().equals( - ConstantsPortlet.MYSQL)) { // refresh - // table - // list - getTables(inputData, ConstantsPortlet.DATABASE); - + if (element.getDatabaseType().equals( + ConstantsPortlet.MYSQL)) { // refresh table + // list + key = inputData.get("ResourceName") + + inputData.get("DatabaseName") + + inputData.get("SchemaName"); } - // resourceName = inputData.get("ResourceName"); - // databaseName = inputData.get("DatabaseName"); - break; case "schema": - getTables(inputData, ConstantsPortlet.SCHEMA); + key = inputData.get("ResourceName") + + inputData.get("DatabaseName") + + inputData.get("SchemaName"); break; } } - } + // System.out.println("server->KEY: " + key); + net.sf.ehcache.Element dataFromCache = getDataFromCache(key); + if (dataFromCache != null) { + // System.out.println("server-> data in cache with key: " + + // key); + refreshCache(key); + // System.out.println("server-> data removed from cache with key: " + // + key); + + if (!ElementType.equals("")) { + // System.out.println("server-> element type not null"); + switch (ElementType) { + case "listResources": + List output1 = getResource(); + result = new GeneralOutputFromServlet(output1); + // System.out.println("server-> output generated"); + break; + case "resource": + resourceName = inputData.get("ResourceName"); + LinkedHashMap output2 = getDBInfo(resourceName); + result = new GeneralOutputFromServlet(output2); + break; + case "database": + if (element.getDatabaseType() != null + && (element.getDatabaseType() + .equals(ConstantsPortlet.POSTGRES))) { // refresh + // schema + // list + List output3 = getDBSchema(inputData); + result = new GeneralOutputFromServlet(output3); + } + if (element.getDatabaseType() != null + && element.getDatabaseType().equals( + ConstantsPortlet.MYSQL)) { // refresh + // table + // list + getTables(inputData, ConstantsPortlet.DATABASE); + + } + // resourceName = inputData.get("ResourceName"); + // databaseName = inputData.get("DatabaseName"); + + break; + + case "schema": + getTables(inputData, ConstantsPortlet.SCHEMA); + break; + } + } + + } + + } + return result; + } catch (Exception e) { + logger.error("dbmanager-> ", e); + if (!(e instanceof StatisticalManagerException)) { + // GWT can't serialize all exceptions + throw new Exception( + "Error in server while loading data. Exception: " + e); + } + throw e; } - return result; } private synchronized void refreshCache(String key) throws Exception { @@ -2149,8 +2293,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements employeeCache.remove(key); } catch (Exception e) { // TODO: handle exception - logger.error("dbmanager-> ", e); - throw new Exception("Failure to clear the cache. " + e); +// logger.error("dbmanager-> ", e); + // throw new Exception("Failure to clear the cache. " + e); + throw new Exception( + "Error in server while loading data. Exception: " + e); } } @@ -2196,9 +2342,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements return fileName; } - - //to check if the session is expired + + // to check if the session is expired private boolean isSessionExpired() throws Exception { - return SessionUtil.isSessionExpired(this.getThreadLocalRequest().getSession()); + return SessionUtil.isSessionExpired(this.getThreadLocalRequest() + .getSession()); } } 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 f5912a1..addf3b2 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 @@ -53,13 +53,16 @@ public class SessionUtil { public static boolean isSessionExpired(HttpSession httpSession) throws Exception { logger.info("session validating..."); - //READING USERNAME FROM ASL SESSION + //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 diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/shared/SessionExpiredException.java b/src/main/java/org/gcube/portlets/user/databasesmanager/shared/SessionExpiredException.java index 57cd1f0..7499c5a 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/shared/SessionExpiredException.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/shared/SessionExpiredException.java @@ -1,7 +1,9 @@ package org.gcube.portlets.user.databasesmanager.shared; -public class SessionExpiredException extends Exception{ - +public class SessionExpiredException extends Exception { + + private static final long serialVersionUID = 1L; + public SessionExpiredException() { super("Session expired"); } diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/shared/StatisticalManagerException.java b/src/main/java/org/gcube/portlets/user/databasesmanager/shared/StatisticalManagerException.java new file mode 100644 index 0000000..e0cb400 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/shared/StatisticalManagerException.java @@ -0,0 +1,15 @@ +package org.gcube.portlets.user.databasesmanager.shared; + +public class StatisticalManagerException extends Exception{ + + private static final long serialVersionUID = 1L; + + public StatisticalManagerException(){ + super(); + } + + public StatisticalManagerException(String message){ + super(message); + } + +}