1 package org.kuali.ole.describe.bo;
2
3 import org.kuali.ole.describe.bo.OleShelvingOrder;
4 import org.kuali.rice.krad.service.BusinessObjectService;
5 import org.kuali.rice.krad.service.KRADServiceLocator;
6
7 import java.util.*;
8
9
10
11
12
13
14
15
16 public class SourceEditorForUI {
17
18 private String leader;
19 private List<MarcEditorControlField> controlFields = new ArrayList<MarcEditorControlField>();
20 private List<MarcEditorDataField> dataFields = new ArrayList<MarcEditorDataField>();
21 private String uuid;
22 private String locationName;
23 private SourceHoldingsCallNumber sourceHoldingsCallNumber;
24 private String primary;
25
26 public String getUuid() {
27 return uuid;
28 }
29
30 public void setUuid(String uuid) {
31 this.uuid = uuid;
32 }
33
34 public SourceEditorForUI() {
35 controlFields.add(new MarcEditorControlField());
36 dataFields.add(new MarcEditorDataField());
37 }
38
39 public String getLeader() {
40 return leader;
41 }
42
43 public void setLeader(String leader) {
44 this.leader = leader;
45 }
46
47 public List<MarcEditorControlField> getControlFields() {
48 return controlFields;
49 }
50
51 public void setControlFields(List<MarcEditorControlField> controlFields) {
52 this.controlFields = controlFields;
53 }
54
55 public List<MarcEditorDataField> getDataFields() {
56 return dataFields;
57 }
58
59 public void setDataFields(List<MarcEditorDataField> dataFields) {
60 this.dataFields = dataFields;
61 }
62
63 public String getLocationName() {
64
65 String marcEditorDataTag;
66 String marcEditorDataFieldValue;
67 String locationValue = "";
68 if (dataFields != null && dataFields.get(0).getTag() != null) {
69 for (int i = 0; i < dataFields.size(); i++) {
70 marcEditorDataTag = dataFields.get(i).getTag();
71 if (marcEditorDataTag.equalsIgnoreCase("852")) {
72 marcEditorDataFieldValue = dataFields.get(i).getValue();
73 StringTokenizer str = new StringTokenizer(marcEditorDataFieldValue, "|");
74 while (str.hasMoreTokens()) {
75 String dataFieldTokenizedVal = str.nextToken();
76 String code = Character.toString(dataFieldTokenizedVal.charAt(0));
77 if (code.equals("a") || code.equals("b") || code.equals("c")) {
78 String value = dataFieldTokenizedVal.substring(1, dataFieldTokenizedVal.length());
79 if (locationValue.equalsIgnoreCase("")) {
80 locationValue = value;
81 } else {
82 locationValue = locationValue + "-" + value;
83 }
84 }
85 }
86 locationName = locationValue;
87 }
88 }
89 }
90 return locationName;
91 }
92
93 public void setLocationName(String locationName) {
94 this.locationName = locationName;
95 }
96
97 public SourceHoldingsCallNumber getSourceHoldingsCallNumber() {
98 String marcEditorDataTag;
99 String marcEditorDataFieldValue;
100 String code = null;
101 String dataFieldTokenizedVal = null;
102 SourceHoldingsCallNumber sourceHoldingsCallNumber1 = new SourceHoldingsCallNumber();
103
104 if (dataFields != null && dataFields.get(0).getTag() != null) {
105 sourceHoldingsCallNumber1.setNumber(buildSubFieldValue("852", "h"));
106 sourceHoldingsCallNumber1.setPrefix(buildSubFieldValue("852", "k"));
107 if (getDataFieldValue("852") != null) {
108 sourceHoldingsCallNumber1.setShelvingScheme(getDataFieldValue("852").getInd1());
109
110 String ind2 = getDataFieldValue("852").getInd2();
111 BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
112 Map parentCriteria = new HashMap();
113 parentCriteria.put("shelvingOrderCode", ind2);
114 OleShelvingOrder oleShelvingOrder = businessObjectService.findByPrimaryKey(OleShelvingOrder.class, parentCriteria);
115 String shelvingOrder = oleShelvingOrder.getShelvingOrderName();
116
117 sourceHoldingsCallNumber1.setShelvingOrder(shelvingOrder);
118 }
119 }
120
121 return sourceHoldingsCallNumber1;
122 }
123
124 public void setSourceHoldingsCallNumber(SourceHoldingsCallNumber sourceHoldingsCallNumber) {
125 this.sourceHoldingsCallNumber = sourceHoldingsCallNumber;
126 }
127
128 private String buildSubFieldValue(String tag, String subField) {
129 String subFieldValue = "";
130 MarcEditorDataField marcEditorDataField = getDataFieldValue(tag);
131 if (marcEditorDataField != null) {
132 StringTokenizer str = new StringTokenizer(marcEditorDataField.getValue(), "|");
133 while (str.hasMoreTokens()) {
134 String dataFieldTokenizedVal = str.nextToken();
135 String code = Character.toString(dataFieldTokenizedVal.charAt(0));
136 if (code.equals(subField)) {
137 subFieldValue = dataFieldTokenizedVal.substring(1, dataFieldTokenizedVal.length());
138 }
139 }
140 }
141 return subFieldValue;
142 }
143
144 private MarcEditorDataField getDataFieldValue(String tag) {
145 String value = "";
146 MarcEditorDataField marcEditorDataField = null;
147 for (int i = 0; i < dataFields.size(); i++) {
148 String tag1 = dataFields.get(i).getTag();
149 if (tag1.equalsIgnoreCase(tag)) {
150 marcEditorDataField = dataFields.get(i);
151 }
152 }
153 return marcEditorDataField;
154 }
155
156 public String getPrimary() {
157 return primary;
158 }
159
160 public void setPrimary(String primary) {
161 if (primary == null) {
162 primary = "false";
163 }
164 this.primary = primary;
165 }
166 }