Coverage Report - org.kuali.rice.kew.actionlist.web.ActionListFilterAction
 
Classes in this File Line Coverage Branch Coverage Complexity
ActionListFilterAction
0%
0/65
0%
0/24
2.625
 
 1  
 /**
 2  
  * Copyright 2005-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  
 package org.kuali.rice.kew.actionlist.web;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.apache.struts.action.ActionForm;
 20  
 import org.apache.struts.action.ActionForward;
 21  
 import org.apache.struts.action.ActionMapping;
 22  
 import org.kuali.rice.core.api.util.ConcreteKeyValue;
 23  
 import org.kuali.rice.core.api.util.KeyValue;
 24  
 import org.kuali.rice.kew.actionlist.ActionListFilter;
 25  
 import org.kuali.rice.kew.actionlist.service.ActionListService;
 26  
 import org.kuali.rice.kew.api.KewApiServiceLocator;
 27  
 import org.kuali.rice.kew.api.preferences.Preferences;
 28  
 import org.kuali.rice.kew.api.preferences.PreferencesService;
 29  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 30  
 import org.kuali.rice.kew.api.KewApiConstants;
 31  
 import org.kuali.rice.kim.api.group.Group;
 32  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 33  
 import org.kuali.rice.kns.web.struts.action.KualiAction;
 34  
 import org.kuali.rice.krad.UserSession;
 35  
 import org.kuali.rice.krad.util.GlobalVariables;
 36  
 
 37  
 import javax.servlet.http.HttpServletRequest;
 38  
 import javax.servlet.http.HttpServletResponse;
 39  
 import java.util.ArrayList;
 40  
 import java.util.Collections;
 41  
 import java.util.List;
 42  
 
 43  
 
 44  
 /**
 45  
  * Action for Action List Filter page.
 46  
  *
 47  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 48  
  */
 49  0
 public class ActionListFilterAction extends KualiAction {
 50  
 
 51  
     @Override
 52  
         public ActionForward execute(ActionMapping mapping, ActionForm form,
 53  
                         HttpServletRequest request, HttpServletResponse response)
 54  
                         throws Exception {
 55  0
             request.setAttribute("Constants", getServlet().getServletContext().getAttribute("KewApiConstants"));
 56  0
             request.setAttribute("preferences", this.getUserSession().retrieveObject(KewApiConstants.PREFERENCES));
 57  0
                 initForm(request, form);
 58  0
                 return super.execute(mapping, form, request, response);
 59  
         }
 60  
 
 61  
         /**
 62  
          * This overridden method ...
 63  
          *
 64  
          * @see org.kuali.rice.krad.web.struts.action.KualiAction#getReturnLocation(javax.servlet.http.HttpServletRequest, org.apache.struts.action.ActionMapping)
 65  
          */
 66  
         @Override
 67  
         protected String getReturnLocation(HttpServletRequest request,
 68  
                         ActionMapping mapping)
 69  
         {
 70  0
             String mappingPath = mapping.getPath();
 71  0
             String basePath = getApplicationBaseUrl();
 72  0
         return basePath + KewApiConstants.WEBAPP_DIRECTORY + mappingPath + ".do";
 73  
         }
 74  
 
 75  
         public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 76  0
         ActionListFilterForm filterForm = (ActionListFilterForm) form;
 77  0
         final UserSession uSession = getUserSession();
 78  0
         final ActionListFilter filter = (ActionListFilter) uSession.retrieveObject(KewApiConstants.ACTION_LIST_FILTER_ATTR_NAME);
 79  0
         if (filter != null) {
 80  0
             if (filterForm.getDocTypeFullName() != null && ! "".equals(filterForm.getDocTypeFullName())) {
 81  0
                     filter.setDocumentType(filterForm.getDocTypeFullName());
 82  0
                     uSession.addObject(KewApiConstants.ACTION_LIST_FILTER_ATTR_NAME, filter);
 83  0
                 filterForm.setFilter(filter);
 84  
             } else {
 85  0
                 filterForm.setFilter(filter);
 86  0
                 filterForm.setDocTypeFullName(filter.getDocumentType());
 87  
             }
 88  
         }
 89  0
         return mapping.findForward("viewFilter");
 90  
     }
 91  
 
 92  
     public ActionForward filter(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 93  0
         ActionListFilterForm filterForm = (ActionListFilterForm) form;
 94  
         //validate the filter through the actionitem/actionlist service (I'm thinking actionlistservice)
 95  0
         final UserSession uSession = getUserSession();
 96  0
         ActionListFilter alFilter = filterForm.getLoadedFilter();
 97  0
         if (StringUtils.isNotBlank(alFilter.getDelegatorId()) && !KewApiConstants.DELEGATION_DEFAULT.equals(alFilter.getDelegatorId()) &&
 98  
                         StringUtils.isNotBlank(alFilter.getPrimaryDelegateId()) && !KewApiConstants.PRIMARY_DELEGATION_DEFAULT.equals(alFilter.getPrimaryDelegateId())){
 99  
                 // If the primary and secondary delegation drop-downs are both visible and are both set to non-default values,
 100  
                 // then reset the secondary delegation drop-down to its default value.
 101  0
                 alFilter.setDelegatorId(KewApiConstants.DELEGATION_DEFAULT);
 102  
         }
 103  0
         uSession.addObject(KewApiConstants.ACTION_LIST_FILTER_ATTR_NAME, alFilter);
 104  0
         KEWServiceLocator.getActionListService().saveRefreshUserOption(getUserSession().getPrincipalId());
 105  0
         if (GlobalVariables.getMessageMap().hasNoErrors()) {
 106  0
             return mapping.findForward("viewActionList");
 107  
         } 
 108  0
         return mapping.findForward("viewFilter");    
 109  
     }
 110  
 
 111  
     public ActionForward clear(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 112  0
         ActionListFilterForm filterForm = (ActionListFilterForm) form;
 113  0
         filterForm.setFilter(new ActionListFilter());
 114  0
         filterForm.setCreateDateFrom("");
 115  0
         filterForm.setCreateDateTo("");
 116  0
         filterForm.setLastAssignedDateFrom("");
 117  0
         filterForm.setLastAssignedDateTo("");
 118  0
         filterForm.setDocTypeFullName("");
 119  0
         UserSession session = getUserSession();
 120  0
         session.removeObject(KewApiConstants.ACTION_LIST_FILTER_ATTR_NAME);
 121  0
         KEWServiceLocator.getActionListService().saveRefreshUserOption(getUserSession().getPrincipalId());
 122  0
         return mapping.findForward("viewFilter");
 123  
     }
 124  
 
 125  
     public void initForm(HttpServletRequest request, ActionForm form) throws Exception {
 126  0
         ActionListFilterForm filterForm = (ActionListFilterForm) form;
 127  0
         filterForm.setUserWorkgroups(getUserWorkgroupsDropDownList(getUserSession().getPrincipalId()));
 128  0
         PreferencesService prefSrv = KewApiServiceLocator.getPreferencesService();
 129  0
         Preferences preferences = prefSrv.getPreferences(getUserSession().getPrincipalId());
 130  0
         request.setAttribute("preferences", preferences);
 131  0
         ActionListService actionListSrv = KEWServiceLocator.getActionListService();
 132  0
         request.setAttribute("delegators", ActionListUtil.getWebFriendlyRecipients(actionListSrv.findUserSecondaryDelegators(getUserSession().getPrincipalId())));
 133  0
         request.setAttribute("primaryDelegates", ActionListUtil.getWebFriendlyRecipients(actionListSrv.findUserPrimaryDelegations(getUserSession().getPrincipalId())));
 134  0
         if (! filterForm.getMethodToCall().equalsIgnoreCase("clear")) {
 135  0
             filterForm.validateDates();
 136  
         }
 137  0
     }
 138  
 
 139  
     private List<? extends KeyValue> getUserWorkgroupsDropDownList(String principalId) {
 140  0
             List<String> userWorkgroups =
 141  
             KimApiServiceLocator.getGroupService().getGroupIdsByPrincipalId(principalId);
 142  
 
 143  
         //note that userWorkgroups is unmodifiable so we need to create a new list that we can sort
 144  0
         List<String> userGroupsToSort = new ArrayList<String>(userWorkgroups);
 145  
 
 146  0
         List<KeyValue> sortedUserWorkgroups = new ArrayList<KeyValue>();
 147  0
             KeyValue keyValue = null;
 148  0
             keyValue = new ConcreteKeyValue(KewApiConstants.NO_FILTERING, KewApiConstants.NO_FILTERING);
 149  0
             sortedUserWorkgroups.add(keyValue);
 150  0
             if (userGroupsToSort != null && userGroupsToSort.size() > 0) {
 151  0
                     Collections.sort(userGroupsToSort);
 152  
 
 153  
                     Group group;
 154  0
             for (String groupId : userGroupsToSort)
 155  
             {
 156  0
                 group = KimApiServiceLocator.getGroupService().getGroup(groupId);
 157  0
                 keyValue = new ConcreteKeyValue(groupId, group.getName());
 158  0
                 sortedUserWorkgroups.add(keyValue);
 159  
             }
 160  
             }
 161  0
             return sortedUserWorkgroups;
 162  
     }
 163  
 
 164  
         private UserSession getUserSession(){
 165  0
                 return GlobalVariables.getUserSession();
 166  
         }
 167  
         
 168  
 }
 169