use of org.akaza.openclinica.domain.rule.action.NotificationActionProcessor in project OpenClinica by OpenClinica.
the class BeanPropertyRuleRunner method runRules.
public void runRules(List<RuleSetBean> ruleSets, DataSource ds, BeanPropertyService beanPropertyService, StudyEventDao studyEventDaoHib, StudyEventDefinitionDao studyEventDefDaoHib, StudyEventChangeDetails changeDetails, Integer userId, JavaMailSenderImpl mailSender) {
for (RuleSetBean ruleSet : ruleSets) {
List<ExpressionBean> expressions = ruleSet.getExpressions();
for (ExpressionBean expressionBean : expressions) {
ruleSet.setTarget(expressionBean);
StudyEvent studyEvent = studyEventDaoHib.findByStudyEventId(Integer.valueOf(getExpressionService().getStudyEventDefenitionOrdninalCurated(ruleSet.getTarget().getValue())));
int eventOrdinal = studyEvent.getSampleOrdinal();
int studySubjectBeanId = studyEvent.getStudySubject().getStudySubjectId();
List<RuleSetRuleBean> ruleSetRules = ruleSet.getRuleSetRules();
for (RuleSetRuleBean ruleSetRule : ruleSetRules) {
Object result = null;
if (ruleSetRule.getStatus() == Status.AVAILABLE) {
RuleBean rule = ruleSetRule.getRuleBean();
// StudyBean currentStudy = rule.getStudy();//TODO:Fix me!
StudyDAO sdao = new StudyDAO(ds);
StudyBean currentStudy = (StudyBean) sdao.findByPK(rule.getStudyId());
ExpressionBeanObjectWrapper eow = new ExpressionBeanObjectWrapper(ds, currentStudy, rule.getExpression(), ruleSet, studySubjectBeanId, studyEventDaoHib, studyEventDefDaoHib);
try {
// StopWatch sw = new StopWatch();
ExpressionObjectWrapper ew = new ExpressionObjectWrapper(ds, currentStudy, rule.getExpression(), ruleSet);
ew.setStudyEventDaoHib(studyEventDaoHib);
ew.setStudySubjectId(studySubjectBeanId);
ew.setExpressionContext(ExpressionObjectWrapper.CONTEXT_EXPRESSION);
OpenClinicaExpressionParser oep = new OpenClinicaExpressionParser(ew);
// eow.setUserAccountBean(ub);
eow.setStudyBean(currentStudy);
result = oep.parseAndEvaluateExpression(rule.getExpression().getValue());
// sw.stop();
logger.debug("Rule Expression Evaluation Result: " + result);
// Actions
List<RuleActionBean> actionListBasedOnRuleExecutionResult = ruleSetRule.getActions(result.toString());
for (RuleActionBean ruleActionBean : actionListBasedOnRuleExecutionResult) {
// ActionProcessor ap =ActionProcessorFacade.getActionProcessor(ruleActionBean.getActionType(), ds, null, null,ruleSet, null, ruleActionBean.getRuleSetRule());
if (ruleActionBean instanceof EventActionBean) {
beanPropertyService.runAction(ruleActionBean, eow, userId, changeDetails.getRunningInTransaction());
} else if (ruleActionBean instanceof NotificationActionBean) {
notificationActionProcessor = new NotificationActionProcessor(ds, mailSender, ruleSetRule);
notificationActionProcessor.runNotificationAction(ruleActionBean, ruleSet, studySubjectBeanId, eventOrdinal);
}
}
} catch (OpenClinicaSystemException osa) {
// osa.printStackTrace();
logger.error("Rule Runner received exception: " + osa.getMessage());
logger.error(ExceptionUtils.getStackTrace(osa));
// TODO: report something useful
}
}
}
// }
}
}
}
Aggregations