Search in sources :

Example 1 with Attribute

use of org.drools.workbench.models.guided.scorecard.shared.Attribute in project drools by kiegroup.

the class Helper method createGuidedScoreCard.

public static ScoreCardModel createGuidedScoreCard() {
    final ScoreCardModel model = new ScoreCardModel();
    model.setName("test");
    model.setPackageName("org.drools.workbench.models.guided.scorecard.backend.test1");
    model.setReasonCodesAlgorithm("none");
    model.setBaselineScore(0.0);
    model.setInitialScore(0.0);
    model.setFactName("org.drools.workbench.models.guided.scorecard.backend.test1.Applicant");
    model.setFieldName("score");
    model.setUseReasonCodes(false);
    model.setReasonCodeField("");
    final Characteristic c = new Characteristic();
    c.setName("c1");
    c.setFact("org.drools.workbench.models.guided.scorecard.backend.test1.ApplicantAttribute");
    c.setDataType("int");
    c.setField("attribute");
    c.setBaselineScore(0.0);
    c.setReasonCode("");
    final Attribute a = new Attribute();
    a.setOperator("=");
    a.setValue("10");
    a.setPartialScore(0.1);
    a.setReasonCode("");
    c.getAttributes().add(a);
    model.getCharacteristics().add(c);
    return model;
}
Also used : ScoreCardModel(org.drools.workbench.models.guided.scorecard.shared.ScoreCardModel) Attribute(org.drools.workbench.models.guided.scorecard.shared.Attribute) Characteristic(org.drools.workbench.models.guided.scorecard.shared.Characteristic)

Example 2 with Attribute

use of org.drools.workbench.models.guided.scorecard.shared.Attribute in project drools-wb by kiegroup.

the class GuidedScoreCardEditor method addAttribute.

private void addAttribute(final FlexTable selectedTable, final Attribute attribute) {
    // Disable the fact & field dropdowns
    ((ListBox) selectedTable.getWidget(2, 0)).setEnabled(false);
    // ( (ListBox) selectedTable.getWidget( 2, 1 ) ).setEnabled( false );
    final ListBox edd = ((ListBox) selectedTable.getWidget(2, 1));
    edd.setEnabled(false);
    int selectedIndex = edd.getSelectedIndex() > -1 ? edd.getSelectedIndex() : 0;
    String field = edd.getValue(selectedIndex);
    // field is in the format 'fieldName : datatype';
    // the actual name
    String fieldName = field.substring(0, field.indexOf(":")).trim();
    // the data type
    String dataType = field.substring(field.indexOf(":") + 1).trim();
    // enum values
    final ListBox factDD = (ListBox) selectedTable.getWidget(2, 0);
    String factName = factDD.getValue(factDD.getSelectedIndex());
    boolean enumColumn = oracle.hasEnums(factName, fieldName);
    final List<String> operators = new ArrayList<String>();
    if ("String".equalsIgnoreCase(dataType)) {
        if (enumColumn) {
            operators.addAll(Arrays.asList(enumStringOperators));
        } else {
            operators.addAll(Arrays.asList(stringOperators));
        }
    } else if ("boolean".equalsIgnoreCase(dataType)) {
        operators.addAll(Arrays.asList(booleanOperators));
    } else {
        operators.addAll(Arrays.asList(numericOperators));
    }
    if (characteristicsAttrMap.get(selectedTable) == null) {
        final Characteristic characteristic = getCharacteristicFromTable(selectedTable);
        // first attribute, construct and add the table
        VerticalPanel vPanel = characteristicsAttrPanelMap.get(selectedTable);
        vPanel.add(addAttributeCellTable(selectedTable, characteristic, enumColumn, dataType, operators));
        characteristicsAttrPanelMap.remove(selectedTable);
    }
    Attribute newAttribute = null;
    if (attribute != null) {
        characteristicsAttrMap.get(selectedTable).getList().add(attribute);
    } else {
        newAttribute = new Attribute();
        characteristicsAttrMap.get(selectedTable).getList().add(newAttribute);
        newAttribute.setOperator(operators.get(0));
    }
    characteristicsAttrMap.get(selectedTable).refresh();
    if ("boolean".equalsIgnoreCase(dataType)) {
        ((Button) selectedTable.getWidget(0, 3)).setEnabled(characteristicsAttrMap.get(selectedTable).getList().size() != 2);
        if (newAttribute != null) {
            newAttribute.setValue(GuidedScoreCardConstants.INSTANCE.notApplicable());
        }
    }
}
Also used : VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) Attribute(org.drools.workbench.models.guided.scorecard.shared.Attribute) Button(org.gwtbootstrap3.client.ui.Button) Characteristic(org.drools.workbench.models.guided.scorecard.shared.Characteristic) ArrayList(java.util.ArrayList) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Example 3 with Attribute

use of org.drools.workbench.models.guided.scorecard.shared.Attribute in project drools-wb by kiegroup.

the class GuidedScoreCardEditorServiceImpl method doValidation.

private List<ValidationMessage> doValidation(final ScoreCardModel model) {
    final List<ValidationMessage> results = new ArrayList<ValidationMessage>();
    if (isBlank(model.getFactName())) {
        results.add(makeValidationMessages("Fact Name is empty."));
    }
    if (isBlank(model.getFieldName())) {
        results.add(makeValidationMessages("Resultant Score Field is empty."));
    }
    if (model.getCharacteristics().size() == 0) {
        results.add(makeValidationMessages("No Characteristics Found."));
    }
    int ctr = 1;
    for (final Characteristic c : model.getCharacteristics()) {
        String characteristicName = "Characteristic ('#" + ctr + "')";
        if (isBlank(c.getName())) {
            results.add(makeValidationMessages("Characteristic Name '" + characteristicName + "' is empty."));
        } else {
            characteristicName = "Characteristic ('" + c.getName() + "')";
        }
        if (isBlank(c.getFact())) {
            results.add(makeValidationMessages("Characteristic Name '" + characteristicName + "'. Fact is empty."));
        }
        if (isBlank(c.getField())) {
            results.add(makeValidationMessages("Characteristic Name '" + characteristicName + "'. Characteristic Field is empty."));
        } else if (isBlank(c.getDataType())) {
            results.add(makeValidationMessages("Characteristic Name '" + characteristicName + "'. Internal Error (missing datatype)."));
        }
        if (c.getAttributes().size() == 0) {
            results.add(makeValidationMessages("Characteristic Name '" + characteristicName + "'. No Attributes Found."));
        }
        if (model.isUseReasonCodes()) {
            if (isBlank(model.getReasonCodeField())) {
                results.add(makeValidationMessages("Characteristic Name '" + characteristicName + "'. Resultant Reason Codes Field is empty."));
            }
            if (!"none".equalsIgnoreCase(model.getReasonCodesAlgorithm())) {
                results.add(makeValidationMessages("Characteristic Name '" + characteristicName + "'. Baseline Score is not specified."));
            }
        }
        int attrCtr = 1;
        for (final Attribute attribute : c.getAttributes()) {
            final String attributeName = "Attribute ('#" + attrCtr + "')";
            if (isBlank(attribute.getOperator())) {
                results.add(makeValidationMessages("Attribute Name '" + attributeName + "'. Attribute Operator is empty."));
            }
            if (isBlank(attribute.getValue())) {
                results.add(makeValidationMessages("Attribute Name '" + attributeName + "'. Attribute Value is empty."));
            }
            if (model.isUseReasonCodes()) {
                if (isBlank(c.getReasonCode())) {
                    if (isBlank(attribute.getReasonCode())) {
                        results.add(makeValidationMessages("Attribute Name '" + attributeName + "'. Reason Code must be set at either attribute or characteristic."));
                    }
                }
            }
            attrCtr++;
        }
        ctr++;
    }
    return results;
}
Also used : ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) Attribute(org.drools.workbench.models.guided.scorecard.shared.Attribute) Characteristic(org.drools.workbench.models.guided.scorecard.shared.Characteristic) ArrayList(java.util.ArrayList)

Example 4 with Attribute

use of org.drools.workbench.models.guided.scorecard.shared.Attribute in project drools by kiegroup.

the class GuidedScoreCardDRLPersistenceTest method testBasicModel.

@Test
public void testBasicModel() {
    final ScoreCardModel model = new ScoreCardModel();
    model.setName("test");
    model.setPackageName("org.drools.workbench.models.guided.scorecard.backend");
    model.getImports().addImport(new Import("org.drools.workbench.models.guided.scorecard.backend.test1.Applicant"));
    model.setReasonCodesAlgorithm("none");
    model.setBaselineScore(0.0);
    model.setInitialScore(0.0);
    model.setFactName("org.drools.workbench.models.guided.scorecard.backend.test1.Applicant");
    model.setFieldName("score");
    model.setUseReasonCodes(false);
    model.setReasonCodeField("");
    final Characteristic c = new Characteristic();
    c.setName("c1");
    c.setFact("org.drools.workbench.models.guided.scorecard.backend.test1.Applicant");
    c.setDataType("Double");
    c.setField("age");
    c.setBaselineScore(0.0);
    c.setReasonCode("");
    final Attribute a = new Attribute();
    a.setOperator("=");
    a.setValue("10");
    a.setPartialScore(0.1);
    a.setReasonCode("");
    c.getAttributes().add(a);
    model.getCharacteristics().add(c);
    final String drl1 = GuidedScoreCardDRLPersistence.marshal(model);
    assertNotNull(drl1);
    final String drl2 = GuidedScoreCardDRLPersistence.marshal(model);
    assertNotNull(drl2);
}
Also used : Import(org.kie.soup.project.datamodel.imports.Import) ScoreCardModel(org.drools.workbench.models.guided.scorecard.shared.ScoreCardModel) Attribute(org.drools.workbench.models.guided.scorecard.shared.Attribute) Characteristic(org.drools.workbench.models.guided.scorecard.shared.Characteristic) Test(org.junit.Test)

Example 5 with Attribute

use of org.drools.workbench.models.guided.scorecard.shared.Attribute in project drools-wb by kiegroup.

the class GuidedScoreCardEditor method addAttributeCellTable.

private Widget addAttributeCellTable(final FlexTable cGrid, final Characteristic characteristic, final boolean enumColumn, final String dataType, final List<String> operators) {
    String[] enumValues = null;
    if (characteristic != null) {
        // enum values
        if (enumColumn) {
            String factName = characteristic.getFact();
            String fieldName = characteristic.getField();
            enumValues = oracle.getEnumValues(factName, fieldName);
        }
    }
    final CellTable<Attribute> attributeCellTable = new CellTable<Attribute>();
    // Operators column
    final DynamicSelectionCell categoryCell = new DynamicSelectionCell(operators);
    final Column<Attribute, String> operatorColumn = new Column<Attribute, String>(categoryCell) {

        public String getValue(final Attribute object) {
            return object.getOperator();
        }
    };
    operatorColumn.setFieldUpdater(new FieldUpdater<Attribute, String>() {

        public void update(int index, Attribute object, String value) {
            object.setOperator(value);
            attributeCellTable.redraw();
        }
    });
    // Value column
    Column<Attribute, String> valueColumn = null;
    if (enumValues != null && enumValues.length > 0) {
        valueColumn = new Column<Attribute, String>(new DynamicSelectionCell(Arrays.asList(enumValues))) {

            public String getValue(final Attribute object) {
                return object.getValue();
            }
        };
        valueColumn.setFieldUpdater(new FieldUpdater<Attribute, String>() {

            public void update(int index, Attribute object, String value) {
                object.setValue(value);
                attributeCellTable.redraw();
            }
        });
    }
    if (valueColumn == null) {
        valueColumn = new Column<Attribute, String>(new CustomEditTextCell()) {

            public String getValue(final Attribute attribute) {
                return attribute.getValue();
            }
        };
        valueColumn.setFieldUpdater(new FieldUpdater<Attribute, String>() {

            public void update(int index, Attribute object, String value) {
                object.setValue(value);
                attributeCellTable.redraw();
            }
        });
    }
    // Partial Score column
    final EditTextCell partialScoreCell = new EditTextCell();
    final Column<Attribute, String> partialScoreColumn = new Column<Attribute, String>(partialScoreCell) {

        public String getValue(final Attribute attribute) {
            return "" + attribute.getPartialScore();
        }
    };
    partialScoreColumn.setFieldUpdater(new FieldUpdater<Attribute, String>() {

        public void update(int index, Attribute object, String value) {
            try {
                double d = Double.parseDouble(value);
                object.setPartialScore(d);
            } catch (Exception e1) {
                partialScoreCell.clearViewData(object);
            }
            attributeCellTable.redraw();
        }
    });
    // Reason Code column
    final Column<Attribute, String> reasonCodeColumn = new Column<Attribute, String>(new EditTextCell()) {

        public String getValue(final Attribute attribute) {
            return attribute.getReasonCode();
        }
    };
    reasonCodeColumn.setFieldUpdater(new FieldUpdater<Attribute, String>() {

        public void update(int index, Attribute object, String value) {
            object.setReasonCode(value);
            attributeCellTable.redraw();
        }
    });
    final ActionCell.Delegate<Attribute> delegate = new ActionCell.Delegate<Attribute>() {

        public void execute(final Attribute attribute) {
            if (Window.confirm(GuidedScoreCardConstants.INSTANCE.promptDeleteAttribute())) {
                final List<Attribute> list = characteristicsAttrMap.get(cGrid).getList();
                list.remove(attribute);
                if ("boolean".equalsIgnoreCase(dataType)) {
                    ((Button) cGrid.getWidget(0, 3)).setEnabled(list.size() != 2);
                }
                attributeCellTable.redraw();
            }
        }
    };
    final Cell<Attribute> actionCell = new ActionCell<Attribute>(GuidedScoreCardConstants.INSTANCE.remove(), delegate);
    final Column<Attribute, String> actionColumn = new IdentityColumn(actionCell);
    // Add the columns.
    attributeCellTable.addColumn(operatorColumn, GuidedScoreCardConstants.INSTANCE.operator());
    attributeCellTable.addColumn(valueColumn, GuidedScoreCardConstants.INSTANCE.value());
    attributeCellTable.addColumn(partialScoreColumn, GuidedScoreCardConstants.INSTANCE.partialScore());
    attributeCellTable.addColumn(reasonCodeColumn, GuidedScoreCardConstants.INSTANCE.reasonCode());
    attributeCellTable.addColumn(actionColumn, GuidedScoreCardConstants.INSTANCE.actions());
    attributeCellTable.setWidth("100%", true);
    attributeCellTable.setColumnWidth(operatorColumn, 20.0, Style.Unit.PCT);
    attributeCellTable.setColumnWidth(valueColumn, 20.0, Style.Unit.PCT);
    attributeCellTable.setColumnWidth(partialScoreColumn, 20.0, Style.Unit.PCT);
    attributeCellTable.setColumnWidth(reasonCodeColumn, 20.0, Style.Unit.PCT);
    attributeCellTable.setColumnWidth(actionColumn, 20.0, Style.Unit.PCT);
    ListDataProvider<Attribute> dataProvider = new ListDataProvider<Attribute>();
    dataProvider.addDataDisplay(attributeCellTable);
    characteristicsAttrMap.put(cGrid, dataProvider);
    if ("boolean".equalsIgnoreCase(dataType)) {
        CustomEditTextCell etc = (CustomEditTextCell) attributeCellTable.getColumn(1).getCell();
        etc.setEnabled(false);
    }
    return (attributeCellTable);
}
Also used : EditTextCell(com.google.gwt.cell.client.EditTextCell) ListDataProvider(com.google.gwt.view.client.ListDataProvider) Attribute(org.drools.workbench.models.guided.scorecard.shared.Attribute) IdentityColumn(com.google.gwt.user.cellview.client.IdentityColumn) ActionCell(com.google.gwt.cell.client.ActionCell) CellTable(com.google.gwt.user.cellview.client.CellTable) IdentityColumn(com.google.gwt.user.cellview.client.IdentityColumn) Column(com.google.gwt.user.cellview.client.Column) Button(org.gwtbootstrap3.client.ui.Button)

Aggregations

Attribute (org.drools.workbench.models.guided.scorecard.shared.Attribute)6 Characteristic (org.drools.workbench.models.guided.scorecard.shared.Characteristic)5 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)2 ArrayList (java.util.ArrayList)2 ScoreCardModel (org.drools.workbench.models.guided.scorecard.shared.ScoreCardModel)2 Button (org.gwtbootstrap3.client.ui.Button)2 ActionCell (com.google.gwt.cell.client.ActionCell)1 EditTextCell (com.google.gwt.cell.client.EditTextCell)1 CellTable (com.google.gwt.user.cellview.client.CellTable)1 Column (com.google.gwt.user.cellview.client.Column)1 IdentityColumn (com.google.gwt.user.cellview.client.IdentityColumn)1 FlexTable (com.google.gwt.user.client.ui.FlexTable)1 ListDataProvider (com.google.gwt.view.client.ListDataProvider)1 ValidationMessage (org.guvnor.common.services.shared.validation.model.ValidationMessage)1 ListBox (org.gwtbootstrap3.client.ui.ListBox)1 Test (org.junit.Test)1 Import (org.kie.soup.project.datamodel.imports.Import)1 DecoratedDisclosurePanel (org.uberfire.ext.widgets.common.client.common.DecoratedDisclosurePanel)1