- 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:
parent
d9735e3f44
commit
10007df08a
|
@ -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.Result;
|
||||
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.PagingLoadResult;
|
||||
import com.google.gwt.user.client.rpc.RemoteService;
|
||||
|
@ -24,18 +27,18 @@ public interface GWTdbManagerService extends RemoteService {
|
|||
List<FileModel> getDBSchema(LinkedHashMap<String, String> dataInput)
|
||||
throws Exception;
|
||||
|
||||
List<String> submitQuery(LinkedHashMap<String, String> dataDB,
|
||||
SubmitQueryResultWithFileFromServlet submitQuery(LinkedHashMap<String, String> dataDB,
|
||||
String query, boolean valueReadOnlyQuery,
|
||||
boolean smartCorrectionQuery, String language, String UID)
|
||||
throws Exception;
|
||||
|
||||
List<Result> sample(LinkedHashMap<String, String> dataInput)
|
||||
SamplingResultWithFileFromServlet sample(LinkedHashMap<String, String> dataInput)
|
||||
throws Exception;
|
||||
|
||||
List<Result> smartSample(LinkedHashMap<String, String> dataInput)
|
||||
SamplingResultWithFileFromServlet smartSample(LinkedHashMap<String, String> dataInput)
|
||||
throws Exception;
|
||||
|
||||
List<Result> randomSample(LinkedHashMap<String, String> dataInput)
|
||||
SamplingResultWithFileFromServlet randomSample(LinkedHashMap<String, String> dataInput)
|
||||
throws Exception;
|
||||
|
||||
List<Row> parseCVSString(List<Result> result, List<String> attrNames)
|
||||
|
|
|
@ -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.GeneralOutputFromServlet;
|
||||
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.SubmitQueryResultWithFileFromServlet;
|
||||
|
||||
import com.extjs.gxt.ui.client.data.PagingLoadConfig;
|
||||
import com.extjs.gxt.ui.client.data.PagingLoadResult;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
|
@ -23,22 +26,22 @@ public interface GWTdbManagerServiceAsync {
|
|||
|
||||
void submitQuery(LinkedHashMap<String, String> dataDB, String query,
|
||||
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,
|
||||
AsyncCallback<List<Row>> callback);
|
||||
|
||||
void sample(LinkedHashMap<String, String> dataInput,
|
||||
AsyncCallback<List<Result>> callback);
|
||||
AsyncCallback<SamplingResultWithFileFromServlet> callback);
|
||||
|
||||
void getTableDetails(LinkedHashMap<String, String> dataInput,
|
||||
AsyncCallback<LinkedHashMap<String, FileModel>> callback);
|
||||
|
||||
void smartSample(LinkedHashMap<String, String> dataInput,
|
||||
AsyncCallback<List<Result>> callback);
|
||||
AsyncCallback<SamplingResultWithFileFromServlet> callback);
|
||||
|
||||
void randomSample(LinkedHashMap<String, String> dataInput,
|
||||
AsyncCallback<List<Result>> callback);
|
||||
AsyncCallback<SamplingResultWithFileFromServlet> callback);
|
||||
|
||||
void LoadTables(PagingLoadConfig config,
|
||||
LinkedHashMap<String, String> dataInput, boolean SearchTable,
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
package org.gcube.portlets.user.databasesmanager.client.datamodel;
|
||||
|
||||
import java.io.Serializable;
|
||||
//import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
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.
|
||||
//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;
|
||||
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
|
@ -10,8 +10,10 @@ import java.util.logging.Logger;
|
|||
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.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.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.RandomSamplingEvent;
|
||||
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.google.gwt.event.dom.client.KeyCodes;
|
||||
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.ui.HTML;
|
||||
import com.extjs.gxt.ui.client.data.BasePagingLoadConfig;
|
||||
import com.extjs.gxt.ui.client.data.BasePagingLoader;
|
||||
import com.extjs.gxt.ui.client.data.PagingLoadConfig;
|
||||
|
@ -311,15 +315,15 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
getTableDetails(table);
|
||||
}
|
||||
});
|
||||
|
||||
eventBus.addHandler(RefreshDataEvent.TYPE, new RefreshDataEventHandler() {
|
||||
|
||||
@Override
|
||||
public void onRefreshData(RefreshDataEvent refreshDataEvent) {
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
eventBus.addHandler(RefreshDataEvent.TYPE,
|
||||
new RefreshDataEventHandler() {
|
||||
|
||||
@Override
|
||||
public void onRefreshData(RefreshDataEvent refreshDataEvent) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// method to load the tables list
|
||||
|
@ -330,8 +334,8 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
// disable table details and sampling buttons
|
||||
toolbar.disableButtonsOperationsOnTable();
|
||||
// clear the panel
|
||||
// centerBottom.removeAll();
|
||||
// centerBottom.layout(true);
|
||||
// centerBottom.removeAll();
|
||||
// centerBottom.layout(true);
|
||||
|
||||
// get the selected item
|
||||
List<FileModel> data = treePanel.getTreePanel().getSelectionModel()
|
||||
|
@ -392,11 +396,12 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
// hide the dialog
|
||||
tablesLoaded.hide();
|
||||
|
||||
if (caught
|
||||
.getMessage()
|
||||
.contains("Result not available")) {
|
||||
MessageBox.alert("Warning ", "<br/>Message:"
|
||||
+ "no tables available", null);
|
||||
if (caught.getMessage().contains(
|
||||
"Result not available")) {
|
||||
MessageBox.alert("Warning ",
|
||||
"<br/>Message:"
|
||||
+ "no tables available",
|
||||
null);
|
||||
} else {
|
||||
MessageBox.alert("Error ", "<br/>Message:"
|
||||
+ caught.getMessage(), null);
|
||||
|
@ -412,26 +417,26 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
rootLogger.log(Level.SEVERE,
|
||||
"SUCCESS RPC LoadTables");
|
||||
callback.onSuccess(result);
|
||||
|
||||
|
||||
if (keyword == null) {
|
||||
startSearchTable = false;
|
||||
}
|
||||
// enable toolbar in the dialog
|
||||
toolBarTop.enable();
|
||||
|
||||
if (result!=null){
|
||||
|
||||
|
||||
if (result != null) {
|
||||
|
||||
List<Result> data = result.getData();
|
||||
if (data.size()==0){
|
||||
MessageBox.alert("Warning ", "<br/>Message:"
|
||||
+ "no tables availables", null);
|
||||
if (data.size() == 0) {
|
||||
MessageBox
|
||||
.alert("Warning ",
|
||||
"<br/>Message:"
|
||||
+ "no tables availables",
|
||||
null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
// rootLogger.log(Level.SEVERE, "End RPC LoadTables");
|
||||
|
@ -690,22 +695,23 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
keyword = null;
|
||||
startSearchTable = false;
|
||||
if (selectedTable != null) {
|
||||
//refresh the content in the two panels
|
||||
// refresh the content in the two panels
|
||||
centerBottom.removeAll();
|
||||
centerBottom.layout(true);
|
||||
centerUpper.removeAll();
|
||||
centerUpper.layout(true);
|
||||
|
||||
|
||||
// display the table in the panel "Database Information"
|
||||
displayTableName(selectedTable);
|
||||
|
||||
|
||||
// to get the selected item in the tree panel
|
||||
List<FileModel> data = treePanel.getTreePanel()
|
||||
.getSelectionModel().getSelectedItems();
|
||||
FileModel selectedItem = data.get(0);
|
||||
|
||||
|
||||
// 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;
|
||||
startSearchTable = false;
|
||||
// refresh the database information panel
|
||||
// centerUpper.removeAll();
|
||||
// centerUpper.layout(true);
|
||||
// centerUpper.removeAll();
|
||||
// centerUpper.layout(true);
|
||||
tablesLoaded.hide();
|
||||
}
|
||||
});
|
||||
|
@ -803,7 +809,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
// remote rpc
|
||||
RPCservice.submitQuery(dataForSubmitQuery, dataQuery.getQuery(), true,
|
||||
dataQuery.getSmartCorrection(), language, UID,
|
||||
new AsyncCallback<List<String>>() {
|
||||
new AsyncCallback<SubmitQueryResultWithFileFromServlet>() {
|
||||
|
||||
// TODO: TO REMOVE data "true" as input if you manage the
|
||||
// read-only query in the form
|
||||
|
@ -833,9 +839,9 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
"Result not available")) {
|
||||
MessageBox.alert("Warning ", "<br/>Message:"
|
||||
+ "The query returned 0 values", null);
|
||||
}else{
|
||||
MessageBox.alert("Error ",
|
||||
"<br/>Message:" + caught.getMessage(), null);
|
||||
} else {
|
||||
MessageBox.alert("Error ", "<br/>Message:"
|
||||
+ caught.getMessage(), null);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -854,84 +860,93 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(List<String> listAttributes) {
|
||||
public void onSuccess(SubmitQueryResultWithFileFromServlet obj) {
|
||||
rootLogger.log(Level.SEVERE, "SUCCESS RPC submitQuery");
|
||||
|
||||
if (form.getBody().isMasked())
|
||||
form.getBody().unmask();
|
||||
if (obj != null){
|
||||
//get list attributes
|
||||
List<String> listAttributes = obj.getListOutput();
|
||||
|
||||
if (form.getBody().isMasked())
|
||||
form.getBody().unmask();
|
||||
|
||||
if (form.getButtonById(Dialog.OK).isEnabled() == false) {
|
||||
form.getButtonById(Dialog.OK).enable();
|
||||
if (form.getButtonById(Dialog.OK).isEnabled() == false) {
|
||||
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
|
||||
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;
|
||||
// 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:"
|
||||
+ caught.getMessage(), l);
|
||||
callback.onFailure(caught);
|
||||
|
@ -991,10 +1006,13 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
rootLogger
|
||||
.log(Level.SEVERE,
|
||||
"No results have been returned");
|
||||
|
||||
MessageBox.alert("Warning ", "<br/>Message:"
|
||||
+ "The query returned 0 values", null);
|
||||
|
||||
|
||||
MessageBox
|
||||
.alert("Warning ",
|
||||
"<br/>Message:"
|
||||
+ "The query returned 0 values",
|
||||
null);
|
||||
|
||||
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.show();
|
||||
}
|
||||
|
@ -1189,39 +1224,88 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
obj.mask("Sampling the table", "x-mask-loading");
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
RPCservice.sample(dataInput,
|
||||
new AsyncCallback<SamplingResultWithFileFromServlet>() {
|
||||
@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);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onSuccess(SamplingResultWithFileFromServlet obj) {
|
||||
rootLogger.log(Level.SEVERE, "SUCCESS RPC sample");
|
||||
|
||||
if (obj != null) {
|
||||
// get data
|
||||
List<Result> result = obj.getListOutput();
|
||||
// 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);
|
||||
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
|
||||
|
@ -1274,39 +1358,50 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
obj.mask("Sampling the table", "x-mask-loading");
|
||||
|
||||
// call remote service
|
||||
RPCservice.smartSample(dataInput, new AsyncCallback<List<Result>>() {
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
// Window.alert(caught.getMessage());
|
||||
rootLogger.log(Level.SEVERE, "FAILURE RPC smartSample");
|
||||
if (caught.getMessage().contains("The table has 0 rows")) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
RPCservice.smartSample(dataInput,
|
||||
new AsyncCallback<SamplingResultWithFileFromServlet>() {
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
// Window.alert(caught.getMessage());
|
||||
rootLogger.log(Level.SEVERE, "FAILURE RPC smartSample");
|
||||
if (caught.getMessage()
|
||||
.contains("The table has 0 rows")) {
|
||||
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 smartSample");
|
||||
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);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onSuccess(SamplingResultWithFileFromServlet obj) {
|
||||
rootLogger.log(Level.SEVERE, "SUCCESS RPC smartSample");
|
||||
|
||||
if (obj != null) {
|
||||
// get data
|
||||
List<Result> result = obj.getListOutput();
|
||||
// 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);
|
||||
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
|
||||
|
@ -1361,44 +1456,57 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
obj.mask("Sampling the table", "x-mask-loading");
|
||||
|
||||
// call remote service
|
||||
RPCservice.randomSample(dataInput, new AsyncCallback<List<Result>>() {
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
// Window.alert(caught.getMessage());
|
||||
rootLogger.log(Level.SEVERE, "FAILURE RPC randomSample");
|
||||
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();
|
||||
}
|
||||
}
|
||||
RPCservice.randomSample(dataInput,
|
||||
new AsyncCallback<SamplingResultWithFileFromServlet>() {
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
// Window.alert(caught.getMessage());
|
||||
rootLogger
|
||||
.log(Level.SEVERE, "FAILURE RPC randomSample");
|
||||
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 randomSample");
|
||||
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);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onSuccess(SamplingResultWithFileFromServlet obj) {
|
||||
rootLogger
|
||||
.log(Level.SEVERE, "SUCCESS RPC randomSample");
|
||||
|
||||
if (obj != null) {
|
||||
// get data
|
||||
List<Result> result = obj.getListOutput();
|
||||
// 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);
|
||||
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
|
||||
private void parseResult(List<Result> result,
|
||||
final List<String> listAttributes) {
|
||||
final List<String> listAttributes, final String fileName) {
|
||||
// to unmask the entire content panel
|
||||
final GxtBorderLayoutPanel obj = this;
|
||||
// final Dialog form = dialog;
|
||||
|
@ -1436,6 +1544,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
if (rows != null) {
|
||||
// Display the submit query result as a table
|
||||
Dialog sampleResult = new Dialog() {
|
||||
|
||||
// override the maximize event modifying it with
|
||||
// a different behaviour if the mimimize event
|
||||
// occurs
|
||||
|
@ -1446,6 +1555,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
super.maximize();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// 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.show();
|
||||
|
||||
|
@ -1841,7 +1967,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
final Result table = new Result("Selected table", tableName);
|
||||
final ListStore<Result> store = new ListStore<Result>();
|
||||
store.add(table);
|
||||
|
||||
|
||||
// create column configuration
|
||||
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
|
||||
ColumnConfig column = new ColumnConfig();
|
||||
|
@ -1857,19 +1983,21 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
|
||||
TextField<String> textValue = new TextField<String>();
|
||||
// text.setAllowBlank(false);
|
||||
// column.setEditor(new CellEditor(textValue));
|
||||
column.setEditor(new CellEditor(textValue){
|
||||
// public Object preProcessValue(Object value) {
|
||||
// System.out.println("value 1: " + store.getModels().get(0).getValue());
|
||||
// return store.getModels().get(0).getValue();
|
||||
// }
|
||||
// column.setEditor(new CellEditor(textValue));
|
||||
column.setEditor(new CellEditor(textValue) {
|
||||
// public Object preProcessValue(Object value) {
|
||||
// System.out.println("value 1: " +
|
||||
// store.getModels().get(0).getValue());
|
||||
// return store.getModels().get(0).getValue();
|
||||
// }
|
||||
public Object postProcessValue(Object value) {
|
||||
// System.out.println("value: " + store.findModel(table).getValue());
|
||||
return store.findModel(table).getValue();
|
||||
// System.out.println("value: " +
|
||||
// store.findModel(table).getValue());
|
||||
return store.findModel(table).getValue();
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
configs.add(column);
|
||||
ColumnModel cm = new ColumnModel(configs);
|
||||
|
||||
|
|
|
@ -899,6 +899,7 @@ public class GxtTreePanel extends LayoutContainer {
|
|||
|
||||
if (result != null) {
|
||||
// remove children
|
||||
|
||||
removeChildren(selectedItem);
|
||||
tree.layout(true);
|
||||
|
||||
|
|
|
@ -5,13 +5,21 @@ 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;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import net.sf.ehcache.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.Parameter;
|
||||
import org.gcube.portlets.user.databasesmanager.client.datamodel.Result;
|
||||
import org.gcube.portlets.user.databasesmanager.client.datamodel.SamplingResultWithFileFromServlet;
|
||||
import org.gcube.portlets.user.databasesmanager.client.datamodel.Row;
|
||||
import org.gcube.portlets.user.databasesmanager.client.datamodel.SubmitQueryResultWithFileFromServlet;
|
||||
import org.gcube.portlets.user.databasesmanager.client.utils.ConstantsPortlet;
|
||||
import org.gcube.portlets.user.databasesmanager.server.util.SessionUtil;
|
||||
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 org.apache.log4j.Logger;
|
||||
|
||||
|
||||
public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||
GWTdbManagerService {
|
||||
|
||||
|
@ -90,7 +99,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
CacheManager cacheManager = CacheManager.newInstance(url);
|
||||
// getcache
|
||||
employeeCache = cacheManager.getEhcache("DBCache");
|
||||
String path = System.getenv("CATALINA_TMPDIR");
|
||||
// String path = System.getenv("CATALINA_TMPDIR");
|
||||
// CacheConfiguration config =
|
||||
// employeeCache.getCacheConfiguration();
|
||||
// String DiskCacheFolderName = "DBManagerDisk";
|
||||
|
@ -107,9 +116,23 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
|
||||
} catch (Exception e) {
|
||||
logger.error("dbmanager-> Failed to get cache: " + e);
|
||||
// e.printStackTrace();
|
||||
// e.printStackTrace();
|
||||
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() {
|
||||
|
@ -130,15 +153,15 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
logger.error("dbmanager-> " + e);
|
||||
// e.printStackTrace();
|
||||
// e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void initVariables() {
|
||||
|
||||
ASLSession session = SessionUtil.getAslSession(this.getThreadLocalRequest()
|
||||
.getSession());
|
||||
ASLSession session = SessionUtil.getAslSession(this
|
||||
.getThreadLocalRequest().getSession());
|
||||
|
||||
// the result generated in the LoadTables method
|
||||
// List<Result> result = new ArrayList<Result>();
|
||||
|
@ -247,7 +270,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
key, outputParameters);
|
||||
|
||||
insertDataIntoCache(dataToCache);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -348,7 +371,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
// e.printStackTrace();
|
||||
// e.printStackTrace();
|
||||
// throw new Exception("Failed to load data " + );
|
||||
logger.error("dbmanager-> " + e);
|
||||
throw e;
|
||||
|
@ -450,7 +473,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
// e.printStackTrace();
|
||||
// e.printStackTrace();
|
||||
// throw new Exception("Failed to load data. " + e);
|
||||
logger.error("dbmanager-> " + e);
|
||||
throw e;
|
||||
|
@ -690,10 +713,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
|
||||
// to submit a query
|
||||
@Override
|
||||
public List<String> submitQuery(LinkedHashMap<String, String> dataDB,
|
||||
String query, boolean valueReadOnlyQuery,
|
||||
boolean smartCorrectionQuery, String language, String UID)
|
||||
throws Exception {
|
||||
public SubmitQueryResultWithFileFromServlet submitQuery(
|
||||
LinkedHashMap<String, String> dataDB, String query,
|
||||
boolean valueReadOnlyQuery, boolean smartCorrectionQuery,
|
||||
String language, String UID) throws Exception {
|
||||
|
||||
logger.info("dbmanager-> Dialect used for smart correction: "
|
||||
+ language);
|
||||
|
@ -796,6 +819,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
}
|
||||
} catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
|
||||
// TODO TO REMOVE. Exception Statistical management to remove a
|
||||
// computation
|
||||
if (e.getMessage()
|
||||
|
@ -807,12 +831,95 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
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
|
||||
public List<Result> sample(LinkedHashMap<String, String> dataInput)
|
||||
throws Exception {
|
||||
public SamplingResultWithFileFromServlet sample(
|
||||
LinkedHashMap<String, String> dataInput) throws Exception {
|
||||
// data input
|
||||
List<Parameter> inputParameters = new ArrayList<Parameter>();
|
||||
// output sample result
|
||||
|
@ -870,12 +977,23 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
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
|
||||
public List<Result> smartSample(LinkedHashMap<String, String> dataInput)
|
||||
throws Exception {
|
||||
public SamplingResultWithFileFromServlet smartSample(
|
||||
LinkedHashMap<String, String> dataInput) throws Exception {
|
||||
// data input
|
||||
List<Parameter> inputParameters = new ArrayList<Parameter>();
|
||||
// output sample result
|
||||
|
@ -933,12 +1051,23 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
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
|
||||
public List<Result> randomSample(LinkedHashMap<String, String> dataInput)
|
||||
throws Exception {
|
||||
public SamplingResultWithFileFromServlet randomSample(
|
||||
LinkedHashMap<String, String> dataInput) throws Exception {
|
||||
|
||||
// data input
|
||||
List<Parameter> inputParameters = new ArrayList<Parameter>();
|
||||
|
@ -997,7 +1126,18 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
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
|
||||
|
@ -1260,8 +1400,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
// }
|
||||
|
||||
private synchronized List<Result> getSubmitQueryResult(String submitQueryUID) {
|
||||
ASLSession session = SessionUtil.getAslSession(this.getThreadLocalRequest()
|
||||
.getSession());
|
||||
ASLSession session = SessionUtil.getAslSession(this
|
||||
.getThreadLocalRequest().getSession());
|
||||
HashMap<String, List<Result>> submitQueryResult = (HashMap<String, List<Result>>) session
|
||||
.getAttribute("submitQueryResult");
|
||||
if (submitQueryResult.containsKey(submitQueryUID)) {
|
||||
|
@ -1273,8 +1413,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
|
||||
private synchronized List<Row> getSubmitQueryResultParsed(
|
||||
String submitQueryUID) {
|
||||
ASLSession session = SessionUtil.getAslSession(this.getThreadLocalRequest()
|
||||
.getSession());
|
||||
ASLSession session = SessionUtil.getAslSession(this
|
||||
.getThreadLocalRequest().getSession());
|
||||
HashMap<String, List<Row>> submitQueryResultParsed = (HashMap<String, List<Row>>) session
|
||||
.getAttribute("submitQueryResultParsed");
|
||||
|
||||
|
@ -1288,8 +1428,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
|
||||
private synchronized void updateSubmitQueryResultParsed(
|
||||
String submitQueryUID, List<Row> data) {
|
||||
ASLSession session = SessionUtil.getAslSession(this.getThreadLocalRequest()
|
||||
.getSession());
|
||||
ASLSession session = SessionUtil.getAslSession(this
|
||||
.getThreadLocalRequest().getSession());
|
||||
HashMap<String, List<Row>> submitQueryResultParsed = (HashMap<String, List<Row>>) session
|
||||
.getAttribute("submitQueryResultParsed");
|
||||
// add data
|
||||
|
@ -1301,8 +1441,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
}
|
||||
|
||||
private synchronized void removeResultParsed(String submitQueryUID) {
|
||||
ASLSession session = SessionUtil.getAslSession(this.getThreadLocalRequest()
|
||||
.getSession());
|
||||
ASLSession session = SessionUtil.getAslSession(this
|
||||
.getThreadLocalRequest().getSession());
|
||||
HashMap<String, List<Row>> submitQueryResultParsed = (HashMap<String, List<Row>>) session
|
||||
.getAttribute("submitQueryResultParsed");
|
||||
if (submitQueryResultParsed.containsKey(submitQueryUID)) {
|
||||
|
@ -1327,8 +1467,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
}
|
||||
|
||||
private synchronized void removeResult(String submitQueryUID) {
|
||||
ASLSession session = SessionUtil.getAslSession(this.getThreadLocalRequest()
|
||||
.getSession());
|
||||
ASLSession session = SessionUtil.getAslSession(this
|
||||
.getThreadLocalRequest().getSession());
|
||||
HashMap<String, List<Result>> submitQueryResult = (HashMap<String, List<Result>>) session
|
||||
.getAttribute("submitQueryResult");
|
||||
if (submitQueryResult.containsKey(submitQueryUID)) {
|
||||
|
@ -1354,8 +1494,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
|
||||
// remove job with the related status
|
||||
private synchronized void removeJobStatus(String jobID) {
|
||||
ASLSession session = SessionUtil.getAslSession(this.getThreadLocalRequest()
|
||||
.getSession());
|
||||
ASLSession session = SessionUtil.getAslSession(this
|
||||
.getThreadLocalRequest().getSession());
|
||||
HashMap<String, String> JobStatusMap = (HashMap<String, String>) session
|
||||
.getAttribute("JobStatusList");
|
||||
String status = JobStatusMap.get(jobID);
|
||||
|
@ -1367,8 +1507,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
|
||||
// get job status
|
||||
private synchronized String getJobStatus(String jobID) {
|
||||
ASLSession session = SessionUtil.getAslSession(this.getThreadLocalRequest()
|
||||
.getSession());
|
||||
ASLSession session = SessionUtil.getAslSession(this
|
||||
.getThreadLocalRequest().getSession());
|
||||
HashMap<String, String> JobStatusMap = (HashMap<String, String>) session
|
||||
.getAttribute("JobStatusList");
|
||||
String status = JobStatusMap.get(jobID);
|
||||
|
@ -1628,8 +1768,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
}
|
||||
|
||||
private String getUsername() {
|
||||
// HttpSession httpSession = this.getThreadLocalRequest().getSession();
|
||||
// return SessionUtil.getUsername(httpSession);
|
||||
// HttpSession httpSession = this.getThreadLocalRequest().getSession();
|
||||
// return SessionUtil.getUsername(httpSession);
|
||||
return "database.manager";
|
||||
}
|
||||
|
||||
|
@ -1813,9 +1953,51 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
employeeCache.remove(key);
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
logger.error("dbmanager-> "+ e);
|
||||
logger.error("dbmanager-> " + 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;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue