| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 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 | |
|
| 53 | |
|
| 54 | |
|
| 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 | |
|
| 70 | |
|
| 71 | |
|
| 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 | |
|
| 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 | |
|
| 106 | |
|
| 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 | |
|