1 package org.kuali.kpme.edo.admin.web;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.apache.struts.action.ActionForm;
5 import org.apache.struts.action.ActionForward;
6 import org.apache.struts.action.ActionMapping;
7 import org.apache.struts.action.ActionRedirect;
8 import org.kuali.kpme.edo.base.web.EdoAction;
9 import org.kuali.kpme.edo.util.EdoConstants;
10 import org.kuali.kpme.edo.candidate.EdoSelectedCandidate;
11 import org.kuali.kpme.edo.util.EdoUser;
12 import org.kuali.rice.kim.api.identity.Person;
13 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
14 import org.kuali.rice.krad.util.GlobalVariables;
15
16 import javax.servlet.http.HttpServletRequest;
17 import javax.servlet.http.HttpServletResponse;
18 import javax.servlet.http.HttpSession;
19
20 public class EdoChangeTargetPersonAction extends EdoAction {
21
22 public ActionForward changeTargetPerson(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
23 throws Exception {
24 ActionForward forward = mapping.findForward("basic");
25
26 EdoChangeTargetPersonForm changeTargetPersonForm = (EdoChangeTargetPersonForm) form;
27
28 if (StringUtils.isNotBlank(changeTargetPersonForm.getPrincipalName())) {
29 Person targetPerson = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(changeTargetPersonForm.getPrincipalName());
30
31 if (targetPerson != null) {
32 EdoUser.setTargetPerson(targetPerson);
33
34 String returnAction = "EdoIndex.do";
35 if (StringUtils.isNotEmpty(changeTargetPersonForm.getTargetUrl())) {
36 returnAction = changeTargetPersonForm.getTargetUrl();
37 }
38 forward = new ActionRedirect(returnAction);
39 } else {
40 GlobalVariables.getMessageMap().putError(EdoConstants.ErrorKeys.ERROR_KEYS, "error.userInfObject.null");
41 }
42 }
43
44 return forward;
45 }
46
47 public ActionForward clearTargetPerson(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
48 throws Exception {
49 EdoUser.clearTargetUser();
50
51 String returnAction = null;
52 if (StringUtils.isNotBlank((String) GlobalVariables.getUserSession().retrieveObject(EdoConstants.EDO_TARGET_USER_RETURN))) {
53 returnAction = (String) GlobalVariables.getUserSession().retrieveObject(EdoConstants.EDO_TARGET_USER_RETURN);
54 }
55
56 if (StringUtils.isBlank(returnAction)) {
57 returnAction = "changeTargetPerson.do";
58 }
59
60 HttpSession ssn = request.getSession();
61 ssn.setAttribute("selectedCandidate", new EdoSelectedCandidate());
62
63 return new ActionRedirect(returnAction);
64 }
65 }