View Javadoc
1   /*
2    * Copyright 2009 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.fp.businessobject.lookup;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.ole.fp.businessobject.CashDrawer;
23  import org.kuali.ole.fp.document.service.CashReceiptService;
24  import org.kuali.ole.fp.service.CashDrawerService;
25  import org.kuali.rice.kns.lookup.HtmlData;
26  import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
27  import org.kuali.rice.krad.bo.BusinessObject;
28  import org.kuali.rice.krad.document.DocumentAuthorizer;
29  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
30  import org.kuali.rice.krad.util.GlobalVariables;
31  import org.kuali.rice.krad.util.KRADConstants;
32  
33  /**
34   * Override of KualiLookupableHelperServiceImpl to prevent the editing and copying of Cash Drawers.  Also to
35   * keep the hobbitses away from my precious.
36   */
37  public class CashDrawerLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl {
38      protected CashReceiptService cashReceiptService;
39      protected CashDrawerService cashDrawerService;
40  
41      /**
42       * Return an empty list - you can't edit or copy cash drawers.
43       * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getCustomActionUrls(org.kuali.rice.krad.bo.BusinessObject, java.util.List)
44       */
45      @Override
46      public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
47          List<HtmlData> htmlDataList = new ArrayList<HtmlData>();
48          if (StringUtils.isNotBlank(getMaintenanceDocumentTypeName()) && allowsMaintenanceEditAction(businessObject) && isEditOfCashDrawerAuthorized((CashDrawer)businessObject) && ((CashDrawer)businessObject).isClosed()) {
49              htmlDataList.add(getUrlData(businessObject, KRADConstants.MAINTENANCE_EDIT_METHOD_TO_CALL, pkNames));
50          }
51          return htmlDataList;
52      }
53  
54      /**
55       *
56       * @param cashDrawer
57       * @return
58       */
59      protected boolean isEditOfCashDrawerAuthorized(CashDrawer cashDrawer) {
60          String cashDrawerDocType = KRADServiceLocatorWeb.getDocumentDictionaryService().getMaintenanceDocumentTypeName(CashDrawer.class);
61          DocumentAuthorizer documentAuthorizer = KRADServiceLocatorWeb.getDocumentDictionaryService().getDocumentAuthorizer(cashDrawerDocType);
62          return documentAuthorizer.canInitiate(cashDrawerDocType, GlobalVariables.getUserSession().getPerson());
63      }
64  
65      /**
66       * Overridden to see if the current user already has a cash drawer created associated with their campus - if
67       * there is a cash drawer already, then no new or copy is allowed
68       * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#allowsMaintenanceNewOrCopyAction()
69       */
70      @Override
71      public boolean allowsMaintenanceNewOrCopyAction() {
72          final String currentUserCampus = cashReceiptService.getCashReceiptVerificationUnitForUser(GlobalVariables.getUserSession().getPerson());
73          final CashDrawer cashDrawer = cashDrawerService.getByCampusCode(currentUserCampus);
74  
75          if (cashDrawer != null) {
76              return false;
77          }
78          return super.allowsMaintenanceNewOrCopyAction();
79      }
80  
81      public void setCashDrawerService(CashDrawerService cashDrawerService) {
82          this.cashDrawerService = cashDrawerService;
83      }
84  
85      public void setCashReceiptService(CashReceiptService cashReceiptService) {
86          this.cashReceiptService = cashReceiptService;
87      }
88  
89  }