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.gl.batch.service.impl; 017 018 import java.util.Collection; 019 import java.util.Iterator; 020 import java.util.Map; 021 022 import org.apache.commons.collections.Closure; 023 import org.apache.commons.collections.CollectionUtils; 024 import org.kuali.kfs.gl.batch.dataaccess.OrganizationReversionUnitOfWorkDao; 025 import org.kuali.kfs.gl.batch.service.OrganizationReversionUnitOfWorkService; 026 import org.kuali.kfs.gl.businessobject.OrgReversionUnitOfWork; 027 import org.kuali.kfs.gl.businessobject.OrgReversionUnitOfWorkCategoryAmount; 028 import org.kuali.rice.kns.service.BusinessObjectService; 029 import org.springframework.transaction.annotation.Transactional; 030 031 /** 032 * The base implementation of OrganizationReversionUnitOfWorkService 033 */ 034 @Transactional 035 public class OrganizationReversionUnitOfWorkServiceImpl implements OrganizationReversionUnitOfWorkService { 036 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OrganizationReversionUnitOfWorkServiceImpl.class); 037 private BusinessObjectService businessObjectService; 038 private OrganizationReversionUnitOfWorkDao orgReversionUnitOfWorkDao; 039 040 /** 041 * This method takes a unit of work retrieved from the persistence store and loads its categories 042 * 043 * @param orgRevUnitOfWork org reversion unit of work to load categories for 044 * @return the org reversion unit of work with loaded categories 045 * @see org.kuali.kfs.gl.batch.service.OrganizationReversionUnitOfWorkService#loadCategories(org.kuali.kfs.gl.businessobject.OrgReversionUnitOfWork) 046 */ 047 public OrgReversionUnitOfWork loadCategories(OrgReversionUnitOfWork orgRevUnitOfWork) { 048 Collection categoryAmounts = businessObjectService.findMatching(OrgReversionUnitOfWorkCategoryAmount.class, orgRevUnitOfWork.toStringMapper()); 049 Map<String, OrgReversionUnitOfWorkCategoryAmount> categories = orgRevUnitOfWork.getCategoryAmounts(); 050 Iterator iter = categoryAmounts.iterator(); 051 while (iter.hasNext()) { 052 OrgReversionUnitOfWorkCategoryAmount catAmount = (OrgReversionUnitOfWorkCategoryAmount) iter.next(); 053 categories.put(catAmount.getCategoryCode(), catAmount); 054 } 055 return orgRevUnitOfWork; 056 } 057 058 /** 059 * Immediate deletion awaits all entries of the unit of work summary tables in the persistence store once 060 * you call this method, for this method is both powerful and deadly and also gets called to clear out 061 * those tables before every single org reversion run. 062 * @see org.kuali.kfs.gl.batch.service.OrganizationReversionUnitOfWorkService#removeAll() 063 */ 064 public void destroyAllUnitOfWorkSummaries() { 065 orgReversionUnitOfWorkDao.destroyAllUnitOfWorkSummaries(); 066 } 067 068 /** 069 * This save method is guaranteed to save the category data as well. 070 * 071 * @param orgRevUnitOfWork organizationReversionUnitOfWork to save 072 * @see org.kuali.kfs.gl.batch.service.OrganizationReversionUnitOfWorkService#save(org.kuali.kfs.gl.businessobject.OrgReversionUnitOfWork) 073 */ 074 public void save(OrgReversionUnitOfWork orgRevUnitOfWork) { 075 if (LOG.isDebugEnabled()) { 076 LOG.debug("Saving org reversion summary for " + orgRevUnitOfWork.toString() + "; its category keys are: " + orgRevUnitOfWork.getCategoryAmounts().keySet()); 077 } 078 getBusinessObjectService().save(orgRevUnitOfWork); 079 for (String category: orgRevUnitOfWork.getCategoryAmounts().keySet()) { 080 final OrgReversionUnitOfWorkCategoryAmount categoryAmount = orgRevUnitOfWork.getCategoryAmounts().get(category); 081 if (LOG.isDebugEnabled()) { 082 LOG.debug("Saving category amount for " + categoryAmount.toString()); 083 } 084 getBusinessObjectService().save(categoryAmount); 085 } 086 } 087 088 /** 089 * Gets the businessObjectService attribute. 090 * 091 * @return Returns the businessObjectService. 092 */ 093 public BusinessObjectService getBusinessObjectService() { 094 return businessObjectService; 095 } 096 097 /** 098 * Sets the businessObjectService attribute value. 099 * 100 * @param businessObjectService The businessObjectService to set. 101 */ 102 public void setBusinessObjectService(BusinessObjectService businessObjectService) { 103 this.businessObjectService = businessObjectService; 104 } 105 106 /** 107 * Gets the orgReversionUnitOfWorkDao attribute. 108 * 109 * @return Returns the orgReversionUnitOfWorkDao. 110 */ 111 public OrganizationReversionUnitOfWorkDao getOrgReversionUnitOfWorkDao() { 112 return orgReversionUnitOfWorkDao; 113 } 114 115 /** 116 * Sets the orgReversionUnitOfWorkDao attribute value. 117 * 118 * @param orgReversionUnitOfWorkDao The orgReversionUnitOfWorkDao to set. 119 */ 120 public void setOrgReversionUnitOfWorkDao(OrganizationReversionUnitOfWorkDao orgReversionUnitOfWorkDao) { 121 this.orgReversionUnitOfWorkDao = orgReversionUnitOfWorkDao; 122 } 123 124 }