use of org.akaza.openclinica.domain.rule.action.RuleActionBean in project OpenClinica by OpenClinica.
the class RuleSetRuleBean method getAllActionsWithEvaluatesToAsKey.
@Transient
public HashMap<String, ArrayList<RuleActionBean>> getAllActionsWithEvaluatesToAsKey() {
HashMap<String, ArrayList<RuleActionBean>> h = new HashMap<String, ArrayList<RuleActionBean>>();
for (RuleActionBean action : actions) {
String key = action.getExpressionEvaluatesTo().toString();
if (h.containsKey(key)) {
h.get(key).add(action);
} else {
ArrayList<RuleActionBean> a = new ArrayList<RuleActionBean>();
a.add(action);
h.put(key, a);
}
}
return h;
}
use of org.akaza.openclinica.domain.rule.action.RuleActionBean in project OpenClinica by OpenClinica.
the class RuleSetRuleBean method getActionsAsKeyPair.
@Transient
public HashMap<String, ArrayList<String>> getActionsAsKeyPair(String actionEvaluatesTo) {
HashMap<String, ArrayList<String>> h = new HashMap<String, ArrayList<String>>();
for (RuleActionBean action : actions) {
String key = action.getExpressionEvaluatesTo().toString();
if (actionEvaluatesTo.equals(key)) {
if (h.containsKey(key)) {
h.get(key).add(action.getSummary());
} else {
ArrayList<String> a = new ArrayList<String>();
a.add(action.getSummary());
h.put(key, a);
}
}
}
return h;
}
use of org.akaza.openclinica.domain.rule.action.RuleActionBean in project OpenClinica by OpenClinica.
the class ImportDataRuleRunner method runRules.
@Transactional
private MessageContainer runRules(StudyBean currentStudy, UserAccountBean ub, HashMap<String, String> variableAndValue, HashMap<String, ArrayList<RuleActionContainer>> toBeExecuted) {
//Copied from DataEntryRuleRunner runRules
MessageContainer messageContainer = new MessageContainer();
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()) {
logger.info("START Expression is : {} , RuleAction : {} ", new Object[] { ruleActionContainer.getExpressionBean().getValue(), ruleActionContainer.getRuleAction().toString() });
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());
ItemDataBean itemData = getExpressionService().getItemDataBeanFromDb(ruleActionContainer.getRuleSetBean().getTarget().getValue());
RuleActionBean rab = ap.execute(RuleRunnerMode.IMPORT_DATA, ExecutionMode.SAVE, ruleActionContainer.getRuleAction(), itemData, DiscrepancyNoteBean.ITEM_DATA, currentStudy, ub, prepareEmailContents(ruleActionContainer.getRuleSetBean(), ruleActionContainer.getRuleAction().getRuleSetRule(), currentStudy, ruleActionContainer.getRuleAction()));
if (rab != null) {
if (rab instanceof ShowActionBean) {
messageContainer.add(getExpressionService().getGroupOidOrdinal(ruleActionContainer.getRuleSetBean().getTarget().getValue()), rab);
} else {
messageContainer.add(getExpressionService().getGroupOrdninalConcatWithItemOid(ruleActionContainer.getRuleSetBean().getTarget().getValue()), ruleActionContainer.getRuleAction());
}
}
logger.info("END Expression is : {} , RuleAction : {} ", new Object[] { ruleActionContainer.getExpressionBean().getValue(), ruleActionContainer.getRuleAction().toString() });
}
}
return messageContainer;
}
use of org.akaza.openclinica.domain.rule.action.RuleActionBean in project OpenClinica by OpenClinica.
the class RuleSetBulkRuleRunner method runRulesBulkFromRuleSetScreenOLD.
public List<RuleSetBasedViewContainer> runRulesBulkFromRuleSetScreenOLD(List<RuleSetBean> ruleSets, Boolean dryRun, 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>();
for (RuleSetBean ruleSet : ruleSets) {
for (ExpressionBean expressionBean : ruleSet.getExpressions()) {
ruleSet.setTarget(expressionBean);
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());
// HashMap<String, ArrayList<RuleActionBean>> actionsToBeExecuted = ruleSetRule.getAllActionsWithEvaluatesToAsKey(result);
List<RuleActionBean> actionListBasedOnRuleExecutionResult = ruleSetRule.getActions(result, Phase.BATCH);
ItemDataBean itemData = getExpressionService().getItemDataBeanFromDb(ruleSet.getTarget().getValue());
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();
}
}
}
logger.info("RuleSet with target : {} , Ran Rule : {} The Result was : {} , Based on that {} action will be executed ", new Object[] { ruleSet.getTarget().getValue(), rule.getName(), result, actionListBasedOnRuleExecutionResult.size() });
if (actionListBasedOnRuleExecutionResult.size() > 0) {
for (RuleActionBean ruleAction : actionListBasedOnRuleExecutionResult) {
ruleAction.setCuratedMessage(curateMessage(ruleAction, ruleSetRule));
// getDiscrepancyNoteService().saveFieldNotes(ruleAction.getSummary(), itemDataBeanId, "ItemData", currentStudy, ub);
ActionProcessor ap = ActionProcessorFacade.getActionProcessor(ruleAction.getActionType(), ds, getMailSender(), dynamicsMetadataService, ruleSet, getRuleActionRunLogDao(), ruleSetRule);
RuleActionBean rab = ap.execute(RuleRunnerMode.RULSET_BULK, ExecutionMode.SAVE, ruleAction, itemData, DiscrepancyNoteBean.ITEM_DATA, currentStudy, ub, prepareEmailContents(ruleSet, ruleSetRule, currentStudy, ruleAction));
if (rab != null) {
ruleSetBasedView = populateForRuleSetBasedView(ruleSetBasedView, ruleSet, rule, result, ruleAction);
}
}
}
} catch (OpenClinicaSystemException osa) {
String errorMessage = "RuleSet with target : " + ruleSet.getTarget().getValue() + " , Ran Rule : " + rule.getName() + " , It resulted in an error due to : " + osa.getMessage();
// log error
logger.warn(errorMessage);
}
}
}
}
return ruleSetBasedView;
}
use of org.akaza.openclinica.domain.rule.action.RuleActionBean in project OpenClinica by OpenClinica.
the class RulesPostImportContainerService method isRuleSetRuleValid.
/**
* If the RuleSet contains any RuleSetRule object with an invalid RuleRef OID (OID that is not in DB or in the Valid Rule Lists) , Then add an error to the
* ruleSetBeanWrapper, which in terms will make the RuleSet inValid.
*
* @param importContainer
* @param ruleSetBeanWrapper
*/
private void isRuleSetRuleValid(RulesPostImportContainer importContainer, AuditableBeanWrapper<RuleSetBean> ruleSetBeanWrapper, List<RuleSetBean> eventActionsRuleSetBean) {
for (RuleSetRuleBean ruleSetRuleBean : ruleSetBeanWrapper.getAuditableBean().getRuleSetRules()) {
String ruleDefOid = ruleSetRuleBean.getOid();
if (ruleSetRuleBean.getId() == null || ruleSetRuleBean.getRuleSetRuleBeanImportStatus() == RuleSetRuleBeanImportStatus.EXACT_DOUBLE) {
EventDefinitionCRFBean eventDefinitionCRFBean = getExpressionService().getEventDefinitionCRF(ruleSetBeanWrapper.getAuditableBean().getTarget().getValue());
if (eventDefinitionCRFBean != null && eventDefinitionCRFBean.getStatus().isDeleted()) {
ruleSetBeanWrapper.error(createError("OCRERR_0026"));
}
if (importContainer.getInValidRules().get(ruleDefOid) != null || importContainer.getValidRules().get(ruleDefOid) == null && getRuleDao().findByOid(ruleDefOid, ruleSetBeanWrapper.getAuditableBean().getStudyId()) == null) {
ruleSetBeanWrapper.error(createError("OCRERR_0025"));
}
if (importContainer.getValidRules().get(ruleDefOid) != null) {
AuditableBeanWrapper<RuleBean> r = importContainer.getValidRules().get(ruleDefOid);
if (!isRuleExpressionValid(r, ruleSetBeanWrapper.getAuditableBean()))
ruleSetBeanWrapper.error(createError("OCRERR_0027"));
}
if (importContainer.getValidRules().get(ruleDefOid) == null) {
RuleBean rule = getRuleDao().findByOid(ruleDefOid, ruleSetBeanWrapper.getAuditableBean().getStudyId());
AuditableBeanWrapper<RuleBean> r = new AuditableBeanWrapper<RuleBean>(rule);
if (rule == null || !isRuleExpressionValid(r, ruleSetBeanWrapper.getAuditableBean()))
ruleSetBeanWrapper.error(createError("OCRERR_0027"));
}
if (ruleSetRuleBean.getActions().size() == 0) {
ruleSetBeanWrapper.error(createError("OCRERR_0027"));
}
for (RuleActionBean ruleActionBean : ruleSetRuleBean.getActions()) {
isRuleActionValid(ruleActionBean, ruleSetBeanWrapper, eventDefinitionCRFBean, eventActionsRuleSetBean);
}
}
}
}
Aggregations