use of org.akaza.openclinica.domain.rule.RuleSetRuleBean in project OpenClinica by OpenClinica.
the class TestRuleServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
String action = request.getParameter("action");
Validator v = new Validator(request);
if (StringUtil.isBlank(action)) {
request.setAttribute("result", resword.getString("test_rule_default_result"));
Integer ruleSetRuleId = fp.getInt("ruleSetRuleId");
if (ruleSetRuleId != 0) {
// If testing an existing ruleSetRule
RuleSetRuleBean rsr = getRuleSetRuleDao().findById(ruleSetRuleId);
rsr.getActions().size();
HashMap presetValues = new HashMap();
presetValues.put(TARGET, rsr.getRuleSetBean().getTarget().getValue());
presetValues.put(RULE, rsr.getRuleBean().getExpression().getValue());
presetValues.put(RULE_SET_RULE_ID, String.valueOf(ruleSetRuleId));
fp.setPresetValues(presetValues);
setPresetValues(presetValues);
session.setAttribute("testRuleActions", rsr.getActions());
session.setAttribute("testRulesTarget", rsr.getRuleSetBean().getTarget().getValue());
request.setAttribute("ruleSetRuleId", ruleSetRuleId);
request.setAttribute("ruleSetId", rsr.getRuleSetBean().getId());
ItemBean item = getExpressionService().getItemBeanFromExpression(rsr.getRuleSetBean().getTarget().getValue());
if (item != null) {
request.setAttribute("itemName", item.getName());
request.setAttribute("itemDefinition", item.getDescription());
} else {
StudyEventDefinitionBean studyEventDef = getExpressionService().getStudyEventDefinitionFromExpressionForEvents(rsr.getRuleSetBean().getTarget().getValue(), this.currentStudy);
request.setAttribute("itemName", studyEventDef.getName());
request.setAttribute("itemDefinition", studyEventDef.getDescription());
}
request.setAttribute("ruleSetRuleAvailable", true);
} else {
// free form testing
putDummyActionInSession();
}
session.removeAttribute("testValues");
request.setAttribute("action", "validate");
forwardPage(Page.TEST_RULES);
} else if (action.equals("validate")) {
HashMap<String, String> result = validate(v);
if (result.get("ruleValidation").equals("rule_valid")) {
addPageMessage(resword.getString("test_rules_message_valid"));
} else {
addPageMessage(resword.getString("test_rules_message_invalid"));
}
request.setAttribute("ruleValidation", result.get("ruleValidation"));
request.setAttribute("validate", "on");
request.setAttribute("ruleEvaluatesTo", resword.getString("test_rules_validate_message"));
request.setAttribute("ruleValidationFailMessage", result.get("ruleValidationFailMessage"));
request.setAttribute("action", result.get("ruleValidation").equals("rule_valid") ? "test" : "validate");
result.remove("result");
result.remove("ruleValidation");
result.remove("ruleEvaluatesTo");
result.remove("ruleValidationFailMessage");
populateTooltip(result);
session.setAttribute("testValues", result);
populteFormFields(fp);
forwardPage(Page.TEST_RULES);
} else if (action.equals("test")) {
HashMap<String, String> result = validate(v);
HashMap errors = v.validate();
if (!errors.isEmpty()) {
setInputMessages(errors);
if (result.get("ruleValidation").equals("rule_valid")) {
addPageMessage(resword.getString("test_rules_message_valid"));
} else {
addPageMessage(resword.getString("test_rules_message_invalid"));
}
request.setAttribute("ruleValidation", result.get("ruleValidation"));
request.setAttribute("validate", "on");
request.setAttribute("ruleEvaluatesTo", resword.getString("test_rules_rule_fail_invalid_data_type") + " " + resword.getString("test_rules_rule_fail_invalid_data_type_desc"));
request.setAttribute("ruleValidationFailMessage", result.get("ruleValidationFailMessage"));
request.setAttribute("action", "test");
} else {
if (result.get("ruleValidation").equals("rule_valid")) {
addPageMessage(resword.getString("test_rules_message_valid"));
} else {
addPageMessage(resword.getString("test_rules_message_invalid"));
}
request.setAttribute("action", result.get("ruleValidation").equals("rule_valid") ? "test" : "validate");
request.setAttribute("ruleValidation", result.get("ruleValidation"));
request.setAttribute("ruleEvaluatesTo", result.get("ruleEvaluatesTo"));
request.setAttribute("ruleValidationFailMessage", result.get("ruleValidationFailMessage"));
}
if (result.get("ruleValidation").equals("rule_invalid")) {
session.setAttribute("testValues", new HashMap<String, String>());
} else {
session.setAttribute("testValues", result);
}
result.remove("result");
result.remove("ruleValidation");
result.remove("ruleEvaluatesTo");
result.remove("ruleValidationFailMessage");
populateTooltip(result);
populteFormFields(fp);
forwardPage(Page.TEST_RULES);
}
}
use of org.akaza.openclinica.domain.rule.RuleSetRuleBean in project OpenClinica by OpenClinica.
the class ViewRuleAssignmentTableFactory method setDataAndLimitVariables.
@Override
public void setDataAndLimitVariables(TableFacade tableFacade) {
// initialize i18n
resword = ResourceBundleProvider.getWordsBundle(getLocale());
Limit limit = tableFacade.getLimit();
ViewRuleAssignmentFilter viewRuleAssignmentFilter = getViewRuleAssignmentFilter(limit);
ViewRuleAssignmentSort viewRuleAssignmentSort = getViewRuleAssignmentSort(limit);
viewRuleAssignmentFilter.addFilter("studyId", currentStudy.getId());
if (viewRuleAssignmentSort.getSorts().size() == 0) {
viewRuleAssignmentSort.addSort("itemName", "asc");
}
Boolean ruleSetRuleStatusFilterNotSelected = true;
for (ViewRuleAssignmentFilter.Filter filter : viewRuleAssignmentFilter.getFilters()) {
if (filter.getProperty().equals("ruleSetRuleStatus")) {
ruleSetRuleStatusFilterNotSelected = false;
}
}
if (ruleSetRuleStatusFilterNotSelected) {
viewRuleAssignmentFilter.addFilter("ruleSetRuleStatus", "1");
}
/*
* Because we are using the State feature (via stateAttr) we can do a check to see if we have a complete limit
* already. See the State feature for more details Very important to set the totalRow before trying to get the row
* start and row end variables. Very important to set the totalRow before trying to get the row start and row end
* variables.
*/
if (!limit.isComplete()) {
int totalRows = getRuleSetService().getCountWithFilter(viewRuleAssignmentFilter);
tableFacade.setTotalRows(totalRows);
}
int rowStart = limit.getRowSelect().getRowStart();
int rowEnd = limit.getRowSelect().getRowEnd();
Collection<RuleSetRuleBean> items = getRuleSetService().getWithFilterAndSort(viewRuleAssignmentFilter, viewRuleAssignmentSort, rowStart, rowEnd);
HashMap<Integer, RuleSetBean> ruleSets = new HashMap<Integer, RuleSetBean>();
Collection<HashMap<Object, Object>> theItems = new ArrayList<HashMap<Object, Object>>();
ruleSetRuleIds = new ArrayList<Integer>();
for (RuleSetRuleBean ruleSetRuleBean : items) {
RuleSetBean ruleSetBean = null;
ruleSetRuleIds.add(ruleSetRuleBean.getId());
if (ruleSets.containsKey(ruleSetRuleBean.getRuleSetBean().getId())) {
ruleSetBean = ruleSets.get(ruleSetRuleBean.getRuleSetBean().getId());
} else {
ruleSetBean = ruleSetRuleBean.getRuleSetBean();
getRuleSetService().getObjects(ruleSetBean);
ruleSets.put(ruleSetBean.getId(), ruleSetBean);
}
HashMap<Object, Object> theItem = new HashMap<Object, Object>();
theItem.put("ruleSetRunSchedule", ruleSetBean.isRunSchedule());
theItem.put("ruleSetRunTime", ruleSetBean.getRunTime());
theItem.put("ruleSetId", ruleSetBean.getId());
theItem.put("ruleSetRuleId", ruleSetRuleBean.getId());
theItem.put("ruleId", ruleSetRuleBean.getRuleBean().getId());
theItem.put("ruleSetRule", ruleSetRuleBean);
theItem.put("targetValue", ruleSetBean.getTarget().getValue());
theItem.put("studyEventDefinitionName", ruleSetBean.getStudyEventDefinitionName());
theItem.put("crf", ruleSetBean.getCrf());
theItem.put("crfVersion", ruleSetBean.getCrfVersion());
theItem.put("item", ruleSetBean.getItem());
theItem.put("crfName", ruleSetBean.getCrfName());
theItem.put("crfVersionName", ruleSetBean.getCrfVersionName());
theItem.put("groupLabel", ruleSetBean.getGroupLabel());
theItem.put("itemName", ruleSetBean.getItemName());
theItem.put("ruleSetRules", ruleSetBean.getRuleSetRules());
theItem.put("ruleName", ruleSetRuleBean.getRuleBean().getName());
theItem.put("ruleExpressionValue", ruleSetRuleBean.getRuleBean().getExpression().getValue());
theItem.put("ruleOid", ruleSetRuleBean.getRuleBean().getOid());
theItem.put("ruleDescription", ruleSetRuleBean.getRuleBean().getDescription());
theItem.put("theActions", ruleSetRuleBean.getActions());
theItem.put("ruleSetRuleStatus", "");
theItem.put("validations", "");
theItem.put("actionExecuteOn", "");
theItem.put("actionType", "XXXXXXXXX");
theItem.put("actionSummary", "");
theItems.add(theItem);
}
// Do not forget to set the items back on the tableFacade.
tableFacade.setItems(theItems);
}
use of org.akaza.openclinica.domain.rule.RuleSetRuleBean in project OpenClinica by OpenClinica.
the class ViewRuleSetServlet method orderRuleSetRulesByStatus.
List<RuleSetRuleBean> orderRuleSetRulesByStatus(RuleSetBean ruleSet) {
ArrayList<RuleSetRuleBean> availableRuleSetRules = new ArrayList<RuleSetRuleBean>();
ArrayList<RuleSetRuleBean> nonAvailableRuleSetRules = new ArrayList<RuleSetRuleBean>();
for (RuleSetRuleBean ruleSetRuleBean : ruleSet.getRuleSetRules()) {
if (ruleSetRuleBean.getStatus() == Status.AVAILABLE) {
availableRuleSetRules.add(ruleSetRuleBean);
} else {
nonAvailableRuleSetRules.add(ruleSetRuleBean);
}
}
availableRuleSetRules.addAll(nonAvailableRuleSetRules);
return availableRuleSetRules;
}
use of org.akaza.openclinica.domain.rule.RuleSetRuleBean in project OpenClinica by OpenClinica.
the class ViewRuleSetServlet method processRequest.
@Override
public void processRequest() throws Exception {
String ruleSetId = request.getParameter(RULESET_ID);
if (ruleSetId == null) {
addPageMessage(respage.getString("please_choose_a_CRF_to_view"));
forwardPage(Page.CRF_LIST);
} else {
RuleSetBean ruleSetBean = getRuleSetService().getRuleSetById(currentStudy, ruleSetId);
Boolean firstTime = true;
String validRuleSetRuleIds = "";
for (int j = 0; j < ruleSetBean.getRuleSetRules().size(); j++) {
RuleSetRuleBean rsr = ruleSetBean.getRuleSetRules().get(j);
if (rsr.getStatus() == Status.AVAILABLE) {
if (firstTime) {
validRuleSetRuleIds += rsr.getId();
firstTime = false;
} else {
validRuleSetRuleIds += "," + rsr.getId();
}
}
}
CoreResources core = (CoreResources) SpringServletAccess.getApplicationContext(context).getBean("coreResources");
String designerUrl = core.getField("designer.url") + "access?host=" + getHostPathFromSysUrl(core.getField("sysURL.base"), request.getContextPath()) + "&app=" + getContextPath(request);
UserAccountBean currentUser = (UserAccountBean) request.getSession().getAttribute("userBean");
request.setAttribute("designerUrl", designerUrl);
request.setAttribute("currentStudy", currentStudy.getOid());
request.setAttribute("providerUser", currentUser.getName());
request.setAttribute("validRuleSetRuleIds", validRuleSetRuleIds);
request.setAttribute("ruleSetRuleBeans", orderRuleSetRulesByStatus(ruleSetBean));
request.setAttribute(RULESET, ruleSetBean);
forwardPage(Page.VIEW_RULES);
}
}
use of org.akaza.openclinica.domain.rule.RuleSetRuleBean in project OpenClinica by OpenClinica.
the class UpdateRuleSetRuleServlet method processRequest.
@Override
public void processRequest() throws Exception {
String ruleSetId = request.getParameter(RULESET_ID);
String ruleSetRuleId = request.getParameter(RULESETRULE_ID);
String source = request.getParameter("source");
String action = request.getParameter(ACTION);
Status status = null;
String pageMessage = "";
if (ruleSetRuleId != null) {
RuleSetRuleBean ruleSetRule = getRuleSetRuleDao().findById(Integer.valueOf(ruleSetRuleId));
if (ruleSetRuleId != null && action.equals("remove")) {
status = Status.DELETED;
updateRuleSetRule(ruleSetRule, status);
pageMessage = "view_rules_remove_confirmation";
} else if (ruleSetRuleId != null && action.equals("restore")) {
status = Status.AVAILABLE;
ruleSetRule.getRuleSetBean().setStatus(Status.AVAILABLE);
updateRuleSetRule(ruleSetRule, status);
pageMessage = "view_rules_restore_confirmation";
}
}
if (ruleSetRuleId == null && ruleSetId != null && action.equals("remove")) {
RuleSetBean rs = getRuleSetDao().findById(Integer.valueOf(ruleSetId));
for (RuleSetRuleBean theRuleSetRule : rs.getRuleSetRules()) {
if (theRuleSetRule.getStatus() != Status.DELETED) {
status = Status.DELETED;
updateRuleSetRule(theRuleSetRule, status);
}
}
pageMessage = "view_rules_remove_confirmation";
}
addPageMessage(resword.getString(pageMessage));
if (source != null && source.equals("ViewRuleSet")) {
context.getRequestDispatcher("/ViewRuleSet?ruleSetId=" + ruleSetId).forward(request, response);
} else {
forwardPage(Page.LIST_RULE_SETS_SERVLET);
}
}
Aggregations