Search in sources :

Example 1 with VetoUpdatePatternInUseException

use of org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoUpdatePatternInUseException in project drools-wb by kiegroup.

the class BRLConditionColumnSynchronizerTest method checkBRLFragmentConditionCannotBeUpdatedWhenFieldBindingIsUsedInAction.

@Test
public void checkBRLFragmentConditionCannotBeUpdatedWhenFieldBindingIsUsedInAction() throws VetoException {
    final BRLConditionColumn column = new BRLConditionColumn();
    column.setDefinition(Collections.singletonList(new FactPattern("Applicant") {

        {
            setBoundName("$a");
            addConstraint(new SingleFieldConstraint("age") {

                {
                    setBoundName("$age");
                }
            });
        }
    }));
    final BRLConditionVariableColumn columnV0 = new BRLConditionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Applicant", "age");
    column.getChildColumns().add(columnV0);
    column.setHeader("col1");
    columnV0.setHeader("col1v0");
    modelSynchronizer.appendColumn(column);
    final BRLActionColumn action = new BRLActionColumn();
    action.setDefinition(Collections.singletonList(new ActionCallMethod() {

        {
            setVariable("$age");
            setMethodName("toString()");
        }
    }));
    final BRLActionVariableColumn columnV1 = new BRLActionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Applicant", "age");
    action.getChildColumns().add(columnV1);
    action.setHeader("col2");
    columnV1.setHeader("col2v0");
    modelSynchronizer.appendColumn(action);
    try {
        final BRLConditionColumn editedColumn = new BRLConditionColumn();
        editedColumn.setDefinition(Collections.singletonList(new FactPattern("Applicant") {

            {
                setBoundName("$a");
                addConstraint(new SingleFieldConstraint("age") {

                    {
                        setBoundName("$age2");
                    }
                });
            }
        }));
        final BRLConditionVariableColumn editedColumnV0 = new BRLConditionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Applicant", "age");
        editedColumn.getChildColumns().add(editedColumnV0);
        editedColumn.setHeader("col1");
        editedColumnV0.setHeader("col1v0");
        modelSynchronizer.updateColumn(column, editedColumn);
        fail("Deletion of the column should have been vetoed.");
    } catch (VetoUpdatePatternInUseException veto) {
    // This is expected
    } catch (VetoException veto) {
        fail("VetoUpdatePatternInUseException was expected.");
    }
    assertEquals(5, model.getExpandedColumns().size());
    assertTrue(model.getExpandedColumns().get(0) instanceof RowNumberCol52);
    assertTrue(model.getExpandedColumns().get(1) instanceof RuleNameColumn);
    assertTrue(model.getExpandedColumns().get(2) instanceof DescriptionCol52);
    assertEquals(columnV0, model.getExpandedColumns().get(3));
    assertEquals(action.getChildColumns().get(0), model.getExpandedColumns().get(4));
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) VetoException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoException) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ActionCallMethod(org.drools.workbench.models.datamodel.rule.ActionCallMethod) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) VetoUpdatePatternInUseException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoUpdatePatternInUseException) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) RuleNameColumn(org.drools.workbench.models.guided.dtable.shared.model.RuleNameColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 2 with VetoUpdatePatternInUseException

use of org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoUpdatePatternInUseException in project drools-wb by kiegroup.

the class BRLConditionColumnSynchronizer method update.

@Override
public List<BaseColumnFieldDiff> update(final ColumnMetaData originalMetaData, final ColumnMetaData editedMetaData) throws VetoException {
    // Check operation is supported
    if (!(handlesUpdate(originalMetaData) && handlesUpdate(editedMetaData))) {
        return Collections.emptyList();
    }
    // Check whether any discarded bindings were used. If so veto the update.
    final BRLConditionColumn originalColumn = (BRLConditionColumn) originalMetaData.getColumn();
    final BRLConditionColumn editedColumn = (BRLConditionColumn) editedMetaData.getColumn();
    final Set<String> originalBindings = getPatternBindings(originalColumn);
    final Set<String> editedBindings = getPatternBindings(editedColumn);
    originalBindings.removeAll(editedBindings);
    for (String binding : originalBindings) {
        if (rm.isBoundFactUsed(binding)) {
            throw new VetoUpdatePatternInUseException();
        }
    }
    final List<BaseColumnFieldDiff> diffs = originalColumn.diff(editedColumn);
    // Copy existing data for re-use if applicable
    final Map<String, List<DTCellValue52>> originalColumnsData = new HashMap<>();
    for (BRLConditionVariableColumn variable : originalColumn.getChildColumns()) {
        int iColumnIndex = model.getExpandedColumns().indexOf(variable);
        final List<DTCellValue52> originalColumnData = new ArrayList<>();
        final String key = makeUpdateBRLConditionColumnKey(variable);
        for (List<DTCellValue52> row : model.getData()) {
            originalColumnData.add(row.get(iColumnIndex));
        }
        originalColumnsData.put(key, originalColumnData);
    }
    // Insert new columns setting data from that above, if applicable. Column visibility is handled here too.
    model.getConditions().add(model.getConditions().indexOf(originalColumn), editedColumn);
    for (BRLConditionVariableColumn childModelColumn : editedColumn.getChildColumns()) {
        final String key = makeUpdateBRLConditionColumnKey(childModelColumn);
        if (originalColumnsData.containsKey(key)) {
            final List<DTCellValue52> originalColumnData = originalColumnsData.get(key);
            synchroniseAppendColumn(childModelColumn, originalColumnData);
        } else {
            synchroniseAppendColumn(childModelColumn);
        }
    }
    // Delete columns for the original definition
    doDelete(originalColumn);
    // Signal patterns changed event to Decision Table Widget
    final BoundFactsChangedEvent pce = new BoundFactsChangedEvent(rm.getLHSBoundFacts());
    eventBus.fireEvent(pce);
    return diffs;
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VetoUpdatePatternInUseException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoUpdatePatternInUseException) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) BoundFactsChangedEvent(org.drools.workbench.screens.guided.dtable.client.widget.table.events.gwt.BoundFactsChangedEvent) BaseColumnFieldDiff(org.drools.workbench.models.guided.dtable.shared.model.BaseColumnFieldDiff) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with VetoUpdatePatternInUseException

use of org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoUpdatePatternInUseException in project drools-wb by kiegroup.

the class ConditionColumnSynchronizer method update.

@Override
public List<BaseColumnFieldDiff> update(final PatternConditionMetaData originalMetaData, final PatternConditionMetaData editedMetaData) throws VetoException {
    // Check operation is supported
    if (!(handlesUpdate(originalMetaData) && handlesUpdate(editedMetaData))) {
        return Collections.emptyList();
    }
    // Get differences between original and edited column
    final Pattern52 originalPattern = originalMetaData.getPattern();
    final Pattern52 editedPattern = editedMetaData.getPattern();
    final ConditionCol52 originalColumn = (ConditionCol52) originalMetaData.getColumn();
    final ConditionCol52 editedColumn = (ConditionCol52) editedMetaData.getColumn();
    final List<BaseColumnFieldDiff> patternDiffs = originalPattern.diff(editedPattern);
    final List<BaseColumnFieldDiff> columnDiffs = originalColumn.diff(editedColumn);
    final List<BaseColumnFieldDiff> diffs = new ArrayList<BaseColumnFieldDiff>();
    if (patternDiffs != null) {
        diffs.addAll(patternDiffs);
    }
    if (columnDiffs != null) {
        diffs.addAll(columnDiffs);
    }
    // Changes to the Pattern create the new column and remove the old column
    final boolean isNewPattern = isNewPattern(editedPattern);
    final boolean isBoundNameUpdated = BaseColumnFieldDiffImpl.hasChanged(Pattern52.FIELD_BOUND_NAME, diffs);
    final boolean isEntryPointNameUpdated = BaseColumnFieldDiffImpl.hasChanged(Pattern52.FIELD_ENTRY_POINT_NAME, diffs);
    final boolean isUpdatedCondition = BaseColumnFieldDiffImpl.hasChanged(ConditionCol52.FIELD_BINDING, diffs);
    // Check if pattern change can be applied to model
    if (isUpdatedCondition) {
        if (!isPotentialConditionDeletionSafe(originalColumn)) {
            throw new VetoUpdatePatternInUseException();
        }
    }
    if (isBoundNameUpdated) {
        if (!isPotentialPatternDeletionSafe(originalPattern)) {
            throw new VetoUpdatePatternInUseException();
        }
    }
    // Perform update
    if (isNewPattern || isBoundNameUpdated) {
        append(editedMetaData);
        copyColumnData(originalColumn, editedColumn, diffs);
        delete(originalMetaData);
        return diffs;
    }
    if (isEntryPointNameUpdated) {
        originalPattern.setEntryPointName(editedPattern.getEntryPointName());
    }
    // Changes to the Condition, but Pattern remains unchanged
    update(originalColumn, editedColumn);
    final boolean isHideUpdated = BaseColumnFieldDiffImpl.hasChanged(ConditionCol52.FIELD_HIDE_COLUMN, diffs);
    final boolean isHeaderUpdated = BaseColumnFieldDiffImpl.hasChanged(ConditionCol52.FIELD_HEADER, diffs);
    final boolean isFactTypeUpdated = BaseColumnFieldDiffImpl.hasChanged(Pattern52.FIELD_FACT_TYPE, diffs);
    final boolean isFactFieldUpdated = BaseColumnFieldDiffImpl.hasChanged(ConditionCol52.FIELD_FACT_FIELD, diffs);
    final boolean isFieldTypeUpdated = BaseColumnFieldDiffImpl.hasChanged(ConditionCol52.FIELD_FIELD_TYPE, diffs);
    final boolean isConstraintValueTypeUpdated = BaseColumnFieldDiffImpl.hasChanged(ConditionCol52.FIELD_CONSTRAINT_VALUE_TYPE, diffs);
    if (isFactTypeUpdated || isFactFieldUpdated || isFieldTypeUpdated || isConstraintValueTypeUpdated) {
        clearColumnData(originalColumn);
    } else {
        cleanColumnData(originalColumn, editedColumn, diffs);
    }
    synchroniseUpdateColumn(originalColumn);
    if (isHideUpdated) {
        setColumnVisibility(originalColumn, originalColumn.isHideColumn());
    }
    if (isHeaderUpdated) {
        setColumnHeader(originalColumn, originalColumn.getHeader());
    }
    return diffs;
}
Also used : ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) BaseColumnFieldDiff(org.drools.workbench.models.guided.dtable.shared.model.BaseColumnFieldDiff) ArrayList(java.util.ArrayList) VetoUpdatePatternInUseException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoUpdatePatternInUseException)

Example 4 with VetoUpdatePatternInUseException

use of org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoUpdatePatternInUseException in project drools-wb by kiegroup.

the class BRLConditionColumnSynchronizerTest method checkBRLFragmentConditionCannotBeUpdatedWhenBindingIsUsedInAction.

@Test
public void checkBRLFragmentConditionCannotBeUpdatedWhenBindingIsUsedInAction() throws VetoException {
    final BRLConditionColumn column = new BRLConditionColumn();
    column.setDefinition(Collections.singletonList(new FactPattern("Applicant") {

        {
            setBoundName("$a");
        }
    }));
    final BRLConditionVariableColumn columnV0 = new BRLConditionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Applicant", "age");
    column.getChildColumns().add(columnV0);
    column.setHeader("col1");
    columnV0.setHeader("col1v0");
    modelSynchronizer.appendColumn(column);
    final ActionSetFieldCol52 action = new ActionSetFieldCol52() {

        {
            setBoundName("$a");
            setFactField("age");
            setHeader("action1");
        }
    };
    modelSynchronizer.appendColumn(action);
    try {
        final BRLConditionColumn editedColumn = new BRLConditionColumn();
        editedColumn.setDefinition(Collections.singletonList(new FactPattern("Applicant") {

            {
                setBoundName("$a2");
            }
        }));
        final BRLConditionVariableColumn editedColumnV0 = new BRLConditionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Applicant", "age");
        editedColumn.getChildColumns().add(editedColumnV0);
        editedColumn.setHeader("col1");
        editedColumnV0.setHeader("col1v0");
        modelSynchronizer.updateColumn(column, editedColumn);
        fail("Deletion of the column should have been vetoed.");
    } catch (VetoUpdatePatternInUseException veto) {
    // This is expected
    } catch (VetoException veto) {
        fail("VetoUpdatePatternInUseException was expected.");
    }
    assertEquals(5, model.getExpandedColumns().size());
    assertTrue(model.getExpandedColumns().get(0) instanceof RowNumberCol52);
    assertTrue(model.getExpandedColumns().get(1) instanceof RuleNameColumn);
    assertTrue(model.getExpandedColumns().get(2) instanceof DescriptionCol52);
    assertEquals(columnV0, model.getExpandedColumns().get(3));
    assertEquals(action, model.getExpandedColumns().get(4));
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) VetoException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoException) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) VetoUpdatePatternInUseException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoUpdatePatternInUseException) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) ActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52) RuleNameColumn(org.drools.workbench.models.guided.dtable.shared.model.RuleNameColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 5 with VetoUpdatePatternInUseException

use of org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoUpdatePatternInUseException in project drools-wb by kiegroup.

the class ConditionColumnSynchronizerTest method checkConditionCannotBeUpdatedWhenBindingIsUsedInAction.

@Test
public void checkConditionCannotBeUpdatedWhenBindingIsUsedInAction() throws VetoException {
    final Pattern52 pattern = boundApplicantPattern("$a");
    final ConditionCol52 condition = ageEqualsCondition();
    final ActionCol52 action = actionUpdatePattern("$a");
    modelSynchronizer.appendColumn(pattern, condition);
    modelSynchronizer.appendColumn(action);
    try {
        final Pattern52 editedPattern = boundApplicantPattern("$a2");
        final ConditionCol52 editedCondition = nameEqualsCondition();
        modelSynchronizer.updateColumn(pattern, condition, editedPattern, editedCondition);
        fail("Update of the column should have been vetoed.");
    } catch (VetoUpdatePatternInUseException veto) {
    // This is expected
    } catch (VetoException veto) {
        fail("VetoUpdatePatternInUseException was expected.");
    }
    assertEquals(5, model.getExpandedColumns().size());
    assertTrue(model.getExpandedColumns().get(0) instanceof RowNumberCol52);
    assertTrue(model.getExpandedColumns().get(1) instanceof RuleNameColumn);
    assertTrue(model.getExpandedColumns().get(2) instanceof DescriptionCol52);
    assertEquals(condition, model.getExpandedColumns().get(3));
    assertEquals(action, model.getExpandedColumns().get(4));
}
Also used : VetoException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoException) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) VetoUpdatePatternInUseException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoUpdatePatternInUseException) RuleNameColumn(org.drools.workbench.models.guided.dtable.shared.model.RuleNameColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Aggregations

VetoUpdatePatternInUseException (org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoUpdatePatternInUseException)6 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)4 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)4 RuleNameColumn (org.drools.workbench.models.guided.dtable.shared.model.RuleNameColumn)4 VetoException (org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoException)4 Test (org.junit.Test)4 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)3 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)3 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)3 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)3 ArrayList (java.util.ArrayList)2 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)2 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)2 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)2 BaseColumnFieldDiff (org.drools.workbench.models.guided.dtable.shared.model.BaseColumnFieldDiff)2 HashMap (java.util.HashMap)1 List (java.util.List)1 ActionCallMethod (org.drools.workbench.models.datamodel.rule.ActionCallMethod)1 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)1 FieldConstraint (org.drools.workbench.models.datamodel.rule.FieldConstraint)1