1 package org.kuali.ole.describe.rule;
2
3 import org.kuali.ole.describe.bo.OleLocationStatus;
4 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
5 import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
6
7 import java.util.HashMap;
8 import java.util.List;
9 import java.util.Map;
10
11
12
13
14 public class OleLocationStatusRule extends MaintenanceDocumentRuleBase {
15
16
17
18
19
20
21 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
22 boolean isValid = true;
23 OleLocationStatus oleLocationStatus = (OleLocationStatus) document.getNewMaintainableObject().getDataObject();
24
25 isValid &= validateLocationStatusCode(oleLocationStatus);
26 return isValid;
27 }
28
29
30
31
32
33
34
35 private boolean validateLocationStatusCode(OleLocationStatus oleLocationStatus) {
36
37 if (oleLocationStatus.getLocationStatusCode() != null) {
38
39 Map<String, String> criteria = new HashMap<String, String>();
40
41
42
43 List<OleLocationStatus> locationStatusCodeInDatabase = (List<OleLocationStatus>) getBoService().findMatching(OleLocationStatus.class, criteria);
44
45 if ((locationStatusCodeInDatabase.size() > 0)) {
46
47 for (OleLocationStatus locationStatusObj : locationStatusCodeInDatabase) {
48 String locationStatusId = locationStatusObj.getLocationStatusId();
49 if (null == oleLocationStatus.getLocationStatusId() ||
50 !(oleLocationStatus.getLocationStatusId().equalsIgnoreCase(locationStatusId))) {
51
52 return false;
53 }
54 }
55 }
56 return true;
57 }
58 return false;
59 }
60 }