use of org.akaza.openclinica.domain.rule.action.RuleActionBean in project OpenClinica by OpenClinica.
the class ViewCRFServlet method html.
private String html(TableFacade tableFacade) {
// set the column properties
tableFacade.setColumnProperties("versionName", "ruleName", "ruleExpression", "executeOnPlaceHolder", "actionTypePlaceHolder", "actionSummaryPlaceHolder", "link");
HtmlTable table = (HtmlTable) tableFacade.getTable();
table.setCaption(resword.getString("rule_rules"));
table.getTableRenderer().setWidth("800px");
HtmlRow row = table.getRow();
HtmlColumn versionName = row.getColumn("versionName");
versionName.setTitle(resword.getString("CRF_version"));
HtmlColumn ruleName = row.getColumn("ruleName");
ruleName.setTitle(resword.getString("rule_name"));
HtmlColumn career = row.getColumn("ruleExpression");
career.setWidth("100px");
career.setTitle(resword.getString("rule_expression"));
HtmlColumn executeOn = row.getColumn("executeOnPlaceHolder");
executeOn.setSortable(false);
executeOn.setFilterable(false);
executeOn.setTitle(resword.getString("rule_execute_on"));
executeOn.getCellRenderer().setCellEditor(new CellEditor() {
@SuppressWarnings("unchecked")
public Object getValue(Object item, String property, int rowcount) {
String value = "";
List<RuleActionBean> ruleActions = (List<RuleActionBean>) new BasicCellEditor().getValue(item, "actions", rowcount);
for (int i = 0; i < ruleActions.size(); i++) {
value += ruleActions.get(i).getExpressionEvaluatesTo();
// Do not add horizontal line after last Summary
if (i != ruleActions.size() - 1) {
value += "<hr>";
}
}
return value;
}
});
HtmlColumn actionTypePlaceHolder = row.getColumn("actionTypePlaceHolder");
actionTypePlaceHolder.setSortable(false);
actionTypePlaceHolder.setFilterable(false);
actionTypePlaceHolder.setTitle(resword.getString("rule_action_type"));
actionTypePlaceHolder.getCellRenderer().setCellEditor(new CellEditor() {
@SuppressWarnings("unchecked")
public Object getValue(Object item, String property, int rowcount) {
String value = "";
List<RuleActionBean> ruleActions = (List<RuleActionBean>) new BasicCellEditor().getValue(item, "actions", rowcount);
for (int i = 0; i < ruleActions.size(); i++) {
value += ruleActions.get(i).getActionType().name();
// Do not add horizontal line after last Summary
if (i != ruleActions.size() - 1) {
value += "<hr>";
}
}
return value;
}
});
HtmlColumn actionSummaryPlaceHolder = row.getColumn("actionSummaryPlaceHolder");
actionSummaryPlaceHolder.setSortable(false);
actionSummaryPlaceHolder.setFilterable(false);
actionSummaryPlaceHolder.setTitle(resword.getString("rule_action_summary"));
actionSummaryPlaceHolder.getCellRenderer().setCellEditor(new CellEditor() {
@SuppressWarnings("unchecked")
public Object getValue(Object item, String property, int rowcount) {
String value = "";
List<RuleActionBean> ruleActions = (List<RuleActionBean>) new BasicCellEditor().getValue(item, "actions", rowcount);
for (int i = 0; i < ruleActions.size(); i++) {
value += ruleActions.get(i).getSummary();
// Do not add horizontal line after last Summary
if (i != ruleActions.size() - 1) {
value += "<hr>";
}
}
return value;
}
});
HtmlColumn link = row.getColumn("link");
link.setSortable(false);
link.setFilterable(false);
link.setTitle(resword.getString("action"));
link.getCellRenderer().setCellEditor(new CellEditor() {
@SuppressWarnings("unchecked")
public Object getValue(Object item, String property, int rowcount) {
String param1 = (String) new BasicCellEditor().getValue(item, "ruleSetRuleId", rowcount);
String param2 = (String) new BasicCellEditor().getValue(item, "versionId", rowcount);
HtmlBuilder html = new HtmlBuilder();
html.a().href().quote().append(request.getContextPath() + "/RunRule?ruleSetRuleId=" + param1 + "&versionId=" + param2 + "&action=dryRun").quote().close();
html.img().name("bt_View1").src("images/bt_ExexuteRules.gif").border("0").end();
html.aEnd();
return html.toString();
}
});
// Return the Html.
return tableFacade.render();
}
use of org.akaza.openclinica.domain.rule.action.RuleActionBean in project OpenClinica by OpenClinica.
the class TestRuleServlet method putDummyActionInSession.
void putDummyActionInSession() {
ArrayList<RuleActionBean> actions = new ArrayList<RuleActionBean>();
DiscrepancyNoteActionBean discNoteAction = new DiscrepancyNoteActionBean();
discNoteAction.setExpressionEvaluatesTo(true);
discNoteAction.setMessage("TEST DISCREPANCY");
actions.add(discNoteAction);
session.setAttribute("testRuleActions", actions);
}
use of org.akaza.openclinica.domain.rule.action.RuleActionBean in project OpenClinica by OpenClinica.
the class RulesPostImportContainerService method addNewRuleSetBeanInList.
private void addNewRuleSetBeanInList(String target, String destination, List<RuleSetBean> eventActionsRuleSetBean) {
ExpressionBean expression = new ExpressionBean();
expression.setValue(target);
RuleSetBean ruleSetBean = new RuleSetBean();
ruleSetBean.setOriginalTarget(expression);
EventActionBean eventActionBean = new EventActionBean();
eventActionBean.setOc_oid_reference(destination);
List<RuleActionBean> listRuleActionBean = new ArrayList<RuleActionBean>();
listRuleActionBean.add(eventActionBean);
RuleSetRuleBean ruleSetRuleBean = new RuleSetRuleBean();
ruleSetRuleBean.setActions(listRuleActionBean);
ruleSetBean.addRuleSetRule(ruleSetRuleBean);
eventActionsRuleSetBean.add(ruleSetBean);
}
use of org.akaza.openclinica.domain.rule.action.RuleActionBean in project OpenClinica by OpenClinica.
the class RulesPostImportContainerService method runValidationInList.
public void runValidationInList(String target, String destination, AuditableBeanWrapper<RuleSetBean> ruleSetBeanWrapper, List<RuleSetBean> eventActionsRuleSetBean) {
// eventActionsRuleSetBean is the list of all events from rule set table
Boolean isDestinationATarget = false;
RuleSetBean isDestination = null;
for (RuleSetBean ruleSetBean : eventActionsRuleSetBean) {
if (isDestinationAndTargetMatch(parseTarget(ruleSetBean.getOriginalTarget().getValue()), parseDestination(destination)) || isDestinationAndTargetAcceptable(parseTarget(ruleSetBean.getOriginalTarget().getValue()), parseDestination(destination))) {
isDestinationATarget = true;
isDestination = ruleSetBean;
break;
}
}
if (isDestinationATarget == true && isDestination != null) {
List<RuleActionBean> ruleActions = getAllRuleActions(isDestination);
for (RuleActionBean ruleActionBean : ruleActions) {
if (ruleActionBean.getActionType().getCode() == 6) {
if (isDestinationAndTargetMatch(parseTarget(target), parseDestination(((EventActionBean) ruleActionBean).getOc_oid_reference() + ".STARTDATE"))) {
ruleSetBeanWrapper.error(createError("OCRERR_0042"));
break;
}
if (isDestinationAndTargetAcceptable(parseTarget(target), parseDestination(((EventActionBean) ruleActionBean).getOc_oid_reference()))) {
ruleSetBeanWrapper.error(createError("OCRERR_0043"));
break;
}
runValidationInList(target, ((EventActionBean) ruleActionBean).getOc_oid_reference(), ruleSetBeanWrapper, eventActionsRuleSetBean);
}
}
} else {
addNewRuleSetBeanInList(target, destination, eventActionsRuleSetBean);
}
}
use of org.akaza.openclinica.domain.rule.action.RuleActionBean 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