View Javadoc

1   /*
2    * Copyright 2012 The Kuali Foundation.
3    * 
4    * Licensed under the Educational Community License, Version 1.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/ecl1.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.coa.document.validation.impl;
17  
18  import java.util.HashMap;
19  import java.util.List;
20  import java.util.Map;
21  
22  import org.kuali.ole.coa.businessobject.OleStewardship;
23  import org.kuali.ole.sys.OLEKeyConstants;
24  import org.kuali.rice.kns.document.MaintenanceDocument;
25  import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
26  
27  public class OleStewardShipRule extends MaintenanceDocumentRuleBase{
28      
29      @Override
30      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
31          boolean isValid = true;
32          OleStewardship oleStewardship = (OleStewardship) document.getNewMaintainableObject().getBusinessObject();
33  
34          isValid &= validateStewardShipTypeName(oleStewardship);
35          return isValid;
36          
37      }
38      
39      /**
40       * This method  validates duplicate  stewardShipTypeName and return boolean value.
41       * @param oleStewardship
42       * @return boolean
43       */
44      private boolean validateStewardShipTypeName(OleStewardship oleStewardship) {
45  
46          if (oleStewardship.getStewardshipTypeName() != null) {
47  
48              Map<String, String> criteria = new HashMap<String, String>();
49  
50              criteria.put(OLEKeyConstants.STWRDSHIP_TYPE_NAME, oleStewardship.getStewardshipTypeName());
51  
52  
53              List<OleStewardship> oleStewardshipInDatabase = (List<OleStewardship>) getBoService().findMatching(OleStewardship.class, criteria);
54  
55              if ((oleStewardshipInDatabase.size() > 0)) {
56                  for(OleStewardship oleStewardshipObj:oleStewardshipInDatabase){
57                      String stewardShipTypeName=oleStewardshipObj.getStewardshipTypeName();
58                      if(null==oleStewardship.getStewardshipTypeName()|| oleStewardship.getStewardshipTypeName().equalsIgnoreCase(stewardShipTypeName)) {
59                          putFieldError(OLEKeyConstants.STWRDSHIP_TYPE_NAME, OLEKeyConstants.ERROR_DUP_FOUND_STWRD_TYP_NAME);
60                          return false;
61                      }
62                  }
63              }
64          }
65  
66          return true;
67      }
68  
69  }