From faac5c9a051e76e43c15f4351dfd985b7824c105 Mon Sep 17 00:00:00 2001 From: Loredana Liccardo Date: Fri, 4 Jul 2014 10:09:47 +0000 Subject: [PATCH] smartSample implemented git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/databases-manager-portlet@98438 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/GWTdbManagerService.java | 3 + .../client/GWTdbManagerServiceAsync.java | 3 + .../client/events/EventsTypeEnum.java | 3 +- .../client/events/SmartSamplingEvent.java | 31 ++++ .../interfaces/SmartSamplingEventHandler.java | 12 ++ .../client/panels/GxtBorderLayoutPanel.java | 156 +++++++++++++++--- .../toolbar/GxtToolbarFunctionality.java | 5 + .../server/GWTdbManagerServiceImpl.java | 90 +++++++++- 8 files changed, 274 insertions(+), 29 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/databasesmanager/client/events/SmartSamplingEvent.java create mode 100644 src/main/java/org/gcube/portlets/user/databasesmanager/client/events/interfaces/SmartSamplingEventHandler.java diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/GWTdbManagerService.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/GWTdbManagerService.java index df534b5..a951ad7 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/client/GWTdbManagerService.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/GWTdbManagerService.java @@ -34,6 +34,9 @@ public interface GWTdbManagerService extends RemoteService { boolean smartCorrectionQuery, String language) throws Exception; List sample(LinkedHashMap dataInput) throws Exception; + + List smartSample(LinkedHashMap dataInput) throws Exception; + List parseCVSString(List result, List attrNames) throws Exception; diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/GWTdbManagerServiceAsync.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/GWTdbManagerServiceAsync.java index 59a58ae..74f81ca 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/client/GWTdbManagerServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/GWTdbManagerServiceAsync.java @@ -39,4 +39,7 @@ public interface GWTdbManagerServiceAsync { void getTableDetails(LinkedHashMap dataInput, AsyncCallback> callback); + void smartSample(LinkedHashMap dataInput, + AsyncCallback> callback); + } diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/EventsTypeEnum.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/EventsTypeEnum.java index 21a7008..673a3c1 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/EventsTypeEnum.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/EventsTypeEnum.java @@ -5,6 +5,7 @@ public enum EventsTypeEnum { SELECTED_ITEM_EVENT, SUBMIT_QUERY_EVENT, SHOW_CREATE_TABLE_EVENT, - SAMPLING_EVENT; + SAMPLING_EVENT, + SMART_SAMPLING_EVENT; } \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/SmartSamplingEvent.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/SmartSamplingEvent.java new file mode 100644 index 0000000..f21a690 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/SmartSamplingEvent.java @@ -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 { + + public static Type TYPE = new Type(); + + @Override + protected void dispatch(SmartSamplingEventHandler handler) { + // TODO Auto-generated method stub + + handler.onSmartSampling(this); + + } + + @Override + public Type getAssociatedType() { + // TODO Auto-generated method stub + return TYPE; + } + + public EventsTypeEnum getKey() { + + // TODO Auto-generated method stub + return EventsTypeEnum.SMART_SAMPLING_EVENT; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/interfaces/SmartSamplingEventHandler.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/interfaces/SmartSamplingEventHandler.java new file mode 100644 index 0000000..1d1fe15 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/events/interfaces/SmartSamplingEventHandler.java @@ -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); + +} diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/panels/GxtBorderLayoutPanel.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/panels/GxtBorderLayoutPanel.java index 9cce800..a486e68 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/client/panels/GxtBorderLayoutPanel.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/panels/GxtBorderLayoutPanel.java @@ -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 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 dataInput = new LinkedHashMap(); + + // 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>() { + + @Override + public void onFailure(Throwable caught) { + + // Window.alert(caught.getMessage()); + // System.out.println("FAILURE"); + rootLogger.log(Level.SEVERE, "FAILURE RPC smartSample"); + + MessageBox.alert("Error ", + "
Message:" + caught.getMessage(), null); + + } + + @Override + public void onSuccess(List result) { + + rootLogger.log(Level.SEVERE, "SUCCESS RPC smartSample"); + + rows = new ArrayList(); + + // 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) { - 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>() { @@ -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(); } diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/toolbar/GxtToolbarFunctionality.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/toolbar/GxtToolbarFunctionality.java index bb8ca11..f557a6d 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/client/toolbar/GxtToolbarFunctionality.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/toolbar/GxtToolbarFunctionality.java @@ -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 diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/server/GWTdbManagerServiceImpl.java b/src/main/java/org/gcube/portlets/user/databasesmanager/server/GWTdbManagerServiceImpl.java index c2c119c..f543972 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/server/GWTdbManagerServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/server/GWTdbManagerServiceImpl.java @@ -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 smartSample(LinkedHashMap dataInput) + throws Exception { + + + List inputParameters = new ArrayList(); + + // sample result + List output = new ArrayList(); + + // get list of algorithms + + List algorithms = new ArrayList(); + + 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 getTableDetails( LinkedHashMap 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 } - - }