Search in sources :

Example 1 with RulesPostImportContainer

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

the class DownloadRuleSetXmlServlet method prepareRulesPostImportRuleSetRuleContainer.

private RulesPostImportContainer prepareRulesPostImportRuleSetRuleContainer(String ruleSetRuleIds) {
    List<RuleSetRuleBean> ruleSetRules = new ArrayList<RuleSetRuleBean>();
    RulesPostImportContainer rpic = new RulesPostImportContainer();
    if (ruleSetRuleIds != "") {
        String[] splitExpression = ruleSetRuleIds.split(",");
        for (String string : splitExpression) {
            RuleSetRuleBean rsr = getRuleSetService().getRuleSetRuleDao().findById(Integer.valueOf(string));
            ruleSetRules.add(rsr);
        }
        rpic.populate(ruleSetRules);
    }
    return rpic;
}
Also used : RulesPostImportContainer(org.akaza.openclinica.domain.rule.RulesPostImportContainer) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) ArrayList(java.util.ArrayList)

Example 2 with RulesPostImportContainer

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

the class ImportRuleServlet method handleLoadCastor.

private RulesPostImportContainer handleLoadCastor(File xmlFile) {
    RulesPostImportContainer ruleImport = null;
    try {
        // create an XMLContext instance
        XMLContext xmlContext = new XMLContext();
        // create and set a Mapping instance
        Mapping mapping = xmlContext.createMapping();
        // mapping.loadMapping(SpringServletAccess.getPropertiesDir(context) + "mapping.xml");
        mapping.loadMapping(getCoreResources().getURL("mapping.xml"));
        xmlContext.addMapping(mapping);
        // create a new Unmarshaller
        Unmarshaller unmarshaller = xmlContext.createUnmarshaller();
        unmarshaller.setWhitespacePreserve(false);
        unmarshaller.setClass(RulesPostImportContainer.class);
        // Create a Reader to the file to unmarshal from
        FileReader reader = new FileReader(xmlFile);
        ruleImport = (RulesPostImportContainer) unmarshaller.unmarshal(reader);
        ruleImport.initializeRuleDef();
        logRuleImport(ruleImport);
        return ruleImport;
    } catch (FileNotFoundException ex) {
        throw new OpenClinicaSystemException(ex.getMessage(), ex.getCause());
    } catch (IOException ex) {
        throw new OpenClinicaSystemException(ex.getMessage(), ex.getCause());
    } catch (MarshalException e) {
        throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
    } catch (ValidationException e) {
        throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
    } catch (MappingException e) {
        throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
    }
}
Also used : RulesPostImportContainer(org.akaza.openclinica.domain.rule.RulesPostImportContainer) MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) XMLContext(org.exolab.castor.xml.XMLContext) FileNotFoundException(java.io.FileNotFoundException) Mapping(org.exolab.castor.mapping.Mapping) FileReader(java.io.FileReader) IOException(java.io.IOException) Unmarshaller(org.exolab.castor.xml.Unmarshaller) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) MappingException(org.exolab.castor.mapping.MappingException)

Example 3 with RulesPostImportContainer

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

the class ImportRuleServlet method processRequest.

@Override
public void processRequest() throws Exception {
    String action = request.getParameter("action");
    request.setAttribute("contextPath", getContextPath());
    request.setAttribute("hostPath", getHostPath());
    copyFiles();
    if (StringUtil.isBlank(action)) {
        forwardPage(Page.IMPORT_RULES);
    }
    if ("downloadrulesxsd".equalsIgnoreCase(action)) {
        // File xsdFile = new File(SpringServletAccess.getPropertiesDir(context) + "rules.xsd");
        File xsdFile = getCoreResources().getFile("rules.xsd", "rules" + File.separator);
        dowloadFile(xsdFile, "text/xml");
    }
    if ("downloadtemplate".equalsIgnoreCase(action)) {
        // File file = new File(SpringServletAccess.getPropertiesDir(context) + "rules_template.xml");
        File file = getCoreResources().getFile("rules_template.xml", "rules" + File.separator);
        dowloadFile(file, "text/xml");
    }
    if ("downloadtemplateWithNotes".equalsIgnoreCase(action)) {
        // File file = new File(SpringServletAccess.getPropertiesDir(context) + "rules_template_with_notes.xml");
        File file = getCoreResources().getFile("rules_template_with_notes.xml", "rules" + File.separator);
        dowloadFile(file, "text/xml");
    }
    if ("confirm".equalsIgnoreCase(action)) {
        try {
            File f = uploadHelper.returnFiles(request, context, getDirToSaveUploadedFileIn()).get(0);
            // File xsdFile = new File(getServletContext().getInitParameter("propertiesDir") + "rules.xsd");
            // File xsdFile = new File(SpringServletAccess.getPropertiesDir(context) + "rules.xsd");
            InputStream xsdFile = getCoreResources().getInputStream("rules.xsd");
            schemaValidator.validateAgainstSchema(f, xsdFile);
            RulesPostImportContainer importedRules = handleLoadCastor(f);
            logger.info(ub.getFirstName());
            importedRules = getRulesPostImportContainerService().validateRuleDefs(importedRules);
            importedRules = getRulesPostImportContainerService().validateRuleSetDefs(importedRules);
            session.setAttribute("importedData", importedRules);
            provideMessage(importedRules);
            forwardPage(Page.VERIFY_RULES_IMPORT_SERVLET);
        } catch (OpenClinicaSystemException re) {
            // re.printStackTrace();
            MessageFormat mf = new MessageFormat("");
            mf.applyPattern(re.getErrorCode() == null ? respage.getString("OCRERR_0016") : respage.getString(re.getErrorCode()));
            Object[] arguments = { re.getMessage() };
            if (re.getErrorCode() != null) {
                arguments = re.getErrorParams();
            }
            addPageMessage(mf.format(arguments));
            forwardPage(Page.IMPORT_RULES);
        }
    }
}
Also used : RulesPostImportContainer(org.akaza.openclinica.domain.rule.RulesPostImportContainer) MessageFormat(java.text.MessageFormat) InputStream(java.io.InputStream) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) File(java.io.File)

Example 4 with RulesPostImportContainer

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

the class RuleController method mapRulesToRulesPostImportContainer.

private RulesPostImportContainer mapRulesToRulesPostImportContainer(org.openclinica.ns.rules.v31.Rules rules) {
    RulesPostImportContainer rpic = new RulesPostImportContainer();
    for (RuleAssignmentType rat : rules.getRuleAssignment()) {
        TargetType targetType = rat.getTarget();
        ExpressionBean targetBean = new ExpressionBean(Context.OC_RULES_V1, targetType.getValue());
        RunOnScheduleType scheduleType = rules.getRuleAssignment().get(0).getRunOnSchedule();
        RuleSetBean ruleSetBean = new RuleSetBean();
        ruleSetBean.setOriginalTarget(targetBean);
        if (scheduleType != null) {
            if (!scheduleType.getTime().equals("")) {
                ruleSetBean.setRunTime(scheduleType.getTime());
            }
        }
        for (RuleRefType rrt : rat.getRuleRef()) {
            RuleSetRuleBean ruleSetRuleBean = new RuleSetRuleBean();
            ruleSetRuleBean.setOid(rrt.getOID());
            for (DiscrepancyNoteActionType discrepancyNoteActionType : rrt.getDiscrepancyNoteAction()) {
                DiscrepancyNoteActionBean action = new DiscrepancyNoteActionBean();
                action.setMessage(discrepancyNoteActionType.getMessage());
                action.setExpressionEvaluatesTo(Boolean.valueOf(discrepancyNoteActionType.getIfExpressionEvaluates()));
                action.getRuleActionRun().setInitialDataEntry(discrepancyNoteActionType.getRun().isInitialDataEntry());
                action.getRuleActionRun().setDoubleDataEntry(discrepancyNoteActionType.getRun().isDoubleDataEntry());
                action.getRuleActionRun().setAdministrativeDataEntry(discrepancyNoteActionType.getRun().isAdministrativeDataEntry());
                action.getRuleActionRun().setImportDataEntry(discrepancyNoteActionType.getRun().isImportDataEntry());
                action.getRuleActionRun().setBatch(discrepancyNoteActionType.getRun().isBatch());
                ruleSetRuleBean.addAction(action);
            }
            for (EmailActionType emailActionType : rrt.getEmailAction()) {
                EmailActionBean action = new EmailActionBean();
                action.setMessage(emailActionType.getMessage());
                action.setTo(emailActionType.getTo());
                action.setExpressionEvaluatesTo(Boolean.valueOf(emailActionType.getIfExpressionEvaluates()));
                action.getRuleActionRun().setInitialDataEntry(emailActionType.getRun().isInitialDataEntry());
                action.getRuleActionRun().setDoubleDataEntry(emailActionType.getRun().isDoubleDataEntry());
                action.getRuleActionRun().setAdministrativeDataEntry(emailActionType.getRun().isAdministrativeDataEntry());
                action.getRuleActionRun().setImportDataEntry(emailActionType.getRun().isImportDataEntry());
                action.getRuleActionRun().setBatch(emailActionType.getRun().isBatch());
                ruleSetRuleBean.addAction(action);
            }
            for (ShowActionType showActionType : rrt.getShowAction()) {
                ShowActionBean action = new ShowActionBean();
                action.setMessage(showActionType.getMessage());
                action.setExpressionEvaluatesTo(Boolean.valueOf(showActionType.getIfExpressionEvaluates()));
                action.getRuleActionRun().setInitialDataEntry(showActionType.getRun().isInitialDataEntry());
                action.getRuleActionRun().setDoubleDataEntry(showActionType.getRun().isDoubleDataEntry());
                action.getRuleActionRun().setAdministrativeDataEntry(showActionType.getRun().isAdministrativeDataEntry());
                action.getRuleActionRun().setImportDataEntry(showActionType.getRun().isImportDataEntry());
                action.getRuleActionRun().setBatch(showActionType.getRun().isBatch());
                for (PropertyType propertyType : showActionType.getDestinationProperty()) {
                    PropertyBean property = new PropertyBean();
                    property.setOid(propertyType.getOID());
                    action.addProperty(property);
                }
                ruleSetRuleBean.addAction(action);
            }
            for (HideActionType hideActionType : rrt.getHideAction()) {
                HideActionBean action = new HideActionBean();
                action.setMessage(hideActionType.getMessage());
                action.setExpressionEvaluatesTo(Boolean.valueOf(hideActionType.getIfExpressionEvaluates()));
                action.getRuleActionRun().setInitialDataEntry(hideActionType.getRun().isInitialDataEntry());
                action.getRuleActionRun().setDoubleDataEntry(hideActionType.getRun().isDoubleDataEntry());
                action.getRuleActionRun().setAdministrativeDataEntry(hideActionType.getRun().isAdministrativeDataEntry());
                action.getRuleActionRun().setImportDataEntry(hideActionType.getRun().isImportDataEntry());
                action.getRuleActionRun().setBatch(hideActionType.getRun().isBatch());
                for (PropertyType propertyType : hideActionType.getDestinationProperty()) {
                    PropertyBean property = new PropertyBean();
                    property.setOid(propertyType.getOID());
                    action.addProperty(property);
                }
                ruleSetRuleBean.addAction(action);
            }
            for (InsertActionType insertActionType : rrt.getInsertAction()) {
                InsertActionBean action = new InsertActionBean();
                action.setExpressionEvaluatesTo(Boolean.valueOf(insertActionType.getIfExpressionEvaluates()));
                action.getRuleActionRun().setInitialDataEntry(insertActionType.getRun().isInitialDataEntry());
                action.getRuleActionRun().setDoubleDataEntry(insertActionType.getRun().isDoubleDataEntry());
                action.getRuleActionRun().setAdministrativeDataEntry(insertActionType.getRun().isAdministrativeDataEntry());
                action.getRuleActionRun().setImportDataEntry(insertActionType.getRun().isImportDataEntry());
                action.getRuleActionRun().setBatch(insertActionType.getRun().isBatch());
                ruleSetRuleBean.addAction(action);
                for (PropertyType propertyType : insertActionType.getDestinationProperty()) {
                    PropertyBean property = new PropertyBean();
                    property.setOid(propertyType.getOID());
                    property.setValue(propertyType.getValue());
                    ExpressionBean expressionBean = new ExpressionBean(Context.OC_RULES_V1, propertyType.getValueExpression().getValue());
                    property.setValueExpression(expressionBean);
                    action.addProperty(property);
                }
                ruleSetRuleBean.addAction(action);
            }
            for (EventActionType eventActionType : rrt.getEventAction()) {
                EventActionBean action = new EventActionBean();
                action.setExpressionEvaluatesTo(Boolean.valueOf(eventActionType.getIfExpressionEvaluates()));
                action.setOc_oid_reference(eventActionType.getOID());
                action.getRuleActionRun().setNot_started(eventActionType.getRunOnStatus().isNotScheduled());
                action.getRuleActionRun().setScheduled(eventActionType.getRunOnStatus().isScheduled());
                action.getRuleActionRun().setData_entry_started(eventActionType.getRunOnStatus().isDataEntryStarted());
                action.getRuleActionRun().setComplete(eventActionType.getRunOnStatus().isCompleted());
                action.getRuleActionRun().setSkipped(eventActionType.getRunOnStatus().isSkipped());
                action.getRuleActionRun().setStopped(eventActionType.getRunOnStatus().isStopped());
                for (EventDestinationType eventDestinationType : eventActionType.getEventDestination()) {
                    EventPropertyBean property = new EventPropertyBean();
                    property.setProperty(eventDestinationType.getProperty());
                    ExpressionBean expressionBean = new ExpressionBean(Context.OC_RULES_V1, eventDestinationType.getValueExpression().getValue());
                    property.setValueExpression(expressionBean);
                    action.addProperty(property);
                }
                ruleSetRuleBean.addAction(action);
            }
            for (NotificationActionType notificationActionType : rrt.getNotificationAction()) {
                NotificationActionBean action = new NotificationActionBean();
                action.setExpressionEvaluatesTo(Boolean.valueOf(notificationActionType.getIfExpressionEvaluates()));
                action.setTo(notificationActionType.getTo());
                action.setSubject(notificationActionType.getSubject());
                action.setMessage(notificationActionType.getMessage());
                ruleSetRuleBean.addAction(action);
            }
            ruleSetBean.addRuleSetRule(ruleSetRuleBean);
        }
        rpic.addRuleSet(ruleSetBean);
    }
    for (RuleDefType rdt : rules.getRuleDef()) {
        RuleBean ruleBean = new RuleBean();
        ExpressionBean ruleExpressionBean = new ExpressionBean(Context.OC_RULES_V1, rdt.getExpression().getValue());
        ruleBean.setExpression(ruleExpressionBean);
        ruleBean.setDescription(rdt.getDescription());
        ruleBean.setName(rdt.getName());
        ruleBean.setOid(rdt.getOID());
        rpic.addRuleDef(ruleBean);
    }
    return rpic;
}
Also used : RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean) RulesPostImportContainer(org.akaza.openclinica.domain.rule.RulesPostImportContainer) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) RuleBean(org.akaza.openclinica.domain.rule.RuleBean)

Example 5 with RulesPostImportContainer

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

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