use of org.akaza.openclinica.domain.rule.RuleSetBean in project OpenClinica by OpenClinica.
the class RuleSetDaoTest method createStubRuleSetBean.
private RuleSetBean createStubRuleSetBean() {
RuleSetBean ruleSet = new RuleSetBean();
ruleSet.setTarget(createExpression(Context.OC_RULES_V1, "SE_ED2REPEA.F_CONC_V20.IG_CONC_CONCOMITANTMEDICATIONS.I_CONC_CON_MED_NAME"));
RuleSetRuleBean ruleSetRule = createRuleSetRule(ruleSet, null);
ruleSet.addRuleSetRule(ruleSetRule);
return ruleSet;
}
use of org.akaza.openclinica.domain.rule.RuleSetBean in project OpenClinica by OpenClinica.
the class RuleSetDaoTest method testFindById.
public void testFindById() {
// RuleSetDao ruleSetDao = (RuleSetDao) getContext().getBean("ruleSetDao");
RuleSetBean ruleSet = null;
ruleSet = ruleSetDao.findById(-1);
// Test RuleSet
assertNotNull("RuleSet is null", ruleSet);
assertEquals("The id of the retrieved RuleSet should be 1", new Integer(-1), ruleSet.getId());
assertNotNull("The Expression is null", ruleSet.getTarget());
assertNotNull("The Context is null", ruleSet.getTarget().getContext());
assertEquals("The context should be 1", new Integer(1), ruleSet.getTarget().getContext().getCode());
// Test RuleSetRules
assertEquals("The size of the RuleSetRules is not 1", new Integer(1), Integer.valueOf(ruleSet.getRuleSetRules().size()));
// Test RuleActions in RuleSetRules
assertEquals("The ActionType should be FILE_DISCREPANCY_NOTE", ActionType.FILE_DISCREPANCY_NOTE, ruleSet.getRuleSetRules().get(0).getActions().get(0).getActionType());
assertEquals("The type of the Action should be DiscrepancyNoteAction", "org.akaza.openclinica.domain.rule.action.DiscrepancyNoteActionBean", ruleSet.getRuleSetRules().get(0).getActions().get(0).getClass().getName());
assertEquals("The size of the RuleSetRules is not 2", new Integer(2), Integer.valueOf(ruleSet.getRuleSetRules().get(0).getActions().size()));
}
use of org.akaza.openclinica.domain.rule.RuleSetBean in project OpenClinica by OpenClinica.
the class RuleSetRuleDaoTest method testFindByRuleSetBeanAndRuleBean.
public void testFindByRuleSetBeanAndRuleBean() {
// RuleDao ruleDao = (RuleDao) getContext().getBean("ruleDao");
// RuleSetDao ruleSetDao = (RuleSetDao) getContext().getBean("ruleSetDao");
// RuleSetRuleDao ruleSetRuleDao = (RuleSetRuleDao) getContext().getBean("ruleSetRuleDao");
RuleBean persistentRuleBean = ruleDao.findById(-1);
RuleSetBean persistentRuleSetBean = ruleSetDao.findById(-1);
List<RuleSetRuleBean> ruleSetRules = ruleSetRuleDao.findByRuleSetBeanAndRuleBean(persistentRuleSetBean, persistentRuleBean);
assertNotNull("RuleSetRules is null", ruleSetRules);
assertEquals("The size of RuleSetRules should be 1", new Integer(1), new Integer(ruleSetRules.size()));
}
use of org.akaza.openclinica.domain.rule.RuleSetBean in project OpenClinica by OpenClinica.
the class RuleSetAuditDaoTest method testSaveOrUpdate.
public void testSaveOrUpdate() {
RuleSetBean ruleSetBean = ruleSetDao.findById(-1);
RuleSetAuditBean ruleSetAuditBean = new RuleSetAuditBean();
ruleSetAuditBean.setRuleSetBean(ruleSetBean);
try {
ruleSetAuditBean = ruleSetAuditDao.saveOrUpdate(ruleSetAuditBean);
} catch (Exception e) {
e.printStackTrace();
}
assertNotNull("Persistant id is null", ruleSetAuditBean.getId());
}
use of org.akaza.openclinica.domain.rule.RuleSetBean in project OpenClinica by OpenClinica.
the class RuleSetBulkRuleRunner method runRulesBulkFromRuleSetScreen.
public List<RuleSetBasedViewContainer> runRulesBulkFromRuleSetScreen(List<RuleSetBean> ruleSets, ExecutionMode executionMode, StudyBean currentStudy, HashMap<String, String> variableAndValue, UserAccountBean ub) {
if (variableAndValue == null || variableAndValue.isEmpty()) {
logger.warn("You must be executing Rules in Batch");
variableAndValue = new HashMap<String, String>();
}
List<RuleSetBasedViewContainer> ruleSetBasedView = new ArrayList<RuleSetBasedViewContainer>();
HashMap<String, ArrayList<RuleActionContainer>> toBeExecuted = new HashMap<String, ArrayList<RuleActionContainer>>();
for (RuleSetBean ruleSet : ruleSets) {
String key = getExpressionService().getItemOid(ruleSet.getOriginalTarget().getValue());
List<RuleActionContainer> allActionContainerListBasedOnRuleExecutionResult = null;
if (toBeExecuted.containsKey(key)) {
allActionContainerListBasedOnRuleExecutionResult = toBeExecuted.get(key);
} else {
toBeExecuted.put(key, new ArrayList<RuleActionContainer>());
allActionContainerListBasedOnRuleExecutionResult = toBeExecuted.get(key);
}
ItemDataBean itemData = null;
for (ExpressionBean expressionBean : ruleSet.getExpressions()) {
ruleSet.setTarget(expressionBean);
System.out.println("tg expression:" + ruleSet.getTarget().getValue());
for (RuleSetRuleBean ruleSetRule : ruleSet.getRuleSetRules()) {
String result = null;
RuleBean rule = ruleSetRule.getRuleBean();
ExpressionObjectWrapper eow = new ExpressionObjectWrapper(ds, currentStudy, rule.getExpression(), ruleSet, variableAndValue);
try {
OpenClinicaExpressionParser oep = new OpenClinicaExpressionParser(eow);
result = (String) oep.parseAndEvaluateExpression(rule.getExpression().getValue());
itemData = getExpressionService().getItemDataBeanFromDb(ruleSet.getTarget().getValue());
System.out.println("The result: " + result);
List<RuleActionBean> actionListBasedOnRuleExecutionResult = ruleSetRule.getActions(result, Phase.BATCH);
if (itemData != null) {
Iterator<RuleActionBean> itr = actionListBasedOnRuleExecutionResult.iterator();
while (itr.hasNext()) {
RuleActionBean ruleActionBean = itr.next();
RuleActionRunLogBean ruleActionRunLog = new RuleActionRunLogBean(ruleActionBean.getActionType(), itemData, itemData.getValue(), ruleSetRule.getRuleBean().getOid());
if (getRuleActionRunLogDao().findCountByRuleActionRunLogBean(ruleActionRunLog) > 0) {
itr.remove();
}
}
}
for (RuleActionBean ruleActionBean : actionListBasedOnRuleExecutionResult) {
RuleActionContainer ruleActionContainer = new RuleActionContainer(ruleActionBean, expressionBean, itemData, ruleSet);
allActionContainerListBasedOnRuleExecutionResult.add(ruleActionContainer);
}
logger.info("RuleSet with target : {} , Ran Rule : {} The Result was : {} , Based on that {} action will be executed in {} mode. ", new Object[] { ruleSet.getTarget().getValue(), rule.getName(), result, actionListBasedOnRuleExecutionResult.size(), executionMode.name() });
} catch (OpenClinicaSystemException osa) {
// TODO: report something useful
}
}
}
}
for (Map.Entry<String, ArrayList<RuleActionContainer>> entry : toBeExecuted.entrySet()) {
// Sort the list of actions
Collections.sort(entry.getValue(), new RuleActionContainerComparator());
for (RuleActionContainer ruleActionContainer : entry.getValue()) {
ruleActionContainer.getRuleSetBean().setTarget(ruleActionContainer.getExpressionBean());
ruleActionContainer.getRuleAction().setCuratedMessage(curateMessage(ruleActionContainer.getRuleAction(), ruleActionContainer.getRuleAction().getRuleSetRule()));
ActionProcessor ap = ActionProcessorFacade.getActionProcessor(ruleActionContainer.getRuleAction().getActionType(), ds, getMailSender(), dynamicsMetadataService, ruleActionContainer.getRuleSetBean(), getRuleActionRunLogDao(), ruleActionContainer.getRuleAction().getRuleSetRule());
RuleActionBean rab = ap.execute(RuleRunnerMode.RULSET_BULK, executionMode, ruleActionContainer.getRuleAction(), ruleActionContainer.getItemDataBean(), DiscrepancyNoteBean.ITEM_DATA, currentStudy, ub, prepareEmailContents(ruleActionContainer.getRuleSetBean(), ruleActionContainer.getRuleAction().getRuleSetRule(), currentStudy, ruleActionContainer.getRuleAction()));
System.out.println(" Action Trigger: " + ap.toString());
if (rab != null) {
ruleSetBasedView = populateForRuleSetBasedView(ruleSetBasedView, ruleActionContainer.getRuleSetBean(), ruleActionContainer.getRuleAction().getRuleSetRule().getRuleBean(), ruleActionContainer.getRuleAction().getExpressionEvaluatesTo().toString(), ruleActionContainer.getRuleAction());
}
}
}
return ruleSetBasedView;
}
Aggregations