use of org.drools.workbench.screens.guided.template.model.GuidedTemplateEditorContent in project drools-wb by kiegroup.
the class GuidedRuleTemplateEditorServiceImplCDITest method testLoadContent.
@Test
public void testLoadContent() throws Exception {
final Path testedPath = getPath(CARS);
final GuidedTemplateEditorContent testedContent = testedService.loadContent(testedPath);
oracleFactory.makeAsyncPackageDataModelOracle(testedPath, testedContent.getModel(), testedContent.getDataModel());
final String declaredFactInEnum = "Car";
final String declaredFieldInEnum = "price";
final Map<String, String> actualFieldValues = new HashMap<String, String>() {
{
put("color", "red");
}
};
final DropDownData dropDownData = asyncOracle.getEnums(declaredFactInEnum, declaredFieldInEnum, actualFieldValues);
Assertions.assertThat(dropDownData.getQueryExpression()).isEqualTo("(new org.kiegroup.PriceHelper()).getPrices(\"@{color}\")");
Assertions.assertThat(dropDownData.getValuePairs()).hasSize(1);
Assertions.assertThat(dropDownData.getValuePairs()[0]).isEqualTo("color=red");
}
use of org.drools.workbench.screens.guided.template.model.GuidedTemplateEditorContent in project drools-wb by kiegroup.
the class GuidedRuleTemplateEditorServiceImplTest method checkConstructContentPopulateProjectCollectionTypes.
@Test
public void checkConstructContentPopulateProjectCollectionTypes() {
final Path path = mock(Path.class);
final Overview overview = mock(Overview.class);
final PackageDataModelOracle oracle = mock(PackageDataModelOracle.class);
when(path.toURI()).thenReturn("default://project/src/main/resources/mypackage/rule.template");
when(dataModelService.getDataModel(any())).thenReturn(oracle);
when(oracle.getPackageGlobals()).thenReturn(new HashMap<String, String>() {
{
put("number", "java.lang.Number");
put("collection", "java.util.Collection");
}
});
when(oracle.getModuleCollectionTypes()).thenReturn(new HashMap<String, Boolean>() {
{
put("java.util.List", true);
put("java.util.Set", true);
put("java.util.Collection", true);
put("java.util.UnknownCollection", false);
}
});
final GuidedTemplateEditorContent content = service.constructContent(path, overview);
assertEquals(3, content.getDataModel().getCollectionTypes().size());
assertTrue(content.getDataModel().getCollectionTypes().containsKey("java.util.Collection"));
assertTrue(content.getDataModel().getCollectionTypes().containsKey("java.util.List"));
assertTrue(content.getDataModel().getCollectionTypes().containsKey("java.util.Set"));
}
use of org.drools.workbench.screens.guided.template.model.GuidedTemplateEditorContent in project drools-wb by kiegroup.
the class GuidedRuleTemplateEditorServiceImpl method constructContent.
@Override
protected GuidedTemplateEditorContent constructContent(Path path, Overview overview) {
final TemplateModel model = load(path);
final PackageDataModelOracle oracle = dataModelService.getDataModel(path);
final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
// Get FQCN's used by model
final GuidedRuleModelVisitor visitor = new GuidedRuleModelVisitor(model);
final Set<String> consumedFQCNs = visitor.getConsumedModelClasses();
// Get FQCN's used by Globals
consumedFQCNs.addAll(oracle.getPackageGlobals().values());
// Get FQCN's of collections defined in project settings
// they can be used in From Collect expressions
consumedFQCNs.addAll(oracle.getModuleCollectionTypes().entrySet().stream().filter(entry -> entry.getValue()).map(entry -> entry.getKey()).collect(Collectors.toSet()));
DataModelOracleUtilities.populateDataModel(oracle, dataModel, consumedFQCNs);
// Signal opening to interested parties
resourceOpenedEvent.fire(new ResourceOpenedEvent(path, safeSessionInfo));
return new GuidedTemplateEditorContent(model, overview, dataModel);
}
use of org.drools.workbench.screens.guided.template.model.GuidedTemplateEditorContent in project drools-wb by kiegroup.
the class GuidedRuleTemplateEditorPresenter method getModelSuccessCallback.
private RemoteCallback<GuidedTemplateEditorContent> getModelSuccessCallback() {
return new RemoteCallback<GuidedTemplateEditorContent>() {
@Override
public void callback(final GuidedTemplateEditorContent content) {
// Path is set to null when the Editor is closed (which can happen before async calls complete).
if (versionRecordManager.getCurrentPath() == null) {
return;
}
resetEditorPages(content.getOverview());
addSourcePage();
addPage(new PageImpl(dataView, GuidedTemplateEditorConstants.INSTANCE.Data()) {
@Override
public void onFocus() {
dataView.setContent(model, oracle, eventBus, isReadOnly);
}
@Override
public void onLostFocus() {
// Nothing to do here
}
});
addImportsTab(importsWidget);
model = content.getModel();
final PackageDataModelOracleBaselinePayload dataModel = content.getDataModel();
oracle = oracleFactory.makeAsyncPackageDataModelOracle(versionRecordManager.getCurrentPath(), model, dataModel);
view.setContent(model, oracle, ruleNamesService, eventBus, isReadOnly);
importsWidget.setContent(oracle, model.getImports(), isReadOnly);
createOriginalHash(model);
view.hideBusyIndicator();
}
};
}
Aggregations