View Javadoc

1   package org.kuali.ole.catalog.rule;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.catalog.bo.OleFieldEncodingLevel;
5   import org.kuali.rice.krad.maintenance.MaintenanceDocument;
6   import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
7   
8   import java.util.HashMap;
9   import java.util.List;
10  import java.util.Map;
11  
12  /**
13   * OleFieldEncodingLevelRule validates maintenance object for Field Encoding Level Maintenance Document
14   */
15  public class OleFieldEncodingLevelRule extends MaintenanceDocumentRuleBase {
16  
17      @Override
18      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
19          boolean isValid = true;
20          OleFieldEncodingLevel oleFieldEncodingLevel = (OleFieldEncodingLevel) document.getNewMaintainableObject().getDataObject();
21  
22          isValid &= validateFieldEncodingLevelCode(oleFieldEncodingLevel);
23          return isValid;
24      }
25  
26      /**
27       * This method  validates duplicate fieldEncodingLevel Id and return boolean value.
28       * @param oleFieldEncodingLevel
29       * @return  boolean
30       */
31      private boolean validateFieldEncodingLevelCode(OleFieldEncodingLevel oleFieldEncodingLevel) {
32  
33          if (oleFieldEncodingLevel.getFieldEncodingLevelCode() != null) {
34  
35              Map<String, String> criteria = new HashMap<String, String>();
36              criteria.put(OLEConstants.OleFieldEncodingLevel.FIELD_ENCODING_LEVEL_CD, oleFieldEncodingLevel.getFieldEncodingLevelCode());
37  
38  
39              List<OleFieldEncodingLevel> fieldEncodingLevelInDatabase = (List<OleFieldEncodingLevel>) getBoService().findMatching(OleFieldEncodingLevel.class, criteria);
40  
41              if ((fieldEncodingLevelInDatabase.size() > 0)) {
42                  for(OleFieldEncodingLevel oleFieldEncodingLevelObj:fieldEncodingLevelInDatabase){
43                          Integer fieldEncodingLevelId=oleFieldEncodingLevelObj.getFieldEncodingLevelId();
44                          if(null==oleFieldEncodingLevel.getFieldEncodingLevelId() ||oleFieldEncodingLevel.getFieldEncodingLevelId().intValue()!=fieldEncodingLevelId){
45                              this.putFieldError(OLEConstants.OleFieldEncodingLevel.FIELD_ENCODING_LEVEL_CODE, "error.duplicate.code");
46                              return false;
47                          }
48                  }
49              }
50          }
51  
52          return true;
53      }
54  }