Search in sources :

Example 6 with RuleBean

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

the class RuleDaoTest method testFindByIdEmptyResultSet.

public void testFindByIdEmptyResultSet() {
    // RuleDao ruleDao = (RuleDao) getContext().getBean("ruleDao");
    RuleBean ruleBean2 = null;
    ruleBean2 = ruleDao.findById(-3);
    // Test Rule
    assertNull("RuleSet is null", ruleBean2);
}
Also used : RuleBean(org.akaza.openclinica.domain.rule.RuleBean)

Example 7 with RuleBean

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

the class RuleDaoTest method testFindByOid.

public void testFindByOid() {
    // RuleDao ruleDao = (RuleDao) getContext().getBean("ruleDao");
    RuleBean ruleBean = new RuleBean();
    ruleBean.setOid("RULE_1");
    StudyBean studyBean = new StudyBean();
    studyBean.setId(1);
    ruleBean.setStudy(studyBean);
    RuleBean persistentRuleBean = ruleDao.findByOid(ruleBean);
    assertNotNull("RuleSet is null", persistentRuleBean);
    assertEquals("The id of the retrieved RuleSet should be 1", new Integer(-1), persistentRuleBean.getId());
}
Also used : StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) RuleBean(org.akaza.openclinica.domain.rule.RuleBean)

Example 8 with RuleBean

use of org.akaza.openclinica.domain.rule.RuleBean 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 9 with RuleBean

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

the class RuleSetDaoTest method testSaveOrUpdate.

// JN:The following commented out tests are failing, suspicion is and arnd studyid and the way it is set, TODO:revisit
/*    public void testFindAllByStudy() {

   //     RuleSetDao ruleSetDao = (RuleSetDao) getContext().getBean("ruleSetDao");
        List<RuleSetBean> ruleSets = null;
        StudyBean study = new StudyBean();
        study.setId(1);
        ruleSets = ruleSetDao.findAllByStudy(study);
        assertEquals("The RuleSets List size should be 2", 2, ruleSets.size());
    }

    public void testFindByCrfVersionOrCrfAndStudyAndStudyEventDefinition() {
        CRFBean crfBean = new CRFBean();
        crfBean.setId(2);
        CRFVersionBean crfVersionBean = new CRFVersionBean();
        crfVersionBean.setId(2);
        StudyBean studyBean = new StudyBean();
        studyBean.setId(1);
        StudyEventDefinitionBean sed = new StudyEventDefinitionBean();
        sed.setId(2);

        RuleSetDao ruleSetDao = (RuleSetDao) getContext().getBean("ruleSetDao");
        List<RuleSetBean> persistentRuleSets = ruleSetDao.findByCrfVersionOrCrfAndStudyAndStudyEventDefinition(crfVersionBean, crfBean, studyBean, sed);
        assertNotNull("The returned ruleSet was null", persistentRuleSets);
        assertEquals("The List size of ruleset objects should be 2 ", persistentRuleSets.size(), 2);

    }*/
public void testSaveOrUpdate() {
    // RuleSetDao ruleSetDao = (RuleSetDao) getContext().getBean("ruleSetDao");
    // RuleDao ruleDao = (RuleDao) getContext().getBean("ruleDao");
    RuleBean persistantRuleBean = ruleDao.findById(1);
    RuleSetBean ruleSetBean = createStubRuleSetBean(persistantRuleBean);
    ruleSetBean = ruleSetDao.saveOrUpdate(ruleSetBean);
    assertNotNull("Persistant id is null", ruleSetBean.getId());
}
Also used : RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) RuleBean(org.akaza.openclinica.domain.rule.RuleBean)

Example 10 with RuleBean

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

Aggregations

RuleBean (org.akaza.openclinica.domain.rule.RuleBean)24 RuleSetRuleBean (org.akaza.openclinica.domain.rule.RuleSetRuleBean)18 RuleSetBean (org.akaza.openclinica.domain.rule.RuleSetBean)15 RuleActionBean (org.akaza.openclinica.domain.rule.action.RuleActionBean)8 ExpressionBean (org.akaza.openclinica.domain.rule.expression.ExpressionBean)8 ExpressionObjectWrapper (org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)7 OpenClinicaExpressionParser (org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser)7 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)6 RuleActionRunLogBean (org.akaza.openclinica.domain.rule.action.RuleActionRunLogBean)6 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)5 RulesPostImportContainer (org.akaza.openclinica.domain.rule.RulesPostImportContainer)5 ActionProcessor (org.akaza.openclinica.domain.rule.action.ActionProcessor)5 Map (java.util.Map)4 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)4 Locale (java.util.Locale)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)3