1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
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 | |
|
46 | |
|
47 | |
|
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 | |
|
63 | |
|
64 | |
|
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 | |
|
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 | |
|
100 | |
|
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 | |
|
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 | |
|