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