- 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:
parent
67dc075dcc
commit
8ffb77cfee
|
@ -9,21 +9,24 @@ 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() {
|
||||
|
|
|
@ -408,7 +408,8 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
"FAILURE RPC LoadTables");
|
||||
|
||||
if (caught instanceof SessionExpiredException) {
|
||||
rootLogger.log(Level.INFO, "Session expired");
|
||||
rootLogger.log(Level.INFO,
|
||||
"Session expired");
|
||||
CheckSession.showLogoutDialog();
|
||||
return;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -1011,7 +1016,8 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
"FAILURE RPC loadSubmitQueryResult");
|
||||
|
||||
if (caught instanceof SessionExpiredException) {
|
||||
rootLogger.log(Level.INFO, "Session expired");
|
||||
rootLogger.log(Level.INFO,
|
||||
"Session expired");
|
||||
CheckSession.showLogoutDialog();
|
||||
return;
|
||||
}
|
||||
|
@ -1162,7 +1168,8 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
// 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
|
||||
// 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);
|
||||
|
@ -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>();
|
||||
|
@ -1348,8 +1357,8 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
parseResult(result, listAttributes, fileName);
|
||||
|
||||
} else {
|
||||
MessageBox.alert("Error ",
|
||||
"<br/>Message: " + "no data available", null);
|
||||
MessageBox.alert("Error ", "<br/>Message: "
|
||||
+ "no data available", null);
|
||||
|
||||
if (obj.isMasked()) {
|
||||
obj.unmask();
|
||||
|
@ -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>();
|
||||
|
@ -1498,8 +1509,8 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
// table
|
||||
parseResult(result, listAttributes, fileName);
|
||||
} else {
|
||||
MessageBox.alert("Error ",
|
||||
"<br/>Message: " + "no data available", null);
|
||||
MessageBox.alert("Error ", "<br/>Message: "
|
||||
+ "no data available", null);
|
||||
|
||||
if (obj.isMasked()) {
|
||||
obj.unmask();
|
||||
|
@ -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>();
|
||||
|
@ -1617,8 +1630,8 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
// table
|
||||
parseResult(result, listAttributes, fileName);
|
||||
} else {
|
||||
MessageBox.alert("Error ",
|
||||
"<br/>Message: " + "no data available", null);
|
||||
MessageBox.alert("Error ", "<br/>Message: "
|
||||
+ "no data available", null);
|
||||
|
||||
if (obj.isMasked()) {
|
||||
obj.unmask();
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -345,8 +349,11 @@ public class GxtToolbarFunctionality {
|
|||
"FAILURE RPC removeComputation");
|
||||
|
||||
if (caught instanceof SessionExpiredException) {
|
||||
rootLogger.log(Level.INFO, "Session expired");
|
||||
CheckSession.showLogoutDialog();
|
||||
rootLogger
|
||||
.log(Level.INFO,
|
||||
"Session expired");
|
||||
CheckSession
|
||||
.showLogoutDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -536,8 +543,7 @@ public class GxtToolbarFunctionality {
|
|||
|
||||
String query = data.getQuery();
|
||||
|
||||
Listener<MessageBoxEvent> l = new
|
||||
Listener<MessageBoxEvent>() {
|
||||
Listener<MessageBoxEvent> l = new Listener<MessageBoxEvent>() {
|
||||
public void handleEvent(MessageBoxEvent ce) {
|
||||
SubmtQueryDialog.getButtonById(Dialog.OK).enable();
|
||||
}
|
||||
|
|
|
@ -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,6 +981,51 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
inputParameters.get(4).setValue(language);
|
||||
inputParameters.get(5).setValue(query);
|
||||
|
||||
// get data from cache
|
||||
// check if data exist considering as key the input parameters
|
||||
|
||||
// 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;
|
||||
|
||||
// System.out.println("KEY:" + keyData);
|
||||
// System.out.println("UID:" + UID);
|
||||
// store key
|
||||
// updateListKeyData(UID, keyData);
|
||||
net.sf.ehcache.Element dataFromCache = getDataFromCache(keyData);
|
||||
|
||||
// key to get query result sent to client calling loadSubmitResult
|
||||
String keySubmitQueryResult = keyData + "_SubmitQueryResult";
|
||||
updateListKeySubmitQueryResult(UID, keySubmitQueryResult);
|
||||
net.sf.ehcache.Element submitQueryResultFromCache = getDataFromCache(keySubmitQueryResult);
|
||||
|
||||
Object data = null;
|
||||
Object submitQueryResult = null;
|
||||
|
||||
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;
|
||||
|
||||
// set variable to true value if cached data are used and a
|
||||
// computation is not started
|
||||
Boolean val = new Boolean(true);
|
||||
updateListSubmitQueryUIDCachedData(UID, val);
|
||||
|
||||
} else {
|
||||
|
||||
// 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();
|
||||
|
@ -973,11 +1035,12 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
inputParameters, outputData, UID);
|
||||
|
||||
// get JobID
|
||||
if (checkJob(UID)) {
|
||||
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");
|
||||
logger.info("output data retrieved");
|
||||
|
||||
// data output values
|
||||
LinkedHashMap<String, String> mapValues = new LinkedHashMap<String, String>();
|
||||
|
@ -992,8 +1055,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
|
||||
// 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)));
|
||||
Result row = new Result(mapKeys.get(String
|
||||
.valueOf(i)), mapValues.get(String
|
||||
.valueOf(i)));
|
||||
output.add(row);
|
||||
}
|
||||
|
||||
|
@ -1010,31 +1074,78 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
|
||||
// get the attributes list for the result table
|
||||
listAttributes = new ArrayList<String>();
|
||||
listAttributes = getListAttributes(output.get(0).getValue());
|
||||
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);
|
||||
// updateSubmitQueryResultMap(UID, output);
|
||||
// remove job with the specified uid
|
||||
removeJob(UID);
|
||||
}
|
||||
} 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();
|
||||
HttpServletRequest request = this
|
||||
.getThreadLocalRequest();
|
||||
String applicationPath = request.getContextPath();
|
||||
// logger.info("dbmanager-> Application Path: " + applicationPath);
|
||||
String partialPathFile = applicationPath + "/computationResult/"
|
||||
+ fileName;
|
||||
// logger.info("dbmanager-> Application Path: " +
|
||||
// applicationPath);
|
||||
String partialPathFile = applicationPath
|
||||
+ "/computationResult/" + fileName;
|
||||
|
||||
SubmitQueryResultWithFileFromServlet result = new SubmitQueryResultWithFileFromServlet(
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
|
@ -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,29 +1685,33 @@ 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;
|
||||
|
||||
// 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 ((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();
|
||||
|
||||
|
@ -1604,6 +1727,55 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
// 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.");
|
||||
}
|
||||
|
||||
// // 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();
|
||||
//
|
||||
// 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,13 +2419,25 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
throw new SessionExpiredException();
|
||||
|
||||
try {
|
||||
|
||||
Boolean isComputationRemoved = false;
|
||||
// verify if this uid submitQuery request uses data in cache
|
||||
Boolean value = checkSubmitQueryUIDCachedData(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("")))) {
|
||||
if ((uidSubmitQuery != null)
|
||||
&& (!(uidSubmitQuery.equals("")))) {
|
||||
// get job status
|
||||
// ASLSession session = WsUtil.getAslSession(this
|
||||
// .getThreadLocalRequest().getSession());
|
||||
// HashMap<String, String> JobStatusMap = (HashMap<String,
|
||||
// HashMap<String, String> JobStatusMap =
|
||||
// (HashMap<String,
|
||||
// String>)
|
||||
// session
|
||||
// .getAttribute("JobStatusList");
|
||||
|
@ -2187,6 +2463,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
// remove submit query result
|
||||
refreshDataOnServer(uidSubmitQuery);
|
||||
// System.out.println("computation removed");
|
||||
isComputationRemoved = true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
|
@ -2197,9 +2474,16 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
logger.error("dbmanager-> ", e);
|
||||
}
|
||||
}
|
||||
// remove job status
|
||||
removeJobStatus(uidSubmitQuery);
|
||||
return (new Boolean(true));
|
||||
// // remove job status
|
||||
// removeJobStatus(uidSubmitQuery);
|
||||
// //remove the element related to the uid submitQuery
|
||||
// request
|
||||
// removeSubmitQueryUIDCachedData(uidSubmitQuery);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue