public String getFieldType(String propertyName) { String[] split = propertyName.split( "\\.", 3 ); if ( split.length != 2 ) { throw new IllegalArgumentException( "Invalid format '" + propertyName + "'. It must be of type className.propertyName" ); } return this.getFieldType( split[0], split[1] ); }
public String getFieldType(String propertyName) { String[] split = propertyName.split( "\\.", 3 ); if ( split.length != 2 ) { throw new IllegalArgumentException( "Invalid format '" + propertyName + "'. It must be of type className.propertyName" ); } return this.getFieldType( split[0], split[1] ); }
public String getType(DTColumnConfig col, SuggestionCompletionEngine sce) { String type = null; if (col instanceof AttributeCol) { AttributeCol at = (AttributeCol) col; type = at.attr; } else if (col instanceof ConditionCol) { ConditionCol c = (ConditionCol) col; type = sce.getFieldType(c.factType, c.factField); } else if (col instanceof ActionSetFieldCol) { ActionSetFieldCol c = (ActionSetFieldCol) col; type = sce.getFieldType(getBoundFactType(c.boundName), c.factField); } else if (col instanceof ActionInsertFactCol) { ActionInsertFactCol c = (ActionInsertFactCol) col; type = sce.getFieldType(c.factType, c.factField); } return type; }
public String getType(DTColumnConfig col, SuggestionCompletionEngine sce) { String type = null; if (col instanceof AttributeCol) { AttributeCol at = (AttributeCol) col; type = at.attr; } else if (col instanceof ConditionCol) { ConditionCol c = (ConditionCol) col; type = sce.getFieldType(c.factType, c.factField); } else if (col instanceof ActionSetFieldCol) { ActionSetFieldCol c = (ActionSetFieldCol) col; type = sce.getFieldType(getBoundFactType(c.boundName), c.factField); } else if (col instanceof ActionInsertFactCol) { ActionInsertFactCol c = (ActionInsertFactCol) col; type = sce.getFieldType(c.factType, c.factField); } return type; }
private String getTypeFromSCE(String factType, String fieldName, SuggestionCompletionEngine sce) { // Columns with enumerations are always Text (for now) if ( sce.hasEnums( factType, fieldName ) ) { return SuggestionCompletionEngine.TYPE_STRING; } //Otherwise lookup from SuggestionCompletionEngine String type = sce.getFieldType( factType, fieldName ); return type; }
private String getTypeFromSCE(String factType, String fieldName, SuggestionCompletionEngine sce) { // Columns with enumerations are always Text (for now) if ( sce.hasEnums( factType, fieldName ) ) { return SuggestionCompletionEngine.TYPE_STRING; } //Otherwise lookup from SuggestionCompletionEngine String type = sce.getFieldType( factType, fieldName ); return type; }
public static ExpressionPart getExpressionPartForField(SuggestionCompletionEngine sce, String factName, String fieldName) { String fieldClassName = sce.getFieldClassName(factName, fieldName); String fieldGenericType = sce.getFieldType(factName, fieldName); if (SuggestionCompletionEngine.TYPE_COLLECTION.equals(fieldGenericType)) { String fieldParametricType = sce.getParametricFieldType(factName, fieldName); return new ExpressionCollection(fieldName, fieldClassName, fieldGenericType, fieldParametricType); } return new ExpressionField(fieldName, fieldClassName, fieldGenericType); }
public static ExpressionPart getExpressionPartForField(SuggestionCompletionEngine sce, String factName, String fieldName) { String fieldClassName = sce.getFieldClassName(factName, fieldName); String fieldGenericType = sce.getFieldType(factName, fieldName); if (SuggestionCompletionEngine.TYPE_COLLECTION.equals(fieldGenericType)) { String fieldParametricType = sce.getParametricFieldType(factName, fieldName); return new ExpressionCollection(fieldName, fieldClassName, fieldGenericType, fieldParametricType); } return new ExpressionField(fieldName, fieldClassName, fieldGenericType); }
public String[] getConnectiveOperatorCompletions(final String factType, final String fieldName) { final String fieldType = this.getFieldType( factType + "." + fieldName ); if ( fieldType == null ) { return STANDARD_CONNECTIVES; } else if ( fieldName.equals( TYPE_THIS ) ) { if ( this.isFactTypeAnEvent( factType ) ) { return joinArrays( STANDARD_CONNECTIVES, SIMPLE_CEP_CONNECTIVES, COMPLEX_CEP_CONNECTIVES ); } else { return STANDARD_CONNECTIVES; } } else if ( fieldType.equals( TYPE_STRING ) ) { return STRING_CONNECTIVES; } else if ( isNumeric( fieldType ) ) { return COMPARABLE_CONNECTIVES; } else if ( fieldType.equals( TYPE_DATE ) ) { return joinArrays( COMPARABLE_CONNECTIVES, SIMPLE_CEP_CONNECTIVES ); } else if ( fieldType.equals( TYPE_COMPARABLE ) ) { return COMPARABLE_CONNECTIVES; } else if ( fieldType.equals( TYPE_COLLECTION ) ) { return COLLECTION_CONNECTIVES; } else { return STANDARD_CONNECTIVES; } }
public String[] getConnectiveOperatorCompletions(final String factType, final String fieldName) { final String fieldType = this.getFieldType( factType + "." + fieldName ); if ( fieldType == null ) { return STANDARD_CONNECTIVES; } else if ( fieldName.equals( TYPE_THIS ) ) { if ( this.isFactTypeAnEvent( factType ) ) { return joinArrays( STANDARD_CONNECTIVES, SIMPLE_CEP_CONNECTIVES, COMPLEX_CEP_CONNECTIVES ); } else { return STANDARD_CONNECTIVES; } } else if ( fieldType.equals( TYPE_STRING ) ) { return STRING_CONNECTIVES; } else if ( isNumeric( fieldType ) ) { return COMPARABLE_CONNECTIVES; } else if ( fieldType.equals( TYPE_DATE ) ) { return joinArrays( COMPARABLE_CONNECTIVES, SIMPLE_CEP_CONNECTIVES ); } else if ( fieldType.equals( TYPE_COMPARABLE ) ) { return COMPARABLE_CONNECTIVES; } else if ( fieldType.equals( TYPE_COLLECTION ) ) { return COLLECTION_CONNECTIVES; } else { return STANDARD_CONNECTIVES; } }
public String[] getOperatorCompletions(final String factType, final String fieldName) { String fieldType = getFieldType( factType, fieldName );
@Test public void testNestedImports() { String pkg = "package org.test\n import org.drools.ide.common.client.modeldriven.SuggestionCompletionEngineTest.NestedClass"; SuggestionCompletionLoader loader = new SuggestionCompletionLoader(); SuggestionCompletionEngine engine = loader.getSuggestionEngine( pkg, new ArrayList<JarInputStream>(), new ArrayList<DSLTokenizedMappingFile>() ); assertEquals( "String", engine.getFieldType( "NestedClass", "name" ) ); }
@Test public void testStringNonNumeric() { String pkg = "package org.test\n import org.drools.ide.common.client.modeldriven.Alert"; SuggestionCompletionLoader loader = new SuggestionCompletionLoader(); SuggestionCompletionEngine engine = loader.getSuggestionEngine( pkg, new ArrayList<JarInputStream>(), new ArrayList<DSLTokenizedMappingFile>() ); assertEquals( SuggestionCompletionEngine.TYPE_STRING, engine.getFieldType( "Alert", "message" ) ); }
@Test public void testLoadDelegatedProperties() throws Exception { SuggestionCompletionLoader loader = new SuggestionCompletionLoader(); SuggestionCompletionEngine eng = loader.getSuggestionEngine( "package foo \n" + "import org.drools.ide.common.server.rules.MotherClass\n" + "import org.drools.ide.common.server.rules.DelegationClass\n" + "import org.drools.ide.common.server.rules.SubClass\n", new ArrayList(), new ArrayList() ); assertNotNull( eng ); assertEquals( SuggestionCompletionEngine.TYPE_COMPARABLE, eng.getFieldType( "MotherClass", "status" ) ); assertEquals( SuggestionCompletionEngine.TYPE_STRING, eng.getFieldType( "SubClass", "message" ) ); assertEquals( SuggestionCompletionEngine.TYPE_COMPARABLE, eng.getFieldType( "SubClass", "status" ) ); assertEquals( SuggestionCompletionEngine.TYPE_COMPARABLE, eng.getFieldType( "DelegationClass", "status" ) ); }
@Test public void testReadOnlyFieldWithAnnotationAndField() throws Exception { SuggestionCompletionLoader loader = new SuggestionCompletionLoader(); String header = ""; header += "package foo \n import org.drools.ide.common.server.rules.ReadOnlyFact\n"; header += "declare ReadOnlyFact\n"; header += "@role( event )\n"; header += "age: Integer\n"; header += "end\n"; SuggestionCompletionEngine eng = loader.getSuggestionEngine( header, new ArrayList(), new ArrayList() ); assertNotNull( eng ); assertEquals( SuggestionCompletionEngine.TYPE_STRING, eng.getFieldType( "ReadOnlyFact", "name" ) ); assertEquals( SuggestionCompletionEngine.TYPE_NUMERIC_INTEGER, eng.getFieldType( "ReadOnlyFact", "age" ) ); }
@Test public void testReadOnlyFieldWithAnnotation() throws Exception { // GUVNOR-1792 SuggestionCompletionLoader loader = new SuggestionCompletionLoader(); String header = ""; header += "package foo \n import org.drools.ide.common.server.rules.ReadOnlyFact\n"; header += "declare ReadOnlyFact\n"; header += "@role( event )\n"; header += "end\n"; SuggestionCompletionEngine eng = loader.getSuggestionEngine( header, new ArrayList(), new ArrayList() ); assertNotNull( eng ); assertEquals( SuggestionCompletionEngine.TYPE_STRING, eng.getFieldType( "ReadOnlyFact", "name" ) ); }
@Test public void testNestedEnums() { String pkg = "package org.test\n import org.drools.ide.common.client.modeldriven.SuggestionCompletionEngineTest.NestedEnum"; SuggestionCompletionLoader loader = new SuggestionCompletionLoader(); SuggestionCompletionEngine engine = loader.getSuggestionEngine( pkg, new ArrayList<JarInputStream>(), new ArrayList<DSLTokenizedMappingFile>(), new ArrayList<String>() ); assertEquals( "Comparable", engine.getFieldType( "NestedEnum", "myEnum" ) ); String[] data = engine.getDataEnumList( "NestedEnum.myEnum" ); assertNotNull( data ); assertEquals( 2, data.length ); assertEquals( "MyEnum.VALUE1=MyEnum.VALUE1", data[0] ); assertEquals( "MyEnum.VALUE2=MyEnum.VALUE2", data[1] ); }
@Test public void testNestedEnumsFieldLookup() { String pkg = "package org.test\n import org.drools.ide.common.client.modeldriven.SuggestionCompletionEngineTest.NestedEnum"; SuggestionCompletionLoader loader = new SuggestionCompletionLoader(); SuggestionCompletionEngine engine = loader.getSuggestionEngine( pkg, new ArrayList<JarInputStream>(), new ArrayList<DSLTokenizedMappingFile>(), new ArrayList<String>() ); assertEquals( "Comparable", engine.getFieldType( "NestedEnum", "myEnum" ) ); String[] data = engine.getEnumValues( "NestedEnum", "myEnum" ); assertNotNull( data ); assertEquals( 2, data.length ); assertEquals( "MyEnum.VALUE1=MyEnum.VALUE1", data[0] ); assertEquals( "MyEnum.VALUE2=MyEnum.VALUE2", data[1] ); }
@Test public void testGeneratedBeans() throws Exception { SuggestionCompletionLoader loader = new SuggestionCompletionLoader(); SuggestionCompletionEngine eng = loader.getSuggestionEngine( "package foo \n declare GenBean \n id: int \n name : String \n end \n declare GenBean2 \n list: java.util.List \n gb: GenBean \n end", new ArrayList(), new ArrayList() ); assertFalse( loader.hasErrors() ); assertNotNull( eng ); assertEquals( 2, eng.getFactTypes().length ); assertEquals( "GenBean", eng.getFactTypes()[0] ); assertEquals( "GenBean2", eng.getFactTypes()[1] ); assertEquals( SuggestionCompletionEngine.TYPE_NUMERIC_INTEGER, eng.getFieldType( "GenBean", "id" ) ); assertEquals( SuggestionCompletionEngine.TYPE_STRING, eng.getFieldType( "GenBean", "name" ) ); assertEquals( "GenBean", eng.getFieldType( "GenBean2", "gb" ) ); }
@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 ); }