use of org.drools.scorecards.ScorecardError in project drools by kiegroup.
the class ExcelScorecardValidator method validateBaselineScores.
private void validateBaselineScores() {
for (Object obj : scorecard.getExtensionsAndCharacteristicsAndMiningSchemas()) {
Double scorecardBaseline = scorecard.getBaselineScore();
if (obj instanceof Characteristics) {
Characteristics characteristics = (Characteristics) obj;
for (Characteristic characteristic : characteristics.getCharacteristics()) {
Double charBaseline = characteristic.getBaselineScore();
if ((charBaseline == null || charBaseline.doubleValue() == 0) && ((scorecardBaseline == null || scorecardBaseline.doubleValue() == 0))) {
String newCellRef = createDataTypeCellRef(ScorecardPMMLUtils.getExtensionValue(characteristic.getExtensions(), "cellRef"), 2);
parseErrors.add(new ScorecardError(newCellRef, "Characteristic is missing Baseline Score"));
}
}
}
}
}
use of org.drools.scorecards.ScorecardError in project drools by kiegroup.
the class ExcelScorecardValidator method validateReasonCodes.
private void validateReasonCodes() {
for (Object obj : scorecard.getExtensionsAndCharacteristicsAndMiningSchemas()) {
if (obj instanceof Characteristics) {
Characteristics characteristics = (Characteristics) obj;
for (Characteristic characteristic : characteristics.getCharacteristics()) {
String charReasonCode = characteristic.getReasonCode();
if (charReasonCode == null || StringUtils.isEmpty(charReasonCode)) {
for (Attribute attribute : characteristic.getAttributes()) {
String newCellRef = createDataTypeCellRef(ScorecardPMMLUtils.getExtensionValue(attribute.getExtensions(), "cellRef"), 3);
String attrReasonCode = attribute.getReasonCode();
if (attrReasonCode == null || StringUtils.isEmpty(attrReasonCode)) {
parseErrors.add(new ScorecardError(newCellRef, "Attribute is missing Reason Code"));
}
}
}
}
}
}
}
use of org.drools.scorecards.ScorecardError in project drools by kiegroup.
the class ExcelScorecardValidator method checkForInvalidDataTypes.
private void checkForInvalidDataTypes() {
for (Object obj : scorecard.getExtensionsAndCharacteristicsAndMiningSchemas()) {
if (obj instanceof Characteristics) {
Characteristics characteristics = (Characteristics) obj;
for (Characteristic characteristic : characteristics.getCharacteristics()) {
String dataType = ScorecardPMMLUtils.getExtensionValue(characteristic.getExtensions(), ScorecardPMMLExtensionNames.CHARACTERTISTIC_DATATYPE);
String newCellRef = createDataTypeCellRef(ScorecardPMMLUtils.getExtensionValue(characteristic.getExtensions(), "cellRef"), 1);
if (dataType == null || StringUtils.isEmpty(dataType)) {
parseErrors.add(new ScorecardError(newCellRef, "Missing Data Type!"));
} else if (!XLSKeywords.DATATYPE_TEXT.equalsIgnoreCase(dataType) && !XLSKeywords.DATATYPE_NUMBER.equalsIgnoreCase(dataType) && !XLSKeywords.DATATYPE_BOOLEAN.equalsIgnoreCase(dataType)) {
parseErrors.add(new ScorecardError(newCellRef, "Invalid Data Type!"));
}
if (XLSKeywords.DATATYPE_BOOLEAN.equalsIgnoreCase(dataType)) {
for (Attribute attribute : characteristic.getAttributes()) {
String value = ScorecardPMMLUtils.getExtensionValue(attribute.getExtensions(), "predicateResolver");
if (!"TRUE".equalsIgnoreCase(value) && !"FALSE".equalsIgnoreCase(value)) {
parseErrors.add(new ScorecardError(newCellRef, "Characteristic '" + characteristic.getName() + "' is Boolean and can support TRUE|FALSE only"));
break;
}
}
} else if (XLSKeywords.DATATYPE_NUMBER.equalsIgnoreCase(dataType)) {
for (Attribute attribute : characteristic.getAttributes()) {
String value = ScorecardPMMLUtils.getExtensionValue(attribute.getExtensions(), "predicateResolver");
if (!StringUtil.isNumericWithOperators(value)) {
parseErrors.add(new ScorecardError(newCellRef, "Characteristic '" + characteristic.getName() + "' is Number and can support numerics only"));
}
}
}
}
}
}
}
use of org.drools.scorecards.ScorecardError in project drools by kiegroup.
the class ExcelScorecardValidator method validateWeights.
private void validateWeights() {
for (Object obj : scorecard.getExtensionsAndCharacteristicsAndMiningSchemas()) {
if (obj instanceof Characteristics) {
Characteristics characteristics = (Characteristics) obj;
for (Characteristic characteristic : characteristics.getCharacteristics()) {
for (Attribute attribute : characteristic.getAttributes()) {
String newCellRef = createDataTypeCellRef(ScorecardPMMLUtils.getExtensionValue(attribute.getExtensions(), "cellRef"), 2);
String weight = ScorecardPMMLUtils.getExtensionValue(attribute.getExtensions(), ScorecardPMMLExtensionNames.CHARACTERTISTIC_WEIGHT);
if (StringUtils.isEmpty(weight) || !isDouble(weight)) {
parseErrors.add(new ScorecardError(newCellRef, "Attribute is missing weight or specified weight is not a double."));
}
}
}
}
}
}
use of org.drools.scorecards.ScorecardError in project drools by kiegroup.
the class XLSEventDataCollector method fulfillExpectation.
private void fulfillExpectation(int currentRowCtr, int currentColCtr, Object cellValue, Class expectedClass) throws ScorecardParseException {
List<DataExpectation> dataExpectations = resolveExpectations(currentRowCtr, currentColCtr);
CellReference cellRef = new CellReference(currentRowCtr, currentColCtr);
Method method = null;
for (DataExpectation dataExpectation : dataExpectations) {
try {
if (dataExpectation != null && dataExpectation.object != null) {
if (cellValue == null || StringUtils.isEmpty(cellValue.toString())) {
if (dataExpectation.errorMessage != null && !StringUtils.isEmpty(dataExpectation.errorMessage)) {
parseErrors.add(new ScorecardError(cellRef.formatAsString(), dataExpectation.errorMessage));
return;
}
}
String setter = "set" + Character.toUpperCase(dataExpectation.property.charAt(0)) + dataExpectation.property.substring(1);
method = getSuitableMethod(cellValue, expectedClass, dataExpectation, setter);
if (method == null) {
if (cellValue != null && !StringUtils.isEmpty(cellValue.toString())) {
parseErrors.add(new ScorecardError(cellRef.formatAsString(), "Unexpected Value! Wrong Datatype?"));
}
return;
}
if (method.getParameterTypes()[0] == Double.class) {
cellValue = Double.parseDouble(cellValue.toString());
}
if (method.getParameterTypes()[0] == Boolean.class) {
cellValue = Boolean.valueOf(cellValue.toString());
}
if (method.getParameterTypes()[0] == String.class && !(cellValue instanceof String) && cellValue != null) {
cellValue = cellValue.toString();
}
method.invoke(dataExpectation.object, cellValue);
if (dataExpectation.object instanceof Extension && ("cellRef".equals(((Extension) dataExpectation.object).getName()))) {
((Extension) dataExpectation.object).setValue(cellRef.formatAsString());
}
// dataExpectations.remove(dataExpectation);
}
} catch (Exception e) {
throw new ScorecardParseException(e);
}
}
}
Aggregations