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