- added the file csv download for the submitQuery, sampling, smartsampling and randomsampling

- class FileModel in package datamodel modified. It implements the IsSerializable and not Serializable

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/databases-manager-portlet@100060 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Loredana Liccardo 2014-09-19 15:36:36 +00:00
parent d9735e3f44
commit 10007df08a
8 changed files with 649 additions and 269 deletions

View File

@ -7,6 +7,9 @@ import org.gcube.portlets.user.databasesmanager.client.datamodel.FileModel;
import org.gcube.portlets.user.databasesmanager.client.datamodel.GeneralOutputFromServlet; import org.gcube.portlets.user.databasesmanager.client.datamodel.GeneralOutputFromServlet;
import org.gcube.portlets.user.databasesmanager.client.datamodel.Result; import org.gcube.portlets.user.databasesmanager.client.datamodel.Result;
import org.gcube.portlets.user.databasesmanager.client.datamodel.Row; import org.gcube.portlets.user.databasesmanager.client.datamodel.Row;
import org.gcube.portlets.user.databasesmanager.client.datamodel.SamplingResultWithFileFromServlet;
import org.gcube.portlets.user.databasesmanager.client.datamodel.SubmitQueryResultWithFileFromServlet;
import com.extjs.gxt.ui.client.data.PagingLoadConfig; import com.extjs.gxt.ui.client.data.PagingLoadConfig;
import com.extjs.gxt.ui.client.data.PagingLoadResult; import com.extjs.gxt.ui.client.data.PagingLoadResult;
import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteService;
@ -24,18 +27,18 @@ public interface GWTdbManagerService extends RemoteService {
List<FileModel> getDBSchema(LinkedHashMap<String, String> dataInput) List<FileModel> getDBSchema(LinkedHashMap<String, String> dataInput)
throws Exception; throws Exception;
List<String> submitQuery(LinkedHashMap<String, String> dataDB, SubmitQueryResultWithFileFromServlet submitQuery(LinkedHashMap<String, String> dataDB,
String query, boolean valueReadOnlyQuery, String query, boolean valueReadOnlyQuery,
boolean smartCorrectionQuery, String language, String UID) boolean smartCorrectionQuery, String language, String UID)
throws Exception; throws Exception;
List<Result> sample(LinkedHashMap<String, String> dataInput) SamplingResultWithFileFromServlet sample(LinkedHashMap<String, String> dataInput)
throws Exception; throws Exception;
List<Result> smartSample(LinkedHashMap<String, String> dataInput) SamplingResultWithFileFromServlet smartSample(LinkedHashMap<String, String> dataInput)
throws Exception; throws Exception;
List<Result> randomSample(LinkedHashMap<String, String> dataInput) SamplingResultWithFileFromServlet randomSample(LinkedHashMap<String, String> dataInput)
throws Exception; throws Exception;
List<Row> parseCVSString(List<Result> result, List<String> attrNames) List<Row> parseCVSString(List<Result> result, List<String> attrNames)

View File

@ -6,7 +6,10 @@ import java.util.List;
import org.gcube.portlets.user.databasesmanager.client.datamodel.FileModel; import org.gcube.portlets.user.databasesmanager.client.datamodel.FileModel;
import org.gcube.portlets.user.databasesmanager.client.datamodel.GeneralOutputFromServlet; import org.gcube.portlets.user.databasesmanager.client.datamodel.GeneralOutputFromServlet;
import org.gcube.portlets.user.databasesmanager.client.datamodel.Result; import org.gcube.portlets.user.databasesmanager.client.datamodel.Result;
import org.gcube.portlets.user.databasesmanager.client.datamodel.SamplingResultWithFileFromServlet;
import org.gcube.portlets.user.databasesmanager.client.datamodel.Row; import org.gcube.portlets.user.databasesmanager.client.datamodel.Row;
import org.gcube.portlets.user.databasesmanager.client.datamodel.SubmitQueryResultWithFileFromServlet;
import com.extjs.gxt.ui.client.data.PagingLoadConfig; import com.extjs.gxt.ui.client.data.PagingLoadConfig;
import com.extjs.gxt.ui.client.data.PagingLoadResult; import com.extjs.gxt.ui.client.data.PagingLoadResult;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
@ -23,22 +26,22 @@ public interface GWTdbManagerServiceAsync {
void submitQuery(LinkedHashMap<String, String> dataDB, String query, void submitQuery(LinkedHashMap<String, String> dataDB, String query,
boolean valueReadOnlyQuery, boolean smartCorrectionQuery, boolean valueReadOnlyQuery, boolean smartCorrectionQuery,
String language, String UID, AsyncCallback<List<String>> callback); String language, String UID, AsyncCallback<SubmitQueryResultWithFileFromServlet> callback);
void parseCVSString(List<Result> result, List<String> attrNames, void parseCVSString(List<Result> result, List<String> attrNames,
AsyncCallback<List<Row>> callback); AsyncCallback<List<Row>> callback);
void sample(LinkedHashMap<String, String> dataInput, void sample(LinkedHashMap<String, String> dataInput,
AsyncCallback<List<Result>> callback); AsyncCallback<SamplingResultWithFileFromServlet> callback);
void getTableDetails(LinkedHashMap<String, String> dataInput, void getTableDetails(LinkedHashMap<String, String> dataInput,
AsyncCallback<LinkedHashMap<String, FileModel>> callback); AsyncCallback<LinkedHashMap<String, FileModel>> callback);
void smartSample(LinkedHashMap<String, String> dataInput, void smartSample(LinkedHashMap<String, String> dataInput,
AsyncCallback<List<Result>> callback); AsyncCallback<SamplingResultWithFileFromServlet> callback);
void randomSample(LinkedHashMap<String, String> dataInput, void randomSample(LinkedHashMap<String, String> dataInput,
AsyncCallback<List<Result>> callback); AsyncCallback<SamplingResultWithFileFromServlet> callback);
void LoadTables(PagingLoadConfig config, void LoadTables(PagingLoadConfig config,
LinkedHashMap<String, String> dataInput, boolean SearchTable, LinkedHashMap<String, String> dataInput, boolean SearchTable,

View File

@ -1,13 +1,14 @@
package org.gcube.portlets.user.databasesmanager.client.datamodel; package org.gcube.portlets.user.databasesmanager.client.datamodel;
import java.io.Serializable; //import java.io.Serializable;
import java.util.List; import java.util.List;
import com.extjs.gxt.ui.client.data.BaseModelData; import com.extjs.gxt.ui.client.data.BaseModelData;
import com.google.gwt.user.client.rpc.IsSerializable;
//class that represents an item that will be displayed in the tree. //class that represents an item that will be displayed in the tree.
//The item can be a resource, a database, a schema and a table. //The item can be a resource, a database, a schema and a table.
public class FileModel extends BaseModelData implements Serializable { public class FileModel extends BaseModelData implements IsSerializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;

View File

@ -0,0 +1,31 @@
package org.gcube.portlets.user.databasesmanager.client.datamodel;
import java.io.Serializable;
import java.util.List;
import com.extjs.gxt.ui.client.data.BaseModelData;
public class SamplingResultWithFileFromServlet extends BaseModelData implements
Serializable {
private static final long serialVersionUID = 1L;
private List<Result> output;
private String fileName;
public SamplingResultWithFileFromServlet() {
}
public SamplingResultWithFileFromServlet(List<Result> result, String fileName) {
set("output", result);
set("fileName", fileName);
}
public List<Result> getListOutput() {
return get("output");
}
public String getFileName() {
return get("fileName");
}
}

View File

@ -0,0 +1,31 @@
package org.gcube.portlets.user.databasesmanager.client.datamodel;
import java.io.Serializable;
import java.util.List;
import com.extjs.gxt.ui.client.data.BaseModelData;
public class SubmitQueryResultWithFileFromServlet extends BaseModelData
implements Serializable {
private static final long serialVersionUID = 1L;
private List<String> output;
private String fileName;
public SubmitQueryResultWithFileFromServlet() {
}
public SubmitQueryResultWithFileFromServlet(List<String> result, String fileName) {
set("output", result);
set("fileName", fileName);
}
public List<String> getListOutput() {
return get("output");
}
public String getFileName() {
return get("fileName");
}
}

View File

@ -10,8 +10,10 @@ import java.util.logging.Logger;
import org.gcube.portlets.user.databasesmanager.client.GWTdbManagerServiceAsync; import org.gcube.portlets.user.databasesmanager.client.GWTdbManagerServiceAsync;
import org.gcube.portlets.user.databasesmanager.client.datamodel.FileModel; import org.gcube.portlets.user.databasesmanager.client.datamodel.FileModel;
import org.gcube.portlets.user.databasesmanager.client.datamodel.Result; import org.gcube.portlets.user.databasesmanager.client.datamodel.Result;
import org.gcube.portlets.user.databasesmanager.client.datamodel.SamplingResultWithFileFromServlet;
import org.gcube.portlets.user.databasesmanager.client.datamodel.Row; import org.gcube.portlets.user.databasesmanager.client.datamodel.Row;
import org.gcube.portlets.user.databasesmanager.client.datamodel.SubmitQueryData; import org.gcube.portlets.user.databasesmanager.client.datamodel.SubmitQueryData;
import org.gcube.portlets.user.databasesmanager.client.datamodel.SubmitQueryResultWithFileFromServlet;
import org.gcube.portlets.user.databasesmanager.client.events.LoadTablesEvent; import org.gcube.portlets.user.databasesmanager.client.events.LoadTablesEvent;
import org.gcube.portlets.user.databasesmanager.client.events.RandomSamplingEvent; import org.gcube.portlets.user.databasesmanager.client.events.RandomSamplingEvent;
import org.gcube.portlets.user.databasesmanager.client.events.RefreshDataEvent; import org.gcube.portlets.user.databasesmanager.client.events.RefreshDataEvent;
@ -57,7 +59,9 @@ import com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar; import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.event.dom.client.KeyCodes; import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HTML;
import com.extjs.gxt.ui.client.data.BasePagingLoadConfig; import com.extjs.gxt.ui.client.data.BasePagingLoadConfig;
import com.extjs.gxt.ui.client.data.BasePagingLoader; import com.extjs.gxt.ui.client.data.BasePagingLoader;
import com.extjs.gxt.ui.client.data.PagingLoadConfig; import com.extjs.gxt.ui.client.data.PagingLoadConfig;
@ -311,15 +315,15 @@ public class GxtBorderLayoutPanel extends ContentPanel {
getTableDetails(table); getTableDetails(table);
} }
}); });
eventBus.addHandler(RefreshDataEvent.TYPE, new RefreshDataEventHandler() { eventBus.addHandler(RefreshDataEvent.TYPE,
new RefreshDataEventHandler() {
@Override
public void onRefreshData(RefreshDataEvent refreshDataEvent) { @Override
public void onRefreshData(RefreshDataEvent refreshDataEvent) {
} }
}); });
} }
// method to load the tables list // method to load the tables list
@ -330,8 +334,8 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// disable table details and sampling buttons // disable table details and sampling buttons
toolbar.disableButtonsOperationsOnTable(); toolbar.disableButtonsOperationsOnTable();
// clear the panel // clear the panel
// centerBottom.removeAll(); // centerBottom.removeAll();
// centerBottom.layout(true); // centerBottom.layout(true);
// get the selected item // get the selected item
List<FileModel> data = treePanel.getTreePanel().getSelectionModel() List<FileModel> data = treePanel.getTreePanel().getSelectionModel()
@ -392,11 +396,12 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// hide the dialog // hide the dialog
tablesLoaded.hide(); tablesLoaded.hide();
if (caught if (caught.getMessage().contains(
.getMessage() "Result not available")) {
.contains("Result not available")) { MessageBox.alert("Warning ",
MessageBox.alert("Warning ", "<br/>Message:" "<br/>Message:"
+ "no tables available", null); + "no tables available",
null);
} else { } else {
MessageBox.alert("Error ", "<br/>Message:" MessageBox.alert("Error ", "<br/>Message:"
+ caught.getMessage(), null); + caught.getMessage(), null);
@ -412,26 +417,26 @@ public class GxtBorderLayoutPanel extends ContentPanel {
rootLogger.log(Level.SEVERE, rootLogger.log(Level.SEVERE,
"SUCCESS RPC LoadTables"); "SUCCESS RPC LoadTables");
callback.onSuccess(result); callback.onSuccess(result);
if (keyword == null) { if (keyword == null) {
startSearchTable = false; startSearchTable = false;
} }
// enable toolbar in the dialog // enable toolbar in the dialog
toolBarTop.enable(); toolBarTop.enable();
if (result!=null){ if (result != null) {
List<Result> data = result.getData(); List<Result> data = result.getData();
if (data.size()==0){ if (data.size() == 0) {
MessageBox.alert("Warning ", "<br/>Message:" MessageBox
+ "no tables availables", null); .alert("Warning ",
"<br/>Message:"
+ "no tables availables",
null);
return; return;
} }
} }
} }
}); });
// rootLogger.log(Level.SEVERE, "End RPC LoadTables"); // rootLogger.log(Level.SEVERE, "End RPC LoadTables");
@ -690,22 +695,23 @@ public class GxtBorderLayoutPanel extends ContentPanel {
keyword = null; keyword = null;
startSearchTable = false; startSearchTable = false;
if (selectedTable != null) { if (selectedTable != null) {
//refresh the content in the two panels // refresh the content in the two panels
centerBottom.removeAll(); centerBottom.removeAll();
centerBottom.layout(true); centerBottom.layout(true);
centerUpper.removeAll(); centerUpper.removeAll();
centerUpper.layout(true); centerUpper.layout(true);
// display the table in the panel "Database Information" // display the table in the panel "Database Information"
displayTableName(selectedTable); displayTableName(selectedTable);
// to get the selected item in the tree panel // to get the selected item in the tree panel
List<FileModel> data = treePanel.getTreePanel() List<FileModel> data = treePanel.getTreePanel()
.getSelectionModel().getSelectedItems(); .getSelectionModel().getSelectedItems();
FileModel selectedItem = data.get(0); FileModel selectedItem = data.get(0);
// fire event // fire event
eventBus.fireEvent(new SelectedTableEvent(selectedItem, selectedTable)); eventBus.fireEvent(new SelectedTableEvent(selectedItem,
selectedTable));
} }
} }
}); });
@ -716,8 +722,8 @@ public class GxtBorderLayoutPanel extends ContentPanel {
keyword = null; keyword = null;
startSearchTable = false; startSearchTable = false;
// refresh the database information panel // refresh the database information panel
// centerUpper.removeAll(); // centerUpper.removeAll();
// centerUpper.layout(true); // centerUpper.layout(true);
tablesLoaded.hide(); tablesLoaded.hide();
} }
}); });
@ -803,7 +809,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// remote rpc // remote rpc
RPCservice.submitQuery(dataForSubmitQuery, dataQuery.getQuery(), true, RPCservice.submitQuery(dataForSubmitQuery, dataQuery.getQuery(), true,
dataQuery.getSmartCorrection(), language, UID, dataQuery.getSmartCorrection(), language, UID,
new AsyncCallback<List<String>>() { new AsyncCallback<SubmitQueryResultWithFileFromServlet>() {
// TODO: TO REMOVE data "true" as input if you manage the // TODO: TO REMOVE data "true" as input if you manage the
// read-only query in the form // read-only query in the form
@ -833,9 +839,9 @@ public class GxtBorderLayoutPanel extends ContentPanel {
"Result not available")) { "Result not available")) {
MessageBox.alert("Warning ", "<br/>Message:" MessageBox.alert("Warning ", "<br/>Message:"
+ "The query returned 0 values", null); + "The query returned 0 values", null);
}else{ } else {
MessageBox.alert("Error ", MessageBox.alert("Error ", "<br/>Message:"
"<br/>Message:" + caught.getMessage(), null); + caught.getMessage(), null);
} }
} }
@ -854,84 +860,93 @@ public class GxtBorderLayoutPanel extends ContentPanel {
} }
@Override @Override
public void onSuccess(List<String> listAttributes) { public void onSuccess(SubmitQueryResultWithFileFromServlet obj) {
rootLogger.log(Level.SEVERE, "SUCCESS RPC submitQuery"); rootLogger.log(Level.SEVERE, "SUCCESS RPC submitQuery");
if (form.getBody().isMasked()) if (obj != null){
form.getBody().unmask(); //get list attributes
List<String> listAttributes = obj.getListOutput();
if (form.getBody().isMasked())
form.getBody().unmask();
if (form.getButtonById(Dialog.OK).isEnabled() == false) { if (form.getButtonById(Dialog.OK).isEnabled() == false) {
form.getButtonById(Dialog.OK).enable(); form.getButtonById(Dialog.OK).enable();
}
if (listAttributes == null) {
return;
}
if (listAttributes.size() == 0) {
// if (form.getBody().isMasked())
// form.getBody().unmask();
rootLogger.log(Level.SEVERE,
"No results have been returned");
MessageBox.alert("Warning ", "<br/>Message:"
+ "The query returned 0 values", null);
return;
}
// if ((listAttributes == null)
// || (listAttributes.size() == 0)) {
//
// // if (form.getBody().isMasked())
// // form.getBody().unmask();
//
// rootLogger.log(Level.SEVERE,
// "No results have been returned");
//
// MessageBox.alert("Error ", "<br/>Message:"
// + "Result not available", null);
// return;
// }
rootLogger.log(Level.SEVERE, "SUCCESS RPC submitQuery");
rootLogger.log(Level.SEVERE, "output size: "
+ listAttributes.size());
// recover query
// Result query = result.remove(0);
// recover converted query
// Result convertedQuery;
// if (dataQuery.getSmartCorrection() == true) {
// result.remove(0);
// // convertedQuery = result.get(1);
// }
// get the attributes list for the result table
// List<String> listAttributes = new
// ArrayList<String>();
// listAttributes = getListAttributes(result.get(0)
// .getValue());
// // remove the header in order to parse only the
// result
// result.remove(0);
// parse the result in order to obtain a table
// boolean submitQueryEventManaged = true;
// parseResult(result, form, dialogID,
// submitQueryEventManaged);
// parseSubmitQueryResult(result, form, dialogID,
// listAttributes, dataQuery.getQuery());
// get path
String fileName = obj.getFileName();
parseSubmitQueryResult(form, dialogID, listAttributes, fileName,
UID);
} }
if (listAttributes == null) {
return;
}
if (listAttributes.size() == 0) {
// if (form.getBody().isMasked())
// form.getBody().unmask();
rootLogger.log(Level.SEVERE,
"No results have been returned");
MessageBox.alert("Warning ", "<br/>Message:"
+ "The query returned 0 values", null);
return;
}
// if ((listAttributes == null)
// || (listAttributes.size() == 0)) {
//
// // if (form.getBody().isMasked())
// // form.getBody().unmask();
//
// rootLogger.log(Level.SEVERE,
// "No results have been returned");
//
// MessageBox.alert("Error ", "<br/>Message:"
// + "Result not available", null);
// return;
// }
rootLogger.log(Level.SEVERE, "SUCCESS RPC submitQuery");
rootLogger.log(Level.SEVERE, "output size: "
+ listAttributes.size());
// recover query
// Result query = result.remove(0);
// recover converted query
// Result convertedQuery;
// if (dataQuery.getSmartCorrection() == true) {
// result.remove(0);
// // convertedQuery = result.get(1);
// }
// get the attributes list for the result table
// List<String> listAttributes = new
// ArrayList<String>();
// listAttributes = getListAttributes(result.get(0)
// .getValue());
// // remove the header in order to parse only the
// result
// result.remove(0);
// parse the result in order to obtain a table
// boolean submitQueryEventManaged = true;
// parseResult(result, form, dialogID,
// submitQueryEventManaged);
// parseSubmitQueryResult(result, form, dialogID,
// listAttributes, dataQuery.getQuery());
parseSubmitQueryResult(form, dialogID, listAttributes,
UID);
} }
}); });
} }
// start the parsing of the submit result in order to obtain a table // start the parsing of the submit result in order to obtain a table
private void parseSubmitQueryResult(Dialog dialog, final int dialogID, private void parseSubmitQueryResult(Dialog dialog, final int dialogID,
final List<String> listAttributes, final String UID) { final List<String> listAttributes, String fileName, final String UID) {
final Dialog form = dialog; final Dialog form = dialog;
// define the proxy and create the grid to display in the dialog // define the proxy and create the grid to display in the dialog
@ -964,7 +979,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
} }
} }
}; };
MessageBox.alert("Error ", "<br/>Message:" MessageBox.alert("Error ", "<br/>Message:"
+ caught.getMessage(), l); + caught.getMessage(), l);
callback.onFailure(caught); callback.onFailure(caught);
@ -991,10 +1006,13 @@ public class GxtBorderLayoutPanel extends ContentPanel {
rootLogger rootLogger
.log(Level.SEVERE, .log(Level.SEVERE,
"No results have been returned"); "No results have been returned");
MessageBox.alert("Warning ", "<br/>Message:" MessageBox
+ "The query returned 0 values", null); .alert("Warning ",
"<br/>Message:"
+ "The query returned 0 values",
null);
return; return;
} }
} }
@ -1132,6 +1150,23 @@ public class GxtBorderLayoutPanel extends ContentPanel {
}); });
} }
}); });
// add the button to download the result
final String urlFile = Window.Location
.getProtocol()
+ "//"
+ Window.Location.getHost() + fileName;
Button download = new Button("Download",
new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(
ButtonEvent ce) {
Window.open(urlFile, "Result File",
"_blank");
}
});
submitResult.addButton(download);
submitResult.add(grid); submitResult.add(grid);
submitResult.show(); submitResult.show();
} }
@ -1189,39 +1224,88 @@ public class GxtBorderLayoutPanel extends ContentPanel {
obj.mask("Sampling the table", "x-mask-loading"); obj.mask("Sampling the table", "x-mask-loading");
// call remote service // call remote service
RPCservice.sample(dataInput, new AsyncCallback<List<Result>>() { RPCservice.sample(dataInput,
@Override new AsyncCallback<SamplingResultWithFileFromServlet>() {
public void onFailure(Throwable caught) { @Override
// Window.alert(caught.getMessage()); public void onFailure(Throwable caught) {
rootLogger.log(Level.SEVERE, "FAILURE RPC sample"); // Window.alert(caught.getMessage());
if (caught.getMessage().contains("Result not available")) { rootLogger.log(Level.SEVERE, "FAILURE RPC sample");
MessageBox.alert("Warning ", "<br/>Message:" if (caught.getMessage()
+ "The table has 0 rows", null); .contains("Result not available")) {
} else { MessageBox.alert("Warning ", "<br/>Message:"
MessageBox.alert("Error ", + "The table has 0 rows", null);
"<br/>Message:" + caught.getMessage(), null); } else {
} MessageBox.alert("Error ",
if (obj.isMasked()) { "<br/>Message:" + caught.getMessage(), null);
obj.unmask(); }
} if (obj.isMasked()) {
} obj.unmask();
}
}
@Override @Override
public void onSuccess(List<Result> result) { public void onSuccess(SamplingResultWithFileFromServlet obj) {
rootLogger.log(Level.SEVERE, "SUCCESS RPC sample"); rootLogger.log(Level.SEVERE, "SUCCESS RPC sample");
rootLogger.log(Level.SEVERE, "output size: " + result.size());
// get the attributes list for the result if (obj != null) {
// table // get data
List<String> listAttributes = new ArrayList<String>(); List<Result> result = obj.getListOutput();
listAttributes = getListAttributes(result.get(0).getValue()); // get the attributes list for the result
// remove the header in order to parse only // table
// the result List<String> listAttributes = new ArrayList<String>();
result.remove(0); listAttributes = getListAttributes(result.get(0)
// parse the result in order to obtain a .getValue());
// table // remove the header in order to parse only
parseResult(result, listAttributes); // the result
} result.remove(0);
}); rootLogger.log(Level.SEVERE, "output size: "
+ result.size());
// get path
String fileName = obj.getFileName();
// parse the result in order to obtain a
// table
parseResult(result, listAttributes, fileName);
}
}
});
// // call remote service
// RPCservice.sample(dataInput, new AsyncCallback<List<Result>>() {
// @Override
// public void onFailure(Throwable caught) {
// // Window.alert(caught.getMessage());
// rootLogger.log(Level.SEVERE, "FAILURE RPC sample");
// if (caught.getMessage().contains("Result not available")) {
// MessageBox.alert("Warning ", "<br/>Message:"
// + "The table has 0 rows", null);
// } else {
// MessageBox.alert("Error ",
// "<br/>Message:" + caught.getMessage(), null);
// }
// if (obj.isMasked()) {
// obj.unmask();
// }
// }
//
// @Override
// public void onSuccess(List<Result> result) {
// rootLogger.log(Level.SEVERE, "SUCCESS RPC sample");
// rootLogger.log(Level.SEVERE, "output size: " + result.size());
// // get the attributes list for the result
// // table
// List<String> listAttributes = new ArrayList<String>();
// listAttributes = getListAttributes(result.get(0).getValue());
// // remove the header in order to parse only
// // the result
// result.remove(0);
// // parse the result in order to obtain a
// // table
// parseResult(result, listAttributes);
// }
// });
} }
// method that performs the smart sample // method that performs the smart sample
@ -1274,39 +1358,50 @@ public class GxtBorderLayoutPanel extends ContentPanel {
obj.mask("Sampling the table", "x-mask-loading"); obj.mask("Sampling the table", "x-mask-loading");
// call remote service // call remote service
RPCservice.smartSample(dataInput, new AsyncCallback<List<Result>>() { RPCservice.smartSample(dataInput,
@Override new AsyncCallback<SamplingResultWithFileFromServlet>() {
public void onFailure(Throwable caught) { @Override
// Window.alert(caught.getMessage()); public void onFailure(Throwable caught) {
rootLogger.log(Level.SEVERE, "FAILURE RPC smartSample"); // Window.alert(caught.getMessage());
if (caught.getMessage().contains("The table has 0 rows")) { rootLogger.log(Level.SEVERE, "FAILURE RPC smartSample");
MessageBox.alert("Warning ", "<br/>Message:" if (caught.getMessage()
+ "The table has 0 rows", null); .contains("The table has 0 rows")) {
} else { MessageBox.alert("Warning ", "<br/>Message:"
MessageBox.alert("Error ", + "The table has 0 rows", null);
"<br/>Message:" + caught.getMessage(), null); } else {
} MessageBox.alert("Error ",
if (obj.isMasked()) { "<br/>Message:" + caught.getMessage(), null);
obj.unmask(); }
} if (obj.isMasked()) {
} obj.unmask();
}
}
@Override @Override
public void onSuccess(List<Result> result) { public void onSuccess(SamplingResultWithFileFromServlet obj) {
rootLogger.log(Level.SEVERE, "SUCCESS RPC smartSample"); rootLogger.log(Level.SEVERE, "SUCCESS RPC smartSample");
rootLogger.log(Level.SEVERE, "output size: " + result.size());
// get the attributes list for the result if (obj != null) {
// table // get data
List<String> listAttributes = new ArrayList<String>(); List<Result> result = obj.getListOutput();
listAttributes = getListAttributes(result.get(0).getValue()); // get the attributes list for the result
// remove the header in order to parse only // table
// the result List<String> listAttributes = new ArrayList<String>();
result.remove(0); listAttributes = getListAttributes(result.get(0)
// parse the result in order to obtain a .getValue());
// table // remove the header in order to parse only
parseResult(result, listAttributes); // the result
} result.remove(0);
}); rootLogger.log(Level.SEVERE, "output size: "
+ result.size());
// get path
String fileName = obj.getFileName();
// parse the result in order to obtain a
// table
parseResult(result, listAttributes, fileName);
}
}
});
} }
// method to perform the random sample // method to perform the random sample
@ -1361,44 +1456,57 @@ public class GxtBorderLayoutPanel extends ContentPanel {
obj.mask("Sampling the table", "x-mask-loading"); obj.mask("Sampling the table", "x-mask-loading");
// call remote service // call remote service
RPCservice.randomSample(dataInput, new AsyncCallback<List<Result>>() { RPCservice.randomSample(dataInput,
@Override new AsyncCallback<SamplingResultWithFileFromServlet>() {
public void onFailure(Throwable caught) { @Override
// Window.alert(caught.getMessage()); public void onFailure(Throwable caught) {
rootLogger.log(Level.SEVERE, "FAILURE RPC randomSample"); // Window.alert(caught.getMessage());
if (caught.getMessage().contains("Result not available")) { rootLogger
MessageBox.alert("Warning ", "<br/>Message:" .log(Level.SEVERE, "FAILURE RPC randomSample");
+ "The table has 0 rows", null); if (caught.getMessage()
} else { .contains("Result not available")) {
MessageBox.alert("Error ", MessageBox.alert("Warning ", "<br/>Message:"
"<br/>Message:" + caught.getMessage(), null); + "The table has 0 rows", null);
} } else {
if (obj.isMasked()) { MessageBox.alert("Error ",
obj.unmask(); "<br/>Message:" + caught.getMessage(), null);
} }
} if (obj.isMasked()) {
obj.unmask();
}
}
@Override @Override
public void onSuccess(List<Result> result) { public void onSuccess(SamplingResultWithFileFromServlet obj) {
rootLogger.log(Level.SEVERE, "SUCCESS RPC randomSample"); rootLogger
rootLogger.log(Level.SEVERE, "output size: " + result.size()); .log(Level.SEVERE, "SUCCESS RPC randomSample");
// get the attributes list for the result
// table if (obj != null) {
List<String> listAttributes = new ArrayList<String>(); // get data
listAttributes = getListAttributes(result.get(0).getValue()); List<Result> result = obj.getListOutput();
// remove the header in order to parse only // get the attributes list for the result
// the result // table
result.remove(0); List<String> listAttributes = new ArrayList<String>();
// parse the result in order to obtain a listAttributes = getListAttributes(result.get(0)
// table .getValue());
parseResult(result, listAttributes); // remove the header in order to parse only
} // the result
}); result.remove(0);
rootLogger.log(Level.SEVERE, "output size: "
+ result.size());
// get path
String fileName = obj.getFileName();
// parse the result in order to obtain a
// table
parseResult(result, listAttributes, fileName);
}
}
});
} }
// start the parsing of the submit result in order to obtain a table // start the parsing of the submit result in order to obtain a table
private void parseResult(List<Result> result, private void parseResult(List<Result> result,
final List<String> listAttributes) { final List<String> listAttributes, final String fileName) {
// to unmask the entire content panel // to unmask the entire content panel
final GxtBorderLayoutPanel obj = this; final GxtBorderLayoutPanel obj = this;
// final Dialog form = dialog; // final Dialog form = dialog;
@ -1436,6 +1544,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
if (rows != null) { if (rows != null) {
// Display the submit query result as a table // Display the submit query result as a table
Dialog sampleResult = new Dialog() { Dialog sampleResult = new Dialog() {
// override the maximize event modifying it with // override the maximize event modifying it with
// a different behaviour if the mimimize event // a different behaviour if the mimimize event
// occurs // occurs
@ -1446,6 +1555,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
super.maximize(); super.maximize();
} }
} }
}; };
// if (submitQueryEventManaged == true) { // if (submitQueryEventManaged == true) {
@ -1506,6 +1616,22 @@ public class GxtBorderLayoutPanel extends ContentPanel {
} }
}); });
// add the button to download the result
final String urlFile = Window.Location
.getProtocol()
+ "//"
+ Window.Location.getHost() + fileName;
Button download = new Button("Download",
new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(
ButtonEvent ce) {
Window.open(urlFile, "Result File",
"_blank");
}
});
sampleResult.addButton(download);
sampleResult.add(grid, data); sampleResult.add(grid, data);
sampleResult.show(); sampleResult.show();
@ -1841,7 +1967,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
final Result table = new Result("Selected table", tableName); final Result table = new Result("Selected table", tableName);
final ListStore<Result> store = new ListStore<Result>(); final ListStore<Result> store = new ListStore<Result>();
store.add(table); store.add(table);
// create column configuration // create column configuration
List<ColumnConfig> configs = new ArrayList<ColumnConfig>(); List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
ColumnConfig column = new ColumnConfig(); ColumnConfig column = new ColumnConfig();
@ -1857,19 +1983,21 @@ public class GxtBorderLayoutPanel extends ContentPanel {
TextField<String> textValue = new TextField<String>(); TextField<String> textValue = new TextField<String>();
// text.setAllowBlank(false); // text.setAllowBlank(false);
// column.setEditor(new CellEditor(textValue)); // column.setEditor(new CellEditor(textValue));
column.setEditor(new CellEditor(textValue){ column.setEditor(new CellEditor(textValue) {
// public Object preProcessValue(Object value) { // public Object preProcessValue(Object value) {
// System.out.println("value 1: " + store.getModels().get(0).getValue()); // System.out.println("value 1: " +
// return store.getModels().get(0).getValue(); // store.getModels().get(0).getValue());
// } // return store.getModels().get(0).getValue();
// }
public Object postProcessValue(Object value) { public Object postProcessValue(Object value) {
// System.out.println("value: " + store.findModel(table).getValue()); // System.out.println("value: " +
return store.findModel(table).getValue(); // store.findModel(table).getValue());
return store.findModel(table).getValue();
} }
}); });
configs.add(column); configs.add(column);
ColumnModel cm = new ColumnModel(configs); ColumnModel cm = new ColumnModel(configs);

View File

@ -899,6 +899,7 @@ public class GxtTreePanel extends LayoutContainer {
if (result != null) { if (result != null) {
// remove children // remove children
removeChildren(selectedItem); removeChildren(selectedItem);
tree.layout(true); tree.layout(true);

View File

@ -5,13 +5,21 @@ import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; 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.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.net.URLStreamHandler; import java.net.URLStreamHandler;
import java.io.OutputStreamWriter;
import java.io.FileOutputStream;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import net.sf.ehcache.CacheManager; import net.sf.ehcache.CacheManager;
@ -50,7 +58,9 @@ import org.gcube.portlets.user.databasesmanager.client.datamodel.FileModel;
import org.gcube.portlets.user.databasesmanager.client.datamodel.GeneralOutputFromServlet; import org.gcube.portlets.user.databasesmanager.client.datamodel.GeneralOutputFromServlet;
import org.gcube.portlets.user.databasesmanager.client.datamodel.Parameter; import org.gcube.portlets.user.databasesmanager.client.datamodel.Parameter;
import org.gcube.portlets.user.databasesmanager.client.datamodel.Result; import org.gcube.portlets.user.databasesmanager.client.datamodel.Result;
import org.gcube.portlets.user.databasesmanager.client.datamodel.SamplingResultWithFileFromServlet;
import org.gcube.portlets.user.databasesmanager.client.datamodel.Row; import org.gcube.portlets.user.databasesmanager.client.datamodel.Row;
import org.gcube.portlets.user.databasesmanager.client.datamodel.SubmitQueryResultWithFileFromServlet;
import org.gcube.portlets.user.databasesmanager.client.utils.ConstantsPortlet; import org.gcube.portlets.user.databasesmanager.client.utils.ConstantsPortlet;
import org.gcube.portlets.user.databasesmanager.server.util.SessionUtil; import org.gcube.portlets.user.databasesmanager.server.util.SessionUtil;
import com.extjs.gxt.ui.client.data.BasePagingLoadResult; import com.extjs.gxt.ui.client.data.BasePagingLoadResult;
@ -60,7 +70,6 @@ import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.XStream;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
GWTdbManagerService { GWTdbManagerService {
@ -90,7 +99,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
CacheManager cacheManager = CacheManager.newInstance(url); CacheManager cacheManager = CacheManager.newInstance(url);
// getcache // getcache
employeeCache = cacheManager.getEhcache("DBCache"); employeeCache = cacheManager.getEhcache("DBCache");
String path = System.getenv("CATALINA_TMPDIR"); // String path = System.getenv("CATALINA_TMPDIR");
// CacheConfiguration config = // CacheConfiguration config =
// employeeCache.getCacheConfiguration(); // employeeCache.getCacheConfiguration();
// String DiskCacheFolderName = "DBManagerDisk"; // String DiskCacheFolderName = "DBManagerDisk";
@ -107,9 +116,23 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
} catch (Exception e) { } catch (Exception e) {
logger.error("dbmanager-> Failed to get cache: " + e); logger.error("dbmanager-> Failed to get cache: " + e);
// e.printStackTrace(); // e.printStackTrace();
throw e; throw e;
} }
// create folder that will contain file samplings and submitquery result
// in the /webapps/folder_portlet
String path = this.getServletContext().getRealPath("") + "/"
+ "computationResult";
// System.out.println("***PATH FILE: " + path);
File computationResult = new File(path);
if (!computationResult.exists()) {
computationResult.mkdir();
// System.out.println("***DIRECTORY CREATED");
}
} }
public void destroy() { public void destroy() {
@ -130,15 +153,15 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
logger.error("dbmanager-> " + e); logger.error("dbmanager-> " + e);
// e.printStackTrace(); // e.printStackTrace();
} }
} }
private void initVariables() { private void initVariables() {
ASLSession session = SessionUtil.getAslSession(this.getThreadLocalRequest() ASLSession session = SessionUtil.getAslSession(this
.getSession()); .getThreadLocalRequest().getSession());
// the result generated in the LoadTables method // the result generated in the LoadTables method
// List<Result> result = new ArrayList<Result>(); // List<Result> result = new ArrayList<Result>();
@ -247,7 +270,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
key, outputParameters); key, outputParameters);
insertDataIntoCache(dataToCache); insertDataIntoCache(dataToCache);
} }
} }
@ -348,7 +371,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
// e.printStackTrace(); // e.printStackTrace();
// throw new Exception("Failed to load data " + ); // throw new Exception("Failed to load data " + );
logger.error("dbmanager-> " + e); logger.error("dbmanager-> " + e);
throw e; throw e;
@ -450,7 +473,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
// e.printStackTrace(); // e.printStackTrace();
// throw new Exception("Failed to load data. " + e); // throw new Exception("Failed to load data. " + e);
logger.error("dbmanager-> " + e); logger.error("dbmanager-> " + e);
throw e; throw e;
@ -690,10 +713,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// to submit a query // to submit a query
@Override @Override
public List<String> submitQuery(LinkedHashMap<String, String> dataDB, public SubmitQueryResultWithFileFromServlet submitQuery(
String query, boolean valueReadOnlyQuery, LinkedHashMap<String, String> dataDB, String query,
boolean smartCorrectionQuery, String language, String UID) boolean valueReadOnlyQuery, boolean smartCorrectionQuery,
throws Exception { String language, String UID) throws Exception {
logger.info("dbmanager-> Dialect used for smart correction: " logger.info("dbmanager-> Dialect used for smart correction: "
+ language); + language);
@ -796,6 +819,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
} }
} catch (Exception e) { } catch (Exception e) {
// e.printStackTrace(); // e.printStackTrace();
// TODO TO REMOVE. Exception Statistical management to remove a // TODO TO REMOVE. Exception Statistical management to remove a
// computation // computation
if (e.getMessage() if (e.getMessage()
@ -807,12 +831,95 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
throw e; throw e;
} }
return listAttributes; // 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, partialPathFile);
return obj;
} }
// @Override
// public List<Result> sample(LinkedHashMap<String, String> dataInput)
// throws Exception {
// // data input
// List<Parameter> inputParameters = new ArrayList<Parameter>();
// // output sample result
// List<Result> output = new ArrayList<Result>();
//
// String algorithmId = "SAMPLEONTABLE";
//
// // 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);
//
// // 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<String, String> mapValues = new LinkedHashMap<String,
// String>();
// // data output keys
// LinkedHashMap<String, String> mapKeys = new LinkedHashMap<String,
// String>();
//
// 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 partialPathFile = storeResultIntoCSVFile(output);
//
//
// ResultWithFileFromServlet obj = new ResultWithFileFromServlet(output,
// partialPathFile);
//
// return output;
// }
@Override @Override
public List<Result> sample(LinkedHashMap<String, String> dataInput) public SamplingResultWithFileFromServlet sample(
throws Exception { LinkedHashMap<String, String> dataInput) throws Exception {
// data input // data input
List<Parameter> inputParameters = new ArrayList<Parameter>(); List<Parameter> inputParameters = new ArrayList<Parameter>();
// output sample result // output sample result
@ -870,12 +977,23 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
output.add(row); output.add(row);
} }
return output; 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 @Override
public List<Result> smartSample(LinkedHashMap<String, String> dataInput) public SamplingResultWithFileFromServlet smartSample(
throws Exception { LinkedHashMap<String, String> dataInput) throws Exception {
// data input // data input
List<Parameter> inputParameters = new ArrayList<Parameter>(); List<Parameter> inputParameters = new ArrayList<Parameter>();
// output sample result // output sample result
@ -933,12 +1051,23 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
output.add(row); output.add(row);
} }
return output; 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 @Override
public List<Result> randomSample(LinkedHashMap<String, String> dataInput) public SamplingResultWithFileFromServlet randomSample(
throws Exception { LinkedHashMap<String, String> dataInput) throws Exception {
// data input // data input
List<Parameter> inputParameters = new ArrayList<Parameter>(); List<Parameter> inputParameters = new ArrayList<Parameter>();
@ -997,7 +1126,18 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
output.add(row); output.add(row);
} }
return output; 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 @Override
@ -1260,8 +1400,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// } // }
private synchronized List<Result> getSubmitQueryResult(String submitQueryUID) { private synchronized List<Result> getSubmitQueryResult(String submitQueryUID) {
ASLSession session = SessionUtil.getAslSession(this.getThreadLocalRequest() ASLSession session = SessionUtil.getAslSession(this
.getSession()); .getThreadLocalRequest().getSession());
HashMap<String, List<Result>> submitQueryResult = (HashMap<String, List<Result>>) session HashMap<String, List<Result>> submitQueryResult = (HashMap<String, List<Result>>) session
.getAttribute("submitQueryResult"); .getAttribute("submitQueryResult");
if (submitQueryResult.containsKey(submitQueryUID)) { if (submitQueryResult.containsKey(submitQueryUID)) {
@ -1273,8 +1413,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
private synchronized List<Row> getSubmitQueryResultParsed( private synchronized List<Row> getSubmitQueryResultParsed(
String submitQueryUID) { String submitQueryUID) {
ASLSession session = SessionUtil.getAslSession(this.getThreadLocalRequest() ASLSession session = SessionUtil.getAslSession(this
.getSession()); .getThreadLocalRequest().getSession());
HashMap<String, List<Row>> submitQueryResultParsed = (HashMap<String, List<Row>>) session HashMap<String, List<Row>> submitQueryResultParsed = (HashMap<String, List<Row>>) session
.getAttribute("submitQueryResultParsed"); .getAttribute("submitQueryResultParsed");
@ -1288,8 +1428,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
private synchronized void updateSubmitQueryResultParsed( private synchronized void updateSubmitQueryResultParsed(
String submitQueryUID, List<Row> data) { String submitQueryUID, List<Row> data) {
ASLSession session = SessionUtil.getAslSession(this.getThreadLocalRequest() ASLSession session = SessionUtil.getAslSession(this
.getSession()); .getThreadLocalRequest().getSession());
HashMap<String, List<Row>> submitQueryResultParsed = (HashMap<String, List<Row>>) session HashMap<String, List<Row>> submitQueryResultParsed = (HashMap<String, List<Row>>) session
.getAttribute("submitQueryResultParsed"); .getAttribute("submitQueryResultParsed");
// add data // add data
@ -1301,8 +1441,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
} }
private synchronized void removeResultParsed(String submitQueryUID) { private synchronized void removeResultParsed(String submitQueryUID) {
ASLSession session = SessionUtil.getAslSession(this.getThreadLocalRequest() ASLSession session = SessionUtil.getAslSession(this
.getSession()); .getThreadLocalRequest().getSession());
HashMap<String, List<Row>> submitQueryResultParsed = (HashMap<String, List<Row>>) session HashMap<String, List<Row>> submitQueryResultParsed = (HashMap<String, List<Row>>) session
.getAttribute("submitQueryResultParsed"); .getAttribute("submitQueryResultParsed");
if (submitQueryResultParsed.containsKey(submitQueryUID)) { if (submitQueryResultParsed.containsKey(submitQueryUID)) {
@ -1327,8 +1467,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
} }
private synchronized void removeResult(String submitQueryUID) { private synchronized void removeResult(String submitQueryUID) {
ASLSession session = SessionUtil.getAslSession(this.getThreadLocalRequest() ASLSession session = SessionUtil.getAslSession(this
.getSession()); .getThreadLocalRequest().getSession());
HashMap<String, List<Result>> submitQueryResult = (HashMap<String, List<Result>>) session HashMap<String, List<Result>> submitQueryResult = (HashMap<String, List<Result>>) session
.getAttribute("submitQueryResult"); .getAttribute("submitQueryResult");
if (submitQueryResult.containsKey(submitQueryUID)) { if (submitQueryResult.containsKey(submitQueryUID)) {
@ -1354,8 +1494,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// remove job with the related status // remove job with the related status
private synchronized void removeJobStatus(String jobID) { private synchronized void removeJobStatus(String jobID) {
ASLSession session = SessionUtil.getAslSession(this.getThreadLocalRequest() ASLSession session = SessionUtil.getAslSession(this
.getSession()); .getThreadLocalRequest().getSession());
HashMap<String, String> JobStatusMap = (HashMap<String, String>) session HashMap<String, String> JobStatusMap = (HashMap<String, String>) session
.getAttribute("JobStatusList"); .getAttribute("JobStatusList");
String status = JobStatusMap.get(jobID); String status = JobStatusMap.get(jobID);
@ -1367,8 +1507,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// get job status // get job status
private synchronized String getJobStatus(String jobID) { private synchronized String getJobStatus(String jobID) {
ASLSession session = SessionUtil.getAslSession(this.getThreadLocalRequest() ASLSession session = SessionUtil.getAslSession(this
.getSession()); .getThreadLocalRequest().getSession());
HashMap<String, String> JobStatusMap = (HashMap<String, String>) session HashMap<String, String> JobStatusMap = (HashMap<String, String>) session
.getAttribute("JobStatusList"); .getAttribute("JobStatusList");
String status = JobStatusMap.get(jobID); String status = JobStatusMap.get(jobID);
@ -1628,8 +1768,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
} }
private String getUsername() { private String getUsername() {
// HttpSession httpSession = this.getThreadLocalRequest().getSession(); // HttpSession httpSession = this.getThreadLocalRequest().getSession();
// return SessionUtil.getUsername(httpSession); // return SessionUtil.getUsername(httpSession);
return "database.manager"; return "database.manager";
} }
@ -1813,9 +1953,51 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
employeeCache.remove(key); employeeCache.remove(key);
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
logger.error("dbmanager-> "+ e); logger.error("dbmanager-> " + e);
throw new Exception("Failure to clear the cache. " + e); throw new Exception("Failure to clear the cache. " + e);
} }
} }
private String storeResultIntoCSVFile(List<Result> result, String n)
throws Exception {
// file that will contain result
BufferedWriter out = null;
String path = this.getServletContext().getRealPath("");
String fileName = "";
fileName = n + "_" + System.currentTimeMillis() + ".csv";
String filePath = path + "/computationResult/" + fileName;
File file = new File(filePath);
try {
// create the file
if (!file.exists()) {
file.createNewFile();
}
out = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(file), "UTF-8"));
// write into file
for (int i = 0; i < result.size(); i++) {
out.write(result.get(i).getValue());
out.newLine();
}
} catch (Exception e) {
logger.error(e);
throw e;
} finally {
if (out != null) {
out.close();
}
}
return fileName;
}
} }