View Javadoc

1   /*
2    * Copyright 2006 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.PurchaseOrderContractLanguage;
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   * Business rule(s) applicable to Purchase Order Contract Language maintenance document.
30   */
31  public class PurchaseOrderContractLanguageRule extends MaintenanceDocumentRuleBase {
32  
33      protected PurchaseOrderContractLanguage newContractLanguage;
34      protected PurchaseOrderContractLanguage oldContractLanguage;
35      protected BusinessObjectService boService;
36  
37      /**
38       * @see org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase#setupConvenienceObjects()
39       */
40      @Override
41      public void setupConvenienceObjects() {
42          oldContractLanguage = (PurchaseOrderContractLanguage) super.getOldBo();
43          // setup newDelegateChange convenience objects, make sure all possible sub-objects are populated
44          newContractLanguage = (PurchaseOrderContractLanguage) super.getNewBo();
45          boService = (BusinessObjectService) super.getBoService();
46          super.setupConvenienceObjects();
47      }
48  
49      /**
50       * @see org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase#processCustomApproveDocumentBusinessRules(org.kuali.rice.kns.document.MaintenanceDocument)
51       */
52      protected boolean processCustomApproveDocumentBusinessRules(MaintenanceDocument document) {
53          LOG.info("processCustomApproveDocumentBusinessRules called");
54          this.setupConvenienceObjects();
55          boolean success = this.checkForDuplicate();
56          return success && super.processCustomApproveDocumentBusinessRules(document);
57      }
58  
59      /**
60       * @see org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase#processCustomRouteDocumentBusinessRules(org.kuali.rice.kns.document.MaintenanceDocument)
61       */
62      protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
63          LOG.info("processCustomRouteDocumentBusinessRules called");
64          this.setupConvenienceObjects();
65          boolean success = this.checkForDuplicate();
66          return success && super.processCustomRouteDocumentBusinessRules(document);
67      }
68  
69      /**
70       * @see org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase#processCustomSaveDocumentBusinessRules(org.kuali.rice.kns.document.MaintenanceDocument)
71       */
72      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
73          LOG.info("processCustomSaveDocumentBusinessRules called");
74          this.setupConvenienceObjects();
75          boolean success = this.checkForDuplicate();
76          return success && super.processCustomSaveDocumentBusinessRules(document);
77      }
78  
79      /**
80       * Check to see if data duplicates existing data
81       *
82       * @return boolean indicating if validation succeeded
83       */
84      protected boolean checkForDuplicate() {
85          LOG.info("checkForDuplicate called");
86          boolean success = true;
87          Map fieldValues = new HashMap();
88  
89          if (oldContractLanguage.getPurchaseOrderContractLanguageIdentifier() != null &&
90                  newContractLanguage.getPurchaseOrderContractLanguageIdentifier() != null &&
91                  StringUtils.equalsIgnoreCase(newContractLanguage.getCampusCode(), oldContractLanguage.getCampusCode()) &&
92                  newContractLanguage.getPurchaseOrderContractLanguageIdentifier().equals(oldContractLanguage.getPurchaseOrderContractLanguageIdentifier()) &&
93                  StringUtils.equalsIgnoreCase(newContractLanguage.getPurchaseOrderContractLanguageDescription(), oldContractLanguage.getPurchaseOrderContractLanguageDescription()) &&
94                  newContractLanguage.getContractLanguageCreateDate().equals(oldContractLanguage.getContractLanguageCreateDate())) {
95              success = true;
96          } else {
97              fieldValues.put("campusCode", newContractLanguage.getCampusCode());
98              fieldValues.put("purchaseOrderContractLanguageDescription", newContractLanguage.getPurchaseOrderContractLanguageDescription());
99              fieldValues.put("contractLanguageCreateDate", newContractLanguage.getContractLanguageCreateDate());
100             if (boService.countMatching(newContractLanguage.getClass(), fieldValues) != 0) {
101                 success &= false;
102                 putGlobalError(PurapKeyConstants.PURAP_GENERAL_POTENTIAL_DUPLICATE);
103             }
104         }
105         return success;
106     }
107 }