001 /* 002 * Copyright 2011 The Kuali Foundation. 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.kfs.fp.businessobject.lookup; 017 018 import java.util.ArrayList; 019 import java.util.List; 020 021 import org.apache.commons.lang.StringUtils; 022 import org.kuali.kfs.fp.businessobject.CashDrawer; 023 import org.kuali.kfs.fp.document.service.CashReceiptService; 024 import org.kuali.kfs.fp.service.CashDrawerService; 025 import org.kuali.kfs.sys.context.SpringContext; 026 import org.kuali.kfs.sys.document.authorization.FinancialSystemMaintenanceDocumentAuthorizerBase; 027 import org.kuali.rice.kns.bo.BusinessObject; 028 import org.kuali.rice.kns.lookup.HtmlData; 029 import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl; 030 import org.kuali.rice.kns.lookup.LookupableHelperService; 031 import org.kuali.rice.kns.service.DocumentHelperService; 032 import org.kuali.rice.kns.util.GlobalVariables; 033 import org.kuali.rice.kns.util.KNSConstants; 034 035 /** 036 * Override of KualiLookupableHelperServiceImpl to prevent the editing and copying of Cash Drawers. Also to 037 * keep the hobbitses away from my precious. 038 */ 039 public class CashDrawerLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl implements LookupableHelperService { 040 private CashReceiptService cashReceiptService; 041 private CashDrawerService cashDrawerService; 042 043 /** 044 * Return an empty list - you can't edit or copy cash drawers. 045 * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getCustomActionUrls(org.kuali.rice.kns.bo.BusinessObject, java.util.List) 046 */ 047 @Override 048 public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) { 049 List<HtmlData> htmlDataList = new ArrayList<HtmlData>(); 050 if (StringUtils.isNotBlank(getMaintenanceDocumentTypeName()) && allowsMaintenanceEditAction(businessObject) && isEditOfCashDrawerAuthorized((CashDrawer)businessObject) && ((CashDrawer)businessObject).isClosed()) { 051 htmlDataList.add(getUrlData(businessObject, KNSConstants.MAINTENANCE_EDIT_METHOD_TO_CALL, pkNames)); 052 } 053 return htmlDataList; 054 } 055 056 /** 057 * 058 * @param cashDrawer 059 * @return 060 */ 061 protected boolean isEditOfCashDrawerAuthorized(CashDrawer cashDrawer) { 062 final FinancialSystemMaintenanceDocumentAuthorizerBase documentAuthorizer = (FinancialSystemMaintenanceDocumentAuthorizerBase) SpringContext.getBean(DocumentHelperService.class).getDocumentAuthorizer("CDS"); 063 final boolean isAuthorized = documentAuthorizer.isAuthorized(cashDrawer, "KFS-FP", "Initiate Document", GlobalVariables.getUserSession().getPerson().getPrincipalId()); 064 065 return isAuthorized; 066 067 } 068 069 /** 070 * Overridden to see if the current user already has a cash drawer created associated with their campus - if 071 * there is a cash drawer already, then no new or copy is allowed 072 * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#allowsMaintenanceNewOrCopyAction() 073 */ 074 @Override 075 public boolean allowsMaintenanceNewOrCopyAction() { 076 final String currentUserCampus = getCashReceiptService().getCashReceiptVerificationUnitForUser(GlobalVariables.getUserSession().getPerson()); 077 final CashDrawer cashDrawer = getCashDrawerService().getByCampusCode(currentUserCampus); 078 079 if (cashDrawer != null) return false; 080 return super.allowsMaintenanceNewOrCopyAction(); 081 } 082 083 /** 084 * Gets the cashDrawerService attribute. 085 * @return Returns the cashDrawerService. 086 */ 087 public CashDrawerService getCashDrawerService() { 088 return cashDrawerService; 089 } 090 091 /** 092 * Sets the cashDrawerService attribute value. 093 * @param cashDrawerService The cashDrawerService to set. 094 */ 095 public void setCashDrawerService(CashDrawerService cashDrawerService) { 096 this.cashDrawerService = cashDrawerService; 097 } 098 099 /** 100 * Gets the cashReceiptService attribute. 101 * @return Returns the cashReceiptService. 102 */ 103 public CashReceiptService getCashReceiptService() { 104 return cashReceiptService; 105 } 106 107 /** 108 * Sets the cashReceiptService attribute value. 109 * @param cashReceiptService The cashReceiptService to set. 110 */ 111 public void setCashReceiptService(CashReceiptService cashReceiptService) { 112 this.cashReceiptService = cashReceiptService; 113 } 114 115 }