View Javadoc
1   package org.kuali.kpme.edo.candidate.delegate.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.kuali.kpme.edo.base.web.EdoAction;
8   import org.kuali.kpme.edo.role.EDORole;
9   import org.kuali.kpme.edo.service.EdoServiceLocator;
10  import org.kuali.kpme.edo.util.EdoConstants;
11  import org.kuali.kpme.edo.util.EdoRule;
12  import org.kuali.kpme.edo.util.EdoUser;
13  import org.kuali.rice.krad.util.GlobalVariables;
14  import org.kuali.rice.krad.util.ObjectUtils;
15  
16  import javax.servlet.http.HttpServletRequest;
17  import javax.servlet.http.HttpServletResponse;
18  import java.util.List;
19  
20  
21  public class EdoAssignCandidateDelegateAction extends EdoAction {
22  
23      public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
24  
25          EdoAssignCandidateDelegateForm assignCandidateDelegateForm = (EdoAssignCandidateDelegateForm) form;
26  
27          assignCandidateDelegateForm.setEdoCandidateDelegatesInfo(EdoServiceLocator.getEdoMaintenanceService().getCandidateDelegateInfo(EdoUser.getCurrentTargetPerson().getPrincipalId(), EDORole.EDO_CANDIDATE_DELEGATE.getEdoRole()));
28          return super.execute(mapping, form, request, response);
29      }
30  
31      public ActionForward search(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
32              throws Exception {
33          EdoAssignCandidateDelegateForm assignCandidateDelegateForm = (EdoAssignCandidateDelegateForm) form;
34  
35          String userId = assignCandidateDelegateForm.getUserId();
36          if (StringUtils.isNotEmpty(userId)) {
37              if (EdoRule.validateUserId(userId)) {
38                  EdoUser userInfo = EdoServiceLocator.getAuthorizationService().getEdoUser(userId);
39                  assignCandidateDelegateForm.setName(userInfo.getName());
40                  assignCandidateDelegateForm.setEmplId(userInfo.getEmplId());
41              }
42          }
43  
44          return mapping.findForward("basic");
45      }
46  
47      public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
48          EdoAssignCandidateDelegateForm assignCandidateDelegateForm = (EdoAssignCandidateDelegateForm) form;
49  
50          if (StringUtils.isEmpty(assignCandidateDelegateForm.getUserId()) || StringUtils.isEmpty(assignCandidateDelegateForm.getName())) {
51              return mapping.findForward("basic");
52          } else {
53              List<String> existingDelegates = EdoServiceLocator.getEdoMaintenanceService().getCandidateDelegatesEmplIds(EdoUser.getCurrentTargetPerson().getPrincipalId(), EDORole.EDO_CANDIDATE_DELEGATE.getEdoRole());
54              if (existingDelegates.contains(assignCandidateDelegateForm.getEmplToAdd())) {
55                  GlobalVariables.getMessageMap().putError(EdoConstants.ErrorKeys.ERROR_KEYS, "error.delegate.duplicate", assignCandidateDelegateForm.getName());
56              } else {
57                  boolean isDelegateAdded = EdoServiceLocator.getEdoMaintenanceService().saveDelegateForCandidate(assignCandidateDelegateForm.getEmplToAdd(), assignCandidateDelegateForm.getStartDate(), assignCandidateDelegateForm.getEndDate(),  EdoUser.getCurrentTargetPerson().getPrincipalId(), EDORole.EDO_CANDIDATE_DELEGATE.getEdoRole());
58  
59                  if (isDelegateAdded) {
60                      assignCandidateDelegateForm.setCandidateDelegateAdded(isDelegateAdded);
61                  }
62                  //	assignCandidateDelegateForm.setCandidateDelegates(EdoServiceLocator.getEdoMaintenanceService().getCandidateDelegates(EdoUser.getCurrentTargetPerson().getPrincipalId()));
63                  assignCandidateDelegateForm.setEdoCandidateDelegatesInfo(EdoServiceLocator.getEdoMaintenanceService().getCandidateDelegateInfo(EdoUser.getCurrentTargetPerson().getPrincipalId(), EDORole.EDO_CANDIDATE_DELEGATE.getEdoRole()));
64              }
65              resetDelegateFormState(assignCandidateDelegateForm);
66              return mapping.findForward("basic");
67          }
68      }
69  
70      public ActionForward deleteFacultyDelegate(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
71          EdoAssignCandidateDelegateForm assignCandidateDelegateForm = (EdoAssignCandidateDelegateForm) form;
72          boolean isDelegateDeleted = false;
73  
74          isDelegateDeleted = EdoServiceLocator.getEdoMaintenanceService().deleteCandidateDelegate(assignCandidateDelegateForm.getEmplToDelete(), EdoUser.getCurrentTargetPerson().getPrincipalId(), EDORole.EDO_CANDIDATE_DELEGATE.getEdoRole());
75          //assignCandidateDelegateForm.setCandidateDelegates(EdoServiceLocator.getEdoMaintenanceService().getCandidateDelegates(EdoUser.getCurrentTargetPerson().getPrincipalId()));
76          assignCandidateDelegateForm.setEdoCandidateDelegatesInfo(EdoServiceLocator.getEdoMaintenanceService().getCandidateDelegateInfo(EdoUser.getCurrentTargetPerson().getPrincipalId(), EDORole.EDO_CANDIDATE_DELEGATE.getEdoRole()));
77          assignCandidateDelegateForm.setCandidateDelegateDeleted(isDelegateDeleted);
78  
79          return mapping.findForward("basic");
80      }
81  
82      public ActionForward cancel(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
83          EdoAssignCandidateDelegateForm assignCandidateDelegateForm = (EdoAssignCandidateDelegateForm) form;
84          resetDelegateFormState(assignCandidateDelegateForm);
85          return mapping.findForward("basic");
86      }
87  
88      private void resetDelegateFormState(EdoAssignCandidateDelegateForm assignCandidateDelegateForm) {
89          if (ObjectUtils.isNotNull(assignCandidateDelegateForm)) {
90              assignCandidateDelegateForm.setUserId(null);
91              assignCandidateDelegateForm.setName(null);
92              assignCandidateDelegateForm.setStartDate(null);
93              assignCandidateDelegateForm.setEndDate(null);
94          }
95      }
96  }