001/* 002 * Copyright 2012 The Kuali Foundation. 003 * 004 * Licensed under the Educational Community License, Version 1.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/ecl1.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 */ 016package org.kuali.ole.select.service.impl; 017 018import org.kuali.ole.coa.businessobject.Account; 019import org.kuali.ole.select.service.OleAccountService; 020import org.kuali.ole.sys.OLEConstants; 021import org.kuali.ole.sys.context.SpringContext; 022import org.kuali.rice.kew.api.exception.WorkflowException; 023import org.kuali.rice.kns.document.MaintenanceDocument; 024import org.kuali.rice.krad.service.BusinessObjectService; 025import org.kuali.rice.krad.service.DocumentService; 026import org.kuali.rice.krad.service.KRADServiceLocatorWeb; 027import org.kuali.rice.krad.util.ObjectUtils; 028 029import java.util.HashMap; 030import java.util.List; 031import java.util.Map; 032 033public class OleAccountServiceImpl implements OleAccountService { 034 035 private BusinessObjectService businessObjectService; 036 037 /** 038 * Gets the businessObjectService attribute. 039 * 040 * @return Returns the businessObjectService. 041 */ 042 public BusinessObjectService getBusinessObjectService() { 043 if (businessObjectService == null) { 044 businessObjectService = SpringContext.getBean(org.kuali.rice.krad.service.BusinessObjectService.class); 045 } 046 return businessObjectService; 047 } 048 049 /** 050 * @see org.kuali.ole.select.service.OleAccountService#getTemporaryRestrictedAccounts() 051 */ 052 @Override 053 public List<Account> getTemporaryRestrictedAccounts() { 054 // TODO Auto-generated method stub 055 String accountRestrictedStatusCode = "T"; 056 Map TRestrictedAccountMap = new HashMap(); 057 TRestrictedAccountMap.put("accountRestrictedStatusCode", accountRestrictedStatusCode); 058 businessObjectService = getBusinessObjectService(); 059 List<Account> accountList = (List<Account>) businessObjectService.findMatching(Account.class, TRestrictedAccountMap); 060 return accountList; 061 } 062 063 /** 064 * @see org.kuali.ole.select.service.OleAccountService#getAccountDetailsWithAccountNumber(java.lang.String) 065 */ 066 @Override 067 public Account getAccountDetailsWithAccountNumber(String accountNumber) { 068 // TODO Auto-generated method stub 069 Map accountNumberMap = new HashMap(); 070 accountNumberMap.put("accountNumber", accountNumber); 071 businessObjectService = getBusinessObjectService(); 072 return (Account) businessObjectService.findMatching(Account.class, accountNumberMap); 073 } 074 075 /** 076 * @see org.kuali.ole.select.service.OleAccountService#getAllAccountDetails() 077 */ 078 @Override 079 public List<Account> getAllAccountDetails() { 080 // TODO Auto-generated method stub 081 businessObjectService = getBusinessObjectService(); 082 return (List<Account>) businessObjectService.findAll(Account.class); 083 } 084 085 /** 086 * @see org.kuali.ole.select.service.OleAccountService#getMatchingAccountDetails(java.util.Map) 087 */ 088 @Override 089 public List<Account> getMatchingAccountDetails(Map<String, String> parameters) { 090 // TODO Auto-generated method stub 091 businessObjectService = getBusinessObjectService(); 092 return (List<Account>) businessObjectService.findMatching(Account.class, parameters); 093 } 094 095 /** 096 * @see org.kuali.ole.vnd.document.service.VendorService#shouldVendorRouteForApproval(java.lang.String) 097 */ 098 @Override 099 public boolean shouldAccountRouteForApproval(String documentId) { 100 boolean shouldRoute = false; 101 MaintenanceDocument newDoc = null; 102 try { 103 DocumentService documentService = KRADServiceLocatorWeb.getDocumentService(); 104 newDoc = (MaintenanceDocument) documentService.getByDocumentHeaderId(documentId); 105 } catch (WorkflowException we) { 106 throw new RuntimeException("A WorkflowException was thrown which prevented the loading of " + "the comparison document (" + documentId + ")", we); 107 } 108 109 if (ObjectUtils.isNotNull(newDoc)) { 110 Account account = (Account) newDoc.getNewMaintainableObject().getBusinessObject(); 111 if (account.getSubFundGroupCode() != null && !account.getSubFundGroupCode().isEmpty() && 112 account.getSubFundGroupCode().equals(OLEConstants.CLEARING_ACCOUNT_CODE)) { 113 shouldRoute = true; 114 } 115 } 116 return shouldRoute; 117 } 118 119 120}