Search in sources :

Example 1 with RunOnSchedule

use of org.akaza.openclinica.domain.rule.RunOnSchedule in project OpenClinica by OpenClinica.

the class RulesPostImportContainerService method validateRuleSetDefs.

public RulesPostImportContainer validateRuleSetDefs(RulesPostImportContainer importContainer) {
    List<RuleSetBean> eventActionsRuleSetBean = getRuleSetDao().findAllEventActions(currentStudy);
    for (RuleSetBean ruleSetBean : importContainer.getRuleSets()) {
        AuditableBeanWrapper<RuleSetBean> ruleSetBeanWrapper = new AuditableBeanWrapper<RuleSetBean>(ruleSetBean);
        ruleSetBeanWrapper.getAuditableBean().setStudy(currentStudy);
        if (isRuleSetExpressionValid(ruleSetBeanWrapper)) {
            RuleSetBean persistentRuleSetBean = getRuleSetDao().findByExpressionAndStudy(ruleSetBean, currentStudy.getId());
            if (persistentRuleSetBean != null) {
                List<RuleSetRuleBean> importedRuleSetRules = ruleSetBeanWrapper.getAuditableBean().getRuleSetRules();
                if (ruleSetBean.getRunTime() != null) {
                    if (ruleSetBean.getRunOnSchedule() == null) {
                        ruleSetBean.setRunOnSchedule(new RunOnSchedule(ruleSetBean.getRunTime()));
                    }
                }
                if (ruleSetBean.getRunOnSchedule() != null) {
                    persistentRuleSetBean.setRunSchedule(true);
                    if (ruleSetBean.getRunOnSchedule().getRunTime() != null) {
                        if (isRunTimeValid(ruleSetBeanWrapper, ruleSetBean.getRunOnSchedule().getRunTime())) {
                            persistentRuleSetBean.setRunTime(ruleSetBean.getRunOnSchedule().getRunTime());
                        }
                    } else {
                        // supposed to act like 23:00
                        persistentRuleSetBean.setRunTime(null);
                    }
                } else {
                    persistentRuleSetBean.setRunSchedule(false);
                    persistentRuleSetBean.setRunTime(null);
                }
                persistentRuleSetBean.setUpdaterAndDate(getUserAccount());
                ruleSetBeanWrapper.setAuditableBean(persistentRuleSetBean);
                Iterator<RuleSetRuleBean> itr = importedRuleSetRules.iterator();
                while (itr.hasNext()) {
                    RuleSetRuleBean ruleSetRuleBean = itr.next();
                    ruleSetRuleBean.setRuleBean(getRuleDao().findByOid(ruleSetRuleBean.getOid(), persistentRuleSetBean.getStudyId()));
                    // ruleSetRuleBean.setRuleSetBean(ruleSetBeanWrapper.getAuditableBean());
                    for (RuleSetRuleBean persistentruleSetRuleBean : persistentRuleSetBean.getRuleSetRules()) {
                        if (persistentruleSetRuleBean.getStatus() != Status.DELETED && ruleSetRuleBean.equals(persistentruleSetRuleBean)) {
                            persistentruleSetRuleBean.setRuleSetRuleBeanImportStatus(RuleSetRuleBeanImportStatus.EXACT_DOUBLE);
                            itr.remove();
                            break;
                        } else if (persistentruleSetRuleBean.getStatus() != Status.DELETED && ruleSetRuleBean.getRuleBean() != null && ruleSetRuleBean.getRuleBean().equals(persistentruleSetRuleBean.getRuleBean())) {
                            // persistentruleSetRuleBean.setActions(ruleSetRuleBean.getActions());
                            persistentruleSetRuleBean.setRuleSetRuleBeanImportStatus(RuleSetRuleBeanImportStatus.TO_BE_REMOVED);
                            // itr.remove();
                            break;
                        }
                        ruleSetRuleBean.setRuleSetRuleBeanImportStatus(RuleSetRuleBeanImportStatus.LINE);
                    }
                }
                ruleSetBeanWrapper.getAuditableBean().addRuleSetRules(importedRuleSetRules);
            // ruleSetBeanWrapper.getAuditableBean().setId(persistentRuleSetBean.getId());
            } else {
                if (importContainer.getValidRuleSetExpressionValues().contains(ruleSetBeanWrapper.getAuditableBean().getTarget().getValue())) {
                    ruleSetBeanWrapper.error(createError("OCRERR_0031"));
                }
                ruleSetBeanWrapper.getAuditableBean().setOwner(getUserAccount());
                ruleSetBeanWrapper.getAuditableBean().setStudyEventDefinition(getExpressionService().getStudyEventDefinitionFromExpression(ruleSetBean.getTarget().getValue()));
                ruleSetBeanWrapper.getAuditableBean().setCrf(getExpressionService().getCRFFromExpression(ruleSetBean.getTarget().getValue()));
                ruleSetBeanWrapper.getAuditableBean().setCrfVersion(getExpressionService().getCRFVersionFromExpression(ruleSetBean.getTarget().getValue()));
                ruleSetBeanWrapper.getAuditableBean().setItem(getExpressionService().getItemBeanFromExpression(ruleSetBean.getTarget().getValue()));
                ruleSetBeanWrapper.getAuditableBean().setItemGroup(getExpressionService().getItemGroupExpression(ruleSetBean.getTarget().getValue()));
                if (ruleSetBean.getRunTime() != null) {
                    if (ruleSetBean.getRunOnSchedule() == null) {
                        ruleSetBeanWrapper.getAuditableBean().setRunOnSchedule(new RunOnSchedule(ruleSetBean.getRunTime()));
                    }
                }
                if (ruleSetBean.getRunOnSchedule() != null) {
                    ruleSetBeanWrapper.getAuditableBean().setRunSchedule(true);
                    if (ruleSetBean.getRunOnSchedule().getRunTime() != null) {
                        //validate Time           isRunTimeValid
                        if (isRunTimeValid(ruleSetBeanWrapper, ruleSetBean.getRunOnSchedule().getRunTime())) {
                            ruleSetBeanWrapper.getAuditableBean().setRunTime(ruleSetBean.getRunOnSchedule().getRunTime());
                        }
                    } else {
                        // supposed to act like DEFAULT_TIME
                        ruleSetBeanWrapper.getAuditableBean().setRunTime(null);
                    }
                } else {
                    ruleSetBeanWrapper.getAuditableBean().setRunSchedule(false);
                    ruleSetBeanWrapper.getAuditableBean().setRunTime(null);
                }
            }
            isRuleSetRuleValid(importContainer, ruleSetBeanWrapper, eventActionsRuleSetBean);
        }
        putRuleSetInCorrectContainer(ruleSetBeanWrapper, importContainer);
    }
    logger.info("# of Valid RuleSetDefs : " + importContainer.getValidRuleSetDefs().size());
    logger.info("# of InValid RuleSetDefs : " + importContainer.getInValidRuleSetDefs().size());
    logger.info("# of Overwritable RuleSetDefs : " + importContainer.getDuplicateRuleSetDefs().size());
    return importContainer;
}
Also used : AuditableBeanWrapper(org.akaza.openclinica.domain.rule.AuditableBeanWrapper) RunOnSchedule(org.akaza.openclinica.domain.rule.RunOnSchedule) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean)

Aggregations

AuditableBeanWrapper (org.akaza.openclinica.domain.rule.AuditableBeanWrapper)1 RuleSetBean (org.akaza.openclinica.domain.rule.RuleSetBean)1 RuleSetRuleBean (org.akaza.openclinica.domain.rule.RuleSetRuleBean)1 RunOnSchedule (org.akaza.openclinica.domain.rule.RunOnSchedule)1