1 package org.kuali.ole.describe.rule;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.OLEParameterConstants;
5 import org.kuali.ole.describe.bo.InstanceEditorFormDataHandler;
6 import org.kuali.ole.describe.bo.OleItemAvailableStatus;
7 import org.kuali.rice.core.api.config.property.ConfigContext;
8 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
9 import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
10
11 import java.util.HashMap;
12 import java.util.List;
13 import java.util.Map;
14
15
16
17
18 public class OleItemAvailableStatusRule extends MaintenanceDocumentRuleBase {
19
20 private InstanceEditorFormDataHandler instanceEditorFormDataHandler;
21
22
23
24
25
26
27 private InstanceEditorFormDataHandler getInstanceEditorFormDataHandler() {
28 if (null == instanceEditorFormDataHandler) {
29 instanceEditorFormDataHandler = new InstanceEditorFormDataHandler();
30 }
31 return instanceEditorFormDataHandler;
32 }
33
34 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
35 boolean isValid = true;
36 OleItemAvailableStatus oleItemAvailableStatus = (OleItemAvailableStatus) document.getNewMaintainableObject().getDataObject();
37
38 isValid &= validateItemAvailableStatusCode(oleItemAvailableStatus);
39 return isValid;
40 }
41
42
43
44
45
46
47
48 private boolean validateItemAvailableStatusCode(OleItemAvailableStatus oleItemAvailableStatus) {
49
50 String itemProperty = getInstanceEditorFormDataHandler()
51 .getParameter(OLEConstants.DESC_NMSPC, OLEConstants.DESCRIBE_COMPONENT, OLEParameterConstants.ITEM_STATUS_READONLY);
52 String[] itemArray = itemProperty.split(",");
53 for (String ItemStatus : itemArray) {
54 if (!(oleItemAvailableStatus.isActive())) {
55 if (ItemStatus.equalsIgnoreCase(oleItemAvailableStatus.getItemAvailableStatusCode())) {
56 this.putFieldError(OLEConstants.OleItemAvailableStatus.ITEM_ACTIVE_INDICATOR, "error.activeIndicator.false");
57 }
58 }
59 }
60 if (oleItemAvailableStatus.getItemAvailableStatusCode() != null) {
61
62 Map<String, String> criteria = new HashMap<String, String>();
63
64 criteria.put(OLEConstants.OleItemAvailableStatus.ITEM_AVAILABLE_STATUS_CD, oleItemAvailableStatus.getItemAvailableStatusCode());
65
66 List<OleItemAvailableStatus> itemAvailableStatusCodeInDatabase = (List<OleItemAvailableStatus>) getBoService().findMatching(OleItemAvailableStatus.class, criteria);
67
68 if ((itemAvailableStatusCodeInDatabase.size() > 0)) {
69 for (OleItemAvailableStatus oleItemAvailableStatusObj : itemAvailableStatusCodeInDatabase) {
70 String itemAvailableStatusId = oleItemAvailableStatusObj.getItemAvailableStatusId();
71
72 if (null == oleItemAvailableStatus.getItemAvailableStatusId() ||
73 !itemAvailableStatusId.equalsIgnoreCase(oleItemAvailableStatus.getItemAvailableStatusId())) {
74 this.putFieldError(OLEConstants.OleItemAvailableStatus.ITEM_AVAILABLE_STATUS_CODE, "error.duplicate.code");
75 return false;
76 }
77 }
78 }
79 }
80
81 return true;
82 }
83 }