1 package org.kuali.kpme.edo.base.web;
2
3 import java.math.BigDecimal;
4 import java.util.HashMap;
5 import java.util.LinkedList;
6 import java.util.List;
7 import java.util.Map;
8 import java.util.SortedMap;
9
10 import javax.servlet.http.HttpServletRequest;
11 import javax.servlet.http.HttpServletResponse;
12 import javax.servlet.http.HttpSession;
13
14 import org.apache.commons.collections.CollectionUtils;
15 import org.apache.commons.lang.StringUtils;
16 import org.apache.log4j.Logger;
17 import org.apache.struts.action.ActionForm;
18 import org.apache.struts.action.ActionForward;
19 import org.apache.struts.action.ActionMapping;
20 import org.kuali.kpme.core.util.HrContext;
21 import org.kuali.kpme.edo.api.checklist.EdoChecklistItem;
22 import org.kuali.kpme.edo.api.dossier.EdoDossier;
23 import org.kuali.kpme.edo.candidate.EdoSelectedCandidate;
24 import org.kuali.kpme.edo.item.EdoItemTracker;
25 import org.kuali.kpme.edo.service.EdoServiceLocator;
26 import org.kuali.kpme.edo.util.EdoConstants;
27 import org.kuali.kpme.edo.util.EdoContext;
28 import org.kuali.kpme.edo.util.EdoRule;
29 import org.kuali.rice.core.api.config.property.Config;
30 import org.kuali.rice.core.api.config.property.ConfigContext;
31 import org.kuali.rice.kim.api.permission.PermissionService;
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.exception.AuthorizationException;
35
36
37
38
39
40
41
42
43 public class EdoAction extends KualiAction {
44
45 protected Config config;
46 private EdoSelectedCandidate selectedCandidate;
47 public HashMap<String, List<EdoChecklistItem>> checklistHash;
48 private PermissionService permissionService;
49 static final Logger LOG = Logger.getLogger(EdoAction.class);
50
51 public HashMap<String, List<EdoChecklistItem>> getChecklistHash() {
52 return checklistHash;
53 }
54
55 @Override
56 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
57
58 EdoForm edoForm = (EdoForm)form;
59 config = ConfigContext.getCurrentContextConfig();
60 Map<String, String> permissionDetails = new HashMap<String, String>();
61
62
63 String pId = HrContext.getPrincipalId();
64
65
66 HttpSession ssn = request.getSession();
67 if (ssn.isNew() || (null == ssn.getAttribute("selectedCandidate")) ) {
68 ssn.setAttribute("selectedCandidate", new EdoSelectedCandidate() );
69
70 ssn.setAttribute("nid", EdoConstants.EDO_DEFAULT_CHECKLIST_NODE_ID);
71 }
72 selectedCandidate = (EdoSelectedCandidate)ssn.getAttribute("selectedCandidate");
73 request.setAttribute("selectedCandidate", selectedCandidate);
74
75
76 if (ssn.isNew() || (null == ssn.getAttribute("itemTracker")) ) {
77 ssn.setAttribute("itemTracker", new EdoItemTracker() );
78 }
79
80
81 if (selectedCandidate.isSelected()) {
82
83
84 SortedMap<String, List<EdoChecklistItem>> checklistHash = EdoServiceLocator.getChecklistItemService().getCheckListHash(null, selectedCandidate.getCandidateSchoolID(), selectedCandidate.getCandidateDepartmentID());
85 request.setAttribute("checklisthash", checklistHash);
86 } else {
87 request.setAttribute("checklisthash", null);
88 }
89
90 if(EdoContext.getUser() != null) {
91 List<String> currRoles = EdoContext.getUser().getCurrentRoleList();
92 request.setAttribute("currRoles",currRoles);
93 request.setAttribute("emplId", EdoContext.getUser().getEmplId());
94 request.setAttribute("fullName", EdoContext.getUser().getName());
95 request.setAttribute("userName", EdoContext.getUser().getNetworkId());
96 request.setAttribute("deptName", EdoContext.getUser().getDeptName());
97 request.setAttribute("isCandidateSelected", selectedCandidate.isSelected());
98 }
99
100 if(selectedCandidate.isSelected() == true)
101 {
102
103 EdoDossier currentDossier = EdoServiceLocator.getEdoDossierService().getCurrentDossierPrincipalName(selectedCandidate.getCandidateUsername());
104 if(currentDossier != null)
105 {
106 request.setAttribute("candidateDossierStatus", currentDossier.getDossierStatus());
107 }
108 }
109
110 if(hasPermission(pId, EdoConstants.EDO_NAME_SPACE, EdoConstants.EDO_LOGIN_PERMISSION))
111 {
112
113 if(getPermissionService().isAuthorized(pId, EdoConstants.EDO_NAME_SPACE, EdoConstants.EDO_CANDIDATE_PERMISSION, new HashMap<String, String>()))
114 {
115 edoForm.setUseCandidateScreen(true);
116 edoForm.setUseHelpScreen(true);
117 }
118 if(isAuthorized(pId, EdoConstants.EDO_NAME_SPACE, EdoConstants.EDO_REVIEWER_PERMISSION, new HashMap<String, String>()))
119 {
120 edoForm.setUseReviewerScreen(true);
121 edoForm.setUseHelpScreen(true);
122 }
123 if(isAuthorized(pId, EdoConstants.EDO_NAME_SPACE, EdoConstants.EDO_GEN_ADMIN_PERMISSION, new HashMap<String, String>()))
124 {
125 edoForm.setUseGenAdminScreen(true);
126 edoForm.setUseHelpScreen(true);
127 }
128
129 if(isAuthorized(pId, EdoConstants.EDO_NAME_SPACE, EdoConstants.EDO_ASSIGN_DELEGATE_PERMISSION, new HashMap<String, String>()))
130 {
131
132 edoForm.setUseAssignDelegateFunc(true);
133 }
134 if(isAuthorized(pId, EdoConstants.EDO_NAME_SPACE, EdoConstants.EDO_ASSIGN_GUEST_PERMISSION, new HashMap<String, String>()))
135 {
136
137 edoForm.setUseAssignGuestFunc(true);
138 }
139
140 List<String> roleIds = new LinkedList<String>();
141 roleIds.add(KimApiServiceLocator.getRoleService().getRoleIdByNamespaceCodeAndName(EdoConstants.EDO_NAME_SPACE, EdoConstants.EDO_SUPERUSER_ROLE));
142 if (KimApiServiceLocator.getRoleService().principalHasRole(pId,roleIds, new HashMap<String, String>())) {
143 edoForm.setCanManageGroups(true);
144 }
145
146 if (EdoServiceLocator.getEdoMaintenanceService().hasCandidateRole(EdoContext.getPrincipalId())) {
147 edoForm.setHasCandidateRole(true);
148 }
149 if (EdoServiceLocator.getEdoMaintenanceService().hasSuperUserRole(EdoContext.getPrincipalId())) {
150 edoForm.setHasSuperUserRole(true);
151 }
152 if (hasChairRole(EdoContext.getPrincipalId())) {
153 edoForm.setHasChairRole(true);
154 }
155
156
157
158
159 if (selectedCandidate.isSelected()) {
160
161 if (EdoServiceLocator.getAuthorizationService().isAuthorizedToEditDossier_W(pId, selectedCandidate.getCandidateDossierID().intValue())) {
162 edoForm.setUseEditDossierFunc(true);
163 }
164
165 if (EdoServiceLocator.getAuthorizationService().isAuthorizedToUploadReviewLetter_W(pId, selectedCandidate.getCandidateDossierID().intValue()) ) {
166 edoForm.setHasUploadReviewLetter(true);
167 }
168
169
170 if (EdoServiceLocator.getAuthorizationService().isAuthorizedToUploadExternalLetter_W(pId, selectedCandidate.getCandidateDossierID().intValue()) ) {
171 edoForm.setHasUploadExternalLetterByDept(true);
172 }
173
174
175 String workflowId = EdoServiceLocator.getEdoDossierService().getEdoDossierById(selectedCandidate.getCandidateDossierID().toString()).getWorkflowId();
176
177 List<BigDecimal> authorizedViewVoteRecordLevels = EdoContext.getAuthorizedViewVoteRecordLevels();
178 List<BigDecimal> authorizedViewReviewLetterLevels = EdoContext.getAuthorizedViewReviewLetterLevels();
179 List<String> routeNodeNames = EdoServiceLocator.getEdoReviewLayerDefinitionService().getValidReviewLevelNodeNames(workflowId);
180 List<String> authLevelVoteNodeIntersect = new LinkedList<String>();
181 List<String> authLevelReviewNodeIntersect = new LinkedList<String>();
182
183
184 for (String nodeName : routeNodeNames) {
185 String nodeLevel = EdoServiceLocator.getEdoReviewLayerDefinitionService().buildReviewLevelByRouteMap(EdoServiceLocator.getEdoReviewLayerDefinitionService().getReviewLayerDefinitions(workflowId)).get(nodeName);
186 if (authorizedViewVoteRecordLevels.contains(nodeLevel)) {
187 authLevelVoteNodeIntersect.add(nodeLevel);
188 }
189 if (authorizedViewReviewLetterLevels.contains(nodeLevel)) {
190 authLevelReviewNodeIntersect.add(nodeLevel);
191 }
192 }
193
194
195 if (CollectionUtils.isNotEmpty(authLevelVoteNodeIntersect) && !(StringUtils.equals(selectedCandidate.getCandidateUsername(), EdoContext.getPrincipalName()))) {
196 edoForm.setHasViewVoteRecordCurrentDossier(true);
197 }
198 if (CollectionUtils.isNotEmpty(authLevelReviewNodeIntersect) && !(StringUtils.equals(selectedCandidate.getCandidateUsername(), EdoContext.getPrincipalName()))) {
199 edoForm.setHasViewReviewLetterCurrentDossier(true);
200 }
201
202 if (EdoRule.canUploadFileUnderReconsiderCategory(selectedCandidate.getCandidateDossierID().toString())) {
203 edoForm.setCanUploadReconsiderItems(true);
204 }
205
206 }
207 }
208 else{
209 edoForm.setUseHelpScreen(true);
210 }
211
212
213 if (request.getParameterMap().containsKey("tabId") ) {
214 request.setAttribute("tabId", request.getParameter("tabId"));
215 } else {
216 request.setAttribute("tabId", "home");
217 }
218
219
220 request.setAttribute("appTitle", config.getProperty("app.title"));
221 request.setAttribute("appSubTitle", config.getProperty("app.subtitle"));
222 request.setAttribute("config", config);
223 request.setAttribute("CGIscript_name", request.getServletPath() );
224 request.setAttribute("CGIquery_string", request.getQueryString() );
225 request.setAttribute("CGIcontext_path", request.getContextPath());
226
227 return super.execute(mapping, form, request, response);
228 }
229
230
231 @Override
232 protected void checkAuthorization(ActionForm form, String methodToCall)
233 throws AuthorizationException {
234
235 }
236
237 public PermissionService getPermissionService() {
238 if(this.permissionService == null) {
239 this.permissionService = KimApiServiceLocator.getPermissionService();
240 }
241 return permissionService;
242 }
243
244 public boolean hasPermission(String principalId, String nameSpace, String permission) {
245 boolean hasPermission = false;
246
247 List<String> allPrincipals = EdoContext.getPrincipalDelegators(principalId);
248
249 for (String principal : allPrincipals) {
250 hasPermission = hasPermission || getPermissionService().hasPermission(principal, nameSpace, permission);
251 }
252
253 return hasPermission;
254
255 }
256
257 public boolean isAuthorized(String principalId, String nameSpace, String permission, HashMap<String, String> quals) {
258 boolean isAuthorized = false;
259
260 List<String> allPrincipals = EdoContext.getPrincipalDelegators(principalId);
261
262 for (String principal : allPrincipals) {
263 isAuthorized = isAuthorized || getPermissionService().isAuthorized(principal, nameSpace, permission, quals);
264 }
265
266 return isAuthorized;
267
268 }
269 public boolean hasCandidateRole(String principalId) {
270 boolean hasCandidateRole = false;
271 List<String> allPrincipals = EdoContext.getPrincipalDelegators(principalId);
272
273 for (String principal : allPrincipals) {
274 hasCandidateRole = hasCandidateRole || EdoServiceLocator.getEdoMaintenanceService().hasCandidateRole_W(principal);
275 }
276 return hasCandidateRole;
277 }
278
279 public boolean hasChairRole(String principalId) {
280 boolean hasChairRole = false;
281 List<String> allPrincipals = EdoContext.getPrincipalDelegators(principalId);
282
283 for (String principal : allPrincipals) {
284 hasChairRole = hasChairRole || EdoServiceLocator.getEdoMaintenanceService().hasChairRole_W(principal);
285 }
286 return hasChairRole;
287 }
288
289
290 }
291
292
293
294
295
296
297