001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.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/ecl2.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.module.ar.web.struts;
017
018 import java.util.ArrayList;
019 import java.util.Collection;
020 import java.util.List;
021
022 import javax.servlet.http.HttpServletRequest;
023 import javax.servlet.http.HttpServletResponse;
024
025 import org.apache.struts.action.ActionForm;
026 import org.apache.struts.action.ActionForward;
027 import org.apache.struts.action.ActionMapping;
028 import org.kuali.kfs.module.ar.businessobject.lookup.CustomerOpenItemReportLookupableHelperServiceImpl;
029 import org.kuali.kfs.sys.KFSConstants;
030 import org.kuali.kfs.sys.KFSKeyConstants;
031 import org.kuali.kfs.sys.KFSPropertyConstants;
032 import org.kuali.rice.kns.lookup.CollectionIncomplete;
033 import org.kuali.rice.kns.lookup.Lookupable;
034 import org.kuali.rice.kns.util.GlobalVariables;
035 import org.kuali.rice.kns.web.struts.action.KualiAction;
036 import org.kuali.rice.kns.web.ui.ResultRow;
037
038
039 /**
040 * This class handles Actions for lookup flow
041 */
042
043 public class CustomerOpenItemReportAction extends KualiAction {
044 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(CustomerOpenItemReportAction.class);
045 private static final String TOTALS_TABLE_KEY = "totalsTable";
046
047 /**
048 * Search - sets the values of the data entered on the form on the jsp into a map and then searches for the results.
049 *
050 * @param mapping
051 * @param form
052 * @param request
053 * @param response
054 * @return
055 * @throws Exception
056 */
057 public ActionForward search(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
058 CustomerOpenItemReportForm lookupForm = (CustomerOpenItemReportForm) form;
059
060 Lookupable lookupable = lookupForm.getLookupable();
061
062 if (lookupable == null) {
063 LOG.error("Lookupable is null.");
064 throw new RuntimeException("Lookupable is null.");
065 }
066
067 Collection displayList = new ArrayList();
068 List<ResultRow> resultTable = new ArrayList<ResultRow>();
069
070 try {
071 displayList = lookupable.performLookup(lookupForm, resultTable, true);
072 Long totalSize = ((CollectionIncomplete) displayList).getActualSizeIfTruncated();
073
074 request.setAttribute(KFSConstants.REQUEST_SEARCH_RESULTS_SIZE, totalSize);
075 request.setAttribute(KFSConstants.REQUEST_SEARCH_RESULTS, resultTable);
076
077 if (request.getParameter(KFSConstants.SEARCH_LIST_REQUEST_KEY) != null)
078 GlobalVariables.getUserSession().removeObject(request.getParameter(KFSConstants.SEARCH_LIST_REQUEST_KEY));
079
080 request.setAttribute(KFSConstants.SEARCH_LIST_REQUEST_KEY, GlobalVariables.getUserSession().addObject(resultTable));
081 } catch (NumberFormatException e) {
082 GlobalVariables.getMessageMap().putError(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, KFSKeyConstants.ERROR_CUSTOM, new String[] { "Fiscal Year must be a four-digit number" });
083 } catch (Exception e) {
084 GlobalVariables.getMessageMap().putError(KFSConstants.DOCUMENT_ERRORS, KFSKeyConstants.ERROR_CUSTOM, new String[] { "Please report the server error." });
085 LOG.error("Application Errors", e);
086 }
087 return mapping.findForward(KFSConstants.MAPPING_BASIC);
088 }
089
090 /**
091 * View results from balance inquiry action
092 *
093 * @param mapping
094 * @param form
095 * @param request
096 * @param response
097 * @return
098 * @throws Exception
099 */
100 public ActionForward viewResults(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
101 request.setAttribute(KFSConstants.SEARCH_LIST_REQUEST_KEY, request.getParameter(KFSConstants.SEARCH_LIST_REQUEST_KEY));
102 request.setAttribute(KFSConstants.REQUEST_SEARCH_RESULTS, GlobalVariables.getUserSession().retrieveObject(request.getParameter(KFSConstants.SEARCH_LIST_REQUEST_KEY)));
103 request.setAttribute(KFSConstants.REQUEST_SEARCH_RESULTS_SIZE, request.getParameter(KFSConstants.REQUEST_SEARCH_RESULTS_SIZE));
104
105 // TODO: use inheritance instead of this if statement
106 if (((CustomerOpenItemReportForm) form).getLookupable().getLookupableHelperService() instanceof CustomerOpenItemReportLookupableHelperServiceImpl) {
107 Object totalsTable = GlobalVariables.getUserSession().retrieveObject(TOTALS_TABLE_KEY);
108 request.setAttribute(TOTALS_TABLE_KEY, totalsTable);
109 }
110 return mapping.findForward(KFSConstants.MAPPING_BASIC);
111 }
112
113 /**
114 * Handling for screen close. Default action is return to caller.
115 *
116 * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm,
117 * javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
118 */
119 /*
120 public ActionForward close(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
121 return returnToCaller(mapping, form, request, response);
122 }
123
124 public ActionForward returnToCaller(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
125 BudgetExpansionForm budgetExpansionForm = (BudgetExpansionForm) form;
126
127 Properties parameters = new Properties();
128 parameters.put(KFSConstants.DISPATCH_REQUEST_PARAMETER, BCConstants.BC_SELECTION_REFRESH_METHOD);
129 parameters.put(KFSConstants.DOC_FORM_KEY, budgetExpansionForm.getReturnFormKey());
130
131 if (StringUtils.isNotEmpty(budgetExpansionForm.getReturnAnchor())) {
132 parameters.put(KFSConstants.ANCHOR, budgetExpansionForm.getReturnAnchor());
133 }
134 parameters.put(KFSConstants.REFRESH_CALLER, this.getClass().getName());
135
136 this.addCallBackMessagesAsObjectInSession(budgetExpansionForm);
137
138 String backUrl = UrlFactory.parameterizeUrl(budgetExpansionForm.getBackLocation(), parameters);
139 return new ActionForward(backUrl, true);
140 }*/
141 }