001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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.module.financial.rules;
017:
018: import java.util.Map;
019:
020: import org.kuali.core.authorization.AuthorizationConstants;
021: import org.kuali.core.bo.user.UniversalUser;
022: import org.kuali.core.document.Document;
023: import org.kuali.core.rules.PreRulesContinuationBase;
024: import org.kuali.core.service.DataDictionaryService;
025: import org.kuali.core.service.DocumentAuthorizationService;
026: import org.kuali.core.service.KualiConfigurationService;
027: import org.kuali.core.util.GlobalVariables;
028: import org.kuali.kfs.KFSConstants;
029: import org.kuali.kfs.KFSKeyConstants;
030: import org.kuali.kfs.context.SpringContext;
031: import org.kuali.kfs.web.struts.form.KualiAccountingDocumentFormBase;
032: import org.kuali.module.financial.document.BudgetAdjustmentDocument;
033: import org.kuali.module.financial.document.authorization.BudgetAdjustmentDocumentAuthorizer;
034: import org.kuali.module.financial.service.BudgetAdjustmentLaborBenefitsService;
035:
036: /**
037: * Checks warnings and prompt conditions for ba document.
038: */
039: public class BudgetAdjustmentDocumentPreRules extends
040: PreRulesContinuationBase {
041: private KualiConfigurationService kualiConfiguration;
042:
043: /**
044: * Execute pre-rules for BudgetAdjustmentDocument
045: *
046: * @document document with pre-rules being applied
047: * @return true if pre-rules fire without problem
048: * @see org.kuali.core.rules.PreRulesContinuationBase#doRules(org.kuali.core.document.MaintenanceDocument)
049: */
050: public boolean doRules(Document document) {
051: boolean preRulesOK = true;
052:
053: BudgetAdjustmentDocument budgetDocument = (BudgetAdjustmentDocument) document;
054: preRulesOK = askLaborBenefitsGeneration(budgetDocument);
055:
056: return preRulesOK;
057: }
058:
059: /**
060: * Calls service to determine if any labor object codes are present on the ba document. If so, asks the user if they want the
061: * system to automatically generate the benefit lines. If Yes, calls service to generate the accounting lines.
062: *
063: * @param budgetDocument submitted budget document
064: * @return true if labor benefits generation question is NOT asked
065: */
066: private boolean askLaborBenefitsGeneration(
067: BudgetAdjustmentDocument budgetDocument) {
068: // before prompting, check the document contains one or more labor object codes
069: boolean hasLaborObjectCodes = SpringContext.getBean(
070: BudgetAdjustmentLaborBenefitsService.class)
071: .hasLaborObjectCodes(budgetDocument);
072:
073: // and check that the user can edit the document
074: String documentTypeName = SpringContext.getBean(
075: DataDictionaryService.class)
076: .getDocumentTypeNameByClass(
077: BudgetAdjustmentDocument.class);
078: BudgetAdjustmentDocumentAuthorizer budgetAdjustmentDocumentAuthorizer = (BudgetAdjustmentDocumentAuthorizer) SpringContext
079: .getBean(DocumentAuthorizationService.class)
080: .getDocumentAuthorizer(documentTypeName);
081: UniversalUser universalUser = GlobalVariables.getUserSession()
082: .getUniversalUser();
083: Map map = budgetAdjustmentDocumentAuthorizer.getEditMode(
084: budgetDocument, universalUser, budgetDocument
085: .getSourceAccountingLines(), budgetDocument
086: .getTargetAccountingLines());
087:
088: if (map.containsKey(AuthorizationConstants.EditMode.FULL_ENTRY)
089: && hasLaborObjectCodes) {
090: String questionText = SpringContext
091: .getBean(KualiConfigurationService.class)
092: .getPropertyString(
093: KFSKeyConstants.QUESTION_GENERATE_LABOR_BENEFIT_LINES);
094: boolean generateBenefits = super
095: .askOrAnalyzeYesNoQuestion(
096: KFSConstants.BudgetAdjustmentDocumentConstants.GENERATE_BENEFITS_QUESTION_ID,
097: questionText);
098: if (generateBenefits) {
099: SpringContext.getBean(
100: BudgetAdjustmentLaborBenefitsService.class)
101: .generateLaborBenefitsAccountingLines(
102: budgetDocument);
103: // update baselines in form
104: ((KualiAccountingDocumentFormBase) form)
105: .setBaselineSourceAccountingLines(budgetDocument
106: .getSourceAccountingLines());
107: ((KualiAccountingDocumentFormBase) form)
108: .setBaselineTargetAccountingLines(budgetDocument
109: .getTargetAccountingLines());
110:
111: // return to document after lines are generated
112: super .event
113: .setActionForwardName(KFSConstants.MAPPING_BASIC);
114: return false;
115: }
116: }
117:
118: return true;
119: }
120:
121: }
|