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