1 package org.kuali.ole.location.rule;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.location.bo.OleLocation;
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 public class OleLocationRule extends MaintenanceDocumentRuleBase{
17
18 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
19 boolean isValid = true;
20 OleLocation oleLocation = (OleLocation) document.getNewMaintainableObject().getDataObject();
21 isValid &= validateLocationCode(oleLocation);
22 return isValid;
23 }
24
25
26
27
28
29
30 private boolean validateLocationCode(OleLocation oleLocation) {
31 if (oleLocation.getLocationCode() != null) {
32 Map<String, String> criteria = new HashMap<String, String>();
33 criteria.put(OLEConstants.LOC_CD, oleLocation.getLocationCode());
34 List<OleLocation> oleLocationInDatabase = (List<OleLocation>) getBoService().findMatching(OleLocation.class, criteria);
35 if ((oleLocationInDatabase.size() > 0)) {
36 for (OleLocation oleLocationObj : oleLocationInDatabase) {
37 String locationId =oleLocationObj.getLocationId();
38 if (null == oleLocation.getLocationId() || (oleLocation.getLocationId() != locationId)) {
39 this.putFieldError(OLEConstants.LOC_CODE, "error.duplicate.code");
40 return false;
41 }
42 }
43 }
44 }
45 return true;
46 }
47 }