View Javadoc
1   /*
2    * Copyright 2007 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.apache.commons.lang.StringUtils;
19  import org.kuali.ole.module.purap.PurapKeyConstants;
20  import org.kuali.ole.module.purap.businessobject.PurchaseOrderQuoteLanguage;
21  import org.kuali.rice.kns.document.MaintenanceDocument;
22  import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
23  import org.kuali.rice.krad.service.BusinessObjectService;
24  
25  import java.util.HashMap;
26  import java.util.Map;
27  
28  /* 
29   * 
30  */
31  public class PurchaseOrderQuoteLanguageRule extends MaintenanceDocumentRuleBase {
32  
33      protected PurchaseOrderQuoteLanguage oldQuoteLanguage;
34      protected PurchaseOrderQuoteLanguage newQuoteLanguage;
35      protected BusinessObjectService boService;
36  
37      /**
38       * @see org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase#setupConvenienceObjects()
39       */
40      @Override
41      public void setupConvenienceObjects() {
42          oldQuoteLanguage = (PurchaseOrderQuoteLanguage) super.getOldBo();
43          // setup newDelegateChange convenience objects, make sure all possible sub-objects are populated
44          newQuoteLanguage = (PurchaseOrderQuoteLanguage) super.getNewBo();
45          boService = (BusinessObjectService) super.getBoService();
46          super.setupConvenienceObjects();
47      }
48  
49      protected boolean processCustomApproveDocumentBusinessRules(MaintenanceDocument document) {
50          LOG.info("processCustomApproveDocumentBusinessRules called");
51          this.setupConvenienceObjects();
52          boolean success = this.checkForDuplicate();
53          return success && super.processCustomApproveDocumentBusinessRules(document);
54      }
55  
56      protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
57          LOG.info("processCustomRouteDocumentBusinessRules called");
58          this.setupConvenienceObjects();
59          boolean success = this.checkForDuplicate();
60          return success && super.processCustomRouteDocumentBusinessRules(document);
61      }
62  
63      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
64          LOG.info("processCustomSaveDocumentBusinessRules called");
65          this.setupConvenienceObjects();
66          boolean success = this.checkForDuplicate();
67          return success && super.processCustomSaveDocumentBusinessRules(document);
68      }
69  
70      protected boolean checkForDuplicate() {
71          LOG.info("checkForDuplicate called");
72          boolean success = true;
73          Map fieldValues = new HashMap();
74  
75          fieldValues.put("purchaseOrderQuoteLanguageDescription", newQuoteLanguage.getPurchaseOrderQuoteLanguageDescription());
76          fieldValues.put("purchaseOrderQuoteLanguageCreateDate", newQuoteLanguage.getPurchaseOrderQuoteLanguageCreateDate());
77  
78          if (oldQuoteLanguage != null && newQuoteLanguage != null &&
79                  newQuoteLanguage.getPurchaseOrderQuoteLanguageIdentifier() != null && oldQuoteLanguage.getPurchaseOrderQuoteLanguageIdentifier() != null &&
80                  newQuoteLanguage.getPurchaseOrderQuoteLanguageCreateDate() != null && oldQuoteLanguage.getPurchaseOrderQuoteLanguageCreateDate() != null &&
81                  StringUtils.equalsIgnoreCase(newQuoteLanguage.getPurchaseOrderQuoteLanguageDescription(), oldQuoteLanguage.getPurchaseOrderQuoteLanguageDescription()) &&
82                  newQuoteLanguage.getPurchaseOrderQuoteLanguageIdentifier().equals(oldQuoteLanguage.getPurchaseOrderQuoteLanguageIdentifier()) &&
83                  newQuoteLanguage.getPurchaseOrderQuoteLanguageCreateDate().equals(oldQuoteLanguage.getPurchaseOrderQuoteLanguageCreateDate())) {
84              success = true;
85          } else if (boService.countMatching(newQuoteLanguage.getClass(), fieldValues) != 0) {
86              success &= false;
87              putGlobalError(PurapKeyConstants.PURAP_GENERAL_POTENTIAL_DUPLICATE);
88          }
89          return success;
90      }
91  }