View Javadoc
1   /*
2    * Copyright 2007-2008 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.FundingSource;
20  import org.kuali.ole.module.purap.document.RequisitionDocument;
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 FundingSourceRule 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> parameterValues = new ArrayList<String>(SpringContext.getBean(ParameterService.class).getParameterValuesAsString(RequisitionDocument.class, PurapParameterConstants.DEFAULT_FUNDING_SOURCE));
61          FundingSource newFundingSource = (FundingSource) getNewBo();
62          FundingSource oldFundingSource = (FundingSource) getOldBo();
63          //If the new funding source code matches with the funding source in the DEFAULT_FUNDING_SOURCE 
64          //system parameters then we can't inactivate this funding source, so return false.
65          if (parameterValues.contains(newFundingSource.getFundingSourceCode()) && !newFundingSource.isActive() && oldFundingSource.isActive()) {
66              success = false;
67              String documentLabel = SpringContext.getBean(DataDictionaryService.class).getDocumentLabelByClass(newFundingSource.getClass());
68              putGlobalError(OLEKeyConstants.ERROR_CANNOT_INACTIVATE_USED_IN_SYSTEM_PARAMETERS, documentLabel);
69          }
70          return success;
71      }
72  }