1 package org.kuali.ole.select.rule;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.select.bo.OLERequestPriority;
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
16
17
18
19 public class OLERequestPriorityRule extends MaintenanceDocumentRuleBase {
20
21
22 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
23 boolean isValid = true;
24 OLERequestPriority OLERequestPriority = (OLERequestPriority) document.getNewMaintainableObject().getDataObject();
25
26 isValid &= validateOleMaterialTypeCode(OLERequestPriority);
27 return isValid;
28 }
29
30
31 private boolean validateOleMaterialTypeCode(OLERequestPriority OLERequestPriority) {
32
33 if (OLERequestPriority.getOleRequestPriorityName() != null) {
34 Map<String, String> criteria = new HashMap<String, String>();
35 criteria.put(OLEConstants.OleRequestPriority.REQUEST_PRIORITY_NAME, OLERequestPriority.getOleRequestPriorityName());
36 List<OLERequestPriority> savedOLERequestPriority = (List<OLERequestPriority>) getBoService().findMatching(OLERequestPriority.class, criteria);
37 if ((savedOLERequestPriority.size() > 0)) {
38 for (OLERequestPriority requestPriority : savedOLERequestPriority) {
39 String requestPriorityId = requestPriority.getOleRequestPriorityId();
40 if (null == OLERequestPriority.getOleRequestPriorityId() || (!OLERequestPriority.getOleRequestPriorityId().equalsIgnoreCase(requestPriorityId))) {
41 this.putFieldError(OLEConstants.OleRequestPriority.REQUEST_PRIORITY_FIELD, OLEConstants.OleRequestPriority.ERROR_REQUEST_PRIORITY_NAME);
42 return false;
43 }
44 }
45 }
46 }
47 return true;
48 }
49 }