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