use of org.akaza.openclinica.domain.rule.RuleSetRuleBean in project OpenClinica by OpenClinica.
the class RulesPostImportContainerServiceTest method getRuleSet.
private RuleSetBean getRuleSet(String ruleOid, String target, String oidRef) {
RuleSetBean ruleSet = new RuleSetBean();
ruleSet.setTarget(createExpression(Context.OC_RULES_V1, target));
ruleSet.setOriginalTarget(createExpression(Context.OC_RULES_V1, target));
RuleSetRuleBean ruleSetRule = createRuleSetRule(ruleSet, ruleOid, oidRef);
ruleSet.addRuleSetRule(ruleSetRule);
return ruleSet;
}
use of org.akaza.openclinica.domain.rule.RuleSetRuleBean 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;
}
use of org.akaza.openclinica.domain.rule.RuleSetRuleBean in project OpenClinica by OpenClinica.
the class RuleSetRuleDao method findByRuleSetStudyIdAndStatusAvail.
/**
* Use this method carefully as we force an eager fetch. It is also annotated with
* Transactional so it can be called from Quartz threads.
* @param studyId
* @return List of RuleSetRuleBeans
*/
@SuppressWarnings("unchecked")
@Transactional
public ArrayList<RuleSetRuleBean> findByRuleSetStudyIdAndStatusAvail(Integer studyId) {
String query = "from " + getDomainClassName() + " ruleSetRule where ruleSetRule.ruleSetBean.studyId = :studyId and status = :status ";
org.hibernate.Query q = getCurrentSession().createQuery(query);
q.setInteger("studyId", studyId);
q.setParameter("status", org.akaza.openclinica.domain.Status.AVAILABLE);
q.setCacheable(true);
q.setCacheRegion(getDomainClassName());
//JN: enabling statistics for hibernate queries etc... to monitor the performance
Statistics stats = getSessionFactory().getStatistics();
logger.info("EntityRuleSet" + stats.getEntityInsertCount());
logger.info(stats.getQueryExecutionMaxTimeQueryString());
logger.info("hit count" + stats.getSecondLevelCacheHitCount());
stats.logSummary();
ArrayList<RuleSetRuleBean> ruleSetRules = (ArrayList<RuleSetRuleBean>) q.list();
// Forcing eager fetch of actions & their properties
for (RuleSetRuleBean ruleSetRuleBean : ruleSetRules) {
for (RuleActionBean action : ruleSetRuleBean.getActions()) {
if (action instanceof RandomizeActionBean) {
((RandomizeActionBean) action).getProperties().size();
}
if (action instanceof InsertActionBean) {
((InsertActionBean) action).getProperties().size();
}
if (action instanceof ShowActionBean) {
((ShowActionBean) action).getProperties().size();
}
if (action instanceof HideActionBean) {
((HideActionBean) action).getProperties().size();
}
if (action instanceof EventActionBean) {
((EventActionBean) action).getProperties().size();
}
}
}
return ruleSetRules;
}
use of org.akaza.openclinica.domain.rule.RuleSetRuleBean in project OpenClinica by OpenClinica.
the class RuleSetDaoTest method createRuleSetRule.
private RuleSetRuleBean createRuleSetRule(RuleSetBean ruleSet, RuleBean ruleBean) {
RuleSetRuleBean ruleSetRule = new RuleSetRuleBean();
DiscrepancyNoteActionBean ruleAction = new DiscrepancyNoteActionBean();
ruleAction.setMessage("HELLO WORLD");
ruleAction.setExpressionEvaluatesTo(true);
ruleSetRule.addAction(ruleAction);
ruleSetRule.setRuleSetBean(ruleSet);
ruleSetRule.setRuleBean(ruleBean);
return ruleSetRule;
}
use of org.akaza.openclinica.domain.rule.RuleSetRuleBean 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;
}
Aggregations