Search in sources :

Example 6 with Characteristic

use of org.drools.workbench.models.guided.scorecard.shared.Characteristic 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 7 with Characteristic

use of org.drools.workbench.models.guided.scorecard.shared.Characteristic 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 8 with Characteristic

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

the class GuidedScoreCardIndexVisitor method visit.

public void visit() {
    // Add type
    final String typeName = model.getFactName();
    if (typeName == null || typeName.isEmpty()) {
        return;
    }
    final String fullyQualifiedClassName = getFullyQualifiedClassName(typeName);
    ResourceReference resRef = addResourceReference(fullyQualifiedClassName, ResourceType.JAVA);
    // Add field
    final String fieldName = model.getFieldName();
    if (fieldName == null || fieldName.isEmpty()) {
        return;
    }
    resRef.addPartReference(fieldName, PartType.FIELD);
    final String fieldFullyQualifiedClassName = getFieldFullyQualifiedClassName(fullyQualifiedClassName, fieldName);
    addResourceReference(fieldFullyQualifiedClassName, ResourceType.JAVA);
    // Add Characteristics
    for (Characteristic c : model.getCharacteristics()) {
        visit(c);
    }
    // agenda-group, ruleflow-group
    String agendaGroup = model.getAgendaGroup();
    if (agendaGroup != null && !agendaGroup.isEmpty()) {
        addSharedReference(agendaGroup, PartType.AGENDA_GROUP);
    }
    String ruleFlowGroup = model.getRuleFlowGroup();
    if (ruleFlowGroup != null && !ruleFlowGroup.isEmpty()) {
        addSharedReference(ruleFlowGroup, PartType.RULEFLOW_GROUP);
    }
    Imports imports = model.getImports();
    if (imports != null) {
        visit(imports);
    }
}
Also used : Characteristic(org.drools.workbench.models.guided.scorecard.shared.Characteristic) ResourceReference(org.kie.workbench.common.services.refactoring.ResourceReference) Imports(org.kie.soup.project.datamodel.imports.Imports)

Example 9 with Characteristic

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

the class GuidedScoreCardEditor method setContent.

public void setContent(final ScoreCardModel model, final AsyncPackageDataModelOracle oracle) {
    this.model = model;
    this.oracle = oracle;
    final DecoratedDisclosurePanel disclosurePanel = new DecoratedDisclosurePanel(GuidedScoreCardConstants.INSTANCE.scoreCardTitle0(model.getName()));
    disclosurePanel.setWidth("100%");
    disclosurePanel.setTitle(GuidedScoreCardConstants.INSTANCE.scorecard());
    disclosurePanel.setOpen(true);
    final DecoratedDisclosurePanel configPanel = new DecoratedDisclosurePanel(GuidedScoreCardConstants.INSTANCE.setupParameters());
    configPanel.setWidth("95%");
    configPanel.setOpen(true);
    configPanel.add(getScorecardProperties());
    final DecoratedDisclosurePanel ruleAttributesPanel = new DecoratedDisclosurePanel(GuidedScoreCardConstants.INSTANCE.ruleAttributes());
    ruleAttributesPanel.setWidth("95%");
    ruleAttributesPanel.setOpen(false);
    ruleAttributesPanel.add(getRuleAttributesPanel());
    final DecoratedDisclosurePanel characteristicsPanel = new DecoratedDisclosurePanel(GuidedScoreCardConstants.INSTANCE.characteristics());
    characteristicsPanel.setOpen(model.getCharacteristics().size() > 0);
    characteristicsPanel.setWidth("95%");
    characteristicsPanel.add(getCharacteristics());
    final VerticalPanel config = new VerticalPanel();
    config.setWidth("100%");
    config.add(ruleAttributesPanel);
    config.add(configPanel);
    config.add(characteristicsPanel);
    disclosurePanel.add(config);
    container.setWidget(disclosurePanel);
    characteristicsAttrMap.clear();
    characteristicsAttrPanelMap.clear();
    for (final Characteristic characteristic : model.getCharacteristics()) {
        final FlexTable flexTable = addCharacteristic(characteristic);
        for (Attribute attribute : characteristic.getAttributes()) {
            addAttribute(flexTable, attribute);
        }
    }
}
Also used : VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) Attribute(org.drools.workbench.models.guided.scorecard.shared.Attribute) Characteristic(org.drools.workbench.models.guided.scorecard.shared.Characteristic) FlexTable(com.google.gwt.user.client.ui.FlexTable) DecoratedDisclosurePanel(org.uberfire.ext.widgets.common.client.common.DecoratedDisclosurePanel)

Example 10 with Characteristic

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

the class GuidedScoreCardModelVisitor method getConsumedModelClasses.

public Set<String> getConsumedModelClasses() {
    final Set<String> factTypes = new HashSet<String>();
    // Extract Fact Types from model
    factTypes.add(model.getFactName());
    for (Characteristic c : model.getCharacteristics()) {
        factTypes.add(c.getFact());
    }
    // Convert Fact Types into Fully Qualified Class Names
    final Set<String> fullyQualifiedClassNames = new HashSet<String>();
    for (String factType : factTypes) {
        fullyQualifiedClassNames.add(convertToFullyQualifiedClassName(factType));
    }
    return fullyQualifiedClassNames;
}
Also used : Characteristic(org.drools.workbench.models.guided.scorecard.shared.Characteristic) HashSet(java.util.HashSet)

Aggregations

Characteristic (org.drools.workbench.models.guided.scorecard.shared.Characteristic)10 Attribute (org.drools.workbench.models.guided.scorecard.shared.Attribute)5 ScoreCardModel (org.drools.workbench.models.guided.scorecard.shared.ScoreCardModel)3 ListBox (org.gwtbootstrap3.client.ui.ListBox)3 FlexTable (com.google.gwt.user.client.ui.FlexTable)2 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)2 ArrayList (java.util.ArrayList)2 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)2 HashSet (java.util.HashSet)1 ValidationMessage (org.guvnor.common.services.shared.validation.model.ValidationMessage)1 Button (org.gwtbootstrap3.client.ui.Button)1 TextBox (org.gwtbootstrap3.client.ui.TextBox)1 Test (org.junit.Test)1 Import (org.kie.soup.project.datamodel.imports.Import)1 Imports (org.kie.soup.project.datamodel.imports.Imports)1 ResourceReference (org.kie.workbench.common.services.refactoring.ResourceReference)1 DecoratedDisclosurePanel (org.uberfire.ext.widgets.common.client.common.DecoratedDisclosurePanel)1