View Javadoc

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   * Created with IntelliJ IDEA.
25   * User: pp7788
26   * Date: 12/12/12
27   * Time: 2:30 PM
28   * To change this template use File | Settings | File Templates.
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          if (null == docId) {
39              WorkBibDocument workBibDocument = new WorkBibDocument();
40              //workBibDocument.setId("New Bib");
41              workBibDocument.setTitle("New Bib");
42              workBibDocumentList.add(workBibDocument); 
43          }
44          else {
45              String bibUuid = buildBibUuid(editorForm);
46              WorkBibDocument workBibDocument = new WorkBibDocument();
47              workBibDocument.setId(bibUuid);
48              workBibDocumentList.add(workBibDocument);
49              DocstoreHelperService docstoreHelperService = new DocstoreHelperService();
50              workBibDocumentList = docstoreHelperService.getInfoForBibTree(workBibDocumentList);
51          }
52  */
53          String treeData = prepareBibTree(workBibDocumentList);
54          editorForm.setTreeData(treeData);
55  //        editorForm.setWorkBibDocumentList(workBibDocumentList);
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          //LOG.info("tree-data-->" + treeData);
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 }