use of org.akaza.openclinica.domain.rule.action.EventActionBean in project OpenClinica by OpenClinica.
the class RulesPostImportContainerService method addNewRuleSetBeanInList.
private void addNewRuleSetBeanInList(String target, String destination, List<RuleSetBean> eventActionsRuleSetBean) {
ExpressionBean expression = new ExpressionBean();
expression.setValue(target);
RuleSetBean ruleSetBean = new RuleSetBean();
ruleSetBean.setOriginalTarget(expression);
EventActionBean eventActionBean = new EventActionBean();
eventActionBean.setOc_oid_reference(destination);
List<RuleActionBean> listRuleActionBean = new ArrayList<RuleActionBean>();
listRuleActionBean.add(eventActionBean);
RuleSetRuleBean ruleSetRuleBean = new RuleSetRuleBean();
ruleSetRuleBean.setActions(listRuleActionBean);
ruleSetBean.addRuleSetRule(ruleSetRuleBean);
eventActionsRuleSetBean.add(ruleSetBean);
}
use of org.akaza.openclinica.domain.rule.action.EventActionBean in project OpenClinica by OpenClinica.
the class RulesPostImportContainerService method runValidationInList.
public void runValidationInList(String target, String destination, AuditableBeanWrapper<RuleSetBean> ruleSetBeanWrapper, List<RuleSetBean> eventActionsRuleSetBean) {
// eventActionsRuleSetBean is the list of all events from rule set table
Boolean isDestinationATarget = false;
RuleSetBean isDestination = null;
for (RuleSetBean ruleSetBean : eventActionsRuleSetBean) {
if (isDestinationAndTargetMatch(parseTarget(ruleSetBean.getOriginalTarget().getValue()), parseDestination(destination)) || isDestinationAndTargetAcceptable(parseTarget(ruleSetBean.getOriginalTarget().getValue()), parseDestination(destination))) {
isDestinationATarget = true;
isDestination = ruleSetBean;
break;
}
}
if (isDestinationATarget == true && isDestination != null) {
List<RuleActionBean> ruleActions = getAllRuleActions(isDestination);
for (RuleActionBean ruleActionBean : ruleActions) {
if (ruleActionBean.getActionType().getCode() == 6) {
if (isDestinationAndTargetMatch(parseTarget(target), parseDestination(((EventActionBean) ruleActionBean).getOc_oid_reference() + ".STARTDATE"))) {
ruleSetBeanWrapper.error(createError("OCRERR_0042"));
break;
}
if (isDestinationAndTargetAcceptable(parseTarget(target), parseDestination(((EventActionBean) ruleActionBean).getOc_oid_reference()))) {
ruleSetBeanWrapper.error(createError("OCRERR_0043"));
break;
}
runValidationInList(target, ((EventActionBean) ruleActionBean).getOc_oid_reference(), ruleSetBeanWrapper, eventActionsRuleSetBean);
}
}
} else {
addNewRuleSetBeanInList(target, destination, eventActionsRuleSetBean);
}
}
use of org.akaza.openclinica.domain.rule.action.EventActionBean 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
}
}
}
// }
}
}
}
use of org.akaza.openclinica.domain.rule.action.EventActionBean in project OpenClinica by OpenClinica.
the class RuleSetRuleDao method findByRuleSetStudyIdAndStatusAvail.
/**
* Use this method carefully as we force an eager fetch. It is also annotated with
* Transactional so it can be called from Quartz threads.
* @param studyId
* @return List of RuleSetRuleBeans
*/
@SuppressWarnings("unchecked")
@Transactional
public ArrayList<RuleSetRuleBean> findByRuleSetStudyIdAndStatusAvail(Integer studyId) {
String query = "from " + getDomainClassName() + " ruleSetRule where ruleSetRule.ruleSetBean.studyId = :studyId and status = :status ";
org.hibernate.Query q = getCurrentSession().createQuery(query);
q.setInteger("studyId", studyId);
q.setParameter("status", org.akaza.openclinica.domain.Status.AVAILABLE);
q.setCacheable(true);
q.setCacheRegion(getDomainClassName());
//JN: enabling statistics for hibernate queries etc... to monitor the performance
Statistics stats = getSessionFactory().getStatistics();
logger.info("EntityRuleSet" + stats.getEntityInsertCount());
logger.info(stats.getQueryExecutionMaxTimeQueryString());
logger.info("hit count" + stats.getSecondLevelCacheHitCount());
stats.logSummary();
ArrayList<RuleSetRuleBean> ruleSetRules = (ArrayList<RuleSetRuleBean>) q.list();
// Forcing eager fetch of actions & their properties
for (RuleSetRuleBean ruleSetRuleBean : ruleSetRules) {
for (RuleActionBean action : ruleSetRuleBean.getActions()) {
if (action instanceof RandomizeActionBean) {
((RandomizeActionBean) action).getProperties().size();
}
if (action instanceof InsertActionBean) {
((InsertActionBean) action).getProperties().size();
}
if (action instanceof ShowActionBean) {
((ShowActionBean) action).getProperties().size();
}
if (action instanceof HideActionBean) {
((HideActionBean) action).getProperties().size();
}
if (action instanceof EventActionBean) {
((EventActionBean) action).getProperties().size();
}
}
}
return ruleSetRules;
}
Aggregations