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