Search in sources :

Example 1 with PackageDataModelOracleBuilder

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

the class LRUDataModelOracleCache method makePackageDataModelOracle.

private PackageDataModelOracle makePackageDataModelOracle(final KieModule module, final Package pkg) {
    final String packageName = pkg.getPackageName();
    final PackageDataModelOracleBuilder dmoBuilder = PackageDataModelOracleBuilder.newPackageOracleBuilder(evaluator, packageName);
    final ModuleDataModelOracle moduleOracle = cacheModules.assertModuleDataModelOracle(module);
    dmoBuilder.setModuleOracle(moduleOracle);
    // Add Guvnor enumerations
    loadEnumsForPackage(dmoBuilder, module, pkg);
    // Add DSLs
    loadExtensionsForPackage(dmoBuilder, pkg);
    // Add Globals
    loadGlobalsForPackage(dmoBuilder, pkg);
    return dmoBuilder.build();
}
Also used : ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) PackageDataModelOracleBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.packages.PackageDataModelOracleBuilder)

Example 2 with PackageDataModelOracleBuilder

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

the class LRUDataModelOracleCache method loadExtensionsForPackage.

private void loadExtensionsForPackage(final PackageDataModelOracleBuilder dmoBuilder, final Package pkg) {
    final org.uberfire.java.nio.file.Path nioPackagePath = Paths.convert(pkg.getPackageMainResourcesPath());
    List<DataModelExtension> extensions = stream(dataModelExtensionsProvider.spliterator(), false).collect(toList());
    for (final DataModelExtension extension : extensions) {
        Filter<org.uberfire.java.nio.file.Path> filter = extension.getFilter();
        final Collection<org.uberfire.java.nio.file.Path> extensionFiles = fileDiscoveryService.discoverFiles(nioPackagePath, filter);
        extensionFiles.stream().map(file -> extension.getExtensions(file, ioService.readAllString(file))).forEach(mappings -> mappings.forEach(mapping -> dmoBuilder.addExtension(mapping.getKind(), mapping.getValues())));
    }
}
Also used : Path(org.uberfire.backend.vfs.Path) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) FileDiscoveryService(org.guvnor.common.services.backend.file.FileDiscoveryService) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) DataModelExtension(org.kie.workbench.common.services.datamodel.spi.DataModelExtension) ArrayList(java.util.ArrayList) Package(org.guvnor.common.services.project.model.Package) Paths(org.uberfire.backend.server.util.Paths) Inject(javax.inject.Inject) KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) Observes(javax.enterprise.event.Observes) GlobalsFileFilter(org.kie.workbench.common.services.backend.file.GlobalsFileFilter) InvalidateDMOModuleCacheEvent(org.guvnor.common.services.project.builder.events.InvalidateDMOModuleCacheEvent) PortablePreconditions(org.kie.soup.commons.validation.PortablePreconditions) Named(javax.inject.Named) Instance(javax.enterprise.inject.Instance) Path(org.uberfire.backend.vfs.Path) BuildInfoService(org.kie.workbench.common.services.backend.builder.service.BuildInfoService) KieModuleMetaData(org.kie.scanner.KieModuleMetaData) Collection(java.util.Collection) KieModule(org.kie.workbench.common.services.shared.project.KieModule) EnumerationsFileFilter(org.kie.workbench.common.services.backend.file.EnumerationsFileFilter) PackageDataModelOracleBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.packages.PackageDataModelOracleBuilder) InvalidateDMOPackageCacheEvent(org.guvnor.common.services.project.builder.events.InvalidateDMOPackageCacheEvent) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) StreamSupport.stream(java.util.stream.StreamSupport.stream) LRUCache(org.guvnor.common.services.backend.cache.LRUCache) IOService(org.uberfire.io.IOService) DirectoryStream(org.uberfire.java.nio.file.DirectoryStream) ApplicationScoped(javax.enterprise.context.ApplicationScoped) MVELEvaluator(org.kie.soup.project.datamodel.commons.util.MVELEvaluator) Filter(org.uberfire.java.nio.file.DirectoryStream.Filter) DataModelExtension(org.kie.workbench.common.services.datamodel.spi.DataModelExtension)

Example 3 with PackageDataModelOracleBuilder

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

Example 4 with PackageDataModelOracleBuilder

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

the class PackageDataModelFactAnnotationsTest method testCorrectPackageDMOAnnotationAttributes.

@Test
public void testCorrectPackageDMOAnnotationAttributes() throws Exception {
    // Build ModuleDMO
    final ModuleDataModelOracleBuilder moduleBuilder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator());
    final ModuleDataModelOracleImpl moduleLoader = new ModuleDataModelOracleImpl();
    final ClassFactBuilder cb = new ClassFactBuilder(moduleBuilder, Smurf.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("Smurf", oracle.getFactTypes()[0]);
    oracle.getTypeAnnotations("Smurf", 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.workbench.common.widgets.client.datamodel.testclasses.annotations.SmurfDescriptor", annotation.getQualifiedTypeName());
            assertEquals("blue", annotation.getParameters().get("colour"));
            assertEquals("M", annotation.getParameters().get("gender"));
            assertEquals("Brains", annotation.getParameters().get("description"));
        }
    });
}
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)

Example 5 with PackageDataModelOracleBuilder

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

the class PackageDataModelFactFieldsAnnotationsTest method testIncorrectPackageDMOAnnotationAttributes.

@Test
public void testIncorrectPackageDMOAnnotationAttributes() throws Exception {
    // Build ModuleDMO
    final ModuleDataModelOracleBuilder moduleBuilder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator());
    final ModuleDataModelOracleImpl moduleLoader = new ModuleDataModelOracleImpl();
    final ClassFactBuilder cb = new ClassFactBuilder(moduleBuilder, SmurfHouse.class, false, TypeSource.JAVA_PROJECT);
    cb.build(moduleLoader);
    // Build PackageDMO. Defaults to defaultpkg
    final PackageDataModelOracleBuilder packageBuilder = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator());
    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(0, oracle.getFactTypes().length);
    oracle.getTypeFieldsAnnotations("SmurfHouse", new Callback<Map<String, Set<Annotation>>>() {

        @Override
        public void callback(final Map<String, Set<Annotation>> fieldAnnotations) {
            assertNotNull(fieldAnnotations);
            assertEquals(0, fieldAnnotations.size());
        }
    });
}
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) Map(java.util.Map) ClassFactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder) Test(org.junit.Test)

Aggregations

PackageDataModelOracleBuilder (org.kie.workbench.common.services.datamodel.backend.server.builder.packages.PackageDataModelOracleBuilder)14 PackageDataModelOracle (org.kie.soup.project.datamodel.oracle.PackageDataModelOracle)13 Path (org.uberfire.backend.vfs.Path)13 ModuleDataModelOracleImpl (org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl)12 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)12 ClassFactBuilder (org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder)12 ModuleDataModelOracleBuilder (org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ModuleDataModelOracleBuilder)12 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)12 IncrementalDataModelService (org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService)12 Test (org.junit.Test)11 Set (java.util.Set)9 Annotation (org.kie.soup.project.datamodel.oracle.Annotation)9 Map (java.util.Map)4 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)2 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)2 FactBuilder (org.kie.workbench.common.services.datamodel.backend.server.builder.projects.FactBuilder)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1