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.Collections; |
21 | |
import java.util.List; |
22 | |
|
23 | |
import javax.servlet.http.HttpServletRequest; |
24 | |
import javax.servlet.http.HttpServletResponse; |
25 | |
|
26 | |
import org.apache.commons.lang.StringUtils; |
27 | |
import org.apache.struts.action.ActionForm; |
28 | |
import org.apache.struts.action.ActionForward; |
29 | |
import org.apache.struts.action.ActionMapping; |
30 | |
import org.kuali.rice.core.util.ConcreteKeyValue; |
31 | |
import org.kuali.rice.core.util.KeyValue; |
32 | |
import org.kuali.rice.kew.actionlist.ActionListFilter; |
33 | |
import org.kuali.rice.kew.actionlist.service.ActionListService; |
34 | |
import org.kuali.rice.kew.preferences.Preferences; |
35 | |
import org.kuali.rice.kew.preferences.service.PreferencesService; |
36 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
37 | |
import org.kuali.rice.kew.util.KEWConstants; |
38 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
39 | |
import org.kuali.rice.kim.api.group.Group; |
40 | |
import org.kuali.rice.kns.UserSession; |
41 | |
import org.kuali.rice.kns.util.GlobalVariables; |
42 | |
import org.kuali.rice.kns.web.struts.action.KualiAction; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | 0 | public class ActionListFilterAction extends KualiAction { |
51 | |
|
52 | |
@Override |
53 | |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
54 | |
HttpServletRequest request, HttpServletResponse response) |
55 | |
throws Exception { |
56 | 0 | request.setAttribute("Constants", getServlet().getServletContext().getAttribute("KEWConstants")); |
57 | 0 | request.setAttribute("preferences", this.getUserSession().retrieveObject(KEWConstants.PREFERENCES)); |
58 | 0 | initForm(request, form); |
59 | 0 | return super.execute(mapping, form, request, response); |
60 | |
} |
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
@Override |
68 | |
protected String getReturnLocation(HttpServletRequest request, |
69 | |
ActionMapping mapping) |
70 | |
{ |
71 | 0 | String mappingPath = mapping.getPath(); |
72 | 0 | String basePath = getApplicationBaseUrl(); |
73 | 0 | return basePath + KEWConstants.WEBAPP_DIRECTORY + mappingPath + ".do"; |
74 | |
} |
75 | |
|
76 | |
public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
77 | 0 | ActionListFilterForm filterForm = (ActionListFilterForm) form; |
78 | 0 | final UserSession uSession = getUserSession(); |
79 | 0 | final ActionListFilter filter = (ActionListFilter) uSession.retrieveObject(KEWConstants.ACTION_LIST_FILTER_ATTR_NAME); |
80 | 0 | if (filter != null) { |
81 | 0 | if (filterForm.getDocTypeFullName() != null && ! "".equals(filterForm.getDocTypeFullName())) { |
82 | 0 | filter.setDocumentType(filterForm.getDocTypeFullName()); |
83 | 0 | uSession.addObject(KEWConstants.ACTION_LIST_FILTER_ATTR_NAME, filter); |
84 | 0 | filterForm.setFilter(filter); |
85 | |
} else { |
86 | 0 | filterForm.setFilter(filter); |
87 | 0 | filterForm.setDocTypeFullName(filter.getDocumentType()); |
88 | |
} |
89 | |
} |
90 | 0 | return mapping.findForward("viewFilter"); |
91 | |
} |
92 | |
|
93 | |
public ActionForward filter(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
94 | 0 | ActionListFilterForm filterForm = (ActionListFilterForm) form; |
95 | |
|
96 | 0 | final UserSession uSession = getUserSession(); |
97 | 0 | ActionListFilter alFilter = filterForm.getLoadedFilter(); |
98 | 0 | if (StringUtils.isNotBlank(alFilter.getDelegatorId()) && !KEWConstants.DELEGATION_DEFAULT.equals(alFilter.getDelegatorId()) && |
99 | |
StringUtils.isNotBlank(alFilter.getPrimaryDelegateId()) && !KEWConstants.PRIMARY_DELEGATION_DEFAULT.equals(alFilter.getPrimaryDelegateId())){ |
100 | |
|
101 | |
|
102 | 0 | alFilter.setDelegatorId(KEWConstants.DELEGATION_DEFAULT); |
103 | |
} |
104 | 0 | uSession.addObject(KEWConstants.ACTION_LIST_FILTER_ATTR_NAME, alFilter); |
105 | 0 | KEWServiceLocator.getActionListService().saveRefreshUserOption(getUserSession().getPrincipalId()); |
106 | 0 | if (GlobalVariables.getMessageMap().hasNoErrors()) { |
107 | 0 | return mapping.findForward("viewActionList"); |
108 | |
} |
109 | 0 | return mapping.findForward("viewFilter"); |
110 | |
} |
111 | |
|
112 | |
public ActionForward clear(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
113 | 0 | ActionListFilterForm filterForm = (ActionListFilterForm) form; |
114 | 0 | filterForm.setFilter(new ActionListFilter()); |
115 | 0 | filterForm.setCreateDateFrom(""); |
116 | 0 | filterForm.setCreateDateTo(""); |
117 | 0 | filterForm.setLastAssignedDateFrom(""); |
118 | 0 | filterForm.setLastAssignedDateTo(""); |
119 | 0 | filterForm.setDocTypeFullName(""); |
120 | 0 | UserSession session = getUserSession(); |
121 | 0 | session.removeObject(KEWConstants.ACTION_LIST_FILTER_ATTR_NAME); |
122 | 0 | KEWServiceLocator.getActionListService().saveRefreshUserOption(getUserSession().getPrincipalId()); |
123 | 0 | return mapping.findForward("viewFilter"); |
124 | |
} |
125 | |
|
126 | |
public void initForm(HttpServletRequest request, ActionForm form) throws Exception { |
127 | 0 | ActionListFilterForm filterForm = (ActionListFilterForm) form; |
128 | 0 | filterForm.setUserWorkgroups(getUserWorkgroupsDropDownList(getUserSession().getPrincipalId())); |
129 | 0 | PreferencesService prefSrv = KEWServiceLocator.getPreferencesService(); |
130 | 0 | Preferences preferences = prefSrv.getPreferences(getUserSession().getPrincipalId()); |
131 | 0 | request.setAttribute("preferences", preferences); |
132 | 0 | ActionListService actionListSrv = KEWServiceLocator.getActionListService(); |
133 | 0 | request.setAttribute("delegators", ActionListUtil.getWebFriendlyRecipients(actionListSrv.findUserSecondaryDelegators(getUserSession().getPrincipalId()))); |
134 | 0 | request.setAttribute("primaryDelegates", ActionListUtil.getWebFriendlyRecipients(actionListSrv.findUserPrimaryDelegations(getUserSession().getPrincipalId()))); |
135 | 0 | if (! filterForm.getMethodToCall().equalsIgnoreCase("clear")) { |
136 | 0 | filterForm.validateDates(); |
137 | |
} |
138 | 0 | } |
139 | |
|
140 | |
private List<? extends KeyValue> getUserWorkgroupsDropDownList(String principalId) { |
141 | 0 | List<String> userWorkgroups = |
142 | |
KimApiServiceLocator.getIdentityManagementService().getGroupIdsForPrincipal(principalId); |
143 | 0 | List<KeyValue> sortedUserWorkgroups = new ArrayList<KeyValue>(); |
144 | 0 | KeyValue keyValue = null; |
145 | 0 | keyValue = new ConcreteKeyValue(KEWConstants.NO_FILTERING, KEWConstants.NO_FILTERING); |
146 | 0 | sortedUserWorkgroups.add(keyValue); |
147 | 0 | if (userWorkgroups != null && userWorkgroups.size() > 0) { |
148 | 0 | Collections.sort(userWorkgroups); |
149 | |
|
150 | |
Group group; |
151 | 0 | for (String groupId : userWorkgroups) |
152 | |
{ |
153 | 0 | group = KimApiServiceLocator.getIdentityManagementService().getGroup(groupId); |
154 | 0 | keyValue = new ConcreteKeyValue(groupId, group.getName()); |
155 | 0 | sortedUserWorkgroups.add(keyValue); |
156 | |
} |
157 | |
} |
158 | 0 | return sortedUserWorkgroups; |
159 | |
} |
160 | |
|
161 | |
private UserSession getUserSession(){ |
162 | 0 | return GlobalVariables.getUserSession(); |
163 | |
} |
164 | |
|
165 | |
} |
166 | |
|