Search in sources :

Example 1 with Condition

use of org.drools.verifier.core.index.model.Condition in project drools-wb by kiegroup.

the class RuleBuilder method resolveColumns.

private void resolveColumns() throws BuildException {
    int columnIndex = 0;
    List<BaseColumn> expandedColumns = model.getExpandedColumns();
    for (final BaseColumn baseColumn : expandedColumns) {
        try {
            if (baseColumn instanceof AttributeCol52) {
                final String attribute = ((AttributeCol52) baseColumn).getAttribute();
                final DTCellValue52 realCellValue = getRealCellValue((AttributeCol52) baseColumn, row.get(columnIndex));
                final Optional<RuleAttribute> ruleAttribute = AttributeBuilder.build(columnIndex, configuration, attribute, realCellValue);
                if (ruleAttribute.isPresent()) {
                    rule.addRuleAttribute(ruleAttribute.get());
                }
            } else if (baseColumn instanceof ConditionCol52) {
                final Condition condition = builderFactory.getConditionBuilder().with((ConditionCol52) baseColumn).with(rule).with(row).with(columnIndex).build();
                rule.getConditions().add(condition);
            } else if (baseColumn instanceof ActionCol52) {
                final Action action = builderFactory.getActionBuilder().with(rule).with((ActionCol52) baseColumn).with(row).with(columnIndex).build();
                rule.getActions().add(action);
            }
            columnIndex++;
        } catch (BuildException e) {
            throw e;
        } catch (Exception e) {
            throw new BuildException("Could not resolve column: Index: " + columnIndex + " header: " + baseColumn.getHeader() + " error message: " + e.getMessage());
        }
    }
}
Also used : Condition(org.drools.verifier.core.index.model.Condition) Action(org.drools.verifier.core.index.model.Action) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) AttributeCol52(org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) RuleAttribute(org.drools.verifier.core.index.model.RuleAttribute) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)

Example 2 with Condition

use of org.drools.verifier.core.index.model.Condition in project drools by kiegroup.

the class FieldInspectorUpdateTest method makeCondition.

private FieldCondition makeCondition(final Field field) {
    final FieldCondition fieldAction = new FieldCondition(field, mock(Column.class), "==", new Values(11), configurationMock);
    final ArrayList<Condition> actionsList = new ArrayList<>();
    actionsList.add(fieldAction);
    final Conditions conditions = new Conditions(actionsList);
    when(field.getConditions()).thenReturn(conditions);
    return fieldAction;
}
Also used : Condition(org.drools.verifier.core.index.model.Condition) FieldCondition(org.drools.verifier.core.index.model.FieldCondition) FieldCondition(org.drools.verifier.core.index.model.FieldCondition) Column(org.drools.verifier.core.index.model.Column) Values(org.drools.verifier.core.index.keys.Values) ArrayList(java.util.ArrayList) Conditions(org.drools.verifier.core.index.model.Conditions)

Example 3 with Condition

use of org.drools.verifier.core.index.model.Condition in project drools by kiegroup.

the class RuleInspectorCache method deleteColumns.

public void deleteColumns(final int firstColumnIndex) {
    final Collection<Column> all = index.getColumns().where(Column.index().is(firstColumnIndex)).select().all();
    final Fields.FieldSelector fieldSelector = index.getRules().where(UUIDMatcher.uuid().any()).select().patterns().where(UUIDMatcher.uuid().any()).select().fields().where(UUIDMatcher.uuid().any()).select();
    final ArrayList<Action> actions = new ArrayList<>();
    final ArrayList<Condition> conditions = new ArrayList<>();
    for (final Field field : fieldSelector.all()) {
        for (final Column column : all) {
            final Collection<Action> all1 = field.getActions().where(Action.columnUUID().is(column.getUuidKey())).select().all();
            final Collection<Condition> all2 = field.getConditions().where(Condition.columnUUID().is(column.getUuidKey())).select().all();
            actions.addAll(all1);
            conditions.addAll(all2);
        }
    }
    for (final Action action : actions) {
        action.getUuidKey().retract();
    }
    for (final Condition condition : conditions) {
        condition.getUuidKey().retract();
    }
    for (final Column column : all) {
        column.getUuidKey().retract();
    }
    reset();
}
Also used : Condition(org.drools.verifier.core.index.model.Condition) Field(org.drools.verifier.core.index.model.Field) Action(org.drools.verifier.core.index.model.Action) Fields(org.drools.verifier.core.index.model.Fields) Column(org.drools.verifier.core.index.model.Column) ArrayList(java.util.ArrayList)

Example 4 with Condition

use of org.drools.verifier.core.index.model.Condition in project drools by kiegroup.

the class ConditionsListenerTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    final Condition condition = new FieldCondition(new Field(mock(ObjectField.class), "Person", "String", "name", configuration), new Column(1, configuration), "==", new Values<>(10), configuration);
    conditions.add(condition);
    reset(allListener);
    condition.setValue(new Values<>(20));
    verify(allListener).onAllChanged(anyCollection());
}
Also used : Condition(org.drools.verifier.core.index.model.Condition) FieldCondition(org.drools.verifier.core.index.model.FieldCondition) FieldCondition(org.drools.verifier.core.index.model.FieldCondition) ObjectField(org.drools.verifier.core.index.model.ObjectField) Field(org.drools.verifier.core.index.model.Field) Column(org.drools.verifier.core.index.model.Column) Test(org.junit.Test)

Example 5 with Condition

use of org.drools.verifier.core.index.model.Condition in project drools-wb by kiegroup.

the class CellBuilder method build.

public void build() throws BuildException {
    if (baseColumn instanceof ActionCol52) {
        final Action action = builderFactory.getActionBuilder().with(rule).with(row).with(columnIndex).with((ActionCol52) baseColumn).build();
        rule.getActions().add(action);
    } else if (baseColumn instanceof ConditionCol52) {
        if (baseColumn instanceof BRLConditionVariableColumn) {
            final Condition condition = builderFactory.getBRLConditionBuilder().with((BRLConditionVariableColumn) baseColumn).with(getRealCellValue((BRLConditionVariableColumn) baseColumn, row.get(columnIndex))).with(columnIndex).build();
            rule.getConditions().add(condition);
        } else {
            final Condition condition = builderFactory.getFieldConditionsBuilder().with(resolvePattern(rule)).with((ConditionCol52) baseColumn).with(getRealCellValue((ConditionCol52) baseColumn, row.get(columnIndex))).with(columnIndex).build();
            rule.getConditions().add(condition);
        }
    }
}
Also used : Condition(org.drools.verifier.core.index.model.Condition) Action(org.drools.verifier.core.index.model.Action) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)

Aggregations

Condition (org.drools.verifier.core.index.model.Condition)6 Action (org.drools.verifier.core.index.model.Action)3 Column (org.drools.verifier.core.index.model.Column)3 Field (org.drools.verifier.core.index.model.Field)3 FieldCondition (org.drools.verifier.core.index.model.FieldCondition)3 ArrayList (java.util.ArrayList)2 ActionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionCol52)2 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)2 Values (org.drools.verifier.core.index.keys.Values)1 Conditions (org.drools.verifier.core.index.model.Conditions)1 Fields (org.drools.verifier.core.index.model.Fields)1 ObjectField (org.drools.verifier.core.index.model.ObjectField)1 RuleAttribute (org.drools.verifier.core.index.model.RuleAttribute)1 AttributeCol52 (org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52)1 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)1 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)1 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)1 Test (org.junit.Test)1