1 package org.kuali.ole.deliver.printSlip;
2
3
4
5 import com.itextpdf.text.*;
6 import com.itextpdf.text.Font;
7 import com.itextpdf.text.Rectangle;
8 import com.itextpdf.text.pdf.*;
9 import org.apache.log4j.Logger;
10 import org.kuali.ole.OLEConstants;
11 import org.kuali.ole.deliver.batch.OleDeliverBatchServiceImpl;
12 import org.kuali.ole.deliver.bo.OleCirculationDesk;
13 import org.kuali.ole.deliver.bo.OleDeliverRequestBo;
14 import org.kuali.ole.deliver.bo.OleLoanDocument;
15 import org.kuali.ole.deliver.bo.OlePatronDocument;
16 import org.kuali.ole.deliver.processor.LoanProcessor;
17 import org.kuali.ole.deliver.service.CircDeskLocationResolver;
18 import org.kuali.ole.describe.bo.OleLocation;
19 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
20 import org.kuali.ole.docstore.common.document.Bib;
21 import org.kuali.ole.docstore.common.document.ItemOleml;
22 import org.kuali.ole.docstore.common.document.content.enums.DocType;
23 import org.kuali.ole.docstore.common.document.content.instance.Item;
24 import org.kuali.ole.docstore.common.search.SearchResponse;
25 import org.kuali.ole.docstore.common.search.SearchResult;
26 import org.kuali.ole.docstore.common.search.SearchResultField;
27 import org.kuali.ole.sys.context.SpringContext;
28 import org.kuali.rice.core.api.util.RiceConstants;
29 import org.kuali.rice.kim.impl.identity.address.EntityAddressBo;
30 import org.kuali.rice.kim.impl.identity.email.EntityEmailBo;
31 import org.kuali.rice.kim.impl.identity.entity.EntityBo;
32 import org.kuali.rice.kim.impl.identity.name.EntityNameBo;
33
34 import javax.servlet.ServletOutputStream;
35 import javax.servlet.http.HttpServletResponse;
36 import java.io.ByteArrayOutputStream;
37 import java.io.OutputStream;
38 import java.text.DateFormat;
39 import java.text.SimpleDateFormat;
40 import java.util.*;
41 import java.util.List;
42
43
44
45
46 public class OlePrintSlip extends PdfPageEventHelper {
47
48 private static final Logger LOG = Logger.getLogger(OlePrintSlip.class);
49 Font boldFont = FontFactory.getFont("Times-Roman", 12, Font.BOLD);
50
51 private Map<String, Font> printFontMap = new HashMap<String, Font>();
52
53 private Map<String, Font> fontMap = new HashMap<String, Font>();
54 private Map<String, BaseColor> colorMap = new HashMap<String, BaseColor>();
55 private Map<String, BaseColor> printColorMap = new HashMap<String, BaseColor>();
56 private DocstoreClientLocator docstoreClientLocator;
57 private OleDeliverBatchServiceImpl oleDeliverBatchService;
58 private CircDeskLocationResolver circDeskLocationResolver;
59
60 private CircDeskLocationResolver getCircDeskLocationResolver() {
61 if (circDeskLocationResolver == null) {
62 circDeskLocationResolver = new CircDeskLocationResolver();
63 }
64 return circDeskLocationResolver;
65 }
66
67 public void setCircDeskLocationResolver(CircDeskLocationResolver circDeskLocationResolver) {
68 this.circDeskLocationResolver = circDeskLocationResolver;
69 }
70
71 public OleDeliverBatchServiceImpl getOleDeliverBatchService() {
72 if(oleDeliverBatchService==null){
73 oleDeliverBatchService=SpringContext.getBean(OleDeliverBatchServiceImpl.class);
74 }
75 return oleDeliverBatchService;
76 }
77
78 public void setOleDeliverBatchService(OleDeliverBatchServiceImpl oleDeliverBatchService) {
79 this.oleDeliverBatchService = oleDeliverBatchService;
80 }
81
82 public DocstoreClientLocator getDocstoreClientLocator() {
83
84 if (docstoreClientLocator == null) {
85 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
86
87 }
88 return docstoreClientLocator;
89 }
90
91 public com.itextpdf.text.Font getBoldFont(){
92 Font boldFont = FontFactory.getFont("Times-Roman", 15, Font.BOLD);
93 return boldFont;
94 }
95
96
97
98 public com.itextpdf.text.Font getDefaultFont(){
99 return getOleDeliverBatchService().getDefaultFont();
100 }
101
102 public com.itextpdf.text.Font getFont(String data){
103 return getOleDeliverBatchService().getFont(data);
104 }
105
106 public void populateFontMap() {
107
108 fontMap.put("COURIER", new Font(FontFactory.getFont("Times-Roman", Font.BOLD).getBaseFont()));
109 fontMap.put("COURIER", new Font(FontFactory.getFont("Times-Roman", Font.BOLDITALIC).getBaseFont()));
110 fontMap.put("COURIER", new Font(FontFactory.getFont("Times-Roman", Font.DEFAULTSIZE).getBaseFont()));
111 fontMap.put("COURIER", new Font(FontFactory.getFont("Times-Roman", Font.STRIKETHRU).getBaseFont()));
112 fontMap.put("COURIER", new Font(FontFactory.getFont("Times-Roman", Font.NORMAL).getBaseFont()));
113 fontMap.put("COURIER", new Font(FontFactory.getFont("Times-Roman", Font.UNDEFINED).getBaseFont()));
114 fontMap.put("COURIER", new Font(FontFactory.getFont("Times-Roman", Font.UNDERLINE).getBaseFont()));
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130 }
131
132 public void populateColorMap() {
133 colorMap.put("WHITE", BaseColor.WHITE);
134 colorMap.put("YELLOW", BaseColor.YELLOW);
135 colorMap.put("BLACK", BaseColor.BLACK);
136 colorMap.put("BLUE", BaseColor.BLUE);
137 colorMap.put("CYAN", BaseColor.CYAN);
138 colorMap.put("DARK_GRAY", BaseColor.DARK_GRAY);
139 colorMap.put("GRAY", BaseColor.GRAY);
140 colorMap.put("GREEN", BaseColor.GREEN);
141 colorMap.put("LIGHT_GRAY", BaseColor.LIGHT_GRAY);
142 colorMap.put("MAGENTA", BaseColor.MAGENTA);
143 colorMap.put("ORANGE", BaseColor.ORANGE);
144 colorMap.put("PINK", BaseColor.PINK);
145 colorMap.put("RED", BaseColor.RED);
146 colorMap.put("PINK", BaseColor.PINK);
147 }
148
149
150
151
152
153
154
155
156 public void createPdfForPrintingSlip(OleLoanDocument oleLoanDocument, HttpServletResponse response) {
157 LOG.debug("Initialize Normal pdf Template");
158 LoanProcessor loanProcessor = new LoanProcessor();
159 OleDeliverRequestBo oleDeliverRequestBo = oleLoanDocument.getOleDeliverRequestBo();
160 OlePatronDocument oleRequestPatronDocument = oleDeliverRequestBo != null ? loanProcessor.getOlePatronDocument(oleDeliverRequestBo.getBorrowerId()) : null;
161 EntityNameBo nameBo = oleRequestPatronDocument != null ? oleRequestPatronDocument.getEntity().getNames().get(0) : null;
162 String patronName = nameBo != null ? nameBo.getLastName() + "," + nameBo.getFirstName() : null;
163 Date expirationDate = oleRequestPatronDocument != null ? oleRequestPatronDocument.getExpirationDate() : null;
164 OlePatronDocument olePatronDocument = oleLoanDocument != null ? loanProcessor.getOlePatronDocument(oleLoanDocument.getPatronId()) : null;
165 OleLocation oleLocation = null;
166 OleCirculationDesk oleCirculationDesk = null;
167 SimpleDateFormat dateFormat = new SimpleDateFormat(OLEConstants.DATEFORMAT);
168 SimpleDateFormat sdf = new SimpleDateFormat(OLEConstants.TIMESTAMP);
169 try {
170 if (oleLoanDocument.getCirculationLocationId() != null) {
171 oleCirculationDesk = getCircDeskLocationResolver().getOleCirculationDesk(oleLoanDocument.getCirculationLocationId());
172 oleLocation = oleCirculationDesk != null ? oleCirculationDesk.getOleCirculationDeskLocations().get(0).getLocation() : null;
173 }
174 String locationName = oleLocation != null ? oleLocation.getLocationName() : null;
175 String itemBarcode = oleLoanDocument.getItemId();
176 String itemCallNumber = null;
177 String copyNumber = null;
178 String volumeNumber = null;
179 Item oleItem = oleLoanDocument.getOleItem();
180 if (oleItem != null) {
181 itemCallNumber = loanProcessor.getItemCallNumber(oleItem, oleLoanDocument.getInstanceUuid());
182 copyNumber = oleItem.getCopyNumber();
183 volumeNumber = oleItem.getEnumeration();
184 } else {
185 getItemDetails(loanProcessor, oleLoanDocument, oleItem, itemBarcode);
186 itemCallNumber = loanProcessor.getItemCallNumber(oleItem, oleLoanDocument.getInstanceUuid());
187 copyNumber = oleItem.getCopyNumber();
188 volumeNumber = oleItem.getEnumeration();
189 }
190 if (copyNumber == null) {
191 copyNumber = "";
192 }
193 if (volumeNumber == null) {
194 volumeNumber = "";
195 }
196 String itemTitle = oleLoanDocument.getTitle();
197 String requestedBy = null;
198 if (oleDeliverRequestBo != null) {
199 requestedBy = oleDeliverRequestBo.getFirstName() + " " + oleDeliverRequestBo.getLastName();
200 }
201 String routeTo = oleLoanDocument.getRouteToLocationName() != null ? oleLoanDocument.getRouteToLocationName() : oleCirculationDesk.getCirculationDeskPublicName();
202 String checkInNote = oleItem != null ? oleItem.getCheckinNote() : null;
203 String itemStatusCode = oleLoanDocument.getItemStatusCode() != null ? oleLoanDocument.getItemStatusCode() : "";
204 boolean checkInNoteDisplay = checkInNote != null && !checkInNote.trim().isEmpty() && !oleLoanDocument.getItemStatusCode().contains(OLEConstants.ITEM_STATUS_IN_TRANSIT) && oleLoanDocument.getRouteToLocation() != null && !oleLoanDocument.getRouteToLocation().trim().isEmpty();
205 boolean holdSlip = itemStatusCode.equalsIgnoreCase(OLEConstants.ITEM_STATUS_ON_HOLD);
206 boolean inTransitSlip = itemStatusCode.equalsIgnoreCase(OLEConstants.ITEM_STATUS_IN_TRANSIT);
207 boolean inTransitForHold = itemStatusCode.equalsIgnoreCase(OLEConstants.ITEM_STATUS_IN_TRANSIT_HOLD);
208 boolean inTransitPerStaff = itemStatusCode.equalsIgnoreCase(OLEConstants.ITEM_STATUS_IN_TRANSIT_STAFF);
209 boolean missingPieceCheck = oleLoanDocument.isMissingPieceFlag();
210 boolean returnedDamaged = oleLoanDocument.isItemDamagedStatus();
211 boolean claimsReturned = oleLoanDocument.isClaimsReturnedIndicator();
212 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
213 populateColorMap();
214 populateFontMap();
215 response.setContentType("application/pdf");
216 OutputStream os = null;
217
218 if (holdSlip && oleCirculationDesk != null && oleCirculationDesk.getHoldFormat() != null && oleCirculationDesk.getHoldFormat().equals(OLEConstants.RECEIPT_PRINTER)) {
219 getHoldSlipForReceiptPrinter(patronName, expirationDate, missingPieceCheck, oleCirculationDesk, itemBarcode, itemTitle, itemCallNumber, copyNumber, volumeNumber, response);
220 } else {
221 Document document = this.getDocument(0, 0, 5, 5);
222 if (missingPieceCheck) {
223 os = response.getOutputStream();
224 PdfWriter.getInstance(document, os);
225 }
226 document.open();
227 document.newPage();
228
229 PdfPTable pdfTable = new PdfPTable(3);
230 Paragraph paraGraph = new Paragraph();
231 paraGraph.setAlignment(Element.ALIGN_CENTER);
232 if (holdSlip) {
233 paraGraph.add(new Chunk("Hold Slip", getBoldFont()));
234 } else if (inTransitSlip) {
235 paraGraph.add(new Chunk("Routing Slip In-Transit", getBoldFont()));
236 } else if (inTransitForHold) {
237 paraGraph.add(new Chunk("Routing Slip In-Transit For Hold", getBoldFont()));
238 } else if (inTransitPerStaff) {
239 paraGraph.add(new Chunk("Routing Slip In-Transit Per Staff Request", getBoldFont()));
240 } else if (missingPieceCheck) {
241 paraGraph.add(new Chunk("Missing Pieces Notice", getBoldFont()));
242 } else if (returnedDamaged) {
243 paraGraph.add(new Chunk("Returned Damaged", getBoldFont()));
244 } else if (claimsReturned) {
245 paraGraph.add(new Chunk("Claims Returned Notice", getBoldFont()));
246 } else if (checkInNoteDisplay) {
247 paraGraph.add(new Chunk("Routing Slip", getBoldFont()));
248 } else {
249 paraGraph.add(new Chunk("Receipt(CheckIn) Slip", getBoldFont()));
250 }
251 paraGraph.add(Chunk.NEWLINE);
252 paraGraph.add(Chunk.NEWLINE);
253 paraGraph.add(Chunk.NEWLINE);
254 if (holdSlip) {
255 pdfTable.addCell(getPdfPCellInJustified("Patron Name"));
256 pdfTable.addCell(getPdfPCellInLeft(":"));
257 pdfTable.addCell(getPdfPCellInJustified(patronName));
258
259 pdfTable.addCell(getPdfPCellInJustified("Expiration Date"));
260 pdfTable.addCell(getPdfPCellInLeft(":"));
261 pdfTable.addCell(getPdfPCellInJustified(expirationDate != null ? dateFormat.format(expirationDate).toString() : null));
262 } else if (inTransitSlip || checkInNoteDisplay) {
263
264 pdfTable.addCell(getPdfPCellInJustified("Route To"));
265 pdfTable.addCell(getPdfPCellInLeft(":"));
266 pdfTable.addCell(getPdfPCellInJustified(routeTo));
267
268 pdfTable.addCell(getPdfPCellInJustified("Date/Time "));
269 pdfTable.addCell(getPdfPCellInLeft(":"));
270 pdfTable.addCell(getPdfPCellInJustified(sdf.format(oleLoanDocument.getCheckInDate()).toString()));
271
272 } else if (inTransitForHold) {
273
274 pdfTable.addCell(getPdfPCellInJustified("Route To"));
275 pdfTable.addCell(getPdfPCellInLeft(":"));
276 pdfTable.addCell(getPdfPCellInJustified(routeTo));
277
278 pdfTable.addCell(getPdfPCellInJustified("Place on hold for"));
279 pdfTable.addCell(getPdfPCellInLeft(":"));
280 pdfTable.addCell(getPdfPCellInJustified(requestedBy));
281
282
283 pdfTable.addCell(getPdfPCellInJustified("Date/Time "));
284 pdfTable.addCell(getPdfPCellInLeft(":"));
285 pdfTable.addCell(getPdfPCellInJustified(sdf.format(oleLoanDocument.getCheckInDate()).toString()));
286
287 } else if (inTransitPerStaff) {
288
289 pdfTable.addCell(getPdfPCellInJustified("Route To"));
290 pdfTable.addCell(getPdfPCellInLeft(":"));
291 pdfTable.addCell(getPdfPCellInJustified(routeTo));
292
293 pdfTable.addCell(getPdfPCellInJustified("Requested By"));
294 pdfTable.addCell(getPdfPCellInLeft(":"));
295 pdfTable.addCell(getPdfPCellInJustified(requestedBy));
296
297
298 pdfTable.addCell(getPdfPCellInJustified("Date/Time "));
299 pdfTable.addCell(getPdfPCellInLeft(":"));
300 pdfTable.addCell(getPdfPCellInJustified(sdf.format(oleLoanDocument.getCheckInDate()).toString()));
301
302 } else if (returnedDamaged) {
303 pdfTable.addCell(getPdfPCellInJustified("Route To"));
304 pdfTable.addCell(getPdfPCellInLeft(":"));
305 pdfTable.addCell(getPdfPCellInJustified(routeTo));
306 } else if (missingPieceCheck) {
307 document.add(paraGraph);
308
309 pdfTable.addCell(getPdfPCellInJustified("Circulation Location / Library Name"));
310 pdfTable.addCell(getPdfPCellInLeft(":"));
311 pdfTable.addCell(getPdfPCellInJustified(oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskPublicName() : ""));
312
313 pdfTable.addCell(getPdfPCellInJustified("Address"));
314 pdfTable.addCell(getPdfPCellInLeft(":"));
315 pdfTable.addCell(getPdfPCellInJustified(""));
316
317 pdfTable.addCell(getPdfPCellInJustified("Email"));
318 pdfTable.addCell(getPdfPCellInLeft(":"));
319 pdfTable.addCell(getPdfPCellInJustified("kuali.ole@org.com"));
320
321 pdfTable.addCell(getPdfPCellInJustified("Phone #"));
322 pdfTable.addCell(getPdfPCellInLeft(":"));
323 pdfTable.addCell(getPdfPCellInJustified("111-5555"));
324
325 document.add(pdfTable);
326 paraGraph = new Paragraph();
327 paraGraph.add(Chunk.NEWLINE);
328 document.add(paraGraph);
329
330
331 paraGraph = new Paragraph();
332 paraGraph.add(new Chunk("Addressee", getBoldFont()));
333 paraGraph.add(Chunk.NEWLINE);
334 document.add(paraGraph);
335
336 pdfTable = new PdfPTable(3);
337 pdfTable.addCell(getPdfPCellInJustified("Borrower Name"));
338 pdfTable.addCell(getPdfPCellInLeft(":"));
339 pdfTable.addCell(getPdfPCellInJustified(patronName));
340
341 pdfTable.addCell(getPdfPCellInJustified("Address"));
342 pdfTable.addCell(getPdfPCellInLeft(":"));
343 pdfTable.addCell(getPdfPCellInJustified(""));
344
345 pdfTable.addCell(getPdfPCellInJustified("Email"));
346 pdfTable.addCell(getPdfPCellInLeft(":"));
347 pdfTable.addCell(getPdfPCellInJustified(olePatronDocument != null && olePatronDocument.getEmailAddress() != null ? olePatronDocument.getEmailAddress() : ""));
348
349 pdfTable.addCell(getPdfPCellInJustified("Phone #"));
350 pdfTable.addCell(getPdfPCellInLeft(":"));
351 pdfTable.addCell(getPdfPCellInJustified(olePatronDocument != null && olePatronDocument.getPhoneNumber() != null ? olePatronDocument.getPhoneNumber() : ""));
352
353 document.add(pdfTable);
354
355 paraGraph = new Paragraph();
356 paraGraph.add(new Chunk("Return with Missing Piece(s) Notice", getBoldFont()));
357 paraGraph.setAlignment(Element.ALIGN_CENTER);
358 paraGraph.add(Chunk.NEWLINE);
359 document.add(paraGraph);
360
361
362
363 paraGraph = new Paragraph();
364 paraGraph.add(new Chunk("The following item(s) returned by you is missing one or more of its pieces.Please return the missing piece(s) to the library shown above or contact the library about this matter to avoid incurring any penalties.", getBoldFont()));
365 paraGraph.setAlignment(Element.ALIGN_CENTER);
366 paraGraph.add(Chunk.NEWLINE);
367 document.add(paraGraph);
368
369
370 paraGraph = new Paragraph();
371 paraGraph.add(new Chunk("Title/item information", getBoldFont()));
372 paraGraph.add(Chunk.NEWLINE);
373 document.add(paraGraph);
374
375 pdfTable = new PdfPTable(3);
376 pdfTable.addCell(getPdfPCellInJustified("Title"));
377 pdfTable.addCell(getPdfPCellInLeft(":"));
378 pdfTable.addCell(getPdfPCellInJustified(itemTitle));
379
380 pdfTable.addCell(getPdfPCellInJustified("Author"));
381 pdfTable.addCell(getPdfPCellInLeft(":"));
382 pdfTable.addCell(getPdfPCellInJustified(oleLoanDocument.getAuthor()));
383
384 pdfTable.addCell(getPdfPCellInJustified("Volume/Issue/Copy #"));
385 pdfTable.addCell(getPdfPCellInLeft(":"));
386 pdfTable.addCell(getPdfPCellInJustified(copyNumber));
387
388 pdfTable.addCell(getPdfPCellInJustified("Library shelving location "));
389 pdfTable.addCell(getPdfPCellInLeft(":"));
390 pdfTable.addCell(getPdfPCellInJustified(locationName));
391
392 pdfTable.addCell(getPdfPCellInJustified("Call #"));
393 pdfTable.addCell(getPdfPCellInLeft(":"));
394 pdfTable.addCell(getPdfPCellInJustified(itemCallNumber));
395
396 pdfTable.addCell(getPdfPCellInJustified("Item barcode"));
397 pdfTable.addCell(getPdfPCellInLeft(":"));
398 pdfTable.addCell(getPdfPCellInJustified(itemBarcode));
399 document.add(pdfTable);
400
401 }
402 if (!missingPieceCheck) {
403 pdfTable.addCell(getPdfPCellInJustified("Route From"));
404 pdfTable.addCell(getPdfPCellInLeft(":"));
405 pdfTable.addCell(getPdfPCellInJustified(oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskPublicName() : ""));
406
407 pdfTable.addCell(getPdfPCellInJustified("Item Barcode"));
408 pdfTable.addCell(getPdfPCellInLeft(":"));
409 pdfTable.addCell(getPdfPCellInJustified(itemBarcode));
410
411 pdfTable.addCell(getPdfPCellInJustified("Title"));
412 pdfTable.addCell(getPdfPCellInLeft(":"));
413 pdfTable.addCell(getPdfPCellInJustified(itemTitle));
414
415 pdfTable.addCell(getPdfPCellInJustified("Call Number"));
416 pdfTable.addCell(getPdfPCellInLeft(":"));
417 pdfTable.addCell(getPdfPCellInJustified(itemCallNumber));
418
419 pdfTable.addCell(getPdfPCellInJustified("Copy Number"));
420 pdfTable.addCell(getPdfPCellInLeft(":"));
421 pdfTable.addCell(getPdfPCellInJustified(copyNumber));
422 if (!(holdSlip | inTransitSlip | inTransitForHold | inTransitPerStaff | checkInNoteDisplay)) {
423 pdfTable.addCell(getPdfPCellInJustified("Check-in Date"));
424 pdfTable.addCell(getPdfPCellInLeft(":"));
425 pdfTable.addCell(getPdfPCellInJustified(sdf.format(oleLoanDocument.getCheckInDate()).toString()));
426
427 pdfTable.addCell(getPdfPCellInJustified("Patron Barcode"));
428 pdfTable.addCell(getPdfPCellInLeft(":"));
429 pdfTable.addCell(getPdfPCellInJustified(olePatronDocument != null && olePatronDocument.getBarcode() != null ? olePatronDocument.getBarcode() : ""));
430 }
431 }
432 if (holdSlip) {
433 if (oleCirculationDesk != null) {
434 int noDays = Integer.parseInt(oleCirculationDesk.getOnHoldDays());
435 Calendar calendar = Calendar.getInstance();
436 calendar.add(Calendar.DATE, noDays);
437 Date date = calendar.getTime();
438 if (date != null) {
439 DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
440 pdfTable.addCell(getPdfPCellInJustified("Expiration onHoldDate"));
441 pdfTable.addCell(getPdfPCellInLeft(":"));
442 String dateString = date == null ? "" : df.format(date);
443 pdfTable.addCell(getPdfPCellInJustified(dateString));
444 }
445 }
446 }
447 response.setContentType("application/pdf");
448 if (!missingPieceCheck) {
449 os = response.getOutputStream();
450 PdfWriter.getInstance(document, os);
451 document.open();
452 document.add(paraGraph);
453 document.add(pdfTable);
454 document.close();
455 } else {
456 document.close();
457 }
458 byteArrayOutputStream.flush();
459 byteArrayOutputStream.close();
460 os.flush();
461 os.close();
462 }
463 }catch (Exception e) {
464 LOG.error("Exception while creating pdf for printing slip", e);
465 }
466 }
467
468
469
470
471
472
473
474 public void createPdfForBackGroundCheckOut(OleLoanDocument oleLoanDocument, HttpServletResponse response) {
475 LOG.debug("Initialize Normal pdf Template");
476 LoanProcessor loanProcessor = new LoanProcessor();
477 OlePatronDocument olePatronDocument = oleLoanDocument != null ? loanProcessor.getOlePatronDocument(oleLoanDocument.getPatronId()) : null;
478 if (olePatronDocument != null) {
479 EntityBo entityBo = olePatronDocument.getEntity();
480 EntityNameBo nameBo = entityBo != null ? entityBo.getNames().get(0) : null;
481 String patronName = nameBo != null ? nameBo.getFirstName() + " " + nameBo.getLastName() : null;
482 List<EntityEmailBo> entityEmailBos = entityBo != null && entityBo.getEntityTypeContactInfos().size() > 0 ? entityBo.getEntityTypeContactInfos().get(0).getEmailAddresses() : new ArrayList<EntityEmailBo>();
483 List<EntityAddressBo> entityAddressBos = entityBo != null && entityBo.getEntityTypeContactInfos().size() > 0 ? entityBo.getEntityTypeContactInfos().get(0).getAddresses() : new ArrayList<EntityAddressBo>();
484 String defaultEmailAddress = null;
485 String defaultAddress = "";
486 for (EntityEmailBo entityEmailBo : entityEmailBos) {
487 if (entityEmailBo.isDefaultValue()) {
488 defaultEmailAddress = entityEmailBo.getEmailAddress();
489 break;
490 }
491 }
492 String line1 = "";
493 String line2 = "";
494 String line3 = "";
495 String city = "";
496 String stateProvisionalCode = "";
497 String countryCode = "";
498 String postalCode = "";
499 for (EntityAddressBo entityAddressBo : entityAddressBos) {
500 if (entityAddressBo.isDefaultValue()) {
501 line1 = entityAddressBo.getLine1() != null && !entityAddressBo.getLine1().isEmpty() ? entityAddressBo.getLine1() + OLEConstants.COMMA : "";
502 line2 = entityAddressBo.getLine2() != null && !entityAddressBo.getLine2().isEmpty() ? entityAddressBo.getLine2() + OLEConstants.COMMA : "";
503 line3 = entityAddressBo.getLine3() != null && !entityAddressBo.getLine3().isEmpty() ? entityAddressBo.getLine3() + OLEConstants.COMMA : "";
504 city = entityAddressBo.getCity() != null && !entityAddressBo.getCity().isEmpty() ? entityAddressBo.getCity() + OLEConstants.COMMA : "";
505 stateProvisionalCode = entityAddressBo.getStateProvinceCode() != null && !entityAddressBo.getStateProvinceCode().isEmpty() ? entityAddressBo.getStateProvinceCode() + OLEConstants.COMMA : "";
506 countryCode = entityAddressBo.getCountryCode() != null && !entityAddressBo.getCountryCode().isEmpty() ? entityAddressBo.getCountryCode() + OLEConstants.COMMA : "";
507 postalCode = entityAddressBo.getPostalCode() != null && !entityAddressBo.getPostalCode().isEmpty() ? entityAddressBo.getPostalCode() : "";
508 }
509 }
510 defaultAddress = line1 + line2 + line3 + city + stateProvisionalCode + countryCode + postalCode;
511 try {
512 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
513 populateColorMap();
514 populateFontMap();
515 response.setContentType("application/pdf");
516 OutputStream os = null;
517 Document document = this.getDocument(0, 0, 5, 5);
518 document.open();
519 document.newPage();
520
521 PdfPTable pdfTable = new PdfPTable(1);
522 Paragraph paraGraph = new Paragraph();
523 paraGraph.setAlignment(Element.ALIGN_CENTER);
524 paraGraph.add(new Chunk("Mailing Label", getBoldFont()));
525 paraGraph.add(Chunk.NEWLINE);
526 paraGraph.add(Chunk.NEWLINE);
527 paraGraph.add(Chunk.NEWLINE);
528 pdfTable.setHorizontalAlignment(Element.ALIGN_CENTER);
529 pdfTable.addCell(getPdfPCellInJustified(patronName));
530 if (defaultAddress != null && !defaultAddress.trim().isEmpty()) {
531 if (!line1.isEmpty()) pdfTable.addCell(getPdfPCellInJustified(line1));
532 if (!line2.isEmpty()) pdfTable.addCell(getPdfPCellInJustified(line2));
533 if (!line3.isEmpty()) pdfTable.addCell(getPdfPCellInJustified(line3));
534 if (!city.isEmpty()) pdfTable.addCell(getPdfPCellInJustified(city));
535 if (!stateProvisionalCode.isEmpty()) pdfTable.addCell(getPdfPCellInJustified(stateProvisionalCode));
536 if (!countryCode.isEmpty()) pdfTable.addCell(getPdfPCellInJustified(countryCode));
537 if (!postalCode.isEmpty()) pdfTable.addCell(getPdfPCellInJustified(postalCode));
538 } else {
539 if (defaultEmailAddress != null && !defaultEmailAddress.trim().isEmpty()) {
540 pdfTable.addCell(getPdfPCellInJustified(defaultEmailAddress));
541 }
542 }
543 document.add(pdfTable);
544 response.setContentType("application/pdf");
545 os = response.getOutputStream();
546 PdfWriter.getInstance(document, os);
547 document.open();
548 document.add(paraGraph);
549 document.add(pdfTable);
550 document.close();
551 byteArrayOutputStream.flush();
552 byteArrayOutputStream.close();
553 os.flush();
554 os.close();
555 } catch (Exception e) {
556 LOG.error("Exception while creating pdf for backgroung check out", e);
557 }
558 }
559 }
560
561
562 public void createDueDateSlipPdf(List<OleLoanDocument> oleLoanDocument, HttpServletResponse response) {
563 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
564
565 try {
566 populateColorMap();
567 populateFontMap();
568 SimpleDateFormat dateFormat = new SimpleDateFormat(RiceConstants.SIMPLE_DATE_FORMAT_FOR_DATE);
569 SimpleDateFormat sdf = new SimpleDateFormat(RiceConstants.SIMPLE_DATE_FORMAT_FOR_DATE+" "+RiceConstants.SIMPLE_DATE_FORMAT_FOR_TIME);
570 String date = dateFormat.format(System.currentTimeMillis());
571 response.setContentType("application/pdf");
572 Document document = this.getDocument(0, 0, 5, 5);
573 PdfWriter writer = PdfWriter.getInstance(document, byteArrayOutputStream);
574 document.open();
575 document.newPage();
576
577 PdfPTable pdfTable = new PdfPTable(3);
578 Paragraph paraGraph = new Paragraph();
579 paraGraph.setAlignment(Element.ALIGN_CENTER);
580 paraGraph.add(new Chunk("Due Date Slip", getBoldFont()));
581 paraGraph.add(Chunk.NEWLINE);
582 paraGraph.add(Chunk.NEWLINE);
583 paraGraph.add(Chunk.NEWLINE);
584 LoanProcessor loanProcessor = new LoanProcessor();
585 OleLocation oleLocation = null;
586 OleCirculationDesk oleCirculationDesk = null;
587 try {
588 if (oleLoanDocument.get(0).getCirculationLocationId() != null) {
589 oleCirculationDesk = getCircDeskLocationResolver().getOleCirculationDesk(oleLoanDocument.get(0).getCirculationLocationId());
590 }
591 oleLocation = oleCirculationDesk.getOleCirculationDeskLocations().get(0).getLocation();
592
593 } catch (Exception e) {
594 LOG.error("Exception", e);
595 }
596 String locationName = oleLocation != null ? oleLocation.getLocationName() : null;
597
598
599 for (int dueDateSlip = 0; dueDateSlip < oleLoanDocument.size(); dueDateSlip++) {
600
601 pdfTable.addCell(getPdfPCellInJustified("Circulation Location/Library Name"));
602 pdfTable.addCell(getPdfPCellInLeft(":"));
603 pdfTable.addCell(getPdfPCellInJustified(oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskPublicName() : ""));
604
605 pdfTable.addCell(getPdfPCellInJustified("Item Barcode"));
606 pdfTable.addCell(getPdfPCellInLeft(":"));
607 pdfTable.addCell(getPdfPCellInJustified(oleLoanDocument.get(dueDateSlip).getItemId()));
608
609 pdfTable.addCell(getPdfPCellInJustified("Title"));
610 pdfTable.addCell(getPdfPCellInLeft(":"));
611 pdfTable.addCell(getPdfPCellInJustified(oleLoanDocument.get(dueDateSlip).getTitle()));
612
613 pdfTable.addCell(getPdfPCellInJustified("Call Number"));
614 pdfTable.addCell(getPdfPCellInLeft(":"));
615 pdfTable.addCell(getPdfPCellInJustified(oleLoanDocument.get(dueDateSlip).getItemCallNumber()));
616
617 pdfTable.addCell(getPdfPCellInJustified("Copy Number"));
618 pdfTable.addCell(getPdfPCellInLeft(":"));
619 pdfTable.addCell(getPdfPCellInJustified(oleLoanDocument.get(dueDateSlip).getItemCopyNumber()));
620
621 pdfTable.addCell(getPdfPCellInJustified("Due Date"));
622 pdfTable.addCell(getPdfPCellInLeft(":"));
623 pdfTable.addCell(getPdfPCellInJustified(oleLoanDocument.get(dueDateSlip).getLoanDueDate()!=null?
624 sdf.format(oleLoanDocument.get(dueDateSlip).getLoanDueDate()).toString():""));
625
626 pdfTable.addCell(getPdfPCellInJustified("Patron Barcode"));
627 pdfTable.addCell(getPdfPCellInLeft(":"));
628 pdfTable.addCell(getPdfPCellInJustified(oleLoanDocument.get(dueDateSlip).getPatronBarcode()));
629
630
631
632
633
634
635 pdfTable.addCell(getEmptyCell());
636 pdfTable.addCell(getEmptyCell());
637 pdfTable.addCell(getEmptyCell());
638
639 pdfTable.addCell(getEmptyCell());
640 pdfTable.addCell(getEmptyCell());
641 pdfTable.addCell(getEmptyCell());
642 }
643 response.setContentType("application/pdf");
644 ServletOutputStream sos = response.getOutputStream();
645 PdfWriter.getInstance(document, sos);
646 document.open();
647 document.add(paraGraph);
648 document.add(pdfTable);
649 document.close();
650 String fileName = "Due date slip_" + date;
651
652
653 byteArrayOutputStream.flush();
654 byteArrayOutputStream.close();
655 sos.flush();
656 sos.close();
657
658 } catch (Exception e) {
659 LOG.error("Exception while creating due date pdf slip", e);
660 }
661 }
662
663 private PdfPCell getEmptyCell() {
664 PdfPCell pdfPCell = new PdfPCell(new Paragraph(Chunk.NEWLINE));
665 pdfPCell.setBorder(pdfPCell.NO_BORDER);
666 pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
667 return pdfPCell;
668 }
669
670 private PdfPCell getPdfPCellInJustified(String chunk) {
671 PdfPCell pdfPCell=null;
672 if(chunk!=null){
673 pdfPCell = new PdfPCell(new Paragraph(new Chunk(chunk, getFont(chunk))));
674 }
675 else{
676 pdfPCell = new PdfPCell(new Paragraph());
677 }
678 pdfPCell.setBorder(pdfPCell.NO_BORDER);
679 pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
680 return pdfPCell;
681 }
682
683 private PdfPCell getPdfPCellAligned(String chunk, int font, int val) {
684 PdfPCell pdfPCell = new PdfPCell(new Phrase(chunk,FontFactory.getFont(FontFactory.TIMES_ROMAN, 16, font)));
685 pdfPCell.setBorder(pdfPCell.NO_BORDER);
686 pdfPCell.setPaddingLeft(val);
687 return pdfPCell;
688 }
689
690 private PdfPCell getPdfPCellInLeft(String chunk) {
691 PdfPCell pdfPCell = new PdfPCell(new Paragraph(new Chunk(chunk, getDefaultFont())));
692 pdfPCell.setBorder(pdfPCell.NO_BORDER);
693 pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
694 return pdfPCell;
695 }
696
697 public Document getDocument(float f1, float f2, float f3, float f4) {
698 Document document = new Document(PageSize.A4);
699 document.setMargins(f1, f2, f3, f4);
700 return document;
701 }
702
703 private void getHoldSlipForReceiptPrinter(String patronName, Date expirationDate, boolean missingPieceCheck, OleCirculationDesk oleCirculationDesk, String itemBarcode, String itemTitle, String itemCallNumber, String copyNumber, String volumeNumber, HttpServletResponse response) throws Exception {
704 SimpleDateFormat dateFormat = new SimpleDateFormat(OLEConstants.DATEFORMAT);
705 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
706 OutputStream os = null;
707 Document document = new Document(new Rectangle(253, 430));
708 document.setMargins(0, 0, 5, 5);
709 document.open();
710 document.newPage();
711 PdfPTable pdfTable = new PdfPTable(1);
712 pdfTable.addCell(getEmptyCell());
713 pdfTable.addCell(getEmptyCell());
714 pdfTable.addCell(getPdfPCellAligned("Hold Slip", Font.BOLD, 11));
715 pdfTable.addCell(getEmptyCell());
716 pdfTable.addCell(getPdfPCellAligned(patronName, Font.NORMAL, 11));
717 if (oleCirculationDesk != null) {
718 int noDays = Integer.parseInt(oleCirculationDesk.getOnHoldDays());
719 Calendar calendar = Calendar.getInstance();
720 calendar.add(Calendar.DATE, noDays);
721 Date date = calendar.getTime();
722 if (date != null) {
723 DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
724 String dateString = date == null ? "" : df.format(date);
725 pdfTable.addCell(getPdfPCellAligned(dateString, Font.NORMAL, 11));
726 }
727 }
728 pdfTable.addCell(getEmptyCell());
729 if (!missingPieceCheck) {
730 pdfTable.addCell(getPdfPCellAligned(oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskPublicName() : "", Font.NORMAL, 11));
731 pdfTable.addCell(getPdfPCellAligned(itemBarcode, Font.NORMAL, 11));
732 pdfTable.addCell(getPdfPCellAligned(itemTitle, Font.NORMAL, 11));
733 pdfTable.addCell(getPdfPCellAligned(itemCallNumber, Font.NORMAL, 11));
734 pdfTable.addCell(getPdfPCellAligned(copyNumber, Font.NORMAL, 11));
735 pdfTable.addCell(getPdfPCellAligned(volumeNumber, Font.NORMAL, 11));
736 }
737 pdfTable.addCell(getEmptyCell());
738 pdfTable.addCell(getEmptyCell());
739 pdfTable.addCell(getEmptyCell());
740 pdfTable.addCell(getEmptyCell());
741 pdfTable.addCell(getEmptyCell());
742 pdfTable.addCell(getEmptyCell());
743 pdfTable.addCell(getEmptyCell());
744 pdfTable.addCell(getEmptyCell());
745 response.setContentType("application/pdf");
746 if (!missingPieceCheck) {
747 os = response.getOutputStream();
748 PdfWriter.getInstance(document, os);
749 document.open();
750 document.add(pdfTable);
751 document.close();
752 } else {
753 document.close();
754 }
755 byteArrayOutputStream.flush();
756 byteArrayOutputStream.close();
757 os.flush();
758 os.close();
759 }
760
761 public void createHoldSlipPdf(List<OleLoanDocument> oleLoanDocumentList, HttpServletResponse response, OleCirculationDesk oleCirculationDesk) throws Exception {
762 LoanProcessor loanProcessor = new LoanProcessor();
763 SimpleDateFormat dateFormat = new SimpleDateFormat(OLEConstants.DATEFORMAT);
764 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
765 OutputStream os = null;
766 Document document;
767 PdfPTable pdfTable;
768 if (oleCirculationDesk != null && oleCirculationDesk.getHoldFormat().equals(OLEConstants.RECEIPT_PRINTER)) {
769 document = new Document(new Rectangle(253, 430));
770 document.open();
771 document.newPage();
772 } else {
773 document = this.getDocument(0, 0, 5, 5);
774 document.open();
775 document.newPage();
776 }
777 response.setContentType("application/pdf");
778 os = response.getOutputStream();
779 PdfWriter.getInstance(document, os);
780 document.open();
781 for (OleLoanDocument oleLoanDocument : oleLoanDocumentList) {
782 OleDeliverRequestBo oleDeliverRequestBo = oleLoanDocument.getOleDeliverRequestBo();
783 OlePatronDocument oleRequestPatronDocument = oleDeliverRequestBo != null ? loanProcessor.getOlePatronDocument(oleDeliverRequestBo.getBorrowerId()) : null;
784 EntityNameBo nameBo = oleRequestPatronDocument != null ? oleRequestPatronDocument.getEntity().getNames().get(0) : null;
785 String patronName = nameBo != null ? nameBo.getLastName() + "," + nameBo.getFirstName() : null;
786 Date expirationDate = oleRequestPatronDocument != null ? oleRequestPatronDocument.getExpirationDate() : null;
787 String itemCallNumber = null;
788 String copyNumber = null;
789 String volumeNumber = null;
790 String itemBarcode = oleLoanDocument.getItemId();
791 Item oleItem = oleLoanDocument.getOleItem();
792 if (oleItem != null) {
793 itemCallNumber = loanProcessor.getItemCallNumber(oleItem, oleLoanDocument.getInstanceUuid());
794 copyNumber = oleItem.getCopyNumber();
795 volumeNumber = oleItem.getEnumeration();
796 } else {
797 getItemDetails(loanProcessor, oleLoanDocument, oleItem, itemBarcode);
798 itemCallNumber = loanProcessor.getItemCallNumber(oleItem, oleLoanDocument.getInstanceUuid());
799 copyNumber = oleItem.getCopyNumber();
800 volumeNumber = oleItem.getEnumeration();
801 }
802 if (copyNumber == null) {
803 copyNumber = "";
804 }
805 if (volumeNumber == null) {
806 volumeNumber = "";
807 }
808 if (oleCirculationDesk != null && oleCirculationDesk.getHoldFormat().equals(OLEConstants.RECEIPT_PRINTER)) {
809 pdfTable = new PdfPTable(1);
810 pdfTable.addCell(getPdfPCellAligned("Hold Slip", Font.BOLD, -18));
811 pdfTable.addCell(getEmptyCell());
812 pdfTable.addCell(getPdfPCellAligned(patronName, Font.NORMAL, -18));
813 if (oleCirculationDesk != null) {
814 int noDays = Integer.parseInt(oleCirculationDesk.getOnHoldDays());
815 Calendar calendar = Calendar.getInstance();
816 calendar.add(Calendar.DATE, noDays);
817 Date date = calendar.getTime();
818 if (date != null) {
819 DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
820 String dateString = date == null ? "" : df.format(date);
821 pdfTable.addCell(getPdfPCellAligned(dateString, Font.NORMAL, -18));
822 }
823 }
824 pdfTable.addCell(getEmptyCell());
825 if (!oleLoanDocument.isMissingPieceFlag()) {
826 pdfTable.addCell(getPdfPCellAligned(oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskPublicName() : "", Font.NORMAL, -18));
827 pdfTable.addCell(getPdfPCellAligned(itemBarcode, Font.NORMAL, -18));
828 pdfTable.addCell(getPdfPCellAligned(oleLoanDocument.getTitle(), Font.NORMAL, -18));
829 pdfTable.addCell(getPdfPCellAligned(itemCallNumber, Font.NORMAL, -18));
830 pdfTable.addCell(getPdfPCellAligned(copyNumber, Font.NORMAL, -18));
831 pdfTable.addCell(getPdfPCellAligned(volumeNumber, Font.NORMAL, -18));
832 }
833 pdfTable.addCell(getEmptyCell());
834 pdfTable.addCell(getEmptyCell());
835 pdfTable.addCell(getEmptyCell());
836 pdfTable.addCell(getEmptyCell());
837 document.add(pdfTable);
838 document.newPage();
839
840 } else {
841 pdfTable = new PdfPTable(3);
842 pdfTable.addCell(getEmptyCell());
843 PdfPCell pdfPCell = new PdfPCell(new Phrase("Hold Slip", FontFactory.getFont(FontFactory.TIMES_ROMAN, 15, Font.BOLD)));
844 pdfPCell.setBorder(pdfPCell.NO_BORDER);
845 pdfPCell.setHorizontalAlignment(Element.ALIGN_CENTER);
846 pdfTable.addCell(pdfPCell);
847 pdfTable.addCell(getEmptyCell());
848
849 pdfTable.addCell(getEmptyCell());
850 pdfTable.addCell(getEmptyCell());
851 pdfTable.addCell(getEmptyCell());
852
853 pdfTable.addCell(getEmptyCell());
854 pdfTable.addCell(getEmptyCell());
855 pdfTable.addCell(getEmptyCell());
856
857 pdfTable.addCell(getPdfPCellInJustified("Patron Name"));
858 pdfTable.addCell(getPdfPCellInLeft(":"));
859 pdfTable.addCell(getPdfPCellInJustified(patronName));
860
861 pdfTable.addCell(getPdfPCellInJustified("Expiration Date"));
862 pdfTable.addCell(getPdfPCellInLeft(":"));
863 pdfTable.addCell(getPdfPCellInJustified(expirationDate != null ? dateFormat.format(expirationDate).toString() : null));
864 if (!oleLoanDocument.isMissingPieceFlag()) {
865 pdfTable.addCell(getPdfPCellInJustified("Route From"));
866 pdfTable.addCell(getPdfPCellInLeft(":"));
867 pdfTable.addCell(getPdfPCellInJustified(oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskPublicName() : ""));
868
869 pdfTable.addCell(getPdfPCellInJustified("Item Barcode"));
870 pdfTable.addCell(getPdfPCellInLeft(":"));
871 pdfTable.addCell(getPdfPCellInJustified(itemBarcode));
872
873 pdfTable.addCell(getPdfPCellInJustified("Title"));
874 pdfTable.addCell(getPdfPCellInLeft(":"));
875 pdfTable.addCell(getPdfPCellInJustified(oleLoanDocument.getTitle()));
876
877 pdfTable.addCell(getPdfPCellInJustified("Call Number"));
878 pdfTable.addCell(getPdfPCellInLeft(":"));
879 pdfTable.addCell(getPdfPCellInJustified(itemCallNumber));
880
881 pdfTable.addCell(getPdfPCellInJustified("Copy Number"));
882 pdfTable.addCell(getPdfPCellInLeft(":"));
883 pdfTable.addCell(getPdfPCellInJustified(copyNumber));
884
885 if (oleCirculationDesk != null) {
886 int noDays = Integer.parseInt(oleCirculationDesk.getOnHoldDays());
887 Calendar calendar = Calendar.getInstance();
888 calendar.add(Calendar.DATE, noDays);
889 Date date = calendar.getTime();
890 if (date != null) {
891 DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
892 pdfTable.addCell(getPdfPCellInJustified("Expiration onHoldDate"));
893 pdfTable.addCell(getPdfPCellInLeft(":"));
894 String dateString = date == null ? "" : df.format(date);
895 pdfTable.addCell(getPdfPCellInJustified(dateString));
896 }
897 }
898 }
899 pdfTable.addCell(getEmptyCell());
900 pdfTable.addCell(getEmptyCell());
901 pdfTable.addCell(getEmptyCell());
902 document.add(pdfTable);
903 document.newPage();
904 }
905 }
906 document.close();
907 byteArrayOutputStream.flush();
908 byteArrayOutputStream.close();
909 os.flush();
910 os.close();
911 }
912
913 private void getItemDetails(LoanProcessor loanProcessor, OleLoanDocument oleLoanDocument, Item oleItem, String itemBarcode) throws Exception {
914 org.kuali.ole.docstore.common.document.Item item = new ItemOleml();
915 org.kuali.ole.docstore.common.search.SearchParams search_Params = new org.kuali.ole.docstore.common.search.SearchParams();
916 SearchResponse searchResponse = null;
917 search_Params.getSearchConditions().add(search_Params.buildSearchCondition("phrase", search_Params.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), item.ITEM_BARCODE, itemBarcode), ""));
918 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(DocType.ITEM.getCode(), "id"));
919 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.HOLDINGS.getCode(), "id"));
920 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode(), "id"));
921 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode(), Bib.TITLE));
922 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode(), Bib.AUTHOR));
923 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(search_Params);
924 for (SearchResult searchResult : searchResponse.getSearchResults()) {
925 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
926 String fieldName = searchResultField.getFieldName();
927 String fieldValue = searchResultField.getFieldValue() != null ? searchResultField.getFieldValue() : "";
928 if (fieldName.equalsIgnoreCase("id") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("holdings")) {
929 oleLoanDocument.setInstanceUuid(fieldValue);
930 } else if (fieldName.equalsIgnoreCase("id") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("item")) {
931 oleLoanDocument.setItemUuid(fieldValue);
932 } else if (fieldName.equalsIgnoreCase(Bib.TITLE) && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("bibliographic")) {
933 oleLoanDocument.setTitle(fieldValue);
934 } else if (fieldName.equalsIgnoreCase(Bib.AUTHOR) && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("bibliographic")) {
935 oleLoanDocument.setAuthor(fieldValue);
936 }
937 }
938 }
939 String itemXml = null;
940 itemXml = loanProcessor.getItemXML(oleLoanDocument.getItemUuid());
941 oleItem = loanProcessor.getItemPojo(itemXml);
942 }
943 }
944
945