use of org.drools.workbench.models.guided.scorecard.shared.Characteristic 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;
}
use of org.drools.workbench.models.guided.scorecard.shared.Characteristic 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;
}
use of org.drools.workbench.models.guided.scorecard.shared.Characteristic in project drools-wb by kiegroup.
the class GuidedScoreCardFactory method makeScoreCardWithCharacteristics.
public static ScoreCardModel makeScoreCardWithCharacteristics(final String packageName, final Collection<Import> imports, final String name) {
final ScoreCardModel model = new ScoreCardModel();
model.getImports().getImports().addAll(imports);
model.setPackageName(packageName);
model.setName(name);
model.setFactName("Applicant");
model.setFieldName("age");
final Characteristic c = new Characteristic();
c.setName("c1");
c.setFact("Mortgage");
c.setField("amount");
c.setDataType(DataType.TYPE_NUMERIC_INTEGER);
model.getCharacteristics().add(c);
return model;
}
use of org.drools.workbench.models.guided.scorecard.shared.Characteristic in project drools-wb by kiegroup.
the class GuidedScoreCardEditor method getCharacteristicFromTable.
private Characteristic getCharacteristicFromTable(FlexTable flexTable) {
ListBox enumDropDown;
final Characteristic characteristic = new Characteristic();
characteristic.setName(((TextBox) flexTable.getWidget(0, 1)).getValue());
// Characteristic Fact Type
enumDropDown = (ListBox) flexTable.getWidget(2, 0);
if (enumDropDown.getSelectedIndex() > -1) {
final String simpleFactName = enumDropDown.getValue(enumDropDown.getSelectedIndex());
characteristic.setFact(simpleFactName);
oracle.getFieldCompletions(simpleFactName, new Callback<ModelField[]>() {
@Override
public void callback(final ModelField[] fields) {
if (fields != null) {
for (ModelField mf : fields) {
if (mf.getType().equals(simpleFactName)) {
characteristic.setFact(mf.getClassName());
break;
}
}
}
}
});
// Characteristic Field (cannot be set if no Fact Type has been set)
enumDropDown = (ListBox) flexTable.getWidget(2, 1);
if (enumDropDown.getSelectedIndex() > -1) {
String fieldName = enumDropDown.getValue(enumDropDown.getSelectedIndex());
fieldName = fieldName.substring(0, fieldName.indexOf(":")).trim();
characteristic.setField(fieldName);
} else {
characteristic.setField("");
}
getDataTypeForField(simpleFactName, characteristic.getField(), new Callback<String>() {
@Override
public void callback(final String result) {
characteristic.setDataType(result);
}
});
}
// Characteristic Reason Code
characteristic.setReasonCode(((TextBox) flexTable.getWidget(2, 3)).getValue());
// Characteristic Base Line Score
final String baselineScore = ((TextBox) flexTable.getWidget(2, 2)).getValue();
try {
characteristic.setBaselineScore(Double.parseDouble(baselineScore));
} catch (Exception e) {
characteristic.setBaselineScore(0.0d);
}
return characteristic;
}
use of org.drools.workbench.models.guided.scorecard.shared.Characteristic in project drools-wb by kiegroup.
the class GuidedScoreCardEditor method getModel.
public ScoreCardModel getModel() {
// ScoreCardModel could be null if the ScoreCard failed to load (e.g. the file was not found in VFS)
if (model == null) {
return null;
}
// Otherwise populate model from UI...
model.setBaselineScore(Double.parseDouble(tbBaselineScore.getValue()));
model.setInitialScore(Double.parseDouble(tbInitialScore.getValue()));
model.setUseReasonCodes(ddUseReasonCode.getSelectedIndex() == 1);
if (ddReasonCodeAlgorithm.getSelectedIndex() > 0) {
model.setReasonCodesAlgorithm(ddReasonCodeAlgorithm.getValue(ddReasonCodeAlgorithm.getSelectedIndex()));
} else {
model.setReasonCodesAlgorithm("");
}
ListBox enumDropDown = (ListBox) scorecardPropertiesGrid.getWidget(1, 0);
if (enumDropDown.getSelectedIndex() > 0) {
final String simpleFactName = enumDropDown.getValue(enumDropDown.getSelectedIndex());
model.setFactName(simpleFactName);
oracle.getFieldCompletions(simpleFactName, new Callback<ModelField[]>() {
@Override
public void callback(final ModelField[] fields) {
if (fields != null) {
for (final ModelField mf : fields) {
if (mf.getType().equals(simpleFactName)) {
model.setFactName(mf.getClassName());
break;
}
}
}
}
});
} else {
model.setFactName("");
}
enumDropDown = (ListBox) scorecardPropertiesGrid.getWidget(1, 1);
if (enumDropDown.getSelectedIndex() > 0) {
String fieldName = enumDropDown.getValue(enumDropDown.getSelectedIndex());
fieldName = fieldName.substring(0, fieldName.indexOf(":")).trim();
model.setFieldName(fieldName);
} else {
model.setFieldName("");
}
if (ddReasonCodeField.getSelectedIndex() > 0) {
String rcField = ddReasonCodeField.getValue(ddReasonCodeField.getSelectedIndex());
rcField = rcField.substring(0, rcField.indexOf(":")).trim();
model.setReasonCodeField(rcField);
} else {
model.setReasonCodeField("");
}
model.getCharacteristics().clear();
for (final FlexTable flexTable : characteristicsTables) {
final Characteristic characteristic = getCharacteristicFromTable(flexTable);
// Characteristic Attributes
characteristic.getAttributes().clear();
characteristic.getAttributes().addAll(characteristicsAttrMap.get(flexTable).getList());
model.getCharacteristics().add(characteristic);
}
model.setAgendaGroup(tbAgendaGroup.getValue());
model.setRuleFlowGroup(tbRuleFlowGroup.getValue());
return model;
}
Aggregations