Search in sources :

Example 16 with DSLSentence

use of org.drools.workbench.models.datamodel.rule.DSLSentence in project drools-wb by kiegroup.

the class DSLExtension method getExtensions.

@Override
public List<ExtensionMapping<?>> getExtensions(Path path, String content) {
    final DSLTokenizedMappingFile dslLoader = new DSLTokenizedMappingFile();
    List<DSLSentence> actionSentences = new ArrayList<>();
    List<DSLSentence> conditionSentences = new ArrayList<>();
    try {
        if (dslLoader.parseAndLoad(new StringReader(content))) {
            for (DSLMappingEntry entry : dslLoader.getMapping().getEntries()) {
                if (entry.getSection() == DSLMappingEntry.CONDITION) {
                    final DSLMappingEntry definition = entry;
                    final DSLSentence sentence = new DSLSentence();
                    sentence.setDrl(definition.getMappingValue());
                    sentence.setDefinition(definition.getMappingKey());
                    conditionSentences.add(sentence);
                } else if (entry.getSection() == DSLMappingEntry.CONSEQUENCE) {
                    final DSLMappingEntry definition = entry;
                    final DSLSentence sentence = new DSLSentence();
                    sentence.setDrl(definition.getMappingValue());
                    sentence.setDefinition(definition.getMappingKey());
                    actionSentences.add(sentence);
                }
            }
        }
    } catch (IOException e) {
        log.error(e.getMessage());
    }
    return Arrays.asList(new DSLMapping(DSLActionSentence.INSTANCE, actionSentences), new DSLMapping(DSLConditionSentence.INSTANCE, conditionSentences));
}
Also used : ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) DSLMappingEntry(org.drools.compiler.lang.dsl.DSLMappingEntry) IOException(java.io.IOException) DSLTokenizedMappingFile(org.drools.compiler.lang.dsl.DSLTokenizedMappingFile) DSLSentence(org.drools.workbench.models.datamodel.rule.DSLSentence)

Example 17 with DSLSentence

use of org.drools.workbench.models.datamodel.rule.DSLSentence in project drools-wb by kiegroup.

the class DRLTextEditorServiceImpl method constructContent.

@Override
protected DrlModelContent constructContent(Path path, Overview overview) {
    final PackageDataModelOracle oracle = dataModelService.getDataModel(path);
    final String[] fullyQualifiedClassNames = DataModelOracleUtilities.getFactTypes(oracle);
    final List<DSLSentence> dslConditions = oracle.getExtensions(DSLConditionSentence.INSTANCE);
    final List<DSLSentence> dslActions = oracle.getExtensions(DSLActionSentence.INSTANCE);
    // Signal opening to interested parties
    resourceOpenedEvent.fire(new ResourceOpenedEvent(path, safeSessionInfo));
    return new DrlModelContent(load(path), overview, Arrays.asList(fullyQualifiedClassNames), dslConditions, dslActions);
}
Also used : DrlModelContent(org.drools.workbench.screens.drltext.model.DrlModelContent) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) ResourceOpenedEvent(org.uberfire.workbench.events.ResourceOpenedEvent) DSLSentence(org.drools.workbench.models.datamodel.rule.DSLSentence)

Example 18 with DSLSentence

use of org.drools.workbench.models.datamodel.rule.DSLSentence in project drools-wb by kiegroup.

the class DSLSentenceBrowserWidget method setDSLSentences.

public void setDSLSentences(final List<DSLSentence> dslSentences) {
    if (tree.getItem(0) != null) {
        tree.clear();
    }
    if (dslSentences != null) {
        for (DSLSentence dslSentence : dslSentences) {
            final TreeItem it = new TreeItem();
            it.setHTML("<small>" + dslSentence.toString() + "</small>");
            it.setUserObject(dslSentence);
            tree.addItem(it);
        }
    }
}
Also used : TreeItem(com.google.gwt.user.client.ui.TreeItem) DSLSentence(org.drools.workbench.models.datamodel.rule.DSLSentence)

Example 19 with DSLSentence

use of org.drools.workbench.models.datamodel.rule.DSLSentence in project drools-wb by kiegroup.

the class RuleModelCloneVisitorTest method buildDslSentence.

private DSLSentence buildDslSentence() {
    DSLSentence dsl = new DSLSentence();
    dsl.setDrl("Person( sex == {$sex} )");
    dsl.setDefinition("Person is {$sex:ENUM:Person.sex}");
    return dsl;
}
Also used : DSLSentence(org.drools.workbench.models.datamodel.rule.DSLSentence)

Example 20 with DSLSentence

use of org.drools.workbench.models.datamodel.rule.DSLSentence in project drools-wb by kiegroup.

the class DSLDropDownTest method testGetDropDown.

@Test
public void testGetDropDown() throws Exception {
    final String fact = "Fact";
    final String field = "field";
    final AsyncPackageDataModelOracle oracle = mock(AsyncPackageDataModelOracle.class);
    final RuleModeller ruleModeller = mock(RuleModeller.class);
    doReturn(oracle).when(ruleModeller).getDataModelOracle();
    final String variableDefinition = "varName:type:" + fact + "." + field;
    final DSLSentence dslSentence = mock(DSLSentence.class);
    final DSLVariableValue dslVariableValue = mock(DSLVariableValue.class);
    final boolean isMultipleSelect = false;
    final Callback<DSLDropDown> updateEnumsCallback = mock(Callback.class);
    testedDropDown = new DSLDropDown(ruleModeller, variableDefinition, dslSentence, dslVariableValue, isMultipleSelect, updateEnumsCallback);
    // reset oracle due to calls in DSLDropDown constructor
    reset(oracle);
    testedDropDown.getDropDownData();
    verify(oracle).getEnums(eq(fact), eq(field), anyMap());
}
Also used : AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) RuleModeller(org.drools.workbench.screens.guided.rule.client.editor.RuleModeller) DSLVariableValue(org.drools.workbench.models.datamodel.rule.DSLVariableValue) DSLSentence(org.drools.workbench.models.datamodel.rule.DSLSentence) Test(org.junit.Test)

Aggregations

DSLSentence (org.drools.workbench.models.datamodel.rule.DSLSentence)29 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)19 Test (org.junit.Test)19 DSLVariableValue (org.drools.workbench.models.datamodel.rule.DSLVariableValue)7 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)6 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)6 DSLComplexVariableValue (org.drools.workbench.models.datamodel.rule.DSLComplexVariableValue)5 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)5 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)4 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)4 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)4 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)3 ActionRetractFact (org.drools.workbench.models.datamodel.rule.ActionRetractFact)3 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)3 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)3 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)3 Command (com.google.gwt.user.client.Command)2 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 ArrayList (java.util.ArrayList)2