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.fp.service.impl;
17  
18  import java.util.ArrayList;
19  import java.util.Collection;
20  import java.util.HashMap;
21  import java.util.Iterator;
22  import java.util.List;
23  
24  import org.kuali.ole.fp.businessobject.FiscalYearFunctionControl;
25  import org.kuali.ole.fp.service.FiscalYearFunctionControlService;
26  import org.kuali.ole.sys.OLEConstants;
27  import org.kuali.ole.sys.OLEPropertyConstants;
28  import org.kuali.rice.krad.service.BusinessObjectService;
29  
30  /**
31   * 
32   * This is the default implementation of the FiscalyearFunctionControlService interface.
33   * 
34   */
35  public class FiscalYearFunctionControlServiceImpl implements FiscalYearFunctionControlService {
36  
37      public static String FY_FUNCTION_CONTROL_BA_ALLOWED = "BAACTV";
38      public static String FY_FUNCTION_CONTROL_BASE_AMT_ALLOWED = "BASEAD";
39  
40      private BusinessObjectService businessObjectService;
41  
42      /**
43       * Retrieves the FiscalYearFunctionControl by its composite primary key (all passed in as parameters) and returns the active
44       * indicator.
45       * 
46       * @param postingYear The posting year associated with the fiscal year function control being retrieved.
47       * @param financialSystemFunctionControlCode The function control code associated with the fiscal year function control being retrieved.
48       * @return Returns the value of the active indicator; returns null if PK is not found
49       */
50      protected boolean getActiveIndByPrimaryId(Integer postingYear, String financialSystemFunctionControlCode) {
51          HashMap<String, Object> keys = new HashMap();
52          keys.put(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, postingYear);
53          keys.put(OLEPropertyConstants.FINANCIAL_SYSTEM_FUNCTION_CONTROL_CODE, financialSystemFunctionControlCode);
54          FiscalYearFunctionControl control = (FiscalYearFunctionControl) businessObjectService.findByPrimaryKey(FiscalYearFunctionControl.class, keys);
55          return (control != null) && control.isFinancialSystemFunctionActiveIndicator();
56      }
57  
58      /**
59       * Retrieves list of FiscalYearFunctionControls by its function control code.
60       * 
61       * @param financialSystemFunctionControlCode The function control code to search by.
62       * @param financialSystemFunctionActiveIndicator An active indicator used as a search parameter.
63       * @return The list of FiscalYearFunctionControls matching the search criteria provided.
64       */
65      protected List getByFunctionControlCodeAndActiveInd(String financialSystemFunctionControlCode, String financialSystemFunctionActiveIndicator) {
66          HashMap values = new HashMap();
67          values.put(OLEPropertyConstants.FINANCIAL_SYSTEM_FUNCTION_CONTROL_CODE, financialSystemFunctionControlCode);
68          values.put(OLEPropertyConstants.FINANCIAL_SYSTEM_FUNCTION_ACTIVE_INDICATOR, financialSystemFunctionActiveIndicator);
69          Collection controls = businessObjectService.findMatching(FiscalYearFunctionControl.class, values);
70          return new ArrayList(controls);
71      }
72  
73      /**
74       * Retrieves a collection of FiscalYearFunctionControls allowed for use in a budget adjustment.
75       * 
76       * @return A collection of FiscalYearFunctionControls representing the years allowed in a budget adjustment.
77       * 
78       * @see FiscalYearFunctionControlService#getBudgetAdjustmentAllowedYears(String)
79       */
80      public List getBudgetAdjustmentAllowedYears() {
81          return getByFunctionControlCodeAndActiveInd(FY_FUNCTION_CONTROL_BA_ALLOWED, "Y");
82      }
83  
84      /**
85       * This method retrieves the value of the active indicator for a FiscalYearFunctionControl instance for the 
86       * given posting year.
87       * 
88       * @param postingYear The posting year used as a search parameter.
89       * @return True if the active indicator for the retrieved FiscalYearFunctionControl value retrieved is true, false otherwise.
90       * 
91       * @see FiscalYearFunctionControlService#isBaseAmountChangeAllowed(Integer, String)
92       */
93      public boolean isBaseAmountChangeAllowed(Integer postingYear) {
94          return getActiveIndByPrimaryId(postingYear, FY_FUNCTION_CONTROL_BASE_AMT_ALLOWED);
95      }
96      /**
97       * 
98       * @see org.kuali.ole.fp.service.FiscalYearFunctionControlService#getActiveBudgetYear()
99       */
100     public List<Integer> getActiveBudgetYear()
101     {
102         ArrayList<FiscalYearFunctionControl> activeYearObjects = (ArrayList<FiscalYearFunctionControl>) getByFunctionControlCodeAndActiveInd(OLEConstants.BudgetConstructionConstants.BUDGET_CONSTRUCTION_ACTIVE,OLEConstants.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.ole.fp.service.FiscalYearFunctionControlService#isApplicationUpdateFromHumanResourcesAllowed(java.lang.Integer)
117      */
118     public boolean isApplicationUpdateFromHumanResourcesAllowed(Integer universityFiscalYear)
119     {
120         return getActiveIndByPrimaryId(universityFiscalYear, OLEConstants.BudgetConstructionConstants.BUDGET_ON_LINE_SYNCHRONIZATION_OK);
121     }
122   
123     /**
124      * 
125      * @see org.kuali.ole.fp.service.FiscalYearFunctionControlService#isBatchUpdateFromHumanResourcesAllowed(java.lang.Integer)
126      */
127     public boolean isBatchUpdateFromHumanResourcesAllowed(Integer universityFiscalYear)
128     {
129         return getActiveIndByPrimaryId(universityFiscalYear, OLEConstants.BudgetConstructionConstants.BUDGET_BATCH_SYNCHRONIZATION_OK);
130     }
131     
132     /**
133      * 
134      * @see org.kuali.ole.fp.service.FiscalYearFunctionControlService#isBatchUpdateFromPayrollAllowed(java.lang.Integer)
135      */
136     public boolean isBatchUpdateFromPayrollAllowed (Integer universityFiscalYear)
137     {
138         return getActiveIndByPrimaryId(universityFiscalYear, OLEConstants.BudgetConstructionConstants.CSF_UPDATES_OK);
139     }
140     
141 
142     public boolean isBudgetConstructionActive(Integer universityFiscalYear)
143     {
144         return getActiveIndByPrimaryId(universityFiscalYear, OLEConstants.BudgetConstructionConstants.BUDGET_CONSTRUCTION_ACTIVE);
145     }
146 
147     /**
148      * 
149      * @see org.kuali.ole.fp.service.FiscalYearFunctionControlService#isBudgetGeneralLedgerUpdateAllowed(java.lang.Integer)
150      */
151     public boolean isBudgetGeneralLedgerUpdateAllowed(Integer universityFiscalYear)
152     {
153         return getActiveIndByPrimaryId(universityFiscalYear, OLEConstants.BudgetConstructionConstants.BASE_BUDGET_UPDATES_OK);
154     }
155     
156     public boolean isBudgetUpdateAllowed(Integer universityFiscalYear)
157     {
158         return getActiveIndByPrimaryId(universityFiscalYear, OLEConstants.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 }