Search in sources :

Example 1 with GuidedEditorContent

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);
}
Also used : PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) GuidedEditorContent(org.drools.workbench.screens.guided.rule.model.GuidedEditorContent) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) RuleModelDRLPersistenceImpl(org.drools.workbench.models.commons.backend.rule.RuleModelDRLPersistenceImpl) ArrayList(java.util.ArrayList) Package(org.guvnor.common.services.project.model.Package) Paths(org.uberfire.backend.server.util.Paths) Inject(javax.inject.Inject) ExceptionUtilities(org.guvnor.common.services.backend.exceptions.ExceptionUtilities) CommentedOptionFactory(org.guvnor.common.services.backend.util.CommentedOptionFactory) Overview(org.guvnor.common.services.shared.metadata.model.Overview) Service(org.jboss.errai.bus.server.annotations.Service) SafeSessionInfo(org.guvnor.common.services.backend.config.SafeSessionInfo) SessionInfo(org.uberfire.rpc.SessionInfo) GuidedRuleDSLRResourceTypeDefinition(org.drools.workbench.screens.guided.rule.type.GuidedRuleDSLRResourceTypeDefinition) Named(javax.inject.Named) KieService(org.kie.workbench.common.services.backend.service.KieService) RenameService(org.uberfire.ext.editor.commons.service.RenameService) Instance(javax.enterprise.inject.Instance) GuidedRuleDRLResourceTypeDefinition(org.drools.workbench.screens.guided.rule.type.GuidedRuleDRLResourceTypeDefinition) Path(org.uberfire.backend.vfs.Path) DeleteService(org.uberfire.ext.editor.commons.service.DeleteService) Event(javax.enterprise.event.Event) DataModelService(org.kie.workbench.common.services.datamodel.backend.server.service.DataModelService) SaveAndRenameServiceImpl(org.uberfire.ext.editor.commons.backend.service.SaveAndRenameServiceImpl) RuleModelIActionPersistenceExtension(org.drools.workbench.models.commons.backend.rule.RuleModelIActionPersistenceExtension) Collection(java.util.Collection) DataModelOracleUtilities(org.kie.workbench.common.services.datamodel.backend.server.DataModelOracleUtilities) Set(java.util.Set) Import(org.kie.soup.project.datamodel.imports.Import) Collectors(java.util.stream.Collectors) ResourceOpenedEvent(org.uberfire.workbench.events.ResourceOpenedEvent) GenericValidator(org.guvnor.common.services.backend.validation.GenericValidator) List(java.util.List) GuidedRuleEditorService(org.drools.workbench.screens.guided.rule.service.GuidedRuleEditorService) PostConstruct(javax.annotation.PostConstruct) IOService(org.uberfire.io.IOService) ApplicationScoped(javax.enterprise.context.ApplicationScoped) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException) CopyService(org.uberfire.ext.editor.commons.service.CopyService) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) GuidedEditorContent(org.drools.workbench.screens.guided.rule.model.GuidedEditorContent) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) ResourceOpenedEvent(org.uberfire.workbench.events.ResourceOpenedEvent) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel)

Example 2 with GuidedEditorContent

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();
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) GuidedEditorContent(org.drools.workbench.screens.guided.rule.model.GuidedEditorContent) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 3 with GuidedEditorContent

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);
        }
    };
}
Also used : PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) GuidedEditorContent(org.drools.workbench.screens.guided.rule.model.GuidedEditorContent) RuleModellerActionPlugin(org.drools.workbench.screens.guided.rule.client.editor.plugin.RuleModellerActionPlugin) ArrayList(java.util.ArrayList) RemoteCallback(org.jboss.errai.common.client.api.RemoteCallback)

Example 4 with GuidedEditorContent

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();
}
Also used : GuidedEditorContent(org.drools.workbench.screens.guided.rule.model.GuidedEditorContent) Before(org.junit.Before)

Example 5 with GuidedEditorContent

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));
}
Also used : Path(org.uberfire.backend.vfs.Path) Set(java.util.Set) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) RawMVELEvaluator(org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator) GuidedEditorContent(org.drools.workbench.screens.guided.rule.model.GuidedEditorContent) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) Overview(org.guvnor.common.services.shared.metadata.model.Overview) Test(org.junit.Test)

Aggregations

GuidedEditorContent (org.drools.workbench.screens.guided.rule.model.GuidedEditorContent)5 ArrayList (java.util.ArrayList)2 Set (java.util.Set)2 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)2 Overview (org.guvnor.common.services.shared.metadata.model.Overview)2 ValidationMessage (org.guvnor.common.services.shared.validation.model.ValidationMessage)2 Test (org.junit.Test)2 PackageDataModelOracle (org.kie.soup.project.datamodel.oracle.PackageDataModelOracle)2 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)2 Collection (java.util.Collection)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 PostConstruct (javax.annotation.PostConstruct)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Event (javax.enterprise.event.Event)1 Instance (javax.enterprise.inject.Instance)1 Inject (javax.inject.Inject)1 Named (javax.inject.Named)1 RuleModelDRLPersistenceImpl (org.drools.workbench.models.commons.backend.rule.RuleModelDRLPersistenceImpl)1 RuleModelIActionPersistenceExtension (org.drools.workbench.models.commons.backend.rule.RuleModelIActionPersistenceExtension)1