1 package org.kuali.ole.docstore.common.document;
2
3
4 import org.kuali.ole.docstore.common.document.content.enums.DocCategory;
5 import org.kuali.ole.docstore.common.document.content.enums.DocFormat;
6 import org.kuali.ole.docstore.common.document.content.enums.DocType;
7 import org.kuali.ole.docstore.common.document.content.instance.*;
8 import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
9 import org.kuali.ole.docstore.common.document.factory.JAXBContextFactory;
10 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory;
12
13 import javax.xml.bind.Marshaller;
14 import javax.xml.bind.Unmarshaller;
15 import javax.xml.bind.annotation.XmlAccessType;
16 import javax.xml.bind.annotation.XmlAccessorType;
17 import javax.xml.bind.annotation.XmlRootElement;
18 import javax.xml.bind.annotation.XmlType;
19 import javax.xml.transform.stream.StreamSource;
20 import java.io.ByteArrayInputStream;
21 import java.io.StringWriter;
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 @XmlAccessorType(XmlAccessType.FIELD)
42 @XmlType(name = "eHoldings", propOrder = {
43 "accessStatus"
44 })
45
46 @XmlRootElement(name = "holdingsDoc")
47 public class EHoldings
48 extends Holdings {
49 public static final Logger LOG = LoggerFactory.getLogger(EHoldings.class);
50 public static final String DESTINATION_FIELD_LINK_TEXT = "Link Text";
51 public static final String DESTINATION_FIELD_LINK_URL = "URL";
52 public static final String DESTINATION_FIELD_PERSISTENTLINK = "Persistent Link";
53 public static final String DESTINATION_FIELD_PUBLIC_DISPLAY_NOTE = "Public Display Note";
54 public static final String DESTINATION_FIELD_COVERAGE_START_DATE = "Coverage Start Date";
55 public static final String DESTINATION_FIELD_COVERAGE_START_ISSUE = "Coverage Start Issue";
56 public static final String DESTINATION_FIELD_COVERAGE_START_VOLUME = "Coverage Start Volume";
57 public static final String DESTINATION_FIELD_COVERAGE_END_DATE = "Coverage End Date";
58 public static final String DESTINATION_FIELD_COVERAGE_END_ISSUE = "Coverage End Issue";
59 public static final String DESTINATION_FIELD_COVERAGE_END_VOLUME = "Coverage End Volume";
60 public static final String DESTINATION_FIELD_STATISTICAL_CODE = "Statistical Code";
61 public static final String DESTINATION_FIELD_ACCESS_STATUS_CODE = "Access Status";
62 public static final String PUBLIC="public";
63 public static final String ACTIVE="active";
64 public static final String INACTIVE="inActive";
65 public static final String ELECTRONIC="electronic";
66
67 public static final String ACCESS_STATUS = "ACCESSSTATUS";
68 public static final String URL = "URL";
69 public static final String PERSISTENT_LINK = "PERSISTENTLINK";
70 public static final String LINK_TEXT = "LINKTEXT";
71 public static final String PUBLIC_DISPLAY_NOTE = "PUBLICDISPLAYNOTE";
72 public static final String COVERAGE_START_DATE = "COVERAGESTARTDATE";
73 public static final String COVERAGE_END_DATE = "COVERAGEENDDATE";
74 public static final String STATISTICAL_CODE = "STATISTICALCODE";
75 public static final String PLATFORM = "PLATFORM";
76
77 protected String accessStatus;
78
79
80 public EHoldings() {
81 holdingsType = ELECTRONIC;
82 category = DocCategory.WORK.getCode();
83 type = DocType.EHOLDINGS.getCode();
84 format = DocFormat.OLEML.getCode();
85 }
86
87
88
89
90
91
92
93 public String getAccessStatus() {
94 return accessStatus;
95 }
96
97
98
99
100
101
102
103 public void setAccessStatus(String value) {
104 this.accessStatus = value;
105 }
106
107
108 @Override
109 public String serialize(Object object) {
110 String result = null;
111 EHoldings holdings = (EHoldings) object;
112 try {
113 StringWriter sw = new StringWriter();
114 Marshaller jaxbMarshaller = JAXBContextFactory.getInstance().getMarshaller(EHoldings.class);
115 synchronized (jaxbMarshaller) {
116 jaxbMarshaller.marshal(holdings, sw);
117 }
118 result = sw.toString();
119 } catch (Exception e) {
120 LOG.error("Exception ", e);
121 }
122 return result;
123 }
124
125 @Override
126 public Object deserialize(String content) {
127 EHoldings holdings = new EHoldings();
128 try {
129 Unmarshaller unmarshaller = JAXBContextFactory.getInstance().getUnMarshaller(EHoldings.class);
130 ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes("UTF-8"));
131 synchronized (unmarshaller) {
132 holdings = unmarshaller.unmarshal(new StreamSource(input), EHoldings.class).getValue();
133 }
134 } catch (Exception e) {
135 LOG.error("Exception ", e);
136 }
137 return holdings;
138 }
139
140
141 @Override
142 public Object deserializeContent(Object object) {
143 return null;
144 }
145
146 public void serializeContent() {
147
148 if (contentObject == null) {
149 contentObject = getContentObject();
150 }
151 OleHoldings oleHoldings = (OleHoldings) contentObject;
152 Location locationPojo = buildLocationObj();
153 oleHoldings.setLocation(locationPojo);
154 HoldingOlemlRecordProcessor recordProcessor = new HoldingOlemlRecordProcessor();
155 content = recordProcessor.toXML(oleHoldings);
156 }
157
158 public void setField(String docField, String fieldValue) {
159 OleHoldings oleHoldings = getContentObject();
160 buildItemCallNumber(oleHoldings);
161 buildExtentOfOwnerShipAndNoteAndLink(oleHoldings);
162
163 if (docField.equalsIgnoreCase(DESTINATION_FIELD_CALL_NUMBER)) {
164 oleHoldings.getCallNumber().setNumber(fieldValue);
165 oleHoldings.getCallNumber().getShelvingScheme().setCodeValue("NONE");
166 } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_HOLDING_CALL_NUMBER_TYPE)) {
167 oleHoldings.getCallNumber().getShelvingScheme().setCodeValue(fieldValue);
168 } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_CALL_NUMBER_TYPE_PREFIX)) {
169 oleHoldings.getCallNumber().setPrefix(fieldValue);
170 } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_LOCATION_LEVEL_1)) {
171 setLocationLevel1(fieldValue);
172 } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_LOCATION_LEVEL_2)) {
173 setLocationLevel2(fieldValue);
174 } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_LOCATION_LEVEL_3)) {
175 setLocationLevel3(fieldValue);
176 } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_LOCATION_LEVEL_4)) {
177 setLocationLevel4(fieldValue);
178 } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_LOCATION_LEVEL_5)) {
179 setLocationLevel5(fieldValue);
180 } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_LINK_TEXT)) {
181 oleHoldings.getLink().get(0).setText(fieldValue);
182 } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_LINK_URL)) {
183 oleHoldings.getLink().get(0).setUrl(fieldValue);
184 } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_PERSISTENTLINK)) {
185 oleHoldings.setLocalPersistentLink(fieldValue);
186 } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_COVERAGE_START_DATE)) {
187 oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().get(0).setCoverageStartDate(fieldValue);
188 } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_COVERAGE_START_VOLUME)) {
189 oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().get(0).setCoverageStartVolume(fieldValue);
190 } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_COVERAGE_START_ISSUE)) {
191 oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().get(0).setCoverageStartIssue(fieldValue);
192 } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_COVERAGE_END_DATE)) {
193 oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().get(0).setCoverageEndDate(fieldValue);
194 } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_COVERAGE_END_ISSUE)) {
195 oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().get(0).setCoverageEndIssue(fieldValue);
196 } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_COVERAGE_END_VOLUME)) {
197 oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().get(0).setCoverageEndVolume(fieldValue);
198 } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_STATISTICAL_CODE)) {
199 oleHoldings.getStatisticalSearchingCode().setCodeValue(fieldValue);
200 oleHoldings.getStatisticalSearchingCode().setFullValue(fieldValue);
201 } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_PUBLIC_DISPLAY_NOTE)) {
202 oleHoldings.getNote().get(0).setValue(fieldValue);
203 oleHoldings.getNote().get(0).setType(PUBLIC);
204 } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_ACCESS_STATUS_CODE)) {
205 if(fieldValue.toLowerCase().equals(ACTIVE)) {
206 oleHoldings.setAccessStatus(ACTIVE);
207 }
208 else if(fieldValue.equalsIgnoreCase(INACTIVE)) {
209 oleHoldings.setAccessStatus(INACTIVE);
210 }
211 } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_COPY_NUMBER)) {
212 oleHoldings.setCopyNumber(fieldValue);
213 } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_PLATFORM)) {
214 Platform platform = new Platform();
215 platform.setPlatformName(fieldValue);
216 oleHoldings.setPlatform(platform);
217 } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_DONOR_CODE) || docField.equalsIgnoreCase(DESTINATION_FIELD_DONOR_PUBLIC_DISPLAY) || docField.equalsIgnoreCase(DESTINATION_FIELD_DONOR_NOTE)) {
218 DonorInfo donorInfo = null;
219 if (oleHoldings.getDonorInfo().size() > 0) {
220 for (DonorInfo existingDonorInfo : oleHoldings.getDonorInfo()) {
221 buildDonorInfo(docField, fieldValue, oleHoldings, existingDonorInfo, false);
222 }
223 } else {
224 donorInfo = new DonorInfo();
225 buildDonorInfo(docField, fieldValue, oleHoldings, donorInfo, false);
226 }
227 }
228 }
229
230 private void buildDonorInfo(String docField, String fieldValue, OleHoldings oleHoldings, DonorInfo donorInfo, boolean isDefault) {
231 if (docField.equalsIgnoreCase(DESTINATION_FIELD_DONOR_CODE)) {
232 if (donorInfo.getDonorCode() == null) {
233 donorInfo.setDonorCode(fieldValue);
234 } else if (!isDefault) {
235 donorInfo.setDonorCode(fieldValue);
236 }
237 } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_DONOR_PUBLIC_DISPLAY)) {
238 if (donorInfo.getDonorPublicDisplay() == null) {
239 donorInfo.setDonorPublicDisplay(fieldValue);
240 } else if (!isDefault) {
241 donorInfo.setDonorPublicDisplay(fieldValue);
242 }
243 } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_DONOR_NOTE)) {
244 if (donorInfo.getDonorNote() == null) {
245 donorInfo.setDonorNote(fieldValue);
246 } else if (!isDefault) {
247 donorInfo.setDonorNote(fieldValue);
248 }
249 }
250 if (oleHoldings.getDonorInfo() == null || oleHoldings.getDonorInfo().size() == 0) {
251 oleHoldings.getDonorInfo().add(donorInfo);
252 }
253 }
254
255 private void buildExtentOfOwnerShipAndNoteAndLink(OleHoldings oleHoldings) {
256 if (oleHoldings.getExtentOfOwnership().size() == 0) {
257 ExtentOfOwnership extentOfOwnership = new ExtentOfOwnership();
258 Coverages coverages = new Coverages();
259 Coverage coverage = new Coverage();
260 coverages.getCoverage().add(coverage);
261 extentOfOwnership.setCoverages(coverages);
262 oleHoldings.getExtentOfOwnership().add(extentOfOwnership);
263 }
264 if (oleHoldings.getNote().size() == 0) {
265 Note note = new Note();
266 oleHoldings.getNote().add(note);
267 }
268 if (oleHoldings.getStatisticalSearchingCode() == null) {
269 StatisticalSearchingCode statisticalSearchingCode = new StatisticalSearchingCode();
270 oleHoldings.setStatisticalSearchingCode(statisticalSearchingCode);
271 }
272
273 if(oleHoldings.getLink().size() == 0) {
274 oleHoldings.getLink().add(new Link());
275 }
276 }
277 }