Search in sources :

Example 1 with AuditableBeanWrapper

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

the class RulesPostImportContainerService method validateRuleDefs.

public RulesPostImportContainer validateRuleDefs(RulesPostImportContainer importContainer) {
    for (RuleBean ruleBean : importContainer.getRuleDefs()) {
        AuditableBeanWrapper<RuleBean> ruleBeanWrapper = new AuditableBeanWrapper<RuleBean>(ruleBean);
        ruleBeanWrapper.getAuditableBean().setStudy(currentStudy);
        // Remove illegal characters from expression value
        ruleBeanWrapper.getAuditableBean().getExpression().setValue(ruleBeanWrapper.getAuditableBean().getExpression().getValue().trim().replaceAll("(\n|\t|\r)", " "));
        if (isRuleOidValid(ruleBeanWrapper) && isRuleExpressionValid(ruleBeanWrapper, null)) {
            RuleBean persistentRuleBean = getRuleDao().findByOid(ruleBeanWrapper.getAuditableBean());
            if (persistentRuleBean != null) {
                String name = ruleBeanWrapper.getAuditableBean().getName();
                String expressionValue = ruleBeanWrapper.getAuditableBean().getExpression().getValue();
                String expressionContextName = ruleBeanWrapper.getAuditableBean().getExpression().getContextName();
                String description = ruleBeanWrapper.getAuditableBean().getDescription();
                Context context = expressionContextName != null ? Context.getByName(expressionContextName) : Context.OC_RULES_V1;
                persistentRuleBean.setUpdaterAndDate(getUserAccount());
                ruleBeanWrapper.setAuditableBean(persistentRuleBean);
                ruleBeanWrapper.getAuditableBean().setName(name);
                ruleBeanWrapper.getAuditableBean().setDescription(description);
                ruleBeanWrapper.getAuditableBean().getExpression().setValue(expressionValue);
                ruleBeanWrapper.getAuditableBean().getExpression().setContext(context);
                doesPersistentRuleBeanBelongToCurrentStudy(ruleBeanWrapper);
            // ruleBeanWrapper.getAuditableBean().setId(persistentRuleBean.getId());
            // ruleBeanWrapper.getAuditableBean().getExpression().setId(persistentRuleBean.getExpression().getId());
            } else {
                ruleBeanWrapper.getAuditableBean().setOwner(getUserAccount());
            }
        }
        putRuleInCorrectContainer(ruleBeanWrapper, importContainer);
    }
    logger.info("# of Valid RuleDefs : {} , # of InValid RuleDefs : {} , # of Overwritable RuleDefs : {}", new Object[] { importContainer.getValidRuleDefs().size(), importContainer.getInValidRuleDefs().size(), importContainer.getDuplicateRuleDefs().size() });
    return importContainer;
}
Also used : Context(org.akaza.openclinica.domain.rule.expression.Context) AuditableBeanWrapper(org.akaza.openclinica.domain.rule.AuditableBeanWrapper) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) RuleBean(org.akaza.openclinica.domain.rule.RuleBean)

Example 2 with AuditableBeanWrapper

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

the class RulesPostImportContainerService method validateRuleSetRuleDefs.

public RulesPostImportContainer validateRuleSetRuleDefs(RulesPostImportContainer importContainer, RuleSetRuleBean ruleSetRuleForm) {
    RuleSetBean ruleSetBean = ruleSetRuleForm.getRuleSetBean();
    RuleSetRuleBean ruleSetRuleBean = ruleSetRuleForm;
    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();
            persistentRuleSetBean.setUpdaterAndDate(getUserAccount());
            ruleSetBeanWrapper.setAuditableBean(persistentRuleSetBean);
            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 {
            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()));
        }
        List<RuleSetBean> eventActionsRuleSetBean = getRuleSetDao().findAllEventActions(currentStudy);
        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) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean)

Example 3 with AuditableBeanWrapper

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

the class RulesPostImportContainerService method isRuleSetRuleValid.

/**
     * If the RuleSet contains any RuleSetRule object with an invalid RuleRef OID (OID that is not in DB or in the Valid Rule Lists) , Then add an error to the
     * ruleSetBeanWrapper, which in terms will make the RuleSet inValid.
     *
     * @param importContainer
     * @param ruleSetBeanWrapper
     */
private void isRuleSetRuleValid(RulesPostImportContainer importContainer, AuditableBeanWrapper<RuleSetBean> ruleSetBeanWrapper, List<RuleSetBean> eventActionsRuleSetBean) {
    for (RuleSetRuleBean ruleSetRuleBean : ruleSetBeanWrapper.getAuditableBean().getRuleSetRules()) {
        String ruleDefOid = ruleSetRuleBean.getOid();
        if (ruleSetRuleBean.getId() == null || ruleSetRuleBean.getRuleSetRuleBeanImportStatus() == RuleSetRuleBeanImportStatus.EXACT_DOUBLE) {
            EventDefinitionCRFBean eventDefinitionCRFBean = getExpressionService().getEventDefinitionCRF(ruleSetBeanWrapper.getAuditableBean().getTarget().getValue());
            if (eventDefinitionCRFBean != null && eventDefinitionCRFBean.getStatus().isDeleted()) {
                ruleSetBeanWrapper.error(createError("OCRERR_0026"));
            }
            if (importContainer.getInValidRules().get(ruleDefOid) != null || importContainer.getValidRules().get(ruleDefOid) == null && getRuleDao().findByOid(ruleDefOid, ruleSetBeanWrapper.getAuditableBean().getStudyId()) == null) {
                ruleSetBeanWrapper.error(createError("OCRERR_0025"));
            }
            if (importContainer.getValidRules().get(ruleDefOid) != null) {
                AuditableBeanWrapper<RuleBean> r = importContainer.getValidRules().get(ruleDefOid);
                if (!isRuleExpressionValid(r, ruleSetBeanWrapper.getAuditableBean()))
                    ruleSetBeanWrapper.error(createError("OCRERR_0027"));
            }
            if (importContainer.getValidRules().get(ruleDefOid) == null) {
                RuleBean rule = getRuleDao().findByOid(ruleDefOid, ruleSetBeanWrapper.getAuditableBean().getStudyId());
                AuditableBeanWrapper<RuleBean> r = new AuditableBeanWrapper<RuleBean>(rule);
                if (rule == null || !isRuleExpressionValid(r, ruleSetBeanWrapper.getAuditableBean()))
                    ruleSetBeanWrapper.error(createError("OCRERR_0027"));
            }
            if (ruleSetRuleBean.getActions().size() == 0) {
                ruleSetBeanWrapper.error(createError("OCRERR_0027"));
            }
            for (RuleActionBean ruleActionBean : ruleSetRuleBean.getActions()) {
                isRuleActionValid(ruleActionBean, ruleSetBeanWrapper, eventDefinitionCRFBean, eventActionsRuleSetBean);
            }
        }
    }
}
Also used : AuditableBeanWrapper(org.akaza.openclinica.domain.rule.AuditableBeanWrapper) RuleActionBean(org.akaza.openclinica.domain.rule.action.RuleActionBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) RuleBean(org.akaza.openclinica.domain.rule.RuleBean)

Example 4 with AuditableBeanWrapper

use of org.akaza.openclinica.domain.rule.AuditableBeanWrapper 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)

Example 5 with AuditableBeanWrapper

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

the class RuleController method validateAndSave.

@RequestMapping(value = "/studies/{study}/validateAndSaveRule", method = RequestMethod.POST)
@ResponseBody
public Response validateAndSave(@RequestBody org.openclinica.ns.rules.v31.Rules rules, Model model, HttpSession session, @PathVariable("study") String studyOid, @RequestParam("ignoreDuplicates") Boolean ignoreDuplicates) throws Exception {
    ResourceBundleProvider.updateLocale(new Locale("en_US"));
    RulesPostImportContainer rpic = mapRulesToRulesPostImportContainer(rules);
    StudyDAO studyDao = new StudyDAO(dataSource);
    StudyBean currentStudy = studyDao.findByOid(studyOid);
    UserAccountBean userAccount = getUserAccount();
    mayProceed(userAccount, currentStudy);
    getRulePostImportContainerService(currentStudy, userAccount);
    rpic = getRulePostImportContainerService(currentStudy, userAccount).validateRuleDefs(rpic);
    rpic = getRulePostImportContainerService(currentStudy, userAccount).validateRuleSetDefs(rpic);
    Response response = new Response();
    response.setValid(Boolean.TRUE);
    if (rpic.getInValidRuleDefs().size() > 0 || rpic.getInValidRuleSetDefs().size() > 0) {
        response.setValid(Boolean.FALSE);
        for (AuditableBeanWrapper<RuleBean> beanWrapper : rpic.getInValidRuleDefs()) {
            for (String error : beanWrapper.getImportErrors()) {
                org.openclinica.ns.response.v31.MessagesType messageType = new MessagesType();
                messageType.setMessage(error);
                response.getMessages().add(messageType);
            }
        }
        for (AuditableBeanWrapper<RuleSetBean> beanWrapper : rpic.getInValidRuleSetDefs()) {
            for (String error : beanWrapper.getImportErrors()) {
                org.openclinica.ns.response.v31.MessagesType messageType = new MessagesType();
                messageType.setMessage(error);
                response.getMessages().add(messageType);
            }
        }
    } else if ((rpic.getDuplicateRuleDefs().size() > 0) && !ignoreDuplicates) {
        response.setValid(Boolean.FALSE);
        for (AuditableBeanWrapper<RuleBean> beanWrapper : rpic.getDuplicateRuleDefs()) {
            org.openclinica.ns.response.v31.MessagesType messageType = new MessagesType();
            messageType.setMessage(DUPLICATE_MESSAGE);
            response.getMessages().add(messageType);
        }
    } else {
        getRuleSetService().saveImportFromDesigner(rpic);
    }
    logger.debug("RPIC READY");
    return response;
}
Also used : Locale(java.util.Locale) AuditableBeanWrapper(org.akaza.openclinica.domain.rule.AuditableBeanWrapper) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) MessagesType(org.openclinica.ns.response.v31.MessagesType) RulesTestMessagesType(org.openclinica.ns.rules_test.v31.RulesTestMessagesType) MessagesType(org.openclinica.ns.response.v31.MessagesType) Response(org.openclinica.ns.response.v31.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) RulesPostImportContainer(org.akaza.openclinica.domain.rule.RulesPostImportContainer) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) RuleBean(org.akaza.openclinica.domain.rule.RuleBean) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

AuditableBeanWrapper (org.akaza.openclinica.domain.rule.AuditableBeanWrapper)5 RuleSetRuleBean (org.akaza.openclinica.domain.rule.RuleSetRuleBean)5 RuleBean (org.akaza.openclinica.domain.rule.RuleBean)3 RuleSetBean (org.akaza.openclinica.domain.rule.RuleSetBean)3 Locale (java.util.Locale)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)1 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)1 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)1 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)1 RulesPostImportContainer (org.akaza.openclinica.domain.rule.RulesPostImportContainer)1 RunOnSchedule (org.akaza.openclinica.domain.rule.RunOnSchedule)1 RuleActionBean (org.akaza.openclinica.domain.rule.action.RuleActionBean)1 Context (org.akaza.openclinica.domain.rule.expression.Context)1 MessagesType (org.openclinica.ns.response.v31.MessagesType)1 Response (org.openclinica.ns.response.v31.Response)1 RulesTestMessagesType (org.openclinica.ns.rules_test.v31.RulesTestMessagesType)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1