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.PurchaseOrderTransmissionMethod;
022 import org.kuali.kfs.module.purap.document.PurchaseOrderDocument;
023 import org.kuali.kfs.module.purap.document.RequisitionDocument;
024 import org.kuali.kfs.sys.KFSKeyConstants;
025 import org.kuali.kfs.sys.context.SpringContext;
026 import org.kuali.rice.kns.document.MaintenanceDocument;
027 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
028 import org.kuali.rice.kns.service.DataDictionaryService;
029 import org.kuali.rice.kns.service.ParameterService;
030
031 /*
032 *
033 */
034 public class PurchaseOrderTransmissionMethodRule extends MaintenanceDocumentRuleBase {
035
036 protected boolean processCustomApproveDocumentBusinessRules(MaintenanceDocument document) {
037 LOG.info("processCustomApproveDocumentBusinessRules called");
038 this.setupConvenienceObjects();
039 boolean success = this.checkForSystemParametersExistence();
040 return success && super.processCustomApproveDocumentBusinessRules(document);
041 }
042
043 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
044 LOG.info("processCustomRouteDocumentBusinessRules called");
045 this.setupConvenienceObjects();
046 boolean success = this.checkForSystemParametersExistence();
047 return success && super.processCustomRouteDocumentBusinessRules(document);
048 }
049
050 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
051 LOG.info("processCustomSaveDocumentBusinessRules called");
052 this.setupConvenienceObjects();
053 boolean success = this.checkForSystemParametersExistence();
054 return success && super.processCustomSaveDocumentBusinessRules(document);
055 }
056
057 protected boolean checkForSystemParametersExistence() {
058 LOG.info("checkForSystemParametersExistence called");
059 boolean success = true;
060 List<String> defaultParameterValues = SpringContext.getBean(ParameterService.class).getParameterValues(RequisitionDocument.class, PurapParameterConstants.PURAP_DEFAULT_PO_TRANSMISSION_CODE);
061 List<String> retransmitParameterValues = SpringContext.getBean(ParameterService.class).getParameterValues(PurchaseOrderDocument.class, PurapParameterConstants.PURAP_PO_RETRANSMIT_TRANSMISSION_METHOD_TYPES);
062 PurchaseOrderTransmissionMethod newBo = (PurchaseOrderTransmissionMethod)getNewBo();
063 PurchaseOrderTransmissionMethod oldBo= (PurchaseOrderTransmissionMethod)getOldBo();
064
065 if ((defaultParameterValues.contains(newBo.getPurchaseOrderTransmissionMethodCode()) || retransmitParameterValues.contains(newBo.getPurchaseOrderTransmissionMethodCode())) && ! newBo.isActive() && oldBo.isActive()) {
066 success = false;
067 String documentLabel = SpringContext.getBean(DataDictionaryService.class).getDocumentLabelByClass(newBo.getClass());
068 putGlobalError(KFSKeyConstants.ERROR_CANNOT_INACTIVATE_USED_IN_SYSTEM_PARAMETERS, documentLabel);
069 }
070 return success;
071 }
072 }