1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.web.struts.action; |
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.util.RiceConstants; |
23 | |
import org.kuali.rice.core.util.RiceKeyConstants; |
24 | |
import org.kuali.rice.kew.exception.WorkflowException; |
25 | |
import org.kuali.rice.kim.api.group.Group; |
26 | |
import org.kuali.rice.kim.api.identity.principal.Principal; |
27 | |
import org.kuali.rice.kim.api.role.Role; |
28 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
29 | |
import org.kuali.rice.kim.bo.ui.KimDocumentRoleMember; |
30 | |
import org.kuali.rice.kim.bo.ui.KimDocumentRolePermission; |
31 | |
import org.kuali.rice.kim.bo.ui.KimDocumentRoleQualifier; |
32 | |
import org.kuali.rice.kim.bo.ui.KimDocumentRoleResponsibility; |
33 | |
import org.kuali.rice.kim.bo.ui.RoleDocumentDelegationMember; |
34 | |
import org.kuali.rice.kim.bo.ui.RoleDocumentDelegationMemberQualifier; |
35 | |
import org.kuali.rice.kim.document.IdentityManagementRoleDocument; |
36 | |
import org.kuali.rice.kim.impl.responsibility.AddResponsibilityEvent; |
37 | |
import org.kuali.rice.kim.impl.responsibility.ResponsibilityBo; |
38 | |
import org.kuali.rice.kim.impl.type.KimTypeLookupableHelperServiceImpl; |
39 | |
import org.kuali.rice.kim.rule.event.ui.AddDelegationMemberEvent; |
40 | |
import org.kuali.rice.kim.rule.event.ui.AddMemberEvent; |
41 | |
import org.kuali.rice.kim.rule.event.ui.AddPermissionEvent; |
42 | |
import org.kuali.rice.kim.util.KimConstants; |
43 | |
import org.kuali.rice.kim.web.struts.form.IdentityManagementRoleDocumentForm; |
44 | |
import org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase; |
45 | |
import org.kuali.rice.kns.web.struts.form.KualiTableRenderFormMetadata; |
46 | |
import org.kuali.rice.krad.question.ConfirmationQuestion; |
47 | |
import org.kuali.rice.krad.service.KRADServiceLocator; |
48 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb; |
49 | |
import org.kuali.rice.krad.util.GlobalVariables; |
50 | |
import org.kuali.rice.krad.util.KRADConstants; |
51 | |
|
52 | |
import javax.servlet.http.HttpServletRequest; |
53 | |
import javax.servlet.http.HttpServletResponse; |
54 | |
import java.sql.Timestamp; |
55 | |
import java.util.ArrayList; |
56 | |
import java.util.Arrays; |
57 | |
import java.util.Calendar; |
58 | |
import java.util.HashMap; |
59 | |
import java.util.List; |
60 | |
import java.util.Map; |
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
public class IdentityManagementRoleDocumentAction extends IdentityManagementDocumentActionBase { |
66 | |
|
67 | |
public static final String CHANGE_DEL_ROLE_MEMBER_METHOD_TO_CALL = "changeDelegationRoleMember"; |
68 | |
public static final String SWITCH_TO_ROLE_MEMBER_METHOD_TO_CALL = "jumpToRoleMember"; |
69 | |
public static final String REMOVE_AFFECTED_DELEGATES_QUESTION_ID = "RemoveAffectedDelegates"; |
70 | |
|
71 | 0 | protected List<String> methodToCallToUncheckedList = new ArrayList<String>(); |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
{ |
86 | 0 | methodToCallToUncheckedList.add(CHANGE_DEL_ROLE_MEMBER_METHOD_TO_CALL); |
87 | 0 | methodToCallToUncheckedList.add(CHANGE_MEMBER_TYPE_CODE_METHOD_TO_CALL); |
88 | 0 | methodToCallToUncheckedList.add(CHANGE_NAMESPACE_METHOD_TO_CALL); |
89 | 0 | methodToCallToUncheckedList.add(SWITCH_TO_ROLE_MEMBER_METHOD_TO_CALL); |
90 | |
} |
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
public IdentityManagementRoleDocumentAction() { |
96 | 0 | super(); |
97 | 0 | for (String methodToCallToUncheck : methodToCallToUncheckedList) { |
98 | 0 | addMethodToCallToUncheckedList(methodToCallToUncheck); |
99 | |
} |
100 | 0 | } |
101 | |
|
102 | |
public ActionForward sort(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
103 | |
|
104 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
105 | |
} |
106 | |
|
107 | |
@Override |
108 | |
public ActionForward execute(ActionMapping mapping, ActionForm form, |
109 | |
HttpServletRequest request, HttpServletResponse response) throws Exception { |
110 | 0 | IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; |
111 | 0 | if (roleDocumentForm.getRoleId() == null) { |
112 | 0 | String roleId = request.getParameter(KimConstants.PrimaryKeyConstants.SUB_ROLE_ID); |
113 | 0 | roleDocumentForm.setRoleId(roleId); |
114 | |
} |
115 | |
|
116 | 0 | KualiTableRenderFormMetadata memberTableMetadata = roleDocumentForm.getMemberTableMetadata(); |
117 | 0 | if (roleDocumentForm.getRoleDocument()!=null && roleDocumentForm.getMemberRows() != null) { |
118 | 0 | memberTableMetadata.jumpToPage(memberTableMetadata.getViewedPageNumber(), roleDocumentForm.getMemberRows().size(), roleDocumentForm.getRecordsPerPage()); |
119 | |
|
120 | 0 | memberTableMetadata.sort(roleDocumentForm.getMemberRows(), roleDocumentForm.getRecordsPerPage()); |
121 | |
} |
122 | |
|
123 | |
|
124 | 0 | ActionForward forward = promptForAffectedDelegates(mapping, form, request, response, |
125 | |
roleDocumentForm); |
126 | |
|
127 | 0 | if (forward != null) { return forward; } |
128 | |
|
129 | 0 | forward = super.execute(mapping, roleDocumentForm, request, response); |
130 | |
|
131 | 0 | roleDocumentForm.setCanAssignRole(validAssignRole(roleDocumentForm.getRoleDocument())); |
132 | 0 | if (KimTypeLookupableHelperServiceImpl.hasDerivedRoleTypeService(roleDocumentForm.getRoleDocument().getKimType())) { |
133 | 0 | roleDocumentForm.setCanModifyAssignees(false); |
134 | |
} |
135 | 0 | GlobalVariables.getUserSession().addObject(KimConstants.KimUIConstants.KIM_ROLE_DOCUMENT_SHORT_KEY, roleDocumentForm.getRoleDocument()); |
136 | 0 | return forward; |
137 | |
} |
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
@Override |
145 | |
protected void loadDocument(KualiDocumentFormBase form) |
146 | |
throws WorkflowException { |
147 | 0 | super.loadDocument(form); |
148 | |
|
149 | 0 | IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; |
150 | 0 | setKimType(roleDocumentForm.getRoleDocument().getRoleTypeId(), roleDocumentForm); |
151 | 0 | getUiDocumentService().setDelegationMembersInDocument(roleDocumentForm.getRoleDocument()); |
152 | |
|
153 | 0 | roleDocumentForm.setMember(roleDocumentForm.getRoleDocument().getBlankMember()); |
154 | 0 | roleDocumentForm.setDelegationMember(roleDocumentForm.getRoleDocument().getBlankDelegationMember()); |
155 | |
|
156 | 0 | KualiTableRenderFormMetadata memberTableMetadata = roleDocumentForm.getMemberTableMetadata(); |
157 | 0 | if (roleDocumentForm.getMemberRows() != null) { |
158 | 0 | memberTableMetadata.jumpToFirstPage(roleDocumentForm.getMemberRows().size(), roleDocumentForm.getRecordsPerPage()); |
159 | |
} |
160 | 0 | } |
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
@Override |
168 | |
protected void createDocument(KualiDocumentFormBase form) |
169 | |
throws WorkflowException { |
170 | 0 | super.createDocument(form); |
171 | 0 | IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; |
172 | |
|
173 | 0 | if (roleDocumentForm.getRoleId() == null) { |
174 | 0 | roleDocumentForm.getRoleDocument().setKimType(roleDocumentForm.getKimType()); |
175 | 0 | roleDocumentForm.getRoleDocument().initializeDocumentForNewRole(); |
176 | 0 | roleDocumentForm.setRoleId(roleDocumentForm.getRoleDocument().getRoleId()); |
177 | 0 | roleDocumentForm.setKimType(KimApiServiceLocator.getKimTypeInfoService().getKimType(roleDocumentForm.getRoleDocument().getRoleTypeId())); |
178 | |
} else { |
179 | 0 | loadRoleIntoDocument(roleDocumentForm.getRoleId(), roleDocumentForm); |
180 | |
} |
181 | |
|
182 | 0 | roleDocumentForm.setMember(roleDocumentForm.getRoleDocument().getBlankMember()); |
183 | 0 | roleDocumentForm.setDelegationMember(roleDocumentForm.getRoleDocument().getBlankDelegationMember()); |
184 | |
|
185 | 0 | KualiTableRenderFormMetadata memberTableMetadata = roleDocumentForm.getMemberTableMetadata(); |
186 | 0 | if (roleDocumentForm.getMemberRows() != null) { |
187 | 0 | memberTableMetadata.jumpToFirstPage(roleDocumentForm.getMemberRows().size(), roleDocumentForm.getRecordsPerPage()); |
188 | |
} |
189 | 0 | } |
190 | |
|
191 | |
protected void setKimType(String kimTypeId, IdentityManagementRoleDocumentForm roleDocumentForm) { |
192 | 0 | if (StringUtils.isNotBlank(kimTypeId)) { |
193 | 0 | roleDocumentForm.setKimType(KimApiServiceLocator.getKimTypeInfoService().getKimType(kimTypeId)); |
194 | 0 | if (roleDocumentForm.getRoleDocument() != null) { |
195 | 0 | roleDocumentForm.getRoleDocument().setKimType(roleDocumentForm.getKimType()); |
196 | |
} |
197 | 0 | } else if (roleDocumentForm.getRoleDocument() != null && StringUtils.isNotBlank(roleDocumentForm.getRoleDocument().getRoleTypeId())) { |
198 | 0 | roleDocumentForm.setKimType(KimApiServiceLocator.getKimTypeInfoService().getKimType( |
199 | |
roleDocumentForm.getRoleDocument().getRoleTypeId())); |
200 | 0 | roleDocumentForm.getRoleDocument().setKimType(roleDocumentForm.getKimType()); |
201 | |
} |
202 | 0 | } |
203 | |
|
204 | |
protected void loadRoleIntoDocument(String roleId, IdentityManagementRoleDocumentForm roleDocumentForm) { |
205 | 0 | Role role = KimApiServiceLocator.getRoleService().getRole(roleId); |
206 | 0 | roleDocumentForm.getRoleDocument().setMemberMetaDataTypeToSort(roleDocumentForm.getMemberTableMetadata().getColumnToSortIndex()); |
207 | 0 | getUiDocumentService().loadRoleDoc(roleDocumentForm.getRoleDocument(), role); |
208 | 0 | } |
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
public String getActionName() { |
214 | 0 | return KimConstants.KimUIConstants.KIM_ROLE_DOCUMENT_ACTION; |
215 | |
} |
216 | |
|
217 | |
protected boolean validAssignRole(IdentityManagementRoleDocument document) { |
218 | 0 | boolean rulePassed = true; |
219 | 0 | if (StringUtils.isNotEmpty(document.getRoleNamespace())) { |
220 | 0 | Map<String, String> additionalPermissionDetails = new HashMap<String, String>(); |
221 | 0 | additionalPermissionDetails.put(KimConstants.AttributeConstants.NAMESPACE_CODE, document.getRoleNamespace()); |
222 | 0 | additionalPermissionDetails.put(KimConstants.AttributeConstants.ROLE_NAME, document.getRoleName()); |
223 | 0 | if (!getDocumentHelperService().getDocumentAuthorizer(document).isAuthorizedByTemplate( |
224 | |
document, |
225 | |
KimConstants.NAMESPACE_CODE, |
226 | |
KimConstants.PermissionTemplateNames.ASSIGN_ROLE, |
227 | |
GlobalVariables.getUserSession().getPrincipalId(), |
228 | |
additionalPermissionDetails, null)) { |
229 | 0 | rulePassed = false; |
230 | |
} |
231 | |
} |
232 | 0 | return rulePassed; |
233 | |
} |
234 | |
|
235 | |
public ActionForward changeMemberTypeCode(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
236 | 0 | IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; |
237 | 0 | roleDocumentForm.getMember().setMemberId(""); |
238 | 0 | return refresh(mapping, roleDocumentForm, request, response); |
239 | |
} |
240 | |
|
241 | |
public ActionForward changeDelegationMemberTypeCode(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
242 | 0 | IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; |
243 | 0 | KimDocumentRoleMember roleMember = roleDocumentForm.getRoleDocument().getMember(roleDocumentForm.getDelegationMember().getRoleMemberId()); |
244 | 0 | if (roleMember != null) { |
245 | |
RoleDocumentDelegationMemberQualifier delegationMemberQualifier; |
246 | 0 | for (KimDocumentRoleQualifier roleQualifier : roleMember.getQualifiers()) { |
247 | 0 | delegationMemberQualifier = roleDocumentForm.getDelegationMember().getQualifier(roleQualifier.getKimAttrDefnId()); |
248 | 0 | delegationMemberQualifier.setAttrVal(roleQualifier.getAttrVal()); |
249 | |
} |
250 | |
} |
251 | 0 | return refresh(mapping, roleDocumentForm, request, response); |
252 | |
} |
253 | |
|
254 | |
public ActionForward addResponsibility(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
255 | 0 | IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; |
256 | 0 | KimDocumentRoleResponsibility newResponsibility = roleDocumentForm.getResponsibility(); |
257 | 0 | if (newResponsibility != null && StringUtils.isNotBlank(newResponsibility.getResponsibilityId())) { |
258 | 0 | Map<String, String> criteria = new HashMap<String, String>(); |
259 | 0 | criteria.put(KimConstants.PrimaryKeyConstants.RESPONSIBILITY_ID, newResponsibility.getResponsibilityId()); |
260 | 0 | ResponsibilityBo responsibilityImpl = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(ResponsibilityBo.class, criteria); |
261 | 0 | newResponsibility.setKimResponsibility(responsibilityImpl); |
262 | |
} |
263 | |
|
264 | 0 | if (KRADServiceLocatorWeb.getKualiRuleService().applyRules(new AddResponsibilityEvent("", roleDocumentForm.getRoleDocument(), newResponsibility))) { |
265 | 0 | if (newResponsibility != null) { |
266 | 0 | newResponsibility.setDocumentNumber(roleDocumentForm.getDocument().getDocumentNumber()); |
267 | |
} |
268 | 0 | roleDocumentForm.getRoleDocument().addResponsibility(newResponsibility); |
269 | 0 | roleDocumentForm.setResponsibility(new KimDocumentRoleResponsibility()); |
270 | 0 | roleDocumentForm.getRoleDocument().updateMembers(newResponsibility); |
271 | |
} |
272 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
273 | |
} |
274 | |
|
275 | |
public ActionForward deleteResponsibility(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
276 | 0 | IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; |
277 | 0 | roleDocumentForm.getRoleDocument().getResponsibilities().remove(getLineToDelete(request)); |
278 | 0 | roleDocumentForm.getRoleDocument().updateMembers(roleDocumentForm); |
279 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
280 | |
} |
281 | |
|
282 | |
public ActionForward addPermission(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
283 | 0 | IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; |
284 | 0 | KimDocumentRolePermission newPermission = roleDocumentForm.getPermission(); |
285 | 0 | if (KRADServiceLocatorWeb.getKualiRuleService().applyRules(new AddPermissionEvent("", roleDocumentForm.getRoleDocument(), newPermission))) { |
286 | 0 | newPermission.setDocumentNumber(roleDocumentForm.getDocument().getDocumentNumber()); |
287 | 0 | newPermission.setRoleId(roleDocumentForm.getRoleDocument().getRoleId()); |
288 | 0 | roleDocumentForm.getRoleDocument().getPermissions().add(newPermission); |
289 | 0 | roleDocumentForm.setPermission(new KimDocumentRolePermission()); |
290 | |
} |
291 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
292 | |
} |
293 | |
|
294 | |
public ActionForward addMember(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
295 | 0 | IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; |
296 | 0 | KimDocumentRoleMember newMember = roleDocumentForm.getMember(); |
297 | |
|
298 | |
|
299 | 0 | if (StringUtils.isEmpty(newMember.getMemberId()) |
300 | |
&& StringUtils.isNotEmpty(newMember.getMemberName()) |
301 | |
&& StringUtils.isNotEmpty(newMember.getMemberNamespaceCode()) |
302 | |
&& StringUtils.equals(newMember.getMemberTypeCode(), KimConstants.KimGroupMemberTypes.GROUP_MEMBER_TYPE)) { |
303 | 0 | Group tempGroup = KimApiServiceLocator.getGroupService().getGroupByName(newMember.getMemberNamespaceCode(), newMember.getMemberName()); |
304 | 0 | if (tempGroup != null) { |
305 | 0 | newMember.setMemberId(tempGroup.getId()); |
306 | |
} |
307 | |
} |
308 | |
|
309 | |
|
310 | 0 | if (StringUtils.isEmpty(newMember.getMemberId()) |
311 | |
&& StringUtils.isNotEmpty(newMember.getMemberName()) |
312 | |
&& StringUtils.equals(newMember.getMemberTypeCode(), KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE)) { |
313 | 0 | Principal principal = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(newMember.getMemberName()); |
314 | 0 | if (principal != null) { |
315 | 0 | newMember.setMemberId(principal.getPrincipalId()); |
316 | |
} |
317 | |
} |
318 | 0 | if (checkKimDocumentRoleMember(newMember) && |
319 | |
KRADServiceLocatorWeb.getKualiRuleService().applyRules(new AddMemberEvent("", roleDocumentForm.getRoleDocument(), newMember))) { |
320 | 0 | newMember.setDocumentNumber(roleDocumentForm.getDocument().getDocumentNumber()); |
321 | 0 | roleDocumentForm.getRoleDocument().addMember(newMember); |
322 | 0 | roleDocumentForm.setMember(roleDocumentForm.getRoleDocument().getBlankMember()); |
323 | 0 | roleDocumentForm.getMemberTableMetadata().jumpToLastPage(roleDocumentForm.getMemberRows().size(), roleDocumentForm.getRecordsPerPage()); |
324 | |
} |
325 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
326 | |
} |
327 | |
|
328 | |
protected boolean checkKimDocumentRoleMember(KimDocumentRoleMember newMember) { |
329 | 0 | boolean memberExists = false; |
330 | 0 | String memberName = null; |
331 | 0 | String memberNamespace = null; |
332 | |
|
333 | 0 | if (StringUtils.isBlank(newMember.getMemberTypeCode()) || StringUtils.isBlank(newMember.getMemberId())) { |
334 | 0 | GlobalVariables.getMessageMap().putError("document.member.memberId", RiceKeyConstants.ERROR_EMPTY_ENTRY, |
335 | |
new String[]{"Member Type Code and Member ID"}); |
336 | 0 | return false; |
337 | |
} |
338 | |
|
339 | 0 | if (KimConstants.KimUIConstants.MEMBER_TYPE_PRINCIPAL_CODE.equals(newMember.getMemberTypeCode())) { |
340 | 0 | Principal pi = this.getIdentityService().getPrincipal(newMember.getMemberId()); |
341 | 0 | if (pi != null) { |
342 | 0 | memberExists = true; |
343 | 0 | memberName = pi.getPrincipalName(); |
344 | 0 | memberNamespace = ""; |
345 | |
} |
346 | 0 | } else if (KimConstants.KimUIConstants.MEMBER_TYPE_GROUP_CODE.equals(newMember.getMemberTypeCode())) { |
347 | 0 | Group gi = KimApiServiceLocator.getGroupService().getGroup(newMember.getMemberId()); |
348 | 0 | if (gi != null) { |
349 | 0 | memberExists = true; |
350 | 0 | memberName = gi.getName(); |
351 | 0 | memberNamespace = gi.getNamespaceCode(); |
352 | |
} |
353 | 0 | } else if (KimConstants.KimUIConstants.MEMBER_TYPE_ROLE_CODE.equals(newMember.getMemberTypeCode())) { |
354 | 0 | Role ri = KimApiServiceLocator.getRoleService().getRole(newMember.getMemberId()); |
355 | 0 | if (!validateRole(newMember.getMemberId(), ri, "document.member.memberId", "Role")) { |
356 | 0 | return false; |
357 | |
} else { |
358 | 0 | memberExists = true; |
359 | 0 | memberName = ri.getName(); |
360 | 0 | memberNamespace = ri.getNamespaceCode(); |
361 | |
} |
362 | |
} |
363 | |
|
364 | 0 | if (!memberExists) { |
365 | 0 | GlobalVariables.getMessageMap().putError("document.member.memberId", RiceKeyConstants.ERROR_MEMBERID_MEMBERTYPE_MISMATCH, |
366 | |
new String[]{newMember.getMemberId()}); |
367 | 0 | return false; |
368 | |
} |
369 | 0 | newMember.setMemberName(memberName); |
370 | 0 | newMember.setMemberNamespaceCode(memberNamespace); |
371 | 0 | return true; |
372 | |
} |
373 | |
|
374 | |
public ActionForward deleteMember(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
375 | 0 | IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; |
376 | 0 | KimDocumentRoleMember inactivatedRoleMember = roleDocumentForm.getRoleDocument().getMembers().get(getLineToDelete(request)); |
377 | |
|
378 | |
|
379 | 0 | ActionForward forward = promptForAffectedDelegates(mapping, form, request, response, |
380 | |
roleDocumentForm, inactivatedRoleMember); |
381 | |
|
382 | 0 | if (forward != null) { |
383 | 0 | return forward; |
384 | |
} |
385 | |
|
386 | 0 | Calendar cal = Calendar.getInstance(); |
387 | 0 | inactivatedRoleMember.setActiveToDate(new Timestamp(cal.getTimeInMillis())); |
388 | |
|
389 | 0 | roleDocumentForm.getRoleDocument().getMembers().set(getLineToDelete(request), inactivatedRoleMember); |
390 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
391 | |
} |
392 | |
|
393 | |
public ActionForward deletePermission(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
394 | 0 | IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; |
395 | 0 | roleDocumentForm.getRoleDocument().getPermissions().remove(getLineToDelete(request)); |
396 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
397 | |
} |
398 | |
|
399 | |
protected boolean checkDelegationMember(RoleDocumentDelegationMember newMember) { |
400 | 0 | if (StringUtils.isBlank(newMember.getMemberTypeCode()) || StringUtils.isBlank(newMember.getMemberId())) { |
401 | 0 | GlobalVariables.getMessageMap().putError("document.delegationMember.memberId", RiceKeyConstants.ERROR_EMPTY_ENTRY, |
402 | |
new String[]{"Member Type Code and Member ID"}); |
403 | 0 | return false; |
404 | |
} |
405 | 0 | if (KimConstants.KimUIConstants.MEMBER_TYPE_PRINCIPAL_CODE.equals(newMember.getMemberTypeCode())) { |
406 | 0 | Principal principalInfo = getIdentityService().getPrincipal(newMember.getMemberId()); |
407 | 0 | if (principalInfo == null) { |
408 | 0 | GlobalVariables.getMessageMap().putError("document.delegationMember.memberId", RiceKeyConstants.ERROR_MEMBERID_MEMBERTYPE_MISMATCH, |
409 | |
new String[]{newMember.getMemberId()}); |
410 | 0 | return false; |
411 | |
} else { |
412 | 0 | newMember.setMemberName(principalInfo.getPrincipalName()); |
413 | |
} |
414 | 0 | } else if (KimConstants.KimUIConstants.MEMBER_TYPE_GROUP_CODE.equals(newMember.getMemberTypeCode())) { |
415 | 0 | Group groupInfo = null; |
416 | 0 | groupInfo = getGroupService().getGroup(newMember.getMemberId()); |
417 | 0 | if (groupInfo == null) { |
418 | 0 | GlobalVariables.getMessageMap().putError("document.delegationMember.memberId", RiceKeyConstants.ERROR_MEMBERID_MEMBERTYPE_MISMATCH, |
419 | |
new String[]{newMember.getMemberId()}); |
420 | 0 | return false; |
421 | |
} else { |
422 | 0 | newMember.setMemberName(groupInfo.getName()); |
423 | 0 | newMember.setMemberNamespaceCode(groupInfo.getNamespaceCode()); |
424 | |
} |
425 | 0 | } else if (KimConstants.KimUIConstants.MEMBER_TYPE_ROLE_CODE.equals(newMember.getMemberTypeCode())) { |
426 | 0 | Role roleInfo = KimApiServiceLocator.getRoleService().getRole(newMember.getMemberId()); |
427 | 0 | if (roleInfo == null) { |
428 | 0 | GlobalVariables.getMessageMap().putError("document.delegationMember.memberId", RiceKeyConstants.ERROR_MEMBERID_MEMBERTYPE_MISMATCH, |
429 | |
new String[]{newMember.getMemberId()}); |
430 | 0 | return false; |
431 | |
} else { |
432 | 0 | newMember.setMemberName(roleInfo.getName()); |
433 | 0 | newMember.setMemberNamespaceCode(roleInfo.getNamespaceCode()); |
434 | |
} |
435 | |
} |
436 | 0 | return true; |
437 | |
} |
438 | |
|
439 | |
public ActionForward addDelegationMember(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
440 | 0 | IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; |
441 | 0 | RoleDocumentDelegationMember newDelegationMember = roleDocumentForm.getDelegationMember(); |
442 | |
|
443 | |
|
444 | 0 | if (StringUtils.isEmpty(newDelegationMember.getMemberId()) |
445 | |
&& StringUtils.isNotEmpty(newDelegationMember.getMemberName()) |
446 | |
&& StringUtils.isNotEmpty(newDelegationMember.getMemberNamespaceCode()) |
447 | |
&& StringUtils.equals(newDelegationMember.getMemberTypeCode(), KimConstants.KimGroupMemberTypes.GROUP_MEMBER_TYPE)) { |
448 | 0 | Group tempGroup = KimApiServiceLocator.getGroupService().getGroupByName(newDelegationMember.getMemberNamespaceCode(), newDelegationMember.getMemberName()); |
449 | 0 | if (tempGroup != null) { |
450 | 0 | newDelegationMember.setMemberId(tempGroup.getId()); |
451 | |
} |
452 | |
} |
453 | |
|
454 | |
|
455 | 0 | if (StringUtils.isEmpty(newDelegationMember.getMemberId()) |
456 | |
&& StringUtils.isNotEmpty(newDelegationMember.getMemberName()) |
457 | |
&& StringUtils.equals(newDelegationMember.getMemberTypeCode(), KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE)) { |
458 | 0 | Principal principal = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(newDelegationMember.getMemberName()); |
459 | 0 | if (principal != null) { |
460 | 0 | newDelegationMember.setMemberId(principal.getPrincipalId()); |
461 | |
} |
462 | |
} |
463 | |
|
464 | 0 | if (checkDelegationMember(newDelegationMember) && KRADServiceLocatorWeb.getKualiRuleService().applyRules( |
465 | |
new AddDelegationMemberEvent("", roleDocumentForm.getRoleDocument(), newDelegationMember))) { |
466 | 0 | newDelegationMember.setDocumentNumber(roleDocumentForm.getDocument().getDocumentNumber()); |
467 | 0 | roleDocumentForm.getRoleDocument().addDelegationMember(newDelegationMember); |
468 | 0 | roleDocumentForm.setDelegationMember(roleDocumentForm.getRoleDocument().getBlankDelegationMember()); |
469 | |
} |
470 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
471 | |
} |
472 | |
|
473 | |
public ActionForward deleteDelegationMember(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
474 | 0 | IdentityManagementRoleDocumentForm roleDocumentForm = (IdentityManagementRoleDocumentForm) form; |
475 | |
|
476 | 0 | roleDocumentForm.getRoleDocument().getDelegationMembers().remove(getLineToDelete(request)); |
477 | 0 | roleDocumentForm.setDelegationMember(roleDocumentForm.getRoleDocument().getBlankDelegationMember()); |
478 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
479 | |
} |
480 | |
|
481 | |
|
482 | |
|
483 | |
|
484 | |
|
485 | |
public ActionForward jumpToRoleMember(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
486 | 0 | IdentityManagementRoleDocumentForm idmForm = (IdentityManagementRoleDocumentForm) form; |
487 | 0 | String delegationRoleMemberId = getDelegationRoleMemberToJumpTo(request); |
488 | 0 | KualiTableRenderFormMetadata memberTableMetadata = idmForm.getMemberTableMetadata(); |
489 | 0 | memberTableMetadata.jumpToPage(idmForm.getPageNumberOfRoleMemberId(delegationRoleMemberId), |
490 | |
idmForm.getMemberRows().size(), idmForm.getRecordsPerPage()); |
491 | 0 | memberTableMetadata.setColumnToSortIndex(memberTableMetadata.getPreviouslySortedColumnIndex()); |
492 | 0 | idmForm.setAnchor(delegationRoleMemberId); |
493 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
494 | |
} |
495 | |
|
496 | |
protected String getDelegationRoleMemberToJumpTo(HttpServletRequest request) { |
497 | 0 | String delegationRoleMemberIdToJumpTo = ""; |
498 | 0 | String parameterName = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE); |
499 | 0 | if (StringUtils.isNotBlank(parameterName)) { |
500 | 0 | delegationRoleMemberIdToJumpTo = StringUtils.substringBetween(parameterName, ".dmrmi", "."); |
501 | |
} |
502 | 0 | return delegationRoleMemberIdToJumpTo; |
503 | |
} |
504 | |
|
505 | |
|
506 | |
|
507 | |
|
508 | |
|
509 | |
|
510 | |
|
511 | |
|
512 | |
|
513 | |
private ActionForward promptForAffectedDelegates(ActionMapping mapping, |
514 | |
ActionForm form, HttpServletRequest request, |
515 | |
HttpServletResponse response, |
516 | |
IdentityManagementRoleDocumentForm roleDocumentForm, KimDocumentRoleMember... roleMembersToConsiderInactive) |
517 | |
throws Exception { |
518 | |
|
519 | |
|
520 | |
|
521 | 0 | List<RoleDocumentDelegationMember> activeDelegatesOfInactiveRoleMembers = |
522 | |
getActiveDelegatesOfInactiveRoleMembers(roleDocumentForm, roleMembersToConsiderInactive); |
523 | 0 | ActionForward forward = getAffectedDelegatesQuestionActionForward(activeDelegatesOfInactiveRoleMembers, mapping, form, request, |
524 | |
response, roleDocumentForm); |
525 | |
|
526 | 0 | if (forward != null) { |
527 | 0 | return forward; |
528 | |
} |
529 | |
|
530 | 0 | if (activeDelegatesOfInactiveRoleMembers.size() > 0) { |
531 | 0 | Calendar cal = Calendar.getInstance(); |
532 | |
|
533 | 0 | for (RoleDocumentDelegationMember delegateToDeactivate : activeDelegatesOfInactiveRoleMembers) { |
534 | 0 | delegateToDeactivate.setActiveToDate(new Timestamp(cal.getTimeInMillis())); |
535 | |
} |
536 | |
} |
537 | 0 | return null; |
538 | |
} |
539 | |
|
540 | |
|
541 | |
|
542 | |
|
543 | |
|
544 | |
|
545 | |
|
546 | |
|
547 | |
private ActionForward getAffectedDelegatesQuestionActionForward(List<RoleDocumentDelegationMember> activeDelegatesOfInactiveRoleMembers, |
548 | |
ActionMapping mapping, ActionForm form, HttpServletRequest request, |
549 | |
HttpServletResponse response, |
550 | |
IdentityManagementRoleDocumentForm roleDocumentForm) |
551 | |
throws Exception { |
552 | |
|
553 | 0 | if (activeDelegatesOfInactiveRoleMembers.size() > 0) { |
554 | 0 | Object question = getQuestion(request); |
555 | |
|
556 | 0 | if (question == null || !REMOVE_AFFECTED_DELEGATES_QUESTION_ID.equals(question)) { |
557 | 0 | return performQuestionWithoutInput(mapping, form, request, response, REMOVE_AFFECTED_DELEGATES_QUESTION_ID, |
558 | |
getKualiConfigurationService().getPropertyString(RiceKeyConstants.QUESTION_ACTIVE_DELEGATES_FOR_INACTIVE_MEMBERS), |
559 | |
KRADConstants.CONFIRMATION_QUESTION, roleDocumentForm.getMethodToCall(), StringUtils.EMPTY); |
560 | |
} |
561 | 0 | Object buttonClicked = request.getParameter(KRADConstants.QUESTION_CLICKED_BUTTON); |
562 | 0 | if ((REMOVE_AFFECTED_DELEGATES_QUESTION_ID.equals(question)) && ConfirmationQuestion.YES.equals(buttonClicked)) { |
563 | |
|
564 | |
|
565 | |
} else { |
566 | |
|
567 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
568 | |
} |
569 | |
} |
570 | |
|
571 | 0 | return null; |
572 | |
} |
573 | |
|
574 | |
|
575 | |
|
576 | |
|
577 | |
|
578 | |
|
579 | |
|
580 | |
|
581 | |
private List<RoleDocumentDelegationMember> getActiveDelegatesOfInactiveRoleMembers( |
582 | |
IdentityManagementRoleDocumentForm roleDocumentForm, KimDocumentRoleMember... roleMembersToConsiderInactive) { |
583 | 0 | List<KimDocumentRoleMember> roleMembers = roleDocumentForm.getMemberRows(); |
584 | 0 | List<KimDocumentRoleMember> inactiveRoleMembers = new ArrayList<KimDocumentRoleMember>(); |
585 | 0 | List<RoleDocumentDelegationMember> activeDelegatesOfInactivatedRoleMembers = new ArrayList<RoleDocumentDelegationMember>(); |
586 | |
|
587 | 0 | inactiveRoleMembers.addAll(Arrays.asList(roleMembersToConsiderInactive)); |
588 | |
|
589 | 0 | if (roleMembers != null) { |
590 | 0 | for (KimDocumentRoleMember roleMember : roleMembers) { |
591 | 0 | if (roleMember != null) { |
592 | 0 | if (!roleMember.isActive()) { |
593 | 0 | inactiveRoleMembers.add(roleMember); |
594 | |
} |
595 | |
} |
596 | |
} |
597 | |
} |
598 | |
|
599 | 0 | for (KimDocumentRoleMember inactiveRoleMember : inactiveRoleMembers) { |
600 | |
|
601 | 0 | List<RoleDocumentDelegationMember> delegationMembers = roleDocumentForm.getRoleDocument().getDelegationMembers(); |
602 | 0 | if (delegationMembers != null) { |
603 | 0 | for (RoleDocumentDelegationMember delegationMember : delegationMembers) { |
604 | 0 | if (delegationMember != null && delegationMember.isActive()) { |
605 | |
|
606 | 0 | if (delegationMember.getRoleMemberId().equals(inactiveRoleMember.getRoleMemberId())) { |
607 | 0 | activeDelegatesOfInactivatedRoleMembers.add(delegationMember); |
608 | |
} |
609 | |
} |
610 | |
} |
611 | |
} |
612 | 0 | } |
613 | 0 | return activeDelegatesOfInactivatedRoleMembers; |
614 | |
} |
615 | |
|
616 | |
|
617 | |
|
618 | |
|
619 | |
|
620 | |
|
621 | |
|
622 | |
@Override |
623 | |
protected boolean validateRole(String roleId, Role role, String propertyName, String message) { |
624 | 0 | if (role == null) { |
625 | 0 | GlobalVariables.getMessageMap().putError(propertyName, RiceKeyConstants.ERROR_INVALID_ROLE, roleId); |
626 | 0 | return false; |
627 | |
} |
628 | 0 | return true; |
629 | |
} |
630 | |
|
631 | |
|
632 | |
} |