From a38018ff3a8d1b8206377d818097b4fe15292399 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Mon, 17 Feb 2014 17:40:04 +0000 Subject: [PATCH] Minor Updated git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-expression-widget@91799 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 1 + pom.xml | 51 +++-- .../expressionwidget/ExpressionWidget.gwt.xml | 2 +- .../client/ColumnExpressionPanel.java | 204 ++++++++++-------- .../client/FilterColumnDialog.java | 124 +++++++++++ .../client/rpc/ExpressionService.java | 3 +- .../client/rpc/ExpressionServiceAsync.java | 3 +- .../server/ExpressionServiceImpl.java | 90 ++++++++ .../expressionwidget/ExpressionWidget.gwt.xml | 2 +- 9 files changed, 372 insertions(+), 108 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/td/expressionwidget/client/FilterColumnDialog.java create mode 100644 src/main/java/org/gcube/portlets/user/td/expressionwidget/server/ExpressionServiceImpl.java diff --git a/.classpath b/.classpath index 8ed3615..3a5b2af 100644 --- a/.classpath +++ b/.classpath @@ -30,6 +30,7 @@ + diff --git a/pom.xml b/pom.xml index 88ed1d1..6d6fdec 100644 --- a/pom.xml +++ b/pom.xml @@ -14,15 +14,15 @@ org.gcube.portlets.user tabular-data-expression-widget 1.0.0-SNAPSHOT - + tabular-data-expression-widget tabular-data-expression-widget allows to create expression on tabular resource - + https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-expression-widget - + Giancarlo Panichi @@ -34,7 +34,7 @@ - + ${project.basedir}/distro ${project.build.directory}/${project.build.finalName} @@ -42,7 +42,7 @@ templates distro config - + 2.5.1 org.gcube.portlets.user @@ -137,7 +147,7 @@ slf4j-api - + junit @@ -145,8 +155,8 @@ 4.8.1 test - - + + @@ -163,8 +173,8 @@ - - + + org.apache.maven.plugins @@ -182,7 +192,7 @@ - + org.codehaus.mojo @@ -201,7 +211,7 @@ org.gcube.portlets.user.td.expressionwidget.ExpressionWidget - + maven-resources-plugin @@ -305,4 +315,5 @@ + war diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/ExpressionWidget.gwt.xml b/src/main/java/org/gcube/portlets/user/td/expressionwidget/ExpressionWidget.gwt.xml index 6e59e72..676dc35 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/ExpressionWidget.gwt.xml +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/ExpressionWidget.gwt.xml @@ -23,7 +23,7 @@ - + diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ColumnExpressionPanel.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ColumnExpressionPanel.java index 49aa5fd..b5b62a9 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ColumnExpressionPanel.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ColumnExpressionPanel.java @@ -7,14 +7,12 @@ import org.gcube.portlets.user.td.widgetcommonevent.client.type.ExpressionType; import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression; import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_ExpressionContainer; -import com.google.web.bindery.event.shared.EventBus; - import com.allen_sauer.gwt.log.client.Log; +import com.google.web.bindery.event.shared.EventBus; import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign; import com.sencha.gxt.core.client.dom.ScrollSupport.ScrollMode; import com.sencha.gxt.core.client.util.Margins; import com.sencha.gxt.widget.core.client.FramedPanel; -import com.sencha.gxt.widget.core.client.button.CellButtonBase; import com.sencha.gxt.widget.core.client.button.TextButton; import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutData; import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutPack; @@ -35,61 +33,79 @@ import com.sencha.gxt.widget.core.client.form.TextField; * */ public class ColumnExpressionPanel extends FramedPanel { + private enum ColumnExpressionPanelType { + ColumnFilter, ColumnRule; + } + + protected ColumnExpressionPanelType type; protected String WIDTH = "640px"; protected String HEIGHT = "520px"; protected EventBus eventBus; - - protected ColumnExpressionDialog parent; + + protected ColumnExpressionDialog parentRuleDialog; + protected FilterColumnDialog parentFilterDialog; protected ColumnData column; protected ConditionWidget conditionWidget; - - + private TextButton btnApply; + private TextButton btnSearch; + private TextButton btnSave; + private TextButton btnClose; + + public ColumnExpressionPanel(FilterColumnDialog parentFilterDialog, ColumnData column) { + type = ColumnExpressionPanelType.ColumnFilter; + this.parentFilterDialog=parentFilterDialog; + } + /** * * @param trId * @param columnName */ - public ColumnExpressionPanel(ColumnExpressionDialog parent, ColumnData column, EventBus eventBus) { - this.parent=parent; + public ColumnExpressionPanel(ColumnExpressionDialog parent, + ColumnData column, EventBus eventBus) { + type = ColumnExpressionPanelType.ColumnRule; + this.parentRuleDialog = parent; this.column = column; - this.eventBus=eventBus; + this.eventBus = eventBus; Log.debug(column.toString()); - + create(); } protected void create() { setBodyBorder(false); setHeaderVisible(false); - + VerticalLayoutContainer basicLayout = new VerticalLayoutContainer(); basicLayout.setScrollMode(ScrollMode.AUTO); basicLayout.setAdjustForScroll(true); - - FieldSet properties = new FieldSet(); - properties.setHeadingText("Properties"); - properties.setCollapsible(false); - - VerticalLayoutContainer propertiesLayout = new VerticalLayoutContainer(); - properties.add(propertiesLayout); - TextField columnType = new TextField(); - columnType.setToolTip("The type of column"); - columnType.setReadOnly(true); - columnType.setValue(column.getTypeCode()); - propertiesLayout.add(new FieldLabel(columnType, "Column Type"), - new VerticalLayoutData(1, -1)); + FieldSet properties=null; + if (type == ColumnExpressionPanelType.ColumnRule) { + properties = new FieldSet(); + properties.setHeadingText("Properties"); + properties.setCollapsible(false); - - TextField dataType = new TextField(); - dataType.setToolTip("The data type"); - dataType.setReadOnly(true); - dataType.setValue(column.getDataTypeName()); - propertiesLayout.add(new FieldLabel(dataType, "Data Type"), - new VerticalLayoutData(1, -1)); + VerticalLayoutContainer propertiesLayout = new VerticalLayoutContainer(); + properties.add(propertiesLayout); + TextField columnType = new TextField(); + columnType.setToolTip("The type of column"); + columnType.setReadOnly(true); + columnType.setValue(column.getTypeCode()); + propertiesLayout.add(new FieldLabel(columnType, "Column Type"), + new VerticalLayoutData(1, -1)); + + TextField dataType = new TextField(); + dataType.setToolTip("The data type"); + dataType.setReadOnly(true); + dataType.setValue(column.getDataTypeName()); + propertiesLayout.add(new FieldLabel(dataType, "Data Type"), + new VerticalLayoutData(1, -1)); + + } FieldSet conditions = new FieldSet(); conditions.setHeadingText("Conditions"); conditions.setCollapsible(false); @@ -101,114 +117,134 @@ public class ColumnExpressionPanel extends FramedPanel { flowButton.setHBoxLayoutAlign(HBoxLayoutAlign.MIDDLE); flowButton.setPack(BoxLayoutPack.CENTER); - TextButton btnApply = new TextButton("Apply"); + btnApply = new TextButton("Apply"); btnApply.setIcon(ExpressionResources.INSTANCE.apply()); btnApply.setIconAlign(IconAlign.RIGHT); btnApply.setTitle("Apply rule"); btnApply.addSelectHandler(new SelectHandler() { - + public void onSelect(SelectEvent event) { Log.debug("Pressed Apply"); applyRule(); - + } }); - - TextButton btnSearch = new TextButton("Search"); + + btnSearch = new TextButton("Search"); btnSearch.setIcon(ExpressionResources.INSTANCE.search()); btnSearch.setIconAlign(IconAlign.RIGHT); btnSearch.setTitle("Search rule"); btnSearch.addSelectHandler(new SelectHandler() { - + public void onSelect(SelectEvent event) { Log.debug("Pressed Search"); searchRule(); - + } }); - - - - TextButton btnSave = new TextButton("Save"); + + btnSave = new TextButton("Save"); btnSave.setIcon(ExpressionResources.INSTANCE.save()); btnSave.setIconAlign(IconAlign.RIGHT); btnSave.setTitle("Save rule"); btnSave.addSelectHandler(new SelectHandler() { - + public void onSelect(SelectEvent event) { Log.debug("Pressed Save"); saveRule(); - + } }); - - CellButtonBase btnClose = new TextButton("Close"); + + btnClose = new TextButton("Close"); btnClose.setIcon(ExpressionResources.INSTANCE.close()); btnClose.setIconAlign(IconAlign.RIGHT); btnClose.setTitle("Cancel rule"); btnClose.addSelectHandler(new SelectHandler() { - + public void onSelect(SelectEvent event) { Log.debug("Pressed Close"); close(); - + } }); - + flowButton.add(btnApply, new BoxLayoutData(new Margins(2, 4, 2, 4))); flowButton.add(btnSave, new BoxLayoutData(new Margins(2, 4, 2, 4))); flowButton.add(btnSearch, new BoxLayoutData(new Margins(2, 4, 2, 4))); flowButton.add(btnClose, new BoxLayoutData(new Margins(2, 4, 2, 4))); - basicLayout.add(properties, new VerticalLayoutData(-1, -1, new Margins( - 1))); + if (type == ColumnExpressionPanelType.ColumnRule) { + basicLayout.add(properties, new VerticalLayoutData(-1, -1, + new Margins(1))); + } basicLayout.add(conditions, new VerticalLayoutData(-1, -1, new Margins( 1))); - basicLayout.add(flowButton, new VerticalLayoutData(-1, -1, new Margins(5,2,5, - 2))); + basicLayout.add(flowButton, new VerticalLayoutData(-1, -1, new Margins( + 5, 2, 5, 2))); add(basicLayout); show(); } - protected void applyRule() { - C_Expression exp=conditionWidget.getExpression(); - parent.setExpression(exp); - ExpressionEvent expressionEvent= new ExpressionEvent(ExpressionType.CREATECOLUMNEXPRESSION); - C_ExpressionContainer container=new C_ExpressionContainer(); - container.setId(C_ExpressionContainer.Contains.C_Expression); - container.setExp(exp); - expressionEvent.setC_ExpressionContainer(container); - expressionEvent.setTrId(column.getTrId()); - expressionEvent.setColumnId(column.getColumnId()); - expressionEvent.setColumnName(column.getName()); - Log.debug(expressionEvent.toString()); - parent.hide(); - eventBus.fireEvent(expressionEvent); - - + C_Expression exp = conditionWidget.getExpression(); + if (type == ColumnExpressionPanelType.ColumnRule) { + parentRuleDialog.setExpression(exp); + ExpressionEvent expressionEvent = new ExpressionEvent( + ExpressionType.CREATECOLUMNEXPRESSION); + C_ExpressionContainer container = new C_ExpressionContainer(); + container.setId(C_ExpressionContainer.Contains.C_Expression); + container.setExp(exp); + expressionEvent.setC_ExpressionContainer(container); + expressionEvent.setTrId(column.getTrId()); + expressionEvent.setColumnId(column.getColumnId()); + expressionEvent.setColumnName(column.getName()); + Log.debug(expressionEvent.toString()); + parentRuleDialog.hide(); + eventBus.fireEvent(expressionEvent); + } else { + parentFilterDialog.setExpression(exp); + } + } - + protected void saveRule() { - //Expression exp=conditionWidget.getExpression(); - //parent.setExpression(exp); + } - - protected void searchRule(){ - + + protected void searchRule() { + } - + protected void close() { - ExpressionEvent expressionEvent= new ExpressionEvent(ExpressionType.EXPRESSIONNULL); - Log.debug(expressionEvent.toString()); - parent.hide(); - eventBus.fireEvent(expressionEvent); - + if (type == ColumnExpressionPanelType.ColumnRule) { + ExpressionEvent expressionEvent = new ExpressionEvent( + ExpressionType.EXPRESSIONNULL); + Log.debug(expressionEvent.toString()); + parentRuleDialog.hide(); + eventBus.fireEvent(expressionEvent); + } else { + parentFilterDialog.close(); + } + } + public TextButton getBtnApply() { + return btnApply; + } + + public TextButton getBtnSearch() { + return btnSearch; + } + + public TextButton getBtnSave() { + return btnSave; + } + + public TextButton getBtnClose() { + return btnClose; + } - - } diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/FilterColumnDialog.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/FilterColumnDialog.java new file mode 100644 index 0000000..5724675 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/FilterColumnDialog.java @@ -0,0 +1,124 @@ +package org.gcube.portlets.user.td.expressionwidget.client; + +import org.gcube.portlets.user.td.expressionwidget.client.resource.ExpressionResources; +import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync; +import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; +import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; +import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression; +import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnDataType; +import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnTypeCode; + +import com.allen_sauer.gwt.log.client.Log; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.HTML; +import com.google.web.bindery.event.shared.EventBus; +import com.sencha.gxt.widget.core.client.Window; + +public class FilterColumnDialog extends Window { + protected String WIDTH = "650px"; + protected String HEIGHT = "426px"; + protected ColumnExpressionPanel columnExpressionPanel; + protected C_Expression exp = null; + protected ColumnData column = null; + protected TRId trId; + protected String columnName = null; + protected EventBus eventBus; + + public FilterColumnDialog(String columnId, + ColumnTypeCode columnTypeCode, ColumnDataType dataTypeName, + EventBus eventBus) { + initWindow(); + this.eventBus = eventBus; + column = new ColumnData(); + column.setColumnId(columnId); + column.setDataTypeName(dataTypeName.toString()); + column.setTypeCode(columnTypeCode.toString()); + create(); + + } + + public FilterColumnDialog(TRId trId, String columnName, + EventBus eventBus) { + initWindow(); + this.eventBus = eventBus; + this.trId = trId; + this.columnName = columnName; + load(trId, columnName); + + } + + protected void initWindow(){ + setWidth(WIDTH); + setHeight(HEIGHT); + setBodyBorder(false); + setResizable(false); + setHeadingText("New Rule"); + setClosable(false); + getHeader().setIcon(ExpressionResources.INSTANCE.rule()); + + } + + protected void create() { + if (column.getTypeCode() + .compareTo(ColumnTypeCode.ANNOTATION.toString()) == 0 + || column.getTypeCode().compareTo( + ColumnTypeCode.ATTRIBUTE.toString()) == 0 + || column.getTypeCode().compareTo( + ColumnTypeCode.CODE.toString()) == 0 + || column.getTypeCode().compareTo( + ColumnTypeCode.CODEDESCRIPTION.toString()) == 0 + || column.getTypeCode().compareTo( + ColumnTypeCode.CODENAME.toString()) == 0 + || column.getTypeCode().compareTo( + ColumnTypeCode.MEASURE.toString()) == 0) { + columnExpressionPanel = new ColumnExpressionPanel(this, column); + add(columnExpressionPanel); + } else { + HTML errorMessage = new HTML( + "This type of column is not supported for now!"); + add(errorMessage); + } + } + + public C_Expression getExpression() { + return exp; + } + + protected void setExpression(C_Expression exp) { + Log.debug("New Expression set:" + exp.toString()); + this.exp = exp; + + + } + + protected void close(){ + + } + + + + protected void load(TRId trId, String columnName) { + TDGWTServiceAsync.INSTANCE.getColumn(trId, columnName, + new AsyncCallback() { + + public void onFailure(Throwable caught) { + Log.error("Error retrieving column: " + + caught.getMessage()); + + } + + public void onSuccess(ColumnData result) { + Log.debug("Retrived column: " + result); + column = result; + create(); + } + + }); + + } + + + + + +} diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/rpc/ExpressionService.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/rpc/ExpressionService.java index c103257..2ee334d 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/rpc/ExpressionService.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/rpc/ExpressionService.java @@ -6,6 +6,7 @@ package org.gcube.portlets.user.td.expressionwidget.client.rpc; import org.gcube.portlets.user.td.expressionwidget.shared.expression.ExpressionServiceException; +import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression; import com.google.gwt.user.client.rpc.RemoteService; @@ -29,7 +30,7 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; @RemoteServiceRelativePath("ExpressionService") public interface ExpressionService extends RemoteService { - public Void submitExpression(C_Expression expression) throws ExpressionServiceException; + public void submitColumnFilter(ColumnData column, C_Expression expression) throws ExpressionServiceException; diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/rpc/ExpressionServiceAsync.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/rpc/ExpressionServiceAsync.java index 673a808..36b6df6 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/rpc/ExpressionServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/rpc/ExpressionServiceAsync.java @@ -3,6 +3,7 @@ */ package org.gcube.portlets.user.td.expressionwidget.client.rpc; +import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression; import com.google.gwt.core.client.GWT; @@ -20,6 +21,6 @@ public interface ExpressionServiceAsync { public static ExpressionServiceAsync INSTANCE = (ExpressionServiceAsync) GWT .create(ExpressionService.class); - void submitExpression(C_Expression expression,AsyncCallback callback); + void submitColumnFilter(ColumnData column, C_Expression expression,AsyncCallback callback); } diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/ExpressionServiceImpl.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/ExpressionServiceImpl.java new file mode 100644 index 0000000..e39ea4e --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/ExpressionServiceImpl.java @@ -0,0 +1,90 @@ +package org.gcube.portlets.user.td.expressionwidget.server; + +import java.text.SimpleDateFormat; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpSession; + +import org.gcube.application.framework.core.session.ASLSession; +import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationProvider; +import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationToken; +import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationDefinition; +import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationExecution; +import org.gcube.data.analysis.tabulardata.service.TabularDataService; +import org.gcube.data.analysis.tabulardata.service.impl.TabularDataServiceFactory; +import org.gcube.portlets.user.td.expressionwidget.client.rpc.ExpressionService; +import org.gcube.portlets.user.td.expressionwidget.shared.expression.ExpressionServiceException; +import org.gcube.portlets.user.td.gwtservice.server.SessionUtil; +import org.gcube.portlets.user.td.gwtservice.server.trservice.OperationDefinitionMap; +import org.gcube.portlets.user.td.gwtservice.server.trservice.OperationsId; +import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; +import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +public class ExpressionServiceImpl extends RemoteServiceServlet implements + ExpressionService { + + private static final long serialVersionUID = -5707400086333186368L; + protected static Logger logger = LoggerFactory + .getLogger(ExpressionServiceImpl.class); + + protected static SimpleDateFormat sdf = new SimpleDateFormat( + "yyyy/MM/dd HH:mm"); + + + /** + * + * {@inheritDoc} + */ + @Override + public void submitColumnFilter(ColumnData column, C_Expression expression) + throws ExpressionServiceException { + + try { + HttpSession session = this.getThreadLocalRequest().getSession(); + + ASLSession aslSession = SessionUtil.getAslSession(session); + + AuthorizationProvider.instance.set(new AuthorizationToken( + aslSession.getUsername())); + TabularDataService service = TabularDataServiceFactory.getService(); + + List capabilities = service.getCapabilities(); + + OperationDefinition importSDMXCodelistOperation = OperationDefinitionMap.map( + OperationsId.FilterByExpression.toString(), capabilities); + + + + + + + Map parameterInstance=null;// = retrieveOperationParameters(sdmxImportSession); + + OperationExecution invocation = new OperationExecution( + importSDMXCodelistOperation.getOperationId(), + parameterInstance); + + + logger.debug("OperationInvocation: \n" + invocation.toString()); + //Task trTask = service.execute(invocation, serviceTR.getId()); + //logger.debug("Start Task on service: TaskId " + trTask.getId()); + //SessionUtil.setSDMXImportTask(session, trTask); + return; + } catch (Exception e) { + e.printStackTrace(); + throw new ExpressionServiceException("Error in Client Library Request: " + + e.getLocalizedMessage()); + } + } + + + + + + +} \ No newline at end of file diff --git a/src/main/resources/org/gcube/portlets/user/td/expressionwidget/ExpressionWidget.gwt.xml b/src/main/resources/org/gcube/portlets/user/td/expressionwidget/ExpressionWidget.gwt.xml index ca5a663..3fc0b17 100644 --- a/src/main/resources/org/gcube/portlets/user/td/expressionwidget/ExpressionWidget.gwt.xml +++ b/src/main/resources/org/gcube/portlets/user/td/expressionwidget/ExpressionWidget.gwt.xml @@ -23,7 +23,7 @@ - +