View Javadoc
1   package org.kuali.ole.docstore.common.document;
2   
3   
4   import org.apache.commons.lang.StringUtils;
5   import org.kuali.ole.docstore.common.document.content.enums.DocCategory;
6   import org.kuali.ole.docstore.common.document.content.enums.DocFormat;
7   import org.kuali.ole.docstore.common.document.content.enums.DocType;
8   import org.kuali.ole.docstore.common.document.content.instance.*;
9   import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
10  import org.kuali.ole.docstore.common.document.factory.JAXBContextFactory;
11  import org.slf4j.Logger;
12  import org.slf4j.LoggerFactory;
13  
14  import javax.xml.bind.Marshaller;
15  import javax.xml.bind.Unmarshaller;
16  import javax.xml.bind.annotation.XmlAccessType;
17  import javax.xml.bind.annotation.XmlAccessorType;
18  import javax.xml.bind.annotation.XmlRootElement;
19  import javax.xml.bind.annotation.XmlType;
20  import javax.xml.transform.stream.StreamSource;
21  import java.io.ByteArrayInputStream;
22  import java.io.StringWriter;
23  import java.util.ArrayList;
24  import java.util.List;
25  
26  
27  /**
28   * <p>Java class for eHoldings complex type.
29   * <p/>
30   * <p>The following schema fragment specifies the expected content contained within this class.
31   * <p/>
32   * <pre>
33   * &lt;complexType name="eHoldings">
34   *   &lt;complexContent>
35   *     &lt;extension base="{}holdings">
36   *       &lt;sequence>
37   *         &lt;element name="accessStatus" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
38   *       &lt;/sequence>
39   *     &lt;/extension>
40   *   &lt;/complexContent>
41   * &lt;/complexType>
42   * </pre>
43   */
44  @XmlAccessorType(XmlAccessType.FIELD)
45  @XmlType(name = "eHoldings", propOrder = {
46          "accessStatus"
47  })
48  
49  @XmlRootElement(name = "holdingsDoc")
50  public class EHoldings
51          extends Holdings {
52      public static final Logger LOG = LoggerFactory.getLogger(EHoldings.class);
53      public static final String DESTINATION_FIELD_LINK_TEXT = "Link Text";
54      public static final String DESTINATION_FIELD_LINK_URL = "URL";
55      public static final String DESTINATION_FIELD_PERSISTENTLINK = "Persistent Link";
56      public static final String DESTINATION_FIELD_PUBLIC_DISPLAY_NOTE = "Public Display Note";
57      public static final String DESTINATION_FIELD_COVERAGE_START_DATE = "Coverage Start Date";
58      public static final String DESTINATION_FIELD_COVERAGE_START_ISSUE = "Coverage Start Issue";
59      public static final String DESTINATION_FIELD_COVERAGE_START_VOLUME = "Coverage Start Volume";
60      public static final String DESTINATION_FIELD_COVERAGE_END_DATE = "Coverage End Date";
61      public static final String DESTINATION_FIELD_COVERAGE_END_ISSUE = "Coverage End Issue";
62      public static final String DESTINATION_FIELD_COVERAGE_END_VOLUME = "Coverage End Volume";
63      public static final String DESTINATION_FIELD_STATISTICAL_CODE = "Statistical Code";
64      public static final String DESTINATION_FIELD_ACCESS_STATUS_CODE = "Access Status";
65      public static final String DESTINATION_FIELD_ERESOURCE_NAME = "EResource Name";
66      public static final String DESTINATION_FIELD_ERESOURCE_ID = "EResource Id";
67      public static final String DESTINATION_FIELD_GOKB_ID = "Gokb Id";
68      public static final String DESTINATION_FIELD_IMPRINT = "Imprint";
69      public static final String DESTINATION_FIELD_PUBLISHER = "Publisher";
70      public static final String PUBLIC="public";
71      public static final String ACTIVE="active";
72      public static final String INACTIVE="inActive";
73      public static final String ELECTRONIC="electronic";
74  
75      public static final String ACCESS_STATUS = "ACCESSSTATUS";
76      public static final String URL = "URL";
77      public static final String PERSISTENT_LINK = "PERSISTENTLINK";
78      public static final String LINK_TEXT = "LINKTEXT";
79      public static final String PUBLIC_DISPLAY_NOTE = "PUBLICDISPLAYNOTE";
80      public static final String COVERAGE_START_DATE = "COVERAGESTARTDATE";
81      public static final String COVERAGE_END_DATE = "COVERAGEENDDATE";
82      public static final String STATISTICAL_CODE = "STATISTICALCODE";
83      public static final String PLATFORM = "PLATFORM";
84  
85      protected String accessStatus;
86  
87  
88      public EHoldings() {
89          holdingsType = ELECTRONIC;
90          category = DocCategory.WORK.getCode();
91          type = DocType.EHOLDINGS.getCode();
92          format = DocFormat.OLEML.getCode();
93      }
94  
95      /**
96       * Gets the value of the accessStatus property.
97       *
98       * @return possible object is
99       *         {@link String }
100      */
101     public String getAccessStatus() {
102         return accessStatus;
103     }
104 
105     /**
106      * Sets the value of the accessStatus property.
107      *
108      * @param value allowed object is
109      *              {@link String }
110      */
111     public void setAccessStatus(String value) {
112         this.accessStatus = value;
113     }
114 
115     @Override
116     public String serialize(Object object) {
117         String result = null;
118         EHoldings holdings = (EHoldings) object;
119         try {
120             StringWriter sw = new StringWriter();
121             Marshaller jaxbMarshaller = JAXBContextFactory.getInstance().getMarshaller(EHoldings.class);
122             synchronized (jaxbMarshaller) {
123             jaxbMarshaller.marshal(holdings, sw);
124             }
125             result = sw.toString();
126         } catch (Exception e) {
127             LOG.error("Exception ", e);
128         }
129         return result;
130     }
131 
132     @Override
133     public Object deserialize(String content) {
134         EHoldings holdings = new EHoldings();
135         try {
136             Unmarshaller unmarshaller = JAXBContextFactory.getInstance().getUnMarshaller(EHoldings.class);
137             ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes("UTF-8"));
138             synchronized (unmarshaller) {
139                 holdings = unmarshaller.unmarshal(new StreamSource(input), EHoldings.class).getValue();
140             }
141         } catch (Exception e) {
142             LOG.error("Exception ", e);
143         }
144         return holdings;
145     }
146 
147 
148     @Override
149     public Object deserializeContent(Object object) {
150         return null;  //To change body of implemented methods use File | Settings | File Templates.
151     }
152 
153     public void serializeContent() {
154 
155         if (contentObject == null) {
156             contentObject = getContentObject();
157         }
158         OleHoldings oleHoldings = (OleHoldings) contentObject;
159         Location locationPojo = buildLocationObj();
160         oleHoldings.setLocation(locationPojo);
161         HoldingOlemlRecordProcessor recordProcessor = new HoldingOlemlRecordProcessor();
162         content = recordProcessor.toXML(oleHoldings);
163     }
164 
165     public void setField(String docField, String fieldValue) {
166         OleHoldings oleHoldings = getContentObject();
167         buildItemCallNumber(oleHoldings);
168         buildExtentOfOwnerShipAndNoteAndLink(oleHoldings);
169 
170         if (docField.equalsIgnoreCase(DESTINATION_FIELD_CALL_NUMBER)) {
171             oleHoldings.getCallNumber().setNumber(fieldValue);
172             oleHoldings.getCallNumber().getShelvingScheme().setCodeValue("NONE");
173         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_HOLDING_CALL_NUMBER_TYPE)) {
174             oleHoldings.getCallNumber().getShelvingScheme().setCodeValue(fieldValue);
175         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_CALL_NUMBER_TYPE_PREFIX)) {
176             oleHoldings.getCallNumber().setPrefix(fieldValue);
177         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_LOCATION_LEVEL_1)) {
178             setLocationLevel1(fieldValue);
179         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_LOCATION_LEVEL_2)) {
180             setLocationLevel2(fieldValue);
181         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_LOCATION_LEVEL_3)) {
182             setLocationLevel3(fieldValue);
183         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_LOCATION_LEVEL_4)) {
184             setLocationLevel4(fieldValue);
185         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_LOCATION_LEVEL_5)) {
186             setLocationLevel5(fieldValue);
187         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_LINK_TEXT)) {
188             oleHoldings.getLink().get(0).setText(fieldValue);
189         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_LINK_URL)) {
190             oleHoldings.getLink().get(0).setUrl(fieldValue);
191         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_PERSISTENTLINK)) {
192             oleHoldings.setLocalPersistentLink(fieldValue);
193         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_COVERAGE_START_DATE)) {
194             oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().get(0).setCoverageStartDate(fieldValue);
195         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_COVERAGE_START_VOLUME)) {
196             oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().get(0).setCoverageStartVolume(fieldValue);
197         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_COVERAGE_START_ISSUE)) {
198             oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().get(0).setCoverageStartIssue(fieldValue);
199         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_COVERAGE_END_DATE)) {
200             oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().get(0).setCoverageEndDate(fieldValue);
201         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_COVERAGE_END_ISSUE)) {
202             oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().get(0).setCoverageEndIssue(fieldValue);
203         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_COVERAGE_END_VOLUME)) {
204             oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().get(0).setCoverageEndVolume(fieldValue);
205         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_STATISTICAL_CODE)) {
206             oleHoldings.getStatisticalSearchingCode().setCodeValue(fieldValue);
207             oleHoldings.getStatisticalSearchingCode().setFullValue(fieldValue);
208         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_PUBLIC_DISPLAY_NOTE)) {
209             oleHoldings.getNote().get(0).setValue(fieldValue);
210             oleHoldings.getNote().get(0).setType(PUBLIC);
211         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_ACCESS_STATUS_CODE)) {
212             if (fieldValue.toLowerCase().equals(ACTIVE)) {
213                 oleHoldings.setAccessStatus(ACTIVE);
214             } else if (fieldValue.equalsIgnoreCase(INACTIVE)) {
215                 oleHoldings.setAccessStatus(INACTIVE);
216             }
217         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_COPY_NUMBER)) {
218             oleHoldings.setCopyNumber(fieldValue);
219         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_PLATFORM)) {
220             Platform platform = new Platform();
221             platform.setPlatformName(fieldValue);
222             oleHoldings.setPlatform(platform);
223         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_DONOR_CODE) || docField.equalsIgnoreCase(DESTINATION_FIELD_DONOR_PUBLIC_DISPLAY) || docField.equalsIgnoreCase(DESTINATION_FIELD_DONOR_NOTE)) {
224             DonorInfo donorInfo = null;
225             if (oleHoldings.getDonorInfo().size() > 0) {
226                 for (DonorInfo existingDonorInfo : oleHoldings.getDonorInfo()) {
227                     buildDonorInfo(docField, fieldValue, oleHoldings, existingDonorInfo, false);
228                 }
229             } else {
230                 donorInfo = new DonorInfo();
231                 buildDonorInfo(docField, fieldValue, oleHoldings, donorInfo, false);
232             }
233         }else if ( docField.equalsIgnoreCase(DESTINATION_FIELD_ERESOURCE_ID)) {
234             oleHoldings.setEResourceId(fieldValue);
235         }
236         else if (docField.equalsIgnoreCase(DESTINATION_FIELD_GOKB_ID)) {
237             if(StringUtils.isNotEmpty(fieldValue)) {
238                 oleHoldings.setGokbIdentifier(Integer.parseInt(fieldValue));
239             }
240         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_IMPRINT)) {
241             if (StringUtils.isNotEmpty(fieldValue)) {
242                 oleHoldings.setImprint(fieldValue);
243             }
244         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_PUBLISHER)) {
245             if (StringUtils.isNotEmpty(fieldValue)) {
246                 oleHoldings.setPublisher(fieldValue);
247             }
248         }
249     }
250 
251 
252     public void setDefaultField(String docField, String fieldValue) {
253         super.setDefaultField(docField, fieldValue);
254         OleHoldings oleHoldings = getContentObject();
255         if (docField.equalsIgnoreCase(DESTINATION_FIELD_LINK_TEXT) && oleHoldings.getLink().get(0).getText() == null) {
256             oleHoldings.getLink().get(0).setText(fieldValue);
257         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_LINK_URL) && oleHoldings.getLink().get(0).getText() == null) {
258             oleHoldings.getLink().get(0).setUrl(fieldValue);
259         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_PERSISTENTLINK) && oleHoldings.getLocalPersistentLink() == null) {
260             oleHoldings.setLocalPersistentLink(fieldValue);
261         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_COVERAGE_START_DATE) && oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().get(0).getCoverageStartDate() == null) {
262             oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().get(0).setCoverageStartDate(fieldValue);
263         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_COVERAGE_START_VOLUME) && oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().get(0).getCoverageStartVolume() == null) {
264             oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().get(0).setCoverageStartVolume(fieldValue);
265         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_COVERAGE_START_ISSUE) && oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().get(0).getCoverageStartIssue() == null) {
266             oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().get(0).setCoverageStartIssue(fieldValue);
267         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_COVERAGE_END_DATE) && oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().get(0).getCoverageEndDate() == null) {
268             oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().get(0).setCoverageEndDate(fieldValue);
269         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_COVERAGE_END_ISSUE) && oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().get(0).getCoverageEndIssue() == null) {
270             oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().get(0).setCoverageEndIssue(fieldValue);
271         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_COVERAGE_END_VOLUME) && oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().get(0).getCoverageEndVolume() == null) {
272             oleHoldings.getExtentOfOwnership().get(0).getCoverages().getCoverage().get(0).setCoverageEndVolume(fieldValue);
273         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_STATISTICAL_CODE) && oleHoldings.getStatisticalSearchingCode().getCodeValue() == null) {
274             oleHoldings.getStatisticalSearchingCode().setCodeValue(fieldValue);
275             oleHoldings.getStatisticalSearchingCode().setFullValue(fieldValue);
276         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_PUBLIC_DISPLAY_NOTE) && oleHoldings.getNote().get(0).getValue() == null) {
277             oleHoldings.getNote().get(0).setValue(fieldValue);
278             oleHoldings.getNote().get(0).setType(PUBLIC);
279         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_ACCESS_STATUS_CODE) && oleHoldings.getAccessStatus() == null) {
280             if (fieldValue.toLowerCase().equals(ACTIVE)) {
281                 oleHoldings.setAccessStatus(ACTIVE);
282             } else if (fieldValue.equalsIgnoreCase(INACTIVE)) {
283                 oleHoldings.setAccessStatus(INACTIVE);
284             }
285         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_PLATFORM) && oleHoldings.getPlatform() == null) {
286             Platform platform = new Platform();
287             platform.setPlatformName(fieldValue);
288             oleHoldings.setPlatform(platform);
289         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_DONOR_CODE) || docField.equalsIgnoreCase(DESTINATION_FIELD_DONOR_PUBLIC_DISPLAY) || docField.equalsIgnoreCase(DESTINATION_FIELD_DONOR_NOTE)) {
290             DonorInfo donorInfo = null;
291             if (oleHoldings.getDonorInfo().size() == 0) {
292                 donorInfo = new DonorInfo();
293                 buildDonorInfo(docField, fieldValue, oleHoldings, donorInfo, false);
294             }
295         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_ERESOURCE_ID) && oleHoldings.getEResourceId() == null) {
296             oleHoldings.setEResourceId(fieldValue);
297         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_GOKB_ID) && oleHoldings.getGokbIdentifier() == null) {
298             if (StringUtils.isNotEmpty(fieldValue)) {
299                 oleHoldings.setGokbIdentifier(Integer.parseInt(fieldValue));
300             }
301         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_IMPRINT) && oleHoldings.getImprint() == null) {
302             if (StringUtils.isNotEmpty(fieldValue)) {
303                 oleHoldings.setImprint(fieldValue);
304             }
305         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_PUBLISHER) && oleHoldings.getPublisher() == null) {
306             if (StringUtils.isNotEmpty(fieldValue)) {
307                 oleHoldings.setPublisher(fieldValue);
308             }
309         }
310     }
311 
312     private void buildDonorInfo(String docField, String fieldValue, OleHoldings oleHoldings, DonorInfo donorInfo, boolean isDefault) {
313         if (docField.equalsIgnoreCase(DESTINATION_FIELD_DONOR_CODE)) {
314             if (donorInfo.getDonorCode() == null) {
315                 donorInfo.setDonorCode(fieldValue);
316             } else if (!isDefault) {
317                 donorInfo.setDonorCode(fieldValue);
318             }
319         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_DONOR_PUBLIC_DISPLAY)) {
320             if (donorInfo.getDonorPublicDisplay() == null) {
321                 donorInfo.setDonorPublicDisplay(fieldValue);
322             } else if (!isDefault) {
323                 donorInfo.setDonorPublicDisplay(fieldValue);
324             }
325         } else if (docField.equalsIgnoreCase(DESTINATION_FIELD_DONOR_NOTE)) {
326             if (donorInfo.getDonorNote() == null) {
327                 donorInfo.setDonorNote(fieldValue);
328             } else if (!isDefault) {
329                 donorInfo.setDonorNote(fieldValue);
330             }
331         }
332         if (oleHoldings.getDonorInfo() == null || oleHoldings.getDonorInfo().size() == 0) {
333             oleHoldings.getDonorInfo().add(donorInfo);
334         }
335     }
336 
337     private void buildExtentOfOwnerShipAndNoteAndLink(OleHoldings oleHoldings) {
338         if (oleHoldings.getExtentOfOwnership().size() == 0) {
339             ExtentOfOwnership extentOfOwnership = new ExtentOfOwnership();
340             Coverages coverages = new Coverages();
341             Coverage coverage = new Coverage();
342             coverages.getCoverage().add(coverage);
343             extentOfOwnership.setCoverages(coverages);
344             oleHoldings.getExtentOfOwnership().add(extentOfOwnership);
345         }
346         if (oleHoldings.getNote().size() == 0) {
347             Note note = new Note();
348             oleHoldings.getNote().add(note);
349         }
350         if (oleHoldings.getStatisticalSearchingCode() == null) {
351             StatisticalSearchingCode statisticalSearchingCode = new StatisticalSearchingCode();
352             oleHoldings.setStatisticalSearchingCode(statisticalSearchingCode);
353         }
354 
355         if(oleHoldings.getLink().size() == 0) {
356           oleHoldings.getLink().add(new Link());
357         }
358     }
359 }