use of org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper in project OpenClinica by OpenClinica.
the class RulesPostImportContainerService method getExpressionService.
private ExpressionService getExpressionService() {
expressionService = this.expressionService != null ? expressionService : new ExpressionService(new ExpressionObjectWrapper(ds, currentStudy, (ExpressionBean) null, (RuleSetBean) null));
expressionService.setExpressionWrapper(new ExpressionObjectWrapper(ds, currentStudy, (ExpressionBean) null, (RuleSetBean) null));
return expressionService;
}
use of org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper in project OpenClinica by OpenClinica.
the class RulesPostImportContainerService method isStratificationExpressionValid.
public boolean isStratificationExpressionValid(ExpressionBean expBean, AuditableBeanWrapper<RuleSetBean> beanWrapper) {
boolean isValid = true;
ExpressionBean expressionBean = isExpressionValid(expBean, beanWrapper);
ExpressionObjectWrapper eow = new ExpressionObjectWrapper(ds, currentStudy, expressionBean, ExpressionObjectWrapper.CONTEXT_TARGET);
ExpressionProcessor ep = ExpressionProcessorFactory.createExpressionProcessor(eow);
ep.setRespage(respage);
// String errorString = ep.isRuleExpressionValid();
String errorString = ep.isRuleAssignmentExpressionValid();
if (errorString != null) {
beanWrapper.error(errorString);
isValid = false;
}
return isValid;
}
use of org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper in project OpenClinica by OpenClinica.
the class EventActionValidator method isEventActionValueExpressionValid.
private boolean isEventActionValueExpressionValid(PropertyBean property, AuditableBeanWrapper<RuleSetBean> ruleSetBeanWrapper) {
StudyDAO studyDAO = new StudyDAO<String, ArrayList>(getDataSource());
StudyBean study = (StudyBean) studyDAO.findByPK(ruleSetBeanWrapper.getAuditableBean().getStudyId());
ExpressionBean expressionBean = isExpressionValid(property.getValueExpression(), ruleSetBeanWrapper);
ExpressionObjectWrapper eow = new ExpressionObjectWrapper(dataSource, study, expressionBean, ruleSetBeanWrapper.getAuditableBean(), ExpressionObjectWrapper.CONTEXT_VALUE_EXPRESSION);
ExpressionProcessor ep = ExpressionProcessorFactory.createExpressionProcessor(eow);
ep.setRespage(respage);
String errorString = ep.isRuleExpressionValid();
if (errorString != null) {
ruleSetBeanWrapper.error(errorString);
return false;
}
// Verify expression generates a valid date string.
try {
SimpleDateFormat df = new SimpleDateFormat(VALUE_EXPRESSION_DATE_FORMAT);
df.setLenient(false);
String valueExpression = ep.testEvaluateExpression();
Date valueExpressionDate = df.parse(valueExpression);
// date that was entered, if it's not, we assume that the date is invalid
if (!df.format(valueExpressionDate).equals(valueExpression)) {
return false;
}
} catch (ParseException ex) {
return false;
}
return true;
}
use of org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper 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.expression.ExpressionObjectWrapper in project OpenClinica by OpenClinica.
the class RulesPostImportContainerService method isRuleExpressionValid.
private boolean isRuleExpressionValid(AuditableBeanWrapper<RuleBean> ruleBeanWrapper, RuleSetBean ruleSet) {
boolean isValid = true;
ExpressionBean expressionBean = isExpressionValid(ruleBeanWrapper.getAuditableBean().getExpression(), ruleBeanWrapper);
ExpressionObjectWrapper eow = new ExpressionObjectWrapper(ds, currentStudy, expressionBean, ruleSet, ExpressionObjectWrapper.CONTEXT_EXPRESSION);
ExpressionProcessor ep = ExpressionProcessorFactory.createExpressionProcessor(eow);
ep.setRespage(respage);
String errorString = ep.isRuleExpressionValid();
if (errorString != null) {
ruleBeanWrapper.error(errorString);
isValid = false;
}
return isValid;
}
Aggregations