1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.kuali.kfs.module.bc.document.web.struts;
20
21 import java.util.Properties;
22
23 import javax.servlet.http.HttpServletRequest;
24 import javax.servlet.http.HttpServletResponse;
25 import javax.servlet.http.HttpSession;
26
27 import org.apache.commons.lang.StringUtils;
28 import org.apache.struts.action.ActionForm;
29 import org.apache.struts.action.ActionForward;
30 import org.apache.struts.action.ActionMapping;
31 import org.kuali.kfs.module.bc.BCConstants;
32 import org.kuali.kfs.module.bc.BCPropertyConstants;
33 import org.kuali.kfs.sys.KFSConstants;
34 import org.kuali.rice.kns.util.KNSGlobalVariables;
35 import org.kuali.rice.kns.util.MessageList;
36 import org.kuali.rice.kns.web.struts.action.KualiAction;
37 import org.kuali.rice.krad.util.GlobalVariables;
38 import org.kuali.rice.krad.util.MessageMap;
39 import org.kuali.rice.krad.util.UrlFactory;
40
41
42
43
44 public class BudgetExpansionAction extends KualiAction {
45
46
47
48
49
50 @Override
51 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
52
53 BudgetExpansionForm budgetExpansionForm = (BudgetExpansionForm) form;
54
55 return super.execute(mapping, form, request, response);
56 }
57
58
59
60
61
62
63
64 public ActionForward close(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
65 return returnToCaller(mapping, form, request, response);
66 }
67
68
69
70
71
72 @Override
73 public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
74 this.moveCallBackMessagesInPlace();
75 this.removeCallBackMessagesObjectFromSession();
76
77 return super.refresh(mapping, form, request, response);
78 }
79
80
81
82
83
84
85
86
87 public ActionForward returnToCaller(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
88 BudgetExpansionForm budgetExpansionForm = (BudgetExpansionForm) form;
89
90
91 this.cleanupAnySessionForm(mapping, request);
92
93 Properties parameters = new Properties();
94 parameters.put(KFSConstants.DISPATCH_REQUEST_PARAMETER, BCConstants.BC_SELECTION_REFRESH_METHOD);
95 parameters.put(KFSConstants.DOC_FORM_KEY, budgetExpansionForm.getReturnFormKey());
96
97 if (StringUtils.isNotEmpty(budgetExpansionForm.getReturnAnchor())) {
98 parameters.put(KFSConstants.ANCHOR, budgetExpansionForm.getReturnAnchor());
99 }
100 parameters.put(KFSConstants.REFRESH_CALLER, this.getClass().getName());
101
102 this.addCallBackMessagesAsObjectInSession(budgetExpansionForm);
103
104 String backUrl = UrlFactory.parameterizeUrl(budgetExpansionForm.getBackLocation(), parameters);
105 return new ActionForward(backUrl, true);
106 }
107
108
109
110
111 public void addCallBackMessagesAsObjectInSession(BudgetExpansionForm budgetExpansionForm) {
112 if (!budgetExpansionForm.getCallBackMessages().isEmpty()) {
113 GlobalVariables.getUserSession().addObject(BCPropertyConstants.CALL_BACK_MESSAGES, budgetExpansionForm.getCallBackMessages());
114 }
115
116 if (budgetExpansionForm.getCallBackErrors().hasErrors()) {
117 GlobalVariables.getUserSession().addObject(BCPropertyConstants.CALL_BACK_ERRORS, budgetExpansionForm.getCallBackErrors());
118 }
119 }
120
121
122
123
124 public void removeCallBackMessagesObjectFromSession() {
125 GlobalVariables.getUserSession().removeObject(BCPropertyConstants.CALL_BACK_MESSAGES);
126 GlobalVariables.getUserSession().removeObject(BCPropertyConstants.CALL_BACK_ERRORS);
127 }
128
129
130
131
132 public void moveCallBackMessagesInPlace() {
133 MessageList messagesList = (MessageList) GlobalVariables.getUserSession().retrieveObject(BCPropertyConstants.CALL_BACK_MESSAGES);
134 if (messagesList != null) {
135 KNSGlobalVariables.getMessageList().addAll(messagesList);
136 }
137
138 MessageMap messageMap = (MessageMap) GlobalVariables.getUserSession().retrieveObject(BCPropertyConstants.CALL_BACK_ERRORS);
139 if (messageMap != null) {
140 GlobalVariables.setMessageMap(messageMap);
141 }
142 }
143
144
145
146
147
148
149
150 public void cleanupAnySessionForm(ActionMapping mapping, HttpServletRequest request) {
151 if (BCConstants.MAPPING_SCOPE_SESSION.equals(mapping.getScope())) {
152 HttpSession sess = request.getSession(Boolean.FALSE);
153 String formName = mapping.getAttribute();
154 sess.removeAttribute(formName);
155 }
156 }
157 }