Search in sources :

Example 1 with VetoDeletePatternInUseException

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

the class ConditionColumnSynchronizerTest method checkConditionCannotBeDeletedWhenFieldBindingIsUsedInAction.

@Test
public void checkConditionCannotBeDeletedWhenFieldBindingIsUsedInAction() throws VetoException {
    final Pattern52 pattern = boundApplicantPattern("$a");
    final ConditionCol52 condition = ageEqualsCondition();
    condition.setBinding("$age");
    final BRLActionColumn action = actionCallMethod("$age");
    modelSynchronizer.appendColumn(pattern, condition);
    modelSynchronizer.appendColumn(action);
    try {
        modelSynchronizer.deleteColumn(condition);
        fail("Deletion of the column should have been vetoed.");
    } catch (VetoDeletePatternInUseException veto) {
    // This is expected
    } catch (VetoException veto) {
        fail("VetoDeletePatternInUseException 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.getChildColumns().get(0), 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) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) RuleNameColumn(org.drools.workbench.models.guided.dtable.shared.model.RuleNameColumn) VetoDeletePatternInUseException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoDeletePatternInUseException) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 2 with VetoDeletePatternInUseException

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

the class BRLConditionColumnSynchronizerTest method checkBRLFragmentConditionCannotBeDeletedWithAction.

@Test
public void checkBRLFragmentConditionCannotBeDeletedWithAction() 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 {
        modelSynchronizer.deleteColumn(column);
        fail("Deletion of the column should have been vetoed.");
    } catch (VetoDeletePatternInUseException veto) {
    // This is expected
    } catch (VetoException veto) {
        fail("VetoDeletePatternInUseException 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) 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) VetoDeletePatternInUseException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoDeletePatternInUseException) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 3 with VetoDeletePatternInUseException

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

the class ColumnManagementView method renderColumn.

HorizontalPanel renderColumn(final ActionCol52 actionColumn) {
    HorizontalPanel action = newHorizontalPanel();
    final ColumnLabelWidget actionLabel = makeColumnLabel(actionColumn);
    action.add(actionLabel);
    final FlowPanel buttons = new FlowPanel() {

        {
            add(editAnchor((clickEvent) -> {
                presenter.getActiveDecisionTable().ifPresent(dt -> dt.editAction(actionColumn));
            }));
            if (presenter.isActiveDecisionTableEditable()) {
                add(deleteAnchor(actionColumn.getHeader(), () -> {
                    try {
                        final Optional<GuidedDecisionTableView.Presenter> dtPresenter = presenter.getActiveDecisionTable();
                        if (dtPresenter.isPresent()) {
                            dtPresenter.get().deleteColumn(actionColumn);
                        }
                    } catch (VetoDeletePatternInUseException veto) {
                        presenter.getView().showUnableToDeleteColumnMessage(actionColumn);
                    } catch (VetoException veto) {
                        presenter.getView().showGenericVetoMessage();
                    }
                }));
            }
        }
    };
    action.add(buttons);
    return action;
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) ManagedInstance(org.jboss.errai.ioc.client.api.ManagedInstance) GuidedDecisionTableModellerView(org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableModellerView) ColumnUtilities(org.drools.workbench.screens.guided.dtable.client.widget.table.utilities.ColumnUtilities) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ArrayList(java.util.ArrayList) VetoDeletePatternInUseException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoDeletePatternInUseException) Inject(javax.inject.Inject) VetoException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoException) List(java.util.List) Widget(com.google.gwt.user.client.ui.Widget) FlowPanel(com.google.gwt.user.client.ui.FlowPanel) Command(com.google.gwt.user.client.Command) Dependent(javax.enterprise.context.Dependent) Label(com.google.gwt.user.client.ui.Label) Map(java.util.Map) HorizontalPanel(com.google.gwt.user.client.ui.HorizontalPanel) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) GuidedDecisionTableView(org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableView) Optional(java.util.Optional) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) VetoException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoException) Optional(java.util.Optional) HorizontalPanel(com.google.gwt.user.client.ui.HorizontalPanel) FlowPanel(com.google.gwt.user.client.ui.FlowPanel) GuidedDecisionTableView(org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableView) VetoDeletePatternInUseException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoDeletePatternInUseException)

Example 4 with VetoDeletePatternInUseException

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

the class BRLConditionColumnSynchronizer method delete.

@Override
public void delete(final ColumnMetaData metaData) throws VetoException {
    // Check operation is supported
    if (!handlesDelete(metaData)) {
        return;
    }
    if (metaData.getColumn() instanceof BRLConditionColumn) {
        final BRLConditionColumn column = (BRLConditionColumn) metaData.getColumn();
        // If Pattern has been updated and there was only one child column then original Pattern will be deleted
        final Set<String> bindings = getPatternBindings(column);
        for (String binding : bindings) {
            if (rm.isBoundFactUsed(binding)) {
                throw new VetoDeletePatternInUseException();
            }
        }
        doDelete(column);
    } else if (metaData.getColumn() instanceof BRLConditionVariableColumn) {
        doDelete((BRLConditionVariableColumn) metaData.getColumn());
    }
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) VetoDeletePatternInUseException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoDeletePatternInUseException)

Example 5 with VetoDeletePatternInUseException

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

the class ConditionColumnSynchronizer method delete.

@Override
public void delete(final ColumnMetaData metaData) throws VetoException {
    // Check operation is supported
    if (!handlesDelete(metaData)) {
        return;
    }
    final ConditionCol52 column = (ConditionCol52) metaData.getColumn();
    final int columnIndex = model.getExpandedColumns().indexOf(column);
    final Pattern52 pattern = model.getPattern(column);
    // Check if pattern change can be applied to model
    if (!isPotentialConditionDeletionSafe(column)) {
        throw new VetoDeletePatternInUseException();
    }
    if (!isPotentialPatternDeletionSafe(pattern)) {
        throw new VetoDeletePatternInUseException();
    }
    // Perform deletion
    pattern.getChildColumns().remove(column);
    // Remove pattern if it contains zero conditions
    if (pattern.getChildColumns().isEmpty()) {
        model.getConditions().remove(pattern);
        // Signal patterns changed event to Decision Table Widget
        final BoundFactsChangedEvent bfce = new BoundFactsChangedEvent(rm.getLHSBoundFacts());
        eventBus.fireEvent(bfce);
    }
    synchroniseDeleteColumn(columnIndex);
}
Also used : ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) BoundFactsChangedEvent(org.drools.workbench.screens.guided.dtable.client.widget.table.events.gwt.BoundFactsChangedEvent) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) VetoDeletePatternInUseException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoDeletePatternInUseException)

Aggregations

VetoDeletePatternInUseException (org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoDeletePatternInUseException)7 VetoException (org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoException)5 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)4 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)4 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)4 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)4 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)4 RuleNameColumn (org.drools.workbench.models.guided.dtable.shared.model.RuleNameColumn)4 Test (org.junit.Test)4 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)3 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)2 ActionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionCol52)2 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 Command (com.google.gwt.user.client.Command)1 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)1 HorizontalPanel (com.google.gwt.user.client.ui.HorizontalPanel)1 Label (com.google.gwt.user.client.ui.Label)1 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)1 Widget (com.google.gwt.user.client.ui.Widget)1