Search in sources :

Example 51 with BRLConditionColumn

use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn 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) 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 52 with BRLConditionColumn

use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn in project drools-wb by kiegroup.

the class BRLConditionColumnSynchronizer method append.

@Override
public void append(final ColumnMetaData metaData) throws VetoException {
    // Check operation is supported
    if (!handlesAppend(metaData)) {
        return;
    }
    final BRLConditionColumn column = (BRLConditionColumn) metaData.getColumn();
    model.getConditions().add(column);
    for (BRLConditionVariableColumn childModelColumn : column.getChildColumns()) {
        synchroniseAppendColumn(childModelColumn);
    }
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)

Example 53 with BRLConditionColumn

use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn in project drools-wb by kiegroup.

the class BRLConditionColumnSynchronizer method isBRLFragment.

private boolean isBRLFragment(final List<? extends MetaData> metaData) {
    if (!metaData.stream().allMatch((c) -> (c instanceof MoveColumnToMetaData))) {
        return false;
    }
    if (!metaData.stream().allMatch((c) -> ((MoveColumnToMetaData) c).getColumn() instanceof BRLConditionVariableColumn)) {
        return false;
    }
    final MoveColumnToMetaData md = (MoveColumnToMetaData) metaData.get(0);
    final BRLConditionVariableColumn srcModelColumn = (BRLConditionVariableColumn) md.getColumn();
    final BRLConditionColumn srcModelPattern = model.getBRLColumn(srcModelColumn);
    return srcModelPattern.getChildColumns().size() == metaData.size();
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) Set(java.util.Set) HashMap(java.util.HashMap) BaseColumnFieldDiff(org.drools.workbench.models.guided.dtable.shared.model.BaseColumnFieldDiff) ArrayList(java.util.ArrayList) ModelSynchronizer(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer) VetoDeletePatternInUseException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoDeletePatternInUseException) HashSet(java.util.HashSet) VetoException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoException) List(java.util.List) BoundFactsChangedEvent(org.drools.workbench.screens.guided.dtable.client.widget.table.events.gwt.BoundFactsChangedEvent) Dependent(javax.enterprise.context.Dependent) Map(java.util.Map) IPattern(org.drools.workbench.models.datamodel.rule.IPattern) VetoUpdatePatternInUseException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoUpdatePatternInUseException) Collections(java.util.Collections) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)

Example 54 with BRLConditionColumn

use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn 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;
    }
    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);
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) VetoDeletePatternInUseException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoDeletePatternInUseException)

Example 55 with BRLConditionColumn

use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn in project drools-wb by kiegroup.

the class BRLConditionColumnSynchronizerTest method testAppend2.

@Test
public void testAppend2() throws VetoException {
    // Single Column, multiple variables
    final BRLConditionColumn column = new BRLConditionColumn();
    final BRLConditionVariableColumn columnV0 = new BRLConditionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Applicant", "age");
    final BRLConditionVariableColumn columnV1 = new BRLConditionVariableColumn("$name", DataType.TYPE_STRING, "Applicant", "name");
    column.getChildColumns().add(columnV0);
    column.getChildColumns().add(columnV1);
    column.setHeader("col1");
    columnV0.setHeader("col1v0");
    columnV1.setHeader("col1v1");
    modelSynchronizer.appendColumn(column);
    assertEquals(4, model.getExpandedColumns().size());
    assertEquals(1, model.getConditions().size());
    assertEquals(4, uiModel.getColumns().size());
    assertTrue(uiModel.getColumns().get(2) instanceof IntegerUiColumn);
    assertTrue(uiModel.getColumns().get(3) instanceof StringUiColumn);
    assertEquals(2, uiModel.getColumns().get(2).getHeaderMetaData().size());
    assertEquals("$age", uiModel.getColumns().get(2).getHeaderMetaData().get(1).getTitle());
    assertEquals(2, uiModel.getColumns().get(3).getHeaderMetaData().size());
    assertEquals("$name", uiModel.getColumns().get(3).getHeaderMetaData().get(1).getTitle());
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) StringUiColumn(org.drools.workbench.screens.guided.dtable.client.widget.table.columns.StringUiColumn) IntegerUiColumn(org.drools.workbench.screens.guided.dtable.client.widget.table.columns.IntegerUiColumn) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) Test(org.junit.Test)

Aggregations

BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)73 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)53 Test (org.junit.Test)49 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)30 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)26 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)26 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)24 ArrayList (java.util.ArrayList)22 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)22 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)22 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)21 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)17 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)16 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)15 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)14 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)14 IAction (org.drools.workbench.models.datamodel.rule.IAction)11 IOException (java.io.IOException)10 InputStream (java.io.InputStream)10 ExcelParser (org.drools.decisiontable.parser.xls.ExcelParser)10