smartSample implemented

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/databases-manager-portlet@98438 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Loredana Liccardo 2014-07-04 10:09:47 +00:00
parent 8412019b17
commit faac5c9a05
8 changed files with 274 additions and 29 deletions

View File

@ -34,6 +34,9 @@ public interface GWTdbManagerService extends RemoteService {
boolean smartCorrectionQuery, String language) throws Exception;
List<Result> sample(LinkedHashMap<String, String> dataInput) throws Exception;
List<Result> smartSample(LinkedHashMap<String, String> dataInput) throws Exception;
List<Row> parseCVSString(List<Result> result, List<String> attrNames)
throws Exception;

View File

@ -39,4 +39,7 @@ public interface GWTdbManagerServiceAsync {
void getTableDetails(LinkedHashMap<String, String> dataInput,
AsyncCallback<LinkedHashMap<String, FileModel>> callback);
void smartSample(LinkedHashMap<String, String> dataInput,
AsyncCallback<List<Result>> callback);
}

View File

@ -5,6 +5,7 @@ public enum EventsTypeEnum {
SELECTED_ITEM_EVENT,
SUBMIT_QUERY_EVENT,
SHOW_CREATE_TABLE_EVENT,
SAMPLING_EVENT;
SAMPLING_EVENT,
SMART_SAMPLING_EVENT;
}

View File

@ -0,0 +1,31 @@
package org.gcube.portlets.user.databasesmanager.client.events;
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.SmartSamplingEventHandler;
import com.google.gwt.event.shared.GwtEvent;
public class SmartSamplingEvent extends GwtEvent<SmartSamplingEventHandler> {
public static Type<SmartSamplingEventHandler> TYPE = new Type<SmartSamplingEventHandler>();
@Override
protected void dispatch(SmartSamplingEventHandler handler) {
// TODO Auto-generated method stub
handler.onSmartSampling(this);
}
@Override
public Type<SmartSamplingEventHandler> getAssociatedType() {
// TODO Auto-generated method stub
return TYPE;
}
public EventsTypeEnum getKey() {
// TODO Auto-generated method stub
return EventsTypeEnum.SMART_SAMPLING_EVENT;
}
}

View File

@ -0,0 +1,12 @@
package org.gcube.portlets.user.databasesmanager.client.events.interfaces;
import org.gcube.portlets.user.databasesmanager.client.events.ShowCreateTableEvent;
import org.gcube.portlets.user.databasesmanager.client.events.SmartSamplingEvent;
import com.google.gwt.event.shared.EventHandler;
public interface SmartSamplingEventHandler extends EventHandler{
public void onSmartSampling(SmartSamplingEvent smartSamplingEvent);
}

View File

@ -15,26 +15,15 @@ import org.gcube.portlets.user.databasesmanager.client.datamodel.SubmitQueryData
import org.gcube.portlets.user.databasesmanager.client.events.SamplingEvent;
import org.gcube.portlets.user.databasesmanager.client.events.SelectedItemEvent;
import org.gcube.portlets.user.databasesmanager.client.events.ShowCreateTableEvent;
import org.gcube.portlets.user.databasesmanager.client.events.SmartSamplingEvent;
import org.gcube.portlets.user.databasesmanager.client.events.SubmitQueryEvent;
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.SamplingEventHandler;
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.SelectedItemEventHandler;
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.ShowCreateTableEventHandler;
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.SmartSamplingEventHandler;
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.SubmitQueryEventHandler;
import org.gcube.portlets.user.databasesmanager.client.toolbar.GxtToolbarFunctionality;
import org.gcube.portlets.user.databasesmanager.client.utils.ConstantsPortlet;
//import org.gcube.portlets.user.dbmanager.client.GWTdbManagerServiceAsync;
//import org.gcube.portlets.user.dbmanager.client.datamodel.FileModel;
//import org.gcube.portlets.user.dbmanager.client.datamodel.Result;
//import org.gcube.portlets.user.dbmanager.client.datamodel.Row;
//import org.gcube.portlets.user.dbmanager.client.datamodel.SubmitQueryData;
//import org.gcube.portlets.user.dbmanager.client.events.SelectedItemEvent;
//import org.gcube.portlets.user.dbmanager.client.events.SubmitQueryEvent;
//import org.gcube.portlets.user.dbmanager.client.events.interfaces.SelectedItemEventHandler;
//import org.gcube.portlets.user.dbmanager.client.events.interfaces.SubmitQueryEventHandler;
//import org.gcube.portlets.user.dbmanager.client.toolbar.GxtToolbarFunctionality;
//import org.gcube.portlets.user.dbmanager.client.utils.ConstantsPortlet;
import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.store.ListStore;
@ -58,7 +47,7 @@ import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.MessageBoxEvent;
import com.extjs.gxt.ui.client.widget.button.Button;
public class GxtBorderLayoutPanel extends ContentPanel {
@ -326,6 +315,17 @@ public class GxtBorderLayoutPanel extends ContentPanel {
}
});
eventBus.addHandler(SmartSamplingEvent.TYPE, new SmartSamplingEventHandler() {
@Override
public void onSmartSampling(SmartSamplingEvent smartSamplingEvent) {
// TODO Auto-generated method stub
smartSample();
}
});
eventBus.addHandler(ShowCreateTableEvent.TYPE,
new ShowCreateTableEventHandler() {
@ -535,6 +535,8 @@ public class GxtBorderLayoutPanel extends ContentPanel {
private void sample() {
// to mask the entire content panel
this.mask("Loading", "x-mask-loading");
// System.out.println("Start RPC - submitQuery");
@ -631,14 +633,120 @@ public class GxtBorderLayoutPanel extends ContentPanel {
});
}
private void smartSample(){
// to mask the entire content panel
this.mask("Loading", "x-mask-loading");
// System.out.println("Start RPC - submitQuery");
rootLogger.log(Level.SEVERE, "Start RPC - smartSample");
// get the selected table
List<FileModel> data = treePanel.getTreePanel().getSelectionModel()
.getSelectedItems();
// the selected item is a table
FileModel selectedItem = data.get(0);
rootLogger.log(Level.INFO, "the selected table is: " + selectedItem);
// recover data inputs for the algorithm
LinkedHashMap<String, String> dataInput = new LinkedHashMap<String, String>();
// check if the table has an associated schema
FileModel schema;
FileModel database;
FileModel resource;
if (treePanel.getTreeStore().getParent(selectedItem).isSchema()) {
schema = treePanel.getTreeStore().getParent(selectedItem);
database = treePanel.getTreeStore().getParent(schema);
resource = treePanel.getTreeStore().getParent(database);
dataInput.put("ResourceName", resource.getName());
dataInput.put("DatabaseName", database.getName());
dataInput.put("SchemaName", schema.getName());
dataInput.put("TableName", selectedItem.getName());
rootLogger.log(Level.INFO, "ResourceName: " + resource.getName());
rootLogger.log(Level.INFO, "DatabaseName: " + database.getName());
rootLogger.log(Level.INFO, "SchemaName: " + schema.getName());
rootLogger.log(Level.INFO, "SchemaName: " + selectedItem.getName());
} else {
// the table has not a schema
database = treePanel.getTreeStore().getParent(selectedItem);
resource = treePanel.getTreeStore().getParent(database);
dataInput.put("ResourceName", resource.getName());
dataInput.put("DatabaseName", database.getName());
dataInput.put("SchemaName", "");
dataInput.put("TableName", selectedItem.getName());
rootLogger.log(Level.INFO, "ResourceName: " + resource.getName());
rootLogger.log(Level.INFO, "DatabaseName: " + database.getName());
rootLogger.log(Level.INFO, "SchemaName: " + "");
rootLogger.log(Level.INFO, "SchemaName: " + selectedItem.getName());
}
// call remote service
RPCservice.smartSample(dataInput, new AsyncCallback<List<Result>>() {
@Override
public void onFailure(Throwable caught) {
// Window.alert(caught.getMessage());
// System.out.println("FAILURE");
rootLogger.log(Level.SEVERE, "FAILURE RPC smartSample");
MessageBox.alert("Error ",
"<br/>Message:" + caught.getMessage(), null);
}
@Override
public void onSuccess(List<Result> result) {
rootLogger.log(Level.SEVERE, "SUCCESS RPC smartSample");
rows = new ArrayList<Row>();
// System.out.println("result size: " + result.size());
rootLogger.log(Level.SEVERE, "output size: " + result.size());
// get the attributes list for the result table
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);
}
});
}
// start the parsing of the submit result in order to obtain a table
private void parseResult(List<Result> result) {
if (this.isMasked()) {
this.unmask();
}
// if (this.isMasked()) {
// this.unmask();
// }
// to unmask the entire content panel
final GxtBorderLayoutPanel obj = this;
RPCservice.parseCVSString(result, listAttributes,
new AsyncCallback<List<Row>>() {
@ -727,6 +835,11 @@ public class GxtBorderLayoutPanel extends ContentPanel {
}
// }
if (obj.isMasked()) {
obj.unmask();
}
}
});
@ -927,6 +1040,8 @@ public class GxtBorderLayoutPanel extends ContentPanel {
private void getTableDetails(final FileModel selectedTable) {
// to mask the entire content panel
this.mask("Loading", "x-mask-loading");
// System.out.println("Start RPC - submitQuery");
@ -989,7 +1104,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
if (selectedTable.isTableDetailsDisplayed()) {
displayTableDetails(selectedTable);
} else {
// call remote service
@ -1079,9 +1194,8 @@ public class GxtBorderLayoutPanel extends ContentPanel {
selectedTable.setTableDetails(TableDetails);
displayTableDetails(selectedTable);
selectedTable.setTableDetailsDisplayed(true);
}
@ -1127,6 +1241,8 @@ public class GxtBorderLayoutPanel extends ContentPanel {
centerBottom.add(grid);
centerBottom.layout(true);
// to unmask the entire content panel
if (this.isMasked()) {
this.unmask();
}

View File

@ -7,6 +7,7 @@ import org.gcube.portlets.user.databasesmanager.client.GWTdbManagerServiceAsync;
import org.gcube.portlets.user.databasesmanager.client.datamodel.SubmitQueryData;
import org.gcube.portlets.user.databasesmanager.client.events.SamplingEvent;
import org.gcube.portlets.user.databasesmanager.client.events.ShowCreateTableEvent;
import org.gcube.portlets.user.databasesmanager.client.events.SmartSamplingEvent;
import org.gcube.portlets.user.databasesmanager.client.events.SubmitQueryEvent;
import org.gcube.portlets.user.databasesmanager.client.form.GxtFormSubmitQuery;
import org.gcube.portlets.user.databasesmanager.client.utils.ConstantsPortlet;
@ -277,6 +278,10 @@ public class GxtToolbarFunctionality {
@Override
public void componentSelected(ButtonEvent ce) {
// TODO Auto-generated method stub
//fire event
eventBus.fireEvent(new SmartSamplingEvent());
// TODO: insert the result of the sample operation

View File

@ -364,7 +364,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
rootLogger.log(Level.SEVERE, "output data retrieved");
System.out.println("size outputMap: " + outputMap.size());
// System.out.println("size outputMap: " + outputMap.size());
for (int i = 0; i < outputMap.size(); i++) {
@ -576,7 +576,86 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
return output;
}
@Override
public List<Result> smartSample(LinkedHashMap<String, String> dataInput)
throws Exception {
List<Parameter> inputParameters = new ArrayList<Parameter>();
// sample result
List<Result> output = new ArrayList<Result>();
// get list of algorithms
List<String> algorithms = new ArrayList<String>();
algorithms = getDatabaseManagerAlgorithms();
// get algorithmId
String algorithmId = null;
for (int i = 0; i < algorithms.size(); i++) {
if (algorithms.get(i).equals("SMARTSAMPLEONTABLE")) {
algorithmId = algorithms.get(i);
// System.out.println("algorithmId: " + algorithmId);
rootLogger.log(Level.SEVERE, "algorithmId: " + algorithmId);
}
}
// get input parameters of the algorithm
rootLogger.log(Level.SEVERE, "getting input parameters");
inputParameters = getParameters(algorithmId);
for (int i = 0; i < inputParameters.size(); i++) {
// System.out.println(inputParameters.get(i).getName());
rootLogger.log(Level.INFO, inputParameters.get(i).getName());
}
inputParameters.get(0).setValue(dataInput.get("ResourceName"));
inputParameters.get(1).setValue(dataInput.get("DatabaseName"));
inputParameters.get(2).setValue(dataInput.get("SchemaName"));
inputParameters.get(3).setValue(dataInput.get("TableName"));
// System.out.println("size outputMap pre computation: "
// + outputMap.size());
String computationId = startComputation(algorithmId, inputParameters);
// retrieve data
// System.out.println("output data retrieved");
// System.out.println("size outputMap: " + outputMap.size());
rootLogger.log(Level.SEVERE, "output data retrieved");
rootLogger.log(Level.SEVERE, "output data size: " + outputMap.size());
for (int i = 0; i < outputMap.size(); i++) {
Result row = new Result(outputKey.get(String.valueOf(i)),
outputMap.get(String.valueOf(i)));
output.add(row);
}
return output;
}
@Override
public LinkedHashMap<String, FileModel> getTableDetails(
LinkedHashMap<String, String> dataInput) throws Exception {
@ -643,7 +722,6 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
rootLogger.log(Level.SEVERE, "output data retrieved");
rootLogger.log(Level.SEVERE, "output data size: " + outputMap.size());
for (int i = 0; i < outputMap.size(); i++) {
// outputParameters.add(outputKey.get(String.valueOf(i)) + " "
@ -662,9 +740,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
outputParameters.put(outputKey.get(String.valueOf(i)), obj);
}
return outputParameters;
}
@ -1123,6 +1199,4 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
}
}