public static void refreshConstraintValueEditorsDropDownData(final Map<SingleFieldConstraint, ConstraintValueEditor> constraintValueEditors, final SingleFieldConstraint modifiedConstraint) { for (Map.Entry<SingleFieldConstraint, ConstraintValueEditor> e : constraintValueEditors.entrySet()) { final SingleFieldConstraint sfc = e.getKey(); if (sfc.getConstraintValueType() == SingleFieldConstraint.TYPE_LITERAL || sfc.getConstraintValueType() == SingleFieldConstraint.TYPE_ENUM) { if (!sfc.equals(modifiedConstraint)) { e.getValue().refresh(); } } } } }
private boolean isParentFactPattern( final SingleFieldConstraint sfc ) { if ( sfc.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_TEMPLATE ) { if ( sfc.getValue().equals( this.baseVariableName ) ) { return true; } } return false; }
public static void refreshConstraintValueEditorsDropDownData(final Map<SingleFieldConstraint, ConstraintValueEditor> constraintValueEditors, final SingleFieldConstraint modifiedConstraint) { for (Map.Entry<SingleFieldConstraint, ConstraintValueEditor> e : constraintValueEditors.entrySet()) { final SingleFieldConstraint sfc = e.getKey(); if (sfc.getConstraintValueType() == SingleFieldConstraint.TYPE_LITERAL || sfc.getConstraintValueType() == SingleFieldConstraint.TYPE_ENUM) { if (!sfc.equals(modifiedConstraint)) { e.getValue().refresh(); } } } } }
private boolean isConstraintComplete(final SingleFieldConstraint constr) { if (constr.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_EXPR_BUILDER_VALUE) { return true; } else if (constr instanceof SingleFieldConstraintEBLeftSide) { return true; } else if (constr.getFieldBinding() != null) { return true; } final String operator = constr.getOperator(); final String fieldType = constr.getFieldType(); final String fieldValue = constr.getValue(); if (operator == null) { return false; } if (operator.equals("== null") || operator.equals("!= null")) { return true; } if (DataType.TYPE_STRING.equals(fieldType)) { return true; } return !(fieldValue == null || fieldValue.isEmpty()); }
protected boolean isValidFieldConstraint(final FieldConstraint constr) { if (constr instanceof SingleFieldConstraint && ((SingleFieldConstraint) constr).getConstraintValueType() == BaseSingleFieldConstraint.TYPE_TEMPLATE) { return !StringUtils.isEmpty(rowDataProvider.getTemplateKeyValue(((SingleFieldConstraint) constr).getValue())); } return true; }
private boolean areOperatorAndValueInvalid(final SingleFieldConstraint singleFieldConstraint) { if (singleFieldConstraint.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_LITERAL) { if (DataType.TYPE_STRING.equals(singleFieldConstraint.getFieldType())) { return false; } } return singleFieldConstraint.getOperator() != null && !singleFieldConstraint.getOperator().equals("== null") && !singleFieldConstraint.getOperator().equals("!= null") && singleFieldConstraint.getValue() == null && singleFieldConstraint.getExpressionValue().isEmpty(); }
private boolean areOperatorAndValueInvalid(final SingleFieldConstraint singleFieldConstraint) { if (singleFieldConstraint.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_LITERAL) { if (DataType.TYPE_STRING.equals(singleFieldConstraint.getFieldType())) { return false; } } return singleFieldConstraint.getOperator() != null && !singleFieldConstraint.getOperator().equals("== null") && !singleFieldConstraint.getOperator().equals("!= null") && singleFieldConstraint.getValue() == null && singleFieldConstraint.getExpressionValue().isEmpty(); }
private void visitSingleFieldConstraint( final SingleFieldConstraint sfc ) { if ( sfc.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_TEMPLATE ) { this.peerVariables.add( new ValueHolder( sfc.getFieldName(), sfc.getValue(), ValueHolder.Type.TEMPLATE_KEY ) ); } else { this.peerVariables.add( new ValueHolder( sfc.getFieldName(), sfc.getValue(), ValueHolder.Type.VALUE ) ); } }
@Test public void testConstraintValueEditorRefreshPredicateNotRefreshed() throws Exception { final SingleFieldConstraint constraintOne = mock(SingleFieldConstraint.class); final SingleFieldConstraint constraintTwo = mock(SingleFieldConstraint.class); final ConstraintValueEditor editorOne = mock(ConstraintValueEditor.class); final ConstraintValueEditor editorTwo = mock(ConstraintValueEditor.class); final Map<SingleFieldConstraint, ConstraintValueEditor> editors = new HashMap<>(); editors.put(constraintOne, editorOne); editors.put(constraintTwo, editorTwo); doReturn(BaseSingleFieldConstraint.TYPE_LITERAL).when(constraintOne).getConstraintValueType(); doReturn(BaseSingleFieldConstraint.TYPE_PREDICATE).when(constraintTwo).getConstraintValueType(); RefreshUtil.refreshConstraintValueEditorsDropDownData(editors, mock(SingleFieldConstraint.class)); verify(editorOne).refresh(); verify(editorTwo, never()).refresh(); }
@Test public void testConstraintValueEditorRefreshMultipleEditors() throws Exception { final SingleFieldConstraint constraintOne = mock(SingleFieldConstraint.class); final SingleFieldConstraint constraintTwo = mock(SingleFieldConstraint.class); final ConstraintValueEditor editorOne = mock(ConstraintValueEditor.class); final ConstraintValueEditor editorTwo = mock(ConstraintValueEditor.class); final Map<SingleFieldConstraint, ConstraintValueEditor> editors = new HashMap<>(); editors.put(constraintOne, editorOne); editors.put(constraintTwo, editorTwo); doReturn(BaseSingleFieldConstraint.TYPE_LITERAL).when(constraintOne).getConstraintValueType(); doReturn(BaseSingleFieldConstraint.TYPE_LITERAL).when(constraintTwo).getConstraintValueType(); RefreshUtil.refreshConstraintValueEditorsDropDownData(editors, mock(SingleFieldConstraint.class)); verify(editorOne).refresh(); verify(editorTwo).refresh(); }
@Before public void setup() { HashMap<String, String> map = new HashMap<>(); map.put(DATE_FORMAT, "dd MMM yyyy"); ApplicationPreferences.setUp(map); when(ruleModeller.getDataModelOracle()).thenReturn(oracle); when(oracle.getFieldType(anyString(), anyString())).thenReturn(DataType.TYPE_STRING); when(constraint.getConstraintValueType()).thenReturn(SingleFieldConstraint.TYPE_LITERAL); }
@Test public void testConstraintValueEditorRefreshPredicateNotRefreshed() throws Exception { final SingleFieldConstraint constraintOne = mock(SingleFieldConstraint.class); final SingleFieldConstraint constraintTwo = mock(SingleFieldConstraint.class); final ConstraintValueEditor editorOne = mock(ConstraintValueEditor.class); final ConstraintValueEditor editorTwo = mock(ConstraintValueEditor.class); final Map<SingleFieldConstraint, ConstraintValueEditor> editors = new HashMap<>(); editors.put(constraintOne, editorOne); editors.put(constraintTwo, editorTwo); doReturn(BaseSingleFieldConstraint.TYPE_LITERAL).when(constraintOne).getConstraintValueType(); doReturn(BaseSingleFieldConstraint.TYPE_PREDICATE).when(constraintTwo).getConstraintValueType(); RefreshUtil.refreshConstraintValueEditorsDropDownData(editors, mock(SingleFieldConstraint.class)); verify(editorOne).refresh(); verify(editorTwo, never()).refresh(); }
@Test public void testConstraintValueEditorRefreshMultipleEditors() throws Exception { final SingleFieldConstraint constraintOne = mock(SingleFieldConstraint.class); final SingleFieldConstraint constraintTwo = mock(SingleFieldConstraint.class); final ConstraintValueEditor editorOne = mock(ConstraintValueEditor.class); final ConstraintValueEditor editorTwo = mock(ConstraintValueEditor.class); final Map<SingleFieldConstraint, ConstraintValueEditor> editors = new HashMap<>(); editors.put(constraintOne, editorOne); editors.put(constraintTwo, editorTwo); doReturn(BaseSingleFieldConstraint.TYPE_LITERAL).when(constraintOne).getConstraintValueType(); doReturn(BaseSingleFieldConstraint.TYPE_LITERAL).when(constraintTwo).getConstraintValueType(); RefreshUtil.refreshConstraintValueEditorsDropDownData(editors, mock(SingleFieldConstraint.class)); verify(editorOne).refresh(); verify(editorTwo).refresh(); }
@Before public void setup() { HashMap<String, String> map = new HashMap<>(); map.put(DATE_FORMAT, "dd MMM yyyy"); ApplicationPreferences.setUp(map); when(ruleModeller.getDataModelOracle()).thenReturn(oracle); when(oracle.getFieldType(anyString(), anyString())).thenReturn(DataType.TYPE_STRING); when(constraint.getConstraintValueType()).thenReturn(SingleFieldConstraint.TYPE_LITERAL); }
private void visitSingleFieldConstraint(SingleFieldConstraint sfc) { InterpolationVariable var = new InterpolationVariable(sfc.getValue(), sfc.getFieldType(), (factPattern == null ? "" : factPattern.getFactType()), sfc.getFieldName(), sfc.getOperator()); if (BaseSingleFieldConstraint.TYPE_TEMPLATE == sfc.getConstraintValueType() && !vars.containsKey(var)) { vars.put(var, vars.size()); } //Visit Connection constraints if (sfc.getConnectives() != null) { for (int i = 0; i < sfc.getConnectives().length; i++) { final ConnectiveConstraint cc = sfc.getConnectives()[i]; InterpolationVariable ccVar = new InterpolationVariable(cc.getValue(), cc.getFieldType(), (factPattern == null ? "" : factPattern.getFactType()), cc.getFieldName()); if (BaseSingleFieldConstraint.TYPE_TEMPLATE == cc.getConstraintValueType() && !vars.containsKey(ccVar)) { vars.put(ccVar, vars.size()); } } } }
private void visitSingleFieldConstraint(final SingleFieldConstraint sfc) { final InterpolationVariable var = new InterpolationVariable(sfc.getValue(), sfc.getFieldType(), (factPattern == null ? "" : factPattern.getFactType()), sfc.getFieldName()); if (BaseSingleFieldConstraint.TYPE_TEMPLATE == sfc.getConstraintValueType() && !vars.contains(var)) { vars.add(var); } else { hasNonTemplateOutput = true; } //Visit Connection constraints if (sfc.getConnectives() != null) { for (int i = 0; i < sfc.getConnectives().length; i++) { final ConnectiveConstraint cc = sfc.getConnectives()[i]; InterpolationVariable ccVar = new InterpolationVariable(cc.getValue(), cc.getFieldType(), (factPattern == null ? "" : factPattern.getFactType()), cc.getFieldName()); if (BaseSingleFieldConstraint.TYPE_TEMPLATE == cc.getConstraintValueType() && !vars.contains(ccVar)) { vars.add(ccVar); } else { hasNonTemplateOutput = true; } } } }
private void generateNormalFieldRestriction(final SingleFieldConstraint constr, final Map<String, String> parameters) { if (constr instanceof SingleFieldConstraintEBLeftSide) { SingleFieldConstraintEBLeftSide sfexp = (SingleFieldConstraintEBLeftSide) constr; addFieldRestriction(buf, sfexp.getConstraintValueType(), sfexp.getExpressionLeftSide().getGenericType(), sfexp.getOperator(), parameters, sfexp.getValue(), sfexp.getExpressionValue(), true); } else { addFieldRestriction(buf, constr.getConstraintValueType(), constr.getFieldType(), constr.getOperator(), parameters, constr.getValue(), constr.getExpressionValue(), true); } }
private SingleFieldConstraint visitSingleFieldConstraint(SingleFieldConstraint sfc) { SingleFieldConstraint clone = new SingleFieldConstraint(); clone.setConstraintValueType(sfc.getConstraintValueType()); clone.setExpressionValue((ExpressionFormLine) visit(sfc.getExpressionValue())); clone.setFieldBinding(sfc.getFieldBinding()); clone.setFactType(sfc.getFactType()); clone.setFieldName(sfc.getFieldName()); clone.setFieldType(sfc.getFieldType()); clone.setId(sfc.getId()); clone.setOperator(sfc.getOperator()); clone.setParent((FieldConstraint) visit(sfc.getParent())); for (Map.Entry<String, String> entry : sfc.getParameters().entrySet()) { clone.setParameter(entry.getKey(), entry.getValue()); } clone.setValue(sfc.getValue()); if (sfc.getConnectives() != null) { clone.setConnectives(new ConnectiveConstraint[sfc.getConnectives().length]); for (int i = 0; i < sfc.getConnectives().length; i++) { clone.getConnectives()[i] = (ConnectiveConstraint) visit(sfc.getConnectives()[i]); } } return clone; }
private SingleFieldConstraint visitSingleFieldConstraint(SingleFieldConstraint sfc) { SingleFieldConstraint clone = new SingleFieldConstraint(); clone.setConstraintValueType(sfc.getConstraintValueType()); clone.setExpressionValue((ExpressionFormLine) visit(sfc.getExpressionValue())); clone.setFieldBinding(sfc.getFieldBinding()); clone.setFactType(sfc.getFactType()); clone.setFieldName(sfc.getFieldName()); clone.setFieldType(sfc.getFieldType()); clone.setId(sfc.getId()); clone.setOperator(sfc.getOperator()); clone.setParent((FieldConstraint) visit(sfc.getParent())); for (Map.Entry<String, String> entry : sfc.getParameters().entrySet()) { clone.setParameter(entry.getKey(), entry.getValue()); } clone.setValue(sfc.getValue()); if (sfc.getConnectives() != null) { clone.setConnectives(new ConnectiveConstraint[sfc.getConnectives().length]); for (int i = 0; i < sfc.getConnectives().length; i++) { clone.getConnectives()[i] = (ConnectiveConstraint) visit(sfc.getConnectives()[i]); } } return clone; }
} else { addConnectiveFieldRestriction(buf, constr.getConstraintValueType(), constr.getFieldType(), constr.getOperator(),