Search in sources :

Example 1 with PluggableIAction

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

the class RuleModelDRLPersistenceImpl method marshalRHS.

protected void marshalRHS(final StringBuilder buf, final RuleModel model, final boolean isDSLEnhanced, final RHSGeneratorContextFactory generatorContextFactory) {
    String indentation = "\t\t";
    if (model.rhs != null) {
        // Add boiler-plate for actions operating on Dates
        Map<String, List<ActionFieldValue>> classes = getRHSClassDependencies(model);
        if (classes.containsKey(DataType.TYPE_DATE)) {
            buf.append(indentation);
            if (isDSLEnhanced) {
                buf.append(">");
            }
            buf.append("java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(\"" + DateUtils.getDateFormatMask() + "\");\n");
        }
        // Add boiler-plate for actions operating on WorkItems
        if (!getRHSWorkItemDependencies(model).isEmpty()) {
            buf.append(indentation);
            buf.append("org.drools.core.process.instance.WorkItemManager wim = (org.drools.core.process.instance.WorkItemManager) drools.getWorkingMemory().getWorkItemManager();\n");
        }
        // Marshall the model itself
        RHSActionVisitor actionVisitor = getRHSActionVisitor(isDSLEnhanced, buf, indentation, generatorContextFactory);
        // Reconcile ActionSetField and ActionUpdateField calls
        final List<IAction> actions = new ArrayList<IAction>();
        for (IAction action : model.rhs) {
            if (action instanceof ActionCallMethod) {
                actions.add(action);
            } else if (action instanceof ActionSetField) {
                final ActionSetField asf = (ActionSetField) action;
                final ActionSetFieldWrapper afw = findExistingAction(asf, actions);
                if (afw == null) {
                    actions.add(new ActionSetFieldWrapper(asf, (asf instanceof ActionUpdateField)));
                } else {
                    final List<ActionFieldValue> existingActionFieldValue = new ArrayList<ActionFieldValue>(Arrays.asList(afw.getAction().getFieldValues()));
                    for (ActionFieldValue afv : asf.getFieldValues()) {
                        existingActionFieldValue.add(afv);
                    }
                    final ActionFieldValue[] temp = new ActionFieldValue[existingActionFieldValue.size()];
                    afw.getAction().setFieldValues(existingActionFieldValue.toArray(temp));
                }
            } else {
                actions.add(action);
            }
        }
        model.rhs = new IAction[actions.size()];
        for (int i = 0; i < actions.size(); i++) {
            final IAction action = actions.get(i);
            if (action instanceof ActionSetFieldWrapper) {
                model.rhs[i] = ((ActionSetFieldWrapper) action).getAction();
            } else {
                model.rhs[i] = action;
            }
        }
        for (IAction action : model.rhs) {
            if (action instanceof PluggableIAction) {
                PluggableIAction processedIAction = (PluggableIAction) actionVisitor.preProcessIActionForExtensions(action);
                buf.append(indentation).append(processedIAction.getStringRepresentation()).append(";\n");
            } else {
                actionVisitor.visit(action);
            }
        }
    }
}
Also used : PluggableIAction(org.drools.workbench.models.datamodel.rule.PluggableIAction) IAction(org.drools.workbench.models.datamodel.rule.IAction) PluggableIAction(org.drools.workbench.models.datamodel.rule.PluggableIAction) ArrayList(java.util.ArrayList) ActionCallMethod(org.drools.workbench.models.datamodel.rule.ActionCallMethod) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ArrayList(java.util.ArrayList) StringUtils.splitArgumentsList(org.drools.core.util.StringUtils.splitArgumentsList) List(java.util.List) ActionFieldList(org.drools.workbench.models.datamodel.rule.ActionFieldList)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 StringUtils.splitArgumentsList (org.drools.core.util.StringUtils.splitArgumentsList)1 ActionCallMethod (org.drools.workbench.models.datamodel.rule.ActionCallMethod)1 ActionFieldList (org.drools.workbench.models.datamodel.rule.ActionFieldList)1 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)1 ActionSetField (org.drools.workbench.models.datamodel.rule.ActionSetField)1 ActionUpdateField (org.drools.workbench.models.datamodel.rule.ActionUpdateField)1 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)1 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)1 ConnectiveConstraint (org.drools.workbench.models.datamodel.rule.ConnectiveConstraint)1 FieldConstraint (org.drools.workbench.models.datamodel.rule.FieldConstraint)1 IAction (org.drools.workbench.models.datamodel.rule.IAction)1 PluggableIAction (org.drools.workbench.models.datamodel.rule.PluggableIAction)1 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)1