View Javadoc
1   package org.kuali.ole.deliver.batch;
2   
3   import com.lowagie.text.*;
4   import com.lowagie.text.Font;
5   import com.lowagie.text.pdf.PdfPCell;
6   import com.lowagie.text.pdf.PdfPTable;
7   import com.lowagie.text.pdf.PdfWriter;
8   import org.apache.log4j.Logger;
9   import org.kuali.ole.OLEConstants;
10  import org.kuali.ole.OLEParameterConstants;
11  import org.kuali.ole.deliver.bo.*;
12  import org.kuali.ole.deliver.processor.LoanProcessor;
13  import org.kuali.ole.deliver.service.OleDeliverRequestDocumentHelperServiceImpl;
14  import org.kuali.ole.describe.bo.OleLocation;
15  import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
16  import org.kuali.ole.docstore.common.document.Bib;
17  import org.kuali.ole.docstore.common.document.Item;
18  import org.kuali.ole.docstore.common.document.ItemOleml;
19  import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor;
20  import org.kuali.ole.docstore.common.search.SearchResponse;
21  import org.kuali.ole.docstore.common.search.SearchResult;
22  import org.kuali.ole.docstore.common.search.SearchResultField;
23  import org.kuali.ole.sys.context.SpringContext;
24  import org.kuali.rice.core.api.config.property.ConfigContext;
25  import org.kuali.rice.kim.impl.identity.type.EntityTypeContactInfoBo;
26  import org.kuali.rice.krad.service.BusinessObjectService;
27  import org.kuali.rice.krad.service.KRADServiceLocator;
28  
29  import javax.servlet.http.HttpServletResponse;
30  import java.awt.*;
31  import java.io.File;
32  import java.io.FileOutputStream;
33  import java.io.OutputStream;
34  import java.text.SimpleDateFormat;
35  import java.util.*;
36  import java.util.List;
37  
38  /**
39   * Created with IntelliJ IDEA.
40   * User: ?
41   * Date: 12/31/12
42   * Time: 5:30 PM
43   * To change this template use File | Settings | File Templates.
44   */
45  public class OleDeliverBatchServiceImpl {
46  
47      private LoanProcessor loanProcessor;
48      private Font boldFont = new Font(Font.TIMES_ROMAN, 15, Font.BOLD);
49      private Font ver_15_normal = FontFactory.getFont("VERDANA", 15, 0);
50      private DocstoreClientLocator docstoreClientLocator;
51      private OutputStream overdueOutPutStream=null;
52      private Document overdueDocument=null;
53  
54      public DocstoreClientLocator getDocstoreClientLocator() {
55  
56          if (docstoreClientLocator == null) {
57              docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
58  
59          }
60          return docstoreClientLocator;
61      }
62  
63  
64      public void setDocstoreClientLocator(DocstoreClientLocator docstoreClientLocator) {
65          this.docstoreClientLocator = docstoreClientLocator;
66      }
67  
68      public void setLoanProcessor(LoanProcessor loanProcessor) {
69          this.loanProcessor = loanProcessor;
70      }
71  
72      private static final Logger LOG = Logger.getLogger(OleDeliverBatchServiceImpl.class);
73  
74      /**
75       * This method initiate LoanProcessor.
76       *
77       * @return LoanProcessor
78       */
79      private LoanProcessor getLoanProcessor() {
80          if (loanProcessor == null) {
81              loanProcessor = SpringContext.getBean(LoanProcessor.class);
82          }
83          return loanProcessor;
84      }
85  
86      public OutputStream getOverdueOutPutStream() {
87          return overdueOutPutStream;
88      }
89  
90      public void setOverdueOutPutStream(OutputStream overdueOutPutStream) {
91          this.overdueOutPutStream = overdueOutPutStream;
92      }
93  
94      public Document getOverdueDocument() {
95          return overdueDocument;
96      }
97  
98      public void setOverdueDocument(Document overdueDocument) {
99          this.overdueDocument = overdueDocument;
100     }
101 
102     private void getHTMLHeader(StringBuffer stringBuffer, String title) throws Exception {
103         stringBuffer.append("<HTML>");
104         stringBuffer.append("<TITLE>" + title + "</TITLE>");
105         stringBuffer.append("<HEAD></HEAD>");
106         stringBuffer.append("<BODY>");
107     }
108 
109     private void getTemplateHeader(OleNoticeBo noticeBo, StringBuffer stringBuffer) throws Exception {
110 
111         stringBuffer.append("<TABLE></BR></BR>");
112         stringBuffer.append("<TR><TD>Patron Name :</TD><TD>" + noticeBo.getPatronName() + "</TD></TR>");
113         stringBuffer.append("<TR><TD>Address :</TD><TD>" + noticeBo.getPatronAddress() + "</TD></TR>");
114         stringBuffer.append("<TR><TD>EMAIL :</TD><TD>" + noticeBo.getPatronEmailAddress() + "</TD></TR>");
115         stringBuffer.append("<TR><TD>Phone Number :</TD><TD>" + ( noticeBo.getPatronPhoneNumber()!=null ? noticeBo.getPatronPhoneNumber() : "") + "</TD></TR>");
116         stringBuffer.append("</TABLE>");
117     }
118 
119     private void getTemplateBody(StringBuffer stringBuffer, String title, String body) throws Exception {
120         stringBuffer.append("<TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>");
121         stringBuffer.append("<TABLE width=\"100%\">");
122         stringBuffer.append("<TR><TD><CENTER>" + title + "</CENTER></TD></TR>");
123         stringBuffer.append("<TR><TD><p>" + body + "</p></TD></TR>");
124         stringBuffer.append("<TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR></TABLE>");
125     }
126 
127     public BusinessObjectService getBusinessObjectService() {
128         BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
129         return businessObjectService;
130     }
131 
132     private String itemShelvingLocationName(String code) {
133         Map<String, String> criteria = new HashMap<String, String>();
134         criteria.put("locationCode", code);
135         List<OleLocation> oleLocation = (List<OleLocation>) getBusinessObjectService().findMatching(OleLocation.class, criteria);
136 
137         return oleLocation.size() == 1 ? oleLocation.get(0).getLocationName() : "";
138     }
139 
140     private void getTemplateFooter(OleNoticeBo noticeBo, StringBuffer stringBuffer) throws Exception {
141         SimpleDateFormat sdf = new SimpleDateFormat(OLEConstants.TIMESTAMP);
142         stringBuffer.append("<table>");
143         if (!(noticeBo.getNoticeName().equalsIgnoreCase(OLEConstants.NOTICE_RECALL) || noticeBo.getNoticeName().equalsIgnoreCase(OLEConstants.CANCELLATION_NOTICE))) {
144             stringBuffer.append("<TR><TD>Circulation Location/Library Name :</TD><TD>" + (noticeBo.getCirculationDeskName() != null ? noticeBo.getCirculationDeskName() : "") + "</TD></TR>");
145         }
146         stringBuffer.append("<TR><TD>Title :</TD><TD>" + (noticeBo.getTitle()!=null ? noticeBo.getTitle() : "") + "</TD></TR>");
147         stringBuffer.append("<TR><TD>Author :</TD><TD>" + (noticeBo.getAuthor()!=null ? noticeBo.getAuthor() : "") + "</TD></TR>");
148         if (!noticeBo.getNoticeName().equalsIgnoreCase(OLEConstants.CANCELLATION_NOTICE)){
149             stringBuffer.append("<TR><TD>Volume/Issue/Copy Number :</TD><TD>" + (noticeBo.getVolumeIssueCopyNumber()!=null ? noticeBo.getVolumeIssueCopyNumber() : "") + "</TD></TR>");
150         }
151         stringBuffer.append("<TR><TD>Library shelving location :</TD><TD>" + (itemShelvingLocationName(noticeBo.getItemShelvingLocation())!=null ? itemShelvingLocationName(noticeBo.getItemShelvingLocation()) : "" )+ "</TD></TR>");
152 
153         stringBuffer.append("<TR><TD>Call Number :</TD><TD>" +(noticeBo.getItemCallNumber()!=null ? noticeBo.getItemCallNumber() : "") + "</TD></TR>");
154         stringBuffer.append("<TR><TD>Item Barcode :</TD><TD>" +(noticeBo.getItemId()!=null ? noticeBo.getItemId() : "") + "</TD></TR>");
155         if (noticeBo.getNoticeName().equalsIgnoreCase(OLEConstants.NOTICE_OVERDUE)) {
156             stringBuffer.append("<TR><TD>Item was due :</TD><TD>" +( noticeBo.getDueDate()!=null ? sdf.format(noticeBo.getDueDate()).toString() : "" )+ "</TD></TR>");
157         }
158         if (noticeBo.getNoticeName().equalsIgnoreCase(OLEConstants.NOTICE_RECALL)) {
159             stringBuffer.append("<TR><TD>Original due date:</TD><TD>" + (noticeBo.getOriginalDueDate()!=null ? sdf.format(noticeBo.getOriginalDueDate()) : "") + "</TD></TR>");
160             stringBuffer.append("<TR><TD>New due date:</TD><TD>" + (noticeBo.getNewDueDate()!=null ? sdf.format(noticeBo.getNewDueDate()) : "") + "</TD></TR>");
161         }
162         stringBuffer.append("<TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>");
163         stringBuffer.append("</table>");
164     }
165 
166     private void getTemplateFooterList(List<OleNoticeBo> noticeBoList, StringBuffer stringBuffer) throws Exception {
167         SimpleDateFormat sdf = new SimpleDateFormat(OLEConstants.TIMESTAMP);
168         for (int courtesy = 0; courtesy < noticeBoList.size(); courtesy++) {
169             stringBuffer.append("<table>");
170             if (courtesy == 0) {
171                 stringBuffer.append("<TR><TD>Title/item information</TD></TR>");
172                 stringBuffer.append("<TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>");
173             }
174             stringBuffer.append("<TR><TD>Title :</TD><TD>" + (noticeBoList.get(courtesy).getTitle() != null ? noticeBoList.get(courtesy).getTitle() : "") + "</TD></TR>");
175             stringBuffer.append("<TR><TD>Author :</TD><TD>" + (noticeBoList.get(courtesy).getAuthor() != null ? noticeBoList.get(courtesy).getAuthor() : "") + "</TD></TR>");
176             if (!noticeBoList.get(courtesy).getNoticeName().equalsIgnoreCase(OLEConstants.CANCELLATION_NOTICE)) {
177                 stringBuffer.append("<TR><TD>Volume/Issue/Copy Number :</TD><TD>" + (noticeBoList.get(courtesy).getVolumeIssueCopyNumber() != null ? noticeBoList.get(courtesy).getVolumeIssueCopyNumber() : "") + "</TD></TR>");
178             }
179             if (noticeBoList.get(courtesy).getNoticeName().equalsIgnoreCase(OLEConstants.NOTICE_OVERDUE)) {
180                 stringBuffer.append("<TR><TD>Item was due :</TD><TD>" + (noticeBoList.get(courtesy).getDueDate() != null ? sdf.format(noticeBoList.get(courtesy).getDueDate()).toString() : "") + "</TD></TR>");
181             }
182             stringBuffer.append("<TR><TD>Library shelving location :</TD><TD>" + (itemShelvingLocationName(noticeBoList.get(courtesy).getItemShelvingLocation()) != null ? itemShelvingLocationName(noticeBoList.get(courtesy).getItemShelvingLocation()) : "") + "</TD></TR>");
183             stringBuffer.append("<TR><TD>Call Number :</TD><TD>" + (noticeBoList.get(courtesy).getItemCallNumber() != null ? noticeBoList.get(courtesy).getItemCallNumber() : "") + "</TD></TR>");
184             stringBuffer.append("<TR><TD>Item Barcode :</TD><TD>" + (noticeBoList.get(courtesy).getItemId() != null ? noticeBoList.get(courtesy).getItemId() : "") + "</TD></TR>");
185             stringBuffer.append("<TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>");
186             stringBuffer.append("</table>");
187         }
188     }
189 
190 
191     private void getPickUpLocationTemplate(OleNoticeBo noticeBo, StringBuffer stringBuffer) throws Exception {
192         SimpleDateFormat sdf = new SimpleDateFormat(OLEConstants.TIMESTAMP);
193         stringBuffer.append("<table>");
194         stringBuffer.append("<TR><TD>Pick up location :</TD><TD></TD></TR>");
195         if (!noticeBo.getNoticeName().equalsIgnoreCase(OLEConstants.NOTICE_RECALL)) {
196             stringBuffer.append("<TR><TD>Circulation Location/Library Name :</TD><TD>" + (noticeBo.getCirculationDeskName() != null ? noticeBo.getCirculationDeskName() : "") + "</TD></TR>");
197         }
198         stringBuffer.append("<TR><TD>Address :</TD><TD>" + (noticeBo.getCirculationDeskAddress()!=null ? noticeBo.getCirculationDeskAddress() : "" )+ "</TD></TR>");
199         stringBuffer.append("<TR><TD>Email :</TD><TD>" + (noticeBo.getCirculationDeskEmailAddress()!=null ? noticeBo.getCirculationDeskEmailAddress() : "" )+ "</TD></TR>");
200         stringBuffer.append("<TR><TD>Phone Number :</TD><TD>" +( noticeBo.getCirculationDeskPhoneNumber()!=null ? noticeBo.getCirculationDeskPhoneNumber() : "") + "</TD></TR>");
201         if (noticeBo.getNoticeName() != null && noticeBo.getNoticeName().equalsIgnoreCase(OLEConstants.NOTICE_ONHOLD)) {
202             SimpleDateFormat dateFormat = new SimpleDateFormat(OLEConstants.DATEFORMAT);
203             if(noticeBo.getExpiredOnHoldDate() != null){
204                 String dateAfterFormat=dateFormat.format(noticeBo.getExpiredOnHoldDate());
205                 stringBuffer.append("<TR><TD>Item will be held until</TD><TD>" + dateAfterFormat + "</TD></TR>");
206             }
207 
208         } else {
209             stringBuffer.append("<TR><TD>Item will be held until</TD><TD>" +( noticeBo.getDueDate()!=null ?sdf.format( noticeBo.getDueDate()).toString() : "") + "</TD></TR>");
210         }
211         stringBuffer.append("</table>");
212     }
213 
214     private void getHTMLFooter(StringBuffer stringBuffer) throws Exception {
215         String url = ConfigContext.getCurrentContextConfig().getProperty("ole.fs.url.base");
216        String myAccountURL = loanProcessor.getParameter(OLEConstants.MY_ACCOUNT_URL);
217         if(myAccountURL!=null && !myAccountURL.trim().isEmpty()){
218         stringBuffer.append("<TABLE width=\"100%\"><TR><TD><CENTER><a href = "+myAccountURL+">"+"My Account"+"</a></CENTER></TD></TR></TABLE>");
219         }
220         stringBuffer.append("</TABLE></BODY></HTML>");
221         if (LOG.isDebugEnabled()){
222             LOG.debug("MAIL HTML CONTENT : "+stringBuffer.toString());
223         }
224     }
225 
226     private Map getSMSTemplate(List<OleNoticeBo> noticeBo) throws Exception {
227         List<OleNoticeBo> overDueNoticeList = new ArrayList<OleNoticeBo>();
228         List<OleNoticeBo> onHoldNoticeList = new ArrayList<OleNoticeBo>();
229         List<OleNoticeBo> recallNoticeList = new ArrayList<OleNoticeBo>();
230         List<OleNoticeBo> expiredNoticeList = new ArrayList<OleNoticeBo>();
231         List<OleNoticeBo> expiredRequiredNoticeList = new ArrayList<OleNoticeBo>();
232         Map smsMap = new HashMap();
233         for (int temp = 0; temp < noticeBo.size(); temp++) {
234             if (noticeBo.get(temp).getNoticeName().equalsIgnoreCase(OLEConstants.NOTICE_OVERDUE)) {
235                 overDueNoticeList.add(noticeBo.get(temp));
236             }
237             if (noticeBo.get(temp).getNoticeName().equalsIgnoreCase(OLEConstants.NOTICE_ONHOLD)) {
238                 onHoldNoticeList.add(noticeBo.get(temp));
239             }
240             if (noticeBo.get(temp).getNoticeName().equalsIgnoreCase(OLEConstants.OleDeliverRequest.RECALL)) {
241                 recallNoticeList.add(noticeBo.get(temp));
242             }
243             if (noticeBo.get(temp).getNoticeName().equalsIgnoreCase(OLEConstants.NOTICE_HOLD_COURTESY)) {
244                 expiredNoticeList.add(noticeBo.get(temp));
245             }
246             if (noticeBo.get(temp).getNoticeName().equalsIgnoreCase(OLEConstants.OleDeliverRequest.EXPIRED_REQUEST)) {
247                 expiredRequiredNoticeList.add(noticeBo.get(temp));
248             }
249         }
250         Map overdue = new HashMap();
251         if (overDueNoticeList != null && overDueNoticeList.size() > 0) {
252             overdue = getOverDueList(overdue, overDueNoticeList);
253         }
254         Map hod = new HashMap();
255         if (onHoldNoticeList != null && onHoldNoticeList.size() > 0) {
256             hod = getHoldList(hod, onHoldNoticeList);
257         }
258         Map recl = new HashMap();
259         if (recallNoticeList != null && recallNoticeList.size() > 0) {
260             recl = getRecallList(recl, recallNoticeList);
261         }
262         Map exp = new HashMap();
263         if (expiredNoticeList != null && expiredNoticeList.size() > 0) {
264             exp = getExpiredList(exp, expiredNoticeList);
265         }
266         Map expReq = new HashMap();
267         if (expiredRequiredNoticeList != null && expiredRequiredNoticeList.size() > 0) {
268             expReq = getExpiredRequiredList(expReq, expiredRequiredNoticeList);
269         }
270 
271         smsMap.put("OVERDUE", overdue);
272         smsMap.put("HOLD", hod);
273         smsMap.put("RECALL", recl);
274         smsMap.put("EXPIRED", exp);
275         smsMap.put("EXPIREDREQ", expReq);
276         return smsMap;
277     }
278 
279     private Map getExpiredRequiredList(Map expReq, List expiredRequiredNoticeList) throws Exception {
280         String smsExpiredReq = "";
281         LoanProcessor loanProcessor = getLoanProcessor();
282         SimpleDateFormat sdf = new SimpleDateFormat(OLEConstants.TIMESTAMP);
283         for (int exReq = 0; exReq < expiredRequiredNoticeList.size(); exReq++) {
284             OleNoticeBo oleNoticeBo = (OleNoticeBo) expiredRequiredNoticeList.get(exReq);
285             smsExpiredReq = loanProcessor.getParameter("EXP_REQ_TITLE") + "    " + "Circulation Location/Library Name :" + oleNoticeBo.getCirculationDeskName() + ",Address :" + oleNoticeBo.getCirculationDeskAddress() + ",Title :" + oleNoticeBo.getTitle() + ",Call Number :" + oleNoticeBo.getItemCallNumber() + ",Item was due :" + sdf.format(oleNoticeBo.getDueDate()).toString();
286             expReq.put(exReq, smsExpiredReq);
287         }
288         return expReq;
289     }
290 
291     private Map getExpiredList(Map expire, List expiredNoticeList) throws Exception {
292         String smsExpire = "";
293         LoanProcessor loanProcessor = getLoanProcessor();
294         SimpleDateFormat sdf = new SimpleDateFormat(OLEConstants.TIMESTAMP);
295         for (int exp = 0; exp < expiredNoticeList.size(); exp++) {
296             OleNoticeBo oleNoticeBo = (OleNoticeBo) expiredNoticeList.get(exp);
297             smsExpire = loanProcessor.getParameter(OLEParameterConstants.EXPIRED_TITLE) + "    " + "Circulation Location/Library Name :" + oleNoticeBo.getCirculationDeskName() + ",Address :" + oleNoticeBo.getCirculationDeskAddress() + ",Title :" + oleNoticeBo.getTitle() + ",Call Number :" + oleNoticeBo.getItemCallNumber() + ",Item was due :" + sdf.format(oleNoticeBo.getDueDate()).toString();
298             expire.put(exp, smsExpire);
299         }
300         return expire;
301     }
302 
303     private Map getRecallList(Map rcall, List recallNoticeList) throws Exception {
304         String smsRecall = "";
305         LoanProcessor loanProcessor = getLoanProcessor();
306         SimpleDateFormat sdf = new SimpleDateFormat(OLEConstants.TIMESTAMP);
307         for (int recall = 0; recall < recallNoticeList.size(); recall++) {
308             OleNoticeBo oleNoticeBo = (OleNoticeBo) recallNoticeList.get(recall);
309             smsRecall = loanProcessor.getParameter(OLEParameterConstants.RECALL_TITLE) + "    " + "Circulation Location/Library Name :" + oleNoticeBo.getCirculationDeskName() + ",Address :" + oleNoticeBo.getCirculationDeskAddress() + ",Title :" + oleNoticeBo.getTitle() + ",Call Number :" + oleNoticeBo.getItemCallNumber() + ",Original due date :" + sdf.format(oleNoticeBo.getDueDate()).toString() + ",New due date: " + sdf.format(oleNoticeBo.getNewDueDate());
310             rcall.put(recall, smsRecall);
311         }
312         return rcall;
313     }
314 
315     private Map getHoldList(Map hod, List onHoldNoticeList) throws Exception {
316         String smsHod = "";
317         LoanProcessor loanProcessor = getLoanProcessor();
318         SimpleDateFormat sdf = new SimpleDateFormat(OLEConstants.TIMESTAMP);
319         for (int hold = 0; hold < onHoldNoticeList.size(); hold++) {
320             OleNoticeBo oleNoticeBo = (OleNoticeBo) onHoldNoticeList.get(hold);
321             smsHod = loanProcessor.getParameter(OLEParameterConstants.ONHOLD_TITLE) + "    " + "Circulation Location/Library Name :" + oleNoticeBo.getCirculationDeskName() + ",Address :" + oleNoticeBo.getCirculationDeskAddress() + ",Title :" + oleNoticeBo.getTitle() + ",Call Number :" + oleNoticeBo.getItemCallNumber() + ",Item will be held until :" + sdf.format(oleNoticeBo.getDueDate()).toString() + ",Pick up location:" + oleNoticeBo.getCirculationDeskName() + ",Pick up location Address :" + oleNoticeBo.getCirculationDeskAddress();
322             hod.put(hold, smsHod);
323         }
324         return hod;
325     }
326 
327 
328     private Map getOverDueList(Map overdue, List overDueNoticeList) throws Exception {
329         String smsDue = "";
330         LoanProcessor loanProcessor = getLoanProcessor();
331         SimpleDateFormat sdf = new SimpleDateFormat(OLEConstants.TIMESTAMP);
332         for (int due = 0; due < overDueNoticeList.size(); due++) {
333             OleNoticeBo oleNoticeBo = (OleNoticeBo) overDueNoticeList.get(due);
334             smsDue = loanProcessor.getParameter(OLEParameterConstants.OVERDUE_TITLE) + "    " + "Circulation Location/Library Name :" + oleNoticeBo.getCirculationDeskName() + ",Address :" + oleNoticeBo.getCirculationDeskAddress() + ",Title :" + oleNoticeBo.getTitle() + ",Call Number :" + oleNoticeBo.getItemCallNumber() + ",Item was due :" + sdf.format(oleNoticeBo.getDueDate()).toString();
335             overdue.put(due, smsDue);
336         }
337 
338         return overdue;
339     }
340 
341     private List getTemplate(List<OleNoticeBo> noticeBo) throws Exception {
342         StringBuffer stringBuffer = new StringBuffer();
343 
344         List templateForNoticeList = new ArrayList();
345         List<OleNoticeBo> overDueNoticeList = new ArrayList<OleNoticeBo>();
346         List<OleNoticeBo> onHoldNoticeList = new ArrayList<OleNoticeBo>();
347         List<OleNoticeBo> recallNoticeList = new ArrayList<OleNoticeBo>();
348         List<OleNoticeBo> expiredNoticeList = new ArrayList<OleNoticeBo>();
349         List<OleNoticeBo> expiredRequiredNoticeList = new ArrayList<OleNoticeBo>();
350         List<OleNoticeBo> courtesyNoticeList = new ArrayList<OleNoticeBo>();
351         List<OleNoticeBo> cancellationNoticeList = new ArrayList<OleNoticeBo>();
352 
353         for (int temp = 0; temp < noticeBo.size(); temp++) {
354             if (noticeBo.get(temp).getNoticeName().equalsIgnoreCase(OLEConstants.NOTICE_OVERDUE)) {
355                 overDueNoticeList.add(noticeBo.get(temp));
356             }
357             if (noticeBo.get(temp).getNoticeName().equalsIgnoreCase(OLEConstants.NOTICE_ONHOLD)) {
358                 onHoldNoticeList.add(noticeBo.get(temp));
359             }
360             if (noticeBo.get(temp).getNoticeName().equalsIgnoreCase("RecallNotice")) {
361                 recallNoticeList.add(noticeBo.get(temp));
362             }
363             if (noticeBo.get(temp).getNoticeName().equalsIgnoreCase(OLEConstants.NOTICE_HOLD_COURTESY)) {
364                 expiredNoticeList.add(noticeBo.get(temp));
365             }
366             if (noticeBo.get(temp).getNoticeName().equalsIgnoreCase(OLEConstants.OleDeliverRequest.EXPIRED_REQUEST)) {
367                 expiredRequiredNoticeList.add(noticeBo.get(temp));
368             }
369             if (noticeBo.get(temp).getNoticeName().equalsIgnoreCase(OLEConstants.NOTICE_COURTESY)) {
370                 courtesyNoticeList.add(noticeBo.get(temp));
371             }
372             if (noticeBo.get(temp).getNoticeName().equalsIgnoreCase(OLEConstants.CANCELLATION_NOTICE)) {
373                 cancellationNoticeList.add(noticeBo.get(temp));
374             }
375         }
376 
377         LoanProcessor loanProcessor = getLoanProcessor();
378 
379         if (overDueNoticeList != null && overDueNoticeList.size() > 0) {
380             getHTMLHeader(stringBuffer, loanProcessor.getParameter(OLEParameterConstants.OVERDUE_TITLE));
381             getTemplateHeader(overDueNoticeList.get(0), stringBuffer);
382             getTemplateBody(stringBuffer, loanProcessor.getParameter(OLEParameterConstants.OVERDUE_TITLE), loanProcessor.getParameter(OLEParameterConstants.OVERDUE_BODY));
383             getTemplateFooterList(overDueNoticeList, stringBuffer);
384             getHTMLFooter(stringBuffer);
385         }
386 
387         if (onHoldNoticeList != null && onHoldNoticeList.size() > 0) {
388             getHTMLHeader(stringBuffer, loanProcessor.getParameter(OLEParameterConstants.ONHOLD_TITLE));
389             getTemplateHeader(onHoldNoticeList.get(0), stringBuffer);
390             getTemplateBody(stringBuffer, loanProcessor.getParameter(OLEParameterConstants.ONHOLD_TITLE), loanProcessor.getParameter(OLEParameterConstants.ONHOLD_BODY));
391             for (int onHold = 0; onHold < onHoldNoticeList.size(); onHold++) {
392                 getTemplateFooter(noticeBo.get(onHold), stringBuffer);
393                 getPickUpLocationTemplate(noticeBo.get(onHold), stringBuffer);
394             }
395             getHTMLFooter(stringBuffer);
396         }
397 
398         if (recallNoticeList != null && recallNoticeList.size() > 0) {
399             getHTMLHeader(stringBuffer, loanProcessor.getParameter(OLEParameterConstants.RECALL_TITLE));
400             getTemplateHeader(recallNoticeList.get(0), stringBuffer);
401             getTemplateBody(stringBuffer, loanProcessor.getParameter(OLEParameterConstants.RECALL_TITLE), loanProcessor.getParameter(OLEParameterConstants.RECALL_BODY));
402             for (int recall = 0; recall < recallNoticeList.size(); recall++) {
403                 getTemplateFooter(noticeBo.get(recall), stringBuffer);
404             }
405             getHTMLFooter(stringBuffer);
406         }
407 
408         if (expiredNoticeList != null && expiredNoticeList.size() > 0) {
409             getHTMLHeader(stringBuffer, loanProcessor.getParameter(OLEParameterConstants.EXPIRED_TITLE));
410             getTemplateHeader(expiredNoticeList.get(0), stringBuffer);
411             getTemplateBody(stringBuffer, loanProcessor.getParameter(OLEParameterConstants.EXPIRED_TITLE), loanProcessor.getParameter(OLEParameterConstants.EXPIRED_BODY));
412 
413             for (int exp = 0; exp < expiredNoticeList.size(); exp++) {
414                 getTemplateFooter(noticeBo.get(exp), stringBuffer);
415             }
416             getHTMLFooter(stringBuffer);
417         }
418 
419         if (expiredRequiredNoticeList != null && expiredRequiredNoticeList.size() > 0) {
420             getHTMLHeader(stringBuffer, loanProcessor.getParameter(OLEParameterConstants.EXP_REQ_TITLE));
421             getTemplateHeader(expiredRequiredNoticeList.get(0), stringBuffer);
422             getTemplateBody(stringBuffer, loanProcessor.getParameter(OLEParameterConstants.EXP_REQ_TITLE), loanProcessor.getParameter(OLEParameterConstants.EXP_REQ_BODY));
423             for (int exReq = 0; exReq < expiredRequiredNoticeList.size(); exReq++) {
424                 getTemplateFooter(noticeBo.get(exReq), stringBuffer);
425             }
426             getHTMLFooter(stringBuffer);
427         }
428         if (courtesyNoticeList != null && courtesyNoticeList.size() > 0) {
429             getHTMLHeader(stringBuffer, loanProcessor.getParameter(OLEParameterConstants.COURTESY_TITLE));
430             getTemplateHeader(courtesyNoticeList.get(0), stringBuffer);
431             getTemplateBody(stringBuffer, loanProcessor.getParameter(OLEParameterConstants.COURTESY_TITLE), loanProcessor.getParameter(OLEParameterConstants.COURTESY_BODY));
432             getTemplateFooterList(courtesyNoticeList, stringBuffer);
433             getHTMLFooter(stringBuffer);
434         }
435         if (cancellationNoticeList != null && cancellationNoticeList.size() > 0) {
436             getHTMLHeader(stringBuffer, loanProcessor.getParameter("CANCELLATION_NOTICE"));
437             getTemplateHeader(cancellationNoticeList.get(0), stringBuffer);
438             getTemplateBody(stringBuffer, loanProcessor.getParameter("CANCELLATION_NOTICE"), loanProcessor.getParameter(OLEParameterConstants.CANCELLATION_BODY));
439             for (int exReq = 0; exReq < cancellationNoticeList.size(); exReq++) {
440                 getTemplateFooter(noticeBo.get(exReq), stringBuffer);
441             }
442             getHTMLFooter(stringBuffer);
443         }
444         templateForNoticeList.add(stringBuffer);
445 
446         return templateForNoticeList;
447     }
448 
449     private OutputStream getPdfHeader(Document document, OutputStream outputStream, String title, String itemId) throws Exception {
450         StringBuffer stringBuffer = new StringBuffer();
451         String pdfLocationSystemParam = getLoanProcessor().getParameter(OLEParameterConstants.PDF_LOCATION);
452         if (LOG.isDebugEnabled()) {
453             LOG.debug("System Parameter for PDF_Location --> " + pdfLocationSystemParam);
454         }
455         if (pdfLocationSystemParam == null || pdfLocationSystemParam.trim().isEmpty()) {
456             pdfLocationSystemParam = ConfigContext.getCurrentContextConfig().getProperty("staging.directory") + "/";
457             if (LOG.isDebugEnabled()) {
458                 LOG.debug("System Parameter for PDF_Location staging dir--> " + pdfLocationSystemParam);
459             }
460         } else {
461             pdfLocationSystemParam = ConfigContext.getCurrentContextConfig().getProperty("homeDirectory") + "/" + pdfLocationSystemParam + "/";
462         }
463         boolean locationExist = new File(pdfLocationSystemParam).exists();
464         boolean fileCreated = false;
465         if (LOG.isDebugEnabled()) {
466             LOG.debug("Is directory Exist ::" + locationExist);
467         }
468         try {
469             if (!locationExist) {
470                 fileCreated = new File(pdfLocationSystemParam).mkdirs();
471                 if (!fileCreated) {
472                     throw new RuntimeException("Not Able to create directory :" + pdfLocationSystemParam);
473                 }
474             }
475         } catch (Exception e) {
476             LOG.error("Exception occured while creating the directory : " + e.getMessage(), e);
477             throw e;
478         }
479 
480         if (title == null || title.trim().isEmpty()) {
481             title = OLEConstants.ITEM_TITLE;
482         }
483         title = title.replaceAll(" ", "_");
484 
485         if (itemId == null || itemId.trim().isEmpty()) {
486             itemId = OLEConstants.ITEM_ID;
487         }
488         String fileName = pdfLocationSystemParam + title + "_" + itemId + "_" + (new Date(System.currentTimeMillis())).toString().replaceAll(":","_") + ".pdf";
489         fileName = fileName.replace(" ","_");
490         if (LOG.isDebugEnabled()) {
491             LOG.debug("File Created :" + title + "file name ::" + fileName + "::");
492         }
493         outputStream = new FileOutputStream(fileName);
494         PdfWriter writer = PdfWriter.getInstance(document, outputStream);
495         Font boldFont = new Font(Font.TIMES_ROMAN, 15, Font.BOLD);
496         Font ver_15_normal = FontFactory.getFont("VERDANA", 15, 0);
497         document.open();
498         document.newPage();
499         Paragraph paraGraph = new Paragraph();
500         paraGraph.setAlignment(Element.ALIGN_CENTER);
501         paraGraph.add(new Chunk(title, boldFont));
502         paraGraph.add(Chunk.NEWLINE);
503         document.add(paraGraph);
504         return outputStream;
505     }
506 
507     public void createPdfForIntransitRequest(OleDeliverRequestBo oleDeliverRequestBo, HttpServletResponse response) {
508         LOG.debug("Creating pdf for intransit request");
509         String title = "InTransit Request";
510         OutputStream outputStream = null;
511         /*String pdfLocationSystemParam = getLoanProcessor().getParameter("PDF_LOCATION");
512         if (LOG.isInfoEnabled()) {
513             LOG.info("System Parameter for PDF_Location --> " + pdfLocationSystemParam);
514         }
515         if (pdfLocationSystemParam == null || pdfLocationSystemParam.trim().isEmpty()) {
516             pdfLocationSystemParam = ConfigContext.getCurrentContextConfig().getProperty("staging.directory") + "/";
517             if (LOG.isInfoEnabled()) {
518                 LOG.info("System Parameter for PDF_Location staging dir--> " + pdfLocationSystemParam);
519             }
520         } else{
521             pdfLocationSystemParam = ConfigContext.getCurrentContextConfig().getProperty("homeDirectory")+ "/" + pdfLocationSystemParam +"/";
522         }
523         boolean locationExist = new File(pdfLocationSystemParam).exists();
524         boolean fileCreated = false;
525         if (LOG.isInfoEnabled()) {
526             LOG.info("Is directory Exist ::" + locationExist);
527         }
528         try {
529             if (!locationExist) {
530                 fileCreated = new File(pdfLocationSystemParam).mkdirs();
531                 if (!fileCreated) {
532                     throw new RuntimeException("Not Able to create directory :" + pdfLocationSystemParam);
533                 }
534             }
535         } catch (Exception e) {
536             LOG.error("Exception occured while creating the directory : " + e.getMessage(),e);
537 
538         } */
539         String fileName = "IntransitRequestSlip" + "_" + oleDeliverRequestBo.getItemId() + "_" + new Date(System.currentTimeMillis()) + ".pdf";
540         if (LOG.isDebugEnabled()) {
541             LOG.debug("File Created :" + title + "file name ::" + fileName + "::");
542         }
543         SimpleDateFormat sdf = new SimpleDateFormat(OLEConstants.TIMESTAMP);
544         try {
545             String itemTitle = oleDeliverRequestBo.getTitle() != null ? oleDeliverRequestBo.getTitle() : "";
546             Date dateOfReq = oleDeliverRequestBo.getCreateDate()!=null?oleDeliverRequestBo.getCreateDate():null;
547             //String dateOfRequest = dateOfReq != null ? dateOfReq.toString() : "";
548             String circulationLocation = oleDeliverRequestBo.getCirculationLocationCode() != null ? oleDeliverRequestBo.getCirculationLocationCode() : "";
549             String itemBarcode = oleDeliverRequestBo.getItemId() != null ? oleDeliverRequestBo.getItemId() : "";
550             String patronBarcode = oleDeliverRequestBo.getBorrowerBarcode() != null ? oleDeliverRequestBo.getBorrowerBarcode() : "";
551             String requestType = oleDeliverRequestBo.getRequestTypeId() != null ? oleDeliverRequestBo.getRequestTypeId() : "";
552             boolean inTransitSlip = requestType.equalsIgnoreCase("8");
553 
554             Document document = this.getDocument(0, 0, 5, 5);
555             //outputStream = new FileOutputStream(fileName);
556 
557             response.setContentType("application/pdf");
558             response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
559             outputStream = response.getOutputStream();
560             PdfWriter.getInstance(document, outputStream);
561             Font boldFont = new Font(Font.TIMES_ROMAN, 15, Font.BOLD);
562             document.open();
563             document.newPage();
564             PdfPTable pdfTable = new PdfPTable(3);
565             pdfTable.setWidths(new int[]{20,2,30});
566             Paragraph paraGraph = new Paragraph();
567             if (inTransitSlip) {
568                 paraGraph.setAlignment(Element.ALIGN_CENTER);
569                 paraGraph.add(new Chunk("InTransit Request Slip", boldFont));
570             }
571             paraGraph.add(Chunk.NEWLINE);
572             paraGraph.add(Chunk.NEWLINE);
573             paraGraph.add(Chunk.NEWLINE);
574             document.add(paraGraph);
575             if (inTransitSlip) {
576                 pdfTable.addCell(getPdfPCellInJustified("Date/Time "));
577                 pdfTable.addCell(getPdfPCellInLeft(":"));
578                 pdfTable.addCell(getPdfPCellInJustified(sdf.format(dateOfReq)));
579 
580                 pdfTable.addCell(getPdfPCellInJustified("Circulation Location"));
581                 pdfTable.addCell(getPdfPCellInLeft(":"));
582                 pdfTable.addCell(getPdfPCellInJustified(circulationLocation));
583 
584                 pdfTable.addCell(getPdfPCellInJustified("Item Barcode"));
585                 pdfTable.addCell(getPdfPCellInLeft(":"));
586                 pdfTable.addCell(getPdfPCellInJustified(itemBarcode));
587 
588                 pdfTable.addCell(getPdfPCellInJustified("Title"));
589                 pdfTable.addCell(getPdfPCellInLeft(":"));
590                 pdfTable.addCell(getPdfPCellInJustified(itemTitle));
591 
592                 pdfTable.addCell(getPdfPCellInJustified("Patron Barcode"));
593                 pdfTable.addCell(getPdfPCellInLeft(":"));
594                 pdfTable.addCell(getPdfPCellInJustified(patronBarcode));
595                 document.add(pdfTable);
596             }
597             document.close();
598             outputStream.flush();
599             outputStream.close();
600         } catch (Exception e) {
601             LOG.error("Exception while creating Pdf For IntransitRequest", e);
602         }
603     }
604 
605     private PdfPCell getPdfPCellInJustified(String chunk) {
606         PdfPCell pdfPCell = new PdfPCell(new Paragraph(new Chunk(chunk)));
607         pdfPCell.setBorder(pdfPCell.NO_BORDER);
608         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
609         return pdfPCell;
610     }
611 
612     private PdfPCell getPdfPCellInLeft(String chunk) {
613         PdfPCell pdfPCell = new PdfPCell(new Paragraph(new Chunk(chunk)));
614         pdfPCell.setBorder(pdfPCell.NO_BORDER);
615         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
616         return pdfPCell;
617     }
618 
619     public Document getDocument(float f1, float f2, float f3, float f4) {
620         Document document = new Document(PageSize.A4);
621         document.setMargins(f1, f2, f3, f4);
622         return document;
623     }
624 
625     private void getPdfTemplateHeader(OleNoticeBo noticeBo, Document document) throws Exception {
626         if (LOG.isDebugEnabled()){
627             LOG.debug("Header for the notice" + noticeBo.getNoticeName() + noticeBo.getItemId());
628         }
629           //PdfPTable pdfTable = new PdfPTable(3);
630 //        PdfPCell pdfPCell = new PdfPCell(new Paragraph("Circulation Location / Library Name"));
631 //        pdfPCell.setBorder(pdfPCell.NO_BORDER);
632 //        pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
633 //        pdfTable.addCell(pdfPCell);
634 //        pdfPCell = new PdfPCell(new Paragraph(":"));
635 //        pdfPCell.setBorder(pdfPCell.NO_BORDER);
636 //        pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
637 //        pdfTable.addCell(pdfPCell);
638 //        pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getCirculationDeskName() != null ? noticeBo.getCirculationDeskName() : "")));
639 //        pdfPCell.setBorder(pdfPCell.NO_BORDER);
640 //        pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
641 //        pdfTable.addCell(pdfPCell);
642 //        pdfPCell = new PdfPCell(new Paragraph(new Chunk("Address")));
643 //        pdfPCell.setBorder(pdfPCell.NO_BORDER);
644 //        pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
645 //        pdfTable.addCell(pdfPCell);
646 //        pdfPCell = new PdfPCell(new Paragraph(":"));
647 //        pdfPCell.setBorder(pdfPCell.NO_BORDER);
648 //        pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
649 //        pdfTable.addCell(pdfPCell);
650 //        pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getPatronAddress() != null ? noticeBo.getPatronAddress() : "")));
651 //        pdfPCell.setBorder(pdfPCell.NO_BORDER);
652 //        pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
653 //        pdfTable.addCell(pdfPCell);
654 //        pdfPCell = new PdfPCell(new Paragraph(new Chunk("Email")));
655 //        pdfPCell.setBorder(pdfPCell.NO_BORDER);
656 //        pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
657 //        pdfTable.addCell(pdfPCell);
658 //        pdfPCell = new PdfPCell(new Paragraph(":"));
659 //        pdfPCell.setBorder(pdfPCell.NO_BORDER);
660 //        pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
661 //        pdfTable.addCell(pdfPCell);
662 //        pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getPatronEmailAddress() != null ? noticeBo.getPatronEmailAddress() : "")));
663 //        pdfPCell.setBorder(pdfPCell.NO_BORDER);
664 //        pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
665 //        pdfTable.addCell(pdfPCell);
666 //        pdfPCell = new PdfPCell(new Paragraph(new Chunk("Phone #")));
667 //        pdfPCell.setBorder(pdfPCell.NO_BORDER);
668 //        pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
669 //        pdfTable.addCell(pdfPCell);
670 //        pdfPCell = new PdfPCell(new Paragraph(":"));
671 //        pdfPCell.setBorder(pdfPCell.NO_BORDER);
672 //        pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
673 //        pdfTable.addCell(pdfPCell);
674 //        pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getPatronPhoneNumber() != null ? noticeBo.getPatronPhoneNumber() : "")));
675 //        pdfPCell.setBorder(pdfPCell.NO_BORDER);
676 //        pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
677 //        pdfTable.addCell(pdfPCell);
678 //        document.add(pdfTable);
679         Paragraph paraGraph = new Paragraph();
680         paraGraph.add(Chunk.NEWLINE);
681         document.add(paraGraph);
682         paraGraph = new Paragraph();
683         paraGraph.add(new Chunk("Patron information", boldFont));
684         paraGraph.add(Chunk.NEWLINE);
685         paraGraph.add(Chunk.NEWLINE);
686         document.add(paraGraph);
687 
688         PdfPTable pdfTable = new PdfPTable(3);
689         pdfTable.setWidths(new int[]{20,2,30});
690         PdfPCell pdfPCell= new PdfPCell(new Paragraph("Patron Name"));
691         pdfPCell.setBorder(pdfPCell.NO_BORDER);
692         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
693         pdfTable.addCell(pdfPCell);
694         pdfPCell = new PdfPCell(new Paragraph(":"));
695         pdfPCell.setBorder(pdfPCell.NO_BORDER);
696         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
697         pdfTable.addCell(pdfPCell);
698         pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getPatronName() != null ? noticeBo.getPatronName() : "")));
699         pdfPCell.setBorder(pdfPCell.NO_BORDER);
700         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
701         pdfTable.addCell(pdfPCell);
702         pdfPCell = new PdfPCell(new Paragraph(new Chunk("Address")));
703         pdfPCell.setBorder(pdfPCell.NO_BORDER);
704         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
705         pdfTable.addCell(pdfPCell);
706         pdfPCell = new PdfPCell(new Paragraph(":"));
707         pdfPCell.setBorder(pdfPCell.NO_BORDER);
708         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
709         pdfTable.addCell(pdfPCell);
710         pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getPatronAddress() != null ? noticeBo.getPatronAddress() : "")));
711         pdfPCell.setBorder(pdfPCell.NO_BORDER);
712         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
713         pdfTable.addCell(pdfPCell);
714         pdfPCell = new PdfPCell(new Paragraph(new Chunk("Email")));
715         pdfPCell.setBorder(pdfPCell.NO_BORDER);
716         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
717         pdfTable.addCell(pdfPCell);
718         pdfPCell = new PdfPCell(new Paragraph(":"));
719         pdfPCell.setBorder(pdfPCell.NO_BORDER);
720         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
721         pdfTable.addCell(pdfPCell);
722         pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getPatronEmailAddress() != null ? noticeBo.getPatronEmailAddress() : "")));
723         pdfPCell.setBorder(pdfPCell.NO_BORDER);
724         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
725         pdfTable.addCell(pdfPCell);
726         pdfPCell = new PdfPCell(new Paragraph(new Chunk("Phone #")));
727         pdfPCell.setBorder(pdfPCell.NO_BORDER);
728         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
729         pdfTable.addCell(pdfPCell);
730         pdfPCell = new PdfPCell(new Paragraph(":"));
731         pdfPCell.setBorder(pdfPCell.NO_BORDER);
732         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
733         pdfTable.addCell(pdfPCell);
734         pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getPatronPhoneNumber() != null ? noticeBo.getPatronPhoneNumber() : "")));
735         pdfPCell.setBorder(pdfPCell.NO_BORDER);
736         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
737         pdfTable.addCell(pdfPCell);
738         document.add(pdfTable);
739         paraGraph = new Paragraph();
740         paraGraph.add(Chunk.NEWLINE);
741         document.add(paraGraph);
742 
743 
744     }
745 
746     private void getPdfTemplateBody(Document document, String title, String body) throws Exception {
747         //Notice Type
748         if (LOG.isDebugEnabled()){
749             LOG.debug("Body Content of the notice :" + title);
750         }
751         Paragraph paraGraph = new Paragraph();
752         paraGraph.add(new Chunk(title, boldFont));
753         paraGraph.setAlignment(Element.ALIGN_CENTER);
754         paraGraph.add(Chunk.NEWLINE);
755         paraGraph.add(Chunk.NEWLINE);
756         document.add(paraGraph);
757 
758 
759         //Notice-specific text
760         paraGraph = new Paragraph();
761         paraGraph.add(new Chunk(body, boldFont));
762         paraGraph.setAlignment(Element.ALIGN_CENTER);
763         paraGraph.add(Chunk.NEWLINE);
764         paraGraph.add(Chunk.NEWLINE);
765         document.add(paraGraph);
766     }
767 
768     private void getPdfTemplateFooter(OleNoticeBo noticeBo, Document document) throws Exception {
769         if (LOG.isDebugEnabled()){
770             LOG.debug("Footer for the notice : " + noticeBo.getNoticeName() + noticeBo.getItemId());
771         }
772         SimpleDateFormat dateFormat = new SimpleDateFormat(OLEConstants.DATEFORMAT);
773         SimpleDateFormat sdf = new SimpleDateFormat(OLEConstants.TIMESTAMP);
774         Paragraph paraGraph = new Paragraph();
775         paraGraph.add(new Chunk("Title/item information", boldFont));
776         paraGraph.add(Chunk.NEWLINE);
777         paraGraph.add(Chunk.NEWLINE);
778         document.add(paraGraph);
779         PdfPTable pdfTable = new PdfPTable(3);
780         pdfTable.setWidths(new int[]{20,2,30});
781         PdfPCell pdfPCell;
782         if (!noticeBo.getNoticeName().equalsIgnoreCase(OLEConstants.NOTICE_RECALL)) {
783             pdfPCell = new PdfPCell(new Paragraph("Circulation Location / Library Name"));
784             pdfPCell.setBorder(pdfPCell.NO_BORDER);
785             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
786             pdfTable.addCell(pdfPCell);
787             pdfPCell = new PdfPCell(new Paragraph(":"));
788             pdfPCell.setBorder(pdfPCell.NO_BORDER);
789             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
790             pdfTable.addCell(pdfPCell);
791             pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getCirculationDeskName() != null ? noticeBo.getCirculationDeskName() : "")));
792             pdfPCell.setBorder(pdfPCell.NO_BORDER);
793             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
794             pdfTable.addCell(pdfPCell);
795         }
796         pdfPCell = new PdfPCell(new Paragraph("Title "));
797         pdfPCell.setBorder(pdfPCell.NO_BORDER);
798         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
799         pdfTable.addCell(pdfPCell);
800         pdfPCell = new PdfPCell(new Paragraph(":"));
801         pdfPCell.setBorder(pdfPCell.NO_BORDER);
802         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
803         pdfTable.addCell(pdfPCell);
804         pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getTitle() == null ? "" : noticeBo.getTitle())));
805         pdfPCell.setBorder(pdfPCell.NO_BORDER);
806         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
807         pdfTable.addCell(pdfPCell);
808         pdfPCell = new PdfPCell(new Paragraph(new Chunk("Author ")));
809         pdfPCell.setBorder(pdfPCell.NO_BORDER);
810         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
811         pdfTable.addCell(pdfPCell);
812         pdfPCell = new PdfPCell(new Paragraph(":"));
813         pdfPCell.setBorder(pdfPCell.NO_BORDER);
814         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
815         pdfTable.addCell(pdfPCell);
816         pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getAuthor() == null ? "" : noticeBo.getAuthor())));
817         pdfPCell.setBorder(pdfPCell.NO_BORDER);
818         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
819         pdfTable.addCell(pdfPCell);
820         pdfPCell = new PdfPCell(new Paragraph(new Chunk("Volume/Issue/Copy # ")));
821         pdfPCell.setBorder(pdfPCell.NO_BORDER);
822         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
823         pdfTable.addCell(pdfPCell);
824         pdfPCell = new PdfPCell(new Paragraph(":"));
825         pdfPCell.setBorder(pdfPCell.NO_BORDER);
826         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
827         pdfTable.addCell(pdfPCell);
828         if(!noticeBo.getNoticeName().equalsIgnoreCase(OLEConstants.NOTICE_RECALL)){
829         pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getVolumeNumber() == null ? "" : noticeBo.getVolumeNumber())));
830         }else{
831         pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getVolumeIssueCopyNumber() == null ? "" : noticeBo.getVolumeIssueCopyNumber())));
832         }
833         pdfPCell.setBorder(pdfPCell.NO_BORDER);
834         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
835         pdfTable.addCell(pdfPCell);
836         pdfPCell = new PdfPCell(new Paragraph(new Chunk("Library shelving location ")));
837         pdfPCell.setBorder(pdfPCell.NO_BORDER);
838         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
839         pdfTable.addCell(pdfPCell);
840         pdfPCell = new PdfPCell(new Paragraph(":"));
841         pdfPCell.setBorder(pdfPCell.NO_BORDER);
842         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
843         pdfTable.addCell(pdfPCell);
844         pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getItemShelvingLocation() == null ? "" : noticeBo.getItemShelvingLocation())));
845         pdfPCell.setBorder(pdfPCell.NO_BORDER);
846         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
847         pdfTable.addCell(pdfPCell);
848         pdfPCell = new PdfPCell(new Paragraph(new Chunk("Call # ")));
849         pdfPCell.setBorder(pdfPCell.NO_BORDER);
850         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
851         pdfTable.addCell(pdfPCell);
852         pdfPCell = new PdfPCell(new Paragraph(":"));
853         pdfPCell.setBorder(pdfPCell.NO_BORDER);
854         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
855         pdfTable.addCell(pdfPCell);
856         pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getItemCallNumber() == null ? "" : noticeBo.getItemCallNumber())));
857         pdfPCell.setBorder(pdfPCell.NO_BORDER);
858         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
859         pdfTable.addCell(pdfPCell);
860         pdfPCell = new PdfPCell(new Paragraph(new Chunk("Item barcode")));
861         pdfPCell.setBorder(pdfPCell.NO_BORDER);
862         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
863         pdfTable.addCell(pdfPCell);
864         pdfPCell = new PdfPCell(new Paragraph(":"));
865         pdfPCell.setBorder(pdfPCell.NO_BORDER);
866         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
867         pdfTable.addCell(pdfPCell);
868         pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getItemId() == null ? "" : noticeBo.getItemId())));
869         pdfPCell.setBorder(pdfPCell.NO_BORDER);
870         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
871         pdfTable.addCell(pdfPCell);
872         if (noticeBo.getExpiredOnHoldDate() != null) {
873             pdfPCell = new PdfPCell(new Paragraph(new Chunk("Expiration onHoldDate")));
874             pdfPCell.setBorder(pdfPCell.NO_BORDER);
875             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
876             pdfTable.addCell(pdfPCell);
877             pdfPCell = new PdfPCell(new Paragraph(":"));
878             pdfPCell.setBorder(pdfPCell.NO_BORDER);
879             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
880             pdfTable.addCell(pdfPCell);
881             pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getExpiredOnHoldDate() == null ? "" : dateFormat.format(noticeBo.getExpiredOnHoldDate()))));
882             pdfPCell.setBorder(pdfPCell.NO_BORDER);
883             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
884             pdfTable.addCell(pdfPCell);
885         }
886         document.add(pdfTable);
887         paraGraph = new Paragraph();
888         paraGraph.add(Chunk.NEWLINE);
889         document.add(paraGraph);
890 
891         //Information specific text
892   /*          paraGraph = new Paragraph();
893             paraGraph.add(new Chunk("Information specific text",boldFont));
894             paraGraph.add(Chunk.NEWLINE);
895             document.add(paraGraph);*/
896         if (noticeBo.getNoticeName().equals(OLEConstants.NOTICE_RECALL)) {
897             if (LOG.isDebugEnabled()){
898                 LOG.debug("Recall Notice Footer Content : " + noticeBo.getNoticeName() + noticeBo.getItemId());
899             }
900             pdfTable = new PdfPTable(3);
901             pdfTable.setWidths(new int[]{20,2,30});
902             pdfPCell = new PdfPCell(new Paragraph("Original Due Date"));
903             pdfPCell.setBorder(pdfPCell.NO_BORDER);
904             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
905             pdfTable.addCell(pdfPCell);
906             pdfPCell = new PdfPCell(new Paragraph(":"));
907             pdfPCell.setBorder(pdfPCell.NO_BORDER);
908             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
909             pdfTable.addCell(pdfPCell);
910             pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getOriginalDueDate() == null ? "" : sdf.format(noticeBo.getOriginalDueDate()))));
911             pdfPCell.setBorder(pdfPCell.NO_BORDER);
912             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
913             pdfTable.addCell(pdfPCell);
914             pdfPCell = new PdfPCell(new Paragraph(new Chunk("New Due Date")));
915             pdfPCell.setBorder(pdfPCell.NO_BORDER);
916             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
917             pdfTable.addCell(pdfPCell);
918             pdfPCell = new PdfPCell(new Paragraph(":"));
919             pdfPCell.setBorder(pdfPCell.NO_BORDER);
920             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
921             pdfTable.addCell(pdfPCell);
922             pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getNewDueDate() == null ? "" : sdf.format(noticeBo.getNewDueDate()))));
923             pdfPCell.setBorder(pdfPCell.NO_BORDER);
924             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
925             pdfTable.addCell(pdfPCell);
926             document.add(pdfTable);
927             paraGraph = new Paragraph();
928             paraGraph.add(Chunk.NEWLINE);
929             document.add(paraGraph);
930         } else if (noticeBo.getNoticeName().equals("OnHold")) {
931             if (LOG.isDebugEnabled()){
932                 LOG.debug("OnHold Notice Footer Content : " + noticeBo.getNoticeName() + noticeBo.getItemId());
933             }
934             pdfTable = new PdfPTable(3);
935             pdfTable.setWidths(new int[]{20,2,30});
936             pdfPCell = new PdfPCell(new Paragraph("Pick Up Location"));
937             pdfPCell.setBorder(pdfPCell.NO_BORDER);
938             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
939             pdfTable.addCell(pdfPCell);
940             pdfPCell = new PdfPCell(new Paragraph(":"));
941             pdfPCell.setBorder(pdfPCell.NO_BORDER);
942             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
943             pdfTable.addCell(pdfPCell);
944             pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getPickUpLocation() != null ? noticeBo.getPickUpLocation() : "")));
945             pdfPCell.setBorder(pdfPCell.NO_BORDER);
946             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
947             pdfTable.addCell(pdfPCell);
948             pdfPCell = new PdfPCell(new Paragraph("Circulation Location / Library Name"));
949             pdfPCell.setBorder(pdfPCell.NO_BORDER);
950             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
951             pdfTable.addCell(pdfPCell);
952             pdfPCell = new PdfPCell(new Paragraph(":"));
953             pdfPCell.setBorder(pdfPCell.NO_BORDER);
954             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
955             pdfTable.addCell(pdfPCell);
956             pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getCirculationDeskName() != null ? noticeBo.getCirculationDeskName() : "")));
957             pdfPCell.setBorder(pdfPCell.NO_BORDER);
958             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
959             pdfTable.addCell(pdfPCell);
960             pdfPCell = new PdfPCell(new Paragraph(new Chunk("Address")));
961             pdfPCell.setBorder(pdfPCell.NO_BORDER);
962             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
963             pdfTable.addCell(pdfPCell);
964             pdfPCell = new PdfPCell(new Paragraph(":"));
965             pdfPCell.setBorder(pdfPCell.NO_BORDER);
966             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
967             pdfTable.addCell(pdfPCell);
968             pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getPatronAddress() != null ? noticeBo.getPatronAddress() : "")));
969             pdfPCell.setBorder(pdfPCell.NO_BORDER);
970             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
971             pdfTable.addCell(pdfPCell);
972             pdfPCell = new PdfPCell(new Paragraph(new Chunk("Email")));
973             pdfPCell.setBorder(pdfPCell.NO_BORDER);
974             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
975             pdfTable.addCell(pdfPCell);
976             pdfPCell = new PdfPCell(new Paragraph(":"));
977             pdfPCell.setBorder(pdfPCell.NO_BORDER);
978             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
979             pdfTable.addCell(pdfPCell);
980             pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getPatronEmailAddress() != null ? noticeBo.getPatronEmailAddress() : "")));
981             pdfPCell.setBorder(pdfPCell.NO_BORDER);
982             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
983             pdfTable.addCell(pdfPCell);
984             pdfPCell = new PdfPCell(new Paragraph(new Chunk("Phone #")));
985             pdfPCell.setBorder(pdfPCell.NO_BORDER);
986             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
987             pdfTable.addCell(pdfPCell);
988             pdfPCell = new PdfPCell(new Paragraph(":"));
989             pdfPCell.setBorder(pdfPCell.NO_BORDER);
990             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
991             pdfTable.addCell(pdfPCell);
992             pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getPatronPhoneNumber() != null ? noticeBo.getPatronPhoneNumber() : "")));
993             pdfPCell.setBorder(pdfPCell.NO_BORDER);
994             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
995             pdfTable.addCell(pdfPCell);
996             document.add(pdfTable);
997             paraGraph = new Paragraph();
998             paraGraph.add(Chunk.NEWLINE);
999             document.add(paraGraph);
1000             pdfTable = new PdfPTable(3);
1001             pdfTable.setWidths(new int[]{20,2,30});
1002             pdfPCell = new PdfPCell(new Paragraph(new Chunk("Item Will Be Held until")));
1003             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1004             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1005             pdfTable.addCell(pdfPCell);
1006             pdfPCell = new PdfPCell(new Paragraph(":"));
1007             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1008             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1009             pdfTable.addCell(pdfPCell);
1010             pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getExpiredOnHoldDate() != null ? dateFormat.format(noticeBo.getExpiredOnHoldDate().toString()) : "")));
1011             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1012             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1013             pdfTable.addCell(pdfPCell);
1014             document.add(pdfTable);
1015             paraGraph = new Paragraph();
1016             paraGraph.add(Chunk.NEWLINE);
1017             document.add(paraGraph);
1018         } else if (noticeBo.getNoticeName().equals("OverdueNotice")) {
1019             if (LOG.isDebugEnabled()){
1020                 LOG.debug("OverdueNotice Footer Content : " + noticeBo.getNoticeName() + noticeBo.getItemId());
1021             }
1022             pdfTable = new PdfPTable(3);
1023             pdfTable.setWidths(new int[]{20,2,30});
1024             pdfPCell = new PdfPCell(new Paragraph("Item was due"));
1025             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1026             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1027             pdfTable.addCell(pdfPCell);
1028             pdfPCell = new PdfPCell(new Paragraph(":"));
1029             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1030             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1031             pdfTable.addCell(pdfPCell);
1032             pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getDueDate() == null ? "" : (sdf.format(noticeBo.getDueDate())))));
1033             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1034             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1035             pdfTable.addCell(pdfPCell);
1036             document.add(pdfTable);
1037             paraGraph = new Paragraph();
1038             paraGraph.add(Chunk.NEWLINE);
1039             document.add(paraGraph);
1040         }
1041 
1042     }
1043 
1044     public void getPdfFooter(Document document, OutputStream outputStream) throws Exception {
1045         String url = ConfigContext.getCurrentContextConfig().getProperty("ole.fs.url.base");
1046         String myAccountURL = loanProcessor.getParameter(OLEConstants.MY_ACCOUNT_URL);
1047         if(myAccountURL!=null && !myAccountURL.trim().isEmpty()){
1048         ver_15_normal.setColor(Color.blue);
1049         ver_15_normal.setStyle(Font.UNDERLINE);
1050         Anchor anchor = new Anchor("MyAccount", ver_15_normal);
1051         anchor.setName("My Account");
1052         anchor.setReference(myAccountURL);
1053         Paragraph paraGraph = new Paragraph();
1054         paraGraph.add(anchor);
1055         paraGraph.setAlignment(Element.ALIGN_CENTER);
1056         document.add(paraGraph);
1057         }
1058         outputStream.flush();
1059         document.close();
1060         outputStream.close();
1061     }
1062 
1063     public List getPdfNoticeForPatron(List<OleNoticeBo> noticeBoList) throws Exception {
1064         return getPdfTemplate(noticeBoList);
1065     }
1066 
1067     private List getPdfTemplate(List<OleNoticeBo> noticeBoList) throws Exception {
1068         List templateForNoticeList = new ArrayList();
1069         LOG.debug("In getPdfTemplate()");
1070         try {
1071             Document document = new Document(PageSize.A4);
1072             OutputStream outputStream = null;
1073 
1074             List<OleNoticeBo> overDueNoticeList = new ArrayList<OleNoticeBo>();
1075             List<OleNoticeBo> onHoldNoticeList = new ArrayList<OleNoticeBo>();
1076             List<OleNoticeBo> recallNoticeList = new ArrayList<OleNoticeBo>();
1077             List<OleNoticeBo> expiredNoticeList = new ArrayList<OleNoticeBo>();
1078             List<OleNoticeBo> expiredRequiredNoticeList = new ArrayList<OleNoticeBo>();
1079             List<OleNoticeBo> courtesyNoticeList = new ArrayList<OleNoticeBo>();
1080 
1081             for (int temp = 0; temp < noticeBoList.size(); temp++) {
1082                 if (noticeBoList.get(temp).getNoticeName().equalsIgnoreCase(OLEConstants.NOTICE_OVERDUE)) {
1083                     overDueNoticeList.add(noticeBoList.get(temp));
1084                 }
1085                 if (noticeBoList.get(temp).getNoticeName().equalsIgnoreCase(OLEConstants.NOTICE_ONHOLD)) {
1086                     onHoldNoticeList.add(noticeBoList.get(temp));
1087                 }
1088                 if (noticeBoList.get(temp).getNoticeName().equalsIgnoreCase(OLEConstants.NOTICE_RECALL)) {
1089                     recallNoticeList.add(noticeBoList.get(temp));
1090                 }
1091                 if (noticeBoList.get(temp).getNoticeName().equalsIgnoreCase(OLEConstants.NOTICE_HOLD_COURTESY)) {
1092                     expiredNoticeList.add(noticeBoList.get(temp));
1093                 }
1094                 if (noticeBoList.get(temp).getNoticeName().equalsIgnoreCase(OLEConstants.OleDeliverRequest.EXPIRED_REQUEST)) {
1095                     expiredRequiredNoticeList.add(noticeBoList.get(temp));
1096                 }
1097                 if (noticeBoList.get(temp).getNoticeName().equalsIgnoreCase(OLEConstants.NOTICE_COURTESY)) {
1098                     courtesyNoticeList.add(noticeBoList.get(temp));
1099                 }
1100             }
1101             LoanProcessor loanProcessor = getLoanProcessor();
1102 
1103             if (overDueNoticeList != null && overDueNoticeList.size() > 0) {
1104                 outputStream = getPdfHeader(document, outputStream, loanProcessor.getParameter(OLEParameterConstants.OVERDUE_TITLE), overDueNoticeList.get(0).getItemId());
1105                 getPdfTemplateHeader(overDueNoticeList.get(0), document);
1106                 getPdfTemplateBody(document, loanProcessor.getParameter(OLEParameterConstants.OVERDUE_TITLE), loanProcessor.getParameter(OLEParameterConstants.OVERDUE_BODY));
1107                 getPdfTemplateFooterList(overDueNoticeList, document);
1108                 getPdfFooter(document, outputStream);
1109             }
1110 
1111             if (onHoldNoticeList != null && onHoldNoticeList.size() > 0) {
1112                 outputStream = getPdfHeader(document, outputStream, loanProcessor.getParameter(OLEParameterConstants.ONHOLD_TITLE), onHoldNoticeList.get(0).getItemId());
1113                 getPdfTemplateHeader(onHoldNoticeList.get(0), document);
1114                 getPdfTemplateBody(document, loanProcessor.getParameter(OLEParameterConstants.ONHOLD_TITLE), loanProcessor.getParameter(OLEParameterConstants.ONHOLD_BODY));
1115                 for (int onHold = 0; onHold < onHoldNoticeList.size(); onHold++) {
1116                     getPdfTemplateFooter(noticeBoList.get(onHold), document);
1117                     //getPickUpLocationTemplate(noticeBoList.get(onHold),stringBuffer);
1118                 }
1119                 getPdfFooter(document, outputStream);
1120             }
1121 
1122             if (recallNoticeList != null && recallNoticeList.size() > 0) {
1123                 outputStream = getPdfHeader(document, outputStream, loanProcessor.getParameter(OLEParameterConstants.RECALL_TITLE), recallNoticeList.get(0).getItemId());
1124                 getPdfTemplateHeader(recallNoticeList.get(0), document);
1125                 getPdfTemplateBody(document, loanProcessor.getParameter(OLEParameterConstants.RECALL_TITLE), loanProcessor.getParameter(OLEParameterConstants.RECALL_BODY));
1126                 for (int recall = 0; recall < recallNoticeList.size(); recall++) {
1127                     getPdfTemplateFooter(noticeBoList.get(recall), document);
1128                 }
1129                 getPdfFooter(document, outputStream);
1130             }
1131 
1132             if (expiredNoticeList != null && expiredNoticeList.size() > 0) {
1133                 outputStream = getPdfHeader(document, outputStream, loanProcessor.getParameter(OLEParameterConstants.EXPIRED_TITLE), expiredNoticeList.get(0).getItemId());
1134                 getPdfTemplateHeader(expiredNoticeList.get(0), document);
1135                 getPdfTemplateBody(document, loanProcessor.getParameter(OLEParameterConstants.EXPIRED_TITLE), loanProcessor.getParameter(OLEParameterConstants.EXPIRED_BODY));
1136                 for (int exp = 0; exp < expiredNoticeList.size(); exp++) {
1137                     getPdfTemplateFooter(noticeBoList.get(exp), document);
1138                 }
1139                 getPdfFooter(document, outputStream);
1140             }
1141 
1142             if (expiredRequiredNoticeList != null && expiredRequiredNoticeList.size() > 0) {
1143                 outputStream = getPdfHeader(document, outputStream, loanProcessor.getParameter(OLEParameterConstants.EXP_REQ_TITLE), expiredRequiredNoticeList.get(0).getItemId());
1144                 getPdfTemplateHeader(expiredRequiredNoticeList.get(0), document);
1145                 getPdfTemplateBody(document, loanProcessor.getParameter(OLEParameterConstants.EXP_REQ_TITLE), loanProcessor.getParameter(OLEParameterConstants.EXP_REQ_BODY));
1146                 for (int exReq = 0; exReq < expiredRequiredNoticeList.size(); exReq++) {
1147                     getPdfTemplateFooter(noticeBoList.get(exReq), document);
1148                 }
1149                 getPdfFooter(document, outputStream);
1150             }
1151             if (courtesyNoticeList != null && courtesyNoticeList.size() > 0) {
1152                 outputStream = getPdfHeader(document, outputStream, loanProcessor.getParameter(OLEParameterConstants.COURTESY_TITLE), courtesyNoticeList.get(0).getItemId());
1153                 getPdfTemplateHeader(courtesyNoticeList.get(0), document);
1154                 getPdfTemplateBody(document, loanProcessor.getParameter(OLEParameterConstants.COURTESY_TITLE), loanProcessor.getParameter(OLEParameterConstants.COURTESY_BODY));
1155                 getPdfTemplateFooterList(courtesyNoticeList, document);
1156                 getPdfFooter(document, outputStream);
1157             }
1158 
1159         } catch (Exception e) {
1160             LOG.error("Exception in getPdfTemplate", e);
1161         }
1162         //     templateForNoticeList.add(stringBuffer);
1163 
1164         return templateForNoticeList;
1165     }
1166 
1167 
1168     public List getNoticeForPatron(List<OleNoticeBo> noticeBo) throws Exception {
1169         return getTemplate(noticeBo);
1170 
1171     }
1172 
1173     public Map getSMSForPatron(List<OleNoticeBo> noticeBo) throws Exception {
1174         return getSMSTemplate(noticeBo);
1175     }
1176 
1177 
1178     public String sendMissingNotice(OleNoticeBo oleNoticeBo) {
1179 
1180         SimpleDateFormat sdf = new SimpleDateFormat(OLEConstants.TIMESTAMP);
1181 
1182         StringBuffer stringBuffer = new StringBuffer();
1183         stringBuffer.append("<HTML>");
1184         stringBuffer.append("<TITLE>" + oleNoticeBo.getNoticeName() + "</TITLE>");
1185         stringBuffer.append("<HEAD><TR><TD><CENTER>" + oleNoticeBo.getNoticeName() + "</CENTER></TD></TR></HEAD>");
1186         stringBuffer.append("<BODY>");
1187         stringBuffer.append("<TABLE></BR></BR>");
1188         stringBuffer.append("<TR><TD>Circulation Location / Library Name :</TD><TD>" + oleNoticeBo.getCirculationDeskName() + "</TD></TR>");
1189         stringBuffer.append("<TR><TD>PatronName :</TD><TD>" + oleNoticeBo.getPatronName() + "</TD></TR>");
1190         stringBuffer.append("<TR><TD>Address :</TD><TD>" + oleNoticeBo.getPatronAddress() + "</TD></TR>");
1191         stringBuffer.append("<TR><TD>EMAIL :</TD><TD>" + oleNoticeBo.getPatronEmailAddress() + "</TD></TR>");
1192         stringBuffer.append("<TR><TD>PhoneNumber :</TD><TD>" + oleNoticeBo.getPatronPhoneNumber() + "</TD></TR>");
1193         stringBuffer.append("</TABLE>");
1194         stringBuffer.append("<TABLE></BR></BR>");
1195         stringBuffer.append("<TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>");
1196         stringBuffer.append("<TABLE width=\"100%\">");
1197         stringBuffer.append("<TR><TD><CENTER>" + oleNoticeBo.getNoticeName() + "</CENTER></TD></TR>");
1198         stringBuffer.append("<TR><TD><p>" + oleNoticeBo.getNoticeSpecificContent() + "</p></TD></TR>");
1199         stringBuffer.append("<TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR></TABLE>");
1200         stringBuffer.append("<TABLE></BR></BR>");
1201         stringBuffer.append("<TR><TD>Title :</TD><TD>" + oleNoticeBo.getTitle() + "</TD></TR>");
1202         stringBuffer.append("<TR><TD>Author :</TD><TD>" + oleNoticeBo.getAuthor() + "</TD></TR>");
1203         stringBuffer.append("<TR><TD>Volume/Issue/Copy # :</TD><TD>" + oleNoticeBo.getVolumeNumber() + "</TD></TR>");
1204         stringBuffer.append("<TR><TD>Library shelvinglocation  :</TD><TD>" + oleNoticeBo.getItemShelvingLocation() + "</TD></TR>");
1205         stringBuffer.append("<TR><TD>Call #:</TD><TD>" + oleNoticeBo.getItemCallNumber() + "</TD></TR>");
1206         stringBuffer.append("<TR><TD>Item barcode  :</TD><TD>" + oleNoticeBo.getItemId() + "</TD></TR>");
1207         stringBuffer.append("<TR><TD>Check In Date  :</TD><TD>" + (oleNoticeBo.getCheckInDate()!=null ? oleNoticeBo.getCheckInDate() : "") + "</TD></TR>");
1208         String missingPieceNote="";
1209         if(oleNoticeBo.getOleItem()!=null&& oleNoticeBo.getOleItem().getMissingPieceFlagNote()!=null){
1210             missingPieceNote=oleNoticeBo.getOleItem().getMissingPieceFlagNote();
1211         }
1212         stringBuffer.append("<TR><TD>Missing Piece Note  :</TD><TD>" + missingPieceNote + "</TD></TR>");
1213         stringBuffer.append("</TABLE>");
1214         stringBuffer.append("</BODY>");
1215         stringBuffer.append("</HTML>");
1216         return stringBuffer.toString();
1217     }
1218     public void getPdfPickUpNotice(OleNoticeBo noticeBo) throws Exception{
1219         if (LOG.isDebugEnabled()){
1220             LOG.debug("PickUp notice : " + noticeBo.getNoticeName() + noticeBo.getItemId());
1221         }
1222         Document document = new Document(PageSize.A4);
1223         OutputStream outputStream = null;
1224         outputStream = getPdfHeader(document, outputStream,getLoanProcessor().getParameter(OLEParameterConstants.PICKUP_TITLE), noticeBo.getItemId());
1225         document.setPageCount(3);
1226         PdfPTable pdfTable = new PdfPTable(1);
1227 
1228         PdfPCell pdfPCell = new PdfPCell(new Paragraph(Chunk.NEWLINE));
1229         pdfPCell.setBorder(pdfPCell.NO_BORDER);
1230         pdfTable.addCell(pdfPCell);
1231 
1232         pdfPCell = new PdfPCell(new Paragraph(new Chunk((noticeBo.getPatronName() != null) ? noticeBo.getPatronName().toString() : "")));
1233         pdfPCell.setBorder(pdfPCell.NO_BORDER);
1234         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1235         pdfTable.addCell(pdfPCell);
1236 
1237         pdfPCell = new PdfPCell(new Paragraph(new Chunk((noticeBo.getPatronAddress() != null) ? noticeBo.getPatronAddress().toString() : "")));
1238         pdfPCell.setBorder(pdfPCell.NO_BORDER);
1239         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1240         pdfTable.addCell(pdfPCell);
1241 
1242         pdfPCell = new PdfPCell(new Paragraph(new Chunk((noticeBo.getPatronEmailAddress() != null) ? noticeBo.getPatronEmailAddress().toString() : "")));
1243         pdfPCell.setBorder(pdfPCell.NO_BORDER);
1244         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1245         pdfTable.addCell(pdfPCell);
1246 
1247         pdfPCell = new PdfPCell(new Paragraph(new Chunk((noticeBo.getPatronPhoneNumber() != null) ? noticeBo.getPatronPhoneNumber().toString() : "")));
1248         pdfPCell.setBorder(pdfPCell.NO_BORDER);
1249         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1250         pdfTable.addCell(pdfPCell);
1251 
1252         document.add(pdfTable);
1253 
1254         pdfTable = new PdfPTable(1);
1255         pdfTable.setWidths(new int[]{10});
1256 
1257         pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getNoticeName(),boldFont)));
1258         pdfPCell.setBorder(pdfPCell.NO_BORDER);
1259         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_CENTER);
1260         pdfTable.addCell(pdfPCell);
1261 
1262         pdfPCell = new PdfPCell(new Paragraph(Chunk.NEWLINE));
1263         pdfPCell.setBorder(pdfPCell.NO_BORDER);
1264         pdfTable.addCell(pdfPCell);
1265 
1266         pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getNoticeSpecificContent())));
1267         pdfPCell.setBorder(pdfPCell.NO_BORDER);
1268         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1269         pdfTable.addCell(pdfPCell);
1270 
1271         pdfPCell = new PdfPCell(new Paragraph(Chunk.NEWLINE));
1272         pdfPCell.setBorder(pdfPCell.NO_BORDER);
1273         pdfTable.addCell(pdfPCell);
1274 
1275         pdfPCell = new PdfPCell(new Paragraph("Thank you."));
1276 
1277         Paragraph paraGraph = new Paragraph();
1278         paraGraph.add(Chunk.NEWLINE);
1279         document.add(paraGraph);
1280 
1281         pdfPCell.setBorder(pdfPCell.NO_BORDER);
1282         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1283         pdfTable.addCell(pdfPCell);
1284 
1285         document.add(pdfTable);
1286 
1287         paraGraph = new Paragraph();
1288         paraGraph.add(Chunk.NEWLINE);
1289         document.add(paraGraph);
1290 
1291         PdfPTable pdfItemTable = new PdfPTable(3);
1292         pdfItemTable.setWidths(new int[]{10,2,30});
1293 
1294         String author=((noticeBo.getAuthor() != null) ? noticeBo.getAuthor().toString() : "");
1295         String title=((noticeBo.getTitle() != null) ? noticeBo.getTitle().toString() : "");
1296         String callNumber=((noticeBo.getItemCallNumber()!=null)?noticeBo.getItemCallNumber().toString():"");
1297 
1298         PdfPCell pdfItemCell = new PdfPCell(new Paragraph(new Chunk("Title")));
1299         pdfItemCell.setBorder(pdfPCell.NO_BORDER);
1300         pdfItemCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1301         pdfItemTable.addCell(pdfItemCell);
1302 
1303         pdfItemCell = new PdfPCell(new Paragraph(new Chunk(":")));
1304         pdfItemCell.setBorder(pdfPCell.NO_BORDER);
1305         pdfItemCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1306         pdfItemTable.addCell(pdfItemCell);
1307 
1308         pdfItemCell = new PdfPCell(new Paragraph(new Chunk(title)));
1309         pdfItemCell.setBorder(pdfPCell.NO_BORDER);
1310         pdfItemCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1311         pdfItemTable.addCell(pdfItemCell);
1312 
1313         pdfItemCell = new PdfPCell(new Paragraph(new Chunk("Author")));
1314         pdfItemCell.setBorder(pdfPCell.NO_BORDER);
1315         pdfItemCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1316         pdfItemTable.addCell(pdfItemCell);
1317 
1318         pdfItemCell = new PdfPCell(new Paragraph(new Chunk(":")));
1319         pdfItemCell.setBorder(pdfPCell.NO_BORDER);
1320         pdfItemCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1321         pdfItemTable.addCell(pdfItemCell);
1322 
1323         pdfItemCell = new PdfPCell(new Paragraph(new Chunk(author)));
1324         pdfItemCell.setBorder(pdfPCell.NO_BORDER);
1325         pdfItemCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1326         pdfItemTable.addCell(pdfItemCell);
1327 
1328         pdfItemCell = new PdfPCell(new Paragraph(new Chunk("Call Number")));
1329         pdfItemCell.setBorder(pdfPCell.NO_BORDER);
1330         pdfItemCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1331         pdfItemTable.addCell(pdfItemCell);
1332 
1333         pdfItemCell = new PdfPCell(new Paragraph(new Chunk(":")));
1334         pdfItemCell.setBorder(pdfPCell.NO_BORDER);
1335         pdfItemCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1336         pdfItemTable.addCell(pdfItemCell);
1337 
1338         pdfItemCell = new PdfPCell(new Paragraph(new Chunk(callNumber)));
1339         pdfItemCell.setBorder(pdfPCell.NO_BORDER);
1340         pdfItemCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1341         pdfItemTable.addCell(pdfItemCell);
1342 
1343         document.add(pdfItemTable);
1344 
1345         document.close();
1346         outputStream.close();
1347 
1348     }
1349     public String getEmailPickUpNotice(OleNoticeBo noticeBo) throws Exception {
1350         StringBuffer stringBuffer=new StringBuffer();
1351         stringBuffer.append("<TABLE>");
1352         stringBuffer.append("<TR><TD>");
1353         stringBuffer.append("<TABLE>");
1354         stringBuffer.append("<TR><TD COLSPAN='3'>" + ((noticeBo.getPatronName() != null) ? noticeBo.getPatronName().toString() : "") + " </TD></TR>");
1355         stringBuffer.append("<TR><TD COLSPAN='3'>" + ((noticeBo.getPatronAddress() != null) ? noticeBo.getPatronAddress().toString() : "") + " </TD></TR>");
1356         stringBuffer.append("<TR><TD COLSPAN='3'>" + ((noticeBo.getPatronEmailAddress() != null) ? noticeBo.getPatronEmailAddress().toString() : "") + " </TD></TR>");
1357         stringBuffer.append("<TR><TD COLSPAN='3'>" + ((noticeBo.getPatronPhoneNumber() != null) ? noticeBo.getPatronPhoneNumber().toString() : "") + " </TD></TR>");
1358         stringBuffer.append("</TABLE>");
1359         stringBuffer.append("</TD></TR>");
1360 
1361         stringBuffer.append("<TR><TD align='center'>");
1362         stringBuffer.append("<B>"+noticeBo.getNoticeName()+"</B>");
1363         stringBuffer.append("</TD></TR>");
1364 
1365         stringBuffer.append("<TR><TD align='left'>");
1366         stringBuffer.append("<P>"+noticeBo.getNoticeSpecificContent()+"</P>");
1367         stringBuffer.append("</TD></TR>");
1368 
1369         stringBuffer.append("<TR><TD align='left'>");
1370         stringBuffer.append("<P>Thank you .</P>");
1371         stringBuffer.append("</TD></TR>");
1372 
1373         stringBuffer.append("<TR><TD>");
1374         String author = ((noticeBo.getAuthor() != null) ? noticeBo.getAuthor().toString() : "");
1375         String title = ((noticeBo.getTitle() != null) ? noticeBo.getTitle().toString() : "");
1376         String callNumber = ((noticeBo.getItemCallNumber() != null) ? noticeBo.getItemCallNumber().toString() : "");
1377         stringBuffer.append("<TR><TD>");
1378         stringBuffer.append("<TABLE>");
1379         stringBuffer.append("<TR><TD COLSPAN='3'> Title : " + title + " </TD></TR>");
1380         stringBuffer.append("<TR><TD COLSPAN='3'> Author : " + author + " </TD></TR>");
1381         stringBuffer.append("<TR><TD COLSPAN='3'> Call Number :" + callNumber + " </TD></TR>");
1382         stringBuffer.append("</TABLE>");
1383         stringBuffer.append("</TD></TR>");
1384         stringBuffer.append("</TABLE>");
1385         return stringBuffer.toString();
1386     }
1387 
1388     public String generateMailContentFromPatronBill(OleLoanDocument oleLoanDocument,OlePatronDocument olePatronDocument,String feeTypeName,String fineAmount,PatronBillPayment patronBillPayment ){
1389         StringBuffer contentForSendMail=new StringBuffer();
1390         OleDeliverRequestDocumentHelperServiceImpl oleDeliverRequestDocumentHelperService=new OleDeliverRequestDocumentHelperServiceImpl();
1391         String patronMail="";
1392         String patronAddress="";
1393         String patronPhoneNumber="";
1394         try{
1395             patronMail=oleDeliverRequestDocumentHelperService.getPatronHomeEmailId(olePatronDocument.getEntity().getEntityTypeContactInfos().get(0));
1396             patronAddress=oleDeliverRequestDocumentHelperService.getPatronPreferredAddress(olePatronDocument.getEntity().getEntityTypeContactInfos().get(0));
1397             patronPhoneNumber=oleDeliverRequestDocumentHelperService.getPatronHomePhoneNumber(olePatronDocument.getEntity().getEntityTypeContactInfos().get(0));
1398         }catch(Exception e){
1399             LOG.error("Exception while generating mail content from patron bill",e);
1400         }
1401         SimpleDateFormat sdf = new SimpleDateFormat(OLEConstants.TIMESTAMP);
1402         contentForSendMail.append("<HTML>");
1403         contentForSendMail.append("<TITLE><CENTER><h2>"+ feeTypeName + " Bill </h2></CENTER></TITLE>");
1404         contentForSendMail.append("<HEAD><TR><TD><CENTER><h2>" + feeTypeName + "<h2></CENTER></TD></TR></HEAD>");
1405         contentForSendMail.append("<BODY>");
1406         contentForSendMail.append("<TABLE width=\"100%\">");
1407         contentForSendMail.append("<TR><TD><h3>Patron Details</h3></TD></TR>");
1408         contentForSendMail.append("<TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR></TABLE>");;
1409         contentForSendMail.append("<TABLE></BR></BR>");
1410         contentForSendMail.append("<TR><TD>PatronName</TD><TD>:</TD><TD>" + olePatronDocument.getEntity().getNames().get(0).getFirstName() + " " + olePatronDocument.getEntity().getNames().get(0).getLastName() + "</TD></TR>");
1411         contentForSendMail.append("<TR><TD>Address</TD><TD>:</TD><TD>" + patronAddress + "</TD></TR>");
1412         contentForSendMail.append("<TR><TD>EMAIL</TD><TD>:</TD><TD>" + patronMail + "</TD></TR>");
1413         contentForSendMail.append("<TR><TD>PhoneNumber</TD><TD>:</TD><TD>" + ( patronPhoneNumber!=null ? patronPhoneNumber : "") + "</TD></TR>");
1414         contentForSendMail.append("</TABLE>");
1415         contentForSendMail.append("<TABLE></BR></BR>");
1416         contentForSendMail.append("<TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>");
1417         contentForSendMail.append("<TABLE width=\"100%\">");
1418         contentForSendMail.append("<TR><TD><h3>Fine Details</h3></TD></TR>");
1419         contentForSendMail.append("<TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR></TABLE>");
1420         contentForSendMail.append("<TABLE></BR></BR>");
1421         contentForSendMail.append("<TR><TD>Bill Number</TD><TD>:</TD><TD>" + patronBillPayment.getBillNumber() + "</TD></TR>");
1422         contentForSendMail.append("<TR><TD>Fee Type</TD><TD>:</TD><TD>" + feeTypeName + "</TD></TR>");
1423         contentForSendMail.append("<TR><TD>Fee Amount</TD><TD>:</TD><TD>" +"$"+ fineAmount + "</TD></TR>");
1424         contentForSendMail.append("<TR><TD>Item Barcode</TD><TD>:</TD><TD>" + oleLoanDocument.getItemId() + "</TD></TR>");
1425         try {
1426             org.kuali.ole.docstore.common.document.Item item = new ItemOleml();
1427             if (oleLoanDocument.getItemId() != null) {
1428 
1429                 org.kuali.ole.docstore.common.search.SearchParams search_Params = new org.kuali.ole.docstore.common.search.SearchParams();
1430                 SearchResponse searchResponse = null;
1431                 search_Params.getSearchConditions().add(search_Params.buildSearchCondition("", search_Params.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), item.ITEM_BARCODE, oleLoanDocument.getItemId()), ""));
1432 
1433                 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), Item.CALL_NUMBER));
1434                 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), Item.COPY_NUMBER));
1435                 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), Item.ENUMERATION));
1436                 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode(), Bib.TITLE));
1437                 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode(), Bib.AUTHOR));
1438 
1439 
1440                 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(search_Params);
1441 
1442 
1443                 for (SearchResult searchResult : searchResponse.getSearchResults()) {
1444                     for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
1445                         String fieldName = searchResultField.getFieldName();
1446                         String fieldValue = searchResultField.getFieldValue() != null ? searchResultField.getFieldValue() : "";
1447 
1448                         if (fieldName.equalsIgnoreCase(Bib.TITLE) && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("bibliographic")) {
1449 
1450 
1451                             oleLoanDocument.setTitle(fieldValue);
1452                         } else if (fieldName.equalsIgnoreCase(Bib.AUTHOR) && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("bibliographic")) {
1453 
1454 
1455                             oleLoanDocument.setAuthor(fieldValue);
1456 
1457                         } else if (fieldName.equalsIgnoreCase(Item.CALL_NUMBER) && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("item")) {
1458 
1459 
1460                             oleLoanDocument.setItemCallNumber(fieldValue);
1461 
1462                         } else if (fieldName.equalsIgnoreCase(Item.COPY_NUMBER) && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("item")) {
1463 
1464 
1465                             oleLoanDocument.setItemCopyNumber(fieldValue);
1466 
1467                         }  else if (fieldName.equalsIgnoreCase(Item.ENUMERATION) && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("item")) {
1468 
1469 
1470                             oleLoanDocument.setItemVolumeNumber(fieldValue);
1471 
1472                         }
1473 
1474                     }
1475                 }
1476             } else {
1477                 item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(oleLoanDocument.getItemUuid());
1478                 ItemOlemlRecordProcessor itemOlemlRecordProcessor=new ItemOlemlRecordProcessor();
1479                 org.kuali.ole.docstore.common.document.content.instance.Item itemXML=itemOlemlRecordProcessor.fromXML(item.getContent());
1480 
1481                 oleLoanDocument.setItemCallNumber(itemXML.getCallNumber().getNumber());
1482                 oleLoanDocument.setAuthor(item.getHolding().getBib().getAuthor());
1483                 oleLoanDocument.setItemVolumeNumber(itemXML.getVolumeNumber());
1484                 oleLoanDocument.setItemCopyNumber(itemXML.getCopyNumber());
1485                 oleLoanDocument.setTitle(item.getHolding().getBib().getTitle());
1486 
1487 
1488             }
1489 
1490 
1491         } catch (Exception e) {
1492            LOG.error("Exception while generating mail content from patron bill",e);
1493         }
1494         String issue = new String(" ");
1495         contentForSendMail.append("<TR><TD>Title</TD><TD>:</TD><TD>" + oleLoanDocument.getTitle() + "</TD></TR>");
1496         contentForSendMail.append("<TR><TD>Author</TD><TD>:</TD><TD>" + oleLoanDocument.getAuthor() + "</TD></TR>");
1497         contentForSendMail.append("<TR><TD>Volume/Issue/Copy # </TD><TD>:</TD><TD>" + (oleLoanDocument.getItemVolumeNumber()!=null? oleLoanDocument.getItemVolumeNumber():"") + "/" + issue + "/" +  (oleLoanDocument.getItemCopyNumber()!=null? oleLoanDocument.getItemCopyNumber():"")+ "</TD></TR>");
1498         contentForSendMail.append("<TR><TD>Library Shelving Location</TD><TD>:</TD><TD>" + oleLoanDocument.getLocation() + "</TD></TR>");
1499         contentForSendMail.append("<TR><TD>Call Number</TD><TD>:</TD><TD>" + (oleLoanDocument.getItemCallNumber()!=null? oleLoanDocument.getItemCallNumber():"") + "</TD></TR>");
1500         contentForSendMail.append("<TR><TD>Item was Due</TD><TD>:</TD><TD>" + (oleLoanDocument.getLoanDueDate()!=null ? sdf.format(oleLoanDocument.getLoanDueDate()) : "") + "</TD></TR>");
1501         contentForSendMail.append("</TABLE>");
1502         contentForSendMail.append("</BODY>");
1503         contentForSendMail.append("</HTML>");
1504         return contentForSendMail.toString();
1505     }
1506 
1507     public void getPdfTemplateFooterList(List<OleNoticeBo> oleNoticeBoList, Document document) throws Exception {
1508 
1509         SimpleDateFormat dateFormat = new SimpleDateFormat(OLEConstants.DATEFORMAT);
1510         SimpleDateFormat sdf = new SimpleDateFormat(OLEConstants.TIMESTAMP);
1511         int count = 0;
1512         for (OleNoticeBo noticeBo : oleNoticeBoList) {
1513             if (LOG.isDebugEnabled()){
1514                 LOG.debug("Footer for the notice : " + noticeBo.getNoticeName() + noticeBo.getItemId());
1515             }
1516             Paragraph paraGraph = new Paragraph();
1517             if (count == 0) {
1518                 paraGraph.add(new Chunk("Title/item information", boldFont));
1519             }
1520             paraGraph.add(Chunk.NEWLINE);
1521             paraGraph.add(Chunk.NEWLINE);
1522             document.add(paraGraph);
1523             PdfPTable pdfTable = new PdfPTable(3);
1524             pdfTable.setWidths(new int[]{20, 2, 30});
1525             PdfPCell pdfPCell;
1526             if (!noticeBo.getNoticeName().equalsIgnoreCase(OLEConstants.NOTICE_RECALL)) {
1527                 pdfPCell = new PdfPCell(new Paragraph("Circulation Location / Library Name"));
1528                 pdfPCell.setBorder(pdfPCell.NO_BORDER);
1529                 pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1530                 pdfTable.addCell(pdfPCell);
1531                 pdfPCell = new PdfPCell(new Paragraph(":"));
1532                 pdfPCell.setBorder(pdfPCell.NO_BORDER);
1533                 pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1534                 pdfTable.addCell(pdfPCell);
1535                 pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getCirculationDeskName() != null ? noticeBo.getCirculationDeskName() : "")));
1536                 pdfPCell.setBorder(pdfPCell.NO_BORDER);
1537                 pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1538                 pdfTable.addCell(pdfPCell);
1539             }
1540             pdfPCell = new PdfPCell(new Paragraph("Title "));
1541             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1542             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1543             pdfTable.addCell(pdfPCell);
1544             pdfPCell = new PdfPCell(new Paragraph(":"));
1545             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1546             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1547             pdfTable.addCell(pdfPCell);
1548             pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getTitle() == null ? "" : noticeBo.getTitle())));
1549             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1550             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1551             pdfTable.addCell(pdfPCell);
1552             pdfPCell = new PdfPCell(new Paragraph(new Chunk("Author ")));
1553             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1554             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1555             pdfTable.addCell(pdfPCell);
1556             pdfPCell = new PdfPCell(new Paragraph(":"));
1557             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1558             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1559             pdfTable.addCell(pdfPCell);
1560             pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getAuthor() == null ? "" : noticeBo.getAuthor())));
1561             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1562             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1563             pdfTable.addCell(pdfPCell);
1564             pdfPCell = new PdfPCell(new Paragraph(new Chunk("Volume/Issue/Copy # ")));
1565             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1566             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1567             pdfTable.addCell(pdfPCell);
1568             pdfPCell = new PdfPCell(new Paragraph(":"));
1569             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1570             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1571             pdfTable.addCell(pdfPCell);
1572             pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getVolumeNumber() == null ? "" : noticeBo.getVolumeNumber())));
1573             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1574             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1575             pdfTable.addCell(pdfPCell);
1576             pdfPCell = new PdfPCell(new Paragraph(new Chunk("Library shelving location ")));
1577             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1578             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1579             pdfTable.addCell(pdfPCell);
1580             pdfPCell = new PdfPCell(new Paragraph(":"));
1581             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1582             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1583             pdfTable.addCell(pdfPCell);
1584             pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getItemShelvingLocation() == null ? "" : noticeBo.getItemShelvingLocation())));
1585             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1586             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1587             pdfTable.addCell(pdfPCell);
1588             pdfPCell = new PdfPCell(new Paragraph(new Chunk("Call # ")));
1589             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1590             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1591             pdfTable.addCell(pdfPCell);
1592             pdfPCell = new PdfPCell(new Paragraph(":"));
1593             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1594             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1595             pdfTable.addCell(pdfPCell);
1596             pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getItemCallNumber() == null ? "" : noticeBo.getItemCallNumber())));
1597             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1598             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1599             pdfTable.addCell(pdfPCell);
1600             pdfPCell = new PdfPCell(new Paragraph(new Chunk("Item barcode")));
1601             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1602             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1603             pdfTable.addCell(pdfPCell);
1604             pdfPCell = new PdfPCell(new Paragraph(":"));
1605             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1606             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1607             pdfTable.addCell(pdfPCell);
1608             pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getItemId() == null ? "" : noticeBo.getItemId())));
1609             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1610             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1611             pdfTable.addCell(pdfPCell);
1612             if (noticeBo.getExpiredOnHoldDate() != null) {
1613                 pdfPCell = new PdfPCell(new Paragraph(new Chunk("Expiration onHoldDate")));
1614                 pdfPCell.setBorder(pdfPCell.NO_BORDER);
1615                 pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1616                 pdfTable.addCell(pdfPCell);
1617                 pdfPCell = new PdfPCell(new Paragraph(":"));
1618                 pdfPCell.setBorder(pdfPCell.NO_BORDER);
1619                 pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1620                 pdfTable.addCell(pdfPCell);
1621                 pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getExpiredOnHoldDate() == null ? "" : dateFormat.format(noticeBo.getExpiredOnHoldDate()))));
1622                 pdfPCell.setBorder(pdfPCell.NO_BORDER);
1623                 pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1624                 pdfTable.addCell(pdfPCell);
1625             }
1626             document.add(pdfTable);
1627             paraGraph = new Paragraph();
1628             paraGraph.add(Chunk.NEWLINE);
1629             document.add(paraGraph);
1630             if (noticeBo.getNoticeName().equals("OverdueNotice")) {
1631                 if (LOG.isDebugEnabled()){
1632                     LOG.debug("OverdueNotice Footer Content : " + noticeBo.getNoticeName() + noticeBo.getItemId());
1633                 }
1634                 pdfTable = new PdfPTable(3);
1635                 pdfTable.setWidths(new int[]{20, 2, 30});
1636 
1637                 pdfPCell = new PdfPCell(new Paragraph("Item was due"));
1638                 pdfPCell.setBorder(pdfPCell.NO_BORDER);
1639                 pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1640                 pdfTable.addCell(pdfPCell);
1641                 pdfPCell = new PdfPCell(new Paragraph(":"));
1642                 pdfPCell.setBorder(pdfPCell.NO_BORDER);
1643                 pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1644                 pdfTable.addCell(pdfPCell);
1645                 pdfPCell = new PdfPCell(new Paragraph(new Chunk(noticeBo.getDueDate() == null ? "" : (sdf.format(noticeBo.getDueDate()).toString()))));
1646                 pdfPCell.setBorder(pdfPCell.NO_BORDER);
1647                 pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1648                 pdfTable.addCell(pdfPCell);
1649                 document.add(pdfTable);
1650                 paraGraph = new Paragraph();
1651                 paraGraph.add(Chunk.NEWLINE);
1652                 document.add(paraGraph);
1653             }
1654             count++;
1655         }
1656     }
1657 
1658     public  String getOverdueNoticeHTMLContent(OleLoanDocument  oleLoanDocument){
1659         SimpleDateFormat sdf = new SimpleDateFormat(OLEConstants.TIMESTAMP);
1660         StringBuffer stringBuffer = new StringBuffer();
1661         try {
1662         stringBuffer.append("<table>");
1663         stringBuffer.append("<TR><TD>Title :</TD><TD>" + (oleLoanDocument.getTitle() != null ? oleLoanDocument.getTitle() : "") + "</TD></TR>");
1664         stringBuffer.append("<TR><TD>Author :</TD><TD>" + (oleLoanDocument.getAuthor() != null ? oleLoanDocument.getAuthor() : "") + "</TD></TR>");
1665         String volume = (String) oleLoanDocument.getOleItem().getEnumeration() != null && !oleLoanDocument.getOleItem().getEnumeration().equals("") ? oleLoanDocument.getOleItem().getEnumeration() : "";
1666         String issue = new String(" ");
1667         String copyNumber = (String) oleLoanDocument.getOleItem().getCopyNumber() != null && !oleLoanDocument.getOleItem().getCopyNumber().equals("") ? oleLoanDocument.getOleItem().getCopyNumber() : "";
1668         String volumeNumber=volume + "/" + issue + "/" + copyNumber;
1669         stringBuffer.append("<TR><TD>Volume/Issue/Copy Number :</TD><TD>" + (volumeNumber != null ? volumeNumber : "") + "</TD></TR>");
1670         stringBuffer.append("<TR><TD>Item was due :</TD><TD>" + (oleLoanDocument.getLoanDueDate() != null ? sdf.format(oleLoanDocument.getLoanDueDate()).toString() : "") + "</TD></TR>");
1671         stringBuffer.append("<TR><TD>Library shelving location :</TD><TD>" + (itemShelvingLocationName(oleLoanDocument.getItemLocation()) != null ? itemShelvingLocationName(oleLoanDocument.getItemLocation()) : "") + "</TD></TR>");
1672         try {
1673             String callNumber = "";
1674             if (oleLoanDocument.getOleItem().getCallNumber().getNumber() != null && !oleLoanDocument.getOleItem().getCallNumber().getNumber().equals("")) {
1675                 callNumber = (String) (oleLoanDocument.getOleItem()!=null&&oleLoanDocument.getOleItem().getCallNumber().getNumber() != null && !oleLoanDocument.getOleItem().getCallNumber().getNumber().equals("") ? oleLoanDocument.getOleItem().getCallNumber().getNumber() : "");
1676             } else {
1677                 callNumber = getLoanProcessor().getItemCallNumber(oleLoanDocument.getOleItem(), oleLoanDocument.getInstanceUuid());
1678             }
1679             stringBuffer.append("<TR><TD>Call Number :</TD><TD>" + (callNumber != null ? callNumber : "") + "</TD></TR>");
1680         } catch (Exception e) {
1681             e.printStackTrace();
1682         }
1683         stringBuffer.append("<TR><TD>Item Barcode :</TD><TD>" + (oleLoanDocument.getItemId() != null ? oleLoanDocument.getItemId() : "") + "</TD></TR>");
1684         stringBuffer.append("<TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>");
1685         stringBuffer.append("</table>");
1686         }catch (Exception e){
1687             LOG.error("Error---->While generating verdue content for email pdf  ");
1688             if(oleLoanDocument!=null){
1689                 LOG.error("Error---->Item Barcode "+oleLoanDocument.getItemId());
1690             }
1691             LOG.error(e.getMessage()+e);
1692         }
1693         return stringBuffer.toString();
1694     }
1695     public String getHeaderAndPatronContent(OlePatronDocument olePatronDocument,boolean isOverdue){
1696 
1697         StringBuffer stringBuffer = new StringBuffer();
1698         try{
1699         String title = getLoanProcessor().getParameter(OLEParameterConstants.OVERDUE_TITLE);
1700         String body = getLoanProcessor().getParameter(OLEParameterConstants.OVERDUE_BODY);
1701         if(!isOverdue){
1702             title=loanProcessor.getParameter(OLEParameterConstants.COURTESY_TITLE);
1703             body=loanProcessor.getParameter(OLEParameterConstants.COURTESY_BODY);
1704         }
1705         OleDeliverRequestDocumentHelperServiceImpl deliverService = new OleDeliverRequestDocumentHelperServiceImpl();
1706         EntityTypeContactInfoBo entityTypeContactInfoBo = olePatronDocument.getEntity().getEntityTypeContactInfos().get(0);
1707 
1708         stringBuffer.append("<HTML>");
1709         stringBuffer.append("<TITLE>" + title + "</TITLE>");
1710         stringBuffer.append("<HEAD></HEAD>");
1711         stringBuffer.append("<BODY>");
1712 
1713         try{
1714         stringBuffer.append("<TABLE></BR></BR>");
1715         stringBuffer.append("<TR><TD>Patron Name :</TD><TD>" + olePatronDocument.getEntity().getNames().get(0).getFirstName() + " " + olePatronDocument.getEntity().getNames().get(0).getLastName() + "</TD></TR>");
1716         stringBuffer.append("<TR><TD>Address :</TD><TD>" + (deliverService.getPatronPreferredAddress(entityTypeContactInfoBo) != null ? deliverService.getPatronPreferredAddress(entityTypeContactInfoBo) : "") + "</TD></TR>");
1717         stringBuffer.append("<TR><TD>EMAIL :</TD><TD>" + (deliverService.getPatronHomeEmailId(entityTypeContactInfoBo) != null ? deliverService.getPatronHomeEmailId(entityTypeContactInfoBo) : "") + "</TD></TR>");
1718 
1719         stringBuffer.append("<TR><TD>Phone Number :</TD><TD>" +(deliverService.getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? deliverService.getPatronHomePhoneNumber(entityTypeContactInfoBo) : "") + "</TD></TR>");
1720         } catch (Exception e){
1721             e.printStackTrace();
1722         }
1723         stringBuffer.append("</TABLE>");
1724 
1725         stringBuffer.append("<TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>");
1726         stringBuffer.append("<TABLE width=\"100%\">");
1727         stringBuffer.append("<TR><TD><CENTER>" + title + "</CENTER></TD></TR>");
1728         stringBuffer.append("<TR><TD><p>" + body + "</p></TD></TR>");
1729         stringBuffer.append("<TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR></TABLE>");
1730         }catch (Exception e){
1731             LOG.error("Error---->While generating overdue content for email(Patron Information) ");
1732         }
1733         return stringBuffer.toString();
1734     }
1735 
1736     public void getHeaderAndPatronPDFContent(OlePatronDocument olePatronDocument,boolean isOverdue){
1737         Document document = new Document(PageSize.A4);
1738         OutputStream outputStream=null;
1739         try {
1740             String title = getLoanProcessor().getParameter(OLEParameterConstants.OVERDUE_TITLE);
1741             String body = getLoanProcessor().getParameter(OLEParameterConstants.OVERDUE_BODY);
1742             if(!isOverdue){
1743                 title=loanProcessor.getParameter(OLEParameterConstants.COURTESY_TITLE);
1744                 body=loanProcessor.getParameter(OLEParameterConstants.COURTESY_BODY);
1745             }
1746             outputStream = getPdfHeader(document, outputStream, title, olePatronDocument.getOlePatronId());
1747             OleDeliverRequestDocumentHelperServiceImpl deliverService = new OleDeliverRequestDocumentHelperServiceImpl();
1748             EntityTypeContactInfoBo entityTypeContactInfoBo = olePatronDocument.getEntity().getEntityTypeContactInfos().get(0);
1749             Paragraph paraGraph = new Paragraph();
1750             paraGraph.add(Chunk.NEWLINE);
1751             document.add(paraGraph);
1752             paraGraph = new Paragraph();
1753             paraGraph.add(new Chunk("Patron information", boldFont));
1754             paraGraph.add(Chunk.NEWLINE);
1755             paraGraph.add(Chunk.NEWLINE);
1756             document.add(paraGraph);
1757 
1758             PdfPTable pdfTable = new PdfPTable(3);
1759             pdfTable.setWidths(new int[]{20, 2, 30});
1760             PdfPCell pdfPCell = new PdfPCell(new Paragraph("Patron Name"));
1761             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1762             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1763             pdfTable.addCell(pdfPCell);
1764             pdfPCell = new PdfPCell(new Paragraph(":"));
1765             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1766             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1767             pdfTable.addCell(pdfPCell);
1768             pdfPCell = new PdfPCell(new Paragraph(new Chunk(olePatronDocument.getEntity().getNames().get(0).getFirstName() + " " + olePatronDocument.getEntity().getNames().get(0).getLastName())));
1769             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1770             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1771             pdfTable.addCell(pdfPCell);
1772             pdfPCell = new PdfPCell(new Paragraph(new Chunk("Address")));
1773             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1774             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1775             pdfTable.addCell(pdfPCell);
1776             pdfPCell = new PdfPCell(new Paragraph(":"));
1777             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1778             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1779             pdfTable.addCell(pdfPCell);
1780             pdfPCell = new PdfPCell(new Paragraph(new Chunk(deliverService.getPatronPreferredAddress(entityTypeContactInfoBo) != null ? deliverService.getPatronPreferredAddress(entityTypeContactInfoBo) : "")));
1781             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1782             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1783             pdfTable.addCell(pdfPCell);
1784             pdfPCell = new PdfPCell(new Paragraph(new Chunk("Email")));
1785             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1786             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1787             pdfTable.addCell(pdfPCell);
1788             pdfPCell = new PdfPCell(new Paragraph(":"));
1789             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1790             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1791             pdfTable.addCell(pdfPCell);
1792             pdfPCell = new PdfPCell(new Paragraph(new Chunk(deliverService.getPatronHomeEmailId(entityTypeContactInfoBo) != null ? deliverService.getPatronHomeEmailId(entityTypeContactInfoBo) : "")));
1793             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1794             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1795             pdfTable.addCell(pdfPCell);
1796             pdfPCell = new PdfPCell(new Paragraph(new Chunk("Phone #")));
1797             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1798             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1799             pdfTable.addCell(pdfPCell);
1800             pdfPCell = new PdfPCell(new Paragraph(":"));
1801             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1802             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1803             pdfTable.addCell(pdfPCell);
1804             pdfPCell = new PdfPCell(new Paragraph(new Chunk(deliverService.getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? deliverService.getPatronHomePhoneNumber(entityTypeContactInfoBo) : "")));
1805             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1806             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1807             pdfTable.addCell(pdfPCell);
1808             document.add(pdfTable);
1809             paraGraph = new Paragraph();
1810             paraGraph.add(Chunk.NEWLINE);
1811             document.add(paraGraph);
1812 
1813 
1814             getPdfTemplateBody(document, title, body);
1815             paraGraph = new Paragraph();
1816             paraGraph.add(new Chunk("Title/item information", boldFont));
1817             paraGraph.add(Chunk.NEWLINE);
1818             paraGraph.add(Chunk.NEWLINE);
1819             document.add(paraGraph);
1820             this.setOverdueDocument(document);
1821             this.setOverdueOutPutStream(outputStream);
1822         } catch (Exception e) {
1823            LOG.error("Error---->While generating overdue notice pdf (Patron Information) "+e.getMessage()+e);
1824         }
1825 
1826     }
1827 
1828     public Document getOverdueNoticePDFContent(OleLoanDocument oleLoanDocument, boolean isOverdue, Document document) {
1829         try {
1830             Paragraph paraGraph = new Paragraph();
1831             OleDeliverRequestDocumentHelperServiceImpl deliverService = new OleDeliverRequestDocumentHelperServiceImpl();
1832             SimpleDateFormat sdf = new SimpleDateFormat(OLEConstants.TIMESTAMP);
1833             PdfPTable pdfTable = new PdfPTable(3);
1834             pdfTable.setWidths(new int[]{20, 2, 30});
1835             PdfPCell pdfPCell = new PdfPCell(new Paragraph("Circulation Location / Library Name"));
1836             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1837             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1838             pdfTable.addCell(pdfPCell);
1839             pdfPCell = new PdfPCell(new Paragraph(":"));
1840             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1841             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1842             pdfTable.addCell(pdfPCell);
1843             OleCirculationDesk oleCirculationDesk = deliverService.getOleCirculationDesk(oleLoanDocument.getCirculationLocationId());
1844             pdfPCell = new PdfPCell(new Paragraph(new Chunk(oleCirculationDesk.getCirculationDeskPublicName() != null ? oleCirculationDesk.getCirculationDeskPublicName() : "")));
1845             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1846             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1847             pdfTable.addCell(pdfPCell);
1848 
1849             pdfPCell = new PdfPCell(new Paragraph("Title "));
1850             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1851             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1852             pdfTable.addCell(pdfPCell);
1853             pdfPCell = new PdfPCell(new Paragraph(":"));
1854             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1855             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1856             pdfTable.addCell(pdfPCell);
1857             pdfPCell = new PdfPCell(new Paragraph(new Chunk(oleLoanDocument.getTitle() == null ? "" : oleLoanDocument.getTitle())));
1858             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1859             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1860             pdfTable.addCell(pdfPCell);
1861             pdfPCell = new PdfPCell(new Paragraph(new Chunk("Author ")));
1862             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1863             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1864             pdfTable.addCell(pdfPCell);
1865             pdfPCell = new PdfPCell(new Paragraph(":"));
1866             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1867             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1868             pdfTable.addCell(pdfPCell);
1869             pdfPCell = new PdfPCell(new Paragraph(new Chunk(oleLoanDocument.getAuthor() == null ? "" : oleLoanDocument.getAuthor())));
1870             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1871             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1872             pdfTable.addCell(pdfPCell);
1873             pdfPCell = new PdfPCell(new Paragraph(new Chunk("Volume/Issue/Copy # ")));
1874             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1875             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1876             pdfTable.addCell(pdfPCell);
1877             pdfPCell = new PdfPCell(new Paragraph(":"));
1878             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1879             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1880             pdfTable.addCell(pdfPCell);
1881             String volume = (String) oleLoanDocument.getOleItem().getEnumeration() != null && !oleLoanDocument.getOleItem().getEnumeration().equals("") ? oleLoanDocument.getOleItem().getEnumeration() : "";
1882             String issue = new String(" ");
1883             String copyNumber = (String) oleLoanDocument.getOleItem().getCopyNumber() != null && !oleLoanDocument.getOleItem().getCopyNumber().equals("") ? oleLoanDocument.getOleItem().getCopyNumber() : "";
1884             String volumeNumber = volume + "/" + issue + "/" + copyNumber;
1885             pdfPCell = new PdfPCell(new Paragraph(new Chunk(volumeNumber == null ? "" : volumeNumber)));
1886             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1887             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1888             pdfTable.addCell(pdfPCell);
1889             pdfPCell = new PdfPCell(new Paragraph(new Chunk("Library shelving location ")));
1890             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1891             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1892             pdfTable.addCell(pdfPCell);
1893             pdfPCell = new PdfPCell(new Paragraph(":"));
1894             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1895             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1896             pdfTable.addCell(pdfPCell);
1897             pdfPCell = new PdfPCell(new Paragraph(new Chunk(oleLoanDocument.getItemLocation() == null ? "" : oleLoanDocument.getItemLocation())));
1898             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1899             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1900             pdfTable.addCell(pdfPCell);
1901             pdfPCell = new PdfPCell(new Paragraph(new Chunk("Call # ")));
1902             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1903             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1904             pdfTable.addCell(pdfPCell);
1905             pdfPCell = new PdfPCell(new Paragraph(":"));
1906             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1907             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1908             pdfTable.addCell(pdfPCell);
1909             String callNumber = "";
1910             if (oleLoanDocument.getOleItem().getCallNumber().getNumber() != null && !oleLoanDocument.getOleItem().getCallNumber().getNumber().equals("")) {
1911                 callNumber = (String) (oleLoanDocument.getOleItem().getCallNumber().getNumber() != null && !oleLoanDocument.getOleItem().getCallNumber().getNumber().equals("") ? oleLoanDocument.getOleItem().getCallNumber().getNumber() : "");
1912             } else {
1913                 callNumber = getLoanProcessor().getItemCallNumber(oleLoanDocument.getOleItem(), oleLoanDocument.getInstanceUuid());
1914             }
1915             pdfPCell = new PdfPCell(new Paragraph(new Chunk(callNumber == null ? "" : callNumber)));
1916             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1917             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1918             pdfTable.addCell(pdfPCell);
1919             pdfPCell = new PdfPCell(new Paragraph(new Chunk("Item barcode")));
1920             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1921             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1922             pdfTable.addCell(pdfPCell);
1923             pdfPCell = new PdfPCell(new Paragraph(":"));
1924             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1925             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1926             pdfTable.addCell(pdfPCell);
1927             pdfPCell = new PdfPCell(new Paragraph(new Chunk(oleLoanDocument.getItemId() == null ? "" : oleLoanDocument.getItemId())));
1928             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1929             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1930             pdfTable.addCell(pdfPCell);
1931             document.add(pdfTable);
1932             paraGraph = new Paragraph();
1933             paraGraph.add(Chunk.NEWLINE);
1934             document.add(paraGraph);
1935 
1936             pdfTable = new PdfPTable(3);
1937             pdfTable.setWidths(new int[]{20, 2, 30});
1938 
1939             pdfPCell = new PdfPCell(new Paragraph("Item was due"));
1940             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1941             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1942             pdfTable.addCell(pdfPCell);
1943             pdfPCell = new PdfPCell(new Paragraph(":"));
1944             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1945             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
1946             pdfTable.addCell(pdfPCell);
1947             pdfPCell = new PdfPCell(new Paragraph(new Chunk(oleLoanDocument.getLoanDueDate() == null ? "" : (sdf.format(oleLoanDocument.getLoanDueDate()).toString()))));
1948             pdfPCell.setBorder(pdfPCell.NO_BORDER);
1949             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
1950             pdfTable.addCell(pdfPCell);
1951             document.add(pdfTable);
1952             paraGraph = new Paragraph();
1953             paraGraph.add(Chunk.NEWLINE);
1954             document.add(paraGraph);
1955 
1956         } catch (Exception e) {
1957             LOG.error("Error---->While generating overdue notice pdf  ");
1958             if(oleLoanDocument!=null){
1959                 LOG.error("Error---->Item Barcode "+oleLoanDocument.getItemId());
1960             }
1961             LOG.error(e.getMessage()+e);
1962         }
1963        return document;
1964     }
1965 
1966     public boolean cleanZeroByteFiles() {
1967         boolean isFileDeleted=false;
1968         String pdfLocationSystemParam = getLoanProcessor().getParameter(OLEParameterConstants.PDF_LOCATION);
1969         if (LOG.isDebugEnabled()) {
1970             LOG.debug("System Parameter for PDF_Location --> " + pdfLocationSystemParam);
1971         }
1972         if (pdfLocationSystemParam == null || pdfLocationSystemParam.trim().isEmpty()) {
1973             pdfLocationSystemParam = ConfigContext.getCurrentContextConfig().getProperty("staging.directory") + "/";
1974             if (LOG.isDebugEnabled()) {
1975                 LOG.debug("System Parameter for PDF_Location staging dir--> " + pdfLocationSystemParam);
1976             }
1977         } else {
1978             pdfLocationSystemParam = ConfigContext.getCurrentContextConfig().getProperty("homeDirectory") + "/" + pdfLocationSystemParam + "/";
1979         }
1980         File file=new File(pdfLocationSystemParam);
1981         boolean locationExist = file.exists();
1982         if(locationExist){
1983             try {
1984                 File folder = new File(pdfLocationSystemParam);
1985                 File[] listOfFiles = folder.listFiles();
1986                 for (File file1 : listOfFiles) {
1987                     if (file1.isFile() && file1.length()==0) {
1988                         file1.delete();
1989                     }
1990                 }
1991             }  catch (Exception e) {
1992 
1993                LOG.error("Error in deleting the file"+e.getMessage());
1994             }
1995         }
1996        return isFileDeleted;
1997     }
1998 
1999 }