Search in sources :

Example 1 with ActionFieldValue

use of org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionFieldValue in project drools by kiegroup.

the class GuidedDecisionTreeModelMarshallingVisitor method generateActionInsertNodeDRL.

protected void generateActionInsertNodeDRL(final ActionInsertNode an, final Node context, final boolean hasDateFieldValue, final StringBuilder drl) {
    if (context == null) {
    // No previous context to close
    } else if (context instanceof ConstraintNode) {
        drl.append(")\n").append(INDENTATION).append("then \n");
        if (hasDateFieldValue) {
            drl.append(INDENTATION).append(INDENTATION).append("java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(\"" + DateUtils.getDateFormatMask() + "\");\n");
        }
    } else if (context instanceof TypeNode) {
        drl.append(")\n").append(INDENTATION).append("then \n");
        if (hasDateFieldValue) {
            drl.append(INDENTATION).append(INDENTATION).append("java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(\"" + DateUtils.getDateFormatMask() + "\");\n");
        }
    }
    final Iterator<ActionFieldValue> itr = an.getFieldValues().iterator();
    if (!itr.hasNext()) {
        return;
    }
    final String var = "$var" + (varCounter++);
    drl.append(INDENTATION).append(INDENTATION).append(an.getClassName()).append(" ").append(var).append(" = new ").append(an.getClassName()).append("();\n");
    while (itr.hasNext()) {
        final ActionFieldValue afv = itr.next();
        drl.append(INDENTATION).append(INDENTATION).append(var).append(".");
        drl.append("set");
        drl.append(Character.toUpperCase(afv.getFieldName().charAt(0)));
        drl.append(afv.getFieldName().substring(1));
        drl.append("( ").append(generateRHSValueDRL(afv.getValue())).append(" );\n");
    }
    if (an.isLogicalInsertion()) {
        drl.append(INDENTATION).append(INDENTATION).append("insertLogical( ").append(var).append(" );\n");
    } else {
        drl.append(INDENTATION).append(INDENTATION).append("insert( ").append(var).append(" );\n");
    }
}
Also used : ConstraintNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode) ActionFieldValue(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionFieldValue) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode)

Example 2 with ActionFieldValue

use of org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionFieldValue in project drools by kiegroup.

the class GuidedDecisionTreeModelUnmarshallingVisitor method visit.

private List<Node> visit(final IAction a, final List<TypeNode> types, final GuidedDecisionTree model, final PackageDataModelOracle dmo, final List<ParserMessage> messages) {
    final List<Node> nodes = new ArrayList<Node>();
    if (a instanceof ActionRetractFact) {
        final ActionRetractFact arf = (ActionRetractFact) a;
        final String binding = arf.getVariableName();
        for (TypeNode tn : types) {
            if (tn.isBound()) {
                if (tn.getBinding().equals(binding)) {
                    final ActionRetractNode arn = new ActionRetractNodeImpl(tn);
                    nodes.add(arn);
                    return nodes;
                }
            }
        }
        messages.add(new BindingNotFoundParserMessage(binding));
        return nodes;
    } else if (a instanceof ActionInsertLogicalFact) {
        final ActionInsertLogicalFact aif = (ActionInsertLogicalFact) a;
        final ActionInsertNode aun = new ActionInsertNodeImpl(aif.getFactType());
        aun.setLogicalInsertion(true);
        for (org.drools.workbench.models.datamodel.rule.ActionFieldValue afv : aif.getFieldValues()) {
            if (afv.getNature() != FieldNatureType.TYPE_LITERAL) {
                messages.add(new UnsupportedFieldNatureTypeParserMessage());
                return nodes;
            }
            final String fieldName = afv.getField();
            final Value value = getValue(aif.getFactType(), afv.getField(), model, dmo, messages, afv.getValue());
            if (value != null) {
                final ActionFieldValue _afv = new ActionFieldValueImpl(fieldName, value);
                aun.getFieldValues().add(_afv);
            }
        }
        nodes.add(aun);
        return nodes;
    } else if (a instanceof ActionInsertFact) {
        final ActionInsertFact aif = (ActionInsertFact) a;
        final ActionInsertNode aun = new ActionInsertNodeImpl(aif.getFactType());
        aun.setLogicalInsertion(false);
        for (org.drools.workbench.models.datamodel.rule.ActionFieldValue afv : aif.getFieldValues()) {
            if (afv.getNature() != FieldNatureType.TYPE_LITERAL) {
                messages.add(new UnsupportedFieldNatureTypeParserMessage());
                return nodes;
            }
            final String fieldName = afv.getField();
            final Value value = getValue(aif.getFactType(), afv.getField(), model, dmo, messages, afv.getValue());
            if (value != null) {
                final ActionFieldValue _afv = new ActionFieldValueImpl(fieldName, value);
                aun.getFieldValues().add(_afv);
            }
        }
        nodes.add(aun);
        return nodes;
    } else if (a instanceof ActionUpdateField) {
        final ActionUpdateField auf = (ActionUpdateField) a;
        final String binding = auf.getVariable();
        for (TypeNode tn : types) {
            if (tn.isBound()) {
                if (tn.getBinding().equals(binding)) {
                    final ActionUpdateNode aun = new ActionUpdateNodeImpl(tn);
                    aun.setModify(true);
                    for (org.drools.workbench.models.datamodel.rule.ActionFieldValue afv : auf.getFieldValues()) {
                        if (afv.getNature() != FieldNatureType.TYPE_LITERAL) {
                            messages.add(new UnsupportedFieldNatureTypeParserMessage());
                            return nodes;
                        }
                        final String fieldName = afv.getField();
                        final Value value = getValue(tn.getClassName(), afv.getField(), model, dmo, messages, afv.getValue());
                        if (value != null) {
                            final ActionFieldValue _afv = new ActionFieldValueImpl(fieldName, value);
                            aun.getFieldValues().add(_afv);
                        }
                    }
                    nodes.add(aun);
                    return nodes;
                }
            }
        }
        messages.add(new BindingNotFoundParserMessage(binding));
        return nodes;
    } else if (a instanceof ActionSetField) {
        final ActionSetField asf = (ActionSetField) a;
        final String binding = asf.getVariable();
        for (TypeNode tn : types) {
            if (tn.isBound()) {
                if (tn.getBinding().equals(binding)) {
                    final ActionUpdateNode aun = new ActionUpdateNodeImpl(tn);
                    for (org.drools.workbench.models.datamodel.rule.ActionFieldValue afv : asf.getFieldValues()) {
                        if (afv.getNature() != FieldNatureType.TYPE_LITERAL) {
                            messages.add(new UnsupportedFieldNatureTypeParserMessage());
                            return nodes;
                        }
                        final String fieldName = afv.getField();
                        final Value value = getValue(tn.getClassName(), afv.getField(), model, dmo, messages, afv.getValue());
                        if (value != null) {
                            final ActionFieldValue _afv = new ActionFieldValueImpl(fieldName, value);
                            aun.getFieldValues().add(_afv);
                        }
                    }
                    nodes.add(aun);
                    return nodes;
                }
            }
        }
        messages.add(new BindingNotFoundParserMessage(binding));
        return nodes;
    } else {
        messages.add(new UnsupportedIActionParserMessage());
        return nodes;
    }
}
Also used : ActionInsertNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode) ActionRetractNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) Node(org.drools.workbench.models.guided.dtree.shared.model.nodes.Node) ActionUpdateNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode) ActionInsertNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode) ConstraintNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode) ArrayList(java.util.ArrayList) ActionRetractNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionRetractNodeImpl) ActionInsertNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionInsertNodeImpl) ActionRetractFact(org.drools.workbench.models.datamodel.rule.ActionRetractFact) ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) BindingNotFoundParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.BindingNotFoundParserMessage) ActionFieldValue(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionFieldValue) ActionRetractNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) UnsupportedFieldNatureTypeParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.UnsupportedFieldNatureTypeParserMessage) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) ActionUpdateNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode) ShortValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.ShortValue) StringValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.StringValue) FloatValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.FloatValue) BigDecimalValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.BigDecimalValue) ByteValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.ByteValue) Value(org.drools.workbench.models.guided.dtree.shared.model.values.Value) DoubleValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.DoubleValue) IntegerValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.IntegerValue) DateValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.DateValue) BooleanValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.BooleanValue) BigIntegerValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.BigIntegerValue) LongValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.LongValue) ActionFieldValue(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionFieldValue) EnumValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.EnumValue) ActionUpdateNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionUpdateNodeImpl) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) ActionFieldValueImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionFieldValueImpl) UnsupportedIActionParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.UnsupportedIActionParserMessage) ActionInsertLogicalFact(org.drools.workbench.models.datamodel.rule.ActionInsertLogicalFact)

Example 3 with ActionFieldValue

use of org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionFieldValue in project drools by kiegroup.

the class GuidedDecisionTreeModelMarshallingVisitor method generateActionSetNodeDRL.

protected void generateActionSetNodeDRL(final ActionUpdateNode an, final StringBuilder drl) {
    final Iterator<ActionFieldValue> itr = an.getFieldValues().iterator();
    while (itr.hasNext()) {
        final ActionFieldValue afv = itr.next();
        drl.append(INDENTATION).append(INDENTATION).append(an.getBoundNode().getBinding()).append(".");
        drl.append("set");
        drl.append(Character.toUpperCase(afv.getFieldName().charAt(0)));
        drl.append(afv.getFieldName().substring(1));
        drl.append("( ").append(generateRHSValueDRL(afv.getValue())).append(" );\n");
    }
}
Also used : ActionFieldValue(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionFieldValue)

Example 4 with ActionFieldValue

use of org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionFieldValue in project drools-wb by kiegroup.

the class EditActionInsertPopup method initialiseFieldValues.

private void initialiseFieldValues() {
    containerFieldValues.clear();
    addFieldValueButton.setEnabled(true);
    for (ActionFieldValue afv : clone.getFieldValues()) {
        final ActionFieldValueEditor afvEditor = new ActionFieldValueEditor(clone.getClassName(), afv, clone.getFieldValues(), oracle, onDeleteCallback);
        containerFieldValues.add(afvEditor);
    }
}
Also used : ActionFieldValue(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionFieldValue)

Example 5 with ActionFieldValue

use of org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionFieldValue in project drools-wb by kiegroup.

the class EditActionInsertPopup method onAddFieldValueButtonClick.

@UiHandler("addFieldValueButton")
void onAddFieldValueButtonClick(final ClickEvent event) {
    final ActionFieldValue afv = new ActionFieldValueImpl();
    final ActionFieldValueEditor afvEditor = new ActionFieldValueEditor(clone.getClassName(), afv, clone.getFieldValues(), oracle, onDeleteCallback);
    containerFieldValues.add(afvEditor);
    clone.getFieldValues().add(afv);
}
Also used : ActionFieldValue(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionFieldValue) ActionFieldValueImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionFieldValueImpl) UiHandler(com.google.gwt.uibinder.client.UiHandler)

Aggregations

ActionFieldValue (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionFieldValue)8 ActionFieldValueImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionFieldValueImpl)3 UiHandler (com.google.gwt.uibinder.client.UiHandler)2 ConstraintNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode)2 TypeNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode)2 ArrayList (java.util.ArrayList)1 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)1 ActionInsertLogicalFact (org.drools.workbench.models.datamodel.rule.ActionInsertLogicalFact)1 ActionRetractFact (org.drools.workbench.models.datamodel.rule.ActionRetractFact)1 ActionSetField (org.drools.workbench.models.datamodel.rule.ActionSetField)1 ActionUpdateField (org.drools.workbench.models.datamodel.rule.ActionUpdateField)1 ActionInsertNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode)1 ActionRetractNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode)1 ActionUpdateNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode)1 Node (org.drools.workbench.models.guided.dtree.shared.model.nodes.Node)1 ActionInsertNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionInsertNodeImpl)1 ActionRetractNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionRetractNodeImpl)1 ActionUpdateNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionUpdateNodeImpl)1 BindingNotFoundParserMessage (org.drools.workbench.models.guided.dtree.shared.model.parser.messages.BindingNotFoundParserMessage)1 UnsupportedFieldNatureTypeParserMessage (org.drools.workbench.models.guided.dtree.shared.model.parser.messages.UnsupportedFieldNatureTypeParserMessage)1