View Javadoc

1   package org.kuali.ole.catalog.rule;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.catalog.bo.OlePrivacy;
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   * OlePrivacyRule validates maintenance object for Privacy Maintenance Document
14   */
15  public class OlePrivacyRule extends MaintenanceDocumentRuleBase {
16  
17      @Override
18      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
19          boolean isValid = true;
20          OlePrivacy OlePrivacy = (OlePrivacy) document.getNewMaintainableObject().getDataObject();
21  
22          isValid &= validatePrivacyCode(OlePrivacy);
23          return isValid;
24      }
25  
26      /**
27       * This method  validates duplicate privacy Id and return boolean value.
28       * @param olePrivacy
29       * @return  boolean
30       */
31      private boolean validatePrivacyCode(OlePrivacy olePrivacy) {
32  
33          if (olePrivacy.getPrivacyCode() != null) {
34  
35              Map<String, String> criteria = new HashMap<String, String>();
36  
37              criteria.put(OLEConstants.OlePrivacy.PRIVACY_CD, olePrivacy.getPrivacyCode());
38  
39              List<OlePrivacy> privacyCodeInDatabase = (List<OlePrivacy>) getBoService().findMatching(OlePrivacy.class, criteria);
40  
41              if ((privacyCodeInDatabase.size() > 0)) {
42  
43                  for(OlePrivacy privacyCodeObj:privacyCodeInDatabase){
44                      String privacyId = privacyCodeObj.getPrivacyId();
45                      if(null == olePrivacy.getPrivacyId() ||
46                              !(olePrivacy.getPrivacyId().equalsIgnoreCase(privacyId))){
47                          this.putFieldError(OLEConstants.OlePrivacy.PRIVACY_CODE, "error.duplicate.code");
48                          return false;
49                      }
50                  }
51              }
52              return true;
53          }
54          return false;
55      }
56  }