- caching on submitQuery requests added

- bug fixed in servlet in submitQuery method when a user clicks the cancel button and the map from statistical is already recovered
- private variable output renamed in class SubmitQueryResultWithFileFromServlet

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/databases-manager-portlet@100324 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Loredana Liccardo 2014-10-01 13:38:16 +00:00
parent 67dc075dcc
commit 8ffb77cfee
4 changed files with 663 additions and 334 deletions

View File

@ -9,29 +9,32 @@ public class SubmitQueryResultWithFileFromServlet extends BaseModelData
implements Serializable {
private static final long serialVersionUID = 1L;
private List<String> output;
private List<String> attributes;
private String convertedQuery;
private String fileName;
public SubmitQueryResultWithFileFromServlet() {
}
public SubmitQueryResultWithFileFromServlet(List<String> result, String query, String fileName) {
set("output", result);
public SubmitQueryResultWithFileFromServlet(List<String> attributes,
String query, String fileName) {
set("attributes", attributes);
set("convertedQuery", query);
set("fileName", fileName);
}
public List<String> getListOutput() {
return get("output");
return get("attributes");
}
public String getFileName() {
return get("fileName");
}
public String getConvertedQuery() {
return get("convertedQuery");
}
}

View File

@ -406,9 +406,10 @@ public class GxtBorderLayoutPanel extends ContentPanel {
public void onFailure(Throwable caught) {
rootLogger.log(Level.SEVERE,
"FAILURE RPC LoadTables");
if(caught instanceof SessionExpiredException){
rootLogger.log(Level.INFO, "Session expired");
if (caught instanceof SessionExpiredException) {
rootLogger.log(Level.INFO,
"Session expired");
CheckSession.showLogoutDialog();
return;
}
@ -445,18 +446,18 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// enable toolbar in the dialog
toolBarTop.enable();
// if (result != null) {
//
// List<Result> data = result.getData();
// if (data.size() == 0) {
// MessageBox
// .alert("Warning ",
// "<br/>Message:"
// + "no tables availables",
// null);
// return;
// }
// }
// if (result != null) {
//
// List<Result> data = result.getData();
// if (data.size() == 0) {
// MessageBox
// .alert("Warning ",
// "<br/>Message:"
// + "no tables availables",
// null);
// return;
// }
// }
}
});
@ -848,12 +849,12 @@ public class GxtBorderLayoutPanel extends ContentPanel {
rootLogger
.log(Level.SEVERE, "FAILURE RPC submitQuery ");
if(caught instanceof SessionExpiredException){
if (caught instanceof SessionExpiredException) {
rootLogger.log(Level.INFO, "Session expired");
CheckSession.showLogoutDialog();
return;
}
// Listener<MessageBoxEvent> l = new
// Listener<MessageBoxEvent>() {
// public void handleEvent(MessageBoxEvent ce) {
@ -909,6 +910,9 @@ public class GxtBorderLayoutPanel extends ContentPanel {
form.getButtonById(Dialog.OK).enable();
}
// if listAttributes is null the computation has
// been removed from the statisticalManager.In this
// case no message is displayed.
if (listAttributes == null) {
return;
}
@ -922,14 +926,14 @@ public class GxtBorderLayoutPanel extends ContentPanel {
+ "The query returned 0 values", null);
return;
}
String query = "";
if (dataQuery.getSmartCorrection()==false){
query = dataQuery.getQuery();
}else{
query = obj.getConvertedQuery();
}
String query = "";
if (dataQuery.getSmartCorrection() == false) {
query = dataQuery.getQuery();
} else {
query = obj.getConvertedQuery();
}
// if ((listAttributes == null)
// || (listAttributes.size() == 0)) {
//
@ -989,7 +993,8 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// start the parsing of the submit result in order to obtain a table
private void parseSubmitQueryResult(Dialog dialog, final int dialogID,
final List<String> listAttributes, String query, String fileName, final String UID) {
final List<String> listAttributes, String query, String fileName,
final String UID) {
final Dialog form = dialog;
// define the proxy and create the grid to display in the dialog
@ -1009,12 +1014,13 @@ public class GxtBorderLayoutPanel extends ContentPanel {
public void onFailure(Throwable caught) {
rootLogger.log(Level.SEVERE,
"FAILURE RPC loadSubmitQueryResult");
if(caught instanceof SessionExpiredException){
rootLogger.log(Level.INFO, "Session expired");
if (caught instanceof SessionExpiredException) {
rootLogger.log(Level.INFO,
"Session expired");
CheckSession.showLogoutDialog();
return;
}
}
Listener<MessageBoxEvent> l = new Listener<MessageBoxEvent>() {
public void handleEvent(MessageBoxEvent ce) {
@ -1151,7 +1157,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
}
};
// submitResult.setLayout(new FitLayout());
// submitResult.setLayout(new FitLayout());
submitResult.setHeading("Result Query " + dialogID);
submitResult.setResizable(false);
submitResult.setSize(600, 400);
@ -1159,23 +1165,24 @@ public class GxtBorderLayoutPanel extends ContentPanel {
submitResult.setHideOnButtonClick(true);
submitResult.setMaximizable(true);
submitResult.setMinimizable(true);
// submitResult.setBottomComponent(toolBar);
// submitResult.setBottomComponent(toolBar);
submitResult.setLayout(new RowLayout(Style.Orientation.VERTICAL));
//to add the panel of the converted query and the panel that display the query's result
ContentPanel q= new ContentPanel();
// to add the panel of the converted query and the panel that display
// the query's result
ContentPanel q = new ContentPanel();
q.setLayout(new FitLayout());
q.setHeaderVisible(false);
q.addText(query);
submitResult.add(q, new RowData(1, 0.3));
ContentPanel g = new ContentPanel();
g.setLayout(new FitLayout());
g.setHeaderVisible(false);
g.setBottomComponent(toolBar);
g.add(grid);
g.layout(true);
g.layout(true);
// mimimize event handled
submitResult.addListener(Events.Minimize, new Listener<WindowEvent>() {
@Override
@ -1204,12 +1211,12 @@ public class GxtBorderLayoutPanel extends ContentPanel {
public void onFailure(Throwable caught) {
rootLogger.log(Level.SEVERE,
"FAILURE RPC refreshDataOnServer");
if(caught instanceof SessionExpiredException){
if (caught instanceof SessionExpiredException) {
rootLogger.log(Level.INFO, "Session expired");
CheckSession.showLogoutDialog();
return;
}
}
}
@Override
@ -1233,8 +1240,8 @@ public class GxtBorderLayoutPanel extends ContentPanel {
}
});
submitResult.addButton(download);
// submitResult.add(grid);
submitResult.add(g,new RowData(1, 0.7));
// submitResult.add(grid);
submitResult.add(g, new RowData(1, 0.7));
submitResult.show();
}
@ -1256,7 +1263,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
FileModel resource;
String elementType;
if (selectedItem.isDatabase()) {
// the table has not a schema because the selected item is a
// database
@ -1272,7 +1279,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;
} else {
// the table has a schema because the selected item is a schema
@ -1289,7 +1296,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;
}
@ -1303,13 +1310,13 @@ public class GxtBorderLayoutPanel extends ContentPanel {
public void onFailure(Throwable caught) {
// Window.alert(caught.getMessage());
rootLogger.log(Level.SEVERE, "FAILURE RPC sample");
if(caught instanceof SessionExpiredException){
if (caught instanceof SessionExpiredException) {
rootLogger.log(Level.INFO, "Session expired");
CheckSession.showLogoutDialog();
return;
}
}
if (caught.getMessage()
.contains("Result not available")) {
MessageBox.alert("Warning ", "<br/>Message:"
@ -1324,12 +1331,14 @@ public class GxtBorderLayoutPanel extends ContentPanel {
}
@Override
public void onSuccess(SamplingResultWithFileFromServlet samplingResult) {
public void onSuccess(
SamplingResultWithFileFromServlet samplingResult) {
rootLogger.log(Level.SEVERE, "SUCCESS RPC sample");
if (samplingResult != null) {
// get data
List<Result> result = samplingResult.getListOutput();
List<Result> result = samplingResult
.getListOutput();
// get the attributes list for the result
// table
List<String> listAttributes = new ArrayList<String>();
@ -1347,14 +1356,14 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// table
parseResult(result, listAttributes, fileName);
} else{
MessageBox.alert("Error ",
"<br/>Message: " + "no data available", null);
} else {
MessageBox.alert("Error ", "<br/>Message: "
+ "no data available", null);
if (obj.isMasked()) {
obj.unmask();
}
}
}
@ -1411,9 +1420,9 @@ public class GxtBorderLayoutPanel extends ContentPanel {
FileModel schema;
FileModel database;
FileModel resource;
String elementType;
if (selectedItem.isDatabase()) {
// the table has not a schema
database = selectedItem;
@ -1428,7 +1437,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 = ConstantsPortlet.DATABASE;
} else {
// the table has a schema
schema = selectedItem;
@ -1444,7 +1453,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 = ConstantsPortlet.SCHEMA;
}
// to mask the entire content panel
obj.mask("Sampling the table", "x-mask-loading");
@ -1456,12 +1465,12 @@ public class GxtBorderLayoutPanel extends ContentPanel {
public void onFailure(Throwable caught) {
// Window.alert(caught.getMessage());
rootLogger.log(Level.SEVERE, "FAILURE RPC smartSample");
if(caught instanceof SessionExpiredException){
if (caught instanceof SessionExpiredException) {
rootLogger.log(Level.INFO, "Session expired");
CheckSession.showLogoutDialog();
return;
}
}
if (caught.getMessage()
.contains("The table has 0 rows")) {
MessageBox.alert("Warning ", "<br/>Message:"
@ -1476,12 +1485,14 @@ public class GxtBorderLayoutPanel extends ContentPanel {
}
@Override
public void onSuccess(SamplingResultWithFileFromServlet samplingResult) {
public void onSuccess(
SamplingResultWithFileFromServlet samplingResult) {
rootLogger.log(Level.SEVERE, "SUCCESS RPC smartSample");
if (samplingResult != null) {
// get data
List<Result> result = samplingResult.getListOutput();
List<Result> result = samplingResult
.getListOutput();
// get the attributes list for the result
// table
List<String> listAttributes = new ArrayList<String>();
@ -1497,14 +1508,14 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// parse the result in order to obtain a
// table
parseResult(result, listAttributes, fileName);
}else{
MessageBox.alert("Error ",
"<br/>Message: " + "no data available", null);
} else {
MessageBox.alert("Error ", "<br/>Message: "
+ "no data available", null);
if (obj.isMasked()) {
obj.unmask();
}
}
}
});
@ -1528,7 +1539,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
FileModel resource;
String elementType;
if (selectedItem.isDatabase()) {
// the table has not a schema
database = selectedItem;
@ -1573,13 +1584,13 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// Window.alert(caught.getMessage());
rootLogger
.log(Level.SEVERE, "FAILURE RPC randomSample");
if(caught instanceof SessionExpiredException){
if (caught instanceof SessionExpiredException) {
rootLogger.log(Level.INFO, "Session expired");
CheckSession.showLogoutDialog();
return;
}
}
if (caught.getMessage()
.contains("Result not available")) {
MessageBox.alert("Warning ", "<br/>Message:"
@ -1594,13 +1605,15 @@ public class GxtBorderLayoutPanel extends ContentPanel {
}
@Override
public void onSuccess(SamplingResultWithFileFromServlet samplingResult) {
public void onSuccess(
SamplingResultWithFileFromServlet samplingResult) {
rootLogger
.log(Level.SEVERE, "SUCCESS RPC randomSample");
if (samplingResult != null) {
// get data
List<Result> result = samplingResult.getListOutput();
List<Result> result = samplingResult
.getListOutput();
// get the attributes list for the result
// table
List<String> listAttributes = new ArrayList<String>();
@ -1616,14 +1629,14 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// parse the result in order to obtain a
// table
parseResult(result, listAttributes, fileName);
} else{
MessageBox.alert("Error ",
"<br/>Message: " + "no data available", null);
} else {
MessageBox.alert("Error ", "<br/>Message: "
+ "no data available", null);
if (obj.isMasked()) {
obj.unmask();
}
}
}
});
@ -1642,13 +1655,13 @@ public class GxtBorderLayoutPanel extends ContentPanel {
public void onFailure(Throwable caught) {
// Window.alert(caught.getMessage());
rootLogger.log(Level.SEVERE, "FAILURE RPC parseResult");
if(caught instanceof SessionExpiredException){
if (caught instanceof SessionExpiredException) {
rootLogger.log(Level.INFO, "Session expired");
CheckSession.showLogoutDialog();
return;
}
}
MessageBox.alert("Error ",
"<br/>Message:" + caught.getMessage(), null);
@ -1999,13 +2012,13 @@ public class GxtBorderLayoutPanel extends ContentPanel {
public void onFailure(Throwable caught) {
rootLogger.log(Level.SEVERE,
"FAILURE RPC getTableDetails");
if(caught instanceof SessionExpiredException){
if (caught instanceof SessionExpiredException) {
rootLogger.log(Level.INFO, "Session expired");
CheckSession.showLogoutDialog();
return;
}
MessageBox.alert("Error ",
"<br/>Message:" + caught.getMessage(), null);

View File

@ -192,7 +192,7 @@ public class GxtToolbarFunctionality {
FileModel tableInfo = selectedTableEvent.getTableInfo();
setInfoOnSelectedTable(tableName, tableInfo);
isTableSelected = true;
// rootLogger.info("table clicked: " + isTableSelected);
// rootLogger.info("table clicked: " + isTableSelected);
}
});
@ -204,7 +204,7 @@ public class GxtToolbarFunctionality {
SelectedItemEvent selectedItemEvent) {
isTableSelected = false;
// rootLogger.info("item clicked: " + isTableSelected);
// rootLogger.info("item clicked: " + isTableSelected);
}
@ -334,6 +334,10 @@ public class GxtToolbarFunctionality {
"computation removed with uid: "
+ uidSubmitQueryList
.get(dialogID));
} else {
rootLogger
.log(Level.INFO,
"computation can not be removed because it is already finished");
}
}
@ -343,13 +347,16 @@ public class GxtToolbarFunctionality {
rootLogger
.log(Level.SEVERE,
"FAILURE RPC removeComputation");
if(caught instanceof SessionExpiredException){
rootLogger.log(Level.INFO, "Session expired");
CheckSession.showLogoutDialog();
if (caught instanceof SessionExpiredException) {
rootLogger
.log(Level.INFO,
"Session expired");
CheckSession
.showLogoutDialog();
return;
}
}
}
});
}
@ -535,13 +542,12 @@ public class GxtToolbarFunctionality {
// data = form.getSubmitQueryData();
String query = data.getQuery();
Listener<MessageBoxEvent> l = new
Listener<MessageBoxEvent>() {
public void handleEvent(MessageBoxEvent ce) {
SubmtQueryDialog.getButtonById(Dialog.OK).enable();
Listener<MessageBoxEvent> l = new Listener<MessageBoxEvent>() {
public void handleEvent(MessageBoxEvent ce) {
SubmtQueryDialog.getButtonById(Dialog.OK).enable();
}
};
};
if ((query == null) || (query.equals(""))) {
MessageBox.alert("Warning", "Query field null", l);
@ -601,7 +607,7 @@ public class GxtToolbarFunctionality {
// query = String.format(queryForSubmitOperation, tableName);
query = "select * from " + tableName + " limit 10";
// System.out.println("query mysql: " + query);
// System.out.println("query mysql: " + query);
}
}
if (tableInfo.isSchema()) { // database postgres
@ -610,7 +616,7 @@ public class GxtToolbarFunctionality {
String tableName = schemaName + "." + "\"" + selectedTable + "\"";
// query = String.format(queryForSubmitOperation, tableName);
query = "select * from " + tableName + " limit 10";
// System.out.println("query postgres: " + query);
// System.out.println("query postgres: " + query);
}
return query;

View File

@ -5,13 +5,10 @@ import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
@ -21,11 +18,8 @@ import java.io.FileOutputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import net.didion.jwnl.data.Exc;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.config.CacheConfiguration;
import net.sf.ehcache.config.MemoryUnit;
import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
@ -70,7 +64,6 @@ 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;
import com.extjs.gxt.ui.client.data.PagingLoadResult;
@ -244,14 +237,17 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// List<Result> result = new ArrayList<Result>();
// session.setAttribute("TablesResult", result);
// map that contains the submit query result and the related uid
HashMap<String, List<Result>> submitQueryResult = new HashMap<String, List<Result>>();
session.setAttribute("submitQueryResult", submitQueryResult);
// // map that contains the submit query result and the related uid
// HashMap<String, List<Result>> submitQueryResult = new HashMap<String,
// List<Result>>();
// session.setAttribute("submitQueryResult", submitQueryResult);
// map that contains the submit query result parsed and the related
// uid
HashMap<String, List<Row>> submitQueryResultParsed = new HashMap<String, List<Row>>();
session.setAttribute("submitQueryResultParsed", submitQueryResultParsed);
// // map that contains the submit query result parsed and the related
// // uid
// HashMap<String, List<Row>> submitQueryResultParsed = new
// HashMap<String, List<Row>>();
// session.setAttribute("submitQueryResultParsed",
// submitQueryResultParsed);
// information about a database
// String currentDB = "";
@ -272,6 +268,27 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// Hashmap that contains the job status with a uid key
HashMap<String, String> JobStatusMap = new HashMap<String, String>();
session.setAttribute("JobStatusList", JobStatusMap);
// map that keeps track if a uid submitQuery request uses cached data
// and it does not start a computation
HashMap<String, Boolean> listSubmitQueryUIDCachedData = new HashMap<String, Boolean>();
session.setAttribute("listSubmitQueryUIDCachedData",
listSubmitQueryUIDCachedData);
// maps that contain key to retrieve data from cache for each uid
// submitQuery request
// map that stores information to send result of the rpc loadsubmitQuery
// to the client
HashMap<String, String> listKeySubmitQueryResult = new HashMap<String, String>();
session.setAttribute("listKeySubmitQueryResult",
listKeySubmitQueryResult);
// TODO DA CANCELLARE
// // map that stores information to send result of the rpc submitQuery
// to
// // the client
// HashMap<String, String> listKeyData = new HashMap<String, String>();
// session.setAttribute("listKeyData", listKeyData);
}
// to get resources from IS
@ -907,7 +924,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// data output
// List<Result> output = new ArrayList<Result>();
List<Result> output = null;
SubmitQueryResultWithFileFromServlet result = null;
// list that contains table attributes
List<String> listAttributes = null;
@ -964,78 +981,172 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
inputParameters.get(4).setValue(language);
inputParameters.get(5).setValue(query);
// create data structure
ComputationOutput outputData = new ComputationOutput();
// get data from cache
// check if data exist considering as key the input parameters
// computation id
String computationId = startComputation(algorithmId,
inputParameters, outputData, UID);
// parse the query in order to remove spaces
String queryParsed = parseQuery(inputParameters.get(5).getValue());
// get data sent to client calling the submitQuery
String keyData = inputParameters.get(0).getValue()
+ inputParameters.get(1).getValue()
+ inputParameters.get(2).getValue()
+ inputParameters.get(3).getValue()
+ inputParameters.get(4).getValue() + queryParsed;
// get JobID
if (checkJob(UID)) {
// computationIDMap.put(id, computationId);
// System.out.println("KEY:" + keyData);
// System.out.println("UID:" + UID);
// store key
// updateListKeyData(UID, keyData);
net.sf.ehcache.Element dataFromCache = getDataFromCache(keyData);
// print check on retrieving data
// logger.info("output data retrieved");
// key to get query result sent to client calling loadSubmitResult
String keySubmitQueryResult = keyData + "_SubmitQueryResult";
updateListKeySubmitQueryResult(UID, keySubmitQueryResult);
net.sf.ehcache.Element submitQueryResultFromCache = getDataFromCache(keySubmitQueryResult);
// data output values
LinkedHashMap<String, String> mapValues = new LinkedHashMap<String, String>();
// data output keys
LinkedHashMap<String, String> mapKeys = new LinkedHashMap<String, String>();
Object data = null;
Object submitQueryResult = null;
mapValues = outputData.getMapValues();
mapKeys = outputData.getmapKeys();
if ((dataFromCache != null) && (submitQueryResultFromCache != null)) {
data = dataFromCache.getObjectValue();
submitQueryResult = submitQueryResultFromCache.getObjectValue();
// System.out.println("***GETTING DATA FROM CACHE");
}
if ((data != null) && (submitQueryResult != null)) {
result = (SubmitQueryResultWithFileFromServlet) data;
if (mapValues.size() != 0) {
output = new ArrayList<Result>();
// set variable to true value if cached data are used and a
// computation is not started
Boolean val = new Boolean(true);
updateListSubmitQueryUIDCachedData(UID, val);
// logger.info("build the result - started");
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);
}
// System.out.println("output size submit: " +
// output.size());
// logger.info("build the result - finished");
// get the converted query
if (smartCorrectionQuery == true) {
convertedQuery = output.get(0).getValue();
output.remove(0);
}
// get the attributes list for the result table
listAttributes = new ArrayList<String>();
listAttributes = getListAttributes(output.get(0).getValue());
// remove the header in order to parse only the result
output.remove(0);
// store the result of the submit query operation
updateSubmitQueryResultMap(UID, output);
// remove job with the specified uid
removeJob(UID);
}
} else {
listAttributes = null;
// set variable to false value if cached data are not used and a
// computation is started
Boolean val = new Boolean(false);
updateListSubmitQueryUIDCachedData(UID, val);
// create data structure
ComputationOutput outputData = new ComputationOutput();
// computation id
String computationId = startComputation(algorithmId,
inputParameters, outputData, UID);
// get JobID
if (checkJob(UID)) { // if the computation has not been removed
// the job uid is present
// computationIDMap.put(id, computationId);
// print check on retrieving data
logger.info("output data retrieved");
// data output values
LinkedHashMap<String, String> mapValues = new LinkedHashMap<String, String>();
// data output keys
LinkedHashMap<String, String> mapKeys = new LinkedHashMap<String, String>();
mapValues = outputData.getMapValues();
mapKeys = outputData.getmapKeys();
if (mapValues.size() != 0) {
output = new ArrayList<Result>();
// logger.info("build the result - started");
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);
}
// System.out.println("output size submit: " +
// output.size());
// logger.info("build the result - finished");
// get the converted query
if (smartCorrectionQuery == true) {
convertedQuery = output.get(0).getValue();
output.remove(0);
}
// get the attributes list for the result table
listAttributes = new ArrayList<String>();
listAttributes = getListAttributes(output.get(0)
.getValue());
if (listAttributes == null) {
logger.error("dbmanager-> Error in server while loading data. variable listAttributes null");
throw new Exception(
"Error in server while loading data.");
}
// remove the header in order to parse only the result
output.remove(0);
// store the result of the submit query operation
// updateSubmitQueryResultMap(UID, output);
// remove job with the specified uid
removeJob(UID);
// 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;
result = new SubmitQueryResultWithFileFromServlet(
listAttributes, convertedQuery, partialPathFile);
// put the two data in cache
net.sf.ehcache.Element dataToCache = new net.sf.ehcache.Element(
keyData, result);
insertDataIntoCache(dataToCache);
net.sf.ehcache.Element submitQueryResultToCache = new net.sf.ehcache.Element(
keySubmitQueryResult, output);
insertDataIntoCache(submitQueryResultToCache);
}
} else { // if the computation has been removed the job uid is
// not present and listAttributes is null.
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;
//
// result = new SubmitQueryResultWithFileFromServlet(
// listAttributes, convertedQuery, partialPathFile);
//
// // put teh two data in cache
// net.sf.ehcache.Element dataToCache = new
// net.sf.ehcache.Element(
// keyData, result);
// insertDataIntoCache(dataToCache);
//
// net.sf.ehcache.Element submitQueryResultToCache = new
// net.sf.ehcache.Element(
// keySubmitQueryResult, output);
// insertDataIntoCache(submitQueryResultToCache);
}
// 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 result = new SubmitQueryResultWithFileFromServlet(
listAttributes, convertedQuery, partialPathFile);
return result;
} catch (Exception e) {
@ -1056,6 +1167,14 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
}
throw e;
} finally {
// remove the element related to the uid submitQuery request if
// present
removeSubmitQueryUIDCachedData(UID);
// remove jobStatus
removeJobStatus(UID);
// remove job
removeJob(UID);
}
}
@ -1566,44 +1685,97 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
throw new SessionExpiredException();
try {
// System.out.println("Server - loadSubmitResultMethod");
// data parsed
List<Row> data = new ArrayList<Row>();
// submit query result
List<Result> result = new ArrayList<Result>();
// 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<Row> sublist = new ArrayList<Row>();
BasePagingLoadResult loadResult = null;
int start = config.getOffset();
int limit = data.size();
// data parsed
List<Row> data = new ArrayList<Row>();
// submit query result
List<Result> result = new ArrayList<Result>();
// get the key to retrieve the submitQuery result
String key = getKeySubmitQueryResult(UID);
if (config.getLimit() > 0) {
limit = Math.min(start + config.getLimit(), limit);
if ((key != null) && (!key.equals(""))) {
// load data
// get data from cache
net.sf.ehcache.Element dataFromCache = getDataFromCache(key);
Object value = null;
if (dataFromCache != null) {
value = dataFromCache.getObjectValue();
}
if (value != null) {
result = (List<Result>) value;
data = parseCVSString(result, listAttributes);
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<Row>(data.subList(start, limit));
loadResult = new BasePagingLoadResult<Row>(sublist,
config.getOffset(), totalNumber);
// System.out.println("start: " + start);
// System.out.println("limit: " + limit);
// System.out.println("sublist size: " + sublist.size());
} else {
logger.error("dbmanager-> Error in server while loading data. variable value null");
throw new Exception("Error in server while loading data.");
}
} else {
logger.error("dbmanager-> Error in server while loading data. key null");
throw new Exception("Error in server while loading data.");
}
int totalNumber = data.size();
sublist = new ArrayList<Row>(data.subList(start, limit));
loadResult = new BasePagingLoadResult<Row>(sublist,
config.getOffset(), totalNumber);
// // System.out.println("Server - loadSubmitResultMethod");
// // data parsed
// List<Row> data = new ArrayList<Row>();
// // submit query result
// List<Result> result = new ArrayList<Result>();
// // 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);
// }
// }
// System.out.println("start: " + start);
// System.out.println("limit: " + limit);
// System.out.println("sublist size: " + sublist.size());
// // Create a sublist and add data to list according
// // to the limit and offset value of the config
// List<Row> sublist = new ArrayList<Row>();
// 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<Row>(data.subList(start, limit));
// loadResult = new BasePagingLoadResult<Row>(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) {
@ -1766,85 +1938,93 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// return params;
// }
private synchronized List<Result> getSubmitQueryResult(String submitQueryUID) {
ASLSession session = SessionUtil.getAslSession(this
.getThreadLocalRequest().getSession());
HashMap<String, List<Result>> submitQueryResult = (HashMap<String, List<Result>>) session
.getAttribute("submitQueryResult");
if (submitQueryResult.containsKey(submitQueryUID)) {
return submitQueryResult.get(submitQueryUID);
} else {
return null;
}
}
// private synchronized List<Result> getSubmitQueryResult(String
// submitQueryUID) {
// ASLSession session = SessionUtil.getAslSession(this
// .getThreadLocalRequest().getSession());
// HashMap<String, List<Result>> submitQueryResult = (HashMap<String,
// List<Result>>) session
// .getAttribute("submitQueryResult");
// if (submitQueryResult.containsKey(submitQueryUID)) {
// return submitQueryResult.get(submitQueryUID);
// } else {
// return null;
// }
// }
private synchronized List<Row> getSubmitQueryResultParsed(
String submitQueryUID) {
ASLSession session = SessionUtil.getAslSession(this
.getThreadLocalRequest().getSession());
HashMap<String, List<Row>> submitQueryResultParsed = (HashMap<String, List<Row>>) session
.getAttribute("submitQueryResultParsed");
// private synchronized List<Row> getSubmitQueryResultParsed(
// String submitQueryUID) {
// ASLSession session = SessionUtil.getAslSession(this
// .getThreadLocalRequest().getSession());
// HashMap<String, List<Row>> submitQueryResultParsed = (HashMap<String,
// List<Row>>) session
// .getAttribute("submitQueryResultParsed");
//
// if (submitQueryResultParsed.containsKey(submitQueryUID)) {
// // System.out.println("ResultParsed: UID contained");
// return submitQueryResultParsed.get(submitQueryUID);
// } else {
// return null;
// }
// }
if (submitQueryResultParsed.containsKey(submitQueryUID)) {
// System.out.println("ResultParsed: UID contained");
return submitQueryResultParsed.get(submitQueryUID);
} else {
return null;
}
}
// private synchronized void updateSubmitQueryResultParsed(
// String submitQueryUID, List<Row> data) {
// ASLSession session = SessionUtil.getAslSession(this
// .getThreadLocalRequest().getSession());
// HashMap<String, List<Row>> submitQueryResultParsed = (HashMap<String,
// List<Row>>) session
// .getAttribute("submitQueryResultParsed");
// // add data
// if (data.size() != 0) {
// submitQueryResultParsed.put(submitQueryUID, data);
// session.setAttribute("submitQueryResultParsed",
// submitQueryResultParsed);
// }
// }
private synchronized void updateSubmitQueryResultParsed(
String submitQueryUID, List<Row> data) {
ASLSession session = SessionUtil.getAslSession(this
.getThreadLocalRequest().getSession());
HashMap<String, List<Row>> submitQueryResultParsed = (HashMap<String, List<Row>>) session
.getAttribute("submitQueryResultParsed");
// add data
if (data.size() != 0) {
submitQueryResultParsed.put(submitQueryUID, data);
session.setAttribute("submitQueryResultParsed",
submitQueryResultParsed);
}
}
// private synchronized void removeResultParsed(String submitQueryUID) {
// ASLSession session = SessionUtil.getAslSession(this
// .getThreadLocalRequest().getSession());
// HashMap<String, List<Row>> submitQueryResultParsed = (HashMap<String,
// List<Row>>) session
// .getAttribute("submitQueryResultParsed");
// if (submitQueryResultParsed.containsKey(submitQueryUID)) {
// // remove data parsed
// submitQueryResultParsed.remove(submitQueryUID);
// // update
// session.setAttribute("submitQueryResultParsed",
// submitQueryResultParsed);
// }
// }
private synchronized void removeResultParsed(String submitQueryUID) {
ASLSession session = SessionUtil.getAslSession(this
.getThreadLocalRequest().getSession());
HashMap<String, List<Row>> submitQueryResultParsed = (HashMap<String, List<Row>>) session
.getAttribute("submitQueryResultParsed");
if (submitQueryResultParsed.containsKey(submitQueryUID)) {
// remove data parsed
submitQueryResultParsed.remove(submitQueryUID);
// update
session.setAttribute("submitQueryResultParsed",
submitQueryResultParsed);
}
}
// private synchronized void updateSubmitQueryResultMap(String
// submitQueryUID,
// List<Result> result) {
// if (submitQueryUID != null) {
// ASLSession session = SessionUtil.getAslSession(this
// .getThreadLocalRequest().getSession());
// HashMap<String, List<Result>> submitQueryResult = (HashMap<String,
// List<Result>>) session
// .getAttribute("submitQueryResult");
// submitQueryResult.put(submitQueryUID, result);
// session.setAttribute("submitQueryResult", submitQueryResult);
// }
// }
private synchronized void updateSubmitQueryResultMap(String submitQueryUID,
List<Result> result) {
if (submitQueryUID != null) {
ASLSession session = SessionUtil.getAslSession(this
.getThreadLocalRequest().getSession());
HashMap<String, List<Result>> submitQueryResult = (HashMap<String, List<Result>>) session
.getAttribute("submitQueryResult");
submitQueryResult.put(submitQueryUID, result);
session.setAttribute("submitQueryResult", submitQueryResult);
}
}
private synchronized void removeResult(String submitQueryUID) {
ASLSession session = SessionUtil.getAslSession(this
.getThreadLocalRequest().getSession());
HashMap<String, List<Result>> submitQueryResult = (HashMap<String, List<Result>>) session
.getAttribute("submitQueryResult");
if (submitQueryResult.containsKey(submitQueryUID)) {
// remove data parsed
submitQueryResult.remove(submitQueryUID);
// update
session.setAttribute("submitQueryResult", submitQueryResult);
}
}
// private synchronized void removeResult(String submitQueryUID) {
// ASLSession session = SessionUtil.getAslSession(this
// .getThreadLocalRequest().getSession());
// HashMap<String, List<Result>> submitQueryResult = (HashMap<String,
// List<Result>>) session
// .getAttribute("submitQueryResult");
// if (submitQueryResult.containsKey(submitQueryUID)) {
// // remove data parsed
// submitQueryResult.remove(submitQueryUID);
// // update
// session.setAttribute("submitQueryResult", submitQueryResult);
// }
// }
// update job with the related status
private synchronized void updateJobStatus(String jobID, String status) {
@ -1931,6 +2111,90 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
return isContained;
}
private synchronized void updateListSubmitQueryUIDCachedData(String UID,
Boolean value) {
ASLSession session = SessionUtil.getAslSession(this
.getThreadLocalRequest().getSession());
HashMap<String, Boolean> listSubmitQueryUIDCachedData = (HashMap<String, Boolean>) session
.getAttribute("listSubmitQueryUIDCachedData");
listSubmitQueryUIDCachedData.put(UID, value);
session.setAttribute("listSubmitQueryUIDCachedData",
listSubmitQueryUIDCachedData);
}
private synchronized Boolean checkSubmitQueryUIDCachedData(String UID) {
ASLSession session = SessionUtil.getAslSession(this
.getThreadLocalRequest().getSession());
HashMap<String, Boolean> listSubmitQueryUIDCachedData = (HashMap<String, Boolean>) session
.getAttribute("listSubmitQueryUIDCachedData");
return listSubmitQueryUIDCachedData.get(UID);
}
private synchronized void removeSubmitQueryUIDCachedData(String UID) {
ASLSession session = SessionUtil.getAslSession(this
.getThreadLocalRequest().getSession());
HashMap<String, Boolean> listSubmitQueryUIDCachedData = (HashMap<String, Boolean>) session
.getAttribute("listSubmitQueryUIDCachedData");
if (listSubmitQueryUIDCachedData.containsKey(UID)) {
listSubmitQueryUIDCachedData.remove(UID);
session.setAttribute("listSubmitQueryUIDCachedData",
listSubmitQueryUIDCachedData);
}
}
private synchronized void removeKeySubmitQueryResult(String UID) {
ASLSession session = SessionUtil.getAslSession(this
.getThreadLocalRequest().getSession());
HashMap<String, String> listKeySubmitQueryResult = (HashMap<String, String>) session
.getAttribute("listKeySubmitQueryResult");
if (listKeySubmitQueryResult.containsKey(UID)) {
listKeySubmitQueryResult.remove(UID);
session.setAttribute("listKeySubmitQueryResult",
listKeySubmitQueryResult);
}
}
// TODO CANCELLARE METDODO
// private synchronized void updateListKeyData(String UID, String value) {
// ASLSession session = SessionUtil.getAslSession(this
// .getThreadLocalRequest().getSession());
//
// HashMap<String, String> listKeyData = (HashMap<String, String>) session
// .getAttribute("listKeyData");
// listKeyData.put(UID, value);
// session.setAttribute("listKeyData", listKeyData);
//
// }
private synchronized void updateListKeySubmitQueryResult(String UID,
String value) {
ASLSession session = SessionUtil.getAslSession(this
.getThreadLocalRequest().getSession());
HashMap<String, String> listKeySubmitQueryResult = (HashMap<String, String>) session
.getAttribute("listKeySubmitQueryResult");
listKeySubmitQueryResult.put(UID, value);
session.setAttribute("listKeySubmitQueryResult",
listKeySubmitQueryResult);
}
private synchronized String getKeySubmitQueryResult(String UID) {
ASLSession session = SessionUtil.getAslSession(this
.getThreadLocalRequest().getSession());
HashMap<String, String> listKeySubmitQueryResult = (HashMap<String, String>) session
.getAttribute("listKeySubmitQueryResult");
return listKeySubmitQueryResult.get(UID);
}
private String startComputation(String algorithmName,
List<Parameter> parameters, ComputationOutput outputData)
throws Exception {
@ -2155,51 +2419,71 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
throw new SessionExpiredException();
try {
String computationId = null;
if ((uidSubmitQuery != null) && (!(uidSubmitQuery.equals("")))) {
// get job status
// ASLSession session = WsUtil.getAslSession(this
// .getThreadLocalRequest().getSession());
// HashMap<String, String> JobStatusMap = (HashMap<String,
// String>)
// session
// .getAttribute("JobStatusList");
// String status = JobStatusMap.get(uidSubmitQuery);
String status = getJobStatus(uidSubmitQuery);
Boolean isComputationRemoved = false;
// verify if this uid submitQuery request uses data in cache
Boolean value = checkSubmitQueryUIDCachedData(uidSubmitQuery);
if (status == null) {
// the computation has not started
while (computationId == null) {
computationId = removeJob(uidSubmitQuery);
if (value != null) {
// System.out.println("For uid " + uidSubmitQuery
// + " data are cached? " + value.booleanValue());
if (!value.booleanValue()) {
// remove computation
String computationId = null;
if ((uidSubmitQuery != null)
&& (!(uidSubmitQuery.equals("")))) {
// get job status
// ASLSession session = WsUtil.getAslSession(this
// .getThreadLocalRequest().getSession());
// HashMap<String, String> JobStatusMap =
// (HashMap<String,
// String>)
// 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");
isComputationRemoved = true;
} catch (Exception e) {
e.printStackTrace();
logger.info("dbmanager-> Could not remove the computation ID "
+ computationId
+ " corresponding to jobID "
+ uidSubmitQuery);
logger.error("dbmanager-> ", e);
}
}
// // remove job status
// removeJobStatus(uidSubmitQuery);
// //remove the element related to the uid submitQuery
// request
// removeSubmitQueryUIDCachedData(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();
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));
return isComputationRemoved;
} catch (Exception e) {
logger.error("dbmanager-> ", e);
@ -2207,6 +2491,14 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
"Error in server while loading data. Exception: " + e);
}
// finally {
// // remove the element related to the uid submitQuery request
// removeSubmitQueryUIDCachedData(uidSubmitQuery);
// // remove job status
// System.out.println("remove job status");
// removeJobStatus(uidSubmitQuery);
// removeJob(uidSubmitQuery);
// }
}
public void refreshDataOnServer(String submitQueryUID) throws Exception {
@ -2216,8 +2508,11 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
throw new SessionExpiredException();
if ((submitQueryUID != null) && (!submitQueryUID.equals(""))) {
removeResultParsed(submitQueryUID);
removeResult(submitQueryUID);
// removeResultParsed(submitQueryUID);
// removeResult(submitQueryUID);
// removeSubmitQueryUIDCachedData(submitQueryUID);
removeKeySubmitQueryResult(submitQueryUID);
// System.out.println("data refreshed on server");
}
}
@ -2367,6 +2662,11 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
private String storeResultIntoCSVFile(List<Result> result, String n)
throws Exception {
if (result == null) {
logger.info("Error in server while loading data. object result null");
throw new Exception("Error in server while loading data");
}
// file that will contain result
BufferedWriter out = null;
@ -2413,5 +2713,12 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
.getSession());
}
private String parseQuery(String query) {
String queryParsed;
queryParsed = query.trim();
queryParsed = queryParsed.replaceAll(" +", " ");
return queryParsed;
}
}