View Javadoc
1   package org.kuali.ole.pojo.bib;
2   
3   import org.kuali.ole.docstore.model.xmlpojo.work.bib.marc.DataField;
4   import org.kuali.ole.docstore.model.xmlpojo.work.bib.marc.SubField;
5   
6   import java.io.Serializable;
7   import java.util.Iterator;
8   import java.util.List;
9   
10  /**
11   * Created by IntelliJ IDEA.
12   * User: pvsubrah
13   * Date: 12/28/11
14   * Time: 3:41 PM
15   * To change this template use File | Settings | File Templates.
16   */
17  public class BibliographicNamedFieldsBean implements Serializable {
18      private String title;
19      private String author;
20      private String publisher;
21      private String description;
22      private BibliographicRecord bibliographicRecord;
23  
24      public String getTitle() {
25          return getFieldNameFor("245", "a");
26      }
27  
28      public void setTitle(String title) {
29          setFieldValue(title, "245", "a");
30      }
31  
32      public String getAuthor() {
33          return getFieldNameFor("100", "a");
34      }
35  
36      public void setAuthor(String author) {
37          setFieldValue(author, "100", "a");
38      }
39  
40      public String getPublisher() {
41          return getFieldNameFor("260", "b");
42      }
43  
44      public void setPublisher(String publisher) {
45          setFieldValue(publisher, "260", "b");
46      }
47  
48      public String getDescription() {
49          StringBuffer stringBuffer = new StringBuffer();
50          stringBuffer.append(getTitle() == "" ? "" : getTitle())
51                  .append(",")
52                  .append(getAuthor() == "" ? "" : getAuthor())
53                  .append(",")
54                  .append(getUniqueNumber() == "" ? "" : getUniqueNumber());
55          String str = stringBuffer.toString();
56          return
57                  str.charAt(str.length() - 1) == ',' ? str.substring(0, str.length() - 1) : str;
58      }
59  
60      public void setDescription(String description) {
61          this.description = description;
62      }
63  
64      public BibliographicRecord getBibliographicRecord() {
65          if (null == bibliographicRecord) {
66              bibliographicRecord = new BibliographicRecord();
67          }
68          return bibliographicRecord;
69      }
70  
71      public void setBibliographicRecord(BibliographicRecord bibliographicRecord) {
72          this.bibliographicRecord = bibliographicRecord;
73      }
74  
75      public String getFieldNameFor(String dfTag, String sfCode) {
76          List<DataField> datafields = getBibliographicRecord().getDatafields();
77          if (null != datafields) {
78              for (Iterator<DataField> iterator = datafields.iterator(); iterator.hasNext(); ) {
79                  DataField marcDataField = iterator.next();
80                  if (marcDataField.getTag().equals(dfTag)) {
81                      List<SubField> subfields = marcDataField.getSubFields();
82                      for (Iterator<SubField> marcSubFieldIterator = subfields.iterator(); marcSubFieldIterator.hasNext(); ) {
83                          SubField marcSubField = marcSubFieldIterator.next();
84                          if (marcSubField.getCode().equals(sfCode)) {
85                              return marcSubField.getValue();
86                          }
87                      }
88                  }
89              }
90          }
91          return "";
92      }
93  
94      private void setFieldValue(String title, String dfTag, String sfCode) {
95          DataField marcDataField = null;
96          List<DataField> datafields = getBibliographicRecord().getDatafields();
97          boolean titleDataFieldExists = false;
98  
99          if (null != datafields) {
100             for (Iterator<DataField> iterator = datafields.iterator(); iterator.hasNext(); ) {
101                 DataField marcDataField1 = iterator.next();
102                 if (marcDataField1.getTag().equals(dfTag)) {
103                     titleDataFieldExists = true;
104                     break;
105                 }
106             }
107         }
108 
109         if (!titleDataFieldExists) {
110             marcDataField = new DataField();
111             marcDataField.setTag(dfTag);
112             SubField marcSubField = new SubField();
113             marcSubField.setCode(sfCode);
114             marcSubField.setValue(title);
115             marcDataField.addSubField(marcSubField);
116             marcDataField.setInd1("");
117             marcDataField.setInd2("");
118 
119             getBibliographicRecord().addDataField(marcDataField);
120         }
121     }
122 
123     public String getUniqueNumber() {
124         return getFieldNameFor("", "");
125     }
126 }