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.List;
19: import java.util.Map;
20:
21: import org.kuali.core.authorization.AuthorizationConstants;
22: import org.kuali.core.bo.user.UniversalUser;
23: import org.kuali.core.document.Document;
24: import org.kuali.core.document.authorization.DocumentActionFlags;
25: import org.kuali.core.document.authorization.TransactionalDocumentActionFlags;
26: import org.kuali.core.exceptions.InactiveDocumentTypeAuthorizationException;
27: import org.kuali.core.workflow.service.KualiWorkflowDocument;
28: import org.kuali.kfs.context.SpringContext;
29: import org.kuali.kfs.document.authorization.AccountingDocumentAuthorizerBase;
30: import org.kuali.module.financial.document.BudgetAdjustmentDocument;
31: import org.kuali.module.financial.service.FiscalYearFunctionControlService;
32:
33: /**
34: * Document Authorizer for the Budget Adjustment document.
35: */
36: public class BudgetAdjustmentDocumentAuthorizer extends
37: AccountingDocumentAuthorizerBase {
38:
39: /**
40: * Overrides to call super and then blanketly reset the actions not allowed on the procurment card document.
41: *
42: * @see org.kuali.core.authorization.DocumentAuthorizer#getDocumentActionFlags(org.kuali.core.document.Document,
43: * org.kuali.core.bo.user.KualiUser)
44: */
45: public DocumentActionFlags getDocumentActionFlags(
46: Document document, UniversalUser user) {
47: TransactionalDocumentActionFlags flags = new TransactionalDocumentActionFlags(
48: super .getDocumentActionFlags(document, user));
49:
50: return flags;
51: }
52:
53: /**
54: * Check if base amount can be edited for the posting year, if so export base amount entry mode.
55: *
56: * @see org.kuali.core.authorization.DocumentAuthorizer#getEditMode(org.kuali.core.document.Document,
57: * org.kuali.core.bo.user.KualiUser)
58: */
59: public Map getEditMode(Document document, UniversalUser user,
60: List sourceLines, List targetLines) {
61: KualiWorkflowDocument workflowDocument = document
62: .getDocumentHeader().getWorkflowDocument();
63:
64: Map editModeMap = super .getEditMode(document, user,
65: sourceLines, targetLines);
66: if (SpringContext.getBean(
67: FiscalYearFunctionControlService.class)
68: .isBaseAmountChangeAllowed(
69: ((BudgetAdjustmentDocument) document)
70: .getPostingYear())) {
71: editModeMap
72: .put(
73: AuthorizationConstants.BudgetAdjustmentEditMode.BASE_AMT_ENTRY,
74: "TRUE");
75: }
76:
77: return editModeMap;
78: }
79:
80: /**
81: * Checks whether the BA document is active and allowed for any fiscal years.
82: *
83: * @see org.kuali.core.authorization.DocumentAuthorizer#canInitiate(java.lang.String, org.kuali.core.bo.user.KualiUser)
84: */
85: @Override
86: public void canInitiate(String documentTypeName, UniversalUser user) {
87: List allowedYears = SpringContext.getBean(
88: FiscalYearFunctionControlService.class)
89: .getBudgetAdjustmentAllowedYears();
90:
91: // if no allowed years found, BA document is not allowed to be initiated
92: if (allowedYears == null || allowedYears.isEmpty()) {
93: throw new InactiveDocumentTypeAuthorizationException(
94: "initiate", "BudgetAdjustmentDocument");
95: }
96:
97: super.canInitiate(documentTypeName, user);
98: }
99: }
|