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.entity.EntityDefault;
29 import org.kuali.rice.kim.api.identity.principal.Principal;
30 import org.kuali.rice.kim.api.role.Role;
31 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
32 import org.kuali.rice.kim.api.type.KimAttributeField;
33 import org.kuali.rice.kim.bo.ui.KimDocumentRoleMember;
34 import org.kuali.rice.kim.bo.ui.KimDocumentRoleQualifier;
35 import org.kuali.rice.kim.bo.ui.KimDocumentRoleResponsibilityAction;
36 import org.kuali.rice.kim.bo.ui.PersonDocumentAddress;
37 import org.kuali.rice.kim.bo.ui.PersonDocumentAffiliation;
38 import org.kuali.rice.kim.bo.ui.PersonDocumentCitizenship;
39 import org.kuali.rice.kim.bo.ui.PersonDocumentEmail;
40 import org.kuali.rice.kim.bo.ui.PersonDocumentEmploymentInfo;
41 import org.kuali.rice.kim.bo.ui.PersonDocumentGroup;
42 import org.kuali.rice.kim.bo.ui.PersonDocumentName;
43 import org.kuali.rice.kim.bo.ui.PersonDocumentPhone;
44 import org.kuali.rice.kim.bo.ui.PersonDocumentRole;
45 import org.kuali.rice.kim.bo.ui.RoleDocumentDelegationMember;
46 import org.kuali.rice.kim.bo.ui.RoleDocumentDelegationMemberQualifier;
47 import org.kuali.rice.kim.document.IdentityManagementPersonDocument;
48 import org.kuali.rice.kim.document.rule.AttributeValidationHelper;
49 import org.kuali.rice.kim.framework.type.KimTypeService;
50 import org.kuali.rice.kim.impl.KIMPropertyConstants;
51 import org.kuali.rice.kim.impl.responsibility.ResponsibilityInternalService;
52 import org.kuali.rice.kim.impl.role.RoleBo;
53 import org.kuali.rice.kim.impl.role.RoleMemberBo;
54 import org.kuali.rice.kim.impl.role.RoleResponsibilityBo;
55 import org.kuali.rice.kim.impl.services.KimImplServiceLocator;
56 import org.kuali.rice.kim.impl.type.KimTypeAttributesHelper;
57 import org.kuali.rice.kim.impl.type.KimTypeBo;
58 import org.kuali.rice.kim.rule.event.ui.AddGroupEvent;
59 import org.kuali.rice.kim.rule.event.ui.AddPersonDelegationMemberEvent;
60 import org.kuali.rice.kim.rule.event.ui.AddPersonDocumentRoleQualifierEvent;
61 import org.kuali.rice.kim.rule.event.ui.AddRoleEvent;
62 import org.kuali.rice.kim.rules.ui.PersonDocumentRoleRule;
63 import org.kuali.rice.kim.service.KIMServiceLocatorInternal;
64 import org.kuali.rice.kim.web.struts.form.IdentityManagementPersonDocumentForm;
65 import org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase;
66 import org.kuali.rice.krad.util.GlobalVariables;
67 import org.kuali.rice.krad.util.KRADConstants;
68 import org.kuali.rice.krad.util.UrlFactory;
69
70 import javax.servlet.http.HttpServletRequest;
71 import javax.servlet.http.HttpServletResponse;
72 import java.sql.Timestamp;
73 import java.text.MessageFormat;
74 import java.util.ArrayList;
75 import java.util.Calendar;
76 import java.util.List;
77 import java.util.Map;
78 import java.util.Properties;
79
80
81
82
83
84
85
86 public class IdentityManagementPersonDocumentAction extends IdentityManagementDocumentActionBase {
87
88 protected ResponsibilityInternalService responsibilityInternalService;
89
90 @Override
91 public ActionForward execute(ActionMapping mapping, ActionForm form,
92 HttpServletRequest request, HttpServletResponse response)
93 throws Exception {
94 ActionForward forward;
95 IdentityManagementPersonDocumentForm personDocumentForm = (IdentityManagementPersonDocumentForm) form;
96
97
98 String principalId = request.getParameter(KIMPropertyConstants.Person.PRINCIPAL_ID);
99 String principalName = request.getParameter(KIMPropertyConstants.Person.PRINCIPAL_NAME);
100 if ( StringUtils.isBlank(principalId) && StringUtils.isNotBlank(principalName) ) {
101 Principal principal = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(principalName);
102 if ( principal != null ) {
103 principalId = principal.getPrincipalId();
104 }
105 }
106 if ( principalId != null ) {
107 personDocumentForm.setPrincipalId(principalId);
108 }
109 forward = super.execute(mapping, form, request, response);
110
111 personDocumentForm.setCanModifyEntity(getUiDocumentService().canModifyEntity(GlobalVariables.getUserSession().getPrincipalId(), personDocumentForm.getPrincipalId()));
112 EntityDefault origEntity = null;
113 if(personDocumentForm.getPersonDocument()!=null) {
114 origEntity = getIdentityService().getEntityDefault(personDocumentForm.getPersonDocument().getEntityId());
115 }
116 boolean isCreatingNew = (personDocumentForm.getPersonDocument()==null || origEntity==null)?true:false;
117 personDocumentForm.setCanOverrideEntityPrivacyPreferences(isCreatingNew || getUiDocumentService().canOverrideEntityPrivacyPreferences(GlobalVariables.getUserSession().getPrincipalId(), personDocumentForm.getPrincipalId()));
118 return forward;
119 }
120
121 @Override
122 protected void loadDocument(KualiDocumentFormBase form)
123 throws WorkflowException {
124 super.loadDocument(form);
125 IdentityManagementPersonDocumentForm personDocumentForm = (IdentityManagementPersonDocumentForm) form;
126 IdentityManagementPersonDocument personDoc = personDocumentForm.getPersonDocument();
127 populateRoleInformation(personDoc);
128 }
129
130 protected void populateRoleInformation( IdentityManagementPersonDocument personDoc ) {
131 for (PersonDocumentRole role : personDoc.getRoles()) {
132
133 KimTypeService kimTypeService = getKimTypeService(KimTypeBo.to(role.getKimRoleType()));
134 if ( kimTypeService != null ) {
135 role.setDefinitions(kimTypeService.getAttributeDefinitions(role.getKimTypeId()));
136 }
137
138 role.setNewRolePrncpl(new KimDocumentRoleMember());
139 for (KimAttributeField key : role.getDefinitions()) {
140 KimDocumentRoleQualifier qualifier = new KimDocumentRoleQualifier();
141
142 setAttrDefnIdForQualifier(qualifier,key);
143 role.getNewRolePrncpl().getQualifiers().add(qualifier);
144 }
145 role.setAttributeEntry( getUiDocumentService().getAttributeEntries( role.getDefinitions() ) );
146 }
147 }
148
149 @Override
150 protected void createDocument(KualiDocumentFormBase form)
151 throws WorkflowException {
152 super.createDocument(form);
153 IdentityManagementPersonDocumentForm personDocumentForm = (IdentityManagementPersonDocumentForm) form;
154 if(StringUtils.isBlank(personDocumentForm.getPrincipalId())){
155 personDocumentForm.getPersonDocument().initializeDocumentForNewPerson();
156 personDocumentForm.setPrincipalId(personDocumentForm.getPersonDocument().getPrincipalId());
157 } else {
158 getUiDocumentService().loadEntityToPersonDoc(personDocumentForm.getPersonDocument(), personDocumentForm.getPrincipalId() );
159 populateRoleInformation( personDocumentForm.getPersonDocument() );
160 if(personDocumentForm.getPersonDocument()!=null) {
161 personDocumentForm.getPersonDocument().setIfRolesEditable();
162 }
163 }
164 }
165
166
167
168
169 @Override
170 public String getActionName(){
171 return KimConstants.KimUIConstants.KIM_PERSON_DOCUMENT_ACTION;
172 }
173
174 public ActionForward addAffln(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
175 IdentityManagementPersonDocumentForm personDocumentForm = (IdentityManagementPersonDocumentForm) form;
176 PersonDocumentAffiliation newAffln = personDocumentForm.getNewAffln();
177 newAffln.setDocumentNumber(personDocumentForm.getPersonDocument().getDocumentNumber());
178 newAffln.refreshReferenceObject("affiliationType");
179 personDocumentForm.getPersonDocument().getAffiliations().add(newAffln);
180 personDocumentForm.setNewAffln(new PersonDocumentAffiliation());
181 return mapping.findForward(RiceConstants.MAPPING_BASIC);
182 }
183
184 public ActionForward deleteAffln(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
185 IdentityManagementPersonDocumentForm personDocumentForm = (IdentityManagementPersonDocumentForm) form;
186 personDocumentForm.getPersonDocument().getAffiliations().remove(getLineToDelete(request));
187 return mapping.findForward(RiceConstants.MAPPING_BASIC);
188 }
189 public ActionForward addCitizenship(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
190 IdentityManagementPersonDocumentForm personDocumentForm = (IdentityManagementPersonDocumentForm) form;
191 PersonDocumentCitizenship newCitizenship = personDocumentForm.getNewCitizenship();
192 personDocumentForm.getPersonDocument().getCitizenships().add(newCitizenship);
193 personDocumentForm.setNewCitizenship(new PersonDocumentCitizenship());
194 return mapping.findForward(RiceConstants.MAPPING_BASIC);
195 }
196
197 public ActionForward deleteCitizenship(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
198 IdentityManagementPersonDocumentForm personDocumentForm = (IdentityManagementPersonDocumentForm) form;
199 personDocumentForm.getPersonDocument().getCitizenships().remove(getLineToDelete(request));
200 return mapping.findForward(RiceConstants.MAPPING_BASIC);
201 }
202
203 public ActionForward addEmpInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
204 IdentityManagementPersonDocumentForm personDocumentForm = (IdentityManagementPersonDocumentForm) form;
205 IdentityManagementPersonDocument personDOc = personDocumentForm.getPersonDocument();
206 PersonDocumentAffiliation affiliation = personDOc.getAffiliations().get(getSelectedLine(request));
207 PersonDocumentEmploymentInfo newempInfo = affiliation.getNewEmpInfo();
208 newempInfo.setDocumentNumber(personDOc.getDocumentNumber());
209 newempInfo.setVersionNumber(new Long(1));
210 affiliation.getEmpInfos().add(newempInfo);
211 affiliation.setNewEmpInfo(new PersonDocumentEmploymentInfo());
212 return mapping.findForward(RiceConstants.MAPPING_BASIC);
213 }
214
215 public ActionForward deleteEmpInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
216 IdentityManagementPersonDocumentForm personDocumentForm = (IdentityManagementPersonDocumentForm) form;
217 String selectedIndexes = getSelectedParentChildIdx(request);
218 if (selectedIndexes != null) {
219 String [] indexes = StringUtils.split(selectedIndexes,":");
220 PersonDocumentAffiliation affiliation = personDocumentForm.getPersonDocument().getAffiliations().get(Integer.parseInt(indexes[0]));
221 affiliation.getEmpInfos().remove(Integer.parseInt(indexes[1]));
222 }
223 return mapping.findForward(RiceConstants.MAPPING_BASIC);
224 }
225
226 protected String getSelectedParentChildIdx(HttpServletRequest request) {
227 String lineNumber = null;
228 String parameterName = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE);
229 if (StringUtils.isNotBlank(parameterName)) {
230 lineNumber = StringUtils.substringBetween(parameterName, ".line", ".");
231 }
232 return lineNumber;
233 }
234
235 public ActionForward addName(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
236 IdentityManagementPersonDocumentForm personDocumentForm = (IdentityManagementPersonDocumentForm) form;
237 PersonDocumentName newName = personDocumentForm.getNewName();
238 newName.setDocumentNumber(personDocumentForm.getDocument().getDocumentNumber());
239 personDocumentForm.getPersonDocument().getNames().add(newName);
240 personDocumentForm.setNewName(new PersonDocumentName());
241 return mapping.findForward(RiceConstants.MAPPING_BASIC);
242 }
243
244 public ActionForward deleteName(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
245 IdentityManagementPersonDocumentForm personDocumentForm = (IdentityManagementPersonDocumentForm) form;
246 personDocumentForm.getPersonDocument().getNames().remove(getLineToDelete(request));
247 return mapping.findForward(RiceConstants.MAPPING_BASIC);
248 }
249
250 public ActionForward addAddress(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
251 IdentityManagementPersonDocumentForm personDocumentForm = (IdentityManagementPersonDocumentForm) form;
252 PersonDocumentAddress newAddress = personDocumentForm.getNewAddress();
253 newAddress.setDocumentNumber(personDocumentForm.getDocument().getDocumentNumber());
254 personDocumentForm.getPersonDocument().getAddrs().add(newAddress);
255 personDocumentForm.setNewAddress(new PersonDocumentAddress());
256 return mapping.findForward(RiceConstants.MAPPING_BASIC);
257 }
258
259 public ActionForward deleteAddress(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
260 IdentityManagementPersonDocumentForm personDocumentForm = (IdentityManagementPersonDocumentForm) form;
261 personDocumentForm.getPersonDocument().getAddrs().remove(getLineToDelete(request));
262 return mapping.findForward(RiceConstants.MAPPING_BASIC);
263 }
264
265 public ActionForward addPhone(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
266 IdentityManagementPersonDocumentForm personDocumentForm = (IdentityManagementPersonDocumentForm) form;
267 PersonDocumentPhone newPhone = personDocumentForm.getNewPhone();
268 newPhone.setDocumentNumber(personDocumentForm.getDocument().getDocumentNumber());
269 personDocumentForm.getPersonDocument().getPhones().add(newPhone);
270 personDocumentForm.setNewPhone(new PersonDocumentPhone());
271 return mapping.findForward(RiceConstants.MAPPING_BASIC);
272 }
273
274 public ActionForward deletePhone(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
275 IdentityManagementPersonDocumentForm personDocumentForm = (IdentityManagementPersonDocumentForm) form;
276 personDocumentForm.getPersonDocument().getPhones().remove(getLineToDelete(request));
277 return mapping.findForward(RiceConstants.MAPPING_BASIC);
278 }
279
280 public ActionForward addEmail(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
281 IdentityManagementPersonDocumentForm personDocumentForm = (IdentityManagementPersonDocumentForm) form;
282 PersonDocumentEmail newEmail = personDocumentForm.getNewEmail();
283 newEmail.setDocumentNumber(personDocumentForm.getDocument().getDocumentNumber());
284 personDocumentForm.getPersonDocument().getEmails().add(newEmail);
285 personDocumentForm.setNewEmail(new PersonDocumentEmail());
286 return mapping.findForward(RiceConstants.MAPPING_BASIC);
287 }
288
289 public ActionForward deleteEmail(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
290 IdentityManagementPersonDocumentForm personDocumentForm = (IdentityManagementPersonDocumentForm) form;
291 personDocumentForm.getPersonDocument().getEmails().remove(getLineToDelete(request));
292 return mapping.findForward(RiceConstants.MAPPING_BASIC);
293 }
294
295 public ActionForward addGroup(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
296 IdentityManagementPersonDocumentForm personDocumentForm = (IdentityManagementPersonDocumentForm) form;
297 PersonDocumentGroup newGroup = personDocumentForm.getNewGroup();
298 if (newGroup.getGroupName() == null
299 && newGroup.getNamespaceCode() == null
300 && newGroup.getGroupId() != null) {
301 Group tempGroup = KimApiServiceLocator.getGroupService().getGroup(newGroup.getGroupId());
302 newGroup.setGroupName(tempGroup.getName());
303 newGroup.setNamespaceCode(tempGroup.getNamespaceCode());
304 newGroup.setKimTypeId(tempGroup.getKimTypeId());
305 } else if (newGroup.getGroupName() != null
306 && newGroup.getNamespaceCode() != null
307 && newGroup.getGroupId() == null) {
308 Group tempGroup = KimApiServiceLocator.getGroupService().getGroupByNameAndNamespaceCode(
309 newGroup.getNamespaceCode(), newGroup.getGroupName());
310 newGroup.setGroupId(tempGroup.getId());
311 newGroup.setKimTypeId(tempGroup.getKimTypeId());
312 }
313 if (getKualiRuleService().applyRules(new AddGroupEvent("",personDocumentForm.getPersonDocument(), newGroup))) {
314 Group group = getGroupService().getGroup(newGroup.getGroupId());
315 newGroup.setGroupName(group.getName());
316 newGroup.setNamespaceCode(group.getNamespaceCode());
317 newGroup.setKimTypeId(group.getKimTypeId());
318 personDocumentForm.getPersonDocument().getGroups().add(newGroup);
319 personDocumentForm.setNewGroup(new PersonDocumentGroup());
320 }
321 return mapping.findForward(RiceConstants.MAPPING_BASIC);
322 }
323
324 public ActionForward deleteGroup(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
325 IdentityManagementPersonDocumentForm personDocumentForm = (IdentityManagementPersonDocumentForm) form;
326 PersonDocumentGroup inactivedGroupMembership = personDocumentForm.getPersonDocument().getGroups().get(getLineToDelete(request));
327 Calendar cal = Calendar.getInstance();
328 inactivedGroupMembership.setActiveToDate(new Timestamp(cal.getTimeInMillis()));
329 personDocumentForm.getPersonDocument().getGroups().set(getLineToDelete(request), inactivedGroupMembership);
330 return mapping.findForward(RiceConstants.MAPPING_BASIC);
331 }
332
333 public ActionForward addRole(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
334 IdentityManagementPersonDocumentForm personDocumentForm = (IdentityManagementPersonDocumentForm) form;
335 PersonDocumentRole newRole = personDocumentForm.getNewRole();
336
337 if (getKualiRuleService().applyRules(new AddRoleEvent("",personDocumentForm.getPersonDocument(), newRole))) {
338 Role role = KimApiServiceLocator.getRoleService().getRole(newRole.getRoleId());
339 if(!validateRole(newRole.getRoleId(), role, PersonDocumentRoleRule.ERROR_PATH, "Person")){
340 return mapping.findForward(RiceConstants.MAPPING_BASIC);
341 }
342 newRole.setRoleName(role.getName());
343 newRole.setNamespaceCode(role.getNamespaceCode());
344 newRole.setKimTypeId(role.getKimTypeId());
345 KimDocumentRoleMember roleMember = new KimDocumentRoleMember();
346 roleMember.setMemberId(personDocumentForm.getPrincipalId());
347 roleMember.setMemberTypeCode(MemberType.PRINCIPAL.getCode());
348 roleMember.setRoleId(newRole.getRoleId());
349 newRole.setNewRolePrncpl(roleMember);
350 if(!validateRoleAssignment(personDocumentForm.getPersonDocument(), newRole)){
351 return mapping.findForward(RiceConstants.MAPPING_BASIC);
352 }
353 KimTypeService kimTypeService = getKimTypeService(KimTypeBo.to(newRole.getKimRoleType()));
354
355
356 if ( kimTypeService != null ) {
357 newRole.setDefinitions(kimTypeService.getAttributeDefinitions(newRole.getKimTypeId()));
358 }
359 KimDocumentRoleMember newRolePrncpl = newRole.getNewRolePrncpl();
360 newRole.refreshReferenceObject("assignedResponsibilities");
361
362 for (KimAttributeField key : newRole.getDefinitions()) {
363 KimDocumentRoleQualifier qualifier = new KimDocumentRoleQualifier();
364
365 setAttrDefnIdForQualifier(qualifier,key);
366 newRolePrncpl.getQualifiers().add(qualifier);
367 }
368 if (newRole.getDefinitions().isEmpty()) {
369 List<KimDocumentRoleMember> rolePrncpls = new ArrayList<KimDocumentRoleMember>();
370 setupRoleRspActions(newRole, newRolePrncpl);
371 rolePrncpls.add(newRolePrncpl);
372 newRole.setRolePrncpls(rolePrncpls);
373 }
374
375 newRole.setAttributeEntry( getUiDocumentService().getAttributeEntries( newRole.getDefinitions() ) );
376 personDocumentForm.getPersonDocument().getRoles().add(newRole);
377 personDocumentForm.setNewRole(new PersonDocumentRole());
378 }
379 return mapping.findForward(RiceConstants.MAPPING_BASIC);
380 }
381
382 protected boolean validateRoleAssignment(IdentityManagementPersonDocument document, PersonDocumentRole newRole){
383 boolean rulePassed = true;
384 if(!document.validAssignRole(newRole)){
385 GlobalVariables.getMessageMap().putError("newRole.roleId",
386 RiceKeyConstants.ERROR_ASSIGN_ROLE,
387 new String[] {newRole.getNamespaceCode(), newRole.getRoleName()});
388 rulePassed = false;
389 }
390 return rulePassed;
391 }
392
393 protected void setupRoleRspActions(PersonDocumentRole role, KimDocumentRoleMember rolePrncpl) {
394 for (RoleResponsibilityBo roleResp : role.getAssignedResponsibilities()) {
395 if (getResponsibilityInternalService().areActionsAtAssignmentLevelById(roleResp.getRoleResponsibilityId())) {
396 KimDocumentRoleResponsibilityAction roleRspAction = new KimDocumentRoleResponsibilityAction();
397 roleRspAction.setRoleResponsibilityId("*");
398 roleRspAction.refreshReferenceObject("roleResponsibility");
399 if(rolePrncpl.getRoleRspActions()==null || rolePrncpl.getRoleRspActions().size()<1){
400 if(rolePrncpl.getRoleRspActions()==null) {
401 rolePrncpl.setRoleRspActions(new ArrayList<KimDocumentRoleResponsibilityAction>());
402 }
403 rolePrncpl.getRoleRspActions().add(roleRspAction);
404 }
405 }
406 }
407 }
408
409
410
411
412
413
414
415
416
417
418
419
420 protected void setAttrDefnIdForQualifier(KimDocumentRoleQualifier qualifier,KimAttributeField definition) {
421 qualifier.setKimAttrDefnId(definition.getId());
422 qualifier.refreshReferenceObject("kimAttribute");
423 }
424
425 public ActionForward deleteRole(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
426 IdentityManagementPersonDocumentForm personDocumentForm = (IdentityManagementPersonDocumentForm) form;
427 personDocumentForm.getPersonDocument().getRoles().remove(getLineToDelete(request));
428 return mapping.findForward(RiceConstants.MAPPING_BASIC);
429 }
430
431 public ActionForward addRoleQualifier(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
432 IdentityManagementPersonDocumentForm personDocumentForm = (IdentityManagementPersonDocumentForm) form;
433 IdentityManagementPersonDocument personDOc = personDocumentForm.getPersonDocument();
434 int selectedRoleIdx = getSelectedLine(request);
435 PersonDocumentRole role = personDOc.getRoles().get(selectedRoleIdx);
436 KimDocumentRoleMember newRolePrncpl = role.getNewRolePrncpl();
437
438 if (getKualiRuleService().applyRules(new AddPersonDocumentRoleQualifierEvent("",
439 personDOc, newRolePrncpl, role, selectedRoleIdx))) {
440 setupRoleRspActions(role, newRolePrncpl);
441 role.getRolePrncpls().add(newRolePrncpl);
442 role.setNewRolePrncpl(new KimDocumentRoleMember());
443 for (KimAttributeField key : role.getDefinitions()) {
444 KimDocumentRoleQualifier qualifier = new KimDocumentRoleQualifier();
445
446 setAttrDefnIdForQualifier(qualifier,key);
447 role.getNewRolePrncpl().getQualifiers().add(qualifier);
448 }
449 }
450
451 return mapping.findForward(RiceConstants.MAPPING_BASIC);
452 }
453
454 public ActionForward deleteRoleQualifier(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
455 IdentityManagementPersonDocumentForm personDocumentForm = (IdentityManagementPersonDocumentForm) form;
456 String selectedIndexes = getSelectedParentChildIdx(request);
457 if (selectedIndexes != null) {
458 String [] indexes = StringUtils.split(selectedIndexes,":");
459 PersonDocumentRole role = personDocumentForm.getPersonDocument().getRoles().get(Integer.parseInt(indexes[0]));
460 role.getRolePrncpls().remove(Integer.parseInt(indexes[1]));
461 }
462 return mapping.findForward(RiceConstants.MAPPING_BASIC);
463 }
464
465 public ActionForward addDelegationMember(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
466 IdentityManagementPersonDocumentForm personDocumentForm = (IdentityManagementPersonDocumentForm) form;
467 IdentityManagementPersonDocument personDocument = personDocumentForm.getPersonDocument();
468 RoleDocumentDelegationMember newDelegationMember = personDocumentForm.getNewDelegationMember();
469 KimTypeAttributesHelper attrHelper = newDelegationMember.getAttributesHelper();
470 if (getKualiRuleService().applyRules(new AddPersonDelegationMemberEvent("", personDocumentForm.getPersonDocument(), newDelegationMember))) {
471
472 Role role;
473 role = KimApiServiceLocator.getRoleService().getRole(newDelegationMember.getRoleBo().getId());
474 if (role != null) {
475 if(!validateRole(newDelegationMember.getRoleBo().getId(),role, PersonDocumentRoleRule.ERROR_PATH, "Person")){
476 return mapping.findForward(RiceConstants.MAPPING_BASIC);
477 }
478 newDelegationMember.setRoleBo(RoleBo.from(role));
479 }
480 KimAttributeField attrDefinition;
481 RoleMemberBo roleMember = KIMServiceLocatorInternal.getUiDocumentService().getRoleMember(newDelegationMember.getRoleMemberId());
482 Map<String, String>
483 roleMemberAttributes = (new AttributeValidationHelper()).convertAttributesToMap(roleMember.getAttributeDetails());
484 for (KimAttributeField key: attrHelper.getDefinitions()) {
485 RoleDocumentDelegationMemberQualifier qualifier = new RoleDocumentDelegationMemberQualifier();
486 attrDefinition = key;
487 qualifier.setKimAttrDefnId(attrHelper.getKimAttributeDefnId(attrDefinition));
488 qualifier.setAttrVal(attrHelper.getAttributeValue(roleMemberAttributes, attrDefinition.getAttributeField().getName()));
489 newDelegationMember.setMemberId(personDocument.getPrincipalId());
490 newDelegationMember.setMemberTypeCode(MemberType.PRINCIPAL.getCode());
491 newDelegationMember.getQualifiers().add(qualifier);
492 }
493
494 personDocument.getDelegationMembers().add(newDelegationMember);
495 personDocumentForm.setNewDelegationMember(new RoleDocumentDelegationMember());
496 }
497 return mapping.findForward(RiceConstants.MAPPING_BASIC);
498 }
499
500 public ActionForward deleteDelegationMember(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
501 IdentityManagementPersonDocumentForm personDocumentForm = (IdentityManagementPersonDocumentForm) form;
502 personDocumentForm.getPersonDocument().getDelegationMembers().remove(getLineToDelete(request));
503 return mapping.findForward(RiceConstants.MAPPING_BASIC);
504 }
505
506 @Override
507 public ActionForward save(ActionMapping mapping, ActionForm form,
508 HttpServletRequest request, HttpServletResponse response)
509 throws Exception {
510
511 return super.save(mapping, form, request, response);
512 }
513
514 @Override
515 public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
516 IdentityManagementPersonDocumentForm impdForm = (IdentityManagementPersonDocumentForm) form;
517
518 ActionForward forward = this.refreshAfterDelegationMemberRoleSelection(mapping, impdForm, request);
519 if (forward != null) {
520 return forward;
521 }
522
523 return super.refresh(mapping, form, request, response);
524 }
525
526 protected ActionForward refreshAfterDelegationMemberRoleSelection(ActionMapping mapping, IdentityManagementPersonDocumentForm impdForm, HttpServletRequest request) {
527 String refreshCaller = impdForm.getRefreshCaller();
528
529 boolean isRoleLookupable = KimConstants.KimUIConstants.ROLE_LOOKUPABLE_IMPL.equals(refreshCaller);
530 boolean isRoleMemberLookupable = KimConstants.KimUIConstants.KIM_DOCUMENT_ROLE_MEMBER_LOOKUPABLE_IMPL.equals(refreshCaller);
531
532
533 if (!isRoleLookupable && !isRoleMemberLookupable) {
534 return null;
535 }
536
537
538 if(impdForm.getNewDelegationMemberRoleId() == null){
539 return null;
540 }
541 if(isRoleLookupable){
542 return renderRoleMemberSelection(mapping, request, impdForm);
543 }
544
545 String roleMemberId = request.getParameter(KimConstants.PrimaryKeyConstants.ROLE_MEMBER_ID);
546 if(StringUtils.isNotBlank(roleMemberId)){
547 impdForm.getNewDelegationMember().setRoleMemberId(roleMemberId);
548 RoleMemberBo roleMember = getUiDocumentService().getRoleMember(roleMemberId);
549 impdForm.getNewDelegationMember().setRoleMemberMemberId(roleMember.getMemberId());
550 impdForm.getNewDelegationMember().setRoleMemberMemberTypeCode(roleMember.getType().getCode());
551 impdForm.getNewDelegationMember().setRoleMemberName(getUiDocumentService().getMemberName(MemberType.fromCode(impdForm.getNewDelegationMember().getRoleMemberMemberTypeCode()), impdForm.getNewDelegationMember().getRoleMemberMemberId()));
552 impdForm.getNewDelegationMember().setRoleMemberNamespaceCode(getUiDocumentService().getMemberNamespaceCode(MemberType.fromCode(impdForm.getNewDelegationMember().getRoleMemberMemberTypeCode()), impdForm.getNewDelegationMember().getRoleMemberMemberId()));
553
554 Role role;
555 role = KimApiServiceLocator.getRoleService().getRole(impdForm.getNewDelegationMember().getRoleBo().getId());
556 if (role != null) {
557 if(!validateRole(impdForm.getNewDelegationMember().getRoleBo().getId(), role, PersonDocumentRoleRule.ERROR_PATH, "Person")){
558 return mapping.findForward(RiceConstants.MAPPING_BASIC);
559 }
560 impdForm.getNewDelegationMember().setRoleBo(RoleBo.from(role));
561 }
562 }
563 impdForm.setNewDelegationMemberRoleId(null);
564 return null;
565 }
566
567 protected ActionForward renderRoleMemberSelection(ActionMapping mapping, HttpServletRequest request, IdentityManagementPersonDocumentForm impdForm) {
568 Properties props = new Properties();
569
570 props.put(KRADConstants.SUPPRESS_ACTIONS, Boolean.toString(true));
571 props.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, KimDocumentRoleMember.class.getName());
572 props.put(KRADConstants.LOOKUP_ANCHOR, KRADConstants.ANCHOR_TOP_OF_FORM);
573 props.put(KRADConstants.LOOKED_UP_COLLECTION_NAME, KimConstants.KimUIConstants.ROLE_MEMBERS_COLLECTION_NAME);
574
575 String conversionPatttern = "{0}" + KRADConstants.FIELD_CONVERSION_PAIR_SEPARATOR + "{0}";
576 StringBuilder fieldConversion = new StringBuilder();
577 fieldConversion.append(MessageFormat.format(conversionPatttern,
578 KimConstants.PrimaryKeyConstants.SUB_ROLE_ID)).append(KRADConstants.FIELD_CONVERSIONS_SEPARATOR);
579 fieldConversion.append(MessageFormat.format(conversionPatttern,
580 KimConstants.PrimaryKeyConstants.ROLE_MEMBER_ID)).append(KRADConstants.FIELD_CONVERSIONS_SEPARATOR);
581
582 props.put(KRADConstants.CONVERSION_FIELDS_PARAMETER, fieldConversion);
583
584 props.put(KimConstants.PrimaryKeyConstants.SUB_ROLE_ID, impdForm.getNewDelegationMember().getRoleBo().getId());
585
586 props.put(KRADConstants.RETURN_LOCATION_PARAMETER, this.getReturnLocation(request, mapping));
587
588
589 props.put(KRADConstants.LOOKUP_AUTO_SEARCH, "Yes");
590 props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.SEARCH_METHOD);
591
592 props.put(KRADConstants.DOC_FORM_KEY, GlobalVariables.getUserSession().addObjectWithGeneratedKey(impdForm));
593
594
595
596 String url = UrlFactory.parameterizeUrl(getApplicationBaseUrl() + "/kr/" + KRADConstants.LOOKUP_ACTION, props);
597
598 impdForm.registerEditableProperty("methodToCall");
599
600 return new ActionForward(url, true);
601 }
602
603
604 public ResponsibilityInternalService getResponsibilityInternalService() {
605 if ( responsibilityInternalService == null ) {
606 responsibilityInternalService = KimImplServiceLocator.getResponsibilityInternalService();
607 }
608 return responsibilityInternalService;
609 }
610 }