/** * Start the creation of a new SuggestionCompletionEngine */ public void newCompletionEngine() { this.instance = new SuggestionCompletionEngine(); this.factTypes = new HashMap<String, FIELD_CLASS_TYPE>(); this.annotationsForType = new HashMap<String, Map<String, Map<String, String>>>(); this.fieldsForType = new HashMap<String, String[]>(); this.fieldTypes = new HashMap<String, String>(); this.fieldTypesField = new HashMap<String, FieldInfo>(); this.globalTypes = new HashMap<String, String>(); this.actionDSLSentences = new ArrayList<DSLSentence>(); this.conditionDSLSentences = new ArrayList<DSLSentence>(); this.keywordDSLItems = new ArrayList<DSLSentence>(); this.anyScopeDSLItems = new ArrayList<DSLSentence>(); this.globalCollections = new ArrayList<String>(); this.accessorsAndMutators = new HashMap<String, FieldAccessorsAndMutators>(); this.allDataEnumsList = new HashMap<String, String[]>(); }
/** * For simple cases - where a list of values are known based on a field. */ public String[] getEnumValues(String factType, String field) { return this.getDataEnumList( factType + "." + field ); }
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); }
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 String[] getFieldCompletionsForGlobalVariable(final String varName) { final String type = this.getGlobalVariable( varName ); return this.getModelFields( type ); }
public String[] getModelFields(String modelClassName) { String shortName = this.getFactNameFromType( modelClassName ); if ( !this.getModelFields().containsKey( shortName ) ) { return new String[0]; } ModelField[] fields = this.getModelFields().get( shortName ); String[] fieldNames = new String[fields.length]; for ( int i = 0; i < fields.length; i++ ) { fieldNames[i] = fields[i].getName(); } return fieldNames; }
@Test public void testSmartEnumsDependingOfSeveralFieldsTwo() { final SuggestionCompletionEngine sce = new SuggestionCompletionEngine(); sce.setDataEnumLists( new HashMap<String, String[]>() ); sce.putDataEnumList( "Fact.field1", new String[]{"a1", "a2"} ); sce.putDataEnumList( "Fact.field2", new String[]{"b1", "b2"} ); sce.putDataEnumList( "Fact.field3[field1=a1,field2=b1]", new String[]{"c1", "c2", "c3"} ); sce.putDataEnumList( "Fact.field4[field1=a1]", new String[]{"d1", "d2"} ); pat.addConstraint( sfc2 ); String[] result = sce.getEnums( pat.getFactType(), pat.constraintList, "field3" ).fixedList;
final SuggestionCompletionEngine com = new SuggestionCompletionEngine(); com.setFactTypes( new String[]{"Person", "Vehicle"} ); com.setFieldsForTypes( new HashMap<String, ModelField[]>() { com.setGlobalVariables( new HashMap<String, String>() { String[] c = com.getConditionalElements(); assertEquals( "not", c[0] ); c = com.getFactTypes(); assertEquals( 2, c.length ); c = com.getFieldCompletions( "Person" ); assertEquals( "age", c[0] ); c = com.getFieldCompletions( "Vehicle" ); assertEquals( "type", c[1] ); c = com.getOperatorCompletions( "Person", "name" ); assertEquals( 12, c = com.getOperatorCompletions( "Person",
public String[] getOperatorCompletions(final String factType, final String fieldName) { String fieldType = getFieldType( factType, fieldName ); return STANDARD_OPERATORS; } else if ( fieldName.equals( TYPE_THIS ) ) { if ( this.isFactTypeAnEvent( factType ) ) { return joinArrays( STANDARD_OPERATORS, SIMPLE_CEP_OPERATORS, COMPLEX_CEP_OPERATORS ); return joinArrays( STRING_OPERATORS, EXPLICIT_LIST_OPERATORS ); } else if ( SuggestionCompletionEngine.isNumeric( fieldType ) ) { return joinArrays( COMPARABLE_OPERATORS, EXPLICIT_LIST_OPERATORS ); } else if ( fieldType.equals( TYPE_DATE ) ) { return joinArrays( COMPARABLE_OPERATORS, EXPLICIT_LIST_OPERATORS, SIMPLE_CEP_OPERATORS );
@Test public void testFilter() { final SuggestionCompletionEngine sce = new SuggestionCompletionEngine(); sce.setFactTypes( new String[]{"Person", "Vehicle"} ); sce.setFieldsForTypes( new HashMap<String, ModelField[]>() { sce.getFactTypes().length ); sce.setFactTypeFilter( new FactTypeFilter() { public boolean filter(String originalFact) { return "Person".equals( originalFact ); sce.getFactTypes().length ); sce.setFilteringFacts( false ); sce.getFactTypes().length ); sce.setFilteringFacts( true ); assertEquals( 1, sce.getFactTypes().length ); sce.setFactTypeFilter( null ); assertEquals( 2, sce.getFactTypes().length );
public void testCEPCompletions() { final SuggestionCompletionEngine com = new SuggestionCompletionEngine(); com.setFactTypes( new String[]{"NotAnEvent", "AnEvent"} ); com.setFieldsForTypes( new HashMap<String, ModelField[]>() { annotations.put( "AnEvent", eventAnnotations ); com.setAnnotationsForTypes( annotations ); String[] c = com.getFactTypes(); assertEquals( 2, c.length ); c ); c = com.getOperatorCompletions( "NotAnEvent", "dateField" ); assertEquals( 13, "coincides" ); c = com.getOperatorCompletions( "AnEvent", "this" ); assertEquals( 17,
final SuggestionCompletionEngine com = new SuggestionCompletionEngine(); com.setFactTypes( new String[]{"AnEvent"} ); com.setFieldsForTypes( new HashMap<String, ModelField[]>() { annotations.put( "AnEvent", eventAnnotations ); com.setAnnotationsForTypes( annotations ); List<Integer> c = SuggestionCompletionEngine.getCEPOperatorParameterSets( "after" ); assertEquals( 3, c.size() ); c = SuggestionCompletionEngine.getCEPOperatorParameterSets( "before" ); assertEquals( 3, c.size() ); c = SuggestionCompletionEngine.getCEPOperatorParameterSets( "coincides" ); assertEquals( 3, c.size() ); c = SuggestionCompletionEngine.getCEPOperatorParameterSets( "during" ); assertEquals( 4, c.size() ); c = SuggestionCompletionEngine.getCEPOperatorParameterSets( "finishes" ); assertEquals( 2, c.size() );
@Test public void testAdd() { final SuggestionCompletionEngine com = new SuggestionCompletionEngine(); com.setFactTypes( new String[]{"Foo"} ); com.setFieldsForTypes( new HashMap<String, ModelField[]>() { { put( "Foo", new ModelField[]{ new ModelField( "a", String.class.getName(), FIELD_CLASS_TYPE.REGULAR_CLASS, "String" ) } ); } } ); assertEquals( 1, com.getFactTypes().length ); assertEquals( "Foo", com.getFactTypes()[0] ); assertEquals( 1, com.getFieldCompletions( "Foo" ).length ); assertEquals( "a", com.getFieldCompletions( "Foo" )[0] ); }
enums ); assertEquals( "String", engine.getFieldType( "NestedClass", "name" ) ); engine.getDataEnumListsSize() ); String[] items = engine.getDataEnumList( "Person.age" ); assertEquals( 2, items.length ); items[1] ); items = engine.getEnums( "Person", null, "age" ).fixedList; items[1] ); assertNull( engine.getEnums( "Nothing", null, "age" ) ); engine.getEnums( "Something", null, "else" ) );
@Test public void testSimpleEnums() { final SuggestionCompletionEngine sce = new SuggestionCompletionEngine(); sce.setDataEnumLists( new HashMap<String, String[]>() ); sce.putDataEnumList( "Fact.type", new String[]{"sex", "colour"} ); assertEquals( 2, sce.getEnumValues( "Fact", "type" ).length ); assertEquals( "sex", sce.getEnumValues( "Fact", "type" )[0] ); assertEquals( "colour", sce.getEnumValues( "Fact", "type" )[1] ); }
dt.getConditions().add( p1 ); SuggestionCompletionEngine sce = new SuggestionCompletionEngine(); sce.setFieldsForTypes( new HashMap<String, ModelField[]>() {
@Test public void testGlobalAndFacts() { final SuggestionCompletionEngine com = new SuggestionCompletionEngine(); com.setGlobalVariables( new HashMap<String, String>() { { put( "y", "Foo" ); } } ); com.setFieldsForTypes( new HashMap<String, ModelField[]>() { { put( "Foo", new ModelField[]{ new ModelField( "a", String.class.getName(), FIELD_CLASS_TYPE.REGULAR_CLASS, "String" ) } ); } } ); assertFalse( com.isGlobalVariable( "x" ) ); assertTrue( com.isGlobalVariable( "y" ) ); }
SuggestionCompletionEngine sce = new SuggestionCompletionEngine(); sce.putDataEnumList( "Driver.name", new String[]{"bob", "michael"} ); sce.putDataEnumList( "Person.rating", new String[]{"1", "2"} ); assertTrue( sce.hasEnums( p1.getFactType(), c1.getFactField() ) ); assertFalse( dt.hasValueList( c1 ) ); String[] r = sce.getEnums( p1.getFactType(), c1.getFactField(), currentValueMap ).fixedList; assertTrue( sce.hasEnums( p1_.getFactType(), c1_.getFactField() ) ); assertFalse( dt.hasValueList( c1_ ) ); r = sce.getEnums( p1_.getFactType(), c1_.getFactField(), currentValueMap ).fixedList; assertFalse( sce.hasEnums( p1_.getFactType(), c1__.getFactField() ) ); assertTrue( dt.hasValueList( c1__ ) ); assertTrue( sce.hasEnums( p1__.getFactType(), c1___.getFactField() ) ); assertTrue( dt.hasValueList( c1___ ) ); assertTrue( sce.hasEnums( p1.getFactType(),
assertNotNull( suggestionCompletionEngine ); assertEquals( 2, suggestionCompletionEngine.getFactTypes().length ); .getFactTypes() ); suggestionCompletionEngine.getFieldClassName( "Person", "bananas" ) ); assertEquals( SuggestionCompletionEngine.TYPE_COLLECTION, suggestionCompletionEngine.getFieldType( "Person", "bananas" ) ); assertEquals( "Banana", suggestionCompletionEngine.getParametricFieldType( "Person", "bananas" ) );
Map<String, String> currentValueMap) { Map<String, Object> dataEnumLookupFields = loadDataEnumLookupFields(); String queryString = getQueryString( type, field, fieldsNeeded, return DropDownData.create( getEnumValues( type, field ) );