1 package org.kuali.ole.deliver.controller;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.kuali.ole.OLEConstants;
5 import org.kuali.ole.deliver.bo.OLEItemNoteResultDisplayRow;
6 import org.kuali.ole.deliver.bo.OLESingleItemResultDisplayRow;
7 import org.kuali.ole.deliver.form.OLEDeliverItemResultForm;
8 import org.kuali.ole.deliver.service.OLEDeliverItemSearchService;
9 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
10 import org.apache.commons.collections.CollectionUtils;
11 import org.kuali.ole.docstore.common.document.Bib;
12 import org.kuali.ole.docstore.common.document.content.bib.marc.BibMarcRecords;
13 import org.kuali.ole.docstore.common.document.content.bib.marc.DataField;
14 import org.kuali.ole.docstore.common.document.content.bib.marc.SubField;
15 import org.kuali.ole.docstore.common.document.content.bib.marc.xstream.BibMarcRecordProcessor;
16 import org.kuali.ole.docstore.common.document.content.instance.Note;
17 import org.kuali.ole.docstore.common.document.content.instance.OleHoldings;
18 import org.kuali.ole.sys.context.SpringContext;
19 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
20 import org.kuali.rice.krad.web.controller.UifControllerBase;
21 import org.kuali.rice.krad.web.form.UifFormBase;
22 import org.springframework.stereotype.Controller;
23 import org.springframework.validation.BindingResult;
24 import org.springframework.web.bind.annotation.ModelAttribute;
25 import org.springframework.web.bind.annotation.RequestMapping;
26 import org.springframework.web.servlet.ModelAndView;
27
28 import javax.servlet.http.HttpServletRequest;
29 import javax.servlet.http.HttpServletResponse;
30 import java.util.ArrayList;
31 import java.util.HashMap;
32 import java.util.List;
33 import java.util.Map;
34
35
36
37
38 @Controller
39 @RequestMapping(value = "/deliverItemResultController")
40 public class OLEDeliverItemResultController extends UifControllerBase {
41
42 private OLEDeliverItemSearchService oleDeliverItemSearchService;
43 private DocstoreClientLocator docstoreClientLocator;
44
45 public OLEDeliverItemSearchService getOleDeliverItemSearchService() {
46 if (oleDeliverItemSearchService == null) {
47 oleDeliverItemSearchService = GlobalResourceLoader.getService(OLEConstants.DELIVER_ITEM__SEARCH_SERVICE);
48 }
49 return oleDeliverItemSearchService;
50 }
51
52 public DocstoreClientLocator getDocstoreClientLocator() {
53 if (docstoreClientLocator == null) {
54 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
55 }
56 return docstoreClientLocator;
57 }
58
59 @Override
60 protected UifFormBase createInitialForm(HttpServletRequest request) {
61 return new OLEDeliverItemResultForm();
62 }
63
64 @Override
65 @RequestMapping(params = "methodToCall=start")
66 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
67 HttpServletRequest request, HttpServletResponse response) {
68 OLEDeliverItemResultForm deliverItemResultForm = (OLEDeliverItemResultForm) form;
69 deliverItemResultForm.setSingleItemFlag(true);
70 OLESingleItemResultDisplayRow oleSingleItemResultDisplayRow = new OLESingleItemResultDisplayRow();
71 String itemid = request.getParameter(OLEConstants.OleDeliverRequest.ITEM_ID);
72 Map itemIdMap = new HashMap();
73 itemIdMap.put(OLEConstants.ITEM_UUID, itemid);
74 org.kuali.ole.docstore.common.document.Item item = null;
75 try {
76 item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(itemid);
77 oleSingleItemResultDisplayRow.setLocation(item.getLocation());
78 oleSingleItemResultDisplayRow.setId(itemid);
79 oleSingleItemResultDisplayRow.setCreatedDate(item.getCreatedOn());
80 oleSingleItemResultDisplayRow.setCreatedBy(item.getCreatedBy());
81 oleSingleItemResultDisplayRow.setUpdatedBy(item.getUpdatedBy());
82 oleSingleItemResultDisplayRow.setUpdatedDate(item.getUpdatedOn());
83 if (item.getHolding() != null) {
84 oleSingleItemResultDisplayRow.setHoldingsLocation(item.getHolding().getLocationName());
85 oleSingleItemResultDisplayRow.setHoldingsIdentifier(item.getHolding().getId());
86 if (item.getHolding().getBib() != null) {
87 Bib bib = item.getHolding().getBib();
88 oleSingleItemResultDisplayRow.setBibIdentifier(bib.getId());
89 oleSingleItemResultDisplayRow.setTitle(bib.getTitle());
90 oleSingleItemResultDisplayRow.setAuthor(bib.getAuthor());
91 oleSingleItemResultDisplayRow.setPublication(bib.getPublisher() +" "+ bib.getPublicationDate());
92 oleSingleItemResultDisplayRow.setIsbn(bib.getIsbn());
93
94 BibMarcRecordProcessor recordProcessor = new BibMarcRecordProcessor();
95 if (bib.getContent() != null) {
96 BibMarcRecords bibMarcRecords = recordProcessor.fromXML(bib.getContent());
97 if (bibMarcRecords.getRecords() != null && bibMarcRecords.getRecords().size() > 0) {
98 DataField dataField = bibMarcRecords.getRecords().get(0).getDataFieldForTag("035");
99 if (dataField != null) {
100 List<SubField> subFields = dataField.getSubFields();
101 if (subFields != null && subFields.size() > 0) {
102 for (SubField subField : subFields) {
103 if (subField.getCode().equals("a")) {
104 oleSingleItemResultDisplayRow.setOclcNumber(subField.getValue());
105 break;
106 }
107 }
108 }
109 }
110 }
111 }
112 }
113 }
114 Object itemContent = item.getContentObject();
115 if (itemContent != null) {
116 org.kuali.ole.docstore.common.document.content.instance.Item itemPojo = (org.kuali.ole.docstore.common.document.content.instance.Item) itemContent;
117 if (itemPojo.getItemType() != null)
118 oleSingleItemResultDisplayRow.setItemType(itemPojo.getItemType().getCodeValue());
119 if (itemPojo.getItemStatus() != null)
120 oleSingleItemResultDisplayRow.setItemStatus(itemPojo.getItemStatus().getCodeValue());
121 if (itemPojo.getAccessInformation() != null)
122 oleSingleItemResultDisplayRow.setItemBarCode(itemPojo.getAccessInformation().getBarcode());
123 if (itemPojo.getCallNumber() != null && StringUtils.isNotBlank(itemPojo.getCallNumber().getNumber())) {
124 oleSingleItemResultDisplayRow.setCallNumber(itemPojo.getCallNumber().getNumber());
125 } else if (item.getHolding() != null) {
126 OleHoldings holdingsContent = item.getHolding().getContentObject();
127 if (holdingsContent != null && holdingsContent.getCallNumber() != null && StringUtils.isNotBlank(holdingsContent.getCallNumber().getNumber())) {
128 oleSingleItemResultDisplayRow.setCallNumber(holdingsContent.getCallNumber().getNumber());
129 }
130 }
131 oleSingleItemResultDisplayRow.setClaimsReturnedFlag(String.valueOf(itemPojo.isClaimsReturnedFlag()));
132 if (itemPojo.isClaimsReturnedFlag()) {
133 oleSingleItemResultDisplayRow.setClaimsReturnedNote(itemPojo.getClaimsReturnedNote());
134 oleSingleItemResultDisplayRow.setClaimsReturnedDate(itemPojo.getClaimsReturnedFlagCreateDate());
135 }
136 oleSingleItemResultDisplayRow.setMissingPieceFlag(String.valueOf(itemPojo.isMissingPieceFlag()));
137 if (itemPojo.isMissingPieceFlag()) {
138 oleSingleItemResultDisplayRow.setMissingPieceCount(itemPojo.getMissingPiecesCount());
139 oleSingleItemResultDisplayRow.setMissingPieceNote(itemPojo.getMissingPieceFlagNote());
140 }
141 oleSingleItemResultDisplayRow.setItemDamagedStatusFlag(String.valueOf(itemPojo.isItemDamagedStatus()));
142 if (itemPojo.isItemDamagedStatus()) {
143 oleSingleItemResultDisplayRow.setItemDamagedNote(itemPojo.getDamagedItemNote());
144 }
145 if (itemPojo.getItemStatusEffectiveDate() != null) {
146 String[] itemStatusEffectiveDate = itemPojo.getItemStatusEffectiveDate().split(" ");
147 oleSingleItemResultDisplayRow.setItemStatusDate(itemStatusEffectiveDate[0]);
148 }
149 oleSingleItemResultDisplayRow.setCurrentBorrowerId(itemPojo.getCurrentBorrower());
150 oleSingleItemResultDisplayRow.setProxyBorrowerId(itemPojo.getProxyBorrower());
151 oleSingleItemResultDisplayRow.setDueDate(itemPojo.getDueDateTime());
152 oleSingleItemResultDisplayRow.setEnumeration(itemPojo.getEnumeration());
153 oleSingleItemResultDisplayRow.setChronology(itemPojo.getChronology());
154 oleSingleItemResultDisplayRow.setNoOfPieces(itemPojo.getNumberOfPieces());
155 if (CollectionUtils.isNotEmpty(itemPojo.getNote())) {
156 List<OLEItemNoteResultDisplayRow> itemNoteResultDisplayRowList = new ArrayList<>();
157 for (Note note : itemPojo.getNote()) {
158 OLEItemNoteResultDisplayRow oleItemNoteResultDisplayRow = new OLEItemNoteResultDisplayRow();
159 oleItemNoteResultDisplayRow.setNoteType(note.getType());
160 oleItemNoteResultDisplayRow.setNoteValue(note.getValue());
161 itemNoteResultDisplayRowList.add(oleItemNoteResultDisplayRow);
162 }
163 oleSingleItemResultDisplayRow.setOleItemNoteResultDisplayRowList(itemNoteResultDisplayRowList);
164 }
165 }
166 getOleDeliverItemSearchService().setBorrowerInfo(oleSingleItemResultDisplayRow);
167 getOleDeliverItemSearchService().setAdditionalCopiesInfo(oleSingleItemResultDisplayRow);
168 getOleDeliverItemSearchService().setDeliverRequestInfo(itemIdMap, oleSingleItemResultDisplayRow);
169 getOleDeliverItemSearchService().setOutstandingFineInfo(itemIdMap, oleSingleItemResultDisplayRow);
170 getOleDeliverItemSearchService().setRequestHistoryInfo(oleSingleItemResultDisplayRow);
171 getOleDeliverItemSearchService().setInTransitHistoryInfo(oleSingleItemResultDisplayRow);
172 getOleDeliverItemSearchService().setMissingPieceItemInfo(oleSingleItemResultDisplayRow);
173 getOleDeliverItemSearchService().setClaimsReturnedInfo(oleSingleItemResultDisplayRow);
174 getOleDeliverItemSearchService().setDamagedInfo(oleSingleItemResultDisplayRow);
175 } catch (Exception e) {
176 e.printStackTrace();
177 }
178 deliverItemResultForm.setOleSingleItemResultDisplayRow(oleSingleItemResultDisplayRow);
179 return super.navigate(deliverItemResultForm, result, request, response);
180 }
181 }