001/* 002 * Copyright 2007-2009 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 */ 016package org.kuali.ole.module.purap.document.validation.impl; 017 018import org.kuali.ole.module.purap.PurapConstants; 019import org.kuali.ole.module.purap.PurapParameterConstants; 020import org.kuali.ole.module.purap.businessobject.PurchaseOrderTransmissionMethod; 021import org.kuali.ole.module.purap.document.PurchaseOrderDocument; 022import org.kuali.ole.module.purap.document.RequisitionDocument; 023import org.kuali.ole.sys.OLEKeyConstants; 024import org.kuali.ole.sys.context.SpringContext; 025import org.kuali.rice.coreservice.framework.parameter.ParameterService; 026import org.kuali.rice.kns.document.MaintenanceDocument; 027import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase; 028import org.kuali.rice.kns.service.DataDictionaryService; 029 030import java.util.ArrayList; 031import java.util.Collection; 032 033/* 034 * 035*/ 036public class PurchaseOrderTransmissionMethodRule extends MaintenanceDocumentRuleBase { 037 038 protected boolean processCustomApproveDocumentBusinessRules(MaintenanceDocument document) { 039 LOG.info("processCustomApproveDocumentBusinessRules called"); 040 this.setupConvenienceObjects(); 041 boolean success = this.checkForSystemParametersExistence(); 042 return success && super.processCustomApproveDocumentBusinessRules(document); 043 } 044 045 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) { 046 LOG.info("processCustomRouteDocumentBusinessRules called"); 047 this.setupConvenienceObjects(); 048 boolean success = this.checkForSystemParametersExistence(); 049 return success && super.processCustomRouteDocumentBusinessRules(document); 050 } 051 052 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) { 053 LOG.info("processCustomSaveDocumentBusinessRules called"); 054 this.setupConvenienceObjects(); 055 boolean success = this.checkForSystemParametersExistence(); 056 return success && super.processCustomSaveDocumentBusinessRules(document); 057 } 058 059 protected boolean checkForSystemParametersExistence() { 060 LOG.info("checkForSystemParametersExistence called"); 061 boolean success = true; 062 Collection<String> defaultParameterValues = new ArrayList<String>(SpringContext.getBean(ParameterService.class).getParameterValuesAsString(RequisitionDocument.class, PurapParameterConstants.PURAP_DEFAULT_PO_TRANSMISSION_CODE)); 063 Collection<String> retransmitParameterValues = new ArrayList<String>(SpringContext.getBean(ParameterService.class).getParameterValuesAsString(PurchaseOrderDocument.class, PurapParameterConstants.PURAP_PO_RETRANSMIT_TRANSMISSION_METHOD_TYPES)); 064 PurchaseOrderTransmissionMethod newBo = (PurchaseOrderTransmissionMethod) getNewBo(); 065 PurchaseOrderTransmissionMethod oldBo = (PurchaseOrderTransmissionMethod) getOldBo(); 066 067 if ((defaultParameterValues.contains(newBo.getPurchaseOrderTransmissionMethodCode()) || retransmitParameterValues.contains(newBo.getPurchaseOrderTransmissionMethodCode())) && !newBo.isActive() && oldBo.isActive()) { 068 success = false; 069 String documentLabel = SpringContext.getBean(DataDictionaryService.class).getDocumentLabelByTypeName(PurapConstants.PURCHASE_ORDER_TRANSMISSION_METHOD); 070 putGlobalError(OLEKeyConstants.ERROR_CANNOT_INACTIVATE_USED_IN_SYSTEM_PARAMETERS, documentLabel); 071 } 072 return success; 073 } 074}