Search in sources :

Example 61 with PackageDataModelOracleBaselinePayload

use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.

the class PackageDataModelOracleCEPCompletionsTest method testCEPCompletions.

@Test
public void testCEPCompletions() {
    final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addFact("NotAnEvent").addField(new ModelField("dateField", Date.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_DATE)).end().addFact("AnEvent", true).addField(new ModelField("this", Object.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.SELF, FieldAccessorsAndMutators.BOTH, "AnEvent")).addField(new ModelField("dateField", Date.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_DATE)).end().build();
    final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator()).setModuleOracle(moduleLoader).build();
    // Emulate server-to-client conversions
    final Caller<IncrementalDataModelService> service = new MockIncrementalDataModelServiceCaller(packageLoader);
    final AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl(service, validatorInstance);
    final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
    dataModel.setPackageName(packageLoader.getPackageName());
    dataModel.setModelFields(packageLoader.getModuleModelFields());
    dataModel.setEventTypes(packageLoader.getModuleEventTypes());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    // Check completions
    String[] types = oracle.getFactTypes();
    assertEquals(2, types.length);
    PackageDataModelOracleTestUtils.assertContains("NotAnEvent", types);
    PackageDataModelOracleTestUtils.assertContains("AnEvent", types);
    oracle.getOperatorCompletions("NotAnEvent", "dateField", new Callback<String[]>() {

        @Override
        public void callback(final String[] notAnEventDateFieldOperators) {
            assertEquals(15, notAnEventDateFieldOperators.length);
            assertEquals(notAnEventDateFieldOperators[0], "==");
            assertEquals(notAnEventDateFieldOperators[1], "!=");
            assertEquals(notAnEventDateFieldOperators[2], "<");
            assertEquals(notAnEventDateFieldOperators[3], ">");
            assertEquals(notAnEventDateFieldOperators[4], "<=");
            assertEquals(notAnEventDateFieldOperators[5], ">=");
            assertEquals(notAnEventDateFieldOperators[6], "== null");
            assertEquals(notAnEventDateFieldOperators[7], "!= null");
            assertEquals(notAnEventDateFieldOperators[8], "memberOf");
            assertEquals(notAnEventDateFieldOperators[9], "not memberOf");
            assertEquals(notAnEventDateFieldOperators[10], "in");
            assertEquals(notAnEventDateFieldOperators[11], "not in");
            assertEquals(notAnEventDateFieldOperators[12], "after");
            assertEquals(notAnEventDateFieldOperators[13], "before");
            assertEquals(notAnEventDateFieldOperators[14], "coincides");
        }
    });
    oracle.getOperatorCompletions("AnEvent", "this", new Callback<String[]>() {

        @Override
        public void callback(final String[] anEventThisOperators) {
            assertEquals(19, anEventThisOperators.length);
            assertEquals(anEventThisOperators[0], "==");
            assertEquals(anEventThisOperators[1], "!=");
            assertEquals(anEventThisOperators[2], "== null");
            assertEquals(anEventThisOperators[3], "!= null");
            assertEquals(anEventThisOperators[4], "memberOf");
            assertEquals(anEventThisOperators[5], "not memberOf");
            assertEquals(anEventThisOperators[6], "after");
            assertEquals(anEventThisOperators[7], "before");
            assertEquals(anEventThisOperators[8], "coincides");
            assertEquals(anEventThisOperators[9], "during");
            assertEquals(anEventThisOperators[10], "finishes");
            assertEquals(anEventThisOperators[11], "finishedby");
            assertEquals(anEventThisOperators[12], "includes");
            assertEquals(anEventThisOperators[13], "meets");
            assertEquals(anEventThisOperators[14], "metby");
            assertEquals(anEventThisOperators[15], "overlaps");
            assertEquals(anEventThisOperators[16], "overlappedby");
            assertEquals(anEventThisOperators[17], "starts");
            assertEquals(anEventThisOperators[18], "startedby");
        }
    });
}
Also used : Path(org.uberfire.backend.vfs.Path) IncrementalDataModelService(org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) RawMVELEvaluator(org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) Test(org.junit.Test)

Example 62 with PackageDataModelOracleBaselinePayload

use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.

the class PackageDataModelOracleEnumTest method testBasicDependentEnums.

@Test
public void testBasicDependentEnums() {
    final ModuleDataModelOracle projectLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addFact("Fact").addField(new ModelField("field1", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).addField(new ModelField("field2", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).end().addFact("Driver").addField(new ModelField("sex", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).end().addEnum("'Fact.field1' : ['val1', 'val2'], 'Fact.field2' : ['val3', 'val4'], 'Fact.field2[field1=val1]' : ['f1val1a', 'f1val1b'], 'Fact.field2[field1=val2]' : ['f1val2a', 'f1val2b']", Thread.currentThread().getContextClassLoader()).build();
    final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator()).setModuleOracle(projectLoader).build();
    // Emulate server-to-client conversions
    final Caller<IncrementalDataModelService> service = new MockIncrementalDataModelServiceCaller(packageLoader);
    final AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl(service, validatorInstance);
    final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
    dataModel.setPackageName(packageLoader.getPackageName());
    dataModel.setModelFields(packageLoader.getModuleModelFields());
    dataModel.setJavaEnumDefinitions(packageLoader.getModuleJavaEnumDefinitions());
    dataModel.setWorkbenchEnumDefinitions(packageLoader.getPackageWorkbenchDefinitions());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    assertEquals("String", oracle.getFieldType("Fact", "field1"));
    assertEquals("String", oracle.getFieldType("Fact", "field2"));
    String[] field1Enums = oracle.getEnumValues("Fact", "field1");
    assertEquals(2, field1Enums.length);
    assertEquals("val1", field1Enums[0]);
    assertEquals("val2", field1Enums[1]);
    String[] field2Enums = oracle.getEnumValues("Fact", "field2");
    assertEquals(2, field2Enums.length);
    assertEquals("val3", field2Enums[0]);
    assertEquals("val4", field2Enums[1]);
}
Also used : Path(org.uberfire.backend.vfs.Path) IncrementalDataModelService(org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) RawMVELEvaluator(org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) Test(org.junit.Test)

Example 63 with PackageDataModelOracleBaselinePayload

use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.

the class PackageDataModelOracleEnumTest method testSmartLookupEnums.

@Test
public void testSmartLookupEnums() {
    final ModuleDataModelOracle projectLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addFact("Fact").addField(new ModelField("type", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).addField(new ModelField("value", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).end().addEnum("Fact", "type", new String[] { "sex", "colour" }).addEnum("Fact", "value[f1, f2]", new String[] { "select something from database where x=@{f1} and y=@{f2}" }).build();
    final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator()).setModuleOracle(projectLoader).build();
    // Emulate server-to-client conversions
    final Caller<IncrementalDataModelService> service = new MockIncrementalDataModelServiceCaller(packageLoader);
    final AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl(service, validatorInstance);
    final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
    dataModel.setPackageName(packageLoader.getPackageName());
    dataModel.setModelFields(packageLoader.getModuleModelFields());
    dataModel.setJavaEnumDefinitions(packageLoader.getModuleJavaEnumDefinitions());
    dataModel.setWorkbenchEnumDefinitions(packageLoader.getPackageWorkbenchDefinitions());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    Map<String, String> currentValueMap = new HashMap<>();
    currentValueMap.put("f1", "f1val");
    currentValueMap.put("f2", "f2val");
    DropDownData dd = oracle.getEnums("Fact", "value", currentValueMap);
    assertNull(dd.getFixedList());
    assertNotNull(dd.getQueryExpression());
    assertNotNull(dd.getValuePairs());
    assertEquals(2, dd.getValuePairs().length);
    assertEquals("select something from database where x=@{f1} and y=@{f2}", dd.getQueryExpression());
    assertEquals("f1=f1val", dd.getValuePairs()[0]);
    assertEquals("f2=f2val", dd.getValuePairs()[1]);
}
Also used : Path(org.uberfire.backend.vfs.Path) IncrementalDataModelService(org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService) HashMap(java.util.HashMap) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) DropDownData(org.kie.soup.project.datamodel.oracle.DropDownData) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) RawMVELEvaluator(org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) Test(org.junit.Test)

Example 64 with PackageDataModelOracleBaselinePayload

use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.

the class PackageDataModelOracleEnumTest method testBasicEnums.

@Test
public void testBasicEnums() {
    final ModuleDataModelOracle projectLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addFact("Person").addField(new ModelField("age", Integer.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_NUMERIC_INTEGER)).addField(new ModelField("sex", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).end().addFact("Driver").addField(new ModelField("sex", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).end().addEnum("Person", "age", new String[] { "42", "43" }).addEnum("Person", "sex", new String[] { "M", "F" }).addEnum("Driver", "sex", new String[] { "M", "F" }).build();
    final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator()).setModuleOracle(projectLoader).build();
    // Emulate server-to-client conversions
    final Caller<IncrementalDataModelService> service = new MockIncrementalDataModelServiceCaller(packageLoader);
    final AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl(service, validatorInstance);
    final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
    dataModel.setPackageName(packageLoader.getPackageName());
    dataModel.setModelFields(packageLoader.getModuleModelFields());
    dataModel.setJavaEnumDefinitions(packageLoader.getModuleJavaEnumDefinitions());
    dataModel.setWorkbenchEnumDefinitions(packageLoader.getPackageWorkbenchDefinitions());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    String[] personAgeEnum = oracle.getEnumValues("Person", "age");
    assertEquals(2, personAgeEnum.length);
    assertEquals("42", personAgeEnum[0]);
    assertEquals("43", personAgeEnum[1]);
    String[] personSexEnum = oracle.getEnumValues("Person", "sex");
    assertEquals(2, personSexEnum.length);
    assertEquals("M", personSexEnum[0]);
    assertEquals("F", personSexEnum[1]);
    String[] driverSexEnum = oracle.getEnumValues("Driver", "sex");
    assertEquals(2, driverSexEnum.length);
    assertEquals("M", driverSexEnum[0]);
    assertEquals("F", driverSexEnum[1]);
}
Also used : Path(org.uberfire.backend.vfs.Path) IncrementalDataModelService(org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) RawMVELEvaluator(org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) Test(org.junit.Test)

Example 65 with PackageDataModelOracleBaselinePayload

use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.

the class PackageDataModelOracleEnumTest method testDataHasEnumsFieldSuffixes.

@Test
public void testDataHasEnumsFieldSuffixes() {
    final ModuleDataModelOracle projectLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addFact("Fact").addField(new ModelField("field1", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).addField(new ModelField("field2", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).addField(new ModelField("field2suffixed", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).end().addEnum("'Fact.field1' : ['val1', 'val2'], 'Fact.field2[field1=val1]' : ['f1val1a', 'f1val1b']", Thread.currentThread().getContextClassLoader()).build();
    final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator()).setModuleOracle(projectLoader).build();
    // Emulate server-to-client conversions
    final Caller<IncrementalDataModelService> service = new MockIncrementalDataModelServiceCaller(packageLoader);
    final AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl(service, validatorInstance);
    final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
    dataModel.setPackageName(packageLoader.getPackageName());
    dataModel.setModelFields(packageLoader.getModuleModelFields());
    dataModel.setJavaEnumDefinitions(packageLoader.getModuleJavaEnumDefinitions());
    dataModel.setWorkbenchEnumDefinitions(packageLoader.getPackageWorkbenchDefinitions());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    // Fact.field1 has explicit enumerations
    assertTrue(oracle.hasEnums("Fact.field1"));
    assertTrue(oracle.hasEnums("Fact", "field1"));
    // Fact.field2 has explicit enumerations dependent upon Fact.field1
    assertTrue(oracle.hasEnums("Fact.field2"));
    assertTrue(oracle.hasEnums("Fact", "field2"));
    // Fact.field2suffixed has no enums
    assertFalse(oracle.hasEnums("Fact.field2suffixed"));
    assertFalse(oracle.hasEnums("Fact", "field2suffixed"));
}
Also used : Path(org.uberfire.backend.vfs.Path) IncrementalDataModelService(org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) RawMVELEvaluator(org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) Test(org.junit.Test)

Aggregations

PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)124 Path (org.uberfire.backend.vfs.Path)105 Test (org.junit.Test)102 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)95 PackageDataModelOracle (org.kie.soup.project.datamodel.oracle.PackageDataModelOracle)84 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)82 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)76 IncrementalDataModelService (org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService)55 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)51 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)48 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)45 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)43 LimitedEntryConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52)38 ArrayList (java.util.ArrayList)32 List (java.util.List)32 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)28 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)20 ActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)20 LimitedEntryActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionInsertFactCol52)18 LimitedEntryActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionSetFieldCol52)18