use of org.drools.scorecards.parser.ScorecardParseException in project drools by kiegroup.
the class ScorecardCompiler method compileFromExcel.
public boolean compileFromExcel(final InputStream stream, final String worksheetName) {
try {
AbstractScorecardParser parser = new XLSScorecardParser();
scorecardErrors = parser.parseFile(stream, worksheetName);
if (scorecardErrors.isEmpty()) {
pmmlDocument = parser.getPMMLDocument();
return true;
}
} catch (ScorecardParseException e) {
logger.error(e.getMessage(), e);
} finally {
closeStream(stream);
}
return false;
}
use of org.drools.scorecards.parser.ScorecardParseException 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);
}
}
}
use of org.drools.scorecards.parser.ScorecardParseException in project drools by kiegroup.
the class XLSScorecardParser method parseFile.
@Override
public List<ScorecardError> parseFile(InputStream inStream, String worksheetName) throws ScorecardParseException {
try {
excelDataCollector = new XLSEventDataCollector();
excelDataCollector.setParser(this);
HSSFWorkbook workbook = new HSSFWorkbook(inStream);
HSSFSheet worksheet = workbook.getSheet(worksheetName);
if (worksheet != null) {
currentWorksheet = worksheet;
excelDataCollector.sheetStart(worksheetName);
excelDataCollector.setMergedRegionsInSheet(getMergedCellRangeList(worksheet));
processSheet(worksheet);
excelDataCollector.sheetComplete();
parseErrors = excelDataCollector.getParseErrors();
scorecard = excelDataCollector.getScorecard();
} else {
throw new ScorecardParseException("No worksheet found with name '" + worksheetName + "'.");
}
} catch (IOException e) {
throw new ScorecardParseException(e);
}
return parseErrors;
}
Aggregations