01: /*
02: * Copyright 2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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.module.financial.document.authorization;
17:
18: import java.util.Iterator;
19: import java.util.List;
20:
21: import org.kuali.core.bo.user.UniversalUser;
22: import org.kuali.core.exceptions.InactiveDocumentTypeAuthorizationException;
23: import org.kuali.kfs.context.SpringContext;
24: import org.kuali.module.financial.bo.FiscalYearFunctionControl;
25: import org.kuali.module.financial.service.FiscalYearFunctionControlService;
26: import org.kuali.module.financial.service.UniversityDateService;
27:
28: /**
29: * Document Authorizer for the Year End Budget Adjustment document.
30: */
31: public class YearEndBudgetAdjustmentDocumentAuthorizer extends
32: BudgetAdjustmentDocumentAuthorizer {
33:
34: /**
35: * Checks whether the BA document is active for the year end posting year.
36: *
37: * @see org.kuali.core.authorization.DocumentAuthorizer#canInitiate(java.lang.String, org.kuali.core.bo.user.KualiUser)
38: */
39: @Override
40: public void canInitiate(String documentTypeName, UniversalUser user) {
41: List allowedYears = SpringContext.getBean(
42: FiscalYearFunctionControlService.class)
43: .getBudgetAdjustmentAllowedYears();
44: Integer previousPostingYear = new Integer(SpringContext
45: .getBean(UniversityDateService.class)
46: .getCurrentFiscalYear().intValue() - 1);
47:
48: // if previous fiscal year not active, BA document is not allowed to be initiated
49: if (allowedYears == null || allowedYears.isEmpty()) {
50: throw new InactiveDocumentTypeAuthorizationException(
51: "initiate", "BudgetAdjustmentDocument");
52: }
53:
54: boolean previousActive = false;
55: for (Iterator iter = allowedYears.iterator(); iter.hasNext();) {
56: FiscalYearFunctionControl fyControl = (FiscalYearFunctionControl) iter
57: .next();
58: if (fyControl.getUniversityFiscalYear().equals(
59: previousPostingYear)) {
60: previousActive = true;
61: }
62: }
63:
64: if (!previousActive) {
65: throw new InactiveDocumentTypeAuthorizationException(
66: "initiate", "BudgetAdjustmentDocument");
67: }
68:
69: super.canInitiate(documentTypeName, user);
70: }
71: }
|