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.fp.service.impl;
017
018 import java.util.ArrayList;
019 import java.util.Collection;
020 import java.util.HashMap;
021 import java.util.Iterator;
022 import java.util.List;
023
024 import org.kuali.kfs.fp.businessobject.FiscalYearFunctionControl;
025 import org.kuali.kfs.fp.service.FiscalYearFunctionControlService;
026 import org.kuali.kfs.sys.KFSConstants;
027 import org.kuali.kfs.sys.KFSPropertyConstants;
028 import org.kuali.rice.kns.service.BusinessObjectService;
029
030 /**
031 *
032 * This is the default implementation of the FiscalyearFunctionControlService interface.
033 *
034 */
035 public class FiscalYearFunctionControlServiceImpl implements FiscalYearFunctionControlService {
036
037 public static String FY_FUNCTION_CONTROL_BA_ALLOWED = "BAACTV";
038 public static String FY_FUNCTION_CONTROL_BASE_AMT_ALLOWED = "BASEAD";
039
040 private BusinessObjectService businessObjectService;
041
042 /**
043 * Retrieves the FiscalYearFunctionControl by its composite primary key (all passed in as parameters) and returns the active
044 * indicator.
045 *
046 * @param postingYear The posting year associated with the fiscal year function control being retrieved.
047 * @param financialSystemFunctionControlCode The function control code associated with the fiscal year function control being retrieved.
048 * @return Returns the value of the active indicator; returns null if PK is not found
049 */
050 protected boolean getActiveIndByPrimaryId(Integer postingYear, String financialSystemFunctionControlCode) {
051 HashMap<String, Object> keys = new HashMap();
052 keys.put(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, postingYear);
053 keys.put(KFSPropertyConstants.FINANCIAL_SYSTEM_FUNCTION_CONTROL_CODE, financialSystemFunctionControlCode);
054 FiscalYearFunctionControl control = (FiscalYearFunctionControl) businessObjectService.findByPrimaryKey(FiscalYearFunctionControl.class, keys);
055 return (control != null) && control.isFinancialSystemFunctionActiveIndicator();
056 }
057
058 /**
059 * Retrieves list of FiscalYearFunctionControls by its function control code.
060 *
061 * @param financialSystemFunctionControlCode The function control code to search by.
062 * @param financialSystemFunctionActiveIndicator An active indicator used as a search parameter.
063 * @return The list of FiscalYearFunctionControls matching the search criteria provided.
064 */
065 protected List getByFunctionControlCodeAndActiveInd(String financialSystemFunctionControlCode, String financialSystemFunctionActiveIndicator) {
066 HashMap values = new HashMap();
067 values.put(KFSPropertyConstants.FINANCIAL_SYSTEM_FUNCTION_CONTROL_CODE, financialSystemFunctionControlCode);
068 values.put(KFSPropertyConstants.FINANCIAL_SYSTEM_FUNCTION_ACTIVE_INDICATOR, financialSystemFunctionActiveIndicator);
069 Collection controls = businessObjectService.findMatching(FiscalYearFunctionControl.class, values);
070 return new ArrayList(controls);
071 }
072
073 /**
074 * Retrieves a collection of FiscalYearFunctionControls allowed for use in a budget adjustment.
075 *
076 * @return A collection of FiscalYearFunctionControls representing the years allowed in a budget adjustment.
077 *
078 * @see FiscalYearFunctionControlService#getBudgetAdjustmentAllowedYears(String)
079 */
080 public List getBudgetAdjustmentAllowedYears() {
081 return getByFunctionControlCodeAndActiveInd(FY_FUNCTION_CONTROL_BA_ALLOWED, "Y");
082 }
083
084 /**
085 * This method retrieves the value of the active indicator for a FiscalYearFunctionControl instance for the
086 * given posting year.
087 *
088 * @param postingYear The posting year used as a search parameter.
089 * @return True if the active indicator for the retrieved FiscalYearFunctionControl value retrieved is true, false otherwise.
090 *
091 * @see FiscalYearFunctionControlService#isBaseAmountChangeAllowed(Integer, String)
092 */
093 public boolean isBaseAmountChangeAllowed(Integer postingYear) {
094 return getActiveIndByPrimaryId(postingYear, FY_FUNCTION_CONTROL_BASE_AMT_ALLOWED);
095 }
096 /**
097 *
098 * @see org.kuali.kfs.fp.service.FiscalYearFunctionControlService#getActiveBudgetYear()
099 */
100 public List<Integer> getActiveBudgetYear()
101 {
102 ArrayList<FiscalYearFunctionControl> activeYearObjects = (ArrayList<FiscalYearFunctionControl>) getByFunctionControlCodeAndActiveInd(KFSConstants.BudgetConstructionConstants.BUDGET_CONSTRUCTION_ACTIVE,KFSConstants.ACTIVE_INDICATOR);
103 ArrayList<Integer> activeYears = new ArrayList<Integer>(activeYearObjects.size());
104 Iterator<FiscalYearFunctionControl> activeYearObjectIterator = activeYearObjects.iterator();
105 int nextSlot = 0;
106 while (activeYearObjectIterator.hasNext())
107 {
108 activeYears.add(nextSlot++,activeYearObjectIterator.next().getUniversityFiscalYear());
109 }
110 return activeYears;
111 }
112
113
114 /**
115 *
116 * @see org.kuali.kfs.fp.service.FiscalYearFunctionControlService#isApplicationUpdateFromHumanResourcesAllowed(java.lang.Integer)
117 */
118 public boolean isApplicationUpdateFromHumanResourcesAllowed(Integer universityFiscalYear)
119 {
120 return getActiveIndByPrimaryId(universityFiscalYear, KFSConstants.BudgetConstructionConstants.BUDGET_ON_LINE_SYNCHRONIZATION_OK);
121 }
122
123 /**
124 *
125 * @see org.kuali.kfs.fp.service.FiscalYearFunctionControlService#isBatchUpdateFromHumanResourcesAllowed(java.lang.Integer)
126 */
127 public boolean isBatchUpdateFromHumanResourcesAllowed(Integer universityFiscalYear)
128 {
129 return getActiveIndByPrimaryId(universityFiscalYear, KFSConstants.BudgetConstructionConstants.BUDGET_BATCH_SYNCHRONIZATION_OK);
130 }
131
132 /**
133 *
134 * @see org.kuali.kfs.fp.service.FiscalYearFunctionControlService#isBatchUpdateFromPayrollAllowed(java.lang.Integer)
135 */
136 public boolean isBatchUpdateFromPayrollAllowed (Integer universityFiscalYear)
137 {
138 return getActiveIndByPrimaryId(universityFiscalYear, KFSConstants.BudgetConstructionConstants.CSF_UPDATES_OK);
139 }
140
141
142 public boolean isBudgetConstructionActive(Integer universityFiscalYear)
143 {
144 return getActiveIndByPrimaryId(universityFiscalYear, KFSConstants.BudgetConstructionConstants.BUDGET_CONSTRUCTION_ACTIVE);
145 }
146
147 /**
148 *
149 * @see org.kuali.kfs.fp.service.FiscalYearFunctionControlService#isBudgetGeneralLedgerUpdateAllowed(java.lang.Integer)
150 */
151 public boolean isBudgetGeneralLedgerUpdateAllowed(Integer universityFiscalYear)
152 {
153 return getActiveIndByPrimaryId(universityFiscalYear, KFSConstants.BudgetConstructionConstants.BASE_BUDGET_UPDATES_OK);
154 }
155
156 public boolean isBudgetUpdateAllowed(Integer universityFiscalYear)
157 {
158 return getActiveIndByPrimaryId(universityFiscalYear, KFSConstants.BudgetConstructionConstants.BUDGET_CONSTRUCTION_UPDATES_OK);
159 }
160
161 /**
162 *
163 * Gets the value of the businessObjectService attribute.
164 * @return An instance of the businessObjectService attribute.
165 */
166 public BusinessObjectService getBusinessObjectService() {
167 return businessObjectService;
168 }
169
170 /**
171 *
172 * Sets the businessObjectService attribute.
173 * @param businessObjectService The businessObjectService instance to set.
174 */
175 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
176 this.businessObjectService = businessObjectService;
177 }
178 }