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.module.bc.document.validation.impl;
017
018 import org.kuali.kfs.module.bc.BCKeyConstants;
019 import org.kuali.kfs.module.bc.businessobject.BudgetConstructionAppointmentFundingReasonCode;
020 import org.kuali.kfs.module.bc.document.service.SalarySettingService;
021 import org.kuali.kfs.sys.KFSKeyConstants;
022 import org.kuali.kfs.sys.context.SpringContext;
023 import org.kuali.rice.kns.document.MaintenanceDocument;
024 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
025
026 /**
027 * Business rules for BudgetConstructionAppointmentFundingReasonCode maintenance document.
028 */
029 public class BudgetConstructionAppointmentFundingReasonCodeRule extends MaintenanceDocumentRuleBase {
030 protected static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BudgetConstructionAppointmentFundingReasonCodeRule.class);
031
032 protected BudgetConstructionAppointmentFundingReasonCode oldBudgetConstructionAppointmentFundingReasonCode;
033 protected BudgetConstructionAppointmentFundingReasonCode newBudgetConstructionAppointmentFundingReasonCode;
034
035 protected SalarySettingService salarySettingService;
036
037 public BudgetConstructionAppointmentFundingReasonCodeRule() {
038
039 this.setSalarySettingService(SpringContext.getBean(SalarySettingService.class));
040 }
041
042 /**
043 * @see org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase#processCustomRouteDocumentBusinessRules(org.kuali.rice.kns.document.MaintenanceDocument)
044 */
045 @Override
046 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
047 LOG.info("processCustomRouteDocumentBusinessRules called");
048
049 boolean success = true;
050
051 // checks when editing existing code
052 if (document.isEdit()) {
053 success &= checkInactivateReason(document);
054 }
055
056 return success;
057 }
058
059 protected boolean checkInactivateReason(MaintenanceDocument document){
060 LOG.info("checkInactivateReason called");
061
062 boolean success = true;
063
064 // just return when not being inactivated
065 if (!(oldBudgetConstructionAppointmentFundingReasonCode.isActive() && !newBudgetConstructionAppointmentFundingReasonCode.isActive())) {
066 return true;
067 }
068
069 // disallow inactivation if appointment funding reasons exist using this editable code
070 if (salarySettingService.hasExistingFundingReason(newBudgetConstructionAppointmentFundingReasonCode)){
071 putGlobalError(BCKeyConstants.ERROR_BUDGET_REASONMAINT_INACTIVATE_REASONEXIST);
072 success &= false;
073 }
074
075 return success;
076 }
077
078 /**
079 * @see org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase#setupConvenienceObjects()
080 */
081 @Override
082 public void setupConvenienceObjects() {
083
084 oldBudgetConstructionAppointmentFundingReasonCode = (BudgetConstructionAppointmentFundingReasonCode) super.getOldBo();
085 newBudgetConstructionAppointmentFundingReasonCode = (BudgetConstructionAppointmentFundingReasonCode) super.getNewBo();
086 }
087
088 /**
089 * Sets the salarySettingService attribute value.
090 * @param salarySettingService The salarySettingService to set.
091 */
092 public void setSalarySettingService(SalarySettingService salarySettingService) {
093 this.salarySettingService = salarySettingService;
094 }
095 }