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