use of org.drools.workbench.screens.guided.rule.model.GuidedEditorContent in project drools-wb by kiegroup.
the class GuidedRuleEditorServiceImpl method constructContent.
@Override
protected GuidedEditorContent constructContent(Path path, Overview overview) {
final RuleModel 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 GuidedEditorContent(model, overview, dataModel);
}
use of org.drools.workbench.screens.guided.rule.model.GuidedEditorContent in project drools-wb by kiegroup.
the class GuidedRuleEditorServiceImplCDITest method testAbbreviatedCondition.
@Test
public void testAbbreviatedCondition() throws Exception {
final String resourcePath = RULES_ROOT + "matchPeopleAbbreviatedCondition.rdrl";
final GuidedEditorContent content = guidedRuleService.loadContent(getPath(resourcePath));
final RuleModel model = content.getModel();
Assertions.assertThat(model.lhs.length).isEqualTo(1);
final FactPattern pattern = (FactPattern) model.lhs[0];
final SingleFieldConstraint fieldConstraintOne = (SingleFieldConstraint) pattern.getConstraint(0);
Assertions.assertThat(fieldConstraintOne.getConnectives()).hasSize(2);
final ConnectiveConstraint fieldConstraintTwo = fieldConstraintOne.getConnectives()[0];
final ConnectiveConstraint fieldConstraintThree = fieldConstraintOne.getConnectives()[1];
Assertions.assertThat(fieldConstraintOne.getFieldName()).isEqualTo("age");
Assertions.assertThat(fieldConstraintOne.getOperator()).isEqualTo(Operator.NOT_EQUAL.getOperatorString());
Assertions.assertThat(fieldConstraintOne.getValue()).isEqualTo("18");
Assertions.assertThat(fieldConstraintTwo.getFieldName()).isEqualTo("age");
Assertions.assertThat(fieldConstraintTwo.getOperator()).isEqualTo("&& " + Operator.LESS.getOperatorString());
Assertions.assertThat(fieldConstraintTwo.getValue()).isEqualTo("25");
Assertions.assertThat(fieldConstraintThree.getFieldName()).isEqualTo("age");
Assertions.assertThat(fieldConstraintThree.getOperator()).isEqualTo("&& " + Operator.GREATER.getOperatorString());
Assertions.assertThat(fieldConstraintThree.getValue()).isEqualTo("15");
final List<ValidationMessage> messages = validateResource(resourcePath);
Assertions.assertThat(messages).isEmpty();
}
use of org.drools.workbench.screens.guided.rule.model.GuidedEditorContent in project drools-wb by kiegroup.
the class GuidedRuleEditorPresenter method getModelSuccessCallback.
private RemoteCallback<GuidedEditorContent> getModelSuccessCallback() {
return new RemoteCallback<GuidedEditorContent>() {
@Override
public void callback(final GuidedEditorContent content) {
// Path is set to null when the Editor is closed (which can happen before async calls complete).
if (versionRecordManager.getCurrentPath() == null) {
return;
}
GuidedRuleEditorPresenter.this.model = content.getModel();
final PackageDataModelOracleBaselinePayload dataModel = content.getDataModel();
oracle = oracleFactory.makeAsyncPackageDataModelOracle(versionRecordManager.getCurrentPath(), model, dataModel);
resetEditorPages(content.getOverview());
addSourcePage();
addImportsTab(importsWidget);
List<RuleModellerActionPlugin> actionPlugins = new ArrayList<>();
actionPluginInstance.forEach(actionPlugins::add);
view.setContent(model, actionPlugins, oracle, getRuleNamesService(), isReadOnly, isDSLEnabled);
importsWidget.setContent(oracle, model.getImports(), isReadOnly);
view.hideBusyIndicator();
createOriginalHash(model);
}
};
}
use of org.drools.workbench.screens.guided.rule.model.GuidedEditorContent in project drools-wb by kiegroup.
the class GuidedRuleEditorPresenterTest method setUp.
@Before
public void setUp() throws Exception {
guidedEditorContent = new GuidedEditorContent(ruleModel, overview, payload);
serviceCaller = new CallerMock<>(service);
ruleNamesServiceCaller = new CallerMock<>(ruleNamesService);
doReturn(imports).when(ruleModel).getImports();
doReturn(oracle).when(oracleFactory).makeAsyncPackageDataModelOracle(resourcePath, ruleModel, payload);
doReturn(resourcePath).when(versionRecordManager).getCurrentPath();
doReturn(resourcePath).when(versionRecordManager).getPathToLatest();
doReturn(guidedEditorContent).when(service).loadContent(resourcePath);
doReturn(serviceCaller).when(presenter).getService();
doReturn(ruleNamesServiceCaller).when(presenter).getRuleNamesService();
doReturn(versionRecordManager).when(presenter).getVersionRecordManager();
}
use of org.drools.workbench.screens.guided.rule.model.GuidedEditorContent in project drools-wb by kiegroup.
the class GuidedRuleEditorServiceImplTest method checkConstructContentPopulateProjectCollectionTypesAndDSLSentences.
@Test
public void checkConstructContentPopulateProjectCollectionTypesAndDSLSentences() throws Exception {
final Path path = mock(Path.class);
final Overview overview = mock(Overview.class);
final ModuleDataModelOracle projectDataModelOracle = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(List.class).addClass(Set.class).addClass(Collection.class).addClass(Integer.class).build();
final PackageDataModelOracle oracle = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator()).setModuleOracle(projectDataModelOracle).addExtension(DSLActionSentence.INSTANCE, Collections.singletonList(dslSentence)).addExtension(DSLConditionSentence.INSTANCE, Collections.singletonList(dslSentence)).build();
when(path.toURI()).thenReturn("file://project/src/main/resources/mypackage/rule.rdrl");
when(dataModelService.getDataModel(any())).thenReturn(oracle);
final GuidedEditorContent 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"));
assertTrue(content.getDataModel().getPackageElements(DSLActionSentence.INSTANCE).contains(dslSentence));
assertTrue(content.getDataModel().getPackageElements(DSLConditionSentence.INSTANCE).contains(dslSentence));
}
Aggregations