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          isValid &= validateStewardShipTypeName(document);
33          return isValid;
34          
35      }
36      
37      /**
38       * This method  validates duplicate  stewardShipTypeName and return boolean value.
39       * @param oleStewardship
40       * @return boolean
41       */
42      private boolean validateStewardShipTypeName(MaintenanceDocument document) {
43          OleStewardship oleStewardship = (OleStewardship) document.getNewMaintainableObject().getBusinessObject();
44          if (!document.isEdit() && oleStewardship.getStewardshipTypeName() != null) {
45              Map<String, String> criteria = new HashMap<String, String>();
46              criteria.put(OLEKeyConstants.STWRDSHIP_TYPE_NAME, oleStewardship.getStewardshipTypeName());
47              List<OleStewardship> oleStewardshipList = (List<OleStewardship>) getBoService().findMatching(OleStewardship.class, criteria);
48  
49              if ((oleStewardshipList.size() > 0)) {
50                  for(OleStewardship oleStewardshipObj:oleStewardshipList){
51                      String stewardShipTypeName=oleStewardshipObj.getStewardshipTypeName();
52                      if(null==oleStewardship.getStewardshipTypeName()|| oleStewardship.getStewardshipTypeName().equalsIgnoreCase(stewardShipTypeName)) {
53                          putFieldError(OLEKeyConstants.STWRDSHIP_TYPE_NAME, OLEKeyConstants.ERROR_DUP_FOUND_STWRD_TYP_NAME);
54                          return false;
55                      }
56                  }
57              }
58          }
59          return true;
60      }
61  
62  }