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.List;
22  import java.util.Map;
23  
24  import org.apache.commons.lang.StringUtils;
25  import org.kuali.kfs.module.tem.businessobject.PerDiem;
26  import org.kuali.rice.kns.document.authorization.MaintenanceDocumentPresentationController;
27  import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
28  import org.kuali.rice.kns.lookup.LookupUtils;
29  import org.kuali.rice.krad.bo.BusinessObject;
30  import org.kuali.rice.krad.lookup.CollectionIncomplete;
31  import org.kuali.rice.krad.service.DocumentDictionaryService;
32  
33  
34  @SuppressWarnings("deprecation")
35  public class PerDiemLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl {
36      protected DocumentDictionaryService documentDictionaryService;
37  
38      /**
39       * @see org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl#getSearchResults(java.util.Map)
40       */
41      @SuppressWarnings("rawtypes")
42      @Override
43      public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
44          List<PerDiem> results = (List<PerDiem>) super.getSearchResultsHelper(fieldValues, true);
45  
46  
47          CollectionIncomplete collection = null;
48          Integer limit = LookupUtils.getSearchResultsLimit(PerDiem.class);
49          if (results.size() > limit.intValue()){
50              collection = new CollectionIncomplete(results.subList(0, limit), (long) results.size());
51          }
52          else{
53              collection = new CollectionIncomplete(results, (long) 0);
54          }
55          return collection;
56      }
57  
58      @Override
59      protected boolean allowsMaintenanceEditAction(BusinessObject businessObject) {
60          String maintDocTypeName = getMaintenanceDocumentTypeName();
61  
62          if (StringUtils.isNotBlank(maintDocTypeName)) {
63              final MaintenanceDocumentPresentationController docPresentationController = (MaintenanceDocumentPresentationController)getDocumentDictionaryService().getDocumentPresentationController(maintDocTypeName);
64              final boolean allowsEdit = docPresentationController.canMaintain(businessObject);
65              if (!allowsEdit) {
66                  return false;
67              }
68          }
69          return super.allowsMaintenanceEditAction(businessObject);
70      }
71  
72      public DocumentDictionaryService getDocumentDictionaryService() {
73          return documentDictionaryService;
74      }
75  
76      public void setDocumentDictionaryService(DocumentDictionaryService documentDictionaryService) {
77          this.documentDictionaryService = documentDictionaryService;
78      }
79  }