Search in sources :

Example 6 with DSLVariableValue

use of org.drools.workbench.models.datamodel.rule.DSLVariableValue 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)

Example 7 with DSLVariableValue

use of org.drools.workbench.models.datamodel.rule.DSLVariableValue in project drools by kiegroup.

the class RuleTemplateModelXMLLegacyPersistenceTest method testUnmarshalDSLVariableValuesLegacy.

@Test
public void testUnmarshalDSLVariableValuesLegacy() {
    // See https://issues.jboss.org/browse/GUVNOR-1872
    final String xml = "<rule>" + "<name>BugReportRule</name>" + "<modelVersion>1.0</modelVersion>" + "<attributes/>" + "<metadataList/>" + "<lhs>" + "<dslSentence>" + "<definition>If processInstance</definition>" + "<values/>" + "</dslSentence>" + "</lhs>" + "<rhs>" + "<dslSentence>" + "<definition>MyLog {myout}</definition>" + "<values>" + "<string>sample out rule 1</string>" + "<string>myout</string>" + "</values>" + "</dslSentence>" + "</rhs>" + "<isNegated>false</isNegated>" + "</rule>";
    RuleModel rm = RuleTemplateModelXMLPersistenceImpl.getInstance().unmarshal(xml);
    assertNotNull(rm);
    assertEquals(1, rm.lhs.length);
    assertTrue(rm.lhs[0] instanceof DSLSentence);
    DSLSentence dslPattern = (DSLSentence) rm.lhs[0];
    assertEquals("If processInstance", dslPattern.getDefinition());
    assertEquals(0, dslPattern.getValues().size());
    assertEquals(1, rm.rhs.length);
    assertTrue(rm.rhs[0] instanceof DSLSentence);
    DSLSentence dslAction = (DSLSentence) rm.rhs[0];
    assertEquals("MyLog {myout}", dslAction.getDefinition());
    assertEquals(2, dslAction.getValues().size());
    assertTrue(dslAction.getValues().get(0) instanceof DSLVariableValue);
    assertTrue(dslAction.getValues().get(1) instanceof DSLVariableValue);
    assertEquals("sample out rule 1", dslAction.getValues().get(0).getValue());
    assertEquals("myout", dslAction.getValues().get(1).getValue());
}
Also used : DSLVariableValue(org.drools.workbench.models.datamodel.rule.DSLVariableValue) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) DSLSentence(org.drools.workbench.models.datamodel.rule.DSLSentence) Test(org.junit.Test)

Example 8 with DSLVariableValue

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

the class DSLSentenceWidget method makeWidgets.

/**
 * This will take a DSL line item, and split it into widget thingamies for
 * displaying. One day, if this is too complex, this will have to be done on
 * the server side.
 */
public void makeWidgets(DSLSentence sentence) {
    String dslDefinition = sentence.getDefinition();
    List<DSLVariableValue> dslValues = sentence.getValues();
    int index = 0;
    int startVariable = dslDefinition.indexOf("{");
    List<Widget> lineWidgets = new ArrayList<Widget>();
    boolean firstOneIsBracket = (dslDefinition.indexOf("{") == 0);
    String startLabel = "";
    if (startVariable > 0) {
        startLabel = dslDefinition.substring(0, startVariable);
    } else if (!firstOneIsBracket) {
        // There are no curly brackets in the text. Just print it
        startLabel = dslDefinition;
    }
    Widget label = getLabel(startLabel);
    lineWidgets.add(label);
    while (startVariable > 0 || firstOneIsBracket) {
        firstOneIsBracket = false;
        int endVariable = getIndexForEndOfVariable(dslDefinition, startVariable);
        String currVariable = dslDefinition.substring(startVariable + 1, endVariable);
        DSLVariableValue value = dslValues.get(index);
        Widget varWidget = processVariable(currVariable, sentence, value);
        lineWidgets.add(varWidget);
        index++;
        // Parse out the next label between variables
        startVariable = dslDefinition.indexOf("{", endVariable);
        String lbl;
        if (startVariable > 0) {
            lbl = dslDefinition.substring(endVariable + 1, startVariable);
        } else {
            lbl = dslDefinition.substring(endVariable + 1, dslDefinition.length());
        }
        if (lbl.indexOf("\\n") > -1) {
            String[] lines = lbl.split("\\\\n");
            for (int i = 0; i < lines.length; i++) {
                lineWidgets.add(new NewLine());
                lineWidgets.add(getLabel(lines[i]));
            }
        } else {
            Widget currLabel = getLabel(lbl);
            lineWidgets.add(currLabel);
        }
    }
    for (Widget widg : lineWidgets) {
        addWidget(widg);
    }
    updateSentence();
}
Also used : DSLVariableValue(org.drools.workbench.models.datamodel.rule.DSLVariableValue) Widget(com.google.gwt.user.client.ui.Widget) ArrayList(java.util.ArrayList)

Aggregations

DSLVariableValue (org.drools.workbench.models.datamodel.rule.DSLVariableValue)8 DSLSentence (org.drools.workbench.models.datamodel.rule.DSLSentence)7 Test (org.junit.Test)7 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)6 ArrayList (java.util.ArrayList)2 DSLComplexVariableValue (org.drools.workbench.models.datamodel.rule.DSLComplexVariableValue)2 Widget (com.google.gwt.user.client.ui.Widget)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 Expander (org.drools.compiler.lang.Expander)1 DSLMappingFile (org.drools.compiler.lang.dsl.DSLMappingFile)1 DSLTokenizedMappingFile (org.drools.compiler.lang.dsl.DSLTokenizedMappingFile)1 DefaultExpander (org.drools.compiler.lang.dsl.DefaultExpander)1 RuleModeller (org.drools.workbench.screens.guided.rule.client.editor.RuleModeller)1 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)1