1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
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          
64          
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  }