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.purap.document.validation.impl; 017 018 import java.util.List; 019 020 import org.kuali.kfs.module.purap.PurapParameterConstants; 021 import org.kuali.kfs.module.purap.businessobject.PurchaseOrderVendorChoice; 022 import org.kuali.kfs.module.purap.document.PurchaseOrderDocument; 023 import org.kuali.kfs.sys.KFSKeyConstants; 024 import org.kuali.kfs.sys.context.SpringContext; 025 import org.kuali.rice.kns.document.MaintenanceDocument; 026 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase; 027 import org.kuali.rice.kns.service.DataDictionaryService; 028 import org.kuali.rice.kns.service.ParameterService; 029 030 /* 031 * 032 */ 033 public class PurchaseOrderVendorChoiceRule extends MaintenanceDocumentRuleBase { 034 035 protected boolean processCustomApproveDocumentBusinessRules(MaintenanceDocument document) { 036 LOG.info("processCustomApproveDocumentBusinessRules called"); 037 this.setupConvenienceObjects(); 038 boolean success = this.checkForSystemParametersExistence(); 039 return success && super.processCustomApproveDocumentBusinessRules(document); 040 } 041 042 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) { 043 LOG.info("processCustomRouteDocumentBusinessRules called"); 044 this.setupConvenienceObjects(); 045 boolean success = this.checkForSystemParametersExistence(); 046 return success && super.processCustomRouteDocumentBusinessRules(document); 047 } 048 049 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) { 050 LOG.info("processCustomSaveDocumentBusinessRules called"); 051 this.setupConvenienceObjects(); 052 boolean success = this.checkForSystemParametersExistence(); 053 return success && super.processCustomSaveDocumentBusinessRules(document); 054 } 055 056 protected boolean checkForSystemParametersExistence() { 057 LOG.info("checkForSystemParametersExistence called"); 058 boolean success = true; 059 List<String> apoParameterValues = SpringContext.getBean(ParameterService.class).getParameterValues(PurchaseOrderDocument.class, PurapParameterConstants.DEFAULT_APO_VENDOR_CHOICE); 060 List<String> b2bParameterValues = SpringContext.getBean(ParameterService.class).getParameterValues(PurchaseOrderDocument.class, PurapParameterConstants.DEFAULT_B2B_VENDOR_CHOICE); 061 PurchaseOrderVendorChoice newVendorChoice = (PurchaseOrderVendorChoice)getNewBo(); 062 PurchaseOrderVendorChoice oldVendorChoice= (PurchaseOrderVendorChoice)getOldBo(); 063 //If the new funding source code matches with the funding source in the DEFAULT_FUNDING_SOURCE 064 //system parameters then we can't inactivate this funding source, so return false. 065 if ((apoParameterValues.contains(newVendorChoice.getPurchaseOrderVendorChoiceCode()) || b2bParameterValues.contains(newVendorChoice.getPurchaseOrderVendorChoiceCode())) && ! newVendorChoice.isActive() && oldVendorChoice.isActive()) { 066 success = false; 067 String documentLabel = SpringContext.getBean(DataDictionaryService.class).getDocumentLabelByClass(newVendorChoice.getClass()); 068 putGlobalError(KFSKeyConstants.ERROR_CANNOT_INACTIVATE_USED_IN_SYSTEM_PARAMETERS, documentLabel); 069 } 070 return success; 071 } 072 }