Search in sources :

Example 6 with MetadataCol52

use of org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52 in project drools by kiegroup.

the class GuidedDTDRLPersistenceResolvedHitPolicyTest method prioritiesSet.

@Test
public void prioritiesSet() throws Exception {
    final MetadataCol52 metadataCol = new MetadataCol52();
    metadataCol.setMetadata(GuidedDecisionTable52.HitPolicy.RESOLVED_HIT_METADATA_NAME);
    dtable.getMetadataCols().add(metadataCol);
    int indexOf = dtable.getExpandedColumns().indexOf(metadataCol);
    int index = 0;
    for (final List<DTCellValue52> row : dtable.getData()) {
        final DTCellValue52 element = new DTCellValue52();
        element.setStringValue(Integer.toString(index++));
        row.add(indexOf, element);
    }
    final String drl = GuidedDTDRLPersistence.getInstance().marshal(dtable);
    assertContainsLinesInOrder(drl, "rule \"Row 1 Resolved hit policy table\"", "activation-group \"resolved-hit-policy-group Resolved hit policy table\"", "salience 0", "rule \"Row 2 Resolved hit policy table\"", "activation-group \"resolved-hit-policy-group Resolved hit policy table\"", "salience 1", "rule \"Row 3 Resolved hit policy table\"", "activation-group \"resolved-hit-policy-group Resolved hit policy table\"", "salience 2");
}
Also used : MetadataCol52(org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) Test(org.junit.Test)

Example 7 with MetadataCol52

use of org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52 in project drools by kiegroup.

the class GuidedDTDRLPersistenceTest method testLHS.

@Test
public void testLHS() {
    GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
    String[] row = new String[] { "1", "desc", "a", "mike", "33 + 1", "age > 6", "stilton" };
    String[][] data = new String[1][];
    data[0] = row;
    List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
    List<CompositeColumn<? extends BaseColumn>> allPatterns = new ArrayList<CompositeColumn<? extends BaseColumn>>();
    allColumns.add(new RowNumberCol52());
    allColumns.add(new DescriptionCol52());
    allColumns.add(new MetadataCol52());
    Pattern52 p1 = new Pattern52();
    p1.setBoundName("p1");
    p1.setFactType("Person");
    allPatterns.add(p1);
    ConditionCol52 col = new ConditionCol52();
    col.setFactField("name");
    col.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    col.setOperator("==");
    p1.getChildColumns().add(col);
    allColumns.add(col);
    ConditionCol52 col2 = new ConditionCol52();
    col2.setFactField("age");
    col2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_RET_VALUE);
    col2.setOperator("<");
    p1.getChildColumns().add(col2);
    allColumns.add(col2);
    ConditionCol52 col3 = new ConditionCol52();
    col3.setConstraintValueType(BaseSingleFieldConstraint.TYPE_PREDICATE);
    p1.getChildColumns().add(col3);
    allColumns.add(col3);
    Pattern52 p2 = new Pattern52();
    p2.setBoundName("c");
    p2.setFactType("Cheese");
    allPatterns.add(p2);
    ConditionCol52 col4 = new ConditionCol52();
    col4.setFactField("type");
    col4.setOperator("==");
    col4.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    p2.getChildColumns().add(col4);
    allColumns.add(col4);
    RuleModel rm = new RuleModel();
    List<DTCellValue52> rowData = DataUtilities.makeDataRowList(row);
    TemplateDataProvider rowDataProvider = new GuidedDTTemplateDataProvider(allColumns, rowData);
    p.doConditions(allColumns, allPatterns, rowDataProvider, rowData, DataUtilities.makeDataLists(data), rm);
    assertEquals(2, rm.lhs.length);
    assertEquals("Person", ((FactPattern) rm.lhs[0]).getFactType());
    assertEquals("p1", ((FactPattern) rm.lhs[0]).getBoundName());
    assertEquals("Cheese", ((FactPattern) rm.lhs[1]).getFactType());
    assertEquals("c", ((FactPattern) rm.lhs[1]).getBoundName());
    // examine the first pattern
    FactPattern person = (FactPattern) rm.lhs[0];
    assertEquals(3, person.getConstraintList().getConstraints().length);
    SingleFieldConstraint cons = (SingleFieldConstraint) person.getConstraint(0);
    assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, cons.getConstraintValueType());
    assertEquals("name", cons.getFieldName());
    assertEquals("==", cons.getOperator());
    assertEquals("mike", cons.getValue());
    cons = (SingleFieldConstraint) person.getConstraint(1);
    assertEquals(BaseSingleFieldConstraint.TYPE_RET_VALUE, cons.getConstraintValueType());
    assertEquals("age", cons.getFieldName());
    assertEquals("<", cons.getOperator());
    assertEquals("33 + 1", cons.getValue());
    cons = (SingleFieldConstraint) person.getConstraint(2);
    assertEquals(BaseSingleFieldConstraint.TYPE_PREDICATE, cons.getConstraintValueType());
    assertEquals("age > 6", cons.getValue());
    // examine the second pattern
    FactPattern cheese = (FactPattern) rm.lhs[1];
    assertEquals(1, cheese.getConstraintList().getConstraints().length);
    cons = (SingleFieldConstraint) cheese.getConstraint(0);
    assertEquals("type", cons.getFieldName());
    assertEquals("==", cons.getOperator());
    assertEquals("stilton", cons.getValue());
    assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, cons.getConstraintValueType());
}
Also used : ArrayList(java.util.ArrayList) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) CompositeColumn(org.drools.workbench.models.guided.dtable.shared.model.CompositeColumn) MetadataCol52(org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) LimitedEntryConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) TemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.TemplateDataProvider) Test(org.junit.Test)

Example 8 with MetadataCol52

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

the class ColumnsPagePresenter method refreshMetaDataWidget.

void refreshMetaDataWidget(final List<MetadataCol52> metaDataColumns) {
    final Optional<GuidedDecisionTableModellerView.Presenter> optionalModeller = Optional.ofNullable(getModeller());
    final VerticalPanel metaDataWidget = getMetaDataWidget();
    if (!optionalModeller.isPresent()) {
        return;
    }
    final GuidedDecisionTableModellerView.Presenter modeller = optionalModeller.get();
    metaDataWidget.clear();
    if (metaDataColumns.isEmpty()) {
        metaDataWidget.add(blankSlate());
        return;
    }
    for (MetadataCol52 metaDataColumn : metaDataColumns) {
        metaDataWidget.add(makeMetaDataWidget(modeller, metaDataColumn));
    }
}
Also used : MetadataCol52(org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) GuidedDecisionTableModellerView(org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableModellerView)

Example 9 with MetadataCol52

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

the class GuidedDecisionTablePresenter method onDeleteSelectedColumns.

@Override
public void onDeleteSelectedColumns() {
    if (isReadOnly()) {
        return;
    }
    final Set<Integer> selectedColumnIndexes = getSelectedColumnIndexes();
    final Set<BaseColumn> columnsToDelete = new HashSet<>();
    for (int selectedColumnIndex : selectedColumnIndexes) {
        final int columnIndex = findUiColumnIndex(selectedColumnIndex);
        final BaseColumn column = model.getExpandedColumns().get(columnIndex);
        if (!(column instanceof RowNumberCol52 || column instanceof DescriptionCol52)) {
            columnsToDelete.add(column);
        }
    }
    for (BaseColumn columnToDelete : columnsToDelete) {
        if (columnToDelete instanceof AttributeCol52) {
            try {
                deleteColumn((AttributeCol52) columnToDelete);
            } catch (VetoException veto) {
                getModellerPresenter().getView().showGenericVetoMessage();
            }
        } else if (columnToDelete instanceof MetadataCol52) {
            try {
                deleteColumn((MetadataCol52) columnToDelete);
            } catch (VetoException veto) {
                getModellerPresenter().getView().showGenericVetoMessage();
            }
        } else if (columnToDelete instanceof ConditionCol52) {
            try {
                deleteColumn((ConditionCol52) columnToDelete);
            } catch (VetoException veto) {
                getModellerPresenter().getView().showUnableToDeleteColumnMessage((ConditionCol52) columnsToDelete);
            }
        } else if (columnToDelete instanceof ActionCol52) {
            try {
                deleteColumn((ActionCol52) columnToDelete);
            } catch (VetoException veto) {
                getModellerPresenter().getView().showUnableToDeleteColumnMessage((ActionCol52) columnsToDelete);
            }
        }
    }
}
Also used : ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) AttributeCol52(org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52) VetoException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoException) MetadataCol52(org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) HashSet(java.util.HashSet) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)

Example 10 with MetadataCol52

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

the class GuidedDecisionTableTheme method getModelColumnType.

ModelColumnType getModelColumnType(final GridColumn<?> uiColumn) {
    final int uiColumnIndex = uiModel.getColumns().indexOf(uiColumn);
    final BaseColumn modelColumn = model.getExpandedColumns().get(uiColumnIndex);
    if (modelColumn instanceof RowNumberCol52) {
        return ModelColumnType.ROW_NUMBER;
    } else if (modelColumn instanceof DescriptionCol52) {
        return ModelColumnType.DESCRIPTION;
    } else if (modelColumn instanceof MetadataCol52) {
        return ModelColumnType.METADATA;
    } else if (modelColumn instanceof AttributeCol52) {
        return ModelColumnType.ATTRIBUTE;
    } else if (modelColumn instanceof ConditionCol52) {
        return ModelColumnType.CONDITION;
    } else if (modelColumn instanceof ActionCol52) {
        return ModelColumnType.ACTION;
    }
    // proof rendering than throw an exception.
    return ModelColumnType.UNKNOWN;
}
Also used : MetadataCol52(org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52) AttributeCol52(org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)

Aggregations

MetadataCol52 (org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52)67 Test (org.junit.Test)52 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)18 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)12 ArrayList (java.util.ArrayList)11 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)10 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)10 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)9 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)9 AttributeCol52 (org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52)8 DecisionTableSelectionsChangedEvent (org.drools.workbench.screens.guided.dtable.client.widget.table.events.cdi.DecisionTableSelectionsChangedEvent)8 DecisionTableSelectedEvent (org.drools.workbench.screens.guided.dtable.client.widget.table.events.cdi.DecisionTableSelectedEvent)7 ActionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionCol52)6 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)6 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)5 GuidedDecisionTableView (org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableView)5 GuidedDTTemplateDataProvider (org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider)4 TemplateDataProvider (org.drools.workbench.models.guided.dtable.backend.util.TemplateDataProvider)4 BaseColumnFieldDiff (org.drools.workbench.models.guided.dtable.shared.model.BaseColumnFieldDiff)4 CompositeColumn (org.drools.workbench.models.guided.dtable.shared.model.CompositeColumn)4