1 package org.kuali.ole.describe.rule;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.describe.bo.OleStatisticalSearchingCodes;
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 OleStatisticalSearchingCodesRule extends MaintenanceDocumentRuleBase {
16
17 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
18 boolean isValid = true;
19 OleStatisticalSearchingCodes oleStatisticalSearchingCodes = (OleStatisticalSearchingCodes) document.getNewMaintainableObject().getDataObject();
20
21 isValid &= validateStatisticalSearchingCode(oleStatisticalSearchingCodes);
22 return isValid;
23 }
24
25
26
27
28
29
30
31 private boolean validateStatisticalSearchingCode(OleStatisticalSearchingCodes oleStatisticalSearchingCodes) {
32
33 if (oleStatisticalSearchingCodes.getStatisticalSearchingCode() != null) {
34
35 Map<String, String> criteria = new HashMap<String, String>();
36
37 criteria.put(OLEConstants.OleStatisticalSearchingCodes.STATISTICAL_SEARCHING_CD, oleStatisticalSearchingCodes.getStatisticalSearchingCode());
38
39 List<OleStatisticalSearchingCodes> statisticalSearchingCodeInDatabase = (List<OleStatisticalSearchingCodes>) getBoService().findMatching(OleStatisticalSearchingCodes.class, criteria);
40
41 if ((statisticalSearchingCodeInDatabase.size() > 0)) {
42
43 for (OleStatisticalSearchingCodes oleStatisticalSearchingCodesObj : statisticalSearchingCodeInDatabase) {
44 Integer statisticalSearchingCodeId = oleStatisticalSearchingCodesObj.getStatisticalSearchingCodeId();
45 if (null == oleStatisticalSearchingCodes.getStatisticalSearchingCodeId() ||
46 statisticalSearchingCodeId.intValue() != oleStatisticalSearchingCodes.getStatisticalSearchingCodeId().intValue()) {
47 this.putFieldError(OLEConstants.OleStatisticalSearchingCodes.STATISTICAL_SEARCHING_CODE, "error.duplicate.code");
48 return false;
49 }
50 }
51
52 }
53 return true;
54 }
55 return false;
56 }
57 }