private ConditionCol52 makeNewColumn(ConditionCol c) { ConditionCol52 nc = new ConditionCol52(); nc.setConstraintValueType( c.constraintValueType ); nc.setDefaultValue( new DTCellValue52( c.defaultValue ) ); nc.setFactField( c.factField ); nc.setFieldType( SuggestionCompletionEngine.TYPE_STRING ); nc.setHeader( c.header ); nc.setHideColumn( c.hideColumn ); nc.setOperator( c.operator ); nc.setValueList( c.valueList ); nc.setWidth( c.width ); return nc; }
private FieldConstraint makeSingleFieldConstraint(ConditionCol52 c, String cell) { SingleFieldConstraint sfc = new SingleFieldConstraint( c.getFactField() ); if ( no( c.getOperator() ) ) { sfc.setOperator( c.getOperator() ); if ( SuggestionCompletionEngine.operatorRequiresList( c.getOperator() ) ) { sfc.setValue( makeInList( cell ) ); } else { if ( !c.getOperator().equals( "== null" ) && !c.getOperator().equals( "!= null" ) ) { sfc.setValue( cell ); if ( c.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_LITERAL && c.isBound() ) { sfc.setFieldBinding( c.getBinding() ); sfc.setParameters( c.getParameters() ); sfc.setConstraintValueType( c.getConstraintValueType() ); sfc.setFieldType( c.getFieldType() ); return sfc;
public ConditionColumnDetails(final ConditionCol52 column) { super( column ); this.factField = column.getFactField(); this.operator = column.getOperator(); }
public BRLConditionVariableColumn(String varName, String fieldType, String factType, String factField) { this.varName = varName; this.factType = factType; super.setFactField( factField ); super.setFieldType( fieldType ); }
dt.getConditions().add( p1 ); ConditionCol52 cc1 = new ConditionCol52(); cc1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); cc1.setFieldType( SuggestionCompletionEngine.TYPE_STRING ); cc1.setFactField( "name" ); cc1.setOperator( "!= null" ); p1.getChildColumns().add( cc1 ); ConditionCol52 cc2 = new ConditionCol52(); cc2.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); cc2.setFieldType( SuggestionCompletionEngine.TYPE_NUMERIC_INTEGER ); cc2.setFactField( "age" ); cc2.setOperator( "!= null" ); p1.getChildColumns().add( cc2 ); ConditionCol52 cc3 = new ConditionCol52(); cc3.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); cc3.setFieldType( SuggestionCompletionEngine.TYPE_DATE ); cc3.setFactField( "dateOfBirth" ); cc3.setOperator( "!= null" ); p1.getChildColumns().add( cc3 );
if ( c.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_LITERAL ) { if ( c.getFactField() == null || c.getFactField().equals( "" ) ) { return false; if ( c.getOperator() == null || c.getOperator().equals( "" ) ) { return false;
ConditionCol52 c1 = new ConditionCol52(); Pattern52 p1 = new Pattern52(); p1.setBoundName( "c1" ); p1.setFactType( "Driver" ); c1.setFactField( "name" ); c1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); p1.getChildColumns().add( c1 ); dt.getConditions().add( p1 ); ConditionCol52 c1_ = new ConditionCol52(); Pattern52 p1_ = new Pattern52(); p1_.setBoundName( "c1" ); p1_.setFactType( "Driver" ); c1_.setFactField( "name" ); p1_.getChildColumns().add( c1_ ); c1_.setConstraintValueType( BaseSingleFieldConstraint.TYPE_RET_VALUE ); dt.getConditions().add( p1_ ); ConditionCol52 c1__ = new ConditionCol52(); c1__.setFactField( "sex" ); p1_.getChildColumns().add( c1__ ); c1__.setConstraintValueType( BaseSingleFieldConstraint.TYPE_RET_VALUE ); c1__.setValueList( "Male,Female" ); dt.getConditions().add( p1_ ); ConditionCol52 c1___ = new ConditionCol52(); Pattern52 p1__ = new Pattern52(); p1__.setBoundName( "c1" ); p1__.setFactType( "Driver" );
tsdt.getConditionPattern( "z1" ).getChildColumns().get( 0 ).getConstraintValueType() ); assertEquals( "age", tsdt.getConditionPattern( "z1" ).getChildColumns().get( 0 ).getFactField() ); assertEquals( "Driver", tsdt.getPattern( tsdt.getConditionPattern( "z1" ).getChildColumns().get( 0 ) ).getFactType() ); assertEquals( "Driver z1 age", tsdt.getConditionPattern( "z1" ).getChildColumns().get( 0 ).getHeader() ); assertEquals( "==", tsdt.getConditionPattern( "z1" ).getChildColumns().get( 0 ).getOperator() ); tsdt.getConditionPattern( "z1" ).getChildColumns().get( 1 ).getConstraintValueType() ); assertEquals( "rating", tsdt.getConditionPattern( "z1" ).getChildColumns().get( 1 ).getFactField() ); assertEquals( "Driver", tsdt.getPattern( tsdt.getConditionPattern( "z1" ).getChildColumns().get( 1 ) ).getFactType() ); assertEquals( "Driver rating", tsdt.getConditionPattern( "z1" ).getChildColumns().get( 1 ).getHeader() ); assertEquals( "==", tsdt.getConditionPattern( "z1" ).getChildColumns().get( 1 ).getOperator() ); tsdt.getConditionPattern( "f1" ).getChildColumns().get( 0 ).getConstraintValueType() ); assertEquals( "name", tsdt.getConditionPattern( "f1" ).getChildColumns().get( 0 ).getFactField() ); assertEquals( "Person", tsdt.getPattern( tsdt.getConditionPattern( "f1" ).getChildColumns().get( 0 ) ).getFactType() ); assertEquals( "Person f1 name", tsdt.getConditionPattern( "f1" ).getChildColumns().get( 0 ).getHeader() ); assertEquals( "==", tsdt.getConditionPattern( "f1" ).getChildColumns().get( 0 ).getOperator() );
GuidedDecisionTable52 dt = new GuidedDecisionTable52(); ConditionCol52 c1 = new ConditionCol52(); Pattern52 p1 = new Pattern52(); p1.setBoundName( "c1" ); p1.setFactType( "Driver" ); c1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_RET_VALUE ); c1.setFieldType( SuggestionCompletionEngine.TYPE_STRING ); c1.setValueList( "getAge()>10,getAge()>20,getAge()>30" ); p1.getChildColumns().add( c1 ); dt.getConditions().add( p1 );
@Override FieldConstraint constructSingleFieldConstraint(ConditionCol52 c, List<DTCellValue52> columnData) { SingleFieldConstraint sfc = new SingleFieldConstraint( c.getFactField() ); sfc.setConstraintValueType( c.getConstraintValueType() ); sfc.setFieldType( c.getFieldType() ); sfc.setOperator( "not in" ); List<String> consumedValues = new ArrayList<String>(); StringBuilder value = new StringBuilder(); value.append( "( " ); for ( DTCellValue52 cv : columnData ) { //Ensure cell values start and end with quotes String scv = GuidedDTDRLUtilities.convertDTCellValueToString( cv ); if ( scv != null ) { if ( !consumedValues.contains( scv ) ) { value.append( scv ).append( ", " ); } consumedValues.add( scv ); } } value.delete( value.lastIndexOf( "," ), value.length() - 1 ); value.append( ")" ); sfc.setValue( value.toString() ); return sfc; }
@Test public void testNoConstraintLists() { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); // add cols for LHS ConditionCol52 c1 = new ConditionCol52(); Pattern52 p1 = new Pattern52(); p1.setBoundName( "c1" ); p1.setFactType( "Driver" ); c1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); p1.getChildColumns().add( c1 ); dt.getConditions().add( p1 ); ConditionCol52 c2 = new ConditionCol52(); Pattern52 p2 = new Pattern52(); p2.setBoundName( "c2" ); p2.setFactType( "Driver" ); c2.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); c2.setValueList( "a,b,c" ); p2.getChildColumns().add( c2 ); dt.getConditions().add( p1 ); SuggestionCompletionEngine sce = new SuggestionCompletionEngine(); sce.putDataEnumList( "Driver.name", new String[]{"bob", "michael"} ); assertEquals( 0, dt.getValueList( c1 ).length ); assertEquals( 3, dt.getValueList( c2 ).length ); }
@Test public void testNoConstraints() { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); Pattern52 p1 = new Pattern52(); p1.setBoundName( "x" ); p1.setFactType( "Context" ); ConditionCol52 c = new ConditionCol52(); c.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); p1.getChildColumns().add( c ); dt.getConditions().add( p1 ); ActionSetFieldCol52 asf = new ActionSetFieldCol52(); asf.setBoundName( "x" ); asf.setFactField( "age" ); asf.setType( SuggestionCompletionEngine.TYPE_STRING ); dt.getActionCols().add( asf ); String[][] data = new String[][]{ new String[]{"1", "desc", "y", "old"} }; dt.setData( upgrader.makeDataLists( data ) ); String drl = GuidedDTDRLPersistence.getInstance().marshal( dt ); assertTrue( drl.indexOf( "Context( )" ) > -1 ); assertTrue( drl.indexOf( "x.setAge" ) > drl.indexOf( "Context( )" ) ); assertFalse( drl.indexOf( "update( x );" ) > -1 ); dt.setData( upgrader.makeDataLists( new String[][]{ new String[]{"1", "desc", "", "old"} } ) ); drl = GuidedDTDRLPersistence.getInstance().marshal( dt ); assertEquals( -1, drl.indexOf( "Context( )" ) ); }
@Override public void setHeader(String header) { super.setHeader( header ); for ( BRLConditionVariableColumn variable : this.childColumns ) { variable.setHeader( header ); } }
public BRLConditionVariableColumn(String varName, String fieldType) { this.varName = varName; super.setFieldType( fieldType ); }
@Override public String getFieldName() { return condition.getFactField(); }
/** * Retrieve the correct OtherwiseBuilder for the given column * * @param c * @return */ public static OtherwiseBuilder getBuilder(ConditionCol52 c) { if ( c.getOperator().equals( "==" ) ) { return new EqualsOtherwiseBuilder(); } else if ( c.getOperator().equals( "!=" ) ) { return new NotEqualsOtherwiseBuilder(); } throw new IllegalArgumentException( "ConditionCol operator does not support Otherwise values" ); }
ConditionCol52 c = new ConditionCol52(); p.getChildColumns().add( c ); dt.getConditions().add( p );
dt.getConditions().add( p1 ); ConditionCol52 cc1 = new ConditionCol52(); cc1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); cc1.setFieldType( SuggestionCompletionEngine.TYPE_STRING ); cc1.setFactField( "name" ); cc1.setOperator( "== null" ); p1.getChildColumns().add( cc1 ); ConditionCol52 cc2 = new ConditionCol52(); cc2.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); cc2.setFieldType( SuggestionCompletionEngine.TYPE_NUMERIC_INTEGER ); cc2.setFactField( "age" ); cc2.setOperator( "== null" ); p1.getChildColumns().add( cc2 ); ConditionCol52 cc3 = new ConditionCol52(); cc3.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); cc3.setFieldType( SuggestionCompletionEngine.TYPE_DATE ); cc3.setFactField( "dateOfBirth" ); cc3.setOperator( "== null" ); p1.getChildColumns().add( cc3 );
if ( c.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_LITERAL ) { if ( c.getFactField() == null || c.getFactField().equals( "" ) ) { return false; if ( c.getOperator() == null || c.getOperator().equals( "" ) ) { return false;
tsdt.getConditionPattern( "f1" ).getChildColumns().get( 0 ).getConstraintValueType() ); assertEquals( "age", tsdt.getConditionPattern( "f1" ).getChildColumns().get( 0 ).getFactField() ); assertEquals( "Driver", tsdt.getPattern( tsdt.getConditionPattern( "f1" ).getChildColumns().get( 0 ) ).getFactType() ); assertEquals( "Driver f1 age", tsdt.getConditionPattern( "f1" ).getChildColumns().get( 0 ).getHeader() ); assertEquals( "==", tsdt.getConditionPattern( "f1" ).getChildColumns().get( 0 ).getOperator() ); tsdt.getConditionPattern( "f1" ).getChildColumns().get( 1 ).getConstraintValueType() ); assertEquals( "rating", tsdt.getConditionPattern( "f1" ).getChildColumns().get( 1 ).getFactField() ); assertEquals( "Driver", tsdt.getPattern( tsdt.getConditionPattern( "f1" ).getChildColumns().get( 1 ) ).getFactType() ); assertEquals( "Driver rating", tsdt.getConditionPattern( "f1" ).getChildColumns().get( 1 ).getHeader() ); assertEquals( "==", tsdt.getConditionPattern( "f1" ).getChildColumns().get( 1 ).getOperator() ); tsdt.getConditionPattern( "f2" ).getChildColumns().get( 0 ).getConstraintValueType() ); assertEquals( "name", tsdt.getConditionPattern( "f2" ).getChildColumns().get( 0 ).getFactField() ); assertEquals( "Person", tsdt.getPattern( tsdt.getConditionPattern( "f2" ).getChildColumns().get( 0 ) ).getFactType() ); assertEquals( "Person f2 name", tsdt.getConditionPattern( "f2" ).getChildColumns().get( 0 ).getHeader() ); assertEquals( "==", tsdt.getConditionPattern( "f2" ).getChildColumns().get( 0 ).getOperator() );