1 package org.kuali.ole.describe.rule;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.deliver.bo.OleCirculationDesk;
5 import org.kuali.ole.deliver.bo.OleCirculationDeskDetail;
6 import org.kuali.ole.describe.bo.OleDiscoveryExportMappingFields;
7 import org.kuali.ole.describe.bo.OleDiscoveryExportProfile;
8 import org.kuali.ole.describe.bo.OleLocation;
9 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
10 import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
11
12 import java.util.ArrayList;
13 import java.util.HashMap;
14 import java.util.List;
15 import java.util.Map;
16
17
18
19
20
21
22
23
24 public class OleDiscoveryExportProfileRule extends MaintenanceDocumentRuleBase {
25
26
27
28
29
30
31
32
33 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
34 boolean isValid = true;
35 OleDiscoveryExportProfile oleDiscoveryExportProfile = (OleDiscoveryExportProfile) document.getNewMaintainableObject().getDataObject();
36 isValid &= validateForDuplicateMARCField(oleDiscoveryExportProfile);
37 isValid &= validateForDuplicateItemField(oleDiscoveryExportProfile);
38 return isValid;
39 }
40
41
42
43
44
45
46
47 private boolean validateForDuplicateMARCField(OleDiscoveryExportProfile oleDiscoveryExportProfile) {
48 List<String> MARCItemlist = new ArrayList<String>();
49 if (oleDiscoveryExportProfile.getOleDiscoveryExportMappingFields() == null || oleDiscoveryExportProfile.getOleDiscoveryExportMappingFields().size() == 0) {
50 this.putFieldError(OLEConstants.OleDiscoveryExportProfile.OLE_EXP_ADD_ITEM, OLEConstants.OleDiscoveryExportProfile.OLE_EXP_ADD_ITEM_ERROR);
51 return false;
52 }
53 for (int i = 0; i < oleDiscoveryExportProfile.getOleDiscoveryExportMappingFields().size(); i++) {
54 MARCItemlist.add(oleDiscoveryExportProfile.getOleDiscoveryExportMappingFields().get(i).getMarcField());
55 }
56 for (int j = 0; j < oleDiscoveryExportProfile.getOleDiscoveryExportMappingFields().size(); j++) {
57 int count = 0;
58 for (int k = 0; k < MARCItemlist.size(); k++) {
59 if (oleDiscoveryExportProfile.getOleDiscoveryExportMappingFields().get(j).getMarcField().equalsIgnoreCase(MARCItemlist.get(k))) {
60 count++;
61 }
62 }
63 if (count > 1) {
64 this.putFieldError(OLEConstants.OleDiscoveryExportProfile.OLE_EXP_MARC_FIELD, OLEConstants.OleDiscoveryExportProfile.OLE_EXP_MARC_DUPLICATE_ERROR);
65 return false;
66 }
67 }
68 return true;
69 }
70
71
72
73
74
75
76
77 private boolean validateForDuplicateItemField(OleDiscoveryExportProfile oleDiscoveryExportProfile) {
78 List<String> MARCItemlist = new ArrayList<String>();
79 for (int i = 0; i < oleDiscoveryExportProfile.getOleDiscoveryExportMappingFields().size(); i++) {
80 MARCItemlist.add(oleDiscoveryExportProfile.getOleDiscoveryExportMappingFields().get(i).getItemField());
81 }
82 for (int j = 0; j < oleDiscoveryExportProfile.getOleDiscoveryExportMappingFields().size(); j++) {
83 int count = 0;
84 for (int k = 0; k < MARCItemlist.size(); k++) {
85 if (oleDiscoveryExportProfile.getOleDiscoveryExportMappingFields().get(j).getItemField().equalsIgnoreCase(MARCItemlist.get(k))) {
86 count++;
87 }
88 }
89 if (count > 1) {
90 this.putFieldError(OLEConstants.OleDiscoveryExportProfile.OLE_EXP_ITEM_FIELD, OLEConstants.OleDiscoveryExportProfile.OLE_EXP_ITEM_DUPLICATE_ERROR);
91 return false;
92 }
93 }
94 return true;
95 }
96 }
97
98