View Javadoc
1   /*
2    * Copyright 2011 The Kuali Foundation.
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.select.document.web.struts;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.apache.struts.action.ActionForm;
20  import org.apache.struts.action.ActionForward;
21  import org.apache.struts.action.ActionMapping;
22  import org.kuali.ole.select.businessobject.OleAcquisitionSearchResult;
23  import org.kuali.ole.select.document.OleAcquisitionsSearchDocument;
24  import org.kuali.ole.sys.OLEConstants;
25  import org.kuali.ole.sys.OLEKeyConstants;
26  import org.kuali.rice.core.api.util.RiceConstants;
27  import org.kuali.rice.kns.web.struts.action.KualiTransactionalDocumentActionBase;
28  import org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase;
29  import org.kuali.rice.krad.util.GlobalVariables;
30  import org.kuali.rice.krad.util.KRADConstants;
31  
32  import javax.servlet.http.HttpServletRequest;
33  import javax.servlet.http.HttpServletResponse;
34  import java.util.ArrayList;
35  import java.util.List;
36  
37  /**
38   * This class is the Action Class for Acquisitions Search
39   */
40  public class OleAcquisitionsSearchAction extends KualiTransactionalDocumentActionBase {
41  
42      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleAcquisitionsSearchAction.class);
43  
44      /**
45       * This method returns the list of requisition items that satisfy the search criteria
46       * input from Acquisitions Search page.
47       *
48       * @param mapping
49       * @param form
50       * @param request
51       * @param response
52       * @return
53       * @throws Exception
54       */
55      public ActionForward search(ActionMapping mapping, ActionForm form,
56                                  HttpServletRequest request, HttpServletResponse response) throws Exception {
57          LOG.debug("Inside searchRequisitions of OleAcquisitionsSearchAction");
58          Long begin = System.currentTimeMillis();
59          OleAcquisitionsSearchForm acqForm = (OleAcquisitionsSearchForm) form;
60          OleAcquisitionsSearchDocument acqDoc = (OleAcquisitionsSearchDocument) acqForm.getDocument();
61  
62          // Modified for Jira Ole-2563 by Aditya Starts
63  
64          boolean isToDateLesserThanFromDate;
65          isToDateLesserThanFromDate = acqDoc.isToDateLesserThanFromDate();
66          if (!isToDateLesserThanFromDate) {
67              List<OleAcquisitionSearchResult> displayList = acqDoc.searchResults();
68              if (displayList.size() > 0) {
69                  acqDoc.setAcqSearchResults(displayList);
70              } else {
71                  acqDoc.setAcqSearchResults(new ArrayList<OleAcquisitionSearchResult>());
72                  GlobalVariables.getMessageMap().clearErrorMessages();
73                  GlobalVariables.getMessageMap().putInfo(OLEConstants.OrderQueue.REQUISITIONS, OLEKeyConstants.ERROR_NO_RESULTS_FOUND);
74              }
75          } else {
76              GlobalVariables.getMessageMap().putError(OLEConstants.OrderQueue.REQUISITIONS, OLEKeyConstants.ERROR_DATE_TO_NOT_LESSER_THAN_DATE_FROM, new String[]{});
77          }
78          Long end = System.currentTimeMillis();
79          Long timeTaken = end-begin;
80          LOG.info("The Time Taken for Fetching Acquisition Search : "+timeTaken);
81  
82          // Modified for Jira Ole-2563 by Aditya Ends
83  
84          //request.setAttribute(OLEConstants.OrderQueue.CONSTANTS, new JSTLConstants(KewApiConstants.class));
85          return mapping.findForward(RiceConstants.MAPPING_BASIC);
86      }
87  
88      /**
89       * @see org.kuali.rice.kns.web.struts.action.KualiDocumentActionBase#cancel(org.apache.struts.action.ActionMapping,
90       *      org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
91       */
92      @Override
93      public ActionForward cancel(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
94          KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
95          return returnToSender(request, mapping, kualiDocumentFormBase);
96      }
97  
98      /**
99       * This method clears the search criteria's that is on the Acquisitions Search Page
100      *
101      * @param mapping
102      * @param form
103      * @param request
104      * @param response
105      * @return
106      * @throws Exception
107      */
108     public ActionForward clear(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
109         OleAcquisitionsSearchForm searchForm = (OleAcquisitionsSearchForm) form;
110         OleAcquisitionsSearchDocument oleAcqSearchDoc = (OleAcquisitionsSearchDocument) searchForm.getDocument();
111         oleAcqSearchDoc.setDocumentType(null);
112         oleAcqSearchDoc.setDocNumber(null);
113         oleAcqSearchDoc.setPurapDocumentIdentifier(null);
114         oleAcqSearchDoc.setVendorName(null);
115         oleAcqSearchDoc.setDateFrom(null);
116         oleAcqSearchDoc.setDateTo(null);
117         oleAcqSearchDoc.setInitiator(null);
118         oleAcqSearchDoc.setRequestorName(null);
119         oleAcqSearchDoc.setAccountNumber(null);
120         oleAcqSearchDoc.setOrganizationCode(null);
121         oleAcqSearchDoc.setChartOfAccountsCode(null);
122         oleAcqSearchDoc.setTitle(null);
123         oleAcqSearchDoc.setPublisher(null);
124         oleAcqSearchDoc.setIsbn(null);
125         oleAcqSearchDoc.setAuthor(null);
126         oleAcqSearchDoc.setLocalIdentifier(null);
127         oleAcqSearchDoc.setAcqSearchResults(new ArrayList<OleAcquisitionSearchResult>());
128         return mapping.findForward(RiceConstants.MAPPING_BASIC);
129     }
130 
131     /**
132      * Takes care of storing the action form in the User session and forwarding to the prlookup action.
133      *
134      * @param mapping
135      * @param form
136      * @param request
137      * @param response
138      * @return
139      * @throws Exception
140      */
141     public ActionForward performPRLookup(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
142 
143         LOG.debug("Inside performPRLookup of OleAcquisitionsSearchAction");
144         ActionForward forward = super.performLookup(mapping, form, request, response);
145         String path = forward.getPath();
146         if (path.contains("kr/" + KRADConstants.LOOKUP_ACTION)) {
147             path = path.replace("kr/" + KRADConstants.LOOKUP_ACTION, OLEConstants.PR_LOOKUP_ACTION);
148         } else if (path.contains(KRADConstants.LOOKUP_ACTION)) {
149             path = path.replace(KRADConstants.LOOKUP_ACTION, OLEConstants.PR_LOOKUP_ACTION);
150         }
151         forward.setPath(path);
152 
153         LOG.debug("Leaving performPRLookup of OleAcquisitionsSearchAction");
154         return forward;
155 
156     }
157 
158     /**
159      * This method... find the List Of All POs search for batch upload
160      * @param mapping
161      * @param form
162      * @param request
163      * @param response
164      * @return
165      * @throws Exception
166      */
167     public ActionForward docHandler(ActionMapping mapping, ActionForm form,
168                                     HttpServletRequest request, HttpServletResponse response) throws Exception {
169         LOG.debug("Inside searchRequisitions of OleAcquisitionsSearchAction");
170         ActionForward af = super.docHandler(mapping, form, request, response);
171         String loadSumId = ((OleAcquisitionsSearchForm) form).getLoadSumId();
172         if (StringUtils.isNotEmpty(loadSumId)) {
173             OleAcquisitionsSearchDocument acqDoc = (OleAcquisitionsSearchDocument) ((OleAcquisitionsSearchForm) form).getDocument();
174             List<OleAcquisitionSearchResult> displayList = acqDoc.listOfPOsSearchResults(loadSumId);
175             if (displayList.size() > 0) {
176                 acqDoc.setAcqSearchResults(displayList);
177             } else {
178                 acqDoc.setAcqSearchResults(new ArrayList<OleAcquisitionSearchResult>());
179                 GlobalVariables.getMessageMap().putInfo(OLEConstants.OrderQueue.REQUISITIONS, OLEKeyConstants.ERROR_NO_RESULTS_FOUND);
180             }
181             ((OleAcquisitionsSearchForm) form).setLoadSumId(null);
182         }
183         return af;
184 
185     }
186 
187 
188     @Override
189     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
190         ActionForward actionForward = null;
191         if(((OleAcquisitionsSearchForm) form).getMethodToCall() != null && ((OleAcquisitionsSearchForm) form).getMethodToCall().equalsIgnoreCase("docHandler")){
192             ((OleAcquisitionsSearchForm) form).setDocId(null);
193         }
194         return super.execute(mapping, form, request, response);
195     }
196 
197 }