From ba8e135c1e0eb20ed8e8bd0791025ac5630a7e87 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Fri, 6 Feb 2015 17:26:57 +0000 Subject: [PATCH] Updated Replace By Expression git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-expression-widget@111786 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/ReplaceArithmeticWidget.java | 1045 ----------------- .../ReplaceColumnByExpressionDialog.java | 2 +- .../ReplaceColumnByExpressionPanel.java | 116 +- .../client/ReplaceWidget.java | 530 ++++++--- .../properties/ReplaceArithmeticElement.java | 57 - .../ReplaceArithmeticElementProperties.java | 21 - .../ReplaceArithmeticElementStore.java | 48 - .../properties/ReplaceElementStore.java | 18 +- .../arithmetic/C_ArithmeticExpression.java | 48 +- .../shared/replace/ReplaceArithmeticType.java | 36 - .../replace/ReplaceArithmeticTypeMap.java | 537 --------- .../shared/replace/ReplaceType.java | 10 +- .../shared/replace/ReplaceTypeMap.java | 683 ++++++++--- 13 files changed, 973 insertions(+), 2178 deletions(-) delete mode 100644 src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceArithmeticWidget.java delete mode 100644 src/main/java/org/gcube/portlets/user/td/expressionwidget/client/properties/ReplaceArithmeticElement.java delete mode 100644 src/main/java/org/gcube/portlets/user/td/expressionwidget/client/properties/ReplaceArithmeticElementProperties.java delete mode 100644 src/main/java/org/gcube/portlets/user/td/expressionwidget/client/properties/ReplaceArithmeticElementStore.java delete mode 100644 src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/replace/ReplaceArithmeticType.java delete mode 100644 src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/replace/ReplaceArithmeticTypeMap.java diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceArithmeticWidget.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceArithmeticWidget.java deleted file mode 100644 index 87446b8..0000000 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceArithmeticWidget.java +++ /dev/null @@ -1,1045 +0,0 @@ -package org.gcube.portlets.user.td.expressionwidget.client; - -import java.util.ArrayList; - -import org.gcube.portlets.user.td.expressionwidget.client.properties.ColumnDataPropertiesCombo; -import org.gcube.portlets.user.td.expressionwidget.client.properties.ReplaceArithmeticElement; -import org.gcube.portlets.user.td.expressionwidget.client.properties.ReplaceArithmeticElementProperties; -import org.gcube.portlets.user.td.expressionwidget.client.properties.ReplaceArithmeticElementStore; -import org.gcube.portlets.user.td.expressionwidget.client.type.ReplaceColumnByExpressionType; -import org.gcube.portlets.user.td.expressionwidget.client.utils.UtilsGXT3; -import org.gcube.portlets.user.td.expressionwidget.shared.exception.ReplaceTypeMapException; -import org.gcube.portlets.user.td.expressionwidget.shared.replace.ReplaceArithmeticType; -import org.gcube.portlets.user.td.expressionwidget.shared.replace.ReplaceArithmeticTypeMap; -import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync; -import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsFinalException; -import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsLockedException; -import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException; -import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; -import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent; -import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType; -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 com.allen_sauer.gwt.log.client.Log; -import com.google.gwt.core.client.GWT; -import com.google.gwt.event.logical.shared.SelectionEvent; -import com.google.gwt.event.logical.shared.SelectionHandler; -import com.google.gwt.user.client.rpc.AsyncCallback; -import com.google.web.bindery.event.shared.EventBus; -import com.sencha.gxt.cell.core.client.form.ComboBoxCell.TriggerAction; -import com.sencha.gxt.core.client.util.Margins; -import com.sencha.gxt.data.shared.ListStore; -import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutData; -import com.sencha.gxt.widget.core.client.container.HBoxLayoutContainer; -import com.sencha.gxt.widget.core.client.container.MarginData; -import com.sencha.gxt.widget.core.client.container.SimpleContainer; -import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer; -import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData; -import com.sencha.gxt.widget.core.client.event.BeforeShowEvent; -import com.sencha.gxt.widget.core.client.form.ComboBox; -import com.sencha.gxt.widget.core.client.form.TextField; - -/** - * - * @author "Giancarlo Panichi" g.panichi@isti.cnr.it - * - */ -public class ReplaceArithmeticWidget extends SimpleContainer { - - private static final String EMPTY_TEXT_TO_STRING = "to string..."; - private static final String EMPTY_TEXT_FROM_STRING = "from string..."; - private static final String EMPTY_TEXT_TO_INDEX = "to index..."; - private static final String EMPTY_TEXT_FROM_INDEX = "from index..."; - private static final String EMPTY_TEXT_REGEXP = "regexp..."; - private static final String EMPTY_TEXT_INSERT_A_STRING = "insert a string..."; - private static final String EMPTY_TEXT_REPLACE_REGEXP = "regexp..."; - private static final String EMPTY_TEXT_REPLACE_REPLACING = "replace with..."; - - private ReplaceArithmeticWidget thisCont; - - private static final String HEIGHT = "210px"; - private static final String WIDTH = "832px"; - private static final String COMBO_WIDTH = "170px"; - - private EventBus eventBus; - private TRId trId; - private ColumnDataType targetColumnDataType; - private ArrayList columns; - - private VerticalLayoutContainer vert; - - private String readableExpression; - private String itemIdComboOperation; - private String itemIdComboLeaf; - private String itemIdComboColumns; - private String itemIdFirstArg; - private String itemIdSecondArg; - private String itemIdHoriz; - private ReplaceColumnByExpressionType replaceColumnByExpressionType; - - protected class ExpressionContainer { - private C_Expression expression; - private String readableExpression; - - public ExpressionContainer(C_Expression expression, - String readableExpression) { - super(); - this.expression = expression; - this.readableExpression = readableExpression; - } - - public C_Expression getExpression() { - return expression; - } - - public void setExpression(C_Expression expression) { - this.expression = expression; - } - - public String getReadableExpression() { - return readableExpression; - } - - public void setReadableExpression(String readableExpression) { - this.readableExpression = readableExpression; - } - - } - - public ReplaceArithmeticWidget(ColumnData column, EventBus eventBus) { - super(); - replaceColumnByExpressionType = ReplaceColumnByExpressionType.Replace; - ColumnDataType targetColumnDataType = ColumnDataType - .getColumnDataTypeFromId(column.getDataTypeName()); - create(column.getTrId(), WIDTH, HEIGHT, eventBus, targetColumnDataType); - retrieveColumns(); - } - - public ReplaceArithmeticWidget(ColumnData column, String width, - String height, EventBus eventBus) { - super(); - replaceColumnByExpressionType = ReplaceColumnByExpressionType.Replace; - ColumnDataType targetColumnDataType = ColumnDataType - .getColumnDataTypeFromId(column.getDataTypeName()); - - create(column.getTrId(), width, height, eventBus, targetColumnDataType); - retrieveColumns(); - } - - public ReplaceArithmeticWidget(ColumnData column, - ArrayList columns, EventBus eventBus) { - super(); - replaceColumnByExpressionType = ReplaceColumnByExpressionType.Template; - this.columns = columns; - ColumnDataType targetColumnDataType = ColumnDataType - .getColumnDataTypeFromId(column.getDataTypeName()); - create(column.getTrId(), WIDTH, HEIGHT, eventBus, targetColumnDataType); - setup(); - } - - public ReplaceArithmeticWidget(ColumnData column, - ArrayList columns, String width, String height, - EventBus eventBus) { - super(); - replaceColumnByExpressionType = ReplaceColumnByExpressionType.Template; - this.columns = columns; - ColumnDataType targetColumnDataType = ColumnDataType - .getColumnDataTypeFromId(column.getDataTypeName()); - create(column.getTrId(), width, height, eventBus, targetColumnDataType); - setup(); - } - - protected void create(TRId trId, String width, String height, - EventBus eventBus, ColumnDataType targetColumnDataType) { - this.trId = trId; - this.targetColumnDataType = targetColumnDataType; - setBorders(true); - setWidth(width); - setHeight(height); - forceLayoutOnResize = true; - thisCont = this; - - addBeforeShowHandler(new BeforeShowEvent.BeforeShowHandler() { - - @Override - public void onBeforeShow(BeforeShowEvent event) { - forceLayout(); - - } - }); - - } - - protected void retrieveColumns() { - TDGWTServiceAsync.INSTANCE.getColumns(trId, - new AsyncCallback>() { - - public void onFailure(Throwable caught) { - if (caught instanceof TDGWTSessionExpiredException) { - eventBus.fireEvent(new SessionExpiredEvent( - SessionExpiredType.EXPIREDONSERVER)); - } else { - if (caught instanceof TDGWTIsLockedException) { - Log.error(caught.getLocalizedMessage()); - UtilsGXT3.alert("Error Locked", - caught.getLocalizedMessage()); - } else { - if (caught instanceof TDGWTIsFinalException) { - Log.error(caught.getLocalizedMessage()); - UtilsGXT3.alert("Error Final", - caught.getLocalizedMessage()); - } else { - Log.error("load combo failure:" - + caught.getLocalizedMessage()); - UtilsGXT3.alert("Error", - "Error retrieving columns of tabular resource:" - + trId.getId()); - } - } - } - } - - public void onSuccess(ArrayList result) { - Log.trace("loaded " + result.size() + " ColumnData"); - columns = result; - setup(); - } - - }); - } - - protected void setup() { - itemIdComboOperation = "ComboOperation" + trId.getId(); - itemIdComboLeaf = "ComboLeaf" + trId.getId(); - itemIdComboColumns = "ComboColumns" + trId.getId(); - itemIdFirstArg = "FirstArg" + trId.getId(); - itemIdSecondArg = "SecondArg" + trId.getId(); - itemIdHoriz = "Horiz" + trId.getId(); - - vert = new VerticalLayoutContainer(); - // vert.setScrollMode(ScrollMode.AUTO); Set in GXT 3.0.1 - - final HBoxLayoutContainer horiz = new HBoxLayoutContainer(); - - final TextField firstArg = new TextField(); - firstArg.setEmptyText("Insert a value"); - firstArg.setItemId(itemIdFirstArg); - - final TextField secondArg = new TextField(); - secondArg.setEmptyText(""); - secondArg.setItemId(itemIdSecondArg); - - // Combo Column - ColumnDataPropertiesCombo propsColumnData = GWT - .create(ColumnDataPropertiesCombo.class); - ListStore storeColumns = new ListStore( - propsColumnData.id()); - Log.debug("Store Columns: " + storeColumns); - storeColumns.addAll(columns); - - final ComboBox comboColumns = new ComboBox( - storeColumns, propsColumnData.label()); - - Log.debug("Combo Columns created"); - - comboColumns.setEmptyText("Select Column..."); - comboColumns.setItemId(itemIdComboColumns); - comboColumns.setWidth(COMBO_WIDTH); - comboColumns.setEditable(false); - - comboColumns.setTriggerAction(TriggerAction.ALL); - - // Replace Arithmetic Elemet Store - ReplaceArithmeticElementStore replaceArithmeticElementStore = new ReplaceArithmeticElementStore(); - - ReplaceArithmeticElementProperties props = GWT - .create(ReplaceArithmeticElementProperties.class); - Log.debug("Props: " + props); - - // Combo Leaf - ListStore storeReplaceArithmeticElementsLeaf = new ListStore( - props.id()); - Log.debug("Store Leaf: " + storeReplaceArithmeticElementsLeaf); - storeReplaceArithmeticElementsLeaf - .addAll(replaceArithmeticElementStore.replaceArithmeticElements); - - Log.debug("Store created"); - final ComboBox comboReplaceArithmeticElementsLeaf = new ComboBox( - storeReplaceArithmeticElementsLeaf, props.label()); - - Log.debug("Combo created"); - - comboReplaceArithmeticElementsLeaf - .addSelectionHandler(new SelectionHandler() { - - public void onSelection( - SelectionEvent event) { - if (event.getSelectedItem() != null) { - ReplaceArithmeticElement re = event - .getSelectedItem(); - Log.debug("Condition selected:" + re.toString()); - switch (re.getReplaceArithmeticType()) { - case Value: - comboColumns.clear(); - comboColumns.setVisible(false); - firstArg.setVisible(true); - firstArg.setEmptyText(EMPTY_TEXT_INSERT_A_STRING); - secondArg.setVisible(false); - secondArg.setEmptyText(""); - break; - case ColumnValue: - comboColumns.clear(); - comboColumns.setVisible(true); - firstArg.setVisible(false); - firstArg.setEmptyText(""); - secondArg.setVisible(false); - secondArg.setEmptyText(""); - break; - case Addition: - case Subtraction: - case Modulus: - case Multiplication: - case Division: - break; - case SubstringByRegex: - comboColumns.clear(); - comboColumns.setVisible(true); - firstArg.setVisible(true); - firstArg.setEmptyText(EMPTY_TEXT_REGEXP); - secondArg.setVisible(false); - secondArg.setEmptyText(""); - break; - case SubstringByIndex: - comboColumns.clear(); - comboColumns.setVisible(true); - firstArg.setVisible(true); - firstArg.setEmptyText(EMPTY_TEXT_FROM_INDEX); - secondArg.setVisible(true); - secondArg.setEmptyText(EMPTY_TEXT_TO_INDEX); - break; - case SubstringByCharSeq: - comboColumns.clear(); - comboColumns.setVisible(true); - firstArg.setVisible(true); - firstArg.setEmptyText(EMPTY_TEXT_FROM_STRING); - secondArg.setVisible(true); - secondArg.setEmptyText(EMPTY_TEXT_TO_STRING); - break; - case TextReplaceMatchingRegex: - comboColumns.clear(); - comboColumns.setVisible(true); - firstArg.setVisible(true); - firstArg.setEmptyText(EMPTY_TEXT_REPLACE_REGEXP); - secondArg.setVisible(true); - secondArg - .setEmptyText(EMPTY_TEXT_REPLACE_REPLACING); - break; - default: - break; - } - - vert.forceLayout(); - thisCont.forceLayout(); - - } - } - - }); - - comboReplaceArithmeticElementsLeaf.setEmptyText("Select..."); - comboReplaceArithmeticElementsLeaf.setItemId(itemIdComboLeaf); - comboReplaceArithmeticElementsLeaf.setWidth(COMBO_WIDTH); - comboReplaceArithmeticElementsLeaf.setEditable(false); - - comboReplaceArithmeticElementsLeaf.setTriggerAction(TriggerAction.ALL); - - // ComboConcat - ListStore storeReplaceArithmeticElementsOperators = new ListStore( - props.id()); - Log.debug("Store Operator: " + storeReplaceArithmeticElementsOperators); - storeReplaceArithmeticElementsOperators - .addAll(replaceArithmeticElementStore.replaceArithmeticElementsOperators); - - Log.debug("Store created"); - final ComboBox comboReplaceArithmeticElementsOperators = new ComboBox( - storeReplaceArithmeticElementsOperators, props.label()); - - Log.debug("Combo created"); - - comboReplaceArithmeticElementsOperators - .addSelectionHandler(new SelectionHandler() { - - public void onSelection( - SelectionEvent event) { - if (event.getSelectedItem() != null) { - @SuppressWarnings("unchecked") - ComboBox source = (ComboBox) event - .getSource(); - ReplaceArithmeticElement re = event - .getSelectedItem(); - Log.debug("Condition selected:" + re.toString()); - switch (re.getReplaceArithmeticType()) { - case Value: - comboReplaceArithmeticElementsLeaf - .setVisible(false); - comboColumns.clear(); - comboColumns.setVisible(false); - firstArg.setEmptyText(EMPTY_TEXT_INSERT_A_STRING); - firstArg.setVisible(true); - secondArg.setVisible(false); - secondArg.setEmptyText(""); - removeOperator(source); - break; - case ColumnValue: - comboReplaceArithmeticElementsLeaf - .setVisible(false); - comboColumns.clear(); - comboColumns.setVisible(true); - firstArg.setVisible(false); - firstArg.setEmptyText(""); - secondArg.setVisible(false); - secondArg.setEmptyText(""); - removeOperator(source); - break; - case Addition: - case Subtraction: - case Modulus: - case Multiplication: - case Division: - if (!existOperator(source)) { - comboReplaceArithmeticElementsLeaf.clear(); - comboReplaceArithmeticElementsLeaf - .setVisible(true); - comboColumns.clear(); - comboColumns.setVisible(false); - firstArg.setVisible(false); - firstArg.setEmptyText(""); - secondArg.setVisible(false); - secondArg.setEmptyText(""); - addOperator(); - } - break; - case SubstringByRegex: - comboReplaceArithmeticElementsLeaf - .setVisible(false); - comboColumns.clear(); - comboColumns.setVisible(true); - firstArg.setVisible(true); - firstArg.setEmptyText(EMPTY_TEXT_REGEXP); - secondArg.setVisible(false); - secondArg.setEmptyText(""); - removeOperator(source); - break; - case SubstringByIndex: - comboReplaceArithmeticElementsLeaf - .setVisible(false); - comboColumns.clear(); - comboColumns.setVisible(true); - firstArg.setVisible(true); - firstArg.setEmptyText(EMPTY_TEXT_FROM_INDEX); - secondArg.setVisible(true); - secondArg.setEmptyText(EMPTY_TEXT_TO_INDEX); - removeOperator(source); - break; - case SubstringByCharSeq: - comboReplaceArithmeticElementsLeaf - .setVisible(false); - comboColumns.clear(); - comboColumns.setVisible(true); - firstArg.setVisible(true); - firstArg.setEmptyText(EMPTY_TEXT_FROM_STRING); - secondArg.setVisible(true); - secondArg.setEmptyText(EMPTY_TEXT_TO_STRING); - removeOperator(source); - break; - case TextReplaceMatchingRegex: - comboReplaceArithmeticElementsLeaf - .setVisible(false); - comboColumns.clear(); - comboColumns.setVisible(true); - firstArg.setVisible(true); - firstArg.setEmptyText(EMPTY_TEXT_REPLACE_REGEXP); - secondArg.setVisible(true); - secondArg - .setEmptyText(EMPTY_TEXT_REPLACE_REPLACING); - removeOperator(source); - break; - default: - break; - } - vert.forceLayout(); - thisCont.forceLayout(); - - } - } - - }); - - comboReplaceArithmeticElementsOperators.setEmptyText("Select..."); - comboReplaceArithmeticElementsOperators.setItemId(itemIdComboOperation); - comboReplaceArithmeticElementsOperators.setWidth(COMBO_WIDTH); - comboReplaceArithmeticElementsOperators.setEditable(false); - comboReplaceArithmeticElementsOperators - .setTriggerAction(TriggerAction.ALL); - - comboReplaceArithmeticElementsOperators.setValue( - storeReplaceArithmeticElementsOperators.get(0), true); - - // - horiz.add(comboReplaceArithmeticElementsOperators, new BoxLayoutData( - new Margins(0))); - horiz.add(comboReplaceArithmeticElementsLeaf, new BoxLayoutData( - new Margins(0))); - horiz.add(comboColumns, new BoxLayoutData(new Margins(0))); - horiz.add(firstArg, new BoxLayoutData(new Margins(0))); - horiz.add(secondArg, new BoxLayoutData(new Margins(0))); - horiz.setItemId(itemIdHoriz); - vert.add(horiz, new VerticalLayoutData(-1, -1, new Margins(1))); - - add(vert, new MarginData(0)); - - firstArg.setVisible(true); - secondArg.setVisible(false); - comboColumns.setVisible(false); - comboReplaceArithmeticElementsLeaf.setVisible(false); - comboReplaceArithmeticElementsOperators.setVisible(true); - forceLayout(); - } - - protected void addOperator() { - final HBoxLayoutContainer horiz = new HBoxLayoutContainer(); - - final TextField firstArg = new TextField(); - firstArg.setItemId(itemIdFirstArg); - - final TextField secondArg = new TextField(); - secondArg.setItemId(itemIdSecondArg); - - // Combo Column - ColumnDataPropertiesCombo propsColumnData = GWT - .create(ColumnDataPropertiesCombo.class); - ListStore storeColumns = new ListStore( - propsColumnData.id()); - Log.debug("Store Columns: " + storeColumns); - storeColumns.addAll(columns); - - final ComboBox comboColumns = new ComboBox( - storeColumns, propsColumnData.label()); - - Log.debug("Combo Columns created"); - - comboColumns.setEmptyText("Select Column..."); - comboColumns.setItemId(itemIdComboColumns); - comboColumns.setWidth(COMBO_WIDTH); - comboColumns.setEditable(false); - - comboColumns.setTriggerAction(TriggerAction.ALL); - - // - ReplaceArithmeticElementStore replaceArithmeticElementStore = new ReplaceArithmeticElementStore(); - - ReplaceArithmeticElementProperties props = GWT - .create(ReplaceArithmeticElementProperties.class); - Log.debug("Props: " + props); - - // Combo Leaf - ListStore storeReplaceArithmeticElementsLeaf = new ListStore( - props.id()); - Log.debug("Store Leaf: " + storeReplaceArithmeticElementsLeaf); - storeReplaceArithmeticElementsLeaf - .addAll(replaceArithmeticElementStore.replaceArithmeticElements); - - Log.debug("Store created"); - final ComboBox comboReplaceArithmeticElementsLeaf = new ComboBox( - storeReplaceArithmeticElementsLeaf, props.label()); - - Log.debug("Combo created"); - - comboReplaceArithmeticElementsLeaf - .addSelectionHandler(new SelectionHandler() { - - public void onSelection( - SelectionEvent event) { - if (event.getSelectedItem() != null) { - ReplaceArithmeticElement re = event - .getSelectedItem(); - Log.debug("Condition selected:" + re.toString()); - switch (re.getReplaceArithmeticType()) { - case Value: - comboColumns.clear(); - comboColumns.setVisible(false); - firstArg.setVisible(true); - firstArg.setEmptyText(EMPTY_TEXT_INSERT_A_STRING); - secondArg.setVisible(false); - secondArg.setEmptyText(""); - break; - case ColumnValue: - comboColumns.clear(); - comboColumns.setVisible(true); - firstArg.setVisible(false); - firstArg.setEmptyText(""); - secondArg.setVisible(false); - secondArg.setEmptyText(""); - break; - case Addition: - case Subtraction: - case Modulus: - case Multiplication: - case Division: - break; - case SubstringByRegex: - comboColumns.clear(); - comboColumns.setVisible(true); - firstArg.setVisible(true); - firstArg.setEmptyText(EMPTY_TEXT_REGEXP); - secondArg.setVisible(false); - secondArg.setEmptyText(""); - break; - case SubstringByIndex: - comboColumns.clear(); - comboColumns.setVisible(true); - firstArg.setVisible(true); - firstArg.setEmptyText(EMPTY_TEXT_FROM_INDEX); - secondArg.setVisible(true); - secondArg.setEmptyText(EMPTY_TEXT_TO_INDEX); - break; - case SubstringByCharSeq: - comboColumns.clear(); - comboColumns.setVisible(true); - firstArg.setVisible(true); - firstArg.setEmptyText(EMPTY_TEXT_FROM_STRING); - secondArg.setVisible(true); - secondArg.setEmptyText(EMPTY_TEXT_TO_STRING); - break; - case TextReplaceMatchingRegex: - comboColumns.clear(); - comboColumns.setVisible(true); - firstArg.setVisible(true); - firstArg.setEmptyText(EMPTY_TEXT_REPLACE_REGEXP); - secondArg.setVisible(true); - secondArg - .setEmptyText(EMPTY_TEXT_REPLACE_REPLACING); - break; - default: - break; - } - vert.forceLayout(); - thisCont.forceLayout(); - - } - } - - }); - - comboReplaceArithmeticElementsLeaf.setEmptyText("Select..."); - comboReplaceArithmeticElementsLeaf.setItemId(itemIdComboLeaf); - comboReplaceArithmeticElementsLeaf.setWidth(COMBO_WIDTH); - comboReplaceArithmeticElementsLeaf.setEditable(false); - - comboReplaceArithmeticElementsLeaf.setTriggerAction(TriggerAction.ALL); - - // Combo Operator - ListStore storeReplaceArithmeticElementsOperator = new ListStore( - props.id()); - Log.debug("Store Concat: " + storeReplaceArithmeticElementsOperator); - storeReplaceArithmeticElementsOperator - .addAll(replaceArithmeticElementStore.replaceArithmeticElementsOperators); - - Log.debug("Store created"); - final ComboBox comboReplaceArithmeticElementsOperator = new ComboBox( - storeReplaceArithmeticElementsOperator, props.label()); - - Log.debug("Combo created"); - - comboReplaceArithmeticElementsOperator - .addSelectionHandler(new SelectionHandler() { - - public void onSelection( - SelectionEvent event) { - - if (event.getSelectedItem() != null) { - @SuppressWarnings("unchecked") - ComboBox source = (ComboBox) event - .getSource(); - ReplaceArithmeticElement re = event - .getSelectedItem(); - Log.debug("Condition selected:" + re.toString()); - switch (re.getReplaceArithmeticType()) { - case Value: - comboReplaceArithmeticElementsLeaf - .setVisible(false); - comboColumns.clear(); - comboColumns.setVisible(false); - firstArg.setEmptyText(EMPTY_TEXT_INSERT_A_STRING); - firstArg.setVisible(true); - secondArg.setVisible(false); - secondArg.setEmptyText(""); - removeOperator(source); - break; - case ColumnValue: - comboReplaceArithmeticElementsLeaf - .setVisible(false); - comboColumns.clear(); - comboColumns.setVisible(true); - firstArg.setVisible(false); - firstArg.setEmptyText(""); - secondArg.setVisible(false); - secondArg.setEmptyText(""); - removeOperator(source); - break; - case Addition: - case Subtraction: - case Modulus: - case Multiplication: - case Division: - if (!existOperator(source)) { - comboReplaceArithmeticElementsLeaf.clear(); - comboReplaceArithmeticElementsLeaf - .setVisible(true); - comboColumns.clear(); - comboColumns.setVisible(false); - firstArg.setVisible(false); - firstArg.setEmptyText(""); - secondArg.setVisible(false); - secondArg.setEmptyText(""); - addOperator(); - } - break; - case SubstringByRegex: - comboReplaceArithmeticElementsLeaf - .setVisible(false); - comboColumns.clear(); - comboColumns.setVisible(true); - firstArg.setVisible(true); - firstArg.setEmptyText(EMPTY_TEXT_REGEXP); - secondArg.setVisible(false); - secondArg.setEmptyText(""); - removeOperator(source); - break; - case SubstringByIndex: - comboReplaceArithmeticElementsLeaf - .setVisible(false); - comboColumns.clear(); - comboColumns.setVisible(true); - firstArg.setVisible(true); - firstArg.setEmptyText(EMPTY_TEXT_FROM_INDEX); - secondArg.setVisible(true); - secondArg.setEmptyText(EMPTY_TEXT_TO_INDEX); - removeOperator(source); - break; - case SubstringByCharSeq: - comboReplaceArithmeticElementsLeaf - .setVisible(false); - comboColumns.clear(); - comboColumns.setVisible(true); - firstArg.setVisible(true); - firstArg.setEmptyText(EMPTY_TEXT_FROM_STRING); - secondArg.setVisible(true); - secondArg.setEmptyText(EMPTY_TEXT_TO_STRING); - removeOperator(source); - break; - case TextReplaceMatchingRegex: - comboReplaceArithmeticElementsLeaf - .setVisible(false); - comboColumns.clear(); - comboColumns.setVisible(true); - firstArg.setVisible(true); - firstArg.setEmptyText(EMPTY_TEXT_REPLACE_REGEXP); - secondArg.setVisible(true); - secondArg - .setEmptyText(EMPTY_TEXT_REPLACE_REPLACING); - removeOperator(source); - break; - default: - break; - } - vert.forceLayout(); - thisCont.forceLayout(); - - } - - } - - }); - - comboReplaceArithmeticElementsOperator.setEmptyText("Select..."); - comboReplaceArithmeticElementsOperator.setItemId(itemIdComboOperation); - comboReplaceArithmeticElementsOperator.setWidth(COMBO_WIDTH); - comboReplaceArithmeticElementsOperator.setEditable(false); - comboReplaceArithmeticElementsOperator - .setTriggerAction(TriggerAction.ALL); - - comboReplaceArithmeticElementsOperator.setValue( - storeReplaceArithmeticElementsOperator.get(0), true); - - // - horiz.add(comboReplaceArithmeticElementsOperator, new BoxLayoutData( - new Margins(0))); - horiz.add(comboReplaceArithmeticElementsLeaf, new BoxLayoutData( - new Margins(0))); - horiz.add(comboColumns, new BoxLayoutData(new Margins(0))); - horiz.add(firstArg, new BoxLayoutData(new Margins(0))); - horiz.add(secondArg, new BoxLayoutData(new Margins(0))); - horiz.setItemId(itemIdHoriz); - vert.add(horiz, new VerticalLayoutData(-1, -1, new Margins(1))); - - firstArg.setVisible(true); - secondArg.setVisible(false); - comboColumns.setVisible(false); - comboReplaceArithmeticElementsLeaf.setVisible(false); - comboReplaceArithmeticElementsOperator.setVisible(true); - forceLayout(); - } - - private void removeOperator(ComboBox source) { - HBoxLayoutContainer horiz = (HBoxLayoutContainer) source.getParent(); - int index = vert.getWidgetIndex(horiz); - Log.debug("No concat for index: " + index); - index++; - for (int i = index; i < vert.getWidgetCount();) { - Log.debug("Remove horiz index: " + i); - vert.remove(i); - } - } - - private boolean existOperator(ComboBox source) { - boolean exist = false; - HBoxLayoutContainer horiz = (HBoxLayoutContainer) source.getParent(); - int index = vert.getWidgetIndex(horiz); - Log.debug("No concat for index: " + index); - index++; - if (index < vert.getWidgetCount()) { - exist = true; - } else { - exist = false; - } - return exist; - } - - public C_Expression getExpression() throws ReplaceTypeMapException { - ExpressionContainer expressionContainer = null; - readableExpression = new String(); - C_Expression expression = null; - - if (vert.getWidgetCount() > 0) { - int index = 0; - expressionContainer = calcCExpression(index); - if (expressionContainer != null) { - readableExpression = expressionContainer - .getReadableExpression(); - expression = expressionContainer.getExpression(); - } else { - - } - } - - Log.debug("ReadableExpression: " + readableExpression); - Log.debug("C_Expression:" + expression); - return expression; - } - - public String getReadableExpression() { - return readableExpression; - } - - protected ExpressionContainer calcCExpression(int index) - throws ReplaceTypeMapException { - ExpressionContainer expressionContainer = null; - ExpressionContainer expContainerOperator = null; - C_Expression exp = null; - C_Expression expLeaf = null; - String readableExp = ""; - String readableExpLeaf = ""; - TextField firstArg; - TextField secondArg; - HBoxLayoutContainer horiz; - ReplaceArithmeticTypeMap mapReplaceArithmetic = new ReplaceArithmeticTypeMap(); - - horiz = (HBoxLayoutContainer) vert.getWidget(index); - @SuppressWarnings("unchecked") - ComboBox comboOperator = (ComboBox) horiz - .getItemByItemId(itemIdComboOperation); - Log.debug("combo Operator: " + comboOperator.getCurrentValue()); - @SuppressWarnings("unchecked") - ComboBox comboLeaf = (ComboBox) horiz - .getItemByItemId(itemIdComboLeaf); - Log.debug("combo Leaf: " + comboLeaf.getCurrentValue()); - - @SuppressWarnings("unchecked") - ComboBox comboColumns = (ComboBox) horiz - .getItemByItemId(itemIdComboColumns); - Log.debug("combo columns: " + comboColumns.getCurrentValue()); - ColumnData column = comboColumns.getCurrentValue(); - - firstArg = (TextField) horiz.getItemByItemId(itemIdFirstArg); - secondArg = (TextField) horiz.getItemByItemId(itemIdSecondArg); - Log.debug("[column: " + column + ", firstArg: " - + firstArg.getCurrentValue() + ", secondArg: " - + secondArg.getCurrentValue() + "]"); - - ReplaceArithmeticType comboOperatorReplaceType = null; - ReplaceArithmeticType comboLeafReplaceType = null; - - if (comboOperator.getCurrentValue() == null) { - throw new ReplaceTypeMapException("Fill all field!"); - } else { - comboOperatorReplaceType = comboOperator.getCurrentValue() - .getReplaceArithmeticType(); - if (comboOperatorReplaceType - .compareTo(ReplaceArithmeticType.Addition) == 0 - || comboOperatorReplaceType - .compareTo(ReplaceArithmeticType.Subtraction) == 0 - || comboOperatorReplaceType - .compareTo(ReplaceArithmeticType.Modulus) == 0 - || comboOperatorReplaceType - .compareTo(ReplaceArithmeticType.Multiplication) == 0 - || comboOperatorReplaceType - .compareTo(ReplaceArithmeticType.Division) == 0) { - - if (comboLeaf.getCurrentValue() == null) { - throw new ReplaceTypeMapException("Fill all field!"); - - } else { - comboLeafReplaceType = comboLeaf.getCurrentValue() - .getReplaceArithmeticType(); - switch (replaceColumnByExpressionType) { - case Replace: - expLeaf = mapReplaceArithmetic.map( - column, - targetColumnDataType, - comboLeafReplaceType, - firstArg == null ? null : firstArg - .getCurrentValue(), - secondArg == null ? null : secondArg - .getCurrentValue(), false); - break; - case Template: - expLeaf = mapReplaceArithmetic.map( - column, - targetColumnDataType, - comboLeafReplaceType, - firstArg == null ? null : firstArg - .getCurrentValue(), - secondArg == null ? null : secondArg - .getCurrentValue(), true); - break; - default: - expLeaf = mapReplaceArithmetic.map( - column, - targetColumnDataType, - comboLeafReplaceType, - firstArg == null ? null : firstArg - .getCurrentValue(), - secondArg == null ? null : secondArg - .getCurrentValue(), false); - break; - - } - - readableExpLeaf = mapReplaceArithmetic - .getReadableExpression(); - } - - index++; - if (index < vert.getWidgetCount()) { - expContainerOperator = calcCExpression(index); - if (expContainerOperator == null) { - return null; - } else { - switch (replaceColumnByExpressionType) { - case Replace: - exp = mapReplaceArithmetic.map( - column, - targetColumnDataType, - comboOperatorReplaceType, - firstArg == null ? null : firstArg - .getCurrentValue(), - secondArg == null ? null : secondArg - .getCurrentValue(), false, expLeaf, - expContainerOperator.getExpression(), - readableExpLeaf, expContainerOperator - .getReadableExpression()); - break; - case Template: - exp = mapReplaceArithmetic.map( - column, - targetColumnDataType, - comboOperatorReplaceType, - firstArg == null ? null : firstArg - .getCurrentValue(), - secondArg == null ? null : secondArg - .getCurrentValue(), true, expLeaf, - expContainerOperator.getExpression(), - readableExpLeaf, expContainerOperator - .getReadableExpression()); - break; - default: - exp = mapReplaceArithmetic.map( - column, - targetColumnDataType, - comboOperatorReplaceType, - firstArg == null ? null : firstArg - .getCurrentValue(), - secondArg == null ? null : secondArg - .getCurrentValue(), false, expLeaf, - expContainerOperator.getExpression(), - readableExpLeaf, expContainerOperator - .getReadableExpression()); - break; - - } - readableExp = mapReplaceArithmetic - .getReadableExpression(); - expressionContainer = new ExpressionContainer(exp, - readableExp); - } - } else { - return null; - } - - } else { - switch (replaceColumnByExpressionType) { - case Replace: - exp = mapReplaceArithmetic.map( - column, - targetColumnDataType, - comboOperatorReplaceType, - firstArg == null ? null : firstArg - .getCurrentValue(), - secondArg == null ? null : secondArg - .getCurrentValue(), false); - break; - case Template: - exp = mapReplaceArithmetic.map( - column, - targetColumnDataType, - comboOperatorReplaceType, - firstArg == null ? null : firstArg - .getCurrentValue(), - secondArg == null ? null : secondArg - .getCurrentValue(), true); - break; - default: - exp = mapReplaceArithmetic.map( - column, - targetColumnDataType, - comboOperatorReplaceType, - firstArg == null ? null : firstArg - .getCurrentValue(), - secondArg == null ? null : secondArg - .getCurrentValue(), false); - break; - - } - readableExp = mapReplaceArithmetic.getReadableExpression(); - expressionContainer = new ExpressionContainer(exp, readableExp); - - } - } - return expressionContainer; - - } -} diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceColumnByExpressionDialog.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceColumnByExpressionDialog.java index d8169a0..9290a33 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceColumnByExpressionDialog.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceColumnByExpressionDialog.java @@ -137,7 +137,7 @@ public class ReplaceColumnByExpressionDialog extends Window implements ||column.getDataTypeName().compareTo(ColumnDataType.Integer.toString()) == 0 ||column.getDataTypeName().compareTo(ColumnDataType.Numeric.toString()) == 0 ||column.getDataTypeName().compareTo(ColumnDataType.Geometry.toString()) == 0 - ||column.getDataTypeName().compareTo(ColumnDataType.Date.toString()) == 0) { + ) { setHeight(HEIGHT); } else { setHeight(HEIGHT_REDUCE); diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceColumnByExpressionPanel.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceColumnByExpressionPanel.java index b65149f..dcf21c1 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceColumnByExpressionPanel.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceColumnByExpressionPanel.java @@ -1,6 +1,7 @@ package org.gcube.portlets.user.td.expressionwidget.client; import java.util.ArrayList; +import java.util.Date; import org.gcube.portlets.user.td.expressionwidget.client.resources.ExpressionResources; import org.gcube.portlets.user.td.expressionwidget.client.type.ReplaceColumnByExpressionType; @@ -18,6 +19,7 @@ import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnDataT import com.allen_sauer.gwt.log.client.Log; import com.google.gwt.event.logical.shared.ValueChangeEvent; import com.google.gwt.event.logical.shared.ValueChangeHandler; +import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.regexp.shared.MatchResult; import com.google.gwt.regexp.shared.RegExp; import com.google.gwt.user.client.ui.HasHorizontalAlignment; @@ -37,6 +39,7 @@ import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer; import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData; import com.sencha.gxt.widget.core.client.event.SelectEvent; import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler; +import com.sencha.gxt.widget.core.client.form.DateField; import com.sencha.gxt.widget.core.client.form.FieldLabel; import com.sencha.gxt.widget.core.client.form.FieldSet; import com.sencha.gxt.widget.core.client.form.Radio; @@ -75,7 +78,7 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel { private ReplaceColumnByExpressionType replaceColumnByExpressionType; - // private DateTimeFormat sdf = DateTimeFormat.getFormat("yyyy-MM-dd"); + private DateTimeFormat sdf = DateTimeFormat.getFormat("yyyy-MM-dd"); private TextButton btnApply; private TextButton btnClose; @@ -84,9 +87,8 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel { private ConditionWidget conditionWidget; private ReplaceWidget replaceWidget; - private ReplaceArithmeticWidget replaceArithmeticWidget; private TextField replaceValue; - // private DateField replaceValueDate; + private DateField replaceValueDate; private VerticalLayoutContainer conditionsVerticalLayout; private FieldLabel allRowsField; @@ -130,9 +132,7 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel { || column.getDataTypeName().compareTo( ColumnDataType.Numeric.toString()) == 0 || column.getDataTypeName().compareTo( - ColumnDataType.Geometry.toString()) == 0 || column - .getDataTypeName().compareTo( - ColumnDataType.Date.toString()) == 0)) { + ColumnDataType.Geometry.toString()) == 0)) { setHeight(HEIGHT); } else { setHeight(HEIGHT_REDUCE); @@ -229,46 +229,21 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel { VerticalLayoutContainer replaceValueFieldSetLayout = new VerticalLayoutContainer(); replaceValueFieldSet.add(replaceValueFieldSetLayout); - if (column.getDataTypeName().compareTo( - ColumnDataType.Integer.toString()) == 0 - || column.getDataTypeName().compareTo( - ColumnDataType.Numeric.toString()) == 0 - || column.getDataTypeName().compareTo( - ColumnDataType.Geometry.toString()) == 0 - || column.getDataTypeName().compareTo( - ColumnDataType.Date.toString()) == 0) { - - switch (replaceColumnByExpressionType) { - case Replace: - replaceArithmeticWidget = new ReplaceArithmeticWidget(column, - REPLACEWIDTH, REPLACEHEIGHT, eventBus); - break; - case Template: - replaceArithmeticWidget = new ReplaceArithmeticWidget(column, - columns, REPLACEWIDTH, REPLACEHEIGHT, eventBus); - break; - default: - Log.debug("Attention Replace Widget have not a valid type"); - UtilsGXT3.alert("Attention", - "Attention Replace Widget have not a valid type"); - if (parent != null) { - parent.hide(); - } - return; - - } - replaceValueFieldSetLayout.add(replaceArithmeticWidget, - new VerticalLayoutData(1, -1)); - /* - * replaceValueDate = new DateField(); - * replaceValueDate.setToolTip("Replace Value"); - * replaceValueFieldSetLayout.add(new FieldLabel(replaceValueDate, - * "Replace Value"), new VerticalLayoutData(1, -1)); - */ + if (column.getDataTypeName().compareTo(ColumnDataType.Date.toString()) == 0) { + replaceValueDate = new DateField(); + replaceValueDate.setToolTip("Replace Value"); + replaceValueFieldSetLayout.add(new FieldLabel(replaceValueDate, + "Replace Value"), new VerticalLayoutData(1, -1)); } else { if (column.getDataTypeName().compareTo( - ColumnDataType.Text.toString()) == 0) { + ColumnDataType.Text.toString()) == 0 + || column.getDataTypeName().compareTo( + ColumnDataType.Integer.toString()) == 0 + || column.getDataTypeName().compareTo( + ColumnDataType.Numeric.toString()) == 0 + || column.getDataTypeName().compareTo( + ColumnDataType.Geometry.toString()) == 0) { switch (replaceColumnByExpressionType) { case Replace: replaceWidget = new ReplaceWidget(column, REPLACEWIDTH, @@ -371,44 +346,33 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel { } String value = null; - if (column.getDataTypeName().compareTo( - ColumnDataType.Integer.toString()) == 0 - || column.getDataTypeName().compareTo( - ColumnDataType.Numeric.toString()) == 0 - || column.getDataTypeName().compareTo( - ColumnDataType.Geometry.toString()) == 0 - || column.getDataTypeName().compareTo( - ColumnDataType.Date.toString()) == 0) { + if (column.getDataTypeName().compareTo(ColumnDataType.Date.toString()) == 0) { - C_Expression cReplaceExpression = null; - try { - cReplaceExpression = replaceArithmeticWidget.getExpression(); - if (cReplaceExpression == null) { - UtilsGXT3.alert("Attention", - "Replace expression is not valid!"); + Date valueDate = replaceValueDate.getCurrentValue(); + if (valueDate == null) { + UtilsGXT3.alert("Error replace value", + "Select a valid date as replace value!"); + return; + } else { + try { + value = sdf.format(valueDate); + } catch (Throwable e) { + UtilsGXT3.alert("Error replace value", + "Select a valid date as replace value!"); return; } - } catch (ReplaceTypeMapException e) { - UtilsGXT3.alert("Attention", e.getLocalizedMessage()); - return; + callApplyReplaceColumnByExpression(cConditionExpression, value); + } - callApplyReplaceColumnByExpression(cConditionExpression, - cReplaceExpression); - /* - * Date valueDate = replaceValueDate.getCurrentValue(); if - * (valueDate == null) { UtilsGXT3.alert("Error replace value", - * "Select a valid date as replace value!"); return; } else { try { - * value = sdf.format(valueDate); } catch (Throwable e) { - * UtilsGXT3.alert("Error replace value", - * "Select a valid date as replace value!"); return; } - * callApplyReplaceColumnByExpression(cConditionExpression, value); - * - * } - */ } else { if (column.getDataTypeName().compareTo( - ColumnDataType.Text.toString()) == 0) { + ColumnDataType.Text.toString()) == 0|| column.getDataTypeName().compareTo( + ColumnDataType.Integer.toString()) == 0 + || column.getDataTypeName().compareTo( + ColumnDataType.Numeric.toString()) == 0 + || column.getDataTypeName().compareTo( + ColumnDataType.Geometry.toString()) == 0) { C_Expression cReplaceExpression = null; try { cReplaceExpression = replaceWidget.getExpression(); @@ -484,7 +448,7 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel { cReplaceExpression, replaceWidget.getReadableExpression()); expressionEvent .setC_ReplaceExpressionContainer(replaceExpressionContainer); - ; + expressionEvent.setTrId(column.getTrId()); expressionEvent.setColumnId(column.getColumnId()); expressionEvent.setColumnName(column.getName()); @@ -504,7 +468,7 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel { private boolean checkValue(String value) { try { boolean ok = false; - ColumnDataType columnDataType =ColumnDataType + ColumnDataType columnDataType = ColumnDataType .getColumnDataTypeFromId(column.getDataTypeName()); switch (columnDataType) { case Boolean: diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceWidget.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceWidget.java index eedef1e..1968a23 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceWidget.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceWidget.java @@ -9,6 +9,7 @@ import org.gcube.portlets.user.td.expressionwidget.client.properties.ReplaceElem import org.gcube.portlets.user.td.expressionwidget.client.type.ReplaceColumnByExpressionType; import org.gcube.portlets.user.td.expressionwidget.client.utils.UtilsGXT3; import org.gcube.portlets.user.td.expressionwidget.shared.exception.ReplaceTypeMapException; +import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.arithmetic.C_ArithmeticExpression; import org.gcube.portlets.user.td.expressionwidget.shared.replace.ReplaceType; import org.gcube.portlets.user.td.expressionwidget.shared.replace.ReplaceTypeMap; import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync; @@ -20,6 +21,7 @@ import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredE import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType; 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 com.allen_sauer.gwt.log.client.Log; import com.google.gwt.core.client.GWT; @@ -66,6 +68,7 @@ public class ReplaceWidget extends SimpleContainer { private EventBus eventBus; private TRId trId; private ArrayList columns; + private ArrayList arithmeticColumns; // private FieldLabel matchLabel; // private ToggleGroup groupMatch; @@ -81,6 +84,7 @@ public class ReplaceWidget extends SimpleContainer { private String itemIdSecondArg; private String itemIdHoriz; private ReplaceColumnByExpressionType replaceColumnByExpressionType; + private ColumnDataType targetColumnType; protected class ExpressionContainer { private C_Expression expression; @@ -114,7 +118,9 @@ public class ReplaceWidget extends SimpleContainer { public ReplaceWidget(ColumnData column, EventBus eventBus) { super(); replaceColumnByExpressionType = ReplaceColumnByExpressionType.Replace; - create(column.getTrId(), WIDTH, HEIGHT, eventBus); + ColumnDataType targetType = ColumnDataType + .getColumnDataTypeFromId(column.getDataTypeName()); + create(column.getTrId(), targetType, WIDTH, HEIGHT, eventBus); retrieveColumns(); } @@ -122,7 +128,9 @@ public class ReplaceWidget extends SimpleContainer { EventBus eventBus) { super(); replaceColumnByExpressionType = ReplaceColumnByExpressionType.Replace; - create(column.getTrId(), width, height, eventBus); + ColumnDataType targetType = ColumnDataType + .getColumnDataTypeFromId(column.getDataTypeName()); + create(column.getTrId(), targetType, width, height, eventBus); retrieveColumns(); } @@ -131,7 +139,9 @@ public class ReplaceWidget extends SimpleContainer { super(); replaceColumnByExpressionType = ReplaceColumnByExpressionType.Template; this.columns = columns; - create(column.getTrId(), WIDTH, HEIGHT, eventBus); + ColumnDataType targetType = ColumnDataType + .getColumnDataTypeFromId(column.getDataTypeName()); + create(column.getTrId(), targetType, WIDTH, HEIGHT, eventBus); setup(); } @@ -140,13 +150,16 @@ public class ReplaceWidget extends SimpleContainer { super(); replaceColumnByExpressionType = ReplaceColumnByExpressionType.Template; this.columns = columns; - create(column.getTrId(), width, height, eventBus); + ColumnDataType targetType = ColumnDataType + .getColumnDataTypeFromId(column.getDataTypeName()); + create(column.getTrId(), targetType, width, height, eventBus); setup(); } - protected void create(TRId trId, String width, String height, - EventBus eventBus) { + protected void create(TRId trId, ColumnDataType targetColumnType, + String width, String height, EventBus eventBus) { this.trId = trId; + this.targetColumnType = targetColumnType; setBorders(true); setWidth(width); setHeight(height); @@ -196,6 +209,16 @@ public class ReplaceWidget extends SimpleContainer { public void onSuccess(ArrayList result) { Log.trace("loaded " + result.size() + " ColumnData"); columns = result; + arithmeticColumns = new ArrayList(); + for (ColumnData col : result) { + ColumnDataType colDataType = ColumnDataType + .getColumnDataTypeFromId(col + .getDataTypeName()); + if (C_ArithmeticExpression.isAccepted(colDataType)) { + arithmeticColumns.add(col); + } + + } setup(); } @@ -211,7 +234,7 @@ public class ReplaceWidget extends SimpleContainer { itemIdHoriz = "Horiz" + trId.getId(); vert = new VerticalLayoutContainer(); - //vert.setScrollMode(ScrollMode.AUTO); Set in GXT 3.0.1 + // vert.setScrollMode(ScrollMode.AUTO); Set in GXT 3.0.1 final HBoxLayoutContainer horiz = new HBoxLayoutContainer(); @@ -244,7 +267,7 @@ public class ReplaceWidget extends SimpleContainer { comboColumns.setTriggerAction(TriggerAction.ALL); // Replace Elemet Store - ReplaceElementStore factory = new ReplaceElementStore(); + final ReplaceElementStore factory = new ReplaceElementStore(); ReplaceElementProperties props = GWT .create(ReplaceElementProperties.class); @@ -287,6 +310,11 @@ public class ReplaceWidget extends SimpleContainer { secondArg.setEmptyText(""); break; case Concat: + case Addition: + case Subtraction: + case Modulus: + case Multiplication: + case Division: break; case SubstringByRegex: comboColumns.clear(); @@ -340,19 +368,20 @@ public class ReplaceWidget extends SimpleContainer { comboReplaceElementsLeaf.setTriggerAction(TriggerAction.ALL); - // ComboConcat - ListStore storeReplaceElementsConcat = new ListStore( + // ComboOperations + ListStore storeReplaceElementsOperations = new ListStore( props.id()); - Log.debug("Store Concat: " + storeReplaceElementsConcat); - storeReplaceElementsConcat.addAll(factory.replaceElementsConcat); + Log.debug("Store Operations: " + storeReplaceElementsOperations); + storeReplaceElementsOperations + .addAll(factory.replaceElementsOperations); Log.debug("Store created"); - final ComboBox comboReplaceElementsConcat = new ComboBox( - storeReplaceElementsConcat, props.label()); + final ComboBox comboReplaceElementsOperations = new ComboBox( + storeReplaceElementsOperations, props.label()); Log.debug("Combo created"); - comboReplaceElementsConcat + comboReplaceElementsOperations .addSelectionHandler(new SelectionHandler() { public void onSelection(SelectionEvent event) { @@ -371,7 +400,7 @@ public class ReplaceWidget extends SimpleContainer { firstArg.setVisible(true); secondArg.setVisible(false); secondArg.setEmptyText(""); - removeConcat(source); + removeOperation(source); break; case ColumnValue: comboReplaceElementsLeaf.setVisible(false); @@ -381,21 +410,51 @@ public class ReplaceWidget extends SimpleContainer { firstArg.setEmptyText(""); secondArg.setVisible(false); secondArg.setEmptyText(""); - removeConcat(source); + removeOperation(source); break; case Concat: - if (!existConcat(source)) { - comboReplaceElementsLeaf.clear(); - comboReplaceElementsLeaf.setVisible(true); + comboReplaceElementsLeaf.clear(); + comboReplaceElementsLeaf.reset(); + comboReplaceElementsLeaf.getStore().clear(); + comboReplaceElementsLeaf.getStore() + .addAll(factory.replaceElements); + comboReplaceElementsLeaf.getStore().commitChanges(); + comboReplaceElementsLeaf.setVisible(true); + comboReplaceElementsLeaf.redraw(); + if (!existOperation(source)) { + comboColumns.clear(); comboColumns.setVisible(false); firstArg.setVisible(false); firstArg.setEmptyText(""); secondArg.setVisible(false); secondArg.setEmptyText(""); - addConcat(); + addOperation(); } break; + case Addition: + case Subtraction: + case Modulus: + case Multiplication: + case Division: + comboReplaceElementsLeaf.clear(); + comboReplaceElementsLeaf.reset(); + comboReplaceElementsLeaf.getStore().clear(); + comboReplaceElementsLeaf.getStore() + .addAll(factory.replaceElementsArithmetic); + comboReplaceElementsLeaf.getStore().commitChanges(); + comboReplaceElementsLeaf.setVisible(true); + comboReplaceElementsLeaf.redraw(); + if (!existOperation(source)) { + comboColumns.clear(); + comboColumns.setVisible(false); + firstArg.setVisible(false); + firstArg.setEmptyText(""); + secondArg.setVisible(false); + secondArg.setEmptyText(""); + addOperation(); + } + break; case SubstringByRegex: comboReplaceElementsLeaf.setVisible(false); comboColumns.clear(); @@ -404,7 +463,7 @@ public class ReplaceWidget extends SimpleContainer { firstArg.setEmptyText(EMPTY_TEXT_REGEXP); secondArg.setVisible(false); secondArg.setEmptyText(""); - removeConcat(source); + removeOperation(source); break; case SubstringByIndex: comboReplaceElementsLeaf.setVisible(false); @@ -414,7 +473,7 @@ public class ReplaceWidget extends SimpleContainer { firstArg.setEmptyText(EMPTY_TEXT_FROM_INDEX); secondArg.setVisible(true); secondArg.setEmptyText(EMPTY_TEXT_TO_INDEX); - removeConcat(source); + removeOperation(source); break; case SubstringByCharSeq: comboReplaceElementsLeaf.setVisible(false); @@ -424,7 +483,7 @@ public class ReplaceWidget extends SimpleContainer { firstArg.setEmptyText(EMPTY_TEXT_FROM_STRING); secondArg.setVisible(true); secondArg.setEmptyText(EMPTY_TEXT_TO_STRING); - removeConcat(source); + removeOperation(source); break; case TextReplaceMatchingRegex: comboReplaceElementsLeaf.setVisible(false); @@ -435,7 +494,7 @@ public class ReplaceWidget extends SimpleContainer { secondArg.setVisible(true); secondArg .setEmptyText(EMPTY_TEXT_REPLACE_REPLACING); - removeConcat(source); + removeOperation(source); break; default: break; @@ -448,17 +507,18 @@ public class ReplaceWidget extends SimpleContainer { }); - comboReplaceElementsConcat.setEmptyText("Select..."); - comboReplaceElementsConcat.setItemId(itemIdComboConcat); - comboReplaceElementsConcat.setWidth(COMBO_WIDTH); - comboReplaceElementsConcat.setEditable(false); - comboReplaceElementsConcat.setTriggerAction(TriggerAction.ALL); + comboReplaceElementsOperations.setEmptyText("Select..."); + comboReplaceElementsOperations.setItemId(itemIdComboConcat); + comboReplaceElementsOperations.setWidth(COMBO_WIDTH); + comboReplaceElementsOperations.setEditable(false); + comboReplaceElementsOperations.setTriggerAction(TriggerAction.ALL); - comboReplaceElementsConcat.setValue(storeReplaceElementsConcat.get(0), - true); + comboReplaceElementsOperations.setValue( + storeReplaceElementsOperations.get(0), true); // - horiz.add(comboReplaceElementsConcat, new BoxLayoutData(new Margins(0))); + horiz.add(comboReplaceElementsOperations, new BoxLayoutData( + new Margins(0))); horiz.add(comboReplaceElementsLeaf, new BoxLayoutData(new Margins(0))); horiz.add(comboColumns, new BoxLayoutData(new Margins(0))); horiz.add(firstArg, new BoxLayoutData(new Margins(0))); @@ -472,11 +532,11 @@ public class ReplaceWidget extends SimpleContainer { secondArg.setVisible(false); comboColumns.setVisible(false); comboReplaceElementsLeaf.setVisible(false); - comboReplaceElementsConcat.setVisible(true); + comboReplaceElementsOperations.setVisible(true); forceLayout(); } - protected void addConcat() { + protected void addOperation() { final HBoxLayoutContainer horiz = new HBoxLayoutContainer(); final TextField firstArg = new TextField(); @@ -506,7 +566,7 @@ public class ReplaceWidget extends SimpleContainer { comboColumns.setTriggerAction(TriggerAction.ALL); // - ReplaceElementStore factory = new ReplaceElementStore(); + final ReplaceElementStore factory = new ReplaceElementStore(); ReplaceElementProperties props = GWT .create(ReplaceElementProperties.class); @@ -549,6 +609,11 @@ public class ReplaceWidget extends SimpleContainer { secondArg.setEmptyText(""); break; case Concat: + case Addition: + case Subtraction: + case Modulus: + case Multiplication: + case Division: break; case SubstringByRegex: comboColumns.clear(); @@ -601,19 +666,20 @@ public class ReplaceWidget extends SimpleContainer { comboReplaceElementsLeaf.setTriggerAction(TriggerAction.ALL); - // ComboConcat - ListStore storeReplaceElementsConcat = new ListStore( + // ComboOperations + ListStore storeReplaceElementsOperations = new ListStore( props.id()); - Log.debug("Store Concat: " + storeReplaceElementsConcat); - storeReplaceElementsConcat.addAll(factory.replaceElementsConcat); + Log.debug("Store Concat: " + storeReplaceElementsOperations); + storeReplaceElementsOperations + .addAll(factory.replaceElementsOperations); Log.debug("Store created"); - final ComboBox comboReplaceElementsConcat = new ComboBox( - storeReplaceElementsConcat, props.label()); + final ComboBox comboReplaceElementsOperations = new ComboBox( + storeReplaceElementsOperations, props.label()); Log.debug("Combo created"); - comboReplaceElementsConcat + comboReplaceElementsOperations .addSelectionHandler(new SelectionHandler() { public void onSelection(SelectionEvent event) { @@ -633,7 +699,7 @@ public class ReplaceWidget extends SimpleContainer { firstArg.setVisible(true); secondArg.setVisible(false); secondArg.setEmptyText(""); - removeConcat(source); + removeOperation(source); break; case ColumnValue: comboReplaceElementsLeaf.setVisible(false); @@ -643,19 +709,48 @@ public class ReplaceWidget extends SimpleContainer { firstArg.setEmptyText(""); secondArg.setVisible(false); secondArg.setEmptyText(""); - removeConcat(source); + removeOperation(source); break; case Concat: - if (!existConcat(source)) { - comboReplaceElementsLeaf.clear(); - comboReplaceElementsLeaf.setVisible(true); + comboReplaceElementsLeaf.clear(); + comboReplaceElementsLeaf.reset(); + comboReplaceElementsLeaf.getStore().clear(); + comboReplaceElementsLeaf.getStore() + .addAll(factory.replaceElements); + comboReplaceElementsLeaf.getStore().commitChanges(); + comboReplaceElementsLeaf.setVisible(true); + comboReplaceElementsLeaf.redraw(); + if (!existOperation(source)) { comboColumns.clear(); comboColumns.setVisible(false); firstArg.setVisible(false); firstArg.setEmptyText(""); secondArg.setVisible(false); secondArg.setEmptyText(""); - addConcat(); + addOperation(); + } + break; + case Addition: + case Subtraction: + case Modulus: + case Multiplication: + case Division: + comboReplaceElementsLeaf.clear(); + comboReplaceElementsLeaf.reset(); + comboReplaceElementsLeaf.getStore().clear(); + comboReplaceElementsLeaf.getStore() + .addAll(factory.replaceElementsArithmetic); + comboReplaceElementsLeaf.getStore().commitChanges(); + comboReplaceElementsLeaf.setVisible(true); + comboReplaceElementsLeaf.redraw(); + if (!existOperation(source)) { + comboColumns.clear(); + comboColumns.setVisible(false); + firstArg.setVisible(false); + firstArg.setEmptyText(""); + secondArg.setVisible(false); + secondArg.setEmptyText(""); + addOperation(); } break; case SubstringByRegex: @@ -666,7 +761,7 @@ public class ReplaceWidget extends SimpleContainer { firstArg.setEmptyText(EMPTY_TEXT_REGEXP); secondArg.setVisible(false); secondArg.setEmptyText(""); - removeConcat(source); + removeOperation(source); break; case SubstringByIndex: comboReplaceElementsLeaf.setVisible(false); @@ -676,7 +771,7 @@ public class ReplaceWidget extends SimpleContainer { firstArg.setEmptyText(EMPTY_TEXT_FROM_INDEX); secondArg.setVisible(true); secondArg.setEmptyText(EMPTY_TEXT_TO_INDEX); - removeConcat(source); + removeOperation(source); break; case SubstringByCharSeq: comboReplaceElementsLeaf.setVisible(false); @@ -686,7 +781,7 @@ public class ReplaceWidget extends SimpleContainer { firstArg.setEmptyText(EMPTY_TEXT_FROM_STRING); secondArg.setVisible(true); secondArg.setEmptyText(EMPTY_TEXT_TO_STRING); - removeConcat(source); + removeOperation(source); break; case TextReplaceMatchingRegex: comboReplaceElementsLeaf.setVisible(false); @@ -697,7 +792,7 @@ public class ReplaceWidget extends SimpleContainer { secondArg.setVisible(true); secondArg .setEmptyText(EMPTY_TEXT_REPLACE_REPLACING); - removeConcat(source); + removeOperation(source); break; default: break; @@ -711,17 +806,18 @@ public class ReplaceWidget extends SimpleContainer { }); - comboReplaceElementsConcat.setEmptyText("Select..."); - comboReplaceElementsConcat.setItemId(itemIdComboConcat); - comboReplaceElementsConcat.setWidth(COMBO_WIDTH); - comboReplaceElementsConcat.setEditable(false); - comboReplaceElementsConcat.setTriggerAction(TriggerAction.ALL); + comboReplaceElementsOperations.setEmptyText("Select..."); + comboReplaceElementsOperations.setItemId(itemIdComboConcat); + comboReplaceElementsOperations.setWidth(COMBO_WIDTH); + comboReplaceElementsOperations.setEditable(false); + comboReplaceElementsOperations.setTriggerAction(TriggerAction.ALL); - comboReplaceElementsConcat.setValue(storeReplaceElementsConcat.get(0), - true); + comboReplaceElementsOperations.setValue( + storeReplaceElementsOperations.get(0), true); // - horiz.add(comboReplaceElementsConcat, new BoxLayoutData(new Margins(0))); + horiz.add(comboReplaceElementsOperations, new BoxLayoutData( + new Margins(0))); horiz.add(comboReplaceElementsLeaf, new BoxLayoutData(new Margins(0))); horiz.add(comboColumns, new BoxLayoutData(new Margins(0))); horiz.add(firstArg, new BoxLayoutData(new Margins(0))); @@ -733,11 +829,11 @@ public class ReplaceWidget extends SimpleContainer { secondArg.setVisible(false); comboColumns.setVisible(false); comboReplaceElementsLeaf.setVisible(false); - comboReplaceElementsConcat.setVisible(true); + comboReplaceElementsOperations.setVisible(true); forceLayout(); } - private void removeConcat(ComboBox source) { + private void removeOperation(ComboBox source) { HBoxLayoutContainer horiz = (HBoxLayoutContainer) source.getParent(); int index = vert.getWidgetIndex(horiz); Log.debug("No concat for index: " + index); @@ -748,7 +844,7 @@ public class ReplaceWidget extends SimpleContainer { } } - private boolean existConcat(ComboBox source) { + private boolean existOperation(ComboBox source) { boolean exist = false; HBoxLayoutContainer horiz = (HBoxLayoutContainer) source.getParent(); int index = vert.getWidgetIndex(horiz); @@ -769,7 +865,8 @@ public class ReplaceWidget extends SimpleContainer { if (vert.getWidgetCount() > 0) { int index = 0; - expressionContainer = calcCExpression(index); + ColumnDataType targetType = targetColumnType; + expressionContainer = calcCExpression(index, targetType); if (expressionContainer != null) { readableExpression = expressionContainer .getReadableExpression(); @@ -788,10 +885,10 @@ public class ReplaceWidget extends SimpleContainer { return readableExpression; } - protected ExpressionContainer calcCExpression(int index) - throws ReplaceTypeMapException { + protected ExpressionContainer calcCExpression(int index, + ColumnDataType targetType) throws ReplaceTypeMapException { ExpressionContainer expressionContainer = null; - ExpressionContainer expContainerConcat = null; + ExpressionContainer expContainerOperation = null; C_Expression exp = null; C_Expression expLeaf = null; String readableExp = ""; @@ -803,9 +900,9 @@ public class ReplaceWidget extends SimpleContainer { horiz = (HBoxLayoutContainer) vert.getWidget(index); @SuppressWarnings("unchecked") - ComboBox comboConcat = (ComboBox) horiz + ComboBox comboOperations = (ComboBox) horiz .getItemByItemId(itemIdComboConcat); - Log.debug("combo Concat: " + comboConcat.getCurrentValue()); + Log.debug("combo Concat: " + comboOperations.getCurrentValue()); @SuppressWarnings("unchecked") ComboBox comboLeaf = (ComboBox) horiz .getItemByItemId(itemIdComboLeaf); @@ -823,93 +920,29 @@ public class ReplaceWidget extends SimpleContainer { + firstArg.getCurrentValue() + ", secondArg: " + secondArg.getCurrentValue() + "]"); - ReplaceType comboConcatReplaceType = null; + ReplaceType comboOperationsReplaceType = null; ReplaceType comboLeafReplaceType = null; - if (comboConcat.getCurrentValue() == null) { - if (index == vert.getWidgetCount() - 1) { - switch (replaceColumnByExpressionType) { - case Replace: - exp = mapReplace.map( - column, - ReplaceType.Null, - firstArg == null ? null : firstArg - .getCurrentValue(), - secondArg == null ? null : secondArg - .getCurrentValue(), false); - break; - case Template: - exp = mapReplace.map( - column, - ReplaceType.Null, - firstArg == null ? null : firstArg - .getCurrentValue(), - secondArg == null ? null : secondArg - .getCurrentValue(), true); - break; - default: - exp = mapReplace.map( - column, - ReplaceType.Null, - firstArg == null ? null : firstArg - .getCurrentValue(), - secondArg == null ? null : secondArg - .getCurrentValue(), false); - break; - - } - readableExp = mapReplace.getReadableExpression(); - expressionContainer = new ExpressionContainer(exp, readableExp); - - } else { - throw new ReplaceTypeMapException("Fill all field!"); - } + if (comboOperations.getCurrentValue() == null) { + throw new ReplaceTypeMapException("Fill all field!"); } else { - comboConcatReplaceType = comboConcat.getCurrentValue() + comboOperationsReplaceType = comboOperations.getCurrentValue() .getReplaceType(); - if (comboConcatReplaceType.compareTo(ReplaceType.Concat) == 0) { - + if (comboOperationsReplaceType.compareTo(ReplaceType.Concat) == 0) { if (comboLeaf.getCurrentValue() == null) { - switch (replaceColumnByExpressionType) { - case Replace: - expLeaf = mapReplace.map( - column, - ReplaceType.Null, - firstArg == null ? null : firstArg - .getCurrentValue(), - secondArg == null ? null : secondArg - .getCurrentValue(), false); - break; - case Template: - expLeaf = mapReplace.map( - column, - ReplaceType.Null, - firstArg == null ? null : firstArg - .getCurrentValue(), - secondArg == null ? null : secondArg - .getCurrentValue(), true); - break; - default: - expLeaf = mapReplace.map( - column, - ReplaceType.Null, - firstArg == null ? null : firstArg - .getCurrentValue(), - secondArg == null ? null : secondArg - .getCurrentValue(), false); - break; - - } - - readableExpLeaf = mapReplace.getReadableExpression(); - + throw new ReplaceTypeMapException("Fill all field!"); } else { comboLeafReplaceType = comboLeaf.getCurrentValue() .getReplaceType(); + /* + * ColumnDataType cType = ColumnDataType + * .getColumnDataTypeFromId(column.getDataTypeName()); + */ switch (replaceColumnByExpressionType) { case Replace: expLeaf = mapReplace.map( column, + ColumnDataType.Text, comboLeafReplaceType, firstArg == null ? null : firstArg .getCurrentValue(), @@ -919,6 +952,7 @@ public class ReplaceWidget extends SimpleContainer { case Template: expLeaf = mapReplace.map( column, + ColumnDataType.Text, comboLeafReplaceType, firstArg == null ? null : firstArg .getCurrentValue(), @@ -928,6 +962,7 @@ public class ReplaceWidget extends SimpleContainer { default: expLeaf = mapReplace.map( column, + ColumnDataType.Text, comboLeafReplaceType, firstArg == null ? null : firstArg .getCurrentValue(), @@ -942,48 +977,52 @@ public class ReplaceWidget extends SimpleContainer { index++; if (index < vert.getWidgetCount()) { - expContainerConcat = calcCExpression(index); - if (expContainerConcat == null) { + expContainerOperation = calcCExpression(index, + ColumnDataType.Text); + if (expContainerOperation == null) { return null; } else { switch (replaceColumnByExpressionType) { case Replace: exp = mapReplace.map( column, - comboConcatReplaceType, + targetType, + comboOperationsReplaceType, firstArg == null ? null : firstArg .getCurrentValue(), secondArg == null ? null : secondArg .getCurrentValue(), false, expLeaf, - expContainerConcat.getExpression(), - readableExpLeaf, expContainerConcat + expContainerOperation.getExpression(), + readableExpLeaf, expContainerOperation .getReadableExpression()); break; case Template: exp = mapReplace.map( column, - comboConcatReplaceType, + targetType, + comboOperationsReplaceType, firstArg == null ? null : firstArg .getCurrentValue(), secondArg == null ? null : secondArg .getCurrentValue(), true, expLeaf, - expContainerConcat.getExpression(), - readableExpLeaf, expContainerConcat + expContainerOperation.getExpression(), + readableExpLeaf, expContainerOperation .getReadableExpression()); break; default: exp = mapReplace.map( column, - comboConcatReplaceType, + targetType, + comboOperationsReplaceType, firstArg == null ? null : firstArg .getCurrentValue(), secondArg == null ? null : secondArg .getCurrentValue(), false, expLeaf, - expContainerConcat.getExpression(), - readableExpLeaf, expContainerConcat + expContainerOperation.getExpression(), + readableExpLeaf, expContainerOperation .getReadableExpression()); break; - + } readableExp = mapReplace.getReadableExpression(); expressionContainer = new ExpressionContainer(exp, @@ -994,30 +1033,161 @@ public class ReplaceWidget extends SimpleContainer { } } else { - switch (replaceColumnByExpressionType) { - case Replace: - exp = mapReplace.map(column, comboConcatReplaceType, - firstArg == null ? null : firstArg.getCurrentValue(), - secondArg == null ? null : secondArg.getCurrentValue(), - false); - break; - case Template: - exp = mapReplace.map(column, comboConcatReplaceType, - firstArg == null ? null : firstArg.getCurrentValue(), - secondArg == null ? null : secondArg.getCurrentValue(), - true); - break; - default: - exp = mapReplace.map(column, comboConcatReplaceType, - firstArg == null ? null : firstArg.getCurrentValue(), - secondArg == null ? null : secondArg.getCurrentValue(), - false); - break; - - } - readableExp = mapReplace.getReadableExpression(); - expressionContainer = new ExpressionContainer(exp, readableExp); + if (comboOperationsReplaceType.compareTo(ReplaceType.Addition) == 0 + || comboOperationsReplaceType + .compareTo(ReplaceType.Subtraction) == 0 + || comboOperationsReplaceType + .compareTo(ReplaceType.Modulus) == 0 + || comboOperationsReplaceType + .compareTo(ReplaceType.Multiplication) == 0 + || comboOperationsReplaceType + .compareTo(ReplaceType.Division) == 0) { + ColumnDataType cType; + if (comboLeaf.getCurrentValue() == null) { + throw new ReplaceTypeMapException("Fill all field!"); + } else { + + comboLeafReplaceType = comboLeaf.getCurrentValue() + .getReplaceType(); + cType = ColumnDataType + .getColumnDataTypeFromId(column + .getDataTypeName()); + + switch (replaceColumnByExpressionType) { + case Replace: + expLeaf = mapReplace.map( + column, + cType, + comboLeafReplaceType, + firstArg == null ? null : firstArg + .getCurrentValue(), + secondArg == null ? null : secondArg + .getCurrentValue(), false); + break; + case Template: + expLeaf = mapReplace.map( + column, + cType, + comboLeafReplaceType, + firstArg == null ? null : firstArg + .getCurrentValue(), + secondArg == null ? null : secondArg + .getCurrentValue(), true); + break; + default: + expLeaf = mapReplace.map( + column, + cType, + comboLeafReplaceType, + firstArg == null ? null : firstArg + .getCurrentValue(), + secondArg == null ? null : secondArg + .getCurrentValue(), false); + break; + } + + readableExpLeaf = mapReplace.getReadableExpression(); + } + + index++; + if (index < vert.getWidgetCount()) { + expContainerOperation = calcCExpression(index, + cType); + if (expContainerOperation == null) { + return null; + } else { + switch (replaceColumnByExpressionType) { + case Replace: + exp = mapReplace.map( + column, + targetType, + comboOperationsReplaceType, + firstArg == null ? null : firstArg + .getCurrentValue(), + secondArg == null ? null : secondArg + .getCurrentValue(), false, + expLeaf, expContainerOperation + .getExpression(), + readableExpLeaf, expContainerOperation + .getReadableExpression()); + break; + case Template: + exp = mapReplace.map( + column, + targetType, + comboOperationsReplaceType, + firstArg == null ? null : firstArg + .getCurrentValue(), + secondArg == null ? null : secondArg + .getCurrentValue(), true, + expLeaf, expContainerOperation + .getExpression(), + readableExpLeaf, expContainerOperation + .getReadableExpression()); + break; + default: + exp = mapReplace.map( + column, + targetType, + comboOperationsReplaceType, + firstArg == null ? null : firstArg + .getCurrentValue(), + secondArg == null ? null : secondArg + .getCurrentValue(), false, + expLeaf, expContainerOperation + .getExpression(), + readableExpLeaf, expContainerOperation + .getReadableExpression()); + break; + + } + readableExp = mapReplace.getReadableExpression(); + expressionContainer = new ExpressionContainer(exp, + readableExp); + } + } else { + return null; + } + + } else { + switch (replaceColumnByExpressionType) { + case Replace: + exp = mapReplace.map( + column, + targetType, + comboOperationsReplaceType, + firstArg == null ? null : firstArg + .getCurrentValue(), + secondArg == null ? null : secondArg + .getCurrentValue(), false); + break; + case Template: + exp = mapReplace.map( + column, + targetType, + comboOperationsReplaceType, + firstArg == null ? null : firstArg + .getCurrentValue(), + secondArg == null ? null : secondArg + .getCurrentValue(), true); + break; + default: + exp = mapReplace.map( + column, + targetType, + comboOperationsReplaceType, + firstArg == null ? null : firstArg + .getCurrentValue(), + secondArg == null ? null : secondArg + .getCurrentValue(), false); + break; + + } + readableExp = mapReplace.getReadableExpression(); + expressionContainer = new ExpressionContainer(exp, + readableExp); + } } } return expressionContainer; diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/properties/ReplaceArithmeticElement.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/properties/ReplaceArithmeticElement.java deleted file mode 100644 index 4bf61b0..0000000 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/properties/ReplaceArithmeticElement.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.gcube.portlets.user.td.expressionwidget.client.properties; - -import java.io.Serializable; - -import org.gcube.portlets.user.td.expressionwidget.shared.replace.ReplaceArithmeticType; - -/** - * - * @author giancarlo email: g.panichi@isti.cnr.it - * - */ -public class ReplaceArithmeticElement implements Serializable { - - private static final long serialVersionUID = 3187480746998044539L; - private Integer id; - private ReplaceArithmeticType replaceArithmeticType; - - public ReplaceArithmeticElement() { - super(); - } - - public ReplaceArithmeticElement(Integer id, ReplaceArithmeticType replaceArithmeticType) { - super(); - this.id = id; - this.replaceArithmeticType = replaceArithmeticType; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getLabel() { - return replaceArithmeticType.toString(); - } - - public ReplaceArithmeticType getReplaceArithmeticType() { - return replaceArithmeticType; - } - - public void setReplaceArithmeticType(ReplaceArithmeticType replaceArithmeticType) { - this.replaceArithmeticType = replaceArithmeticType; - } - - @Override - public String toString() { - return "ReplaceArithmeticElement [id=" + id - + ", replaceArithmeticType=" + replaceArithmeticType + "]"; - } - - - -} diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/properties/ReplaceArithmeticElementProperties.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/properties/ReplaceArithmeticElementProperties.java deleted file mode 100644 index 5c32208..0000000 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/properties/ReplaceArithmeticElementProperties.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.gcube.portlets.user.td.expressionwidget.client.properties; - -import com.google.gwt.editor.client.Editor.Path; -import com.sencha.gxt.data.shared.LabelProvider; -import com.sencha.gxt.data.shared.ModelKeyProvider; -import com.sencha.gxt.data.shared.PropertyAccess; - -/** - * - * @author "Giancarlo Panichi" - * g.panichi@isti.cnr.it - * - */ -public interface ReplaceArithmeticElementProperties extends PropertyAccess { - - @Path("id") - ModelKeyProvider id(); - - LabelProvider label(); - -} diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/properties/ReplaceArithmeticElementStore.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/properties/ReplaceArithmeticElementStore.java deleted file mode 100644 index 488c867..0000000 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/properties/ReplaceArithmeticElementStore.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.gcube.portlets.user.td.expressionwidget.client.properties; - -import java.util.ArrayList; - -import org.gcube.portlets.user.td.expressionwidget.shared.replace.ReplaceArithmeticType; - -/** - * - * @author "Giancarlo Panichi" g.panichi@isti.cnr.it - * - */ -public class ReplaceArithmeticElementStore { - - public ArrayList replaceArithmeticElementsOperators = new ArrayList() { - - private static final long serialVersionUID = 7803379977670393398L; - - { - add(new ReplaceArithmeticElement(1, ReplaceArithmeticType.Value)); - add(new ReplaceArithmeticElement(2, ReplaceArithmeticType.ColumnValue)); - add(new ReplaceArithmeticElement(3, ReplaceArithmeticType.SubstringByRegex)); - add(new ReplaceArithmeticElement(4, ReplaceArithmeticType.SubstringByIndex)); - add(new ReplaceArithmeticElement(5, ReplaceArithmeticType.SubstringByCharSeq)); - add(new ReplaceArithmeticElement(6, ReplaceArithmeticType.TextReplaceMatchingRegex)); - add(new ReplaceArithmeticElement(7, ReplaceArithmeticType.Addition)); - add(new ReplaceArithmeticElement(8, ReplaceArithmeticType.Subtraction)); - add(new ReplaceArithmeticElement(9, ReplaceArithmeticType.Modulus)); - add(new ReplaceArithmeticElement(10, ReplaceArithmeticType.Multiplication)); - add(new ReplaceArithmeticElement(11, ReplaceArithmeticType.Division)); - } - }; - - public ArrayList replaceArithmeticElements = new ArrayList() { - private static final long serialVersionUID = 7803379977670393398L; - - { - add(new ReplaceArithmeticElement(1, ReplaceArithmeticType.Value)); - add(new ReplaceArithmeticElement(2, ReplaceArithmeticType.ColumnValue)); - add(new ReplaceArithmeticElement(3, ReplaceArithmeticType.SubstringByRegex)); - add(new ReplaceArithmeticElement(4, ReplaceArithmeticType.SubstringByIndex)); - add(new ReplaceArithmeticElement(5, ReplaceArithmeticType.SubstringByCharSeq)); - add(new ReplaceArithmeticElement(6, ReplaceArithmeticType.TextReplaceMatchingRegex)); - - } - }; - -} diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/properties/ReplaceElementStore.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/properties/ReplaceElementStore.java index d4d6b52..455839e 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/properties/ReplaceElementStore.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/properties/ReplaceElementStore.java @@ -12,7 +12,7 @@ import org.gcube.portlets.user.td.expressionwidget.shared.replace.ReplaceType; */ public class ReplaceElementStore { - public ArrayList replaceElementsConcat = new ArrayList() { + public ArrayList replaceElementsOperations = new ArrayList() { private static final long serialVersionUID = 1690916203781730778L; @@ -24,6 +24,11 @@ public class ReplaceElementStore { add(new ReplaceElement(5, ReplaceType.SubstringByCharSeq)); add(new ReplaceElement(6, ReplaceType.TextReplaceMatchingRegex)); add(new ReplaceElement(7, ReplaceType.Concat)); + add(new ReplaceElement(8, ReplaceType.Addition)); + add(new ReplaceElement(9, ReplaceType.Subtraction)); + add(new ReplaceElement(10, ReplaceType.Modulus)); + add(new ReplaceElement(11, ReplaceType.Multiplication)); + add(new ReplaceElement(12, ReplaceType.Division)); } }; @@ -41,5 +46,16 @@ public class ReplaceElementStore { } }; + + public ArrayList replaceElementsArithmetic = new ArrayList() { + + private static final long serialVersionUID = 1690916203781730778L; + + { + add(new ReplaceElement(1, ReplaceType.ColumnValue)); + + } + }; + } diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/model/composite/arithmetic/C_ArithmeticExpression.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/model/composite/arithmetic/C_ArithmeticExpression.java index 487ba75..e2a87d1 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/model/composite/arithmetic/C_ArithmeticExpression.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/model/composite/arithmetic/C_ArithmeticExpression.java @@ -7,59 +7,64 @@ import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnDataT /** * - * @author giancarlo - * email: g.panichi@isti.cnr.it + * @author giancarlo email: g.panichi@isti.cnr.it * */ public class C_ArithmeticExpression extends C_Expression { private static final long serialVersionUID = 897961910530874376L; - - private String id="ArithmeticExpression"; - - public static final ArrayList acceptedDataTypes=new ArrayList(); - + private String id = "ArithmeticExpression"; + + public static final ArrayList acceptedDataTypes = new ArrayList(); + protected C_Expression leftArgument; protected C_Expression rightArgument; public C_ArithmeticExpression() { - + } - - public C_ArithmeticExpression(C_Expression leftArgument, C_Expression rightArgument) { + + public C_ArithmeticExpression(C_Expression leftArgument, + C_Expression rightArgument) { this.leftArgument = leftArgument; this.rightArgument = rightArgument; } - static { acceptedDataTypes.add(ColumnDataType.Numeric); acceptedDataTypes.add(ColumnDataType.Integer); acceptedDataTypes.add(ColumnDataType.Date); acceptedDataTypes.add(ColumnDataType.Geometry); } - - + public String getReturnedDataType() { return "DataType"; } - public ArrayList allowedLeftDataTypes() { + public ArrayList allowedLeftDataTypes() { return acceptedDataTypes; } - - public ArrayList allowedRightDataTypes() { + + public ArrayList allowedRightDataTypes() { return acceptedDataTypes; } - - + + public static boolean isAccepted(ColumnDataType columnDataType) { + for (ColumnDataType c : acceptedDataTypes) { + if (c.compareTo(columnDataType) == 0) { + return true; + } + } + return false; + } + @Override public String getId() { return id; } - public C_Expression getLeftArgument() { return leftArgument; } @@ -81,8 +86,5 @@ public class C_ArithmeticExpression extends C_Expression { return "C_ArithmeticExpression [id=" + id + ", leftArgument=" + leftArgument + ", rightArgument=" + rightArgument + "]"; } - - - - + } diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/replace/ReplaceArithmeticType.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/replace/ReplaceArithmeticType.java deleted file mode 100644 index 654ba54..0000000 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/replace/ReplaceArithmeticType.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.gcube.portlets.user.td.expressionwidget.shared.replace; - -/** - * - * @author giancarlo - * email: g.panichi@isti.cnr.it - * - */ -public enum ReplaceArithmeticType { - Value("Value"), - ColumnValue("Column Value"), - SubstringByRegex("Substring by Regex"), - SubstringByIndex("Substring by Index"), - SubstringByCharSeq("Substring by Char Seq."), - TextReplaceMatchingRegex("Replace Matching Regex"), - Addition("Addition"), - Subtraction("Subtraction"), - Modulus("Modulus"), - Multiplication("Multiplication"), - Division("Division"); - - /** - * @param text - */ - private ReplaceArithmeticType(final String id) { - this.id = id; - } - - private final String id; - - @Override - public String toString() { - return id; - } - -} diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/replace/ReplaceArithmeticTypeMap.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/replace/ReplaceArithmeticTypeMap.java deleted file mode 100644 index 07b062d..0000000 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/replace/ReplaceArithmeticTypeMap.java +++ /dev/null @@ -1,537 +0,0 @@ -package org.gcube.portlets.user.td.expressionwidget.shared.replace; - -import org.gcube.portlets.user.td.expressionwidget.shared.exception.ReplaceTypeMapException; -import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.arithmetic.C_Addition; -import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.arithmetic.C_ArithmeticExpression; -import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.arithmetic.C_Division; -import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.arithmetic.C_Modulus; -import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.arithmetic.C_Multiplication; -import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.arithmetic.C_Subtraction; -import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.functions.C_Cast; -import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_SubstringByIndex; -import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_SubstringByRegex; -import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_SubstringPosition; -import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_TextReplaceMatchingRegex; -import org.gcube.portlets.user.td.expressionwidget.shared.model.leaf.C_ColumnReference; -import org.gcube.portlets.user.td.expressionwidget.shared.model.leaf.C_ColumnReferencePlaceholder; -import org.gcube.portlets.user.td.expressionwidget.shared.model.leaf.TD_Value; -import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; -import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression; -import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnDataType; - -import com.allen_sauer.gwt.log.client.Log; - -/** - * ReplaceArithmeticTypeMap creates a C_Expression usable client-side - * - * @author "Giancarlo Panichi" g.panichi@isti.cnr.it - * - */ -public class ReplaceArithmeticTypeMap { - private String readableExpression; - - public ReplaceArithmeticTypeMap() { - - } - - public C_Expression map(ColumnData column, - ColumnDataType targetColumnDataType, - ReplaceArithmeticType replaceType, String firstArg, - String secondArg, boolean template) throws ReplaceTypeMapException { - return map(column, targetColumnDataType, replaceType, firstArg, - secondArg, template, null, null, null, null); - } - - public C_Expression map(ColumnData column, - ColumnDataType targetColumnDataType, - ReplaceArithmeticType replaceType, String firstArg, - String secondArg, boolean template, C_Expression firstE, - C_Expression secondE, String readableFirstE, String readableSecondE) - throws ReplaceTypeMapException { - Log.debug("ReplaceArithmeticTypeMap Map"); - C_Expression exp = null; - readableExpression = new String(); - if (template) { - exp = mapPlaceHolder(column, targetColumnDataType, replaceType, - firstArg, secondArg, firstE, secondE, readableFirstE, - readableSecondE); - } else { - exp = mapColumnReference(column, targetColumnDataType, replaceType, - firstArg, secondArg, firstE, secondE, readableFirstE, - readableSecondE); - } - return exp; - } - - public C_Expression mapPlaceHolder(ColumnData column, - ColumnDataType targetColumnDataType, - ReplaceArithmeticType replaceType, String firstArg, - String secondArg, C_Expression firstE, C_Expression secondE, - String readableFirstE, String readableSecondE) - throws ReplaceTypeMapException { - Log.debug("ReplaceArithmeticTypeMap Map Place Holder"); - C_Expression exp = null; - - if (column == null) { - switch (replaceType) { - case Value: - checkArithmeticTypeArgument(targetColumnDataType, firstArg); - exp = new TD_Value(targetColumnDataType, firstArg); - readableExpression = "Value(" + firstArg + ")"; - break; - case Addition: - exp = new C_Addition(firstE, secondE); - readableExpression = "Addition(" + readableFirstE + ", " - + readableSecondE + ")"; - break; - case Subtraction: - exp = new C_Subtraction(firstE, secondE); - readableExpression = "Subtraction(" + readableFirstE + ", " - + readableSecondE + ")"; - break; - case Modulus: - exp = new C_Modulus(firstE, secondE); - readableExpression = "Modulus(" + readableFirstE + ", " - + readableSecondE + ")"; - break; - case Multiplication: - exp = new C_Multiplication(firstE, secondE); - readableExpression = "Multiplication(" + readableFirstE + ", " - + readableSecondE + ")"; - break; - case Division: - exp = new C_Division(firstE, secondE); - readableExpression = "Division(" + readableFirstE + ", " - + readableSecondE + ")"; - break; - default: - throw new ReplaceTypeMapException("No valid column selected"); - } - return exp; - } - - Log.debug("Column Data Type Name:" + column.getDataTypeName()); - ColumnDataType dataType = ColumnDataType - .getColumnDataTypeFromId(column - .getDataTypeName()); - Log.debug("Data Type:" + dataType); - C_ColumnReferencePlaceholder placeH = new C_ColumnReferencePlaceholder( - dataType, column.getColumnId()); - - C_Expression placeHolder; - String readablePlaceHolder; - if (dataType != targetColumnDataType) { - placeHolder = new C_Cast(placeH, targetColumnDataType); - readablePlaceHolder = "Cast(" + column.getColumnId() + "," - + targetColumnDataType + ")"; - } else { - placeHolder = placeH; - readablePlaceHolder = column.getColumnId(); - - } - - C_Expression placeHolderForStringExp; - String readablePlaceHolderForStringExp; - if (dataType != ColumnDataType.Text) { - placeHolderForStringExp = new C_Cast(placeH, ColumnDataType.Text); - readablePlaceHolderForStringExp = "Cast(" + column.getColumnId() - + "," + ColumnDataType.Text + ")"; - } else { - placeHolderForStringExp = placeH; - readablePlaceHolderForStringExp = column.getColumnId(); - - } - - Log.debug("placeHolder:" + placeHolder); - - TD_Value fArg, sArg; - C_Expression posFrom, posTo; - - switch (replaceType) { - case Value: - checkArithmeticTypeArgument(targetColumnDataType, firstArg); - exp = new TD_Value(targetColumnDataType, firstArg); - readableExpression = "Value(" + firstArg + ")"; - break; - case ColumnValue: - exp = placeHolder; - readableExpression = "ColumnValue(" + readablePlaceHolder + ")"; - break; - case Addition: - exp = new C_Addition(firstE, secondE); - readableExpression = "Addition(" + readableFirstE + ", " - + readableSecondE + ")"; - break; - case Subtraction: - exp = new C_Subtraction(firstE, secondE); - readableExpression = "Subtraction(" + readableFirstE + ", " - + readableSecondE + ")"; - break; - case Modulus: - exp = new C_Modulus(firstE, secondE); - readableExpression = "Modulus(" + readableFirstE + ", " - + readableSecondE + ")"; - break; - case Multiplication: - exp = new C_Multiplication(firstE, secondE); - readableExpression = "Multiplication(" + readableFirstE + ", " - + readableSecondE + ")"; - break; - case Division: - exp = new C_Division(firstE, secondE); - readableExpression = "Division(" + readableFirstE + ", " - + readableSecondE + ")"; - break; - case SubstringByRegex: - checkTypeArgument(ColumnDataType.Text, firstArg); - fArg = new TD_Value(ColumnDataType.Text, firstArg); - C_SubstringByRegex substringByRegex = new C_SubstringByRegex( - placeHolderForStringExp, fArg); - exp = new C_Cast(substringByRegex, targetColumnDataType); - readableExpression = "Cast(SubstringByRegex(" - + readablePlaceHolderForStringExp + ", " + firstArg + ")," - + targetColumnDataType + ")"; - break; - case SubstringByIndex: - checkTypeArgument(ColumnDataType.Integer, firstArg); - checkTypeArgument(ColumnDataType.Integer, secondArg); - fArg = new TD_Value(ColumnDataType.Integer, firstArg); - sArg = new TD_Value(ColumnDataType.Integer, secondArg); - C_SubstringByIndex substringByIndex = new C_SubstringByIndex( - placeHolderForStringExp, fArg, sArg); - exp = new C_Cast(substringByIndex, targetColumnDataType); - readableExpression = "Cast(SubstringByIndex(" - + readablePlaceHolderForStringExp + ", " + firstArg + ", " - + secondArg + ")," + targetColumnDataType + ")"; - break; - case SubstringByCharSeq: - checkTypeArgument(ColumnDataType.Text, firstArg); - fArg = new TD_Value(ColumnDataType.Text, firstArg); - posFrom = new C_SubstringPosition(placeHolderForStringExp, fArg); - checkTypeArgument(ColumnDataType.Text, secondArg); - sArg = new TD_Value(ColumnDataType.Text, secondArg); - posTo = new C_SubstringPosition(placeHolderForStringExp, fArg); - C_SubstringByIndex substringByCharSeq = new C_SubstringByIndex( - placeHolderForStringExp, posFrom, posTo); - exp = new C_Cast(substringByCharSeq, targetColumnDataType); - readableExpression = "Cast(SubstringByCharSeq(" - + readablePlaceHolderForStringExp + ", " + firstArg + ", " - + secondArg + ")," + targetColumnDataType + ")"; - break; - case TextReplaceMatchingRegex: - checkTypeArgument(ColumnDataType.Text, firstArg); - checkTypeArgument(ColumnDataType.Text, secondArg); - fArg = new TD_Value(ColumnDataType.Text, firstArg); - sArg = new TD_Value(ColumnDataType.Text, secondArg); - C_TextReplaceMatchingRegex textReplaceMatchingRegex = new C_TextReplaceMatchingRegex( - placeHolderForStringExp, fArg, sArg); - exp = new C_Cast(textReplaceMatchingRegex, targetColumnDataType); - readableExpression = "Cast(TextReplaceMatchingRegex(" - + readablePlaceHolderForStringExp + ", " + firstArg + ", " - + secondArg + ")," + targetColumnDataType + ")"; - break; - default: - break; - } - return exp; - } - - public C_Expression mapColumnReference(ColumnData column, - ColumnDataType targetColumnDataType, - ReplaceArithmeticType replaceType, String firstArg, - String secondArg, C_Expression firstE, C_Expression secondE, - String readableFirstE, String readableSecondE) - throws ReplaceTypeMapException { - Log.debug("ReplaceArithmeticTypeMap Map Typed Column Reference"); - C_Expression exp = null; - - if (column == null) { - switch (replaceType) { - case Value: - checkArithmeticTypeArgument(targetColumnDataType, firstArg); - exp = new TD_Value(targetColumnDataType, firstArg); - readableExpression = "Value(" + firstArg + ")"; - break; - case Addition: - exp = new C_Addition(firstE, secondE); - readableExpression = "Addition(" + readableFirstE + ", " - + readableSecondE + ")"; - break; - case Subtraction: - exp = new C_Subtraction(firstE, secondE); - readableExpression = "Subtraction(" + readableFirstE + ", " - + readableSecondE + ")"; - break; - case Modulus: - exp = new C_Modulus(firstE, secondE); - readableExpression = "Modulus(" + readableFirstE + ", " - + readableSecondE + ")"; - break; - case Multiplication: - exp = new C_Multiplication(firstE, secondE); - readableExpression = "Multiplication(" + readableFirstE + ", " - + readableSecondE + ")"; - break; - case Division: - exp = new C_Division(firstE, secondE); - readableExpression = "Division(" + readableFirstE + ", " - + readableSecondE + ")"; - break; - default: - throw new ReplaceTypeMapException("No valid column selected"); - } - return exp; - } - - Log.debug("Column Data Type Name:" + column.getDataTypeName()); - ColumnDataType dataType = ColumnDataType - .getColumnDataTypeFromId(column - .getDataTypeName()); - Log.debug("Data Type:" + dataType); - - C_ColumnReference columnRef = new C_ColumnReference(column.getTrId(), - dataType, column.getColumnId()); - - C_Expression columnReference; - String readableColumnReference; - if (dataType != targetColumnDataType) { - columnReference = new C_Cast(columnRef, targetColumnDataType); - readableColumnReference = "Cast(" + column.getColumnId() + "," - + targetColumnDataType + ")"; - } else { - columnReference = columnRef; - readableColumnReference = column.getColumnId(); - - } - - C_Expression columnReferenceForStringExp; - String readableColumnReferenceForStringExp; - if (dataType != ColumnDataType.Text) { - columnReferenceForStringExp = new C_Cast(columnRef, - ColumnDataType.Text); - readableColumnReferenceForStringExp = "Cast(" - + column.getColumnId() + "," + ColumnDataType.Text + ")"; - } else { - columnReferenceForStringExp = columnRef; - readableColumnReferenceForStringExp = column.getColumnId(); - - } - - Log.debug("Typed Column Reference:" + columnReference); - - TD_Value fArg, sArg; - C_Expression posFrom, posTo; - - switch (replaceType) { - case Value: - checkArithmeticTypeArgument(targetColumnDataType, firstArg); - exp = new TD_Value(targetColumnDataType, firstArg); - readableExpression = "Value(" + firstArg + ")"; - break; - case ColumnValue: - exp = columnReference; - readableExpression = "ColumnValue(" + readableColumnReference + ")"; - break; - case Addition: - exp = new C_Addition(firstE, secondE); - readableExpression = "Addition(" + readableFirstE + ", " - + readableSecondE + ")"; - break; - case Subtraction: - exp = new C_Subtraction(firstE, secondE); - readableExpression = "Subtraction(" + readableFirstE + ", " - + readableSecondE + ")"; - break; - case Modulus: - exp = new C_Modulus(firstE, secondE); - readableExpression = "Modulus(" + readableFirstE + ", " - + readableSecondE + ")"; - break; - case Multiplication: - exp = new C_Multiplication(firstE, secondE); - readableExpression = "Multiplication(" + readableFirstE + ", " - + readableSecondE + ")"; - break; - case Division: - exp = new C_Division(firstE, secondE); - readableExpression = "Division(" + readableFirstE + ", " - + readableSecondE + ")"; - break; - case SubstringByRegex: - checkTypeArgument(ColumnDataType.Text, firstArg); - fArg = new TD_Value(ColumnDataType.Text, firstArg); - C_SubstringByRegex substringByRegex = new C_SubstringByRegex( - columnReferenceForStringExp, fArg); - exp = new C_Cast(substringByRegex, targetColumnDataType); - readableExpression = "Cast(SubStringByRegex(" - + readableColumnReferenceForStringExp + ", " + firstArg - + ")," + targetColumnDataType + ")"; - break; - case SubstringByIndex: - checkTypeArgument(ColumnDataType.Integer, firstArg); - checkTypeArgument(ColumnDataType.Integer, secondArg); - fArg = new TD_Value(ColumnDataType.Integer, firstArg); - sArg = new TD_Value(ColumnDataType.Integer, secondArg); - C_SubstringByIndex substringByIndex = new C_SubstringByIndex( - columnReferenceForStringExp, fArg, sArg); - exp = new C_Cast(substringByIndex, targetColumnDataType); - readableExpression = "Cast(SubstringByIndex(" - + readableColumnReferenceForStringExp + ", " + firstArg - + ", " + secondArg + ")," + targetColumnDataType + ")"; - break; - case SubstringByCharSeq: - checkTypeArgument(ColumnDataType.Text, firstArg); - fArg = new TD_Value(ColumnDataType.Text, firstArg); - posFrom = new C_SubstringPosition(columnReferenceForStringExp, fArg); - checkTypeArgument(ColumnDataType.Text, secondArg); - sArg = new TD_Value(ColumnDataType.Text, secondArg); - posTo = new C_SubstringPosition(columnReferenceForStringExp, fArg); - C_SubstringByIndex substringByCharSeq = new C_SubstringByIndex( - columnReferenceForStringExp, posFrom, posTo); - exp = new C_Cast(substringByCharSeq, targetColumnDataType); - readableExpression = "Cast(SubstringByCharSeq(" - + readableColumnReferenceForStringExp + ", " + firstArg - + ", " + secondArg + ")," + targetColumnDataType + ")"; - break; - case TextReplaceMatchingRegex: - checkTypeArgument(ColumnDataType.Text, firstArg); - checkTypeArgument(ColumnDataType.Text, secondArg); - fArg = new TD_Value(ColumnDataType.Text, firstArg); - sArg = new TD_Value(ColumnDataType.Text, secondArg); - C_TextReplaceMatchingRegex textReplaceMatchingRegex = new C_TextReplaceMatchingRegex( - columnReferenceForStringExp, fArg, sArg); - exp = new C_Cast(textReplaceMatchingRegex, targetColumnDataType); - readableExpression = "Cast(TextReplaceMatchingRegex(" - + readableColumnReferenceForStringExp + ", " + firstArg - + ", " + secondArg + ")," + targetColumnDataType + ")"; - break; - default: - break; - } - - return exp; - } - - public String getReadableExpression() { - return readableExpression; - } - - protected void checkArithmeticTypeArgument(ColumnDataType columnDataType, - String arg) throws ReplaceTypeMapException { - boolean accepted = false; - for (ColumnDataType acceptedColumnDataType : C_ArithmeticExpression.acceptedDataTypes) { - if (acceptedColumnDataType.compareTo(columnDataType) == 0) { - accepted = true; - break; - } - } - - if (!accepted) { - throw new ReplaceTypeMapException("Attention, " + columnDataType - + " is not a valid arithmetic type!"); - } - - if (columnDataType == ColumnDataType.Date) { - if (arg == null || arg.isEmpty()) { - throw new ReplaceTypeMapException( - "Insert a valid Date (ex: 2015-01-10)!"); - } - } else { - if (columnDataType == ColumnDataType.Geometry) { - if (arg == null || arg.isEmpty()) { - throw new ReplaceTypeMapException( - "Insert a valid Geometry (ex: POINT(10 10))!"); - } - } else { - if (columnDataType == ColumnDataType.Integer) { - if (arg == null) { - throw new ReplaceTypeMapException( - "Insert a valid Integer(ex: -1, 0, 1, 2)!"); - } - - try { - Integer.parseInt(arg); - } catch (NumberFormatException e) { - throw new ReplaceTypeMapException(arg - + " is not valid Integer(ex: -1, 0, 1, 2)!"); - } - } else { - if (columnDataType == ColumnDataType.Numeric) { - if (arg == null) { - throw new ReplaceTypeMapException( - "Insert a valid Numeric(ex: -1.2, 0, 1, 2.4)!"); - } - try { - Float.parseFloat(arg); - } catch (NumberFormatException e) { - throw new ReplaceTypeMapException( - arg - + " is not valid Numeric(ex: -1.2, 0, 1, 2.4)!"); - } - } else { - - } - } - } - } - - } - - protected void checkTypeArgument(ColumnDataType columnDataType, String arg) - throws ReplaceTypeMapException { - if (columnDataType == ColumnDataType.Text) { - if (arg == null) { - arg = ""; - } - } else { - if (columnDataType == ColumnDataType.Boolean) { - if (arg == null) { - throw new ReplaceTypeMapException( - "Insert a valid Boolean(ex: true, false)!"); - } - } else { - if (columnDataType == ColumnDataType.Date) { - - } else { - if (columnDataType == ColumnDataType.Geometry) { - - } else { - if (columnDataType == ColumnDataType.Integer) { - if (arg == null) { - throw new ReplaceTypeMapException( - "Insert a valid Integer(ex: -1, 0, 1, 2)!"); - } - - try { - Integer.parseInt(arg); - } catch (NumberFormatException e) { - throw new ReplaceTypeMapException( - arg - + " is not valid Integer(ex: -1, 0, 1, 2)!"); - } - } else { - if (columnDataType == ColumnDataType.Numeric) { - if (arg == null) { - throw new ReplaceTypeMapException( - "Insert a valid Numeric(ex: -1.2, 0, 1, 2.4)!"); - } - try { - Float.parseFloat(arg); - } catch (NumberFormatException e) { - throw new ReplaceTypeMapException( - arg - + " is not valid Numeric(ex: -1.2, 0, 1, 2.4)!"); - } - } else { - - } - } - } - } - } - - } - } - -} diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/replace/ReplaceType.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/replace/ReplaceType.java index e6398c6..36861b4 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/replace/ReplaceType.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/replace/ReplaceType.java @@ -7,14 +7,20 @@ package org.gcube.portlets.user.td.expressionwidget.shared.replace; * */ public enum ReplaceType { - Null("Null"), Value("Value"), ColumnValue("Column Value"), SubstringByRegex("Substring by Regex"), SubstringByIndex("Substring by Index"), SubstringByCharSeq("Substring by Char Seq."), TextReplaceMatchingRegex("Replace Matching Regex"), - Concat("Concat"); + Concat("Concat"), + Addition("Addition"), + Subtraction("Subtraction"), + Modulus("Modulus"), + Multiplication("Multiplication"), + Division("Division"); + + /** * @param text diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/replace/ReplaceTypeMap.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/replace/ReplaceTypeMap.java index 3ff86a3..f406246 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/replace/ReplaceTypeMap.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/replace/ReplaceTypeMap.java @@ -1,6 +1,11 @@ package org.gcube.portlets.user.td.expressionwidget.shared.replace; import org.gcube.portlets.user.td.expressionwidget.shared.exception.ReplaceTypeMapException; +import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.arithmetic.C_Addition; +import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.arithmetic.C_Division; +import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.arithmetic.C_Modulus; +import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.arithmetic.C_Multiplication; +import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.arithmetic.C_Subtraction; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.functions.C_Cast; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_Concat; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_SubstringByIndex; @@ -30,28 +35,28 @@ public class ReplaceTypeMap { } - public C_Expression map(ColumnData column, ReplaceType replaceType, + public C_Expression map(ColumnData column, ColumnDataType targetType, ReplaceType replaceType, String firstArg, String secondArg,boolean template) throws ReplaceTypeMapException { - return map(column, replaceType,firstArg, secondArg, template, null, null, null, null); + return map(column, targetType, replaceType,firstArg, secondArg, template, null, null, null, null); } - public C_Expression map(ColumnData column, ReplaceType replaceType, + public C_Expression map(ColumnData column, ColumnDataType targetType, ReplaceType replaceType, String firstArg, String secondArg, boolean template, C_Expression firstE, C_Expression secondE, String readableFirstE, String readableSecondE) throws ReplaceTypeMapException { Log.debug("ReplaceTypeMap Map"); C_Expression exp = null; readableExpression = new String(); if (template) { - exp = mapPlaceHolder(column, replaceType, firstArg, secondArg, + exp = mapPlaceHolder(column, targetType, replaceType, firstArg, secondArg, firstE, secondE, readableFirstE,readableSecondE); } else { - exp = mapColumnReference(column, replaceType, firstArg, + exp = mapColumnReference(column, targetType, replaceType, firstArg, secondArg, firstE, secondE,readableFirstE,readableSecondE); } return exp; } - public C_Expression mapPlaceHolder(ColumnData column, + public C_Expression mapPlaceHolder(ColumnData column,ColumnDataType targetType, ReplaceType replaceType, String firstArg, String secondArg, C_Expression firstE, C_Expression secondE,String readableFirstE, String readableSecondE) throws ReplaceTypeMapException { Log.debug("ReplaceTypeMap Map Place Holder"); @@ -59,27 +64,127 @@ public class ReplaceTypeMap { if(column==null){ switch (replaceType) { - case Null: - exp = new TD_Value(ColumnDataType.Text, ""); - readableExpression = "Null()"; - break; case Value: - checkTypeArgument(ColumnDataType.Text,firstArg); - exp = new TD_Value(ColumnDataType.Text, firstArg); + checkTypeArgument(targetType,firstArg); + exp = new TD_Value(targetType, firstArg); readableExpression = "Value(" + firstArg + ")"; break; case Concat: - exp = new C_Concat(firstE, secondE); - readableExpression = "Concat(" + readableFirstE - + ", " + readableSecondE + ")"; + C_Concat concat = new C_Concat(firstE, secondE); + exp= new C_Cast(concat,targetType); + readableExpression = "Cast(Concat(" + readableFirstE + + ", " + readableSecondE + "),"+targetType+")"; + break; + case Addition: + C_Addition add = new C_Addition(firstE, secondE); + exp= new C_Cast(add, targetType); + readableExpression = "Cast(Addition(" + readableFirstE + ", " + + readableSecondE + "),"+targetType+")"; + break; + case Subtraction: + C_Subtraction sub = new C_Subtraction(firstE, secondE); + exp= new C_Cast(sub,targetType); + readableExpression = "Cast(Subtraction(" + readableFirstE + ", " + + readableSecondE + "),"+targetType+")"; + break; + case Modulus: + C_Modulus modu = new C_Modulus(firstE, secondE); + exp=new C_Cast(modu,targetType); + readableExpression = "Cast(Modulus(" + readableFirstE + ", " + + readableSecondE + "),"+targetType+")"; + break; + case Multiplication: + C_Multiplication multi = new C_Multiplication(firstE, secondE); + exp=new C_Cast(multi,targetType); + + readableExpression = "Cast(Multiplication(" + readableFirstE + ", " + + readableSecondE + "),"+targetType+")"; + break; + case Division: + C_Division divi = new C_Division(firstE, secondE); + exp=new C_Cast(divi,targetType); + readableExpression = "Cast(Division(" + readableFirstE + ", " + + readableSecondE + "),"+targetType+")"; break; default: throw new ReplaceTypeMapException("No valid column selected"); } return exp; } - - + + switch (replaceType) { + case Value: + checkTypeArgument(targetType,firstArg); + exp = new TD_Value(targetType, firstArg); + readableExpression = "Value(" + firstArg + ")"; + break; + case ColumnValue: + exp = columnValuePlaceHolder(column, targetType); + break; + case Concat: + C_Concat concat = new C_Concat(firstE, secondE); + exp= new C_Cast(concat,targetType); + readableExpression = "Cast(Concat(" + readableFirstE + + ", " + readableSecondE + "),"+targetType+")"; + break; + case Addition: + C_Addition add = new C_Addition(firstE, secondE); + exp= new C_Cast(add, targetType); + readableExpression = "Cast(Addition(" + readableFirstE + ", " + + readableSecondE + "),"+targetType+")"; + break; + case Subtraction: + C_Subtraction sub = new C_Subtraction(firstE, secondE); + exp= new C_Cast(sub,targetType); + readableExpression = "Cast(Subtraction(" + readableFirstE + ", " + + readableSecondE + "),"+targetType+")"; + break; + case Modulus: + C_Modulus modu = new C_Modulus(firstE, secondE); + exp=new C_Cast(modu,targetType); + readableExpression = "Cast(Modulus(" + readableFirstE + ", " + + readableSecondE + "),"+targetType+")"; + break; + case Multiplication: + C_Multiplication multi = new C_Multiplication(firstE, secondE); + exp=new C_Cast(multi,targetType); + + readableExpression = "Cast(Multiplication(" + readableFirstE + ", " + + readableSecondE + "),"+targetType+")"; + break; + case Division: + C_Division divi = new C_Division(firstE, secondE); + exp=new C_Cast(divi,targetType); + readableExpression = "Cast(Division(" + readableFirstE + ", " + + readableSecondE + "),"+targetType+")"; + break; + case SubstringByRegex: + exp = substringByRegexPlaceHolder(column, targetType, firstArg); + break; + case SubstringByIndex: + exp = substringByIndexPlaceHolder(column, targetType, firstArg, + secondArg); + break; + case SubstringByCharSeq: + exp = substringByCharSeqPlaceHolder(column, targetType, firstArg, + secondArg); + break; + case TextReplaceMatchingRegex: + exp = textReplaceMatchingRegexPlaceHolder(column, targetType, + firstArg, secondArg); + break; + default: + break; + } + return exp; + } + + private C_Expression textReplaceMatchingRegexPlaceHolder(ColumnData column, + ColumnDataType targetType, String firstArg, String secondArg) + throws ReplaceTypeMapException { + C_Expression exp; + TD_Value fArg; + TD_Value sArg; Log.debug("Column Data Type Name:" + column.getDataTypeName()); ColumnDataType dataType = ColumnDataType .getColumnDataTypeFromId(column @@ -90,8 +195,8 @@ public class ReplaceTypeMap { C_Expression placeHolder; String readablePlaceHolder; if(dataType!=ColumnDataType.Text){ - placeHolder=new C_Cast(placeH,ColumnDataType.Text); - readablePlaceHolder= "Cast("+column.getColumnId()+")"; + placeHolder=new C_Cast(placeH, ColumnDataType.Text); + readablePlaceHolder= "Cast("+column.getColumnId()+","+ColumnDataType.Text+")"; } else { placeHolder=placeH; readablePlaceHolder= column.getColumnId(); @@ -99,71 +204,157 @@ public class ReplaceTypeMap { } Log.debug("placeHolder:" + placeHolder); - TD_Value fArg, sArg; - C_Expression posFrom, posTo; - - switch (replaceType) { - case Null: - exp = new TD_Value(ColumnDataType.Text, ""); - readableExpression = "Null()"; - break; - case Value: - checkTypeArgument(ColumnDataType.Text,firstArg); - exp = new TD_Value(ColumnDataType.Text, firstArg); - readableExpression = "Value(" + firstArg + ")"; - break; - case ColumnValue: - exp = placeHolder; - readableExpression = "ColumnValue(" + readablePlaceHolder + ")"; - break; - case Concat: - exp = new C_Concat(firstE, secondE); - readableExpression = "Concat(" + readableFirstE - + ", " + readableSecondE + ")"; - break; - case SubstringByRegex: - checkTypeArgument(ColumnDataType.Text,firstArg); - fArg = new TD_Value(ColumnDataType.Text, firstArg); - exp = new C_SubstringByRegex(placeHolder, fArg); - readableExpression = "SubStringByRegex(" + readablePlaceHolder - + ", " + firstArg + ")"; - break; - case SubstringByIndex: - checkTypeArgument(ColumnDataType.Integer,firstArg); - checkTypeArgument(ColumnDataType.Integer,secondArg); - fArg = new TD_Value(ColumnDataType.Integer, firstArg); - sArg = new TD_Value(ColumnDataType.Integer, secondArg); - exp = new C_SubstringByIndex(placeHolder, fArg, sArg); - readableExpression = "SubstringByIndex(" + readablePlaceHolder - + ", " + firstArg + ", " + secondArg + ")"; - break; - case SubstringByCharSeq: - checkTypeArgument(ColumnDataType.Text,firstArg); - fArg = new TD_Value(ColumnDataType.Text, firstArg); - posFrom = new C_SubstringPosition(placeHolder, fArg); - checkTypeArgument(ColumnDataType.Text,secondArg); - sArg = new TD_Value(ColumnDataType.Text, secondArg); - posTo = new C_SubstringPosition(placeHolder, fArg); - exp = new C_SubstringByIndex(placeHolder, posFrom, posTo); - readableExpression = "SubstringByCharSeq(" + readablePlaceHolder - + ", " + firstArg + ", " + secondArg + ")"; - break; - case TextReplaceMatchingRegex: - checkTypeArgument(ColumnDataType.Text,firstArg); - checkTypeArgument(ColumnDataType.Text,secondArg); - fArg = new TD_Value(ColumnDataType.Text, firstArg); - sArg = new TD_Value(ColumnDataType.Text, secondArg); - exp = new C_TextReplaceMatchingRegex(placeHolder, fArg, sArg); - readableExpression = "TextReplaceMatchingRegex(" + readablePlaceHolder - + ", " + firstArg + ", " + secondArg + ")"; - break; - default: - break; - } + checkTypeArgument(ColumnDataType.Text,firstArg); + checkTypeArgument(ColumnDataType.Text,secondArg); + fArg = new TD_Value(ColumnDataType.Text, firstArg); + sArg = new TD_Value(ColumnDataType.Text, secondArg); + C_TextReplaceMatchingRegex substring = new C_TextReplaceMatchingRegex(placeHolder, fArg, sArg); + exp=new C_Cast(substring, targetType); + readableExpression = "Cast(TextReplaceMatchingRegex(" + readablePlaceHolder + + ", " + firstArg + ", " + secondArg + "),"+targetType+")"; return exp; } - public C_Expression mapColumnReference(ColumnData column, + private C_Expression substringByCharSeqPlaceHolder(ColumnData column, + ColumnDataType targetType, String firstArg, String secondArg) + throws ReplaceTypeMapException { + C_Expression exp; + TD_Value fArg; + //TD_Value sArg; + C_Expression posFrom; + C_Expression posTo; + Log.debug("Column Data Type Name:" + column.getDataTypeName()); + ColumnDataType dataType = ColumnDataType + .getColumnDataTypeFromId(column + .getDataTypeName()); + Log.debug("Data Type:" + dataType); + C_ColumnReferencePlaceholder placeH = new C_ColumnReferencePlaceholder( + dataType, column.getColumnId()); + C_Expression placeHolder; + String readablePlaceHolder; + if(dataType!=ColumnDataType.Text){ + placeHolder=new C_Cast(placeH, ColumnDataType.Text); + readablePlaceHolder= "Cast("+column.getColumnId()+","+ColumnDataType.Text+")"; + } else { + placeHolder=placeH; + readablePlaceHolder= column.getColumnId(); + + } + Log.debug("placeHolder:" + placeHolder); + + + checkTypeArgument(ColumnDataType.Text,firstArg); + fArg = new TD_Value(ColumnDataType.Text, firstArg); + posFrom = new C_SubstringPosition(placeHolder, fArg); + checkTypeArgument(ColumnDataType.Text,secondArg); + //sArg = new TD_Value(ColumnDataType.Text, secondArg); + posTo = new C_SubstringPosition(placeHolder, fArg); + C_SubstringByIndex substring = new C_SubstringByIndex(placeHolder, posFrom, posTo); + exp=new C_Cast(substring, targetType); + readableExpression = "Cast(SubstringByCharSeq(" + readablePlaceHolder + + ", " + firstArg + ", " + secondArg + "),"+targetType+")"; + return exp; + } + + private C_Expression substringByIndexPlaceHolder(ColumnData column, + ColumnDataType targetType, String firstArg, String secondArg) + throws ReplaceTypeMapException { + C_Expression exp; + TD_Value fArg; + TD_Value sArg; + Log.debug("Column Data Type Name:" + column.getDataTypeName()); + ColumnDataType dataType = ColumnDataType + .getColumnDataTypeFromId(column + .getDataTypeName()); + Log.debug("Data Type:" + dataType); + C_ColumnReferencePlaceholder placeH = new C_ColumnReferencePlaceholder( + dataType, column.getColumnId()); + C_Expression placeHolder; + String readablePlaceHolder; + if(dataType!=ColumnDataType.Text){ + placeHolder=new C_Cast(placeH, ColumnDataType.Text); + readablePlaceHolder= "Cast("+column.getColumnId()+","+ColumnDataType.Text+")"; + } else { + placeHolder=placeH; + readablePlaceHolder= column.getColumnId(); + + } + Log.debug("placeHolder:" + placeHolder); + + + checkTypeArgument(ColumnDataType.Integer,firstArg); + checkTypeArgument(ColumnDataType.Integer,secondArg); + fArg = new TD_Value(ColumnDataType.Integer, firstArg); + sArg = new TD_Value(ColumnDataType.Integer, secondArg); + C_SubstringByIndex substring = new C_SubstringByIndex(placeHolder, fArg, sArg); + exp=new C_Cast(substring, targetType); + readableExpression = "Cast(SubstringByIndex(" + readablePlaceHolder + + ", " + firstArg + ", " + secondArg + "),"+targetType+")"; + return exp; + } + + private C_Expression substringByRegexPlaceHolder(ColumnData column, + ColumnDataType targetType, String firstArg) + throws ReplaceTypeMapException { + C_Expression exp; + TD_Value fArg; + Log.debug("Column Data Type Name:" + column.getDataTypeName()); + ColumnDataType dataType = ColumnDataType + .getColumnDataTypeFromId(column + .getDataTypeName()); + Log.debug("Data Type:" + dataType); + C_ColumnReferencePlaceholder placeH = new C_ColumnReferencePlaceholder( + dataType, column.getColumnId()); + C_Expression placeHolder; + String readablePlaceHolder; + if(dataType!=ColumnDataType.Text){ + placeHolder=new C_Cast(placeH, ColumnDataType.Text); + readablePlaceHolder= "Cast("+column.getColumnId()+","+ColumnDataType.Text+")"; + } else { + placeHolder=placeH; + readablePlaceHolder= column.getColumnId(); + + } + Log.debug("placeHolder:" + placeHolder); + + checkTypeArgument(ColumnDataType.Text,firstArg); + fArg = new TD_Value(ColumnDataType.Text, firstArg); + C_SubstringByRegex substring = new C_SubstringByRegex(placeHolder, fArg); + exp=new C_Cast(substring, targetType); + readableExpression = "Cast(SubStringByRegex(" + readablePlaceHolder + + ", " + firstArg + "),"+targetType+")"; + return exp; + } + + private C_Expression columnValuePlaceHolder(ColumnData column, + ColumnDataType targetType) { + C_Expression exp; + Log.debug("Column Data Type Name:" + column.getDataTypeName()); + ColumnDataType dataType = ColumnDataType + .getColumnDataTypeFromId(column + .getDataTypeName()); + Log.debug("Data Type:" + dataType); + C_ColumnReferencePlaceholder placeH = new C_ColumnReferencePlaceholder( + dataType, column.getColumnId()); + C_Expression placeHolder; + String readablePlaceHolder; + if(dataType!=targetType){ + placeHolder=new C_Cast(placeH, targetType); + readablePlaceHolder= "Cast("+column.getColumnId()+","+targetType+")"; + } else { + placeHolder=placeH; + readablePlaceHolder= column.getColumnId(); + + } + Log.debug("placeHolder:" + placeHolder); + + + exp = placeHolder; + readableExpression = "ColumnValue(" + readablePlaceHolder + ")"; + return exp; + } + + public C_Expression mapColumnReference(ColumnData column,ColumnDataType targetType, ReplaceType replaceType, String firstArg, String secondArg, C_Expression firstE, C_Expression secondE, String readableFirstE, String readableSecondE) throws ReplaceTypeMapException { Log.debug("ReplaceTypeMap Map Typed Column Reference"); @@ -171,19 +362,47 @@ public class ReplaceTypeMap { if(column==null){ switch (replaceType) { - case Null: - exp = new TD_Value(ColumnDataType.Text, ""); - readableExpression = "Null()"; - break; case Value: - checkTypeArgument(ColumnDataType.Text,firstArg); - exp = new TD_Value(ColumnDataType.Text, firstArg); + checkTypeArgument(targetType,firstArg); + exp = new TD_Value(targetType, firstArg); readableExpression = "Value(" + firstArg + ")"; break; case Concat: - exp = new C_Concat(firstE, secondE); - readableExpression = "Concat(" + readableFirstE - + ", " + readableSecondE + ")"; + C_Concat concat = new C_Concat(firstE, secondE); + exp= new C_Cast(concat,targetType); + readableExpression = "Cast(Concat(" + readableFirstE + + ", " + readableSecondE + "),"+targetType+")"; + break; + case Addition: + C_Addition add = new C_Addition(firstE, secondE); + exp= new C_Cast(add, targetType); + readableExpression = "Cast(Addition(" + readableFirstE + ", " + + readableSecondE + "),"+targetType+")"; + break; + case Subtraction: + C_Subtraction sub = new C_Subtraction(firstE, secondE); + exp= new C_Cast(sub,targetType); + readableExpression = "Cast(Subtraction(" + readableFirstE + ", " + + readableSecondE + "),"+targetType+")"; + break; + case Modulus: + C_Modulus modu = new C_Modulus(firstE, secondE); + exp=new C_Cast(modu,targetType); + readableExpression = "Cast(Modulus(" + readableFirstE + ", " + + readableSecondE + "),"+targetType+")"; + break; + case Multiplication: + C_Multiplication multi = new C_Multiplication(firstE, secondE); + exp=new C_Cast(multi,targetType); + + readableExpression = "Cast(Multiplication(" + readableFirstE + ", " + + readableSecondE + "),"+targetType+")"; + break; + case Division: + C_Division divi = new C_Division(firstE, secondE); + exp=new C_Cast(divi,targetType); + readableExpression = "Cast(Division(" + readableFirstE + ", " + + readableSecondE + "),"+targetType+")"; break; default: throw new ReplaceTypeMapException("No valid column selected"); @@ -192,6 +411,79 @@ public class ReplaceTypeMap { } + switch (replaceType) { + case Value: + checkTypeArgument(targetType, firstArg); + exp = new TD_Value(targetType, firstArg); + readableExpression = "Value(" + firstArg + ")"; + break; + case ColumnValue: + exp = columnValueReference(column, targetType); + break; + case Concat: + C_Concat concat = new C_Concat(firstE, secondE); + exp= new C_Cast(concat,targetType); + readableExpression = "Cast(Concat(" + readableFirstE + + ", " + readableSecondE + "),"+targetType+")"; + break; + case Addition: + C_Addition add = new C_Addition(firstE, secondE); + exp= new C_Cast(add, targetType); + readableExpression = "Cast(Addition(" + readableFirstE + ", " + + readableSecondE + "),"+targetType+")"; + break; + case Subtraction: + C_Subtraction sub = new C_Subtraction(firstE, secondE); + exp= new C_Cast(sub,targetType); + readableExpression = "Cast(Subtraction(" + readableFirstE + ", " + + readableSecondE + "),"+targetType+")"; + break; + case Modulus: + C_Modulus modu = new C_Modulus(firstE, secondE); + exp=new C_Cast(modu,targetType); + readableExpression = "Cast(Modulus(" + readableFirstE + ", " + + readableSecondE + "),"+targetType+")"; + break; + case Multiplication: + C_Multiplication multi = new C_Multiplication(firstE, secondE); + exp=new C_Cast(multi,targetType); + + readableExpression = "Cast(Multiplication(" + readableFirstE + ", " + + readableSecondE + "),"+targetType+")"; + break; + case Division: + C_Division divi = new C_Division(firstE, secondE); + exp=new C_Cast(divi,targetType); + readableExpression = "Cast(Division(" + readableFirstE + ", " + + readableSecondE + "),"+targetType+")"; + break; + case SubstringByRegex: + exp = SubstringByRegexReference(column, targetType, firstArg); + break; + case SubstringByIndex: + exp = substringByIndexReference(column, targetType, firstArg, + secondArg); + break; + case SubstringByCharSeq: + exp = substringByCharSeq(column, targetType, firstArg, secondArg); + break; + case TextReplaceMatchingRegex: + exp = textReplaceMatchingRegexReference(column, targetType, + firstArg, secondArg); + break; + default: + break; + } + + return exp; + } + + private C_Expression textReplaceMatchingRegexReference(ColumnData column, + ColumnDataType targetType, String firstArg, String secondArg) + throws ReplaceTypeMapException { + C_Expression exp; + TD_Value fArg; + TD_Value sArg; Log.debug("Column Data Type Name:" + column.getDataTypeName()); ColumnDataType dataType = ColumnDataType .getColumnDataTypeFromId(column @@ -205,7 +497,7 @@ public class ReplaceTypeMap { String readableColumnReference; if(dataType!=ColumnDataType.Text){ columnReference=new C_Cast(columnRef,ColumnDataType.Text); - readableColumnReference= "Cast("+column.getColumnId()+")"; + readableColumnReference= "Cast("+column.getColumnId()+","+ColumnDataType.Text+")"; } else { columnReference=columnRef; readableColumnReference= column.getColumnId(); @@ -213,69 +505,158 @@ public class ReplaceTypeMap { } Log.debug("Typed Column Reference:" + columnReference); - TD_Value fArg, sArg; - C_Expression posFrom, posTo; + checkTypeArgument(ColumnDataType.Text, firstArg); + checkTypeArgument(ColumnDataType.Text, secondArg); + fArg = new TD_Value(ColumnDataType.Text, firstArg); + sArg = new TD_Value(ColumnDataType.Text, secondArg); + C_TextReplaceMatchingRegex substring = new C_TextReplaceMatchingRegex(columnReference, fArg, sArg); + exp=new C_Cast(substring, targetType); + readableExpression = "Cast(TextReplaceMatchingRegex(" + readableColumnReference + + ", " + firstArg + ", " + secondArg + "),"+targetType+")"; + return exp; + } + + private C_Expression substringByCharSeq(ColumnData column, + ColumnDataType targetType, String firstArg, String secondArg) + throws ReplaceTypeMapException { + C_Expression exp; + TD_Value fArg; + C_Expression posFrom; + C_Expression posTo; + Log.debug("Column Data Type Name:" + column.getDataTypeName()); + ColumnDataType dataType = ColumnDataType + .getColumnDataTypeFromId(column + .getDataTypeName()); + Log.debug("Data Type:" + dataType); + + C_ColumnReference columnRef = new C_ColumnReference( + column.getTrId(), dataType, column.getColumnId()); + + C_Expression columnReference; + String readableColumnReference; + if(dataType!=ColumnDataType.Text){ + columnReference=new C_Cast(columnRef,ColumnDataType.Text); + readableColumnReference= "Cast("+column.getColumnId()+","+ColumnDataType.Text+")"; + } else { + columnReference=columnRef; + readableColumnReference= column.getColumnId(); - switch (replaceType) { - case Null: - exp = new TD_Value(ColumnDataType.Text, ""); - readableExpression = "Null()"; - break; - case Value: - checkTypeArgument(ColumnDataType.Text, firstArg); - exp = new TD_Value(ColumnDataType.Text, firstArg); - readableExpression = "Value(" + firstArg + ")"; - break; - case ColumnValue: - exp = columnReference; - readableExpression = "ColumnValue(" + readableColumnReference + ")"; - break; - case Concat: - exp = new C_Concat(firstE, secondE); - readableExpression = "Concat(" + readableFirstE - + ", " + readableSecondE + ")"; - break; - case SubstringByRegex: - checkTypeArgument(ColumnDataType.Text, firstArg); - fArg = new TD_Value(ColumnDataType.Text, firstArg); - exp = new C_SubstringByRegex(columnReference, fArg); - readableExpression = "SubStringByRegex(" + readableColumnReference - + ", " + firstArg + ")"; - break; - case SubstringByIndex: - checkTypeArgument(ColumnDataType.Integer, firstArg); - checkTypeArgument(ColumnDataType.Integer, secondArg); - fArg = new TD_Value(ColumnDataType.Integer, firstArg); - sArg = new TD_Value(ColumnDataType.Integer, secondArg); - exp = new C_SubstringByIndex(columnReference, fArg, sArg); - readableExpression = "SubstringByIndex(" + readableColumnReference - + ", " + firstArg + ", " + secondArg + ")"; - break; - case SubstringByCharSeq: - checkTypeArgument(ColumnDataType.Text, firstArg); - fArg = new TD_Value(ColumnDataType.Text, firstArg); - posFrom = new C_SubstringPosition(columnReference, fArg); - checkTypeArgument(ColumnDataType.Text, secondArg); - sArg = new TD_Value(ColumnDataType.Text, secondArg); - posTo = new C_SubstringPosition(columnReference, fArg); - exp = new C_SubstringByIndex(columnReference, posFrom, posTo); - readableExpression = "SubstringByCharSeq(" - + readableColumnReference + ", " + firstArg + ", " - + secondArg + ")"; - break; - case TextReplaceMatchingRegex: - checkTypeArgument(ColumnDataType.Text, firstArg); - checkTypeArgument(ColumnDataType.Text, secondArg); - fArg = new TD_Value(ColumnDataType.Text, firstArg); - sArg = new TD_Value(ColumnDataType.Text, secondArg); - exp = new C_TextReplaceMatchingRegex(columnReference, fArg, sArg); - readableExpression = "TextReplaceMatchingRegex(" + readableColumnReference - + ", " + firstArg + ", " + secondArg + ")"; - break; - default: - break; } + Log.debug("Typed Column Reference:" + columnReference); + + checkTypeArgument(ColumnDataType.Text, firstArg); + fArg = new TD_Value(ColumnDataType.Text, firstArg); + posFrom = new C_SubstringPosition(columnReference, fArg); + checkTypeArgument(ColumnDataType.Text, secondArg); + //sArg = new TD_Value(ColumnDataType.Text, secondArg); + posTo = new C_SubstringPosition(columnReference, fArg); + C_SubstringByIndex substring = new C_SubstringByIndex(columnReference, posFrom, posTo); + exp=new C_Cast(substring, targetType); + readableExpression = "Cast(SubstringByCharSeq(" + + readableColumnReference + ", " + firstArg + ", " + + secondArg + "),"+targetType+")"; + return exp; + } + private C_Expression substringByIndexReference(ColumnData column, + ColumnDataType targetType, String firstArg, String secondArg) + throws ReplaceTypeMapException { + C_Expression exp; + TD_Value fArg; + TD_Value sArg; + Log.debug("Column Data Type Name:" + column.getDataTypeName()); + ColumnDataType dataType = ColumnDataType + .getColumnDataTypeFromId(column + .getDataTypeName()); + Log.debug("Data Type:" + dataType); + + C_ColumnReference columnRef = new C_ColumnReference( + column.getTrId(), dataType, column.getColumnId()); + + C_Expression columnReference; + String readableColumnReference; + if(dataType!=ColumnDataType.Text){ + columnReference=new C_Cast(columnRef,ColumnDataType.Text); + readableColumnReference= "Cast("+column.getColumnId()+","+ColumnDataType.Text+")"; + } else { + columnReference=columnRef; + readableColumnReference= column.getColumnId(); + + } + Log.debug("Typed Column Reference:" + columnReference); + + checkTypeArgument(ColumnDataType.Integer, firstArg); + checkTypeArgument(ColumnDataType.Integer, secondArg); + fArg = new TD_Value(ColumnDataType.Integer, firstArg); + sArg = new TD_Value(ColumnDataType.Integer, secondArg); + C_SubstringByIndex substring = new C_SubstringByIndex(columnReference, fArg, sArg); + exp=new C_Cast(substring,targetType); + readableExpression = "Cast(SubstringByIndex(" + readableColumnReference + + ", " + firstArg + ", " + secondArg + "),"+targetType+")"; + return exp; + } + + private C_Expression SubstringByRegexReference(ColumnData column, + ColumnDataType targetType, String firstArg) + throws ReplaceTypeMapException { + C_Expression exp; + TD_Value fArg; + Log.debug("Column Data Type Name:" + column.getDataTypeName()); + ColumnDataType dataType = ColumnDataType + .getColumnDataTypeFromId(column + .getDataTypeName()); + Log.debug("Data Type:" + dataType); + + C_ColumnReference columnRef = new C_ColumnReference( + column.getTrId(), dataType, column.getColumnId()); + + C_Expression columnReference; + String readableColumnReference; + if(dataType!=ColumnDataType.Text){ + columnReference=new C_Cast(columnRef,ColumnDataType.Text); + readableColumnReference= "Cast("+column.getColumnId()+","+ColumnDataType.Text+")"; + } else { + columnReference=columnRef; + readableColumnReference= column.getColumnId(); + + } + Log.debug("Typed Column Reference:" + columnReference); + + + checkTypeArgument(ColumnDataType.Text, firstArg); + fArg = new TD_Value(ColumnDataType.Text, firstArg); + C_SubstringByRegex substring= new C_SubstringByRegex(columnReference, fArg); + exp=new C_Cast(substring, targetType); + readableExpression = "Cast(SubStringByRegex(" + readableColumnReference + + ", " + firstArg + "),"+targetType+")"; + return exp; + } + + private C_Expression columnValueReference(ColumnData column, + ColumnDataType targetType) { + C_Expression exp; + Log.debug("Column Data Type Name:" + column.getDataTypeName()); + ColumnDataType dataType = ColumnDataType + .getColumnDataTypeFromId(column + .getDataTypeName()); + Log.debug("Data Type:" + dataType); + + C_ColumnReference columnRef = new C_ColumnReference( + column.getTrId(), dataType, column.getColumnId()); + + C_Expression columnReference; + String readableColumnReference; + if(dataType!=targetType){ + columnReference=new C_Cast(columnRef,targetType); + readableColumnReference= "Cast("+column.getColumnId()+","+targetType+")"; + } else { + columnReference=columnRef; + readableColumnReference= column.getColumnId(); + + } + Log.debug("Typed Column Reference:" + columnReference); + exp = columnReference; + readableExpression = "ColumnValue(" + readableColumnReference + ")"; return exp; }