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();
}
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())));
}
}
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"));
}
});
}
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"));
}
});
}
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());
}
});
}
Aggregations