Search in sources :

Example 6 with RulesPostImportContainer

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

the class MetaDataReportBean method addNodeRulesData.

public void addNodeRulesData(MetaDataVersionBean a) {
    RulesPostImportContainer rpic = new RulesPostImportContainer();
    rpic.populate(a.getRuleSetRules());
    if (rpic.getRuleSets() != null && rpic.getRuleSets().size() > 0) {
        StringBuffer xml = this.getXmlOutput();
        xml.append(handleLoadCastor(rpic));
    }
}
Also used : RulesPostImportContainer(org.akaza.openclinica.domain.rule.RulesPostImportContainer)

Example 7 with RulesPostImportContainer

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

the class RulesPostImportContainerServiceTest method prepareContainer.

private ArrayList<RuleSetBean> prepareContainer() {
    RulesPostImportContainer container = new RulesPostImportContainer();
    ArrayList<RuleSetBean> ruleSets = new ArrayList<RuleSetBean>();
    ArrayList<RuleBean> ruleDefs = new ArrayList<RuleBean>();
    RuleBean rule = createRuleBean();
    RuleSetBean ruleSet = getRuleSet(rule.getOid(), "SE_REG.STARTDATE", "SE_REG3");
    RuleSetBean ruleSet2 = getRuleSet(rule.getOid(), "SE_REG3.STARTDATE", "SE_REG2");
    ruleSets.add(ruleSet);
    ruleSets.add(ruleSet2);
    // container.setRuleDefs(ruleDefs);
    return ruleSets;
}
Also used : RulesPostImportContainer(org.akaza.openclinica.domain.rule.RulesPostImportContainer) ArrayList(java.util.ArrayList) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) RuleBean(org.akaza.openclinica.domain.rule.RuleBean)

Example 8 with RulesPostImportContainer

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

the class RuleController method create.

@RequestMapping(value = "/studies/{study}/validateAndTestRule", method = RequestMethod.POST)
@ResponseBody
public org.openclinica.ns.rules_test.v31.RulesTest create(@RequestBody org.openclinica.ns.rules_test.v31.RulesTest ruleTest, Model model, HttpSession session, @PathVariable("study") String studyOid) throws Exception {
    ResourceBundleProvider.updateLocale(new Locale("en_US"));
    RulesPostImportContainer rpic = mapRulesToRulesPostImportContainer(ruleTest.getRules());
    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);
            }
        }
    }
    HashMap<String, String> p = new HashMap<String, String>();
    for (ParameterType parameterType : ruleTest.getParameters()) {
        p.put(parameterType.getKey(), parameterType.getValue());
    }
    ExpressionObjectWrapper eow = new ExpressionObjectWrapper(dataSource, currentStudy, rpic.getRuleDefs().get(0).getExpression(), rpic.getRuleSets().get(0));
    ExpressionProcessor ep = ExpressionProcessorFactory.createExpressionProcessor(eow);
    // Run expression with populated HashMap
    DateTime start = new DateTime();
    HashMap<String, String> result = ep.testEvaluateExpression(p);
    DateTime end = new DateTime();
    Duration dur = new Duration(start, end);
    PeriodFormatter yearsAndMonths = new PeriodFormatterBuilder().printZeroAlways().appendSecondsWithMillis().appendSuffix(" second", " seconds").toFormatter();
    yearsAndMonths.print(dur.toPeriod());
    // Run expression with empty HashMap to check rule validity, because
    // using illegal test values will cause invalidity
    HashMap<String, String> k = new HashMap<String, String>();
    HashMap<String, String> theResult = ep.testEvaluateExpression(k);
    ruleTest.getParameters().clear();
    for (Map.Entry<String, String> entry : result.entrySet()) {
        ParameterType parameterType = new ParameterType();
        parameterType.setKey(entry.getKey());
        parameterType.setValue(entry.getValue());
        ruleTest.getParameters().add(parameterType);
    }
    // if (theResult.get("ruleValidation").equals("rule_valid") && result.get("ruleValidation").equals("rule_invalid")) {
    // result.put("ruleValidation", "rule_valid");
    // result.put("ruleEvaluatesTo", resword.getString("test_rules_rule_fail") + " " +
    // result.get("ruleValidationFailMessage"));
    // result.remove("ruleValidationFailMessage");
    // }
    // Put on screen
    // request.setAttribute("duration", yearsAndMonths.print(dur.toPeriod()));
    RulesTestMessagesType messageType = new RulesTestMessagesType();
    messageType.setKey("duration");
    messageType.setValue(yearsAndMonths.print(dur.toPeriod()));
    ruleTest.getRulesTestMessages().add(messageType);
    return ruleTest;
}
Also used : Locale(java.util.Locale) HashMap(java.util.HashMap) DateTime(org.joda.time.DateTime) ExpressionProcessor(org.akaza.openclinica.domain.rule.expression.ExpressionProcessor) org.openclinica.ns.rules.v31(org.openclinica.ns.rules.v31) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) RulesTestMessagesType(org.openclinica.ns.rules_test.v31.RulesTestMessagesType) ParameterType(org.openclinica.ns.rules_test.v31.ParameterType) PeriodFormatter(org.joda.time.format.PeriodFormatter) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) MessagesType(org.openclinica.ns.response.v31.MessagesType) RulesTestMessagesType(org.openclinica.ns.rules_test.v31.RulesTestMessagesType) Duration(org.joda.time.Duration) 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) PeriodFormatterBuilder(org.joda.time.format.PeriodFormatterBuilder) ExpressionObjectWrapper(org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper) Map(java.util.Map) HashMap(java.util.HashMap) 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 9 with RulesPostImportContainer

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

Example 10 with RulesPostImportContainer

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

the class VerifyImportedRuleServlet method processRequest.

@Override
public void processRequest() throws Exception {
    String action = request.getParameter("action");
    FormProcessor fp = new FormProcessor(request);
    if ("confirm".equalsIgnoreCase(action)) {
        // session.setAttribute("crf", new CRFBean());
        RulesPostImportContainer rulesContainer = (RulesPostImportContainer) session.getAttribute("importedData");
        logger.info("Size of ruleDefs : " + rulesContainer.getRuleDefs().size());
        logger.info("Size of ruleSets : " + rulesContainer.getRuleSets().size());
        forwardPage(Page.VERIFY_RULES_IMPORT);
    }
    if ("save".equalsIgnoreCase(action)) {
        RulesPostImportContainer rulesContainer = (RulesPostImportContainer) session.getAttribute("importedData");
        getRuleSetService().saveImport(rulesContainer);
        MessageFormat mf = new MessageFormat("");
        mf.applyPattern(resword.getString("successful_rule_upload"));
        Object[] arguments = { rulesContainer.getValidRuleDefs().size() + rulesContainer.getDuplicateRuleDefs().size(), rulesContainer.getValidRuleSetDefs().size() + rulesContainer.getDuplicateRuleSetDefs().size() };
        addPageMessage(mf.format(arguments));
        ArrayList pageMessages = (ArrayList) request.getAttribute(PAGE_MESSAGE);
        session.setAttribute("pageMessages", pageMessages);
        response.sendRedirect(request.getContextPath() + Page.MANAGE_STUDY_MODULE.getFileName());
    }
}
Also used : RulesPostImportContainer(org.akaza.openclinica.domain.rule.RulesPostImportContainer) MessageFormat(java.text.MessageFormat) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList)

Aggregations

RulesPostImportContainer (org.akaza.openclinica.domain.rule.RulesPostImportContainer)10 RuleSetRuleBean (org.akaza.openclinica.domain.rule.RuleSetRuleBean)6 RuleBean (org.akaza.openclinica.domain.rule.RuleBean)5 RuleSetBean (org.akaza.openclinica.domain.rule.RuleSetBean)5 ArrayList (java.util.ArrayList)3 Locale (java.util.Locale)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)3 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)3 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)3 MessagesType (org.openclinica.ns.response.v31.MessagesType)3 Response (org.openclinica.ns.response.v31.Response)3 org.openclinica.ns.rules.v31 (org.openclinica.ns.rules.v31)3 RulesTestMessagesType (org.openclinica.ns.rules_test.v31.RulesTestMessagesType)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 MessageFormat (java.text.MessageFormat)2 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1