/** * Similar to the one above - but this one is for RHS. */ public DropDownData getEnums(String type, String field, FieldNature[] currentFieldNatures) { Map<String, String> currentValueMap = new HashMap<String, String>(); if ( currentFieldNatures != null ) { for ( FieldNature currentFieldNature : currentFieldNatures ) { currentValueMap.put( currentFieldNature.getField(), currentFieldNature.getValue() ); } } return getEnums( type, field, currentValueMap ); }
/** * Similar to the one above - but this one is for RHS. */ public DropDownData getEnums(String type, String field, FieldNature[] currentFieldNatures) { Map<String, String> currentValueMap = new HashMap<String, String>(); if ( currentFieldNatures != null ) { for ( FieldNature currentFieldNature : currentFieldNatures ) { currentValueMap.put( currentFieldNature.getField(), currentFieldNature.getValue() ); } } return getEnums( type, field, currentValueMap ); }
/** * This returns a list of enums options (values) that can be used for the * given field of the given FactPattern. This also takes into account enums * that depend on other fields. */ public DropDownData getEnums(String factType, CompositeFieldConstraint constraintList, String field) { if ( field == null ) { return null; } Map<String, String> currentValueMap = new HashMap<String, String>(); if ( constraintList != null && constraintList.constraints != null ) { for ( FieldConstraint con : constraintList.constraints ) { if ( con instanceof SingleFieldConstraint ) { SingleFieldConstraint sfc = (SingleFieldConstraint) con; String fieldName = sfc.getFieldName(); currentValueMap.put( fieldName, sfc.getValue() ); } } } return getEnums( factType, field, currentValueMap ); }
/** * This returns a list of enums options (values) that can be used for the * given field of the given FactPattern. This also takes into account enums * that depend on other fields. */ public DropDownData getEnums(String factType, CompositeFieldConstraint constraintList, String field) { if ( field == null ) { return null; } Map<String, String> currentValueMap = new HashMap<String, String>(); if ( constraintList != null && constraintList.constraints != null ) { for ( FieldConstraint con : constraintList.constraints ) { if ( con instanceof SingleFieldConstraint ) { SingleFieldConstraint sfc = (SingleFieldConstraint) con; String fieldName = sfc.getFieldName(); currentValueMap.put( fieldName, sfc.getValue() ); } } } return getEnums( factType, field, currentValueMap ); }
@Test public void testDataEnums3() { String pkg = "package org.test\n import org.drools.ide.common.client.modeldriven.SuggestionCompletionEngineTest.NestedClass"; SuggestionCompletionLoader loader = new SuggestionCompletionLoader(); List<String> enums = new ArrayList<String>(); enums.add( "'Fact.f1' : ['a1', 'a2'] \n 'Fact.f2' : ['def1', 'def2', 'def3'] \n 'Fact.f2[f1=a2]' : ['c1', 'c2']" ); SuggestionCompletionEngine engine = loader.getSuggestionEngine( pkg, new ArrayList<JarInputStream>(), new ArrayList<DSLTokenizedMappingFile>(), enums ); assertEquals( "String", engine.getFieldType( "NestedClass", "name" ) ); FactPattern pat = new FactPattern( "Fact" ); SingleFieldConstraint f1 = new SingleFieldConstraint( "f1" ); f1.setValue( "a1" ); pat.addConstraint( f1 ); pat.addConstraint( new SingleFieldConstraint( "f2" ) ); DropDownData data = engine.getEnums( pat.getFactType(), pat.constraintList, "f2" ); assertNotNull( data ); assertEquals( 3, data.fixedList.length ); }
sfc.setValue( "sex" ); pat.addConstraint( sfc ); String[] result = sce.getEnums( pat.getFactType(), pat.constraintList, "value" ).fixedList; pat.addConstraint( sfc ); result = sce.getEnums( pat.getFactType(), pat.constraintList, "value" ).fixedList; result[2] ); result = sce.getEnums( pat.getFactType(), pat.constraintList, "type" ).fixedList; null, "blah" ); result = sce.getEnums( "Fact", "value", vals assertNull( sce.getEnums( "Nothing", "value", vals
pat.addConstraint( sfc2 ); String[] result = sce.getEnums( pat.getFactType(), pat.constraintList, "field3" ).fixedList;
c1.getFactField() ) ); assertFalse( dt.hasValueList( c1 ) ); String[] r = sce.getEnums( p1.getFactType(), c1.getFactField(), currentValueMap ).fixedList; c1_.getFactField() ) ); assertFalse( dt.hasValueList( c1_ ) ); r = sce.getEnums( p1_.getFactType(), c1_.getFactField(), currentValueMap ).fixedList; asf.getFactField() ) ); assertFalse( dt.hasValueList( asf ) ); r = sce.getEnums( p1.getFactType(), asf.getFactField(), currentValueMap ).fixedList; ins.getFactField() ) ); assertFalse( dt.hasValueList( ins ) ); r = sce.getEnums( ins.getFactType(), ins.getFactField(), currentValueMap ).fixedList;