1 package org.kuali.ole.describe.rule;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.describe.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
14
15 public class OlePrivacyRule extends MaintenanceDocumentRuleBase {
16
17
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
28
29
30
31
32 private boolean validatePrivacyCode(OlePrivacy olePrivacy) {
33
34 if (olePrivacy.getPrivacyCode() != null) {
35
36 Map<String, String> criteria = new HashMap<String, String>();
37
38 criteria.put(OLEConstants.OlePrivacy.PRIVACY_CD, olePrivacy.getPrivacyCode());
39
40 List<OlePrivacy> privacyCodeInDatabase = (List<OlePrivacy>) getBoService().findMatching(OlePrivacy.class, criteria);
41
42 if ((privacyCodeInDatabase.size() > 0)) {
43
44 for (OlePrivacy privacyCodeObj : privacyCodeInDatabase) {
45 String privacyId = privacyCodeObj.getPrivacyId();
46 if (null == olePrivacy.getPrivacyId() ||
47 !(olePrivacy.getPrivacyId().equalsIgnoreCase(privacyId))) {
48 this.putFieldError(OLEConstants.OlePrivacy.PRIVACY_CODE, "error.duplicate.code");
49 return false;
50 }
51 }
52 }
53 return true;
54 }
55 return false;
56 }
57 }