Search in sources :

Example 6 with EventActionBean

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);
}
Also used : EventActionBean(org.akaza.openclinica.domain.rule.action.EventActionBean) RuleActionBean(org.akaza.openclinica.domain.rule.action.RuleActionBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) ArrayList(java.util.ArrayList) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean)

Example 7 with EventActionBean

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);
    }
}
Also used : RuleActionBean(org.akaza.openclinica.domain.rule.action.RuleActionBean) EventActionBean(org.akaza.openclinica.domain.rule.action.EventActionBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean)

Example 8 with EventActionBean

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
                    }
                }
            }
        //     	}
        }
    }
}
Also used : RuleActionBean(org.akaza.openclinica.domain.rule.action.RuleActionBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) NotificationActionBean(org.akaza.openclinica.domain.rule.action.NotificationActionBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ExpressionBeanObjectWrapper(org.akaza.openclinica.domain.rule.expression.ExpressionBeanObjectWrapper) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean) OpenClinicaExpressionParser(org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser) EventActionBean(org.akaza.openclinica.domain.rule.action.EventActionBean) ExpressionObjectWrapper(org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper) NotificationActionProcessor(org.akaza.openclinica.domain.rule.action.NotificationActionProcessor) StudyEvent(org.akaza.openclinica.domain.datamap.StudyEvent) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) RuleBean(org.akaza.openclinica.domain.rule.RuleBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean)

Example 9 with EventActionBean

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;
}
Also used : ShowActionBean(org.akaza.openclinica.domain.rule.action.ShowActionBean) HideActionBean(org.akaza.openclinica.domain.rule.action.HideActionBean) RuleActionBean(org.akaza.openclinica.domain.rule.action.RuleActionBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) InsertActionBean(org.akaza.openclinica.domain.rule.action.InsertActionBean) ArrayList(java.util.ArrayList) Statistics(org.hibernate.stat.Statistics) EventActionBean(org.akaza.openclinica.domain.rule.action.EventActionBean) RandomizeActionBean(org.akaza.openclinica.domain.rule.action.RandomizeActionBean) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

EventActionBean (org.akaza.openclinica.domain.rule.action.EventActionBean)9 RuleSetRuleBean (org.akaza.openclinica.domain.rule.RuleSetRuleBean)5 RuleSetBean (org.akaza.openclinica.domain.rule.RuleSetBean)4 PropertyBean (org.akaza.openclinica.domain.rule.action.PropertyBean)4 RuleActionBean (org.akaza.openclinica.domain.rule.action.RuleActionBean)4 ExpressionBean (org.akaza.openclinica.domain.rule.expression.ExpressionBean)4 HideActionBean (org.akaza.openclinica.domain.rule.action.HideActionBean)3 InsertActionBean (org.akaza.openclinica.domain.rule.action.InsertActionBean)3 NotificationActionBean (org.akaza.openclinica.domain.rule.action.NotificationActionBean)3 ShowActionBean (org.akaza.openclinica.domain.rule.action.ShowActionBean)3 ArrayList (java.util.ArrayList)2 StudyEvent (org.akaza.openclinica.domain.datamap.StudyEvent)2 RuleBean (org.akaza.openclinica.domain.rule.RuleBean)2 DiscrepancyNoteActionBean (org.akaza.openclinica.domain.rule.action.DiscrepancyNoteActionBean)2 RandomizeActionBean (org.akaza.openclinica.domain.rule.action.RandomizeActionBean)2 RuleActionRunBean (org.akaza.openclinica.domain.rule.action.RuleActionRunBean)2 OpenClinicaExpressionParser (org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser)2 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)1 StudyGroupClassBean (org.akaza.openclinica.bean.managestudy.StudyGroupClassBean)1 EmailActionBean (org.akaza.openclinica.bean.rule.action.EmailActionBean)1