*/
public Boolean evaluateCondition(Map<String, Object> context, Map<String, String> attrs, String expression, DispatchContext dctx) throws EvaluationException {
// get the service to call
String serviceName = (String) attrs.get("serviceName");
if (UtilValidate.isEmpty(serviceName))
throw new EvaluationException("Invalid serviceName; be sure to set the serviceName ExtendedAttribute");
// get the dispatcher
LocalDispatcher dispatcher = dctx.getDispatcher();
if (dispatcher == null)
throw new EvaluationException("Bad LocalDispatcher found in the DispatchContext");
// create a map of all context and extended attributes, attributes will overwrite context values
Map<String, Object> newContext = new HashMap<String, Object>(context);
newContext.putAll(attrs);
// build the context for the service
Map<String, Object> serviceContext = null;
ModelService model = null;
try {
model = dctx.getModelService(serviceName);
serviceContext = model.makeValid(newContext, ModelService.IN_PARAM);
} catch (GenericServiceException e) {
throw new EvaluationException("Cannot get ModelService object for service named: " + serviceName, e);
}
// invoke the service
Map<String, Object> serviceResult = null;
try {
serviceResult = dispatcher.runSync(serviceName, serviceContext);
} catch (GenericServiceException e) {
throw new EvaluationException("Cannot invoke the service named: " + serviceName, e);
}
// get the evaluationResult object from the result
Boolean evaluationResult = null;
try {
evaluationResult = (Boolean) serviceResult.get("evaluationResult");
} catch (ClassCastException e) {
throw new EvaluationException("Service did not return a valid evaluationResult object");
}
return evaluationResult;
}