Search in sources :

Example 1 with org.openclinica.ns.rules.v31

use of org.openclinica.ns.rules.v31 in project OpenClinica by OpenClinica.

the class RuleController method create.

@RequestMapping(value = "/studies/{study}/validateRule", method = RequestMethod.POST)
@ResponseBody
public Response create(@RequestBody org.openclinica.ns.rules.v31.Rules rules, Model model, HttpSession session, @PathVariable("study") String studyOid) 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);
            }
        }
    }
    logger.debug("RPIC READY");
    return response;
}
Also used : Locale(java.util.Locale) 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) org.openclinica.ns.rules.v31(org.openclinica.ns.rules.v31) 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)

Example 2 with org.openclinica.ns.rules.v31

use of org.openclinica.ns.rules.v31 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) org.openclinica.ns.rules.v31(org.openclinica.ns.rules.v31) 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

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