View Javadoc
1   /*
2    * Copyright 2007 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.gl.batch.service.impl;
17  
18  import java.util.Collection;
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  import org.kuali.ole.gl.batch.dataaccess.OrganizationReversionUnitOfWorkDao;
23  import org.kuali.ole.gl.batch.service.OrganizationReversionUnitOfWorkService;
24  import org.kuali.ole.gl.businessobject.OrgReversionUnitOfWork;
25  import org.kuali.ole.gl.businessobject.OrgReversionUnitOfWorkCategoryAmount;
26  import org.kuali.rice.krad.service.BusinessObjectService;
27  import org.springframework.transaction.annotation.Transactional;
28  
29  /**
30   * The base implementation of OrganizationReversionUnitOfWorkService
31   */
32  @Transactional
33  public class OrganizationReversionUnitOfWorkServiceImpl implements OrganizationReversionUnitOfWorkService {
34      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OrganizationReversionUnitOfWorkServiceImpl.class);
35      
36      protected BusinessObjectService businessObjectService;
37      protected OrganizationReversionUnitOfWorkDao orgReversionUnitOfWorkDao;
38  
39      /**
40       * This method takes a unit of work retrieved from the persistence store and loads its categories
41       * 
42       * @param orgRevUnitOfWork org reversion unit of work to load categories for
43       * @return the org reversion unit of work with loaded categories
44       * @see org.kuali.ole.gl.batch.service.OrganizationReversionUnitOfWorkService#loadCategories(org.kuali.ole.gl.businessobject.OrgReversionUnitOfWork)
45       */
46      public OrgReversionUnitOfWork loadCategories(OrgReversionUnitOfWork orgRevUnitOfWork) {
47          Map<String,Object> criteria = new HashMap<String, Object>();
48          criteria.put("chartOfAccountsCode", orgRevUnitOfWork.chartOfAccountsCode);
49          criteria.put("accountNbr", orgRevUnitOfWork.accountNumber);
50          criteria.put("subAccountNbr", orgRevUnitOfWork.subAccountNumber);
51  
52          Collection<OrgReversionUnitOfWorkCategoryAmount> categoryAmounts = businessObjectService.findMatching(OrgReversionUnitOfWorkCategoryAmount.class, criteria);
53          Map<String, OrgReversionUnitOfWorkCategoryAmount> categories = orgRevUnitOfWork.getCategoryAmounts();
54          for ( OrgReversionUnitOfWorkCategoryAmount catAmount : categoryAmounts ) {
55              categories.put(catAmount.getCategoryCode(), catAmount);
56          }
57          return orgRevUnitOfWork;
58      }
59  
60      /**
61       * Immediate deletion awaits all entries of the unit of work summary tables in the persistence store once
62       * you call this method, for this method is both powerful and deadly and also gets called to clear out
63       * those tables before every single org reversion run.
64       * @see org.kuali.ole.gl.batch.service.OrganizationReversionUnitOfWorkService#removeAll()
65       */
66      public void destroyAllUnitOfWorkSummaries() {
67          orgReversionUnitOfWorkDao.destroyAllUnitOfWorkSummaries();
68      }
69  
70      /**
71       * This save method is guaranteed to save the category data as well.
72       * 
73       * @param orgRevUnitOfWork organizationReversionUnitOfWork to save
74       * @see org.kuali.ole.gl.batch.service.OrganizationReversionUnitOfWorkService#save(org.kuali.ole.gl.businessobject.OrgReversionUnitOfWork)
75       */
76      public void save(OrgReversionUnitOfWork orgRevUnitOfWork) {
77          if (LOG.isDebugEnabled()) {
78              LOG.debug("Saving org reversion summary for " + orgRevUnitOfWork.toString() + "; its category keys are: " + orgRevUnitOfWork.getCategoryAmounts().keySet());
79          }
80          businessObjectService.save(orgRevUnitOfWork);
81          for (String category: orgRevUnitOfWork.getCategoryAmounts().keySet()) {
82              final OrgReversionUnitOfWorkCategoryAmount categoryAmount = orgRevUnitOfWork.getCategoryAmounts().get(category);
83              if (LOG.isDebugEnabled()) {
84                  LOG.debug("Saving category amount for " + categoryAmount.toString());
85              }
86              businessObjectService.save(categoryAmount);
87      }
88      }
89  
90      /**
91       * Sets the businessObjectService attribute value.
92       * 
93       * @param businessObjectService The businessObjectService to set.
94       */
95      public void setBusinessObjectService(BusinessObjectService businessObjectService) {
96          this.businessObjectService = businessObjectService;
97      }
98  
99      /**
100      * Sets the orgReversionUnitOfWorkDao attribute value.
101      * 
102      * @param orgReversionUnitOfWorkDao The orgReversionUnitOfWorkDao to set.
103      */
104     public void setOrgReversionUnitOfWorkDao(OrganizationReversionUnitOfWorkDao orgReversionUnitOfWorkDao) {
105         this.orgReversionUnitOfWorkDao = orgReversionUnitOfWorkDao;
106     }
107 
108 }