try {
@SuppressWarnings("unchecked")
List<Map<String, Object>> resultSet = (List<Map<String, Object>>) beanRepository.getBean(resultSetBeanId);
if(resultSet == null) {
throw new SmooksException("Resultset '" + resultSetName + "' not found in bean context. Make sure an appropriate SQLExecutor resource config wraps this selector config.");
}
try {
Object selectedRow = null;
Iterator<Map<String, Object>> resultIter = resultSet.iterator();
while (selectedRow == null && resultIter.hasNext()) {
Map<String, Object> row = resultIter.next();
beanMapClone.put("row", row);
if(whereEvaluator.eval(beanMapClone)) {
selectedRow = row;
beanRepository.addBean(beanIdObj, selectedRow, source);
}
}
if(selectedRow == null && failedSelectError != null) {
throw new DataSelectionException(failedSelectError.apply(beanRepository.getBeanMap()));
}
if(logger.isDebugEnabled()) {
logger.debug("Selected resultset where '" + whereEvaluator.getExpression() + "': [" + selectedRow + "].");
}
} catch(ClassCastException e) {
throw new SmooksException("Bean '" + resultSetName + "' cannot be used as a Reference Data resultset. The resultset List must contain entries of type Map<String, Object>.");
}
} catch(ClassCastException e) {
throw new SmooksException("Bean '" + resultSetName + "' cannot be used as a Reference Data resultset. A resultset must be of type List<Map<String, Object>>. '" + resultSetName + "' is of type '" + beanRepository.getBean(resultSetBeanId).getClass().getName() + "'.");
}
}