1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
46
47
48
49
50
51
52
53
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
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
83
84
85 return mapping.findForward(RiceConstants.MAPPING_BASIC);
86 }
87
88
89
90
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
100
101
102
103
104
105
106
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
133
134
135
136
137
138
139
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
160
161
162
163
164
165
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 }