1 package org.kuali.ole.describe.rule;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.describe.bo.OleReproductionPolicy;
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 OleReproductionPolicyRule extends MaintenanceDocumentRuleBase {
16
17
18 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
19 boolean isValid = true;
20 OleReproductionPolicy oleReproductionPolicy = (OleReproductionPolicy) document.getNewMaintainableObject().getDataObject();
21 isValid &= validateReproductionPolicyCode(oleReproductionPolicy);
22 return isValid;
23 }
24
25
26
27
28
29
30
31 private boolean validateReproductionPolicyCode(OleReproductionPolicy oleReproductionPolicy) {
32
33 if (oleReproductionPolicy.getReproductionPolicyCode() != null) {
34 Map<String, String> criteria = new HashMap<String, String>();
35 criteria.put(OLEConstants.OleReproductionPolicy.REPRODUCTION_POLICY_CD, oleReproductionPolicy.getReproductionPolicyCode());
36 List<OleReproductionPolicy> reproductionPolicyCodeInDatabase = (List<OleReproductionPolicy>) getBoService().findMatching(OleReproductionPolicy.class, criteria);
37 if ((reproductionPolicyCodeInDatabase.size() > 0)) {
38 for (OleReproductionPolicy reproductionPolicyObj : reproductionPolicyCodeInDatabase) {
39 Integer reproductionPolicyId = reproductionPolicyObj.getReproductionPolicyId();
40 if (null == oleReproductionPolicy.getReproductionPolicyId() || (reproductionPolicyId.intValue() != oleReproductionPolicy.getReproductionPolicyId().intValue())) {
41 this.putFieldError(OLEConstants.OleReproductionPolicy.REPRODUCTION_POLICY_CODE, "error.duplicate.code");
42 return false;
43 }
44 }
45 }
46 }
47 return true;
48 }
49 }