View Javadoc
1   /*
2    * Copyright 2006 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.coa.service.impl;
17  
18  import java.util.ArrayList;
19  import java.util.Collection;
20  import java.util.Collections;
21  import java.util.HashMap;
22  import java.util.List;
23  import java.util.Map;
24  
25  import org.kuali.ole.coa.businessobject.OrganizationReversion;
26  import org.kuali.ole.coa.businessobject.OrganizationReversionCategory;
27  import org.kuali.ole.coa.service.OrganizationReversionService;
28  import org.kuali.ole.gl.GeneralLedgerConstants;
29  import org.kuali.ole.gl.batch.service.OrganizationReversionCategoryLogic;
30  import org.kuali.ole.gl.batch.service.impl.GenericOrganizationReversionCategory;
31  import org.kuali.ole.sys.OLEPropertyConstants;
32  import org.kuali.ole.sys.context.SpringContext;
33  import org.kuali.ole.sys.service.NonTransactional;
34  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
35  import org.kuali.rice.krad.service.BusinessObjectService;
36  
37  /**
38   * 
39   * This service implementation is the default implementation of the OrganizationReversion service that is delivered with Kuali.
40   */
41  
42  @NonTransactional
43  public class OrganizationReversionServiceImpl implements OrganizationReversionService {
44      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OrganizationReversionServiceImpl.class);
45  
46      protected BusinessObjectService businessObjectService;
47      protected ParameterService parameterService;
48  
49      /**
50       * @see org.kuali.ole.coa.service.OrganizationReversionService#getByPrimaryId(java.lang.Integer, java.lang.String,
51       *      java.lang.String)
52       */
53      @Override
54      public OrganizationReversion getByPrimaryId(Integer fiscalYear, String chartCode, String orgCode) {
55          Map<String, Object> keys = new HashMap<String, Object>(3);
56          keys.put(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, fiscalYear);
57          keys.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
58          keys.put(OLEPropertyConstants.ORGANIZATION_CODE, orgCode);
59          return SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(OrganizationReversion.class, keys);
60      }
61  
62      /**
63       * @see org.kuali.ole.coa.service.OrganizationReversionService#getCategories()
64       */
65      @Override
66      public Map<String, OrganizationReversionCategoryLogic> getCategories() {
67          List<OrganizationReversionCategory> cats = getCategoryList();
68          Map<String, OrganizationReversionCategoryLogic> orgReversionCategoryLogicMap = SpringContext.getBeansOfType(OrganizationReversionCategoryLogic.class);
69          Map<String, OrganizationReversionCategoryLogic> categories = new HashMap<String, OrganizationReversionCategoryLogic>(cats.size());
70  
71          for ( OrganizationReversionCategory orc : cats ) {
72              String categoryCode = orc.getOrganizationReversionCategoryCode();
73              OrganizationReversionCategoryLogic cat = null;
74              String key = "gl" + categoryCode + "OrganizationReversionCategory";
75              if (orgReversionCategoryLogicMap.containsKey(key)) {
76                  if ( LOG.isDebugEnabled() ) {
77                      LOG.debug("Found Organization Reversion Category Logic for " + key);
78                  }
79                  cat = orgReversionCategoryLogicMap.get(key);
80              } else {
81                  if ( LOG.isInfoEnabled() ) {
82                      LOG.info("No Organization Reversion Category Logic for " + key + "; using generic");
83                  }
84                  // This is a prototype bean - a new instance is pulled every time this is called
85                  cat = SpringContext.getBean(GenericOrganizationReversionCategory.class);
86                  ((GenericOrganizationReversionCategory) cat).setCategoryCode(categoryCode);
87                  ((GenericOrganizationReversionCategory) cat).setCategoryName(orc.getOrganizationReversionCategoryName());
88              }
89              categories.put(categoryCode, cat);
90          }
91          return categories;
92      }
93  
94      /**
95       * 
96       * @see org.kuali.ole.coa.service.OrganizationReversionService#getCategoryList()
97       */
98      @Override
99      public List<OrganizationReversionCategory> getCategoryList() {
100         return new ArrayList<OrganizationReversionCategory>(
101                 businessObjectService.findMatchingOrderBy(OrganizationReversionCategory.class, Collections.singletonMap(OLEPropertyConstants.ACTIVE, true), "organizationReversionSortCode", true)
102                 );
103     }
104 
105     
106     /**
107      * @see org.kuali.ole.coa.service.OrganizationReversionService#getOrganizationReversionDetaiFromSystemParameters()
108      */
109     @Override
110     public String  getOrganizationReversionDetaiFromSystemParameters() {
111         return parameterService.getParameterValueAsString(OrganizationReversion.class, GeneralLedgerConstants.OrganizationReversionProcess.UNALLOC_OBJECT_CODE_PARM);
112     }
113     
114 
115     /**
116      * @see org.kuali.ole.coa.service.OrganizationReversionService#isCategoryActive(java.lang.String)
117      */
118     @Override
119     public boolean isCategoryActive(String categoryCode) {
120         OrganizationReversionCategory category = businessObjectService.findBySinglePrimaryKey(OrganizationReversionCategory.class, categoryCode);
121         if (category == null) {
122             return false;
123         }
124         return category.isActive();
125     }
126 
127     /**
128      * @see org.kuali.ole.coa.service.OrganizationReversionService#isCategoryActiveByName(java.lang.String)
129      */
130     @Override
131     public boolean isCategoryActiveByName(String categoryName) {
132         Collection<OrganizationReversionCategory> categories = businessObjectService.findMatching(OrganizationReversionCategory.class, Collections.singletonMap("organizationReversionCategoryName", categoryName));
133         for ( OrganizationReversionCategory category : categories ) {
134             if ( category.isActive() ) {
135                 return true;
136         }
137         }
138         return false;
139     }
140 
141     public void setParameterService(ParameterService parameterService) {
142         this.parameterService = parameterService;
143     }
144 
145     public void setBusinessObjectService(BusinessObjectService boService) {
146         this.businessObjectService = boService;
147     }
148 }