Search in sources :

Example 1 with FactBuilder

use of org.kie.workbench.common.services.datamodel.backend.server.builder.projects.FactBuilder in project kie-wb-common by kiegroup.

the class BPMNRuntimeFormGeneratorService method getModuleOracle.

protected ModuleDataModelOracle getModuleOracle(Class clazz) {
    try {
        final ModuleDataModelOracleBuilder builder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(evaluator);
        final ClassFactBuilder modelFactBuilder = new ClassFactBuilder(builder, clazz, false, TypeSource.JAVA_PROJECT);
        ModuleDataModelOracle oracle = modelFactBuilder.getDataModelBuilder().build();
        Map<String, FactBuilder> builders = new HashMap<>();
        for (FactBuilder factBuilder : modelFactBuilder.getInternalBuilders().values()) {
            if (factBuilder instanceof ClassFactBuilder) {
                builders.put(((ClassFactBuilder) factBuilder).getType(), factBuilder);
                factBuilder.build((ModuleDataModelOracleImpl) oracle);
            }
        }
        builders.put(modelFactBuilder.getType(), modelFactBuilder);
        modelFactBuilder.build((ModuleDataModelOracleImpl) oracle);
        return oracle;
    } catch (IOException ex) {
    }
    return null;
}
Also used : HashMap(java.util.HashMap) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) ClassFactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder) FactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.FactBuilder) IOException(java.io.IOException) ClassFactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder) ModuleDataModelOracleBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ModuleDataModelOracleBuilder)

Example 2 with FactBuilder

use of org.kie.workbench.common.services.datamodel.backend.server.builder.projects.FactBuilder in project kie-wb-common by kiegroup.

the class RuntimeDMOModelReader method getModuleOracle.

private ModuleDataModelOracle getModuleOracle(String typeName) {
    Class<?> clazz = null;
    try {
        clazz = classLoader.loadClass(typeName);
        if (clazz == null) {
            clazz = getClass().forName(typeName);
        }
    } catch (ClassNotFoundException e) {
        logger.error("Unable to extract model for class '{}'.", typeName);
        throw new IllegalStateException("Unable to extract model for class '" + typeName + "'");
    }
    if (clazz == null) {
        logger.error("Unable to extract model for class '{}'.", typeName);
        throw new IllegalStateException("Unable to extract model for class '" + typeName + "'");
    }
    try {
        final ModuleDataModelOracleBuilder builder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(evaluator);
        final ClassFactBuilder modelFactBuilder = new ClassFactBuilder(builder, clazz, false, type -> TypeSource.JAVA_PROJECT);
        ModuleDataModelOracle oracle = modelFactBuilder.getDataModelBuilder().build();
        Map<String, FactBuilder> builders = new HashMap<>();
        for (FactBuilder factBuilder : modelFactBuilder.getInternalBuilders().values()) {
            if (factBuilder instanceof ClassFactBuilder) {
                builders.put(((ClassFactBuilder) factBuilder).getType(), factBuilder);
                factBuilder.build((ModuleDataModelOracleImpl) oracle);
            }
        }
        builders.put(modelFactBuilder.getType(), modelFactBuilder);
        modelFactBuilder.build((ModuleDataModelOracleImpl) oracle);
        return oracle;
    } catch (IOException ex) {
        logger.warn("Couldn't inspect model {} due to: {}", typeName, ex);
    }
    return null;
}
Also used : HashMap(java.util.HashMap) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) FactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.FactBuilder) ClassFactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder) IOException(java.io.IOException) ClassFactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder) ModuleDataModelOracleBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ModuleDataModelOracleBuilder)

Example 3 with FactBuilder

use of org.kie.workbench.common.services.datamodel.backend.server.builder.projects.FactBuilder in project kie-wb-common by kiegroup.

the class PackageDataModelOracleTest method testDirectRecursion.

@Test
public void testDirectRecursion() throws Exception {
    // Build ModuleDMO
    final ModuleDataModelOracleBuilder moduleBuilder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator());
    final ModuleDataModelOracleImpl moduleLoader = new ModuleDataModelOracleImpl();
    final ClassFactBuilder cb = new ClassFactBuilder(moduleBuilder, new HashMap<String, FactBuilder>(), TestDirectRecursionClass.class, false, type -> TypeSource.JAVA_PROJECT);
    cb.build(moduleLoader);
    // Build PackageDMO
    final PackageDataModelOracleBuilder packageBuilder = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "org.kie.workbench.common.widgets.client.datamodel.testclasses");
    packageBuilder.setModuleOracle(moduleLoader);
    final PackageDataModelOracle packageLoader = packageBuilder.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.setTypeAnnotations(packageLoader.getModuleTypeAnnotations());
    dataModel.setTypeFieldsAnnotations(packageLoader.getModuleTypeFieldsAnnotations());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    assertEquals(1, oracle.getFactTypes().length);
    assertEquals("TestDirectRecursionClass", oracle.getFactTypes()[0]);
    oracle.getFieldCompletions("TestDirectRecursionClass", new Callback<ModelField[]>() {

        @Override
        public void callback(final ModelField[] result) {
            assertEquals(2, result.length);
            assertEquals("TestDirectRecursionClass", result[0].getClassName());
            assertEquals("recursiveField", result[0].getName());
            assertEquals("TestDirectRecursionClass", result[1].getClassName());
            assertEquals(DataType.TYPE_THIS, result[1].getName());
        }
    });
}
Also used : Path(org.uberfire.backend.vfs.Path) IncrementalDataModelService(org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService) PackageDataModelOracleBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.packages.PackageDataModelOracleBuilder) ModuleDataModelOracleImpl(org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl) ModuleDataModelOracleBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ModuleDataModelOracleBuilder) 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) ClassFactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder) FactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.FactBuilder) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) ClassFactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder) Test(org.junit.Test)

Example 4 with FactBuilder

use of org.kie.workbench.common.services.datamodel.backend.server.builder.projects.FactBuilder in project kie-wb-common by kiegroup.

the class PackageDataModelOracleTest method testIndirectRecursion.

@Test
public void testIndirectRecursion() throws Exception {
    // Build ModuleDMO
    final ModuleDataModelOracleBuilder moduleBuilder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator());
    final ModuleDataModelOracleImpl moduleLoader = new ModuleDataModelOracleImpl();
    final ClassFactBuilder cb = new ClassFactBuilder(moduleBuilder, new HashMap<String, FactBuilder>(), TestIndirectRecursionClassA.class, false, type -> TypeSource.JAVA_PROJECT);
    cb.build(moduleLoader);
    // Build PackageDMO
    final PackageDataModelOracleBuilder packageBuilder = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "org.kie.workbench.common.widgets.client.datamodel.testclasses");
    packageBuilder.setModuleOracle(moduleLoader);
    final PackageDataModelOracle packageLoader = packageBuilder.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.setTypeAnnotations(packageLoader.getModuleTypeAnnotations());
    dataModel.setTypeFieldsAnnotations(packageLoader.getModuleTypeFieldsAnnotations());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    assertEquals(1, oracle.getFactTypes().length);
    assertEquals("TestIndirectRecursionClassA", oracle.getFactTypes()[0]);
    oracle.getFieldCompletions("TestIndirectRecursionClassA", new Callback<ModelField[]>() {

        @Override
        public void callback(final ModelField[] result) {
            assertEquals(2, result.length);
            assertEquals("TestIndirectRecursionClassB", result[0].getClassName());
            assertEquals("recursiveField", result[0].getName());
            assertEquals("TestIndirectRecursionClassA", result[1].getClassName());
            assertEquals(DataType.TYPE_THIS, result[1].getName());
        }
    });
}
Also used : Path(org.uberfire.backend.vfs.Path) IncrementalDataModelService(org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService) PackageDataModelOracleBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.packages.PackageDataModelOracleBuilder) ModuleDataModelOracleImpl(org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl) ModuleDataModelOracleBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ModuleDataModelOracleBuilder) 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) ClassFactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder) FactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.FactBuilder) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) ClassFactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder) Test(org.junit.Test)

Aggregations

ClassFactBuilder (org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder)4 FactBuilder (org.kie.workbench.common.services.datamodel.backend.server.builder.projects.FactBuilder)4 ModuleDataModelOracleBuilder (org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ModuleDataModelOracleBuilder)4 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 ModuleDataModelOracleImpl (org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl)2 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)2 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)2 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)2 PackageDataModelOracle (org.kie.soup.project.datamodel.oracle.PackageDataModelOracle)2 PackageDataModelOracleBuilder (org.kie.workbench.common.services.datamodel.backend.server.builder.packages.PackageDataModelOracleBuilder)2 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)2 IncrementalDataModelService (org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService)2 Path (org.uberfire.backend.vfs.Path)2