001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.kfs.web.struts.action;
017:
018: import java.util.Properties;
019:
020: import javax.servlet.http.HttpServletRequest;
021: import javax.servlet.http.HttpServletResponse;
022:
023: import org.apache.commons.lang.StringUtils;
024: import org.apache.struts.action.ActionForm;
025: import org.apache.struts.action.ActionForward;
026: import org.apache.struts.action.ActionMapping;
027: import org.kuali.core.util.GlobalVariables;
028: import org.kuali.core.util.UrlFactory;
029: import org.kuali.core.web.struts.action.KualiAction;
030: import org.kuali.core.web.struts.form.KualiForm;
031: import org.kuali.kfs.KFSConstants;
032: import org.kuali.kfs.web.struts.form.KualiBalanceInquiryReportMenuForm;
033:
034: /**
035: * This class handles Actions for the balance inquiry report menu
036: */
037: public class KualiBalanceInquiryReportMenuAction extends KualiAction {
038: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
039: .getLogger(KualiBalanceInquiryReportMenuAction.class);
040:
041: /**
042: * Entry point to balance inquiry menu, forwards to jsp for rendering.
043: *
044: * @param mapping
045: * @param form
046: * @param request
047: * @param response
048: * @return ActionForward
049: * @throws Exception
050: */
051: public ActionForward start(ActionMapping mapping, ActionForm form,
052: HttpServletRequest request, HttpServletResponse response)
053: throws Exception {
054: return mapping.findForward(KFSConstants.MAPPING_BASIC);
055: }
056:
057: /**
058: * Returns back to calling document.
059: *
060: * @param mapping
061: * @param form
062: * @param request
063: * @param response
064: * @return ActionForward
065: * @throws Exception
066: */
067: public ActionForward cancel(ActionMapping mapping, ActionForm form,
068: HttpServletRequest request, HttpServletResponse response)
069: throws Exception {
070: KualiBalanceInquiryReportMenuForm balanceInquiryReportMenuForm = (KualiBalanceInquiryReportMenuForm) form;
071:
072: String backUrl = balanceInquiryReportMenuForm.getBackLocation()
073: + "?methodToCall=refresh&docFormKey="
074: + balanceInquiryReportMenuForm.getDocFormKey();
075: return new ActionForward(backUrl, true);
076: }
077:
078: /**
079: * Needs to overrided to inject the real value into the docFormKey b/c otherwise the lookup's refresh back to this menu
080: * overwrites the original value that we actually need. It too leverages the docFormKey.
081: *
082: * @param mapping
083: * @param form
084: * @param request
085: * @param response
086: * @return ActionForward
087: * @throws Exception
088: */
089: public ActionForward refresh(ActionMapping mapping,
090: ActionForm form, HttpServletRequest request,
091: HttpServletResponse response) throws Exception {
092: KualiBalanceInquiryReportMenuForm balanceInquiryReportMenuForm = (KualiBalanceInquiryReportMenuForm) form;
093:
094: // need to inject the real value into the docFormKey b/c otherwise the lookup's refresh back to this menu overwrites
095: // the original value that we actually need.
096: balanceInquiryReportMenuForm
097: .setDocFormKey(balanceInquiryReportMenuForm
098: .getBalanceInquiryReportMenuCallerDocFormKey());
099:
100: return mapping.findForward(KFSConstants.MAPPING_BASIC);
101: }
102:
103: /**
104: * Takes care of storing the action form in the user session and forwarding to the balance inquiry lookup action.
105: *
106: * @param mapping
107: * @param form
108: * @param request
109: * @param response
110: * @return ActionForward
111: * @throws Exception
112: */
113: public ActionForward performBalanceInquiryLookup(
114: ActionMapping mapping, ActionForm form,
115: HttpServletRequest request, HttpServletResponse response)
116: throws Exception {
117: String basePath = request.getScheme() + "://"
118: + request.getServerName() + ":"
119: + request.getServerPort() + request.getContextPath();
120:
121: // parse out the important strings from our methodToCall parameter
122: String fullParameter = (String) request
123: .getAttribute(KFSConstants.METHOD_TO_CALL_ATTRIBUTE);
124:
125: // parse out business object class name for lookup
126: String boClassName = StringUtils.substringBetween(
127: fullParameter,
128: KFSConstants.METHOD_TO_CALL_BOPARM_LEFT_DEL,
129: KFSConstants.METHOD_TO_CALL_BOPARM_RIGHT_DEL);
130: if (StringUtils.isBlank(boClassName)) {
131: throw new RuntimeException(
132: "Illegal call to perform lookup, no business object class name specified.");
133: }
134:
135: // build the parameters for the lookup url
136: Properties parameters = new Properties();
137: String conversionFields = StringUtils.substringBetween(
138: fullParameter,
139: KFSConstants.METHOD_TO_CALL_PARM1_LEFT_DEL,
140: KFSConstants.METHOD_TO_CALL_PARM1_RIGHT_DEL);
141: if (StringUtils.isNotBlank(conversionFields)) {
142: parameters.put(KFSConstants.CONVERSION_FIELDS_PARAMETER,
143: conversionFields);
144: }
145:
146: // pass values from form that should be pre-populated on lookup search
147: String parameterFields = StringUtils.substringBetween(
148: fullParameter,
149: KFSConstants.METHOD_TO_CALL_PARM2_LEFT_DEL,
150: KFSConstants.METHOD_TO_CALL_PARM2_RIGHT_DEL);
151: if (StringUtils.isNotBlank(parameterFields)) {
152: String[] lookupParams = parameterFields
153: .split(KFSConstants.FIELD_CONVERSIONS_SEPERATOR);
154:
155: for (int i = 0; i < lookupParams.length; i++) {
156: String[] keyValue = lookupParams[i]
157: .split(KFSConstants.FIELD_CONVERSION_PAIR_SEPERATOR);
158:
159: // hard-coded passed value
160: if (StringUtils.contains(keyValue[0], "'")) {
161: parameters.put(keyValue[1], StringUtils.replace(
162: keyValue[0], "'", ""));
163: }
164: // passed value should come from property
165: else if (StringUtils.isNotBlank(request
166: .getParameter(keyValue[0]))) {
167: parameters.put(keyValue[1], request
168: .getParameter(keyValue[0]));
169: }
170: }
171: }
172:
173: // grab whether or not the "return value" link should be hidden or not
174: String hideReturnLink = StringUtils.substringBetween(
175: fullParameter,
176: KFSConstants.METHOD_TO_CALL_PARM3_LEFT_DEL,
177: KFSConstants.METHOD_TO_CALL_PARM3_RIGHT_DEL);
178: if (StringUtils.isNotBlank(hideReturnLink)) {
179: parameters.put(KFSConstants.HIDE_LOOKUP_RETURN_LINK,
180: hideReturnLink);
181: }
182:
183: System.out.println("Setting the anchor to "
184: + ((KualiForm) form).getAnchor());
185: // anchor, if it exists
186: if (form instanceof KualiForm
187: && StringUtils.isNotEmpty(((KualiForm) form)
188: .getAnchor())) {
189: parameters.put(KFSConstants.LOOKUP_ANCHOR,
190: ((KualiForm) form).getAnchor());
191: }
192:
193: // determine what the action path is
194: String actionPath = StringUtils.substringBetween(fullParameter,
195: KFSConstants.METHOD_TO_CALL_PARM4_LEFT_DEL,
196: KFSConstants.METHOD_TO_CALL_PARM4_RIGHT_DEL);
197: if (StringUtils.isBlank(actionPath)) {
198: throw new IllegalStateException(
199: "The \"actionPath\" attribute is an expected parameter for the <gl:balanceInquiryLookup> tag - it "
200: + "should never be blank.");
201: }
202:
203: // now add required parameters
204: parameters
205: .put(KFSConstants.DISPATCH_REQUEST_PARAMETER, "start");
206: parameters.put(KFSConstants.DOC_FORM_KEY, GlobalVariables
207: .getUserSession().addObject(form));
208: parameters.put(KFSConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE,
209: boClassName);
210: parameters.put(KFSConstants.RETURN_LOCATION_PARAMETER, basePath
211: + mapping.getPath() + ".do");
212:
213: String lookupUrl = UrlFactory.parameterizeUrl(basePath + "/"
214: + actionPath, parameters);
215:
216: return new ActionForward(lookupUrl, true);
217: }
218: }
|