Coverage Report - org.kuali.rice.kew.actionlist.web.ActionListFilterAction
 
Classes in this File Line Coverage Branch Coverage Complexity
ActionListFilterAction
0%
0/69
0%
0/26
2.4
ActionListFilterAction$1
0%
0/3
N/A
2.4
 
 1  
 /*
 2  
  * Copyright 2005-2009 The Kuali Foundation
 3  
  *
 4  
  *
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.kew.actionlist.web;
 18  
 
 19  
 import java.util.ArrayList;
 20  
 import java.util.Collection;
 21  
 import java.util.Collections;
 22  
 import java.util.Comparator;
 23  
 import java.util.Iterator;
 24  
 import java.util.List;
 25  
 
 26  
 import javax.servlet.http.HttpServletRequest;
 27  
 import javax.servlet.http.HttpServletResponse;
 28  
 
 29  
 import org.apache.commons.collections.comparators.ComparableComparator;
 30  
 import org.apache.commons.lang.StringUtils;
 31  
 import org.apache.struts.action.ActionForm;
 32  
 import org.apache.struts.action.ActionForward;
 33  
 import org.apache.struts.action.ActionMapping;
 34  
 import org.kuali.rice.core.util.JSTLConstants;
 35  
 import org.kuali.rice.kew.actionlist.ActionListFilter;
 36  
 import org.kuali.rice.kew.actionlist.service.ActionListService;
 37  
 import org.kuali.rice.kew.actionrequest.Recipient;
 38  
 import org.kuali.rice.kew.preferences.Preferences;
 39  
 import org.kuali.rice.kew.preferences.service.PreferencesService;
 40  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 41  
 import org.kuali.rice.kew.util.KEWConstants;
 42  
 import org.kuali.rice.kew.util.WebFriendlyRecipient;
 43  
 import org.kuali.rice.kew.web.KeyValue;
 44  
 import org.kuali.rice.kew.web.session.UserSession;
 45  
 import org.kuali.rice.kim.bo.Group;
 46  
 import org.kuali.rice.kim.service.KIMServiceLocator;
 47  
 import org.kuali.rice.kns.util.GlobalVariables;
 48  
 import org.kuali.rice.kns.web.struts.action.KualiAction;
 49  
 
 50  
 
 51  
 /**
 52  
  * Action for Action List Filter page.
 53  
  *
 54  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 55  
  */
 56  0
 public class ActionListFilterAction extends KualiAction {
 57  
 
 58  
     @Override
 59  
         public ActionForward execute(ActionMapping mapping, ActionForm form,
 60  
                         HttpServletRequest request, HttpServletResponse response)
 61  
                         throws Exception {
 62  0
             request.setAttribute("Constants", new JSTLConstants(KEWConstants.class));
 63  0
             request.setAttribute("preferences", this.getUserSession(request).getPreferences());
 64  0
                 initForm(request, form);
 65  0
                 return super.execute(mapping, form, request, response);
 66  
         }
 67  
 
 68  
         /**
 69  
          * This overridden method ...
 70  
          *
 71  
          * @see org.kuali.rice.kns.web.struts.action.KualiAction#getReturnLocation(javax.servlet.http.HttpServletRequest, org.apache.struts.action.ActionMapping)
 72  
          */
 73  
         @Override
 74  
         protected String getReturnLocation(HttpServletRequest request,
 75  
                         ActionMapping mapping)
 76  
         {
 77  0
             String mappingPath = mapping.getPath();
 78  0
             String basePath = getBasePath(request);
 79  0
         return basePath + KEWConstants.WEBAPP_DIRECTORY + mappingPath + ".do";
 80  
         }
 81  
 
 82  
         public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 83  0
         ActionListFilterForm filterForm = (ActionListFilterForm) form;
 84  0
         if (getUserSession(request).getActionListFilter() != null) {
 85  0
             ActionListFilter actionListFilter = getUserSession(request).getActionListFilter();
 86  0
             if (filterForm.getDocTypeFullName() != null && ! "".equals(filterForm.getDocTypeFullName())) {
 87  0
                 actionListFilter.setDocumentType(filterForm.getDocTypeFullName());
 88  0
                 getUserSession(request).setActionListFilter(actionListFilter);
 89  0
                 filterForm.setFilter(actionListFilter);
 90  
             } else {
 91  0
                 filterForm.setFilter(actionListFilter);
 92  0
                 filterForm.setDocTypeFullName(actionListFilter.getDocumentType());
 93  
             }
 94  
         }
 95  0
         return mapping.findForward("viewFilter");
 96  
     }
 97  
 
 98  
     public ActionForward filter(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 99  0
         ActionListFilterForm filterForm = (ActionListFilterForm) form;
 100  
         //validate the filter through the actionitem/actionlist service (I'm thinking actionlistservice)
 101  0
         UserSession session = getUserSession(request);
 102  0
         ActionListFilter alFilter = filterForm.getLoadedFilter();
 103  0
         if (StringUtils.isNotBlank(alFilter.getDelegatorId()) && !KEWConstants.DELEGATION_DEFAULT.equals(alFilter.getDelegatorId()) &&
 104  
                         StringUtils.isNotBlank(alFilter.getPrimaryDelegateId()) && !KEWConstants.PRIMARY_DELEGATION_DEFAULT.equals(alFilter.getPrimaryDelegateId())){
 105  
                 // If the primary and secondary delegation drop-downs are both visible and are both set to non-default values,
 106  
                 // then reset the secondary delegation drop-down to its default value.
 107  0
                 alFilter.setDelegatorId(KEWConstants.DELEGATION_DEFAULT);
 108  
         }
 109  0
         session.setActionListFilter(alFilter);
 110  0
         KEWServiceLocator.getActionListService().saveRefreshUserOption(getUserSession(request).getPrincipal().getPrincipalId());
 111  0
         if (GlobalVariables.getMessageMap().isEmpty()) {
 112  0
             return mapping.findForward("viewActionList");
 113  
         } else {
 114  0
             return mapping.findForward("viewFilter");
 115  
         }
 116  
     }
 117  
 
 118  
     public ActionForward clear(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 119  0
         ActionListFilterForm filterForm = (ActionListFilterForm) form;
 120  0
         filterForm.setFilter(new ActionListFilter());
 121  0
         filterForm.setCreateDateFrom("");
 122  0
         filterForm.setCreateDateTo("");
 123  0
         filterForm.setLastAssignedDateFrom("");
 124  0
         filterForm.setLastAssignedDateTo("");
 125  0
         filterForm.setDocTypeFullName("");
 126  0
         UserSession session = getUserSession(request);
 127  0
         session.setActionListFilter(null);
 128  0
         KEWServiceLocator.getActionListService().saveRefreshUserOption(getUserSession(request).getPrincipal().getPrincipalId());
 129  0
         return mapping.findForward("viewFilter");
 130  
     }
 131  
 
 132  
     public void initForm(HttpServletRequest request, ActionForm form) throws Exception {
 133  0
         ActionListFilterForm filterForm = (ActionListFilterForm) form;
 134  0
         filterForm.setUserWorkgroups(getUserWorkgroupsDropDownList(getUserSession(request).getPerson().getPrincipalId()));
 135  0
         PreferencesService prefSrv = (PreferencesService) KEWServiceLocator.getPreferencesService();
 136  0
         Preferences preferences = prefSrv.getPreferences(getUserSession(request).getPerson().getPrincipalId());
 137  0
         request.setAttribute("preferences", preferences);
 138  0
         ActionListService actionListSrv = (ActionListService) KEWServiceLocator.getActionListService();
 139  0
         request.setAttribute("delegators", getWebFriendlyRecipients(actionListSrv.findUserSecondaryDelegators(getUserSession(request).getPrincipal().getPrincipalId())));
 140  0
         request.setAttribute("primaryDelegates", getWebFriendlyRecipients(actionListSrv.findUserPrimaryDelegations(getUserSession(request).getPrincipal().getPrincipalId())));
 141  0
         if (! filterForm.getMethodToCall().equalsIgnoreCase("clear")) {
 142  0
             filterForm.validateDates();
 143  
         }
 144  0
     }
 145  
 
 146  
     private List<? extends KeyValue> getUserWorkgroupsDropDownList(String principalId) {
 147  0
             List<String> userWorkgroups =
 148  
             KIMServiceLocator.getIdentityManagementService().getGroupIdsForPrincipal(principalId);
 149  0
         List<KeyValue> sortedUserWorkgroups = new ArrayList<KeyValue>();
 150  0
             KeyValue keyValue = null;
 151  0
             keyValue = new KeyValue(KEWConstants.NO_FILTERING, KEWConstants.NO_FILTERING);
 152  0
             sortedUserWorkgroups.add(keyValue);
 153  0
             if (userWorkgroups != null && userWorkgroups.size() > 0) {
 154  0
                     Collections.sort(userWorkgroups);
 155  
 
 156  
                     Group group;
 157  0
             for (String groupId : userWorkgroups)
 158  
             {
 159  0
                 group = KIMServiceLocator.getIdentityManagementService().getGroup(groupId);
 160  0
                 keyValue = new KeyValue(groupId, group.getGroupName());
 161  0
                 sortedUserWorkgroups.add(keyValue);
 162  
             }
 163  
             }
 164  0
             return sortedUserWorkgroups;
 165  
     }
 166  
 
 167  
     private List getWebFriendlyRecipients(Collection<Recipient> recipients) {
 168  0
         Collection<Recipient> newRecipients = new ArrayList<Recipient>(recipients.size());
 169  0
         for (Recipient recipient : recipients)
 170  
         {
 171  0
             newRecipients.add(new WebFriendlyRecipient(recipient));
 172  
         }
 173  0
         List recipientList = new ArrayList(newRecipients);
 174  0
         Collections.sort(recipientList, new Comparator() {
 175  0
             Comparator comp = new ComparableComparator();
 176  
             public int compare(Object o1, Object o2) {
 177  0
                 return comp.compare(((WebFriendlyRecipient)o1).getDisplayName().trim().toLowerCase(), ((WebFriendlyRecipient)o2).getDisplayName().trim().toLowerCase());
 178  
             }
 179  
         });
 180  0
         return recipientList;
 181  
     }
 182  
 
 183  
         private UserSession getUserSession(HttpServletRequest request){
 184  0
                 return UserSession.getAuthenticatedUser();
 185  
         }
 186  
 
 187  
 }
 188