View Javadoc
1   /*
2    * Copyright 2007-2009 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.module.purap.document.validation.impl;
17  
18  import org.kuali.ole.module.purap.PurapConstants;
19  import org.kuali.ole.module.purap.PurapParameterConstants;
20  import org.kuali.ole.module.purap.businessobject.PurchaseOrderTransmissionMethod;
21  import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
22  import org.kuali.ole.module.purap.document.RequisitionDocument;
23  import org.kuali.ole.sys.OLEKeyConstants;
24  import org.kuali.ole.sys.context.SpringContext;
25  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
26  import org.kuali.rice.kns.document.MaintenanceDocument;
27  import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
28  import org.kuali.rice.kns.service.DataDictionaryService;
29  
30  import java.util.ArrayList;
31  import java.util.Collection;
32  
33  /* 
34   * 
35  */
36  public class PurchaseOrderTransmissionMethodRule extends MaintenanceDocumentRuleBase {
37  
38      protected boolean processCustomApproveDocumentBusinessRules(MaintenanceDocument document) {
39          LOG.info("processCustomApproveDocumentBusinessRules called");
40          this.setupConvenienceObjects();
41          boolean success = this.checkForSystemParametersExistence();
42          return success && super.processCustomApproveDocumentBusinessRules(document);
43      }
44  
45      protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
46          LOG.info("processCustomRouteDocumentBusinessRules called");
47          this.setupConvenienceObjects();
48          boolean success = this.checkForSystemParametersExistence();
49          return success && super.processCustomRouteDocumentBusinessRules(document);
50      }
51  
52      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
53          LOG.info("processCustomSaveDocumentBusinessRules called");
54          this.setupConvenienceObjects();
55          boolean success = this.checkForSystemParametersExistence();
56          return success && super.processCustomSaveDocumentBusinessRules(document);
57      }
58  
59      protected boolean checkForSystemParametersExistence() {
60          LOG.info("checkForSystemParametersExistence called");
61          boolean success = true;
62          Collection<String> defaultParameterValues = new ArrayList<String>(SpringContext.getBean(ParameterService.class).getParameterValuesAsString(RequisitionDocument.class, PurapParameterConstants.PURAP_DEFAULT_PO_TRANSMISSION_CODE));
63          Collection<String> retransmitParameterValues = new ArrayList<String>(SpringContext.getBean(ParameterService.class).getParameterValuesAsString(PurchaseOrderDocument.class, PurapParameterConstants.PURAP_PO_RETRANSMIT_TRANSMISSION_METHOD_TYPES));
64          PurchaseOrderTransmissionMethod newBo = (PurchaseOrderTransmissionMethod) getNewBo();
65          PurchaseOrderTransmissionMethod oldBo = (PurchaseOrderTransmissionMethod) getOldBo();
66  
67          if ((defaultParameterValues.contains(newBo.getPurchaseOrderTransmissionMethodCode()) || retransmitParameterValues.contains(newBo.getPurchaseOrderTransmissionMethodCode())) && !newBo.isActive() && oldBo.isActive()) {
68              success = false;
69              String documentLabel = SpringContext.getBean(DataDictionaryService.class).getDocumentLabelByTypeName(PurapConstants.PURCHASE_ORDER_TRANSMISSION_METHOD);
70              putGlobalError(OLEKeyConstants.ERROR_CANNOT_INACTIVATE_USED_IN_SYSTEM_PARAMETERS, documentLabel);
71          }
72          return success;
73      }
74  }