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