Search in sources :

Example 41 with PackageDataModelOracleBaselinePayload

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

the class PackageDataModelOracleCompletionsTest method testFactFieldConnectiveOperatorCompletions.

@Test
public void testFactFieldConnectiveOperatorCompletions() {
    final ModuleDataModelOracle moduleLoader = 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("rank", Integer.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_COMPARABLE)).addField(new ModelField("name", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).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());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    Callback<String[]> personThisCallback = spy(new Callback<String[]>() {

        @Override
        public void callback(final String[] personThisConnectiveOperators) {
            assertEquals(3, personThisConnectiveOperators.length);
            assertEquals(personThisConnectiveOperators[0], "|| ==");
            assertEquals(personThisConnectiveOperators[1], "|| !=");
            assertEquals(personThisConnectiveOperators[2], "&& !=");
        }
    });
    oracle.getConnectiveOperatorCompletions("Person", "this", personThisCallback);
    verify(personThisCallback).callback(any(String[].class));
    Callback<String[]> personAgeCallback = spy(new Callback<String[]>() {

        @Override
        public void callback(final String[] personAgeConnectiveOperators) {
            assertEquals(11, personAgeConnectiveOperators.length);
            assertEquals(personAgeConnectiveOperators[0], "|| ==");
            assertEquals(personAgeConnectiveOperators[1], "|| !=");
            assertEquals(personAgeConnectiveOperators[2], "&& !=");
            assertEquals(personAgeConnectiveOperators[3], "&& >");
            assertEquals(personAgeConnectiveOperators[4], "&& <");
            assertEquals(personAgeConnectiveOperators[5], "|| >");
            assertEquals(personAgeConnectiveOperators[6], "|| <");
            assertEquals(personAgeConnectiveOperators[7], "&& >=");
            assertEquals(personAgeConnectiveOperators[8], "&& <=");
            assertEquals(personAgeConnectiveOperators[9], "|| <=");
            assertEquals(personAgeConnectiveOperators[10], "|| >=");
        }
    });
    oracle.getConnectiveOperatorCompletions("Person", "age", personAgeCallback);
    verify(personAgeCallback).callback(any(String[].class));
    Callback<String[]> personNameCallback = spy(new Callback<String[]>() {

        @Override
        public void callback(final String[] personRankConnectiveOperators) {
            assertEquals(11, personRankConnectiveOperators.length);
            assertEquals(personRankConnectiveOperators[0], "|| ==");
            assertEquals(personRankConnectiveOperators[1], "|| !=");
            assertEquals(personRankConnectiveOperators[2], "&& !=");
            assertEquals(personRankConnectiveOperators[3], "&& >");
            assertEquals(personRankConnectiveOperators[4], "&& <");
            assertEquals(personRankConnectiveOperators[5], "|| >");
            assertEquals(personRankConnectiveOperators[6], "|| <");
            assertEquals(personRankConnectiveOperators[7], "&& >=");
            assertEquals(personRankConnectiveOperators[8], "&& <=");
            assertEquals(personRankConnectiveOperators[9], "|| <=");
            assertEquals(personRankConnectiveOperators[10], "|| >=");
        }
    });
    oracle.getConnectiveOperatorCompletions("Person", "rank", personNameCallback);
    verify(personAgeCallback).callback(any(String[].class));
    Callback<String[]> personNameCallback2 = spy(new Callback<String[]>() {

        @Override
        public void callback(final String[] personNameConnectiveOperators) {
            assertEquals(13, personNameConnectiveOperators.length);
            assertEquals(personNameConnectiveOperators[0], "|| ==");
            assertEquals(personNameConnectiveOperators[1], "|| !=");
            assertEquals(personNameConnectiveOperators[2], "&& !=");
            assertEquals(personNameConnectiveOperators[3], "&& >");
            assertEquals(personNameConnectiveOperators[4], "&& <");
            assertEquals(personNameConnectiveOperators[5], "|| >");
            assertEquals(personNameConnectiveOperators[6], "|| <");
            assertEquals(personNameConnectiveOperators[7], "&& >=");
            assertEquals(personNameConnectiveOperators[8], "&& <=");
            assertEquals(personNameConnectiveOperators[9], "|| <=");
            assertEquals(personNameConnectiveOperators[10], "|| >=");
            assertEquals(personNameConnectiveOperators[11], "&& matches");
            assertEquals(personNameConnectiveOperators[12], "|| matches");
        }
    });
    oracle.getConnectiveOperatorCompletions("Person", "name", personNameCallback2);
    verify(personNameCallback2).callback(any(String[].class));
}
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 42 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 43 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 44 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 45 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)103 Path (org.uberfire.backend.vfs.Path)88 Test (org.junit.Test)83 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)75 PackageDataModelOracle (org.kie.soup.project.datamodel.oracle.PackageDataModelOracle)74 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)62 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)56 IncrementalDataModelService (org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService)55 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)32 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)29 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)26 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)25 ArrayList (java.util.ArrayList)24 List (java.util.List)23 LimitedEntryConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52)19 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)14 Set (java.util.Set)13 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)12 ActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)12 ModuleDataModelOracleImpl (org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl)12