Search in sources :

Example 1 with ActionType

use of org.drools.decisiontable.parser.ActionType in project drools by kiegroup.

the class ActionTypeTest method testChooseActionType.

@Test
public void testChooseActionType() {
    Map<Integer, ActionType> actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "C", 0, 1);
    ActionType type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.CONDITION, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "CONDITION", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.CONDITION, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "A", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.ACTION, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "ACTION", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.ACTION, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "N", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.NAME, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "NAME", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.NAME, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "I", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.DESCRIPTION, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "DESCRIPTION", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.DESCRIPTION, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "P", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.SALIENCE, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "PRIORITY", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.SALIENCE, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "D", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.DURATION, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "DURATION", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.DURATION, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "T", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.TIMER, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "TIMER", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.TIMER, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "E", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.CALENDARS, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "CALENDARS", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.CALENDARS, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "U", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.NOLOOP, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "NO-LOOP", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.NOLOOP, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "L", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.LOCKONACTIVE, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "LOCK-ON-ACTIVE", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.LOCKONACTIVE, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "F", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.AUTOFOCUS, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "AUTO-FOCUS", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.AUTOFOCUS, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "X", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.ACTIVATIONGROUP, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "ACTIVATION-GROUP", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.ACTIVATIONGROUP, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "G", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.AGENDAGROUP, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "AGENDA-GROUP", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.AGENDAGROUP, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "R", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.RULEFLOWGROUP, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "RULEFLOW-GROUP", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.RULEFLOWGROUP, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "V", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.DATEEFFECTIVE, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "DATE-EFFECTIVE", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.DATEEFFECTIVE, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "Z", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.DATEEXPIRES, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "DATE-EXPIRES", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.DATEEXPIRES, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "@", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.METADATA, type.getCode());
    actionTypeMap = new HashMap<Integer, ActionType>();
    ActionType.addNewActionType(actionTypeMap, "METADATA", 0, 1);
    type = (ActionType) actionTypeMap.get(new Integer(0));
    assertEquals(Code.METADATA, type.getCode());
}
Also used : ActionType(org.drools.decisiontable.parser.ActionType) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 2 with ActionType

use of org.drools.decisiontable.parser.ActionType in project drools-wb by kiegroup.

the class GuidedDecisionTableGeneratorListener method doCodeCell.

private void doCodeCell(final int row, final int column, final String value) {
    final ActionType actionType = getActionForColumn(row, column);
    if (actionType.getSourceBuilder() == null) {
        if (actionType.getCode() == Code.CONDITION) {
            GuidedDecisionTableSourceBuilder sb = new GuidedDecisionTableLHSBuilder(row - 2, column, "", this._parameterUtilities, this._conversionResult);
            this._sourceBuilders.add(sb);
            actionType.setSourceBuilder(sb);
        } else if (actionType.getCode() == Code.ACTION) {
            GuidedDecisionTableSourceBuilder sb = new GuidedDecisionTableRHSBuilder(row - 2, column, "", this._sourceBuilders, this._parameterUtilities, this._conversionResult);
            this._sourceBuilders.add(sb);
            actionType.setSourceBuilder(sb);
        }
    }
    if (value.trim().equals("") && (actionType.getCode() == Code.ACTION || actionType.getCode() == Code.CONDITION || actionType.getCode() == Code.METADATA)) {
        final String message = "Code description in cell " + RuleSheetParserUtil.rc2name(row, column) + " does not contain any code specification. It should!";
        this._conversionResult.addMessage(message, ConversionMessageType.ERROR);
    }
    actionType.addTemplate(row, column, value);
}
Also used : ActionType(org.drools.decisiontable.parser.ActionType) GuidedDecisionTableSourceBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableSourceBuilder) GuidedDecisionTableRHSBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableRHSBuilder) GuidedDecisionTableLHSBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableLHSBuilder)

Example 3 with ActionType

use of org.drools.decisiontable.parser.ActionType in project drools-wb by kiegroup.

the class GuidedDecisionTableGeneratorListener method doObjectTypeCell.

private void doObjectTypeCell(final int row, final int column, final String value, final int mergedColStart) {
    if (value.indexOf("$param") > -1 || value.indexOf("$1") > -1) {
        final String message = "It looks like you have snippets in the row that is " + "meant for object declarations." + " Please insert an additional row before the snippets, " + "at cell " + RuleSheetParserUtil.rc2name(row, column);
        this._conversionResult.addMessage(message, ConversionMessageType.ERROR);
    }
    ActionType actionType = getActionForColumn(row, column);
    if (mergedColStart == RuleSheetListener.NON_MERGED) {
        if (actionType.getCode() == Code.CONDITION) {
            GuidedDecisionTableSourceBuilder sb = new GuidedDecisionTableLHSBuilder(row - 1, column, value, this._parameterUtilities, this._conversionResult);
            this._sourceBuilders.add(sb);
            actionType.setSourceBuilder(sb);
        } else if (actionType.getCode() == Code.ACTION) {
            GuidedDecisionTableSourceBuilder sb = new GuidedDecisionTableRHSBuilder(row - 1, column, value, this._sourceBuilders, this._parameterUtilities, this._conversionResult);
            this._sourceBuilders.add(sb);
            actionType.setSourceBuilder(sb);
        }
    } else {
        if (column == mergedColStart) {
            if (actionType.getCode() == Code.CONDITION) {
                GuidedDecisionTableSourceBuilder sb = new GuidedDecisionTableLHSBuilder(row - 1, column, value, this._parameterUtilities, this._conversionResult);
                this._sourceBuilders.add(sb);
                actionType.setSourceBuilder(sb);
            } else if (actionType.getCode() == Code.ACTION) {
                GuidedDecisionTableSourceBuilder sb = new GuidedDecisionTableRHSBuilder(row - 1, column, value, this._sourceBuilders, this._parameterUtilities, this._conversionResult);
                this._sourceBuilders.add(sb);
                actionType.setSourceBuilder(sb);
            }
        } else {
            ActionType startOfMergeAction = getActionForColumn(row, mergedColStart);
            actionType.setSourceBuilder(startOfMergeAction.getSourceBuilder());
        }
    }
}
Also used : ActionType(org.drools.decisiontable.parser.ActionType) GuidedDecisionTableSourceBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableSourceBuilder) GuidedDecisionTableRHSBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableRHSBuilder) GuidedDecisionTableLHSBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableLHSBuilder)

Example 4 with ActionType

use of org.drools.decisiontable.parser.ActionType in project drools-wb by kiegroup.

the class GuidedDecisionTableGeneratorListener method getActionForColumn.

private ActionType getActionForColumn(final int row, final int column) {
    final ActionType actionType = this._actions.get(column);
    if (actionType == null) {
        final String message = "Code description in cell " + RuleSheetParserUtil.rc2name(row, column) + " does not have an 'ACTION' or 'CONDITION' column header.";
        this._conversionResult.addMessage(message, ConversionMessageType.ERROR);
    }
    return actionType;
}
Also used : ActionType(org.drools.decisiontable.parser.ActionType)

Example 5 with ActionType

use of org.drools.decisiontable.parser.ActionType in project drools-wb by kiegroup.

the class GuidedDecisionTableGeneratorListener method initRuleTable.

/**
 * This gets called each time a "new" rule table is found.
 */
private void initRuleTable(final int row, final int column, final String value) {
    preInitRuleTable(row, column, value);
    this._isInRuleTable = true;
    this._actions = new HashMap<Integer, ActionType>();
    this._ruleStartColumn = column;
    this._ruleEndColumn = column;
    this._ruleStartRow = row;
    this._ruleRow = row + LABEL_ROW + 1;
    this._isNewDataRow = false;
    // setup stuff for the rules to come.. (the order of these steps are important !)
    this._currentSequentialFlag = getSequentialFlag();
    this._currentEscapeQuotesFlag = getEscapeQuotesFlag();
    this._parameterUtilities = new ParameterUtilities();
    // Setup new Decision Table
    this._dtable = new GuidedDecisionTable52();
    this._dtable.setTableFormat(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY);
    this._dtable.setTableName(RuleSheetParserUtil.getRuleName(value));
    this._dtable.setPackageName(_dmo.getPackageName());
    this._sourceBuilders = new ArrayList<GuidedDecisionTableSourceBuilder>();
    ROW_NUMBER_BUILDER.clearValues();
    DEFAULT_DESCRIPTION_BUILDER.clearValues();
    this._sourceBuilders.add(ROW_NUMBER_COLUMN_INDEX, ROW_NUMBER_BUILDER);
    this._sourceBuilders.add(DESCRIPTION_COLUMN_INDEX, DEFAULT_DESCRIPTION_BUILDER);
    postInitRuleTable(row, column, value);
}
Also used : ActionType(org.drools.decisiontable.parser.ActionType) ParameterUtilities(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.ParameterUtilities) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) GuidedDecisionTableSourceBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableSourceBuilder)

Aggregations

ActionType (org.drools.decisiontable.parser.ActionType)8 GuidedDecisionTableSourceBuilder (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableSourceBuilder)5 GuidedDecisionTableLHSBuilder (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableLHSBuilder)2 GuidedDecisionTableRHSBuilder (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableRHSBuilder)2 HashMap (java.util.HashMap)1 SourceBuilder (org.drools.decisiontable.parser.SourceBuilder)1 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)1 GuidedDecisionTableActivationGroupBuilder (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableActivationGroupBuilder)1 GuidedDecisionTableAgendaGroupBuilder (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableAgendaGroupBuilder)1 GuidedDecisionTableAutoFocusBuilder (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableAutoFocusBuilder)1 GuidedDecisionTableCalendarsBuilder (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableCalendarsBuilder)1 GuidedDecisionTableDateEffectiveBuilder (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableDateEffectiveBuilder)1 GuidedDecisionTableDateExpiresBuilder (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableDateExpiresBuilder)1 GuidedDecisionTableDescriptionBuilder (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableDescriptionBuilder)1 GuidedDecisionTableDurationBuilder (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableDurationBuilder)1 GuidedDecisionTableLockonActiveBuilder (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableLockonActiveBuilder)1 GuidedDecisionTableMetadataBuilder (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableMetadataBuilder)1 GuidedDecisionTableNameBuilder (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableNameBuilder)1 GuidedDecisionTableNoLoopBuilder (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableNoLoopBuilder)1 GuidedDecisionTableRuleflowGroupBuilder (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableRuleflowGroupBuilder)1