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.PurapParameterConstants;
19  import org.kuali.ole.module.purap.businessobject.PurchaseOrderVendorChoice;
20  import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
21  import org.kuali.ole.sys.OLEKeyConstants;
22  import org.kuali.ole.sys.context.SpringContext;
23  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
24  import org.kuali.rice.kns.document.MaintenanceDocument;
25  import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
26  import org.kuali.rice.kns.service.DataDictionaryService;
27  
28  import java.util.ArrayList;
29  import java.util.Collection;
30  
31  /* 
32   * 
33  */
34  public class PurchaseOrderVendorChoiceRule extends MaintenanceDocumentRuleBase {
35  
36      protected boolean processCustomApproveDocumentBusinessRules(MaintenanceDocument document) {
37          LOG.info("processCustomApproveDocumentBusinessRules called");
38          this.setupConvenienceObjects();
39          boolean success = this.checkForSystemParametersExistence();
40          return success && super.processCustomApproveDocumentBusinessRules(document);
41      }
42  
43      protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
44          LOG.info("processCustomRouteDocumentBusinessRules called");
45          this.setupConvenienceObjects();
46          boolean success = this.checkForSystemParametersExistence();
47          return success && super.processCustomRouteDocumentBusinessRules(document);
48      }
49  
50      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
51          LOG.info("processCustomSaveDocumentBusinessRules called");
52          this.setupConvenienceObjects();
53          boolean success = this.checkForSystemParametersExistence();
54          return success && super.processCustomSaveDocumentBusinessRules(document);
55      }
56  
57      protected boolean checkForSystemParametersExistence() {
58          LOG.info("checkForSystemParametersExistence called");
59          boolean success = true;
60          Collection<String> apoParameterValues = new ArrayList<String>(SpringContext.getBean(ParameterService.class).getParameterValuesAsString(PurchaseOrderDocument.class, PurapParameterConstants.DEFAULT_APO_VENDOR_CHOICE));
61          Collection<String> b2bParameterValues = new ArrayList<String>(SpringContext.getBean(ParameterService.class).getParameterValuesAsString(PurchaseOrderDocument.class, PurapParameterConstants.DEFAULT_B2B_VENDOR_CHOICE));
62          PurchaseOrderVendorChoice newVendorChoice = (PurchaseOrderVendorChoice) getNewBo();
63          PurchaseOrderVendorChoice oldVendorChoice = (PurchaseOrderVendorChoice) getOldBo();
64          //If the new funding source code matches with the funding source in the DEFAULT_FUNDING_SOURCE 
65          //system parameters then we can't inactivate this funding source, so return false.
66          if ((apoParameterValues.contains(newVendorChoice.getPurchaseOrderVendorChoiceCode()) || b2bParameterValues.contains(newVendorChoice.getPurchaseOrderVendorChoiceCode())) && !newVendorChoice.isActive() && oldVendorChoice.isActive()) {
67              success = false;
68              String documentLabel = SpringContext.getBean(DataDictionaryService.class).getDocumentLabelByClass(newVendorChoice.getClass());
69              putGlobalError(OLEKeyConstants.ERROR_CANNOT_INACTIVATE_USED_IN_SYSTEM_PARAMETERS, documentLabel);
70          }
71          return success;
72      }
73  }