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.coa.service.impl; 017 018 import java.util.Collection; 019 import java.util.HashMap; 020 import java.util.Iterator; 021 import java.util.List; 022 import java.util.Map; 023 024 import org.kuali.kfs.coa.businessobject.Account; 025 import org.kuali.kfs.coa.businessobject.OrganizationReversion; 026 import org.kuali.kfs.coa.businessobject.OrganizationReversionCategory; 027 import org.kuali.kfs.coa.dataaccess.OrganizationReversionDao; 028 import org.kuali.kfs.coa.service.OrganizationReversionService; 029 import org.kuali.kfs.gl.GeneralLedgerConstants; 030 import org.kuali.kfs.gl.batch.service.OrganizationReversionCategoryLogic; 031 import org.kuali.kfs.gl.batch.service.impl.GenericOrganizationReversionCategory; 032 import org.kuali.kfs.sys.KFSConstants; 033 import org.kuali.kfs.sys.context.SpringContext; 034 import org.kuali.kfs.sys.service.NonTransactional; 035 import org.kuali.rice.kns.service.BusinessObjectService; 036 import org.kuali.rice.kns.service.ParameterService; 037 038 /** 039 * 040 * This service implementation is the default implementation of the OrganizationReversion service that is delivered with Kuali. 041 */ 042 043 @NonTransactional 044 public class OrganizationReversionServiceImpl implements OrganizationReversionService { 045 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OrganizationReversionServiceImpl.class); 046 047 private OrganizationReversionDao organizationReversionDao; 048 private BusinessObjectService businessObjectService; 049 private ParameterService parameterService; 050 /** 051 * @see org.kuali.kfs.coa.service.OrganizationReversionService#getByPrimaryId(java.lang.Integer, java.lang.String, 052 * java.lang.String) 053 */ 054 public OrganizationReversion getByPrimaryId(Integer fiscalYear, String chartCode, String orgCode) { 055 LOG.debug("getByPrimaryId() started"); 056 return organizationReversionDao.getByPrimaryId(fiscalYear, chartCode, orgCode); 057 } 058 059 /** 060 * @see org.kuali.kfs.coa.service.OrganizationReversionService#getCategories() 061 */ 062 public Map<String, OrganizationReversionCategoryLogic> getCategories() { 063 LOG.debug("getCategories() started"); 064 065 Map<String, OrganizationReversionCategoryLogic> categories = new HashMap<String, OrganizationReversionCategoryLogic>(); 066 067 Collection cats = organizationReversionDao.getCategories(); 068 069 for (Iterator iter = cats.iterator(); iter.hasNext();) { 070 OrganizationReversionCategory orc = (OrganizationReversionCategory) iter.next(); 071 072 String categoryCode = orc.getOrganizationReversionCategoryCode(); 073 074 Map<String, OrganizationReversionCategoryLogic> beanMap = SpringContext.getBeansOfType(OrganizationReversionCategoryLogic.class); 075 if (beanMap.containsKey("gl" + categoryCode + "OrganizationReversionCategory")) { 076 LOG.info("Found Organization Reversion Category Logic for gl" + categoryCode + "OrganizationReversionCategory"); 077 categories.put(categoryCode, beanMap.get("gl" + categoryCode + "OrganizationReversionCategory")); 078 } 079 else { 080 LOG.info("No Organization Reversion Category Logic for gl" + categoryCode + "OrganizationReversionCategory; using generic"); 081 GenericOrganizationReversionCategory cat = SpringContext.getBean(GenericOrganizationReversionCategory.class); 082 cat.setCategoryCode(categoryCode); 083 cat.setCategoryName(orc.getOrganizationReversionCategoryName()); 084 categories.put(categoryCode, (OrganizationReversionCategoryLogic) cat); 085 } 086 } 087 return categories; 088 } 089 090 /** 091 * 092 * @see org.kuali.kfs.coa.service.OrganizationReversionService#getCategoryList() 093 */ 094 public List<OrganizationReversionCategory> getCategoryList() { 095 LOG.debug("getCategoryList() started"); 096 097 return organizationReversionDao.getCategories(); 098 } 099 100 101 /** 102 * @see org.kuali.kfs.coa.service.OrganizationReversionService#getOrganizationReversionDetaiFromSystemParameters() 103 */ 104 public String getOrganizationReversionDetaiFromSystemParameters() { 105 return parameterService.getParameterValue(OrganizationReversion.class, GeneralLedgerConstants.OrganizationReversionProcess.UNALLOC_OBJECT_CODE_PARM); 106 } 107 108 109 /** 110 * @see org.kuali.kfs.coa.service.OrganizationReversionService#isCategoryActive(java.lang.String) 111 */ 112 public boolean isCategoryActive(String categoryCode) { 113 Map<String, Object> pkMap = new HashMap<String, Object>(); 114 pkMap.put("organizationReversionCategoryCode", categoryCode); 115 final OrganizationReversionCategory category = (OrganizationReversionCategory)businessObjectService.findByPrimaryKey(OrganizationReversionCategory.class, pkMap); 116 if (category == null) return false; 117 return category.isActive(); 118 } 119 120 /** 121 * @see org.kuali.kfs.coa.service.OrganizationReversionService#isCategoryActiveByName(java.lang.String) 122 */ 123 public boolean isCategoryActiveByName(String categoryName) { 124 Map<String, Object> fieldMap = new HashMap<String, Object>(); 125 fieldMap.put("organizationReversionCategoryName", categoryName); 126 final Collection categories = businessObjectService.findMatching(OrganizationReversionCategory.class, fieldMap); 127 final Iterator categoriesIterator = categories.iterator(); 128 OrganizationReversionCategory category = null; 129 while (categoriesIterator.hasNext()) { 130 category = (OrganizationReversionCategory)categoriesIterator.next(); 131 } 132 if (category == null) return false; 133 return category.isActive(); 134 } 135 136 /** 137 * 138 * This method injects the ParameterService 139 * @param parameterService 140 */ 141 public void setParameterService(ParameterService parameterService) { 142 this.parameterService = parameterService; 143 } 144 145 146 /** 147 * 148 * This method injects the OrganizationReversionDao 149 * @param orgDao 150 */ 151 public void setOrganizationReversionDao(OrganizationReversionDao orgDao) { 152 organizationReversionDao = orgDao; 153 } 154 155 /** 156 * Sets an implementation of the business object service 157 * @param boService the implementation of the BusinessObjectService to set 158 */ 159 public void setBusinessObjectService(BusinessObjectService boService) { 160 this.businessObjectService = boService; 161 } 162 }