diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ColumnExpressionPanel.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ColumnExpressionPanel.java index 310a276..ddbd530 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ColumnExpressionPanel.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ColumnExpressionPanel.java @@ -1,7 +1,7 @@ package org.gcube.portlets.user.td.expressionwidget.client; import org.gcube.portlets.user.td.expressionwidget.client.resources.ExpressionResources; -import org.gcube.portlets.user.td.expressionwidget.shared.exception.OperatorTypeMapException; +import org.gcube.portlets.user.td.expressionwidget.shared.exception.ConditionTypeMapException; import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; import org.gcube.portlets.user.td.monitorwidget.client.utils.UtilsGXT3; import org.gcube.portlets.user.td.widgetcommonevent.client.event.ExpressionEvent; @@ -326,7 +326,7 @@ public class ColumnExpressionPanel extends FramedPanel { C_Expression exp; try { exp = conditionWidget.getExpression(); - } catch (OperatorTypeMapException e) { + } catch (ConditionTypeMapException e) { Log.debug(e.getLocalizedMessage()); UtilsGXT3.alert("Attention", e.getLocalizedMessage()); return; diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ConditionWidget.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ConditionWidget.java index ef492fe..1c29e76 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ConditionWidget.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ConditionWidget.java @@ -10,8 +10,8 @@ import org.gcube.portlets.user.td.expressionwidget.client.operation.Operation; import org.gcube.portlets.user.td.expressionwidget.client.operation.OperationProperties; import org.gcube.portlets.user.td.expressionwidget.client.operation.OperationsStore; import org.gcube.portlets.user.td.expressionwidget.client.resources.ExpressionResources; -import org.gcube.portlets.user.td.expressionwidget.shared.exception.OperatorTypeMapException; -import org.gcube.portlets.user.td.expressionwidget.shared.model.OperatorTypeMap; +import org.gcube.portlets.user.td.expressionwidget.shared.condition.ConditionTypeMap; +import org.gcube.portlets.user.td.expressionwidget.shared.exception.ConditionTypeMapException; 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; @@ -488,7 +488,7 @@ public class ConditionWidget extends SimpleContainer { } - public C_Expression getExpression() throws OperatorTypeMapException { + public C_Expression getExpression() throws ConditionTypeMapException { C_Expression exp = null; readableExpression = new String(); List arguments = new ArrayList(); @@ -501,7 +501,7 @@ public class ConditionWidget extends SimpleContainer { DateTimeFormat sdf = DateTimeFormat.getFormat("yyyy-MM-dd"); - OperatorTypeMap mapOp = new OperatorTypeMap(); + ConditionTypeMap mapOp = new ConditionTypeMap(); Iterator iteratorVert = vert.iterator(); HBoxLayoutContainer horiz; while (iteratorVert.hasNext()) { 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 new file mode 100644 index 0000000..6098723 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceArithmeticWidget.java @@ -0,0 +1,1027 @@ +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.properties.ReplaceElement; +import org.gcube.portlets.user.td.expressionwidget.client.properties.ReplaceElementProperties; +import org.gcube.portlets.user.td.expressionwidget.client.properties.ReplaceElementStore; +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.ReplaceType; +import org.gcube.portlets.user.td.expressionwidget.shared.replace.ReplaceTypeMap; +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 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 ArrayList columns; + + // private FieldLabel matchLabel; + // private ToggleGroup groupMatch; + + private VerticalLayoutContainer vert; + // protected ColumnData column; + + private String readableExpression; + private String itemIdComboArithmetic; + 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; + create(column.getTrId(), WIDTH, HEIGHT, eventBus); + retrieveColumns(); + } + + public ReplaceArithmeticWidget(ColumnData column, String width, String height, + EventBus eventBus) { + super(); + replaceColumnByExpressionType = ReplaceColumnByExpressionType.Replace; + create(column.getTrId(), width, height, eventBus); + retrieveColumns(); + } + + public ReplaceArithmeticWidget(ColumnData column, ArrayList columns, + EventBus eventBus) { + super(); + replaceColumnByExpressionType = ReplaceColumnByExpressionType.Template; + this.columns = columns; + create(column.getTrId(), WIDTH, HEIGHT, eventBus); + setup(); + } + + public ReplaceArithmeticWidget(ColumnData column, ArrayList columns, + String width, String height, EventBus eventBus) { + super(); + replaceColumnByExpressionType = ReplaceColumnByExpressionType.Template; + this.columns = columns; + create(column.getTrId(), width, height, eventBus); + setup(); + } + + protected void create(TRId trId, String width, String height, + EventBus eventBus) { + this.trId = trId; + 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() { + itemIdComboArithmetic = "ComboArithmetic" + 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 Elemet Store + ReplaceArithmeticElementStore factory = new ReplaceArithmeticElementStore(); + + ReplaceArithmeticElementProperties props = GWT + .create(ReplaceArithmeticElementProperties.class); + Log.debug("Props: " + props); + + // Combo Leaf + ListStore storeReplaceElementsLeaf = new ListStore( + props.id()); + Log.debug("Store Leaf: " + storeReplaceElementsLeaf); + storeReplaceElementsLeaf.addAll(factory.replaceArithmeticElements); + + Log.debug("Store created"); + final ComboBox comboReplaceElementsLeaf = new ComboBox( + storeReplaceElementsLeaf, props.label()); + + Log.debug("Combo created"); + + comboReplaceElementsLeaf + .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 Concat: + 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(); + + } + } + + }); + + comboReplaceElementsLeaf.setEmptyText("Select..."); + comboReplaceElementsLeaf.setItemId(itemIdComboLeaf); + comboReplaceElementsLeaf.setWidth(COMBO_WIDTH); + comboReplaceElementsLeaf.setEditable(false); + + comboReplaceElementsLeaf.setTriggerAction(TriggerAction.ALL); + + // ComboConcat + ListStore storeReplaceElementsConcat = new ListStore( + props.id()); + Log.debug("Store Concat: " + storeReplaceElementsConcat); + storeReplaceElementsConcat.addAll(factory.replaceElementsConcat); + + Log.debug("Store created"); + final ComboBox comboReplaceElementsConcat = new ComboBox( + storeReplaceElementsConcat, props.label()); + + Log.debug("Combo created"); + + comboReplaceElementsConcat + .addSelectionHandler(new SelectionHandler() { + + public void onSelection(SelectionEvent event) { + if (event.getSelectedItem() != null) { + @SuppressWarnings("unchecked") + ComboBox source = (ComboBox) event + .getSource(); + ReplaceElement re = event.getSelectedItem(); + Log.debug("Condition selected:" + re.toString()); + switch (re.getReplaceType()) { + case Value: + comboReplaceElementsLeaf.setVisible(false); + comboColumns.clear(); + comboColumns.setVisible(false); + firstArg.setEmptyText(EMPTY_TEXT_INSERT_A_STRING); + firstArg.setVisible(true); + secondArg.setVisible(false); + secondArg.setEmptyText(""); + removeConcat(source); + break; + case ColumnValue: + comboReplaceElementsLeaf.setVisible(false); + comboColumns.clear(); + comboColumns.setVisible(true); + firstArg.setVisible(false); + firstArg.setEmptyText(""); + secondArg.setVisible(false); + secondArg.setEmptyText(""); + break; + case Concat: + if (!existConcat(source)) { + comboReplaceElementsLeaf.clear(); + comboReplaceElementsLeaf.setVisible(true); + comboColumns.clear(); + comboColumns.setVisible(false); + firstArg.setVisible(false); + firstArg.setEmptyText(""); + secondArg.setVisible(false); + secondArg.setEmptyText(""); + addConcat(); + } + break; + case SubstringByRegex: + comboReplaceElementsLeaf.setVisible(false); + comboColumns.clear(); + comboColumns.setVisible(true); + firstArg.setVisible(true); + firstArg.setEmptyText(EMPTY_TEXT_REGEXP); + secondArg.setVisible(false); + secondArg.setEmptyText(""); + removeConcat(source); + break; + case SubstringByIndex: + comboReplaceElementsLeaf.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); + removeConcat(source); + break; + case SubstringByCharSeq: + comboReplaceElementsLeaf.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); + removeConcat(source); + break; + case TextReplaceMatchingRegex: + comboReplaceElementsLeaf.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); + removeConcat(source); + break; + default: + break; + } + vert.forceLayout(); + thisCont.forceLayout(); + + } + } + + }); + + comboReplaceElementsConcat.setEmptyText("Select..."); + comboReplaceElementsConcat.setItemId(itemIdComboConcat); + comboReplaceElementsConcat.setWidth(COMBO_WIDTH); + comboReplaceElementsConcat.setEditable(false); + comboReplaceElementsConcat.setTriggerAction(TriggerAction.ALL); + + comboReplaceElementsConcat.setValue(storeReplaceElementsConcat.get(0), + true); + + // + horiz.add(comboReplaceElementsConcat, 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))); + 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); + comboReplaceElementsLeaf.setVisible(false); + comboReplaceElementsConcat.setVisible(true); + forceLayout(); + } + + protected void addConcat() { + 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); + + // + ReplaceElementStore factory = new ReplaceElementStore(); + + ReplaceElementProperties props = GWT + .create(ReplaceElementProperties.class); + Log.debug("Props: " + props); + + // Combo Leaf + ListStore storeReplaceElementsLeaf = new ListStore( + props.id()); + Log.debug("Store Leaf: " + storeReplaceElementsLeaf); + storeReplaceElementsLeaf.addAll(factory.replaceElements); + + Log.debug("Store created"); + final ComboBox comboReplaceElementsLeaf = new ComboBox( + storeReplaceElementsLeaf, props.label()); + + Log.debug("Combo created"); + + comboReplaceElementsLeaf + .addSelectionHandler(new SelectionHandler() { + + public void onSelection(SelectionEvent event) { + if (event.getSelectedItem() != null) { + ReplaceElement re = event.getSelectedItem(); + Log.debug("Condition selected:" + re.toString()); + switch (re.getReplaceType()) { + 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 Concat: + 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(); + + } + } + + }); + + comboReplaceElementsLeaf.setEmptyText("Select..."); + comboReplaceElementsLeaf.setItemId(itemIdComboLeaf); + comboReplaceElementsLeaf.setWidth(COMBO_WIDTH); + comboReplaceElementsLeaf.setEditable(false); + + comboReplaceElementsLeaf.setTriggerAction(TriggerAction.ALL); + + // ComboConcat + ListStore storeReplaceElementsConcat = new ListStore( + props.id()); + Log.debug("Store Concat: " + storeReplaceElementsConcat); + storeReplaceElementsConcat.addAll(factory.replaceElementsConcat); + + Log.debug("Store created"); + final ComboBox comboReplaceElementsConcat = new ComboBox( + storeReplaceElementsConcat, props.label()); + + Log.debug("Combo created"); + + comboReplaceElementsConcat + .addSelectionHandler(new SelectionHandler() { + + public void onSelection(SelectionEvent event) { + + if (event.getSelectedItem() != null) { + @SuppressWarnings("unchecked") + ComboBox source = (ComboBox) event + .getSource(); + ReplaceElement re = event.getSelectedItem(); + Log.debug("Condition selected:" + re.toString()); + switch (re.getReplaceType()) { + case Value: + comboReplaceElementsLeaf.setVisible(false); + comboColumns.clear(); + comboColumns.setVisible(false); + firstArg.setEmptyText(EMPTY_TEXT_INSERT_A_STRING); + firstArg.setVisible(true); + secondArg.setVisible(false); + secondArg.setEmptyText(""); + removeConcat(source); + break; + case ColumnValue: + comboReplaceElementsLeaf.setVisible(false); + comboColumns.clear(); + comboColumns.setVisible(true); + firstArg.setVisible(false); + firstArg.setEmptyText(""); + secondArg.setVisible(false); + secondArg.setEmptyText(""); + break; + case Concat: + if (!existConcat(source)) { + comboReplaceElementsLeaf.clear(); + comboReplaceElementsLeaf.setVisible(true); + comboColumns.clear(); + comboColumns.setVisible(false); + firstArg.setVisible(false); + firstArg.setEmptyText(""); + secondArg.setVisible(false); + secondArg.setEmptyText(""); + addConcat(); + } + break; + case SubstringByRegex: + comboReplaceElementsLeaf.setVisible(false); + comboColumns.clear(); + comboColumns.setVisible(true); + firstArg.setVisible(true); + firstArg.setEmptyText(EMPTY_TEXT_REGEXP); + secondArg.setVisible(false); + secondArg.setEmptyText(""); + removeConcat(source); + break; + case SubstringByIndex: + comboReplaceElementsLeaf.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); + removeConcat(source); + break; + case SubstringByCharSeq: + comboReplaceElementsLeaf.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); + removeConcat(source); + break; + case TextReplaceMatchingRegex: + comboReplaceElementsLeaf.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); + removeConcat(source); + break; + default: + break; + } + vert.forceLayout(); + thisCont.forceLayout(); + + } + + } + + }); + + comboReplaceElementsConcat.setEmptyText("Select..."); + comboReplaceElementsConcat.setItemId(itemIdComboConcat); + comboReplaceElementsConcat.setWidth(COMBO_WIDTH); + comboReplaceElementsConcat.setEditable(false); + comboReplaceElementsConcat.setTriggerAction(TriggerAction.ALL); + + comboReplaceElementsConcat.setValue(storeReplaceElementsConcat.get(0), + true); + + // + horiz.add(comboReplaceElementsConcat, 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))); + 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); + comboReplaceElementsLeaf.setVisible(false); + comboReplaceElementsConcat.setVisible(true); + forceLayout(); + } + + private void removeConcat(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 existConcat(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 expContainerConcat = null; + C_Expression exp = null; + C_Expression expLeaf = null; + String readableExp = ""; + String readableExpLeaf = ""; + TextField firstArg; + TextField secondArg; + HBoxLayoutContainer horiz; + ReplaceTypeMap mapReplace = new ReplaceTypeMap(); + + horiz = (HBoxLayoutContainer) vert.getWidget(index); + @SuppressWarnings("unchecked") + ComboBox comboConcat = (ComboBox) horiz + .getItemByItemId(itemIdComboConcat); + Log.debug("combo Concat: " + comboConcat.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() + "]"); + + ReplaceType comboConcatReplaceType = 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!"); + } + } else { + comboConcatReplaceType = comboConcat.getCurrentValue() + .getReplaceType(); + if (comboConcatReplaceType.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(); + + } else { + comboLeafReplaceType = comboLeaf.getCurrentValue() + .getReplaceType(); + switch (replaceColumnByExpressionType) { + case Replace: + expLeaf = mapReplace.map( + column, + comboLeafReplaceType, + firstArg == null ? null : firstArg + .getCurrentValue(), + secondArg == null ? null : secondArg + .getCurrentValue(), false); + break; + case Template: + expLeaf = mapReplace.map( + column, + comboLeafReplaceType, + firstArg == null ? null : firstArg + .getCurrentValue(), + secondArg == null ? null : secondArg + .getCurrentValue(), true); + break; + default: + expLeaf = mapReplace.map( + column, + comboLeafReplaceType, + firstArg == null ? null : firstArg + .getCurrentValue(), + secondArg == null ? null : secondArg + .getCurrentValue(), false); + break; + + } + + readableExpLeaf = mapReplace.getReadableExpression(); + } + + index++; + if (index < vert.getWidgetCount()) { + expContainerConcat = calcCExpression(index); + if (expContainerConcat == null) { + return null; + } else { + switch (replaceColumnByExpressionType) { + case Replace: + exp = mapReplace.map( + column, + comboConcatReplaceType, + firstArg == null ? null : firstArg + .getCurrentValue(), + secondArg == null ? null : secondArg + .getCurrentValue(), false, expLeaf, + expContainerConcat.getExpression(), + readableExpLeaf, expContainerConcat + .getReadableExpression()); + break; + case Template: + exp = mapReplace.map( + column, + comboConcatReplaceType, + firstArg == null ? null : firstArg + .getCurrentValue(), + secondArg == null ? null : secondArg + .getCurrentValue(), true, expLeaf, + expContainerConcat.getExpression(), + readableExpLeaf, expContainerConcat + .getReadableExpression()); + break; + default: + exp = mapReplace.map( + column, + comboConcatReplaceType, + firstArg == null ? null : firstArg + .getCurrentValue(), + secondArg == null ? null : secondArg + .getCurrentValue(), false, expLeaf, + expContainerConcat.getExpression(), + readableExpLeaf, expContainerConcat + .getReadableExpression()); + break; + + } + readableExp = mapReplace.getReadableExpression(); + expressionContainer = new ExpressionContainer(exp, + readableExp); + } + } else { + return null; + } + + } 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); + + } + } + return expressionContainer; + + } +} 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 602d72b..57c876b 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 @@ -5,7 +5,7 @@ import java.util.Date; import org.gcube.portlets.user.td.expressionwidget.client.resources.ExpressionResources; import org.gcube.portlets.user.td.expressionwidget.client.type.ReplaceColumnByExpressionType; -import org.gcube.portlets.user.td.expressionwidget.shared.exception.OperatorTypeMapException; +import org.gcube.portlets.user.td.expressionwidget.shared.exception.ConditionTypeMapException; import org.gcube.portlets.user.td.expressionwidget.shared.exception.ReplaceTypeMapException; import org.gcube.portlets.user.td.expressionwidget.shared.model.leaf.TD_Value; import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; @@ -328,7 +328,7 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel { try { cConditionExpression = conditionWidget.getExpression(); - } catch (OperatorTypeMapException e) { + } catch (ConditionTypeMapException e) { Log.debug(e.getLocalizedMessage()); UtilsGXT3.alert("Attention", e.getLocalizedMessage()); return; 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 new file mode 100644 index 0000000..4bf61b0 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/properties/ReplaceArithmeticElement.java @@ -0,0 +1,57 @@ +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 new file mode 100644 index 0000000..5c32208 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/properties/ReplaceArithmeticElementProperties.java @@ -0,0 +1,21 @@ +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 new file mode 100644 index 0000000..488c867 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/properties/ReplaceArithmeticElementStore.java @@ -0,0 +1,48 @@ +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/shared/model/OperatorTypeMap.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/condition/ConditionTypeMap.java similarity index 96% rename from src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/model/OperatorTypeMap.java rename to src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/condition/ConditionTypeMap.java index b1c70d3..59697b2 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/model/OperatorTypeMap.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/condition/ConditionTypeMap.java @@ -1,9 +1,10 @@ -package org.gcube.portlets.user.td.expressionwidget.shared.model; +package org.gcube.portlets.user.td.expressionwidget.shared.condition; import java.util.ArrayList; import java.util.List; -import org.gcube.portlets.user.td.expressionwidget.shared.exception.OperatorTypeMapException; +import org.gcube.portlets.user.td.expressionwidget.shared.exception.ConditionTypeMapException; +import org.gcube.portlets.user.td.expressionwidget.shared.model.C_OperatorType; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.comparable.C_Equals; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.comparable.C_GreaterOrEquals; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.comparable.C_GreaterThan; @@ -36,22 +37,22 @@ import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnTypeM import com.allen_sauer.gwt.log.client.Log; /** - * OperatorTypeMap creates a C_Expression usable client-side + * ConditionTypeMap creates a C_Expression usable client-side * * @author "Giancarlo Panichi" g.panichi@isti.cnr.it * */ -public class OperatorTypeMap { +public class ConditionTypeMap { private String readableExpression; - public OperatorTypeMap() { + public ConditionTypeMap() { } public C_Expression map(ColumnData column, C_OperatorType operatorType, - String firstArg, String secondArg) throws OperatorTypeMapException { - Log.debug("OperatorTypeMap Map"); + String firstArg, String secondArg) throws ConditionTypeMapException { + Log.debug("ConditionTypeMap Map"); C_Expression exp = null; readableExpression = new String(); if (column.getTrId() == null) { @@ -65,8 +66,8 @@ public class OperatorTypeMap { public C_Expression mapPlaceHolder(ColumnData column, C_OperatorType operatorType, String firstArg, String secondArg) - throws OperatorTypeMapException { - Log.debug("OperatorTypeMap Map Place Holder"); + throws ConditionTypeMapException { + Log.debug("ConditionTypeMap Map Place Holder"); C_Expression exp = null; Log.debug("Column Data Type Name:" + column.getDataTypeName()); ColumnDataType dataType = ColumnTypeMap.getColumnDataType(column @@ -336,8 +337,8 @@ public class OperatorTypeMap { public C_Expression mapTypedColumnReference(ColumnData column, C_OperatorType operatorType, String firstArg, String secondArg) - throws OperatorTypeMapException { - Log.debug("OperatorTypeMap Map Typed Column Reference"); + throws ConditionTypeMapException { + Log.debug("ConditionTypeMap Map Typed Column Reference"); C_Expression exp = null; Log.debug("Column Data Type Name:" + column.getDataTypeName()); @@ -626,7 +627,7 @@ public class OperatorTypeMap { } protected void checkTypeArgument(ColumnData column, String arg) - throws OperatorTypeMapException { + throws ConditionTypeMapException { if (column.getDataTypeName().compareTo(ColumnDataType.Text.toString()) == 0) { if (arg == null) { arg = ""; @@ -635,7 +636,7 @@ public class OperatorTypeMap { if (column.getDataTypeName().compareTo( ColumnDataType.Boolean.toString()) == 0) { if(arg==null){ - throw new OperatorTypeMapException( + throw new ConditionTypeMapException( "Insert a valid Boolean(ex: true, false)!"); } } else { @@ -650,27 +651,27 @@ public class OperatorTypeMap { if (column.getDataTypeName().compareTo( ColumnDataType.Integer.toString()) == 0) { if(arg==null){ - throw new OperatorTypeMapException( + throw new ConditionTypeMapException( "Insert a valid Integer(ex: -1, 0, 1, 2)!"); } try { Integer.parseInt(arg); } catch (NumberFormatException e) { - throw new OperatorTypeMapException(arg + throw new ConditionTypeMapException(arg + " is not valid Integer(ex: -1, 0, 1, 2)!"); } } else { if (column.getDataTypeName().compareTo( ColumnDataType.Numeric.toString()) == 0) { if(arg==null){ - throw new OperatorTypeMapException( + throw new ConditionTypeMapException( "Insert a valid Numeric(ex: -1.2, 0, 1, 2.4)!"); } try { Float.parseFloat(arg); } catch (NumberFormatException e) { - throw new OperatorTypeMapException(arg + throw new ConditionTypeMapException(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/exception/OperatorTypeMapException.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/exception/ConditionTypeMapException.java similarity index 63% rename from src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/exception/OperatorTypeMapException.java rename to src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/exception/ConditionTypeMapException.java index 463d50e..0696a9a 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/exception/OperatorTypeMapException.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/exception/ConditionTypeMapException.java @@ -6,26 +6,26 @@ package org.gcube.portlets.user.td.expressionwidget.shared.exception; * email: g.panichi@isti.cnr.it * */ -public class OperatorTypeMapException extends Exception { +public class ConditionTypeMapException extends Exception { private static final long serialVersionUID = -9066034060104406559L; /** * */ - public OperatorTypeMapException() { + public ConditionTypeMapException() { super(); } /** * @param message */ - public OperatorTypeMapException(String message) { + public ConditionTypeMapException(String message) { super(message); } - public OperatorTypeMapException(String message,Throwable t) { + public ConditionTypeMapException(String message,Throwable t) { super(message,t); } 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 b9cd0ec..487ba75 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 @@ -18,7 +18,7 @@ public class C_ArithmeticExpression extends C_Expression { private String id="ArithmeticExpression"; - protected static final ArrayList ACCEPTED_DATA_TYPES=new ArrayList(); + public static final ArrayList acceptedDataTypes=new ArrayList(); protected C_Expression leftArgument; protected C_Expression rightArgument; @@ -34,10 +34,10 @@ public class C_ArithmeticExpression extends C_Expression { static { - ACCEPTED_DATA_TYPES.add(ColumnDataType.Numeric); - ACCEPTED_DATA_TYPES.add(ColumnDataType.Integer); - ACCEPTED_DATA_TYPES.add(ColumnDataType.Date); - ACCEPTED_DATA_TYPES.add(ColumnDataType.Geometry); + acceptedDataTypes.add(ColumnDataType.Numeric); + acceptedDataTypes.add(ColumnDataType.Integer); + acceptedDataTypes.add(ColumnDataType.Date); + acceptedDataTypes.add(ColumnDataType.Geometry); } @@ -46,11 +46,11 @@ public class C_ArithmeticExpression extends C_Expression { } public ArrayList allowedLeftDataTypes() { - return ACCEPTED_DATA_TYPES; + return acceptedDataTypes; } public ArrayList allowedRightDataTypes() { - return ACCEPTED_DATA_TYPES; + return acceptedDataTypes; } 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 new file mode 100644 index 0000000..32fe618 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/replace/ReplaceArithmeticType.java @@ -0,0 +1,36 @@ +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("Substring by Index"), + Modulus("Substring by Char Seq."), + Multiplication("Replace Matching Regex"), + Division("Replace Matching Regex"); + + /** + * @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 new file mode 100644 index 0000000..a3d4d6a --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/replace/ReplaceArithmeticTypeMap.java @@ -0,0 +1,536 @@ +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 org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnTypeMap; + +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 = ColumnTypeMap.getColumnDataType(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 = ColumnTypeMap.getColumnDataType(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 495ec0c..e6398c6 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 @@ -1,5 +1,11 @@ package org.gcube.portlets.user.td.expressionwidget.shared.replace; +/** + * + * @author giancarlo + * email: g.panichi@isti.cnr.it + * + */ public enum ReplaceType { Null("Null"), Value("Value"), 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 3e84058..8601024 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 @@ -18,7 +18,7 @@ import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnTypeM import com.allen_sauer.gwt.log.client.Log; /** - * OperatorTypeMap creates a C_Expression usable client-side + * ReplaceTypeMap creates a C_Expression usable client-side * * @author "Giancarlo Panichi" g.panichi@isti.cnr.it @@ -55,7 +55,7 @@ public class ReplaceTypeMap { public C_Expression mapPlaceHolder(ColumnData column, ReplaceType replaceType, String firstArg, String secondArg, C_Expression firstE, C_Expression secondE,String readableFirstE, String readableSecondE) throws ReplaceTypeMapException { - Log.debug("OperatorTypeMap Map Place Holder"); + Log.debug("ReplaceTypeMap Map Place Holder"); C_Expression exp = null; if(column==null){ @@ -166,7 +166,7 @@ public class ReplaceTypeMap { public C_Expression mapColumnReference(ColumnData column, ReplaceType replaceType, String firstArg, String secondArg, C_Expression firstE, C_Expression secondE, String readableFirstE, String readableSecondE) throws ReplaceTypeMapException { - Log.debug("OperatorTypeMap Map Typed Column Reference"); + Log.debug("ReplaceTypeMap Map Typed Column Reference"); C_Expression exp = null; if(column==null){