Search in sources :

Example 1 with DTCellValue52

use of org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52 in project drools by kiegroup.

the class GuidedDTDRLPersistence method marshal.

public String marshal(final GuidedDecisionTable52 originalDTable) {
    final GuidedDecisionTable52 dt = DecisionTableHitPolicyEnhancer.enhance(originalDTable);
    StringBuilder sb = new StringBuilder();
    List<List<DTCellValue52>> data = dt.getData();
    List<BaseColumn> allColumns = dt.getExpandedColumns();
    // Append package name and imports to DRL
    PackageNameWriter.write(sb, dt);
    ImportsWriter.write(sb, dt);
    // Build rules
    for (int i = 0; i < data.size(); i++) {
        List<DTCellValue52> row = data.get(i);
        // Specialised BRDRLPersistence provider than can handle template key expansion
        TemplateDataProvider rowDataProvider = new GuidedDTTemplateDataProvider(allColumns, row);
        Integer num = (Integer) row.get(0).getNumericValue();
        String desc = row.get(1).getStringValue();
        BRLRuleModel rm = new BRLRuleModel(dt);
        rm.name = getName(dt.getTableName(), num);
        doMetadata(allColumns, dt.getMetadataCols(), row, rm);
        doAttribs(allColumns, dt.getAttributeCols(), row, rm);
        doConditions(allColumns, dt.getConditions(), rowDataProvider, row, data, rm);
        doActions(allColumns, dt.getActionCols(), rowDataProvider, row, rm);
        if (dt.getParentName() != null) {
            rm.parentName = dt.getParentName();
        }
        sb.append("//from row number: " + (i + 1) + "\n");
        if (desc != null && desc.length() > 0) {
            sb.append("//" + desc + "\n");
        }
        GuidedDTBRDRLPersistence drlMarshaller = new GuidedDTBRDRLPersistence(rowDataProvider);
        String rule = drlMarshaller.marshal(rm);
        sb.append(rule);
        sb.append("\n");
    }
    return sb.toString();
}
Also used : GuidedDTBRDRLPersistence(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTBRDRLPersistence) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) BRLRuleModel(org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) List(java.util.List) ActionFieldList(org.drools.workbench.models.datamodel.rule.ActionFieldList) ArrayList(java.util.ArrayList) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) TemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.TemplateDataProvider)

Example 2 with DTCellValue52

use of org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52 in project drools by kiegroup.

the class GuidedDTDRLPersistence method doActions.

void doActions(List<BaseColumn> allColumns, List<ActionCol52> actionCols, TemplateDataProvider rowDataProvider, List<DTCellValue52> row, RuleModel rm) {
    List<LabelledAction> actions = new ArrayList<LabelledAction>();
    for (ActionCol52 c : actionCols) {
        if (c instanceof LimitedEntryBRLActionColumn) {
            doAction(allColumns, (LimitedEntryBRLActionColumn) c, actions, rowDataProvider, row, rm);
        } else if (c instanceof BRLActionColumn) {
            doAction(allColumns, (BRLActionColumn) c, actions, rowDataProvider, row, rm);
        } else {
            int index = allColumns.indexOf(c);
            DTCellValue52 dcv = row.get(index);
            String cell = "";
            if (c instanceof LimitedEntryCol) {
                if (dcv.getBooleanValue() == true) {
                    LimitedEntryCol lec = (LimitedEntryCol) c;
                    cell = GuidedDTDRLUtilities.convertDTCellValueToString(lec.getValue());
                }
            } else {
                cell = GuidedDTDRLUtilities.convertDTCellValueToString(dcv);
            }
            if (validCell(cell, dcv.getDataType())) {
                if (c instanceof ActionWorkItemInsertFactCol52) {
                    doAction(actions, (ActionWorkItemInsertFactCol52) c, cell);
                } else if (c instanceof ActionInsertFactCol52) {
                    doAction(actions, (ActionInsertFactCol52) c, cell);
                } else if (c instanceof ActionWorkItemSetFieldCol52) {
                    doAction(actions, (ActionWorkItemSetFieldCol52) c, cell);
                } else if (c instanceof ActionSetFieldCol52) {
                    doAction(actions, (ActionSetFieldCol52) c, cell);
                } else if (c instanceof ActionRetractFactCol52) {
                    doAction(actions, cell);
                } else if (c instanceof ActionWorkItemCol52) {
                    doAction(actions, (ActionWorkItemCol52) c, cell);
                }
            }
        }
    }
    rm.rhs = new IAction[actions.size()];
    for (int i = 0; i < rm.rhs.length; i++) {
        rm.rhs[i] = actions.get(i).action;
    }
}
Also used : ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) ActionWorkItemInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemInsertFactCol52) ActionRetractFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionRetractFactCol52) ActionWorkItemCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemCol52) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) ArrayList(java.util.ArrayList) ActionWorkItemSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemSetFieldCol52) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) ActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) LimitedEntryCol(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryCol) LimitedEntryBRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryBRLActionColumn) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) LimitedEntryBRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryBRLActionColumn)

Example 3 with DTCellValue52

use of org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52 in project drools by kiegroup.

the class GuidedDTDRLPersistence method doMetadata.

void doMetadata(List<BaseColumn> allColumns, List<MetadataCol52> metadataCols, List<DTCellValue52> row, RuleModel rm) {
    // setup temp list
    List<RuleMetadata> metadataList = new ArrayList<RuleMetadata>();
    for (int j = 0; j < metadataCols.size(); j++) {
        MetadataCol52 meta = metadataCols.get(j);
        int index = allColumns.indexOf(meta);
        final DTCellValue52 dcv = row.get(index);
        String cell = GuidedDTDRLUtilities.convertDTCellValueToString(dcv);
        if (validateMetadataCell(cell)) {
            metadataList.add(new RuleMetadata(meta.getMetadata(), cell));
        }
    }
    if (metadataList.size() > 0) {
        rm.metadataList = metadataList.toArray(new RuleMetadata[metadataList.size()]);
    }
}
Also used : MetadataCol52(org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52) ArrayList(java.util.ArrayList) RuleMetadata(org.drools.workbench.models.datamodel.rule.RuleMetadata) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)

Example 4 with DTCellValue52

use of org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52 in project drools by kiegroup.

the class GuidedDTDRLPersistence method doCondition.

private void doCondition(List<BaseColumn> allColumns, BRLConditionColumn column, List<IPattern> patterns, TemplateDataProvider rowDataProvider, List<DTCellValue52> row, RuleModel rm) {
    // Check whether the parameter-less BRL fragment needs inclusion
    if (!hasVariables(column)) {
        final BRLConditionVariableColumn variableColumn = column.getChildColumns().get(0);
        final int index = allColumns.indexOf(variableColumn);
        final DTCellValue52 dcv = row.get(index);
        if (dcv != null && dcv.getBooleanValue()) {
            for (IPattern pattern : column.getDefinition()) {
                patterns.add(pattern);
            }
        }
    } else {
        for (IPattern pattern : column.getDefinition()) {
            boolean addPattern = false;
            // Get interpolation variables used by the Pattern
            Map<InterpolationVariable, Integer> ivs = new HashMap<InterpolationVariable, Integer>();
            RuleModelVisitor rmv = new RuleModelVisitor(pattern, ivs);
            rmv.visit(pattern);
            if (ivs.size() == 0) {
                addPattern = true;
            } else if (ivs.size() > 0) {
                int templateKeyCount = 0;
                for (InterpolationVariable variable : ivs.keySet()) {
                    String value = rowDataProvider.getTemplateKeyValue(variable.getVarName());
                    if (!"".equals(value)) {
                        templateKeyCount++;
                    }
                }
                // Ensure at least one key has a value (FreeFormLines need all values to be provided)
                if (pattern instanceof FreeFormLine) {
                    addPattern = templateKeyCount == ivs.size();
                } else if (templateKeyCount > 0) {
                    addPattern = true;
                }
            }
            if (addPattern) {
                patterns.add(pattern);
            }
        }
    }
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) RuleModelVisitor(org.drools.workbench.models.datamodel.rule.visitors.RuleModelVisitor) InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) HashMap(java.util.HashMap) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)

Example 5 with DTCellValue52

use of org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52 in project drools by kiegroup.

the class GuidedDTDRLPersistence method doAttribs.

void doAttribs(List<BaseColumn> allColumns, List<AttributeCol52> attributeCols, List<DTCellValue52> row, RuleModel rm) {
    List<RuleAttribute> attribs = new ArrayList<RuleAttribute>();
    for (int j = 0; j < attributeCols.size(); j++) {
        AttributeCol52 at = attributeCols.get(j);
        int index = allColumns.indexOf(at);
        final DTCellValue52 dcv = row.get(index);
        String cell = GuidedDTDRLUtilities.convertDTCellValueToString(dcv);
        if (validateAttributeCell(cell)) {
            // If instance of "otherwise" column then flag RuleModel as being negated
            if (at.getAttribute().equals(GuidedDecisionTable52.NEGATE_RULE_ATTR)) {
                rm.setNegated(Boolean.valueOf(cell));
            } else {
                attribs.add(new RuleAttribute(at.getAttribute(), cell));
            }
        }
    }
    if (attribs.size() > 0) {
        rm.attributes = attribs.toArray(new RuleAttribute[attribs.size()]);
    }
}
Also used : AttributeCol52(org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52) RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) ArrayList(java.util.ArrayList) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)

Aggregations

DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)285 Test (org.junit.Test)143 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)68 ArrayList (java.util.ArrayList)67 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)66 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)61 LimitedEntryConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52)54 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)43 List (java.util.List)40 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)38 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)33 AttributeCol52 (org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52)32 ActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)30 Path (org.uberfire.backend.vfs.Path)29 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)28 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)28 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)28 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)28 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)28 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)23