randomSample implemented

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

View File

@ -37,6 +37,8 @@ public interface GWTdbManagerService extends RemoteService {
List<Result> smartSample(LinkedHashMap<String, String> dataInput) throws Exception;
List<Result> randomSample(LinkedHashMap<String, String> dataInput) throws Exception;
List<Row> parseCVSString(List<Result> result, List<String> attrNames)
throws Exception;

View File

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

View File

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

View File

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

View File

@ -0,0 +1,10 @@
package org.gcube.portlets.user.databasesmanager.client.events.interfaces;
import org.gcube.portlets.user.databasesmanager.client.events.RandomSamplingEvent;
import com.google.gwt.event.shared.EventHandler;
public interface RandomSamplingEventHandler extends EventHandler{
public void onRandomSampling(RandomSamplingEvent randomSamplingEvent);
}

View File

@ -12,11 +12,13 @@ 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.Row;
import org.gcube.portlets.user.databasesmanager.client.datamodel.SubmitQueryData;
import org.gcube.portlets.user.databasesmanager.client.events.RandomSamplingEvent;
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.RandomSamplingEventHandler;
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;
@ -48,7 +50,6 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.MessageBoxEvent;
public class GxtBorderLayoutPanel extends ContentPanel {
/* Create Root Logger */
@ -315,17 +316,32 @@ 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(SmartSamplingEvent.TYPE,
new SmartSamplingEventHandler() {
@Override
public void onSmartSampling(
SmartSamplingEvent smartSamplingEvent) {
// TODO Auto-generated method stub
smartSample();
}
});
eventBus.addHandler(RandomSamplingEvent.TYPE,
new RandomSamplingEventHandler() {
@Override
public void onRandomSampling(
RandomSamplingEvent randomSamplingEvent) {
// TODO Auto-generated method stub
randomSample();
}
});
eventBus.addHandler(ShowCreateTableEvent.TYPE,
new ShowCreateTableEventHandler() {
@ -634,16 +650,117 @@ public class GxtBorderLayoutPanel extends ContentPanel {
});
}
private void smartSample(){
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);
}
});
}
private void randomSample() {
// 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");
rootLogger.log(Level.SEVERE, "Start RPC - randomSample");
// get the selected table
@ -697,14 +814,14 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// call remote service
RPCservice.smartSample(dataInput, new AsyncCallback<List<Result>>() {
RPCservice.randomSample(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");
rootLogger.log(Level.SEVERE, "FAILURE RPC randomSample");
MessageBox.alert("Error ",
"<br/>Message:" + caught.getMessage(), null);
@ -714,7 +831,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
@Override
public void onSuccess(List<Result> result) {
rootLogger.log(Level.SEVERE, "SUCCESS RPC smartSample");
rootLogger.log(Level.SEVERE, "SUCCESS RPC randomSample");
rows = new ArrayList<Row>();
@ -734,8 +851,8 @@ public class GxtBorderLayoutPanel extends ContentPanel {
}
});
}
// start the parsing of the submit result in order to obtain a table

View File

@ -5,6 +5,7 @@ import java.util.logging.Logger;
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.RandomSamplingEvent;
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;
@ -314,6 +315,10 @@ public class GxtToolbarFunctionality {
@Override
public void componentSelected(ButtonEvent ce) {
// TODO Auto-generated method stub
//fire event
eventBus.fireEvent(new RandomSamplingEvent());
// TODO: insert the result of the sample operation

View File

@ -655,6 +655,85 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
return output;
}
@Override
public List<Result> randomSample(LinkedHashMap<String, String> dataInput)
throws Exception {
// TODO Auto-generated method stub
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("RANDOMSAMPLEONTABLE")) {
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(
@ -1199,4 +1278,6 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
}
}