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