View Javadoc

1   package org.kuali.ole.describe.bo;
2   
3   import org.apache.commons.lang.StringEscapeUtils;
4   import org.kuali.ole.docstore.model.bo.*;
5   import org.kuali.ole.docstore.model.enums.DocType;
6   
7   import java.util.Map;
8   
9   /**
10   * Created with IntelliJ IDEA.
11   * User: Sreekanth
12   * Date: 12/20/12
13   * Time: 10:57 AM
14   * To change this template use File | Settings | File Templates.
15   */
16  public class DocumentTreeNode {
17  
18      private String title;
19      private String uuid;
20      private boolean select;
21      private boolean returnCheck;
22  
23      private OleDocument oleDocument;
24      private String selectedInstance;
25      private Map<String, String> selectionMap;
26      private String holdingLocation;
27  
28      public DocumentTreeNode() {
29  
30      }
31  
32      public String getTitle() {
33          return title;
34      }
35  
36      public void setTitle(String title) {
37          this.title = title;
38      }
39  
40      public String getUuid() {
41          return uuid;
42      }
43  
44      public void setUuid(String uuid) {
45          this.uuid = uuid;
46      }
47  
48  
49      public void setWorkBibDocument(WorkBibDocument workBibDocument) {
50          this.oleDocument = workBibDocument;
51          StringBuilder titleBuilder = new StringBuilder();
52          if (workBibDocument != null) {
53              if (workBibDocument.getTitle() != null) {
54                  titleBuilder.append(workBibDocument.getTitle());
55              }
56              if (titleBuilder.length() > 0) {
57                  titleBuilder.append(" / ");
58              }
59              if (workBibDocument.getAuthor() != null) {
60                  titleBuilder.append(workBibDocument.getAuthor());
61              }
62  
63              setTitle(StringEscapeUtils.escapeHtml(titleBuilder.toString()));
64          } else {
65              setTitle("Bibliographic Title");
66          }
67  
68          setUuid(workBibDocument.getId());
69  
70      }
71  
72      public void setWorkInstanceDocument(WorkInstanceDocument workInstanceDocument) {
73          this.oleDocument = workInstanceDocument;
74          if (workInstanceDocument.getHoldingsDocument() != null) {
75              setTitle(buildTreeDataForHoldings(workInstanceDocument));
76          } else {
77              setTitle("Holdings");
78          }
79          setUuid(workInstanceDocument.getInstanceIdentifier());
80  
81  
82      }
83  
84      public void setWorkItemDocument(WorkItemDocument workItemDocument) {
85          this.oleDocument = workItemDocument;
86          if (workItemDocument != null) {
87              setTitle(buildTreeDataForItem(workItemDocument));
88          } else {
89              setTitle("Item");
90          }
91  
92          setUuid(workItemDocument.getItemIdentifier());
93      }
94  
95      public void setWorkHoldingsDocument(WorkItemDocument workItemDocument, WorkHoldingsDocument workHoldingsDocument) {
96          this.oleDocument = workItemDocument;
97          if (workItemDocument != null) {
98              setTitle(buildTreeDataForItem(workItemDocument, workHoldingsDocument));
99          } else {
100             setTitle("Item");
101         }
102 
103         setUuid(workItemDocument.getItemIdentifier());
104     }
105 
106     public void setWorkEInstanceDocument(WorkEInstanceDocument workEInstanceDocument) {
107         this.oleDocument = workEInstanceDocument;
108         if (workEInstanceDocument != null && workEInstanceDocument.getWorkEHoldingsDocument() != null) {
109             StringBuffer stringBuffer = new StringBuffer();
110             if (workEInstanceDocument.getWorkEHoldingsDocument() != null) {
111                 if (workEInstanceDocument.getWorkEHoldingsDocument().getLocation() != null && workEInstanceDocument.getWorkEHoldingsDocument().getLocation().length() > 0) {
112                     stringBuffer.append(workEInstanceDocument.getWorkEHoldingsDocument().getLocation());
113                 }
114                 if (stringBuffer.length() > 0 && workEInstanceDocument.getWorkEHoldingsDocument().geteResourceName() != null && workEInstanceDocument.getWorkEHoldingsDocument().geteResourceName().length() > 0) {
115                     stringBuffer.append("-");
116                 }
117                 if (workEInstanceDocument.getWorkEHoldingsDocument().geteResourceName() != null) {
118                     stringBuffer.append(workEInstanceDocument.getWorkEHoldingsDocument().geteResourceName());
119                 }
120 
121             }
122             setTitle(stringBuffer.toString());
123         } else {
124             setTitle("eHoldings");
125         }
126 
127         setUuid(workEInstanceDocument.getInstanceIdentifier() + " " + DocType.EINSTANCE.getCode());
128     }
129 
130     public OleDocument getWorkBibDocument() {
131         getTitle();
132         getUuid();
133         return oleDocument = new WorkBibDocument();
134     }
135 
136     public OleDocument getWorkInstanceDocument() {
137 /*        getTitle();
138         getUuid();*/
139         return oleDocument = new WorkInstanceDocument();
140     }
141 
142     public OleDocument getWorkItemDocument() {
143         getTitle();
144         getUuid();
145         return oleDocument = new WorkItemDocument();
146     }
147 
148 
149     public OleDocument getWorkEInstanceDocument() {
150         getTitle();
151         getUuid();
152         return oleDocument = new WorkEInstanceDocument();
153     }
154 
155 
156     public String getSelectedInstance() {
157         return selectedInstance;
158     }
159 
160     public void setSelectedInstance(String selectedInstance) {
161         this.selectedInstance = selectedInstance;
162     }
163 
164 
165     public boolean isSelect() {
166         return select;
167     }
168 
169     public void setSelect(boolean select) {
170         this.select = select;
171     }
172 
173     public Map<String, String> getSelectionMap() {
174         return selectionMap;
175     }
176 
177     public void setSelectionMap(Map<String, String> selectionMap) {
178         this.selectionMap = selectionMap;
179     }
180 
181     public boolean isReturnCheck() {
182         return returnCheck;
183     }
184 
185     public void setReturnCheck(boolean returnCheck) {
186         this.returnCheck = returnCheck;
187     }
188 
189 
190     public String buildTreeDataForHoldings(WorkInstanceDocument workInstanceDocument) {
191 
192         StringBuffer holdingsLabelBufferForStaffOnly = new StringBuffer();
193         WorkHoldingsDocument workHoldingsDocument = workInstanceDocument.getHoldingsDocument();
194         return new EditorFormDataHandler().getHoldingsLabel(workHoldingsDocument);
195     }
196 
197     public String buildTreeDataForItem(WorkItemDocument workItemDocument, WorkHoldingsDocument workHoldingsDocument) {
198 
199         return new EditorFormDataHandler().getItemLabel(workHoldingsDocument, workItemDocument);
200 
201     }
202 
203     public String buildTreeDataForItem(WorkItemDocument workItemDocument) {
204         String itemLevelContent = null;
205         StringBuilder treeBuilder = new StringBuilder();
206         String locationName = this.getHoldingLocation();
207 //        if (workItemDocument.getLocation() != null) {
208 //            treeBuilder.append(workItemDocument.getLocation());
209 //        }
210         StringBuffer removeFromCallNumber = new StringBuffer();
211         String callNumberPrefix = null;
212         String itemLocation = null;
213         if (workItemDocument.getLocation() != null) {
214             itemLocation = workItemDocument.getLocation();
215             if (!(itemLocation).equalsIgnoreCase(locationName)) {
216 
217                 treeBuilder.append(itemLocation);
218             }
219         }
220         if (workItemDocument.getCallNumberPrefix() != null && workItemDocument.getCallNumberPrefix().length() > 0) {
221             callNumberPrefix = workItemDocument.getCallNumberPrefix();
222         }
223         if (callNumberPrefix != null) {
224             if (treeBuilder.length() > 0) {
225                 treeBuilder.append("-").append(callNumberPrefix);
226             } else {
227                 treeBuilder.append(callNumberPrefix);
228             }
229         }
230         if (workItemDocument.getCallNumber() != null && workItemDocument.getCallNumber().length() > 0) {
231             if (treeBuilder.length() > 0) {
232                 treeBuilder.append("-");
233             }
234             treeBuilder.append(workItemDocument.getCallNumber());
235         }
236         if (workItemDocument.getEnumeration() != null && workItemDocument.getEnumeration().length() > 0) {
237             if (treeBuilder.length() > 0) {
238                 treeBuilder.append("-");
239             }
240             treeBuilder.append(workItemDocument.getEnumeration());
241             removeFromCallNumber.append(" " + workItemDocument.getEnumeration());
242         }
243         if (workItemDocument.getChronology() != null && workItemDocument.getChronology().length() > 0) {
244             if (treeBuilder.length() > 0) {
245                 treeBuilder.append("-");
246             }
247             treeBuilder.append(workItemDocument.getChronology());
248             removeFromCallNumber.append(" " + workItemDocument.getChronology());
249 
250         }
251         if (workItemDocument.getCopyNumber() != null && workItemDocument.getCopyNumber().length() > 0) {
252             if (treeBuilder.length() > 0) {
253                 treeBuilder.append("-");
254             }
255             treeBuilder.append(workItemDocument.getCopyNumber());
256             removeFromCallNumber.append(" " + workItemDocument.getCopyNumber());
257         }
258         if (workItemDocument.getBarcode() != null && workItemDocument.getBarcode().length() > 0) {
259             if (treeBuilder.length() > 0) {
260                 treeBuilder.append("-");
261             }
262             treeBuilder.append(workItemDocument.getBarcode());
263         }
264         if (treeBuilder.length() == 0) {
265             if (workItemDocument.getVolumeNumber() != null) {
266                 treeBuilder.append(workItemDocument.getVolumeNumber());
267             } else {
268                 treeBuilder.append("Item");
269             }
270         }
271         itemLevelContent = treeBuilder.toString().replaceAll(removeFromCallNumber.toString(), "");
272 
273         return itemLevelContent;
274 
275     }
276 
277     public String getHoldingLocation() {
278         return holdingLocation;
279     }
280 
281     public void setHoldingLocation(String holdingLocation) {
282         this.holdingLocation = holdingLocation;
283     }
284 }