1 package org.kuali.ole.catalog.rule;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.catalog.bo.OleShelvingOrder;
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 OleShelvingOrderRule extends MaintenanceDocumentRuleBase {
20
21 @Override
22 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
23 boolean isValid = true;
24 OleShelvingOrder oleShelvingOrder = (OleShelvingOrder) document.getNewMaintainableObject().getDataObject();
25
26 isValid &= validateShelvingOrderCode(oleShelvingOrder);
27 return isValid;
28 }
29
30
31
32
33
34
35 private boolean validateShelvingOrderCode(OleShelvingOrder oleShelvingOrder) {
36
37 if (oleShelvingOrder.getShelvingOrderCode() != null) {
38 Map<String, String> criteria = new HashMap<String, String>();
39 criteria.put(OLEConstants.OleShelvingOrder.SHELVING_ORDER_CD, oleShelvingOrder.getShelvingOrderCode());
40 List<OleShelvingOrder> shelvingOrderCodeInDatabase = (List<OleShelvingOrder>) getBoService().findMatching(OleShelvingOrder.class, criteria);
41 if ((shelvingOrderCodeInDatabase.size() > 0)) {
42 for (OleShelvingOrder shelvingOrderObj : shelvingOrderCodeInDatabase) {
43 Integer shelvingOrderId = shelvingOrderObj.getShelvingOrderId();
44 if (null == oleShelvingOrder.getShelvingOrderId() || (oleShelvingOrder.getShelvingOrderId().intValue() != shelvingOrderId.intValue())) {
45 this.putFieldError(OLEConstants.OleShelvingOrder.SHELVING_ORDER_CODE, "error.duplicate.code");
46 return false;
47 }
48 }
49 }
50 }
51 return true;
52 }
53 }