Search in sources :

Example 1 with ClassFactBuilder

use of org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder 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 ClassFactBuilder

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

the class ModuleDataModelFactAnnotationsTest method testModuleDMOAnnotationAttributes2.

@Test
public void testModuleDMOAnnotationAttributes2() throws Exception {
    final ModuleDataModelOracleBuilder builder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator());
    final ModuleDataModelOracleImpl oracle = new ModuleDataModelOracleImpl();
    final ClassFactBuilder cb = new ClassFactBuilder(builder, RoleSmurf.class, false, TypeSource.JAVA_PROJECT);
    cb.build(oracle);
    assertEquals(1, oracle.getModuleModelFields().size());
    assertContains("org.kie.workbench.common.services.datamodel.backend.server.testclasses.annotations.RoleSmurf", oracle.getModuleModelFields().keySet());
    final Set<Annotation> annotations = oracle.getModuleTypeAnnotations().get("org.kie.workbench.common.services.datamodel.backend.server.testclasses.annotations.RoleSmurf");
    assertNotNull(annotations);
    assertEquals(1, annotations.size());
    final Annotation annotation = annotations.iterator().next();
    assertEquals("org.kie.api.definition.type.Role", annotation.getQualifiedTypeName());
    assertEquals("EVENT", annotation.getParameters().get("value"));
}
Also used : RawMVELEvaluator(org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator) ModuleDataModelOracleImpl(org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl) ClassFactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder) Annotation(org.kie.soup.project.datamodel.oracle.Annotation) ModuleDataModelOracleBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ModuleDataModelOracleBuilder) Test(org.junit.Test)

Example 3 with ClassFactBuilder

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

the class ModuleDataModelFactFieldsAnnotationsTest method testModuleDMOAnnotationAttributes.

@Test
public void testModuleDMOAnnotationAttributes() throws Exception {
    final ModuleDataModelOracleBuilder builder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator());
    final ModuleDataModelOracleImpl oracle = new ModuleDataModelOracleImpl();
    final ClassFactBuilder cb = new ClassFactBuilder(builder, SmurfHouse.class, false, TypeSource.JAVA_PROJECT);
    cb.build(oracle);
    assertEquals(1, oracle.getModuleModelFields().size());
    assertContains("org.kie.workbench.common.services.datamodel.backend.server.testclasses.annotations.SmurfHouse", oracle.getModuleModelFields().keySet());
    final Map<String, Set<Annotation>> fieldsAnnotations = oracle.getModuleTypeFieldsAnnotations().get("org.kie.workbench.common.services.datamodel.backend.server.testclasses.annotations.SmurfHouse");
    assertNotNull(fieldsAnnotations);
    assertEquals(2, fieldsAnnotations.size());
    testBaseAnnotations(fieldsAnnotations);
}
Also used : Set(java.util.Set) RawMVELEvaluator(org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator) ModuleDataModelOracleImpl(org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl) ClassFactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder) ModuleDataModelOracleBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ModuleDataModelOracleBuilder) Test(org.junit.Test)

Example 4 with ClassFactBuilder

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

the class ModuleDataModelFactFieldsAnnotationsTest method testModuleDMOZeroAnnotationAttributes.

@Test
public void testModuleDMOZeroAnnotationAttributes() throws Exception {
    final ModuleDataModelOracleBuilder builder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator());
    final ModuleDataModelOracleImpl oracle = new ModuleDataModelOracleImpl();
    final ClassFactBuilder cb = new ClassFactBuilder(builder, Product.class, false, TypeSource.JAVA_PROJECT);
    cb.build(oracle);
    assertEquals(1, oracle.getModuleModelFields().size());
    assertContains("org.kie.workbench.common.services.datamodel.backend.server.testclasses.Product", oracle.getModuleModelFields().keySet());
    final Map<String, Set<Annotation>> fieldAnnotations = oracle.getModuleTypeFieldsAnnotations().get("org.kie.workbench.common.services.datamodel.backend.server.testclasses.Product");
    assertNotNull(fieldAnnotations);
    assertEquals(0, fieldAnnotations.size());
}
Also used : Set(java.util.Set) RawMVELEvaluator(org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator) ModuleDataModelOracleImpl(org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl) ClassFactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder) ModuleDataModelOracleBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ModuleDataModelOracleBuilder) Test(org.junit.Test)

Example 5 with ClassFactBuilder

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

the class PackageDataModelFactAnnotationsTest method testCorrectPackageDMOAnnotationAttributes2.

@Test
public void testCorrectPackageDMOAnnotationAttributes2() throws Exception {
    // Build ModuleDMO
    final ModuleDataModelOracleBuilder moduleBuilder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator());
    final ModuleDataModelOracleImpl moduleLoader = new ModuleDataModelOracleImpl();
    final ClassFactBuilder cb = new ClassFactBuilder(moduleBuilder, RoleSmurf.class, false, TypeSource.JAVA_PROJECT);
    cb.build(moduleLoader);
    // Build PackageDMO
    final PackageDataModelOracleBuilder packageBuilder = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "org.kie.workbench.common.widgets.client.datamodel.testclasses.annotations");
    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("RoleSmurf", oracle.getFactTypes()[0]);
    oracle.getTypeAnnotations("RoleSmurf", new Callback<Set<Annotation>>() {

        @Override
        public void callback(final Set<Annotation> annotations) {
            assertNotNull(annotations);
            assertEquals(1, annotations.size());
            final Annotation annotation = annotations.iterator().next();
            assertEquals("org.kie.api.definition.type.Role", annotation.getQualifiedTypeName());
            assertEquals("EVENT", annotation.getParameters().get("value"));
        }
    });
}
Also used : Path(org.uberfire.backend.vfs.Path) IncrementalDataModelService(org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService) Set(java.util.Set) PackageDataModelOracleBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.packages.PackageDataModelOracleBuilder) ModuleDataModelOracleImpl(org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl) Annotation(org.kie.soup.project.datamodel.oracle.Annotation) ModuleDataModelOracleBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ModuleDataModelOracleBuilder) 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) 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)21 ModuleDataModelOracleBuilder (org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ModuleDataModelOracleBuilder)21 ModuleDataModelOracleImpl (org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl)20 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)20 Test (org.junit.Test)19 Annotation (org.kie.soup.project.datamodel.oracle.Annotation)14 Set (java.util.Set)12 PackageDataModelOracle (org.kie.soup.project.datamodel.oracle.PackageDataModelOracle)12 PackageDataModelOracleBuilder (org.kie.workbench.common.services.datamodel.backend.server.builder.packages.PackageDataModelOracleBuilder)12 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)12 IncrementalDataModelService (org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService)12 Path (org.uberfire.backend.vfs.Path)12 Map (java.util.Map)4 FactBuilder (org.kie.workbench.common.services.datamodel.backend.server.builder.projects.FactBuilder)3 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)1 Product (org.kie.workbench.common.services.datamodel.backend.server.testclasses.Product)1 ProductOrder (org.kie.workbench.common.services.datamodel.backend.server.testclasses.ProductOrder)1