use of org.akaza.openclinica.domain.rule.RuleBean 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.RuleBean in project OpenClinica by OpenClinica.
the class RuleSetService method saveImportFromDesigner.
@Transactional
public void saveImportFromDesigner(RulesPostImportContainer rulesContainer) {
HashMap<String, RuleBean> ruleBeans = new HashMap<String, RuleBean>();
for (AuditableBeanWrapper<RuleBean> ruleBeanWrapper : rulesContainer.getValidRuleDefs()) {
RuleBean r = getRuleDao().saveOrUpdate(ruleBeanWrapper.getAuditableBean());
ruleBeans.put(r.getOid(), r);
}
for (AuditableBeanWrapper<RuleBean> ruleBeanWrapper : rulesContainer.getDuplicateRuleDefs()) {
RuleBean r = getRuleDao().saveOrUpdate(ruleBeanWrapper.getAuditableBean());
ruleBeans.put(r.getOid(), r);
}
for (AuditableBeanWrapper<RuleSetBean> ruleBeanWrapper : rulesContainer.getValidRuleSetDefs()) {
loadRuleSetRuleWithPersistentRules(ruleBeanWrapper.getAuditableBean());
saveRuleSet(ruleBeanWrapper.getAuditableBean());
}
for (AuditableBeanWrapper<RuleSetBean> ruleBeanWrapper : rulesContainer.getDuplicateRuleSetDefs()) {
loadRuleSetRuleWithPersistentRulesWithHashMap(ruleBeanWrapper.getAuditableBean(), ruleBeans);
replaceRuleSet(ruleBeanWrapper.getAuditableBean());
}
}
use of org.akaza.openclinica.domain.rule.RuleBean 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);
}
}
}
}
use of org.akaza.openclinica.domain.rule.RuleBean in project OpenClinica by OpenClinica.
the class RuleDaoTest method testFindByOidString.
public void testFindByOidString() {
// RuleDao ruleDao = (RuleDao) getContext().getBean("ruleDao");
String oid = "RULE_1";
RuleBean persistentRuleBean = ruleDao.findByOid(oid, 1);
assertNotNull("RuleSet is null", persistentRuleBean);
assertEquals("The id of the retrieved RuleSet should be 1", new Integer(-1), persistentRuleBean.getId());
}
use of org.akaza.openclinica.domain.rule.RuleBean in project OpenClinica by OpenClinica.
the class RuleDaoTest method testFindById.
public void testFindById() {
// RuleDao ruleDao = (RuleDao) getContext().getBean("ruleDao");
RuleBean ruleBean = null;
ruleBean = ruleDao.findById(-1);
// Test Rule
assertNotNull("RuleSet is null", ruleBean);
assertEquals("The id of the retrieved RuleSet should be 1", new Integer(-1), ruleBean.getId());
}
Aggregations