1 package org.kuali.ole.catalog.rule;
2
3
4 import org.kuali.ole.OLEConstants;
5 import org.kuali.ole.catalog.bo.OleAccessMethod;
6 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
7 import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
8
9 import java.util.HashMap;
10 import java.util.List;
11 import java.util.Map;
12
13
14
15
16 public class OleAccessMethodsRule extends MaintenanceDocumentRuleBase {
17
18
19
20
21
22
23 @Override
24 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
25 boolean isValid = true;
26 OleAccessMethod accessMethod = (OleAccessMethod) document.getNewMaintainableObject().getDataObject();
27 isValid &= validateAccessMethodCode(accessMethod);
28 return isValid;
29 }
30
31
32
33
34
35
36 private boolean validateAccessMethodCode(OleAccessMethod accessMethod) {
37 if (accessMethod.getAccessMethodCode() != null) {
38 Map<String, String> criteria = new HashMap<String, String>();
39 criteria.put(OLEConstants.OleAccessMethod.ACCESS_METHOD_CD, accessMethod.getAccessMethodCode());
40 List<OleAccessMethod> accessMethodInDatabase = (List<OleAccessMethod>) getBoService().findMatching(OleAccessMethod.class, criteria);
41 if ((accessMethodInDatabase.size() > 0)) {
42 for (OleAccessMethod accessMethodObj : accessMethodInDatabase) {
43 Integer accessMethodId = accessMethodObj.getAccessMethodId();
44 if (null == accessMethod.getAccessMethodId() || (accessMethod.getAccessMethodId().intValue() != accessMethodId.intValue())) {
45 this.putFieldError(OLEConstants.OleAccessMethod.ACCESS_METHOD_CODE, "error.duplicate.code");
46 return false;
47 }
48 }
49 }
50 }
51 return true;
52 }
53 }
54