1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.ole.sys.web.struts;
17  
18  import java.util.Properties;
19  
20  import javax.servlet.http.HttpServletRequest;
21  import javax.servlet.http.HttpServletResponse;
22  
23  import org.apache.commons.lang.StringUtils;
24  import org.apache.struts.action.ActionForm;
25  import org.apache.struts.action.ActionForward;
26  import org.apache.struts.action.ActionMapping;
27  import org.kuali.ole.sys.OLEConstants;
28  import org.kuali.rice.kns.web.struts.action.KualiAction;
29  import org.kuali.rice.kns.web.struts.form.KualiForm;
30  import org.kuali.rice.krad.util.GlobalVariables;
31  import org.kuali.rice.krad.util.UrlFactory;
32  
33  
34  
35  
36  public class KualiBalanceInquiryReportMenuAction extends KualiAction {
37      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KualiBalanceInquiryReportMenuAction.class);
38  
39      
40  
41  
42  
43  
44  
45  
46  
47  
48  
49      public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
50          return mapping.findForward(OLEConstants.MAPPING_BASIC);
51      }
52  
53      
54  
55  
56  
57  
58  
59  
60  
61  
62  
63      public ActionForward cancel(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
64          KualiBalanceInquiryReportMenuForm balanceInquiryReportMenuForm = (KualiBalanceInquiryReportMenuForm) form;
65  
66          String backUrl = balanceInquiryReportMenuForm.getBackLocation() + "?methodToCall=refresh&docFormKey=" + balanceInquiryReportMenuForm.getDocFormKey();
67          return new ActionForward(backUrl, true);
68      }
69  
70      
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81      public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
82          KualiBalanceInquiryReportMenuForm balanceInquiryReportMenuForm = (KualiBalanceInquiryReportMenuForm) form;
83  
84          
85          
86          balanceInquiryReportMenuForm.setDocFormKey(balanceInquiryReportMenuForm.getBalanceInquiryReportMenuCallerDocFormKey());
87  
88          return mapping.findForward(OLEConstants.MAPPING_BASIC);
89      }
90  
91      
92  
93  
94  
95  
96  
97  
98  
99  
100 
101     public ActionForward performBalanceInquiryLookup(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
102         String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
103 
104         
105         String fullParameter = (String) request.getAttribute(OLEConstants.METHOD_TO_CALL_ATTRIBUTE);
106 
107         
108         String boClassName = StringUtils.substringBetween(fullParameter, OLEConstants.METHOD_TO_CALL_BOPARM_LEFT_DEL, OLEConstants.METHOD_TO_CALL_BOPARM_RIGHT_DEL);
109         if (StringUtils.isBlank(boClassName)) {
110             throw new RuntimeException("Illegal call to perform lookup, no business object class name specified.");
111         }
112 
113         
114         Properties parameters = new Properties();
115         String conversionFields = StringUtils.substringBetween(fullParameter, OLEConstants.METHOD_TO_CALL_PARM1_LEFT_DEL, OLEConstants.METHOD_TO_CALL_PARM1_RIGHT_DEL);
116         if (StringUtils.isNotBlank(conversionFields)) {
117             parameters.put(OLEConstants.CONVERSION_FIELDS_PARAMETER, conversionFields);
118         }
119 
120         
121         String parameterFields = StringUtils.substringBetween(fullParameter, OLEConstants.METHOD_TO_CALL_PARM2_LEFT_DEL, OLEConstants.METHOD_TO_CALL_PARM2_RIGHT_DEL);
122         if (StringUtils.isNotBlank(parameterFields)) {
123             String[] lookupParams = parameterFields.split(OLEConstants.FIELD_CONVERSIONS_SEPERATOR);
124 
125             for (int i = 0; i < lookupParams.length; i++) {
126                 String[] keyValue = lookupParams[i].split(OLEConstants.FIELD_CONVERSION_PAIR_SEPERATOR);
127 
128                 
129                 if (StringUtils.contains(keyValue[0], "'")) {
130                     parameters.put(keyValue[1], StringUtils.replace(keyValue[0], "'", ""));
131                 }
132                 
133                 else if (StringUtils.isNotBlank(request.getParameter(keyValue[0]))) {
134                     parameters.put(keyValue[1], request.getParameter(keyValue[0]));
135                 }
136             }
137         }
138 
139         
140         String hideReturnLink = StringUtils.substringBetween(fullParameter, OLEConstants.METHOD_TO_CALL_PARM3_LEFT_DEL, OLEConstants.METHOD_TO_CALL_PARM3_RIGHT_DEL);
141         if (StringUtils.isNotBlank(hideReturnLink)) {
142             parameters.put(OLEConstants.HIDE_LOOKUP_RETURN_LINK, hideReturnLink);
143         }
144 
145         
146         if (form instanceof KualiForm && StringUtils.isNotEmpty(((KualiForm) form).getAnchor())) {
147             parameters.put(OLEConstants.LOOKUP_ANCHOR, ((KualiForm) form).getAnchor());
148         }
149 
150         
151         String actionPath = StringUtils.substringBetween(fullParameter, OLEConstants.METHOD_TO_CALL_PARM4_LEFT_DEL, OLEConstants.METHOD_TO_CALL_PARM4_RIGHT_DEL);
152         if (StringUtils.isBlank(actionPath)) {
153             throw new IllegalStateException("The \"actionPath\" attribute is an expected parameter for the <gl:balanceInquiryLookup> tag - it " + "should never be blank.");
154         }
155 
156         
157         parameters.put(OLEConstants.DISPATCH_REQUEST_PARAMETER, "start");
158         parameters.put(OLEConstants.DOC_FORM_KEY, GlobalVariables.getUserSession().addObjectWithGeneratedKey(form));
159         parameters.put(OLEConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, boClassName);
160         parameters.put(OLEConstants.RETURN_LOCATION_PARAMETER, basePath + mapping.getPath() + ".do");
161 
162         String lookupUrl = UrlFactory.parameterizeUrl(basePath + "/" + actionPath, parameters);
163 
164         return new ActionForward(lookupUrl, true);
165     }
166 }