Coverage Report - org.kuali.rice.kew.actionlist.web.ActionListAction
 
Classes in this File Line Coverage Branch Coverage Complexity
ActionListAction
0%
0/419
0%
0/254
6.704
ActionListAction$ActionItemComparator
0%
0/23
0%
0/14
6.704
 
 1  
 /*
 2  
  * Copyright 2006-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 package org.kuali.rice.kew.actionlist.web;
 18  
 
 19  
 import org.apache.commons.collections.ComparatorUtils;
 20  
 import org.apache.commons.lang.StringUtils;
 21  
 import org.apache.struts.action.ActionForm;
 22  
 import org.apache.struts.action.ActionForward;
 23  
 import org.apache.struts.action.ActionMapping;
 24  
 import org.apache.struts.action.ActionMessage;
 25  
 import org.apache.struts.action.ActionMessages;
 26  
 import org.displaytag.pagination.PaginatedList;
 27  
 import org.displaytag.properties.SortOrderEnum;
 28  
 import org.displaytag.util.LookupUtil;
 29  
 import org.kuali.rice.core.api.config.property.ConfigContext;
 30  
 import org.kuali.rice.core.api.exception.RiceRuntimeException;
 31  
 import org.kuali.rice.kew.actionitem.ActionItem;
 32  
 import org.kuali.rice.kew.actionitem.ActionItemActionListExtension;
 33  
 import org.kuali.rice.kew.actionlist.ActionListFilter;
 34  
 import org.kuali.rice.kew.actionlist.ActionToTake;
 35  
 import org.kuali.rice.kew.actionlist.CustomActionListAttribute;
 36  
 import org.kuali.rice.kew.actionlist.PaginatedActionList;
 37  
 import org.kuali.rice.kew.actionlist.service.ActionListService;
 38  
 import org.kuali.rice.kew.actionrequest.Recipient;
 39  
 import org.kuali.rice.kew.actions.ActionSet;
 40  
 import org.kuali.rice.kew.actions.asyncservices.ActionInvocation;
 41  
 import org.kuali.rice.kew.exception.WorkflowException;
 42  
 import org.kuali.rice.kew.preferences.Preferences;
 43  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
 44  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValueActionListExtension;
 45  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 46  
 import org.kuali.rice.kew.util.KEWConstants;
 47  
 import org.kuali.rice.kew.util.PerformanceLogger;
 48  
 import org.kuali.rice.kim.api.entity.principal.Principal;
 49  
 import org.kuali.rice.kim.api.entity.principal.PrincipalContract;
 50  
 import org.kuali.rice.kim.bo.Person;
 51  
 
 52  
 import org.kuali.rice.kns.UserSession;
 53  
 import org.kuali.rice.kns.exception.AuthorizationException;
 54  
 import org.kuali.rice.kns.util.GlobalVariables;
 55  
 import org.kuali.rice.kns.web.struts.action.KualiAction;
 56  
 import org.kuali.rice.kns.web.ui.ExtraButton;
 57  
 
 58  
 import javax.servlet.http.HttpServletRequest;
 59  
 import javax.servlet.http.HttpServletResponse;
 60  
 import java.util.ArrayList;
 61  
 import java.util.Arrays;
 62  
 import java.util.Collection;
 63  
 import java.util.Collections;
 64  
 import java.util.Comparator;
 65  
 import java.util.Iterator;
 66  
 import java.util.LinkedHashMap;
 67  
 import java.util.List;
 68  
 import java.util.Map;
 69  
 
 70  
 
 71  
 /**
 72  
  * Action doing Action list stuff
 73  
  *
 74  
  * @author Kuali Rice Team (rice.collab@kuali.org)a
 75  
  *
 76  
  */
 77  0
 public class ActionListAction extends KualiAction {
 78  
 
 79  0
         private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ActionListAction.class);
 80  
 
 81  
     private static final String ACTION_LIST_KEY = "actionList";
 82  
     private static final String ACTION_LIST_PAGE_KEY = "actionListPage";
 83  
     private static final String ACTION_LIST_USER_KEY = "actionList.user";
 84  
     private static final String REQUERY_ACTION_LIST_KEY = "requeryActionList";
 85  
 
 86  
     private static final String ACTIONREQUESTCD_PROP = "actionRequestCd";
 87  
     private static final String CUSTOMACTIONLIST_PROP = "customActionList";
 88  
     private static final String ACTIONITEM_PROP = "actionitem";
 89  
     private static final String HELPDESK_ACTIONLIST_USERNAME = "helpDeskActionListUserName";
 90  
 
 91  
     private static final String ACTIONITEM_ACTIONREQUESTCD_INVALID_ERRKEY = "actionitem.actionrequestcd.invalid";
 92  
     private static final String ACTIONLIST_BAD_CUSTOM_ACTION_LIST_ITEMS_ERRKEY = "actionlist.badCustomActionListItems";
 93  
         private static final String ACTIONLIST_BAD_ACTION_ITEMS_ERRKEY = "actionlist.badActionItems";
 94  
         private static final String HELPDESK_LOGIN_EMPTY_ERRKEY = "helpdesk.login.empty";
 95  
         private static final String HELPDESK_LOGIN_INVALID_ERRKEY = "helpdesk.login.invalid";
 96  
 
 97  
 
 98  
         @Override
 99  
         public ActionForward execute(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
 100  0
             ActionListForm frm = (ActionListForm)actionForm;
 101  0
             request.setAttribute("Constants", getServlet().getServletContext().getAttribute("KEWConstants"));
 102  0
             request.setAttribute("preferences", getUserSession().retrieveObject(KEWConstants.PREFERENCES));
 103  0
             frm.setHeaderButtons(getHeaderButtons());
 104  0
             return super.execute(mapping, actionForm, request, response);
 105  
     }
 106  
 
 107  
     private List<ExtraButton> getHeaderButtons(){
 108  0
             List<ExtraButton> headerButtons = new ArrayList<ExtraButton>();
 109  0
             ExtraButton eb = new ExtraButton();
 110  0
             String krBaseUrl = ConfigContext.getCurrentContextConfig().getKRBaseURL();
 111  0
             eb.setExtraButtonSource( krBaseUrl + "/images/tinybutton-preferences.gif");
 112  0
             eb.setExtraButtonOnclick("Preferences.do?returnMapping=viewActionList");
 113  
 
 114  0
             headerButtons.add(eb);
 115  0
             eb = new ExtraButton();
 116  0
             eb.setExtraButtonSource(krBaseUrl + "/images/tinybutton-refresh.gif");
 117  0
             eb.setExtraButtonProperty("methodToCall.start");
 118  
 
 119  0
             headerButtons.add(eb);
 120  0
             eb = new ExtraButton();
 121  0
             eb.setExtraButtonSource(krBaseUrl + "/images/tinybutton-filter.gif");
 122  0
             eb.setExtraButtonOnclick("javascript: window.open('ActionListFilter.do?methodToCall=start');");
 123  0
             headerButtons.add(eb);
 124  
 
 125  
 
 126  0
             return headerButtons;
 127  
     }
 128  
 
 129  
 
 130  
 
 131  
         @Override
 132  
         protected ActionForward defaultDispatch(ActionMapping mapping,
 133  
                         ActionForm form, HttpServletRequest request,
 134  
                         HttpServletResponse response) throws Exception {
 135  0
                 return start(mapping, form, request, response);
 136  
         }
 137  
 
 138  
         public ActionForward start(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
 139  0
         PerformanceLogger plog = new PerformanceLogger();
 140  0
         plog.log("Starting ActionList fetch");
 141  0
         ActionListForm form = (ActionListForm) actionForm;
 142  0
         ActionListService actionListSrv = KEWServiceLocator.getActionListService();
 143  
 
 144  
 
 145  
         // process display tag parameters
 146  0
         Integer page = form.getPage();
 147  0
         String sortCriterion = form.getSort();
 148  0
         SortOrderEnum sortOrder = SortOrderEnum.ASCENDING;
 149  0
         final UserSession uSession = getUserSession();
 150  
         
 151  0
         if (form.getDir() != null) {
 152  0
                 sortOrder = parseSortOrder(form.getDir());
 153  
         }
 154  0
         else if ( !StringUtils.isEmpty((String) uSession.retrieveObject(KEWConstants.SORT_ORDER_ATTR_NAME)))     {
 155  0
                 sortOrder = parseSortOrder((String) uSession.retrieveObject(KEWConstants.SORT_ORDER_ATTR_NAME));
 156  
         }
 157  
         // if both the page and the sort criteria are null, that means its the first entry into the page, use defaults
 158  0
         if (page == null && sortCriterion == null) {
 159  0
                 page = Integer.valueOf(1);
 160  0
                 sortCriterion = ActionItemComparator.DOCUMENT_ID;
 161  
         }
 162  0
         else if ( !StringUtils.isEmpty((String) uSession.retrieveObject(KEWConstants.SORT_CRITERIA_ATTR_NAME)))     {
 163  0
                 sortCriterion = (String) uSession.retrieveObject(KEWConstants.SORT_CRITERIA_ATTR_NAME);
 164  
         }
 165  
         // if the page is still null, that means the user just performed a sort action, pull the currentPage off of the form
 166  0
         if (page == null) {
 167  0
                 page = form.getCurrentPage();
 168  
         }
 169  
 
 170  
         // update the values of the "current" display tag parameters
 171  0
         form.setCurrentPage(page);
 172  0
         if (!StringUtils.isEmpty(sortCriterion)) {
 173  0
                 form.setCurrentSort(sortCriterion);
 174  0
                 form.setCurrentDir(getSortOrderValue(sortOrder));
 175  
         }
 176  
 
 177  
         // reset the default action on the form
 178  0
         form.setDefaultActionToTake("NONE");
 179  
 
 180  0
         boolean freshActionList = true;
 181  
         // retrieve cached action list
 182  0
         List actionList = (List)request.getSession().getAttribute(ACTION_LIST_KEY);
 183  0
         plog.log("Time to initialize");
 184  
         try {
 185  
             //UserSession uSession = getUserSession(request);
 186  0
             String principalId = null;
 187  0
             if (uSession.retrieveObject(KEWConstants.ACTION_LIST_FILTER_ATTR_NAME) == null) {
 188  0
                 ActionListFilter filter = new ActionListFilter();
 189  0
                 filter.setDelegationType(KEWConstants.DELEGATION_SECONDARY);
 190  0
                 filter.setExcludeDelegationType(true);
 191  0
                 uSession.addObject(KEWConstants.ACTION_LIST_FILTER_ATTR_NAME, filter);
 192  
             }
 193  
 
 194  0
             final ActionListFilter filter = (ActionListFilter) uSession.retrieveObject(KEWConstants.ACTION_LIST_FILTER_ATTR_NAME);
 195  
             /* 'forceListRefresh' variable used to signify that the action list filter has changed
 196  
              * any time the filter changes the action list must be refreshed or filter may not take effect on existing
 197  
              * list items... only exception is if action list has not loaded previous and fetching of the list has not
 198  
              * occurred yet
 199  
              */
 200  0
             boolean forceListRefresh = request.getSession().getAttribute(REQUERY_ACTION_LIST_KEY) != null;
 201  0
             if (uSession.retrieveObject(KEWConstants.HELP_DESK_ACTION_LIST_PRINCIPAL_ATTR_NAME) != null) {
 202  0
                     principalId = ((PrincipalContract) uSession.retrieveObject(KEWConstants.HELP_DESK_ACTION_LIST_PRINCIPAL_ATTR_NAME)).getPrincipalId();
 203  
             } else {
 204  0
                 if (!StringUtils.isEmpty(form.getDocType())) {
 205  0
                         filter.setDocumentType(form.getDocType());
 206  0
                         filter.setExcludeDocumentType(false);
 207  0
                     forceListRefresh = true;
 208  
                 }
 209  0
                 principalId = uSession.getPerson().getPrincipalId();
 210  
             }
 211  
 
 212  0
             final Preferences preferences = (Preferences) getUserSession().retrieveObject(KEWConstants.PREFERENCES);
 213  
 
 214  0
             if (!StringUtils.isEmpty(form.getDelegationId())) {
 215  0
                     if (!KEWConstants.DELEGATION_DEFAULT.equals(form.getDelegationId())) {
 216  
                             // If the user can filter by both primary and secondary delegation, and both drop-downs have non-default values assigned,
 217  
                             // then reset the primary delegation drop-down's value when the primary delegation drop-down's value has remained unaltered
 218  
                             // but the secondary drop-down's value has been altered; but if one of these alteration situations does not apply, reset the
 219  
                             // secondary delegation drop-down.
 220  0
                             if (StringUtils.isNotBlank(form.getPrimaryDelegateId()) && !KEWConstants.PRIMARY_DELEGATION_DEFAULT.equals(form.getPrimaryDelegateId())){
 221  0
                                     if (form.getPrimaryDelegateId().equals(request.getParameter("oldPrimaryDelegateId")) &&
 222  
                                                     !form.getDelegationId().equals(request.getParameter("oldDelegationId"))) {
 223  0
                                             form.setPrimaryDelegateId(KEWConstants.PRIMARY_DELEGATION_DEFAULT);
 224  
                                     } else {
 225  0
                                             form.setDelegationId(KEWConstants.DELEGATION_DEFAULT);
 226  
                                     }
 227  0
                             } else if (StringUtils.isNotBlank(filter.getPrimaryDelegateId()) &&
 228  
                                             !KEWConstants.PRIMARY_DELEGATION_DEFAULT.equals(filter.getPrimaryDelegateId())) {
 229  
                                     // If the primary delegation drop-down is invisible but a primary delegation filter is in place, and if the secondary delegation
 230  
                                     // drop-down has a non-default value selected, then reset the primary delegation filtering.
 231  0
                                     filter.setPrimaryDelegateId(KEWConstants.PRIMARY_DELEGATION_DEFAULT);
 232  
                             }
 233  
                     }
 234  
                     // Enable the secondary delegation filtering.
 235  0
                            filter.setDelegatorId(form.getDelegationId());
 236  0
                            filter.setExcludeDelegatorId(false);
 237  0
                            actionList = null;
 238  
             }
 239  
 
 240  0
             if (!StringUtils.isEmpty(form.getPrimaryDelegateId())) {
 241  
                     // If the secondary delegation drop-down is invisible but a secondary delegation filter is in place, and if the primary delegation
 242  
                     // drop-down has a non-default value selected, then reset the secondary delegation filtering.
 243  0
                     if (StringUtils.isBlank(form.getDelegationId()) && !KEWConstants.PRIMARY_DELEGATION_DEFAULT.equals(form.getPrimaryDelegateId()) && 
 244  
                                     StringUtils.isNotBlank(filter.getDelegatorId()) &&
 245  
                                                     !KEWConstants.DELEGATION_DEFAULT.equals(filter.getDelegatorId())) {
 246  0
                             filter.setDelegatorId(KEWConstants.DELEGATION_DEFAULT);
 247  
                     }
 248  
                     // Enable the primary delegation filtering.
 249  0
                     filter.setPrimaryDelegateId(form.getPrimaryDelegateId());
 250  0
                     filter.setExcludeDelegatorId(false);
 251  0
                     actionList = null;
 252  
             }
 253  
             
 254  
             // if the user has changed, we need to refresh the action list
 255  0
             if (!principalId.equals(request.getSession().getAttribute(ACTION_LIST_USER_KEY))) {
 256  0
                 actionList = null;
 257  
             }
 258  
 
 259  0
             if (isOutboxMode(form, request, preferences)) {
 260  0
                     actionList = new ArrayList(actionListSrv.getOutbox(principalId, filter));
 261  0
                     form.setOutBoxEmpty(actionList.isEmpty());
 262  
             } else {
 263  0
                 if (actionList == null) {
 264  
                         //clear out old User Option records if they exist
 265  0
                         actionListSrv.refreshActionList(getUserSession().getPerson().getPrincipalId());
 266  
                         // fetch the action list
 267  0
                     actionList = new ArrayList(actionListSrv.getActionList(principalId, filter));
 268  0
                     request.getSession().setAttribute(ACTION_LIST_USER_KEY, principalId);
 269  0
                 } else if (forceListRefresh) {
 270  
                         // force a refresh... usually based on filter change or parameter specifying refresh needed
 271  0
                     actionList = new ArrayList(actionListSrv.getActionList(principalId, filter));
 272  0
                     request.getSession().setAttribute(ACTION_LIST_USER_KEY, principalId);
 273  0
                 } else if (actionListSrv.refreshActionList(getUserSession().getPerson().getPrincipalId())) {
 274  0
                     actionList = new ArrayList(actionListSrv.getActionList(principalId, filter));
 275  0
                     request.getSession().setAttribute(ACTION_LIST_USER_KEY, principalId);
 276  
                 } else {
 277  0
                         Boolean update = (Boolean) uSession.retrieveObject(KEWConstants.UPDATE_ACTION_LIST_ATTR_NAME);
 278  0
                         if (update == null || !update) {
 279  0
                                 freshActionList = false;
 280  
                         }
 281  
                 }
 282  0
                 request.getSession().setAttribute(ACTION_LIST_KEY, actionList);
 283  
             }
 284  
             // reset the requery action list key
 285  0
             request.getSession().setAttribute(REQUERY_ACTION_LIST_KEY, null);
 286  
 
 287  
             // build the drop-down of delegators
 288  0
             if (KEWConstants.DELEGATORS_ON_ACTION_LIST_PAGE.equalsIgnoreCase(preferences.getDelegatorFilter())) {
 289  0
                 Collection delegators = actionListSrv.findUserSecondaryDelegators(principalId);
 290  0
                 form.setDelegators(ActionListUtil.getWebFriendlyRecipients(delegators));
 291  0
                 form.setDelegationId(filter.getDelegatorId());
 292  
             }
 293  
 
 294  
             // Build the drop-down of primary delegates.
 295  0
             if (KEWConstants.PRIMARY_DELEGATES_ON_ACTION_LIST_PAGE.equalsIgnoreCase(preferences.getPrimaryDelegateFilter())) {
 296  0
                     Collection<Recipient> pDelegates = actionListSrv.findUserPrimaryDelegations(principalId);
 297  0
                     form.setPrimaryDelegates(ActionListUtil.getWebFriendlyRecipients(pDelegates));
 298  0
                     form.setPrimaryDelegateId(filter.getPrimaryDelegateId());
 299  
             }
 300  
             
 301  0
             form.setFilterLegend(filter.getFilterLegend());
 302  0
             plog.log("Setting attributes");
 303  
 
 304  0
             int pageSize = getPageSize(preferences);
 305  
             // initialize the action list if necessary
 306  0
             if (freshActionList) {
 307  0
                     plog.log("calling initializeActionList");
 308  0
                     initializeActionList(actionList, preferences);
 309  0
                     plog.log("done w/ initializeActionList");
 310  
                     // put this in to resolve EN-112 (http://beatles.uits.indiana.edu:8081/jira/browse/EN-112)
 311  
                 // if the action list gets "refreshed" in between page switches, we need to be sure and re-sort it, even though we don't have sort criteria on the request
 312  0
                     if (sortCriterion == null) {
 313  0
                             sortCriterion = form.getCurrentSort();
 314  0
                             sortOrder = parseSortOrder(form.getCurrentDir());
 315  
                     }
 316  
             }
 317  
             // sort the action list if necessary
 318  0
             if (sortCriterion != null) {
 319  0
                     sortActionList(actionList, sortCriterion, sortOrder);
 320  
             }
 321  
             
 322  0
             plog.log("calling buildCurrentPage");
 323  0
             PaginatedList currentPage = buildCurrentPage(actionList, form.getCurrentPage(), form.getCurrentSort(), 
 324  
                                     form.getCurrentDir(), pageSize, preferences, form);
 325  0
             plog.log("done w/ buildCurrentPage");
 326  0
             request.setAttribute(ACTION_LIST_PAGE_KEY, currentPage);
 327  0
             uSession.addObject(KEWConstants.UPDATE_ACTION_LIST_ATTR_NAME, Boolean.FALSE);
 328  0
             uSession.addObject(KEWConstants.CURRENT_PAGE_ATTR_NAME, form.getCurrentPage());
 329  0
             uSession.addObject(KEWConstants.SORT_CRITERIA_ATTR_NAME, form.getSort());
 330  0
             uSession.addObject(KEWConstants.SORT_ORDER_ATTR_NAME, form.getCurrentDir());
 331  0
             plog.log("finished setting attributes, finishing action list fetch");
 332  0
         } catch (Exception e) {
 333  0
             LOG.error("Error loading action list.", e);
 334  0
         }
 335  
 
 336  0
         LOG.debug("end start ActionListAction");
 337  0
         return mapping.findForward("viewActionList");
 338  
     }
 339  
 
 340  
     private SortOrderEnum parseSortOrder(String dir) throws WorkflowException {
 341  0
             if ("asc".equals(dir)) {
 342  0
                     return SortOrderEnum.ASCENDING;
 343  0
             } else if ("desc".equals(dir)) {
 344  0
                     return SortOrderEnum.DESCENDING;
 345  
             }
 346  0
             throw new WorkflowException("Invalid sort direction: " + dir);
 347  
     }
 348  
 
 349  
     private String getSortOrderValue(SortOrderEnum sortOrder) {
 350  0
             if (SortOrderEnum.ASCENDING.equals(sortOrder)) {
 351  0
                     return "asc";
 352  0
             } else if (SortOrderEnum.DESCENDING.equals(sortOrder)) {
 353  0
                     return "desc";
 354  
             }
 355  0
             return null;
 356  
     }
 357  
 
 358  
     private static final String OUT_BOX_MODE = "_OUT_BOX_MODE";
 359  
 
 360  
     /**
 361  
      * this method is setting 2 props on the {@link ActionListForm} that controls outbox behavior.
 362  
      *  alForm.setViewOutbox("false"); -> this is set by user preferences and the actionlist.outbox.off config prop
 363  
      *  alForm.setShowOutbox(false); -> this is set by user action clicking the ActionList vs. Outbox links.
 364  
      *
 365  
      * @param alForm
 366  
      * @param request
 367  
      * @return boolean indication whether the outbox should be fetched
 368  
      */
 369  
     private boolean isOutboxMode(ActionListForm alForm, HttpServletRequest request, Preferences preferences) {
 370  
 
 371  0
         boolean outBoxView = false;
 372  
 
 373  0
         if (! preferences.isUsingOutbox() || ! ConfigContext.getCurrentContextConfig().getOutBoxOn()) {
 374  0
             request.getSession().setAttribute(OUT_BOX_MODE, Boolean.valueOf(false));
 375  0
             alForm.setViewOutbox("false");
 376  0
             alForm.setShowOutbox(false);
 377  0
             return false;
 378  
         }
 379  
 
 380  0
         alForm.setShowOutbox(true);
 381  0
         if (StringUtils.isNotEmpty(alForm.getViewOutbox())) {
 382  0
             if (!Boolean.valueOf(alForm.getViewOutbox())) {
 383  0
                 request.getSession().setAttribute(OUT_BOX_MODE, Boolean.valueOf(false));
 384  0
                 outBoxView = false;
 385  
             } else {
 386  0
                 request.getSession().setAttribute(OUT_BOX_MODE, Boolean.valueOf(true));
 387  0
                 outBoxView = true;
 388  
             }
 389  
         } else {
 390  
 
 391  0
             if (request.getSession().getAttribute(OUT_BOX_MODE) == null) {
 392  0
                 outBoxView = false;
 393  
             } else {
 394  0
                 outBoxView = (Boolean) request.getSession().getAttribute(OUT_BOX_MODE);
 395  
             }
 396  
         }
 397  0
         if (outBoxView) {
 398  0
             alForm.setViewOutbox("true");
 399  
         } else {
 400  0
             alForm.setViewOutbox("false");
 401  
         }
 402  0
         return outBoxView;
 403  
     }
 404  
 
 405  
     private void sortActionList(List actionList, String sortName, SortOrderEnum sortOrder) {
 406  0
             if (StringUtils.isEmpty(sortName)) {
 407  0
                     return;
 408  
             }
 409  0
             Comparator comparator = new ActionItemComparator(sortName);
 410  0
             if (SortOrderEnum.DESCENDING.equals(sortOrder)) {
 411  0
                     comparator = ComparatorUtils.reversedComparator(comparator);
 412  
             }
 413  0
             Collections.sort(actionList, comparator);
 414  
             // re-index the action items
 415  0
             int index = 0;
 416  0
             for (Iterator iterator = actionList.iterator(); iterator.hasNext();) {
 417  0
                         ActionItemActionListExtension actionItem = (ActionItemActionListExtension) iterator.next();
 418  0
                         actionItem.setActionItemIndex(Integer.valueOf(index++));
 419  0
                 }
 420  0
     }
 421  
 
 422  
     private void initializeActionList(List actionList, Preferences preferences) throws WorkflowException {
 423  0
             List actionItemProblemIds = new ArrayList();
 424  0
             Map<String,DocumentRouteHeaderValue> routeHeaders = KEWServiceLocator.getRouteHeaderService().getRouteHeadersForActionItems(actionList);
 425  
 
 426  0
             int index = 0;
 427  0
             generateActionItemErrors(actionList);
 428  
             //RouteHeaderService routeHeaderService = KEWServiceLocator.getRouteHeaderService();
 429  0
             for (Iterator iterator = actionList.iterator(); iterator.hasNext();) {
 430  0
                     ActionItemActionListExtension actionItem = (ActionItemActionListExtension)iterator.next();
 431  0
                     if (actionItem.getDocumentId() == null) {
 432  0
                             LOG.error("Somehow there exists an ActionItem with a null document id!  actionItemId=" + actionItem.getActionItemId());
 433  0
                             iterator.remove();
 434  0
                             continue;
 435  
                     }
 436  
                     try {
 437  0
                             actionItem.initialize(preferences);
 438  0
                             DocumentRouteHeaderValue routeHeader = routeHeaders.get(actionItem.getDocumentId());
 439  
                             //DocumentRouteHeaderValue routeHeader = routeHeaderService.getRouteHeader(actionItem.getDocumentId());
 440  0
                             DocumentRouteHeaderValueActionListExtension routeHeaderExtension = toDocumentRouteHeaderValueActionListExtension(routeHeader);
 441  0
                             routeHeaderExtension.setActionListInitiatorPrincipal(routeHeaderExtension.getInitiatorPrincipal());
 442  0
                             actionItem.setActionItemIndex(Integer.valueOf(index));
 443  0
                             actionItem.setRouteHeader(routeHeaderExtension);
 444  
                             //set background colors for document statuses
 445  0
                             if (KEWConstants.ROUTE_HEADER_APPROVED_CD.equalsIgnoreCase(routeHeader.getDocRouteStatus())) {
 446  0
                                     actionItem.setRowStyleClass(KEWConstants.ACTION_LIST_COLOR_PALETTE.get(preferences.getColorApproved()));
 447  0
                             } else if (KEWConstants.ROUTE_HEADER_CANCEL_CD.equalsIgnoreCase(routeHeader.getDocRouteStatus())) {
 448  0
                                     actionItem.setRowStyleClass(KEWConstants.ACTION_LIST_COLOR_PALETTE.get(preferences.getColorCanceled()));
 449  0
                             } else if (KEWConstants.ROUTE_HEADER_DISAPPROVED_CD.equalsIgnoreCase(routeHeader.getDocRouteStatus())) {
 450  0
                                     actionItem.setRowStyleClass(KEWConstants.ACTION_LIST_COLOR_PALETTE.get(preferences.getColorDissaproved()));
 451  0
                             } else if (KEWConstants.ROUTE_HEADER_ENROUTE_CD.equalsIgnoreCase(routeHeader.getDocRouteStatus())) {
 452  0
                                     actionItem.setRowStyleClass(KEWConstants.ACTION_LIST_COLOR_PALETTE.get(preferences.getColorEnroute()));
 453  0
                             } else if (KEWConstants.ROUTE_HEADER_EXCEPTION_CD.equalsIgnoreCase(routeHeader.getDocRouteStatus())) {
 454  0
                                     actionItem.setRowStyleClass(KEWConstants.ACTION_LIST_COLOR_PALETTE.get(preferences.getColorException()));
 455  0
                             } else if (KEWConstants.ROUTE_HEADER_FINAL_CD.equalsIgnoreCase(routeHeader.getDocRouteStatus())) {
 456  0
                                     actionItem.setRowStyleClass(KEWConstants.ACTION_LIST_COLOR_PALETTE.get(preferences.getColorFinal()));
 457  0
                             } else if (KEWConstants.ROUTE_HEADER_INITIATED_CD.equalsIgnoreCase(routeHeader.getDocRouteStatus())) {
 458  0
                                     actionItem.setRowStyleClass(KEWConstants.ACTION_LIST_COLOR_PALETTE.get(preferences.getColorInitiated()));
 459  0
                             } else if (KEWConstants.ROUTE_HEADER_PROCESSED_CD.equalsIgnoreCase(routeHeader.getDocRouteStatus())) {
 460  0
                                     actionItem.setRowStyleClass(KEWConstants.ACTION_LIST_COLOR_PALETTE.get(preferences.getColorProccessed()));
 461  0
                             } else if (KEWConstants.ROUTE_HEADER_SAVED_CD.equalsIgnoreCase(routeHeader.getDocRouteStatus())) {
 462  0
                                     actionItem.setRowStyleClass(KEWConstants.ACTION_LIST_COLOR_PALETTE.get(preferences.getColorSaved()));
 463  
                             }
 464  0
                             index++;
 465  0
                     } catch (Exception e) {
 466  
                             // if there's a problem loading the action item, we don't want to blow out the whole screen but we will remove it from the list
 467  
                             // and display an approriate error message to the user
 468  0
                             LOG.error("Error loading action list for action item " + actionItem.getActionItemId(), e);
 469  0
                             iterator.remove();
 470  0
                             actionItemProblemIds.add(actionItem.getDocumentId());
 471  0
                     }
 472  0
             }
 473  0
             generateActionItemErrors(ACTIONITEM_PROP, ACTIONLIST_BAD_ACTION_ITEMS_ERRKEY, actionItemProblemIds);
 474  0
     }
 475  
 
 476  
     private DocumentRouteHeaderValueActionListExtension toDocumentRouteHeaderValueActionListExtension(
 477  
                         DocumentRouteHeaderValue routeHeader) {
 478  
 
 479  0
                 if(routeHeader==null){
 480  0
                         return null;
 481  
                 }
 482  
                 
 483  0
                 DocumentRouteHeaderValueActionListExtension extension = new DocumentRouteHeaderValueActionListExtension();
 484  
                 
 485  0
                 extension.setDocumentId(routeHeader.getDocumentId());
 486  0
                 extension.setDocumentTypeId(routeHeader.getDocumentTypeId());
 487  0
                 extension.setDocRouteStatus(routeHeader.getDocRouteStatus());
 488  0
                 extension.setDocRouteLevel(routeHeader.getDocRouteLevel());
 489  0
                 extension.setStatusModDate(routeHeader.getStatusModDate());
 490  0
                 extension.setCreateDate(routeHeader.getCreateDate());
 491  0
                 extension.setApprovedDate(routeHeader.getApprovedDate());
 492  0
                 extension.setFinalizedDate(routeHeader.getFinalizedDate());
 493  0
                 extension.setRouteStatusDate(routeHeader.getRouteStatusDate());
 494  0
                 extension.setRouteLevelDate(routeHeader.getRouteLevelDate());
 495  0
                 extension.setDocTitle(routeHeader.getDocTitle());
 496  0
                 extension.setAppDocId(routeHeader.getAppDocId());
 497  0
                 extension.setDocVersion(routeHeader.getDocVersion());
 498  0
                 extension.setInitiatorWorkflowId(routeHeader.getInitiatorWorkflowId());
 499  0
                 extension.setVersionNumber(routeHeader.getVersionNumber());
 500  0
                 extension.setAppDocStatus(routeHeader.getAppDocStatus());
 501  0
                 extension.setAppDocStatusDate(routeHeader.getAppDocStatusDate());
 502  
 
 503  0
                 return extension;
 504  
         }
 505  
     
 506  
     /**
 507  
      * Gets the page size of the Action List.  Uses the user's preferences for page size unless the action list
 508  
      * has been throttled by an application constant, in which case it uses the smaller of the two values.
 509  
      */
 510  
     protected int getPageSize(Preferences preferences) {
 511  0
             return Integer.parseInt(preferences.getPageSize());
 512  
     }
 513  
 
 514  
     protected PaginatedList buildCurrentPage(List actionList, Integer page, String sortCriterion, String sortDirection, 
 515  
                     int pageSize, Preferences preferences, ActionListForm form) throws WorkflowException {
 516  0
             List currentPage = new ArrayList(pageSize);
 517  0
             boolean haveFyis = false;
 518  0
             boolean haveApproves = false;
 519  0
             boolean haveAcknowledges = false;
 520  0
             boolean haveCancels = false;
 521  0
             boolean haveDisapproves = false;
 522  0
             boolean haveCustomActions = false;
 523  0
             boolean haveDisplayParameters = false;
 524  0
             List customActionListProblemIds = new ArrayList();
 525  0
             SortOrderEnum sortOrder = parseSortOrder(sortDirection);
 526  0
             int startIndex = (page.intValue() - 1) * pageSize;
 527  0
             int endIndex = startIndex + pageSize;
 528  0
             generateActionItemErrors(actionList);
 529  0
             Map<String,DocumentRouteHeaderValue> routeHeaders = KEWServiceLocator.getRouteHeaderService().getRouteHeadersForActionItems(actionList);
 530  0
             for (int index = startIndex; index < endIndex && index < actionList.size(); index++) {
 531  0
                     ActionItemActionListExtension actionItem = (ActionItemActionListExtension)actionList.get(index);
 532  
                     // evaluate custom action list component for mass actions
 533  
                     try {
 534  0
                             boolean itemHasApproves = false;
 535  0
                             boolean itemHasDisapproves = false;
 536  0
                             boolean itemHasCancels = false;
 537  0
                             boolean itemHasAcknowledges = false;
 538  0
                             boolean itemHasFyis = false;
 539  0
                             boolean itemHasCustomActions = false;
 540  0
                             CustomActionListAttribute customActionListAttribute = routeHeaders.get(actionItem.getDocumentId()).getCustomActionListAttribute();
 541  0
                             if (customActionListAttribute != null) {
 542  0
                                     Map customActions = new LinkedHashMap();
 543  0
                                     customActions.put("NONE", "NONE");
 544  0
                                     ActionSet legalActions = customActionListAttribute.getLegalActions(getUserSession().getPrincipalId(), actionItem);
 545  0
                                     if (legalActions != null && legalActions.hasApprove() && isActionCompatibleRequest(actionItem, KEWConstants.ACTION_TAKEN_APPROVED_CD)) {
 546  0
                                             customActions.put(KEWConstants.ACTION_TAKEN_APPROVED_CD, KEWConstants.ACTION_REQUEST_APPROVE_REQ_LABEL);
 547  0
                                             itemHasApproves = true;
 548  
                                     }
 549  0
                                     if (legalActions != null && legalActions.hasDisapprove() && isActionCompatibleRequest(actionItem, KEWConstants.ACTION_TAKEN_DENIED_CD)) {
 550  0
                                             customActions.put(KEWConstants.ACTION_TAKEN_DENIED_CD, KEWConstants.ACTION_REQUEST_DISAPPROVE_LABEL);
 551  0
                                             itemHasDisapproves = true;
 552  
                                     }
 553  0
                                     if (legalActions != null && legalActions.hasCancel() && isActionCompatibleRequest(actionItem, KEWConstants.ACTION_TAKEN_CANCELED_CD)) {
 554  0
                                             customActions.put(KEWConstants.ACTION_TAKEN_CANCELED_CD, KEWConstants.ACTION_REQUEST_CANCEL_REQ_LABEL);
 555  0
                                             itemHasCancels = true;
 556  
                                     }
 557  0
                                     if (legalActions != null && legalActions.hasAcknowledge() && isActionCompatibleRequest(actionItem, KEWConstants.ACTION_TAKEN_ACKNOWLEDGED_CD)) {
 558  0
                                             customActions.put(KEWConstants.ACTION_TAKEN_ACKNOWLEDGED_CD, KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ_LABEL);
 559  0
                                             itemHasAcknowledges = true;
 560  
                                     }
 561  0
                                     if (legalActions != null && legalActions.hasFyi() && isActionCompatibleRequest(actionItem, KEWConstants.ACTION_TAKEN_FYI_CD) && KEWConstants.PREFERENCES_YES_VAL.equalsIgnoreCase(preferences.getShowClearFyi())) {
 562  0
                                             customActions.put(KEWConstants.ACTION_TAKEN_FYI_CD, KEWConstants.ACTION_REQUEST_FYI_REQ_LABEL);
 563  0
                                             itemHasFyis = true;
 564  
                                     }
 565  0
                                     if (customActions.size() > 1) {
 566  0
                                             actionItem.setCustomActions(customActions);
 567  0
                                             itemHasCustomActions = true;
 568  
                                     }
 569  0
                                     actionItem.setDisplayParameters(customActionListAttribute.getDocHandlerDisplayParameters(getUserSession().getPrincipalId(), actionItem));
 570  0
                                     haveApproves = haveApproves || itemHasApproves;
 571  0
                                     haveAcknowledges = haveAcknowledges || itemHasAcknowledges;
 572  0
                                     haveFyis = haveFyis || itemHasFyis;
 573  0
                                     haveDisapproves = haveDisapproves || itemHasDisapproves;
 574  0
                                     haveCancels = haveCancels || itemHasCancels;
 575  0
                                     haveCustomActions = haveCustomActions || itemHasCustomActions;
 576  0
                                     haveDisplayParameters = haveDisplayParameters || (actionItem.getDisplayParameters() != null);
 577  
                             }
 578  0
                     } catch (Exception e) {
 579  
                             // if there's a problem loading the custom action list attribute, let's go ahead and display the vanilla action item
 580  0
                             LOG.error("Problem loading custom action list attribute", e);
 581  0
                             customActionListProblemIds.add(actionItem.getDocumentId());
 582  0
                     }
 583  0
                     currentPage.add(actionItem);
 584  
             }
 585  
 
 586  
             // configure custom actions on form
 587  0
             form.setHasCustomActions(Boolean.valueOf(haveCustomActions));
 588  0
             Map defaultActions = new LinkedHashMap();
 589  0
             defaultActions.put("NONE", "NONE");
 590  0
             if (haveApproves) {
 591  0
                     defaultActions.put(KEWConstants.ACTION_TAKEN_APPROVED_CD, KEWConstants.ACTION_REQUEST_APPROVE_REQ_LABEL);
 592  0
                     form.setCustomActionList(Boolean.TRUE);
 593  
             }
 594  0
             if (haveDisapproves) {
 595  0
                     defaultActions.put(KEWConstants.ACTION_TAKEN_DENIED_CD, KEWConstants.ACTION_REQUEST_DISAPPROVE_LABEL);
 596  0
                     form.setCustomActionList(Boolean.TRUE);
 597  
             }
 598  0
             if (haveCancels) {
 599  0
                     defaultActions.put(KEWConstants.ACTION_TAKEN_CANCELED_CD, KEWConstants.ACTION_REQUEST_CANCEL_REQ_LABEL);
 600  0
                     form.setCustomActionList(Boolean.TRUE);
 601  
             }
 602  0
             if (haveAcknowledges) {
 603  0
                     defaultActions.put(KEWConstants.ACTION_TAKEN_ACKNOWLEDGED_CD, KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ_LABEL);
 604  0
                     form.setCustomActionList(Boolean.TRUE);
 605  
             }
 606  
             //clearing FYI's can be done in any action list not just a customized one
 607  0
             if (haveFyis && KEWConstants.PREFERENCES_YES_VAL.equalsIgnoreCase(preferences.getShowClearFyi())) {
 608  0
                     defaultActions.put(KEWConstants.ACTION_TAKEN_FYI_CD, KEWConstants.ACTION_REQUEST_FYI_REQ_LABEL);
 609  
             }
 610  0
             if (defaultActions.size() > 1) {
 611  0
                     form.setDefaultActions(defaultActions);
 612  
             }
 613  
 
 614  0
                    form.setHasDisplayParameters(haveDisplayParameters);
 615  
             
 616  0
             generateActionItemErrors(CUSTOMACTIONLIST_PROP, ACTIONLIST_BAD_CUSTOM_ACTION_LIST_ITEMS_ERRKEY, customActionListProblemIds);
 617  0
             return new PaginatedActionList(currentPage, actionList.size(), page.intValue(), pageSize, "actionList", sortCriterion, sortOrder);
 618  
     }
 619  
 
 620  
     private void generateActionItemErrors(String propertyName, String errorKey, List documentIds) {
 621  0
             if (!documentIds.isEmpty()) {
 622  0
                     String documentIdsString = StringUtils.join(documentIds.iterator(), ", ");
 623  0
                     GlobalVariables.getMessageMap().putError(propertyName, errorKey, documentIdsString);
 624  
             }
 625  0
     }
 626  
     
 627  
     private void generateActionItemErrors(List actionList) {
 628  0
             for (Iterator iterator = actionList.iterator(); iterator.hasNext();) {
 629  0
                     ActionItemActionListExtension actionItem = (ActionItemActionListExtension)iterator.next();
 630  
                     
 631  
                     // removing this check for the time being, it hinders action list performance. (KULRICE-2931)
 632  
 //                    if (KEWServiceLocator.getRouteHeaderService().getRouteHeader(actionItem.getDocumentId()) == null) {
 633  
 //                            GlobalVariables.getErrorMap().putError(ROUTEHEADERID_PROP, ACTIONITEM_ROUTEHEADERID_INVALID_ERRKEY,actionItem.getActionItemId()+"");
 634  
 //                    }
 635  
                     
 636  0
                     if(!KEWConstants.ACTION_REQUEST_CODES.containsKey(actionItem.getActionRequestCd())) {
 637  0
                             GlobalVariables.getMessageMap().putError(ACTIONREQUESTCD_PROP,ACTIONITEM_ACTIONREQUESTCD_INVALID_ERRKEY,actionItem.getActionItemId()+"");
 638  
                     }
 639  0
              }
 640  0
     }
 641  
 
 642  
 
 643  
     public ActionForward takeMassActions(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 644  0
         ActionListForm actionListForm = (ActionListForm) form;
 645  0
         List actionList = (List) request.getSession().getAttribute(ACTION_LIST_KEY);
 646  0
         if (actionList == null) {
 647  0
             return start(mapping, new ActionListForm(), request, response);
 648  
         }
 649  0
         ActionMessages messages = new ActionMessages();
 650  0
         List invocations = new ArrayList();
 651  0
         int index = 0;
 652  0
         for (Object element : actionListForm.getActionsToTake()) {
 653  0
                 ActionToTake actionToTake = (ActionToTake) element;
 654  0
                 if (actionToTake != null && actionToTake.getActionTakenCd() != null &&
 655  
                                 !"".equals(actionToTake.getActionTakenCd()) &&
 656  
                                 !"NONE".equalsIgnoreCase(actionToTake.getActionTakenCd()) &&
 657  
                                 actionToTake.getActionItemId() != null) {
 658  0
                         ActionItem actionItem = getActionItemFromActionList(actionList, actionToTake.getActionItemId());
 659  0
                         if (actionItem == null) {
 660  0
                                 LOG.warn("Could not locate the ActionItem to take mass action against in the action list: " + actionToTake.getActionItemId());
 661  0
                                 continue;
 662  
                         }
 663  0
                     invocations.add(new ActionInvocation(actionItem.getActionItemId(), actionToTake.getActionTakenCd()));
 664  
             }
 665  0
                 index++;
 666  0
                 }
 667  0
         KEWServiceLocator.getWorkflowDocumentService().takeMassActions(getUserSession().getPrincipalId(), invocations);
 668  0
         messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("general.routing.processed"));
 669  0
         saveMessages(request, messages);
 670  0
         ActionListForm cleanForm = new ActionListForm();
 671  0
         request.setAttribute(mapping.getName(), cleanForm);
 672  0
         request.getSession().setAttribute(REQUERY_ACTION_LIST_KEY, "true");
 673  0
         return start(mapping, cleanForm, request, response);
 674  
     }
 675  
 
 676  
     protected ActionItem getActionItemFromActionList(List actionList, Long actionItemId) {
 677  0
             for (Iterator iterator = actionList.iterator(); iterator.hasNext();) {
 678  0
                         ActionItem actionItem = (ActionItem) iterator.next();
 679  0
                         if (actionItem.getActionItemId().equals(actionItemId)) {
 680  0
                                 return actionItem;
 681  
                         }
 682  0
                 }
 683  0
             return null;
 684  
     }
 685  
 
 686  
     public ActionForward helpDeskActionListLogin(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 687  0
         ActionListForm actionListForm = (ActionListForm) form;
 688  0
         String name = actionListForm.getHelpDeskActionListUserName();
 689  0
         if (!"true".equals(request.getAttribute("helpDeskActionList"))) {
 690  0
                 throw new AuthorizationException(getUserSession().getPrincipalId(), "helpDeskActionListLogin", getClass().getSimpleName());
 691  
         }
 692  
         try
 693  
         {
 694  0
                 final Principal helpDeskActionListPrincipal = KEWServiceLocator.getIdentityHelperService().getPrincipalByPrincipalName(name);
 695  0
                 final Person helpDeskActionListPerson = KEWServiceLocator.getIdentityHelperService().getPersonByPrincipalName(name);
 696  
                 
 697  0
                 GlobalVariables.getUserSession().addObject(KEWConstants.HELP_DESK_ACTION_LIST_PRINCIPAL_ATTR_NAME, helpDeskActionListPrincipal);
 698  0
                 GlobalVariables.getUserSession().addObject(KEWConstants.HELP_DESK_ACTION_LIST_PERSON_ATTR_NAME, helpDeskActionListPerson);
 699  
         }
 700  0
         catch (RiceRuntimeException rre)
 701  
         {
 702  0
                 GlobalVariables.getMessageMap().putError(HELPDESK_ACTIONLIST_USERNAME, HELPDESK_LOGIN_INVALID_ERRKEY, name);
 703  
         }
 704  0
         catch (NullPointerException npe)
 705  
         {
 706  0
                 GlobalVariables.getMessageMap().putError("null", HELPDESK_LOGIN_EMPTY_ERRKEY, name);
 707  0
         }
 708  0
             actionListForm.setDelegator(null);
 709  0
         request.getSession().setAttribute(REQUERY_ACTION_LIST_KEY, "true");
 710  0
         return start(mapping, form, request, response);
 711  
     }
 712  
 
 713  
     public ActionForward clearFilter(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 714  0
         LOG.debug("clearFilter ActionListAction");
 715  0
         final org.kuali.rice.kns.UserSession commonUserSession = getUserSession();
 716  0
         commonUserSession.removeObject(KEWConstants.ACTION_LIST_FILTER_ATTR_NAME);
 717  0
         request.getSession().setAttribute(REQUERY_ACTION_LIST_KEY, "true");
 718  0
         KEWServiceLocator.getActionListService().saveRefreshUserOption(commonUserSession.getPrincipalId());
 719  0
         LOG.debug("end clearFilter ActionListAction");
 720  0
         return start(mapping, form, request, response);
 721  
     }
 722  
 
 723  
     public ActionForward clearHelpDeskActionListUser(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 724  0
         LOG.debug("clearHelpDeskActionListUser ActionListAction");
 725  0
             GlobalVariables.getUserSession().removeObject(KEWConstants.HELP_DESK_ACTION_LIST_PRINCIPAL_ATTR_NAME);
 726  0
             GlobalVariables.getUserSession().removeObject(KEWConstants.HELP_DESK_ACTION_LIST_PERSON_ATTR_NAME);
 727  0
         LOG.debug("end clearHelpDeskActionListUser ActionListAction");
 728  0
         return start(mapping, form, request, response);
 729  
     }
 730  
 
 731  
     /**
 732  
      * Generates an Action List count.
 733  
      */
 734  
     public ActionForward count(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 735  0
             ActionListForm alForm = (ActionListForm)form;
 736  0
             Person user = getUserSession().getPerson();
 737  0
             alForm.setCount(KEWServiceLocator.getActionListService().getCount(user.getPrincipalId()));
 738  0
             LOG.info("Fetched Action List count of " + alForm.getCount() + " for user " + user.getPrincipalName());
 739  0
             return mapping.findForward("count");
 740  
     }
 741  
 
 742  
     public ActionForward removeOutboxItems(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 743  0
         ActionListForm alForm = (ActionListForm)form;
 744  0
         if (alForm.getOutboxItems() != null) {
 745  0
             KEWServiceLocator.getActionListService().removeOutboxItems(getUserSession().getPrincipalId(), Arrays.asList(alForm.getOutboxItems()));
 746  
         }
 747  
 
 748  0
         alForm.setViewOutbox("true");
 749  0
         return start(mapping, form, request, response);
 750  
     }
 751  
 
 752  
     /**
 753  
      * Navigate to the Action List Filter page, preserving any newly-modified primary/secondary delegation filters as necessary.
 754  
      */
 755  
     public ActionForward viewFilter(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
 756  0
             start(mapping, actionForm, request, response);
 757  0
             return mapping.findForward("viewFilter");
 758  
     }
 759  
     
 760  
     /**
 761  
      * Navigate to the user's Preferences page, preserving any newly-modified primary/secondary delegation filters as necessary.
 762  
      */
 763  
     public ActionForward viewPreferences(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
 764  0
             start(mapping, actionForm, request, response);
 765  0
             return mapping.findForward("viewPreferences");
 766  
     }
 767  
     
 768  
     private boolean isActionCompatibleRequest(ActionItemActionListExtension actionItem, String actionTakenCode) {
 769  0
         boolean actionCompatible = false;
 770  0
         String requestCd = actionItem.getActionRequestCd();
 771  
 
 772  
         //FYI request matches FYI
 773  0
         if (KEWConstants.ACTION_REQUEST_FYI_REQ.equals(requestCd) && KEWConstants.ACTION_TAKEN_FYI_CD.equals(actionTakenCode)) {
 774  0
             actionCompatible = true || actionCompatible;
 775  
         }
 776  
 
 777  
         // ACK request matches ACK
 778  0
         if (KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ.equals(requestCd) && KEWConstants.ACTION_TAKEN_ACKNOWLEDGED_CD.equals(actionTakenCode)) {
 779  0
             actionCompatible = true || actionCompatible;
 780  
         }
 781  
 
 782  
         // APPROVE request matches all but FYI and ACK
 783  0
         if (KEWConstants.ACTION_REQUEST_APPROVE_REQ.equals(requestCd) && !(KEWConstants.ACTION_TAKEN_FYI_CD.equals(actionTakenCode) || KEWConstants.ACTION_TAKEN_ACKNOWLEDGED_CD.equals(actionTakenCode))) {
 784  0
             actionCompatible = true || actionCompatible;
 785  
         }
 786  
 
 787  
         // COMPLETE request matches all but FYI and ACK
 788  0
         if (KEWConstants.ACTION_REQUEST_COMPLETE_REQ.equals(requestCd) && !(KEWConstants.ACTION_TAKEN_FYI_CD.equals(actionTakenCode) || KEWConstants.ACTION_TAKEN_ACKNOWLEDGED_CD.equals(actionTakenCode))) {
 789  0
             actionCompatible = true || actionCompatible;
 790  
         }
 791  
 
 792  0
         return actionCompatible;
 793  
     }
 794  
 
 795  
         private UserSession getUserSession(){
 796  0
                 return GlobalVariables.getUserSession();
 797  
         }
 798  
 
 799  0
     private static class ActionItemComparator implements Comparator<ActionItem> {
 800  
 
 801  
             private static final String DOCUMENT_ID = "documentId";
 802  
 
 803  
             private final String sortName;
 804  
 
 805  0
             public ActionItemComparator(String sortName) {
 806  0
                     if (StringUtils.isEmpty(sortName)) {
 807  0
                             sortName = DOCUMENT_ID;
 808  
                     }
 809  0
                     this.sortName = sortName;
 810  0
             }
 811  
 
 812  
                 @Override
 813  
                 public int compare(ActionItem object1, ActionItem object2) {
 814  
                         try {
 815  0
                                 ActionItem actionItem1 = object1;
 816  0
                                 ActionItem actionItem2 = object2;
 817  
                                 // invoke the power of the lookup functionality provided by the display tag library, this LookupUtil method allows for us
 818  
                                 // to evaulate nested bean properties (like workgroup.groupNameId.nameId) in a null-safe manner.  For example, in the
 819  
                                 // example if workgroup evaluated to NULL then LookupUtil.getProperty would return null rather than blowing an exception
 820  0
                                 Object property1 = LookupUtil.getProperty(actionItem1, sortName);
 821  0
                                 Object property2 = LookupUtil.getProperty(actionItem2, sortName);
 822  0
                                 if (property1 == null && property2 == null) {
 823  0
                                         return 0;
 824  0
                                 } else if (property1 == null) {
 825  0
                                         return -1;
 826  0
                                 } else if (property2 == null) {
 827  0
                                         return 1;
 828  
                                 }
 829  0
                                 if (property1 instanceof Comparable) {
 830  0
                                         return ((Comparable)property1).compareTo(property2);
 831  
                                 }
 832  0
                                 return property1.toString().compareTo(property2.toString());
 833  0
                         } catch (Exception e) {
 834  0
                                 if (e instanceof RuntimeException) {
 835  0
                                         throw (RuntimeException) e;
 836  
                                 }
 837  0
                                 throw new RuntimeException("Could not sort for the given sort name: " + sortName, e);
 838  
                         }
 839  
                 }
 840  
     }
 841  
 
 842  
 }