1 package org.kuali.ole.describe.bo;
2
3 import org.apache.log4j.Logger;
4 import org.kuali.ole.OLEConstants;
5 import org.kuali.ole.describe.controller.DocumentEditor;
6 import org.kuali.ole.describe.controller.DocumentEditorFactory;
7 import org.kuali.ole.describe.form.EditorForm;
8 import org.kuali.ole.docstore.discovery.service.DiscoveryService;
9 import org.kuali.ole.docstore.model.bo.WorkBibDocument;
10 import org.kuali.ole.docstore.model.bo.WorkHoldingsDocument;
11 import org.kuali.ole.docstore.model.bo.WorkInstanceDocument;
12 import org.kuali.ole.docstore.model.bo.WorkItemDocument;
13 import org.kuali.ole.docstore.model.xmlpojo.work.instance.oleml.InstanceCollection;
14 import org.kuali.ole.docstore.model.xstream.work.instance.oleml.WorkInstanceOlemlRecordProcessor;
15 import org.kuali.ole.editor.service.DiscoveryHelperService;
16 import org.kuali.ole.editor.service.DocstoreHelperService;
17
18 import java.util.ArrayList;
19 import java.util.Iterator;
20 import java.util.List;
21 import java.util.Map;
22
23
24
25
26
27
28
29
30 public class EditorFormDataHandler {
31
32 private static final Logger LOG = Logger.getLogger(EditorFormDataHandler.class);
33
34 public EditorForm buildLeftPaneData(EditorForm editorForm) {
35 String docId = editorForm.getDocId();
36 List<WorkBibDocument> workBibDocumentList = editorForm.getWorkBibDocumentList();
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 String treeData = prepareBibTree(workBibDocumentList);
54 editorForm.setTreeData(treeData);
55
56 return editorForm;
57 }
58
59 public String prepareBibTree(List<WorkBibDocument> bibDocumentList) {
60 StringBuilder sb = new StringBuilder();
61 for (WorkBibDocument workBibDocument : bibDocumentList) {
62 sb.append("<ul id=\"navigation\">");
63 sb.append("<li><div id=\"rightClick\"><b>").append(workBibDocument.getTitle()).append("</b></div>");
64 sb.append("<div class=\"vmenu\">\n");
65 sb.append("<div class=\"add_li\"><span>Add Instance</span></div>\n");
66 sb.append("<div class=\"delete_li\"><span>Delete Bib</span></div></div>");
67 sb.append("<div id=\"itmMenu\" style=\"border: 1px solid #aaa; border-left:1px solid #ccc; padding: 10px; display: none; position: absolute; top: 663px; left: 539px; background:#fff;\">");
68 sb.append("<table>");
69 sb.append("<tr><td class=\"delete_itm\"width=\"100%\" >Delete Item</td></tr> ");
70 sb.append("</table>");
71 sb.append("</div>");
72 List<WorkInstanceDocument> workInstanceDocumentList = workBibDocument.getWorkInstanceDocumentList();
73 WorkHoldingsDocument workHoldingsDocument = new WorkHoldingsDocument();
74 List<WorkItemDocument> workItemDocumentList = new ArrayList<WorkItemDocument>();
75 if (null != workInstanceDocumentList) {
76 for (WorkInstanceDocument workInstanceDocument : workInstanceDocumentList) {
77 workHoldingsDocument = workInstanceDocument.getHoldingsDocument();
78 String holdingIdentifier = workHoldingsDocument.getHoldingsIdentifier() + "_holdings" + "_oleml";
79 String holdingLevelContent = workHoldingsDocument.getLocationName();
80 sb.append("<ul>");
81 sb.append("<li><div class=\"holdingIdentifierClass\" id=\"").append(holdingIdentifier).append("\">").append(holdingLevelContent).append("</div>");
82 workItemDocumentList = workInstanceDocument.getItemDocumentList();
83 for (int i = 0; i < workItemDocumentList.size(); i++) {
84 WorkItemDocument workItemDocument = workItemDocumentList.get(i);
85 String itemIdentifier = workItemDocument.getItemIdentifier() + "_item_oleml";
86 String itemLevelContent = workItemDocument.getBarcode() + "-" + workItemDocument.getCallNumber();
87 sb.append("<ul>");
88 sb.append("<li><div class=\"itemIdentifierClass\" id=\"").append(itemIdentifier).append("\">").append(itemLevelContent).append("</div></li>");
89 }
90 sb.append("<ul></li></ul>");
91 }
92 }
93 sb.append("</li></ul>");
94 }
95
96 return sb.toString();
97 }
98
99 private String buildBibUuid(EditorForm editorForm) {
100 String docType = editorForm.getDocType();
101 String bibUuid = null;
102 if (!docType.equalsIgnoreCase("bibliographic")) {
103 List solrResponse = new DiscoveryHelperService().getResponseFromSOLR("id", editorForm.getUuid());
104 for (Iterator iterator = solrResponse.iterator(); iterator.hasNext(); ) {
105 Map map = (Map) iterator.next();
106 if (map.containsKey("bibIdentifier")) {
107 List list = (List) map.get("bibIdentifier");
108 bibUuid = list != null & list.size() > 0 ? (String) list.get(0) : null;
109 break;
110 }
111 }
112 } else {
113 bibUuid = editorForm.getUuid();
114 }
115 LOG.info("bib uuid-->" + bibUuid);
116 return bibUuid;
117 }
118 }