View Javadoc
1   /*
2    * Copyright 2012 The Kuali Foundation.
3    *
4    * Licensed under the Educational Community License, Version 1.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/ecl1.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.select.service.impl;
17  
18  import org.kuali.ole.coa.businessobject.Account;
19  import org.kuali.ole.select.service.OleAccountService;
20  import org.kuali.ole.sys.OLEConstants;
21  import org.kuali.ole.sys.context.SpringContext;
22  import org.kuali.rice.kew.api.exception.WorkflowException;
23  import org.kuali.rice.kns.document.MaintenanceDocument;
24  import org.kuali.rice.krad.service.BusinessObjectService;
25  import org.kuali.rice.krad.service.DocumentService;
26  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
27  import org.kuali.rice.krad.util.ObjectUtils;
28  
29  import java.util.HashMap;
30  import java.util.List;
31  import java.util.Map;
32  
33  public class OleAccountServiceImpl implements OleAccountService {
34  
35      private BusinessObjectService businessObjectService;
36  
37      /**
38       * Gets the businessObjectService attribute.
39       *
40       * @return Returns the businessObjectService.
41       */
42      public BusinessObjectService getBusinessObjectService() {
43          if (businessObjectService == null) {
44              businessObjectService = SpringContext.getBean(org.kuali.rice.krad.service.BusinessObjectService.class);
45          }
46          return businessObjectService;
47      }
48  
49      /**
50       * @see org.kuali.ole.select.service.OleAccountService#getTemporaryRestrictedAccounts()
51       */
52      @Override
53      public List<Account> getTemporaryRestrictedAccounts() {
54          // TODO Auto-generated method stub
55          String accountRestrictedStatusCode = "T";
56          Map TRestrictedAccountMap = new HashMap();
57          TRestrictedAccountMap.put("accountRestrictedStatusCode", accountRestrictedStatusCode);
58          businessObjectService = getBusinessObjectService();
59          List<Account> accountList = (List<Account>) businessObjectService.findMatching(Account.class, TRestrictedAccountMap);
60          return accountList;
61      }
62  
63      /**
64       * @see org.kuali.ole.select.service.OleAccountService#getAccountDetailsWithAccountNumber(java.lang.String)
65       */
66      @Override
67      public Account getAccountDetailsWithAccountNumber(String accountNumber) {
68          // TODO Auto-generated method stub
69          Map accountNumberMap = new HashMap();
70          accountNumberMap.put("accountNumber", accountNumber);
71          businessObjectService = getBusinessObjectService();
72          return (Account) businessObjectService.findMatching(Account.class, accountNumberMap);
73      }
74  
75      /**
76       * @see org.kuali.ole.select.service.OleAccountService#getAllAccountDetails()
77       */
78      @Override
79      public List<Account> getAllAccountDetails() {
80          // TODO Auto-generated method stub
81          businessObjectService = getBusinessObjectService();
82          return (List<Account>) businessObjectService.findAll(Account.class);
83      }
84  
85      /**
86       * @see org.kuali.ole.select.service.OleAccountService#getMatchingAccountDetails(java.util.Map)
87       */
88      @Override
89      public List<Account> getMatchingAccountDetails(Map<String, String> parameters) {
90          // TODO Auto-generated method stub
91          businessObjectService = getBusinessObjectService();
92          return (List<Account>) businessObjectService.findMatching(Account.class, parameters);
93      }
94  
95      /**
96       * @see org.kuali.ole.vnd.document.service.VendorService#shouldVendorRouteForApproval(java.lang.String)
97       */
98      @Override
99      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 }