use of org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser in project OpenClinica by OpenClinica.
the class OpenClinicaV1ExpressionProcessor method testEvaluateExpression.
public HashMap<String, String> testEvaluateExpression(HashMap<String, String> testValues) {
try {
oep = new OpenClinicaExpressionParser(expressionWrapper);
HashMap<String, String> resultAndTestValues = oep.parseAndTestEvaluateExpression(e.getValue(), testValues);
String returnedResult = resultAndTestValues.get("result");
logger.debug("Test Result : " + returnedResult);
resultAndTestValues.put("ruleValidation", "rule_valid");
resultAndTestValues.put("ruleEvaluatesTo", returnedResult);
return resultAndTestValues;
} catch (OpenClinicaSystemException e) {
MessageFormat mf = new MessageFormat("");
mf.applyPattern(respage.getString(e.getErrorCode()));
Object[] arguments = e.getErrorParams();
testValues.put("ruleValidation", "rule_invalid");
testValues.put("ruleValidationFailMessage", e.getErrorCode() + " : " + mf.format(arguments));
testValues.put("ruleEvaluatesTo", "");
return testValues;
}
}
use of org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser in project OpenClinica by OpenClinica.
the class OpenClinicaV1ExpressionProcessor method isRuleExpressionValid.
public String isRuleExpressionValid() {
try {
oep = new OpenClinicaExpressionParser(expressionWrapper);
String result = oep.parseAndTestEvaluateExpression(e.getValue());
logger.debug("Test Result : " + result);
return null;
} catch (OpenClinicaSystemException e) {
MessageFormat mf = new MessageFormat("");
mf.applyPattern(respage.getString(e.getErrorCode()));
Object[] arguments = e.getErrorParams();
return e.getErrorCode() + " : " + mf.format(arguments);
}
}
use of org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser 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.logic.expressionTree.OpenClinicaExpressionParser in project OpenClinica by OpenClinica.
the class BeanPropertyService method runAction.
/**
* Complete adding to this Service to evaluate Event action
* @param ruleActionBean
* @param eow
* @param isTransaction
*/
public void runAction(RuleActionBean ruleActionBean, ExpressionBeanObjectWrapper eow, Integer userId, Boolean isTransaction) {
boolean statusMatch = false;
OpenClinicaExpressionParser oep = new OpenClinicaExpressionParser(eow);
ExpressionBeanService ebs = new ExpressionBeanService(eow);
StudyEvent studyEvent = ebs.getStudyEventFromOID(((EventActionBean) ruleActionBean).getOc_oid_reference());
RuleActionRunBean runOnStatuses = ruleActionBean.getRuleActionRun();
if (studyEvent != null) {
switch(SubjectEventStatus.getByCode(studyEvent.getSubjectEventStatusId())) {
case NOT_SCHEDULED:
if (runOnStatuses.getNot_started())
statusMatch = true;
break;
case SCHEDULED:
if (runOnStatuses.getScheduled())
statusMatch = true;
break;
case DATA_ENTRY_STARTED:
if (runOnStatuses.getData_entry_started())
statusMatch = true;
break;
case COMPLETED:
if (runOnStatuses.getComplete())
statusMatch = true;
break;
case SKIPPED:
if (runOnStatuses.getSkipped())
statusMatch = true;
break;
case STOPPED:
if (runOnStatuses.getStopped())
statusMatch = true;
break;
case SIGNED:
case LOCKED:
default:
statusMatch = false;
break;
}
} else //Special case if destination study event doesn't exist yet, ie not scheduled.
{
if (runOnStatuses.getNot_started())
statusMatch = true;
}
if (statusMatch) {
for (PropertyBean propertyBean : ((EventActionBean) ruleActionBean).getProperties()) {
// This will execute the contents of <ValueExpression>SS.ENROLLMENT_DATE + 2</ValueExpression>
LOGGER.debug("Values:expression??::" + propertyBean.getValueExpression().getValue());
Object result = oep.parseAndEvaluateExpression(propertyBean.getValueExpression().getValue());
executeAction(result, propertyBean, eow, (EventActionBean) ruleActionBean, userId, isTransaction);
}
}
}
use of org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser 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