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.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          
65          
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  }