View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.module.tem.businessobject.lookup;
20  
21  import java.util.ArrayList;
22  import java.util.Iterator;
23  import java.util.List;
24  import java.util.Map;
25  import java.util.Properties;
26  
27  import org.apache.commons.lang.text.StrBuilder;
28  import org.kuali.kfs.module.tem.TemConstants;
29  import org.kuali.kfs.module.tem.TemConstants.TravelParameters;
30  import org.kuali.kfs.module.tem.TemParameterConstants;
31  import org.kuali.kfs.module.tem.TemPropertyConstants;
32  import org.kuali.kfs.module.tem.businessobject.HistoricalTravelExpense;
33  import org.kuali.kfs.sys.KFSPropertyConstants;
34  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
35  import org.kuali.rice.kns.document.authorization.BusinessObjectRestrictions;
36  import org.kuali.rice.kns.lookup.HtmlData;
37  import org.kuali.rice.kns.lookup.HtmlData.InputHtmlData;
38  import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
39  import org.kuali.rice.kns.lookup.LookupUtils;
40  import org.kuali.rice.kns.web.struts.form.LookupForm;
41  import org.kuali.rice.krad.bo.BusinessObject;
42  import org.kuali.rice.krad.lookup.CollectionIncomplete;
43  import org.kuali.rice.krad.util.GlobalVariables;
44  
45  @SuppressWarnings("deprecation")
46  public class ImportedExpenseLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl {
47  
48      ParameterService parameterService;
49  
50      /**
51       * @see org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl#getSearchResults(java.util.Map)
52       */
53      @SuppressWarnings("rawtypes")
54      @Override
55      public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
56          Integer profileID = (Integer) GlobalVariables.getUserSession().retrieveObject(TemPropertyConstants.TemProfileProperties.PROFILE_ID);
57  
58          List<String> lookupableProfileId = new ArrayList<String>();
59          lookupableProfileId.add(profileID.toString());
60  
61          boolean includeTravelerExpense = parameterService.getParameterValueAsBoolean(TemParameterConstants.TEM_DOCUMENT.class, TravelParameters.INCLUDE_ARRANGER_EXPENSE_IN_IMPORTED_EXPENSE_IND);
62          //also use the traveler's profile ID to get the result
63          if (includeTravelerExpense){
64              Integer travelerProfileID = (Integer) GlobalVariables.getUserSession().retrieveObject(TemPropertyConstants.ARRANGER_PROFILE_ID);
65              if (travelerProfileID != null){
66                  lookupableProfileId.add(travelerProfileID.toString());
67              }
68          }
69          StrBuilder builder = new StrBuilder();
70          builder.appendWithSeparators(lookupableProfileId, "|");
71  
72          fieldValues.put(TemPropertyConstants.TemProfileProperties.PROFILE_ID, builder.toString());
73          String value = GlobalVariables.getUserSession().retrieveObject(KFSPropertyConstants.DOCUMENT_TYPE_CODE).toString();
74  
75          List<HistoricalTravelExpense> results = (List<HistoricalTravelExpense>) super.getSearchResultsHelper(fieldValues, true);
76          List<HistoricalTravelExpense> newResults = new ArrayList<HistoricalTravelExpense>();
77          Iterator<HistoricalTravelExpense> it = results.iterator();
78          while (it.hasNext()){
79              HistoricalTravelExpense historicalTravelExpense = it.next();
80              newResults.add(historicalTravelExpense);
81          }
82          CollectionIncomplete collection = null;
83          Integer limit = LookupUtils.getSearchResultsLimit(HistoricalTravelExpense.class);
84          if (newResults.size() > limit.intValue()){
85              collection = new CollectionIncomplete(newResults.subList(0, limit), (long) newResults.size());
86          }
87          else{
88              collection = new CollectionIncomplete(newResults, (long) 0);
89          }
90  
91          return collection;
92      }
93  
94      /**
95       * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getReturnInputHtmlData(org.kuali.rice.kns.bo.BusinessObject, java.util.Properties, org.kuali.rice.kns.web.struts.form.LookupForm, java.util.List, org.kuali.rice.kns.authorization.BusinessObjectRestrictions)
96       */
97      @SuppressWarnings("rawtypes")
98      @Override
99      protected HtmlData getReturnInputHtmlData(BusinessObject businessObject, Properties parameters, LookupForm lookupForm, List returnKeys, BusinessObjectRestrictions businessObjectRestrictions) {
100         HistoricalTravelExpense expense = (HistoricalTravelExpense)businessObject;
101         if (!expense.getAssigned()
102                 && (expense.getReconciled() == null || expense.getReconciled().equals(TemConstants.ReconciledCodes.UNRECONCILED))){
103             InputHtmlData input = (InputHtmlData) super.getReturnInputHtmlData(businessObject, parameters, lookupForm, returnKeys, businessObjectRestrictions);
104             input.setAppendDisplayText("</div>");
105             input.setPrependDisplayText("<div align=\"center\">");
106             return input;
107         }
108         else{
109             InputHtmlData input = new InputHtmlData("","hidden");
110             return input;
111         }
112 
113     }
114 
115     @Override
116     public void setParameterService(ParameterService parameterService) {
117         this.parameterService = parameterService;
118     }
119 }