View Javadoc
1   package org.kuali.ole.batch.service;
2   
3   import com.lowagie.text.*;
4   import com.lowagie.text.pdf.PdfPCell;
5   import com.lowagie.text.pdf.PdfPTable;
6   import com.lowagie.text.pdf.PdfWriter;
7   import org.apache.commons.lang.StringUtils;
8   import org.apache.commons.lang.time.DateUtils;
9   import org.apache.log4j.Logger;
10  import org.kuali.ole.OLEConstants;
11  import org.kuali.ole.OLEParameterConstants;
12  import org.kuali.ole.batch.bo.OLEBatchProcessJobDetailsBo;
13  import org.kuali.ole.batch.bo.OLEClaimNotice;
14  import org.kuali.ole.batch.form.OLEClaimNoticeForm;
15  import org.kuali.ole.deliver.batch.OleMailer;
16  import org.kuali.ole.deliver.processor.LoanProcessor;
17  import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
18  import org.kuali.ole.docstore.common.document.Bib;
19  import org.kuali.ole.docstore.common.document.BibMarc;
20  import org.kuali.ole.docstore.discovery.service.QueryService;
21  import org.kuali.ole.docstore.discovery.service.QueryServiceImpl;
22  import org.kuali.ole.docstore.model.bo.WorkBibDocument;
23  import org.kuali.ole.docstore.model.enums.DocType;
24  import org.kuali.ole.module.purap.businessobject.PurchaseOrderType;
25  import org.kuali.ole.select.bo.*;
26  import org.kuali.ole.select.businessobject.OleCopy;
27  import org.kuali.ole.select.businessobject.OlePurchaseOrderItem;
28  import org.kuali.ole.select.document.OlePurchaseOrderDocument;
29  import org.kuali.ole.select.lookup.DocData;
30  import org.kuali.ole.select.service.OleTransmissionService;
31  import org.kuali.ole.service.impl.OLESerialReceivingService;
32  import org.kuali.ole.service.impl.OLESerialReceivingServiceImpl;
33  import org.kuali.ole.sys.context.SpringContext;
34  import org.kuali.ole.vnd.businessobject.VendorDetail;
35  import org.kuali.ole.vnd.businessobject.VendorTransmissionFormatDetail;
36  import org.kuali.rice.core.api.CoreApiServiceLocator;
37  import org.kuali.rice.core.api.config.property.ConfigContext;
38  import org.kuali.rice.core.api.mail.EmailBody;
39  import org.kuali.rice.core.api.mail.EmailFrom;
40  import org.kuali.rice.core.api.mail.EmailSubject;
41  import org.kuali.rice.core.api.mail.EmailTo;
42  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
43  import org.kuali.rice.core.api.util.type.KualiInteger;
44  import org.kuali.rice.coreservice.api.CoreServiceApiServiceLocator;
45  import org.kuali.rice.coreservice.api.parameter.Parameter;
46  import org.kuali.rice.coreservice.api.parameter.ParameterKey;
47  import org.kuali.rice.coreservice.impl.parameter.ParameterBo;
48  import org.kuali.rice.krad.maintenance.MaintenanceDocument;
49  import org.kuali.rice.krad.service.BusinessObjectService;
50  import org.kuali.rice.krad.service.DocumentService;
51  import org.kuali.rice.krad.util.GlobalVariables;
52  
53  
54  import java.io.File;
55  import java.io.FileOutputStream;
56  import java.io.OutputStream;
57  import java.math.BigDecimal;
58  import java.text.SimpleDateFormat;
59  import java.util.*;
60  import java.util.Date;
61  import java.util.List;
62  
63  /**
64   * Created with IntelliJ IDEA.
65   * User: vivekb
66   * Date: 11/7/12
67   * Time: 3:38 PM
68   * To change this template use File | Settings | File Templates.
69   */
70  public class OLEClaimNoticeService {
71  
72      private static final Logger LOG = Logger.getLogger(OLEClaimNoticeService.class);
73  
74      private BusinessObjectService businessObjectService;
75  
76      private int totalCount = 0;
77  
78      private int successRecord = 0;
79  
80      private DocstoreClientLocator docstoreClientLocator;
81  
82      public BusinessObjectService getBusinessObjectService() {
83          if (null == businessObjectService) {
84              return  SpringContext.getBean(BusinessObjectService.class);
85          }
86          return businessObjectService;
87      }
88  
89      public void setBusinessObjectService(BusinessObjectService businessObjectService) {
90          this.businessObjectService = businessObjectService;
91      }
92  
93      public DocstoreClientLocator getDocstoreClientLocator() {
94          if (null == docstoreClientLocator) {
95              return  SpringContext.getBean(DocstoreClientLocator.class);
96          }
97          return docstoreClientLocator;
98      }
99  
100     public void generateClaimReports(OLEBatchProcessJobDetailsBo job) {
101         LOG.info("Start of scheduled job to execute generateClaimReports.");
102       //  generateClaimReportFromSRR();
103         List<OlePurchaseOrderItem> olePurchaseOrderItems = ( List<OlePurchaseOrderItem> )businessObjectService.findAll(OlePurchaseOrderItem.class);
104         generateClaimReportFromPO(olePurchaseOrderItems,true);
105         job.setTotalNoOfRecords(totalCount+"");
106         job.setNoOfRecordsProcessed(totalCount+"");
107         job.setNoOfSuccessRecords(successRecord + "");
108         job.setNoOfFailureRecords((totalCount - successRecord) + "");
109         job.setStatus(OLEConstants.OLEBatchProcess.JOB_STATUS_COMPLETED);
110         job.setStatusDesc(OLEConstants.OLEBatchProcess.JOB_STATUS_COMPLETED);
111     }
112 
113     public void generateClaimReportFromSRR(){
114         try {
115             LOG.info("Start of scheduled job to execute generateClaimReportFromSRR.");
116             OLESerialReceivingService oleSerialReceivingService = new OLESerialReceivingServiceImpl();
117             List<OLESerialReceivingDocument> oleSerialReceivingDocuments = ( List<OLESerialReceivingDocument> )businessObjectService.findAll(OLESerialReceivingDocument.class);
118             for(OLESerialReceivingDocument oleSerialReceivingDocument : oleSerialReceivingDocuments){
119                 List<OLESerialReceivingHistory> oleSerialReceivingHistoryList = oleSerialReceivingDocument.getOleSerialReceivingHistoryList();
120                 totalCount = oleSerialReceivingHistoryList.size();
121                 for(OLESerialReceivingHistory oleSerialReceivingHistory : oleSerialReceivingHistoryList){
122                     Map parentCriterial = new HashMap();
123                     parentCriterial.put("serialReceivingIdentifier",oleSerialReceivingDocument.getSerialReceivingRecordId());
124                     List<OleCopy> copyList = (List<OleCopy>) businessObjectService.findMatching(OleCopy.class,parentCriterial);
125                     Boolean doNotClaim = false;
126                     if(copyList.size()>0){
127                         Integer poItemId = copyList.get(0).getPoItemId();
128                         Map map = new HashMap();
129                         map.put("itemIdentifier",poItemId);
130                         OlePurchaseOrderItem olePurchaseOrderItem = businessObjectService.findByPrimaryKey(OlePurchaseOrderItem.class,map);
131                         doNotClaim = olePurchaseOrderItem.isDoNotClaim();
132                     }
133                     if(oleSerialReceivingHistory.getReceiptStatus().equalsIgnoreCase(OLEConstants.CLAIMED) && !doNotClaim){
134                         String emailAddress ="";
135                         if (oleSerialReceivingDocument.getVendorId() != null && oleSerialReceivingDocument.getVendorId().length() > 0) {
136                             String[] vendorDetails = oleSerialReceivingDocument.getVendorId().split("-");
137                             String vendorHeaderGeneratedIdentifier = vendorDetails[0];
138                             String vendorDetailAssignedIdentifier = vendorDetails[1];
139                             Map vendorNameMap = new HashMap();
140                             vendorNameMap.put(org.kuali.ole.sys.OLEConstants.VENDOR_HEADER_IDENTIFIER,vendorHeaderGeneratedIdentifier);
141                             vendorNameMap.put(org.kuali.ole.sys.OLEConstants.VENDOR_DETAIL_IDENTIFIER,vendorDetailAssignedIdentifier);
142                             List<VendorDetail> vendorDetailList = (List) businessObjectService.findMatching(VendorDetail.class, vendorNameMap);
143                             if(vendorDetailList != null && vendorDetailList.size() >0) {
144                                 oleSerialReceivingDocument.setVendorName(vendorDetailList.get(0).getVendorName());
145                                 if( vendorDetailList.get(0).getVendorContacts()!=null &&  vendorDetailList.get(0).getVendorContacts().size()>0){
146                                     emailAddress = vendorDetailList.get(0).getVendorContacts().get(0).getVendorContactEmailAddress();
147                                 }
148                                 if((emailAddress==null || emailAddress.isEmpty() )&& vendorDetailList.get(0).getVendorAddresses()!=null &&  vendorDetailList.get(0).getVendorAddresses().size()>0){
149                                     emailAddress = vendorDetailList.get(0).getVendorAddresses().get(0).getVendorAddressEmailAddress();
150                                 }
151                             }
152                         }
153                         LinkedHashMap<String, String> bibIdList = new LinkedHashMap<String, String>();
154                         bibIdList.put(DocType.BIB.getDescription(), oleSerialReceivingDocument.getBibId());
155                         List<WorkBibDocument> workBibDocuments = getWorkBibDocuments(bibIdList);
156                         WorkBibDocument workBibDocument = workBibDocuments != null && workBibDocuments.size() > 0 ? workBibDocuments.get(0) : null;
157                         oleSerialReceivingService.setEnumerationAndChronologyValues(oleSerialReceivingHistory);
158                         DocumentService documentService= GlobalResourceLoader.getService(OLEConstants.DOCUMENT_HEADER_SERVICE);
159                         MaintenanceDocument maintenanceDocument = (MaintenanceDocument) documentService.getNewDocument("OLE_CLM_NTC");
160                         OLEClaimNoticeBo oleClaimNoticeBo = (OLEClaimNoticeBo) maintenanceDocument.getDocumentDataObject();
161                         oleClaimNoticeBo.setNameOfTheSender(oleSerialReceivingDocument.getBoundLocation());
162                         oleClaimNoticeBo.setNameOfTheVendor(oleSerialReceivingDocument.getVendorName());
163                         oleClaimNoticeBo.setClaimDate(oleSerialReceivingHistory.getClaimDate() != null ? oleSerialReceivingHistory.getClaimDate().toString() : "");
164                         oleClaimNoticeBo.setClaimCount(oleSerialReceivingHistory.getClaimCount());
165                         oleClaimNoticeBo.setClaimType(oleSerialReceivingHistory.getClaimType());
166                         oleClaimNoticeBo.setTitle(oleSerialReceivingDocument.getTitle());
167                         if(workBibDocument!=null){
168                             oleClaimNoticeBo.setPlaceOfPublication(workBibDocument.getPublicationPlaces()!=null && workBibDocument.getPublicationPlaces().size()>0?
169                             workBibDocument.getPublicationPlaces().get(0).toString():"");
170                             oleClaimNoticeBo.setPublicationDate(workBibDocument.getPublicationDate());
171                         }
172 
173                         oleClaimNoticeBo.setPublication(oleSerialReceivingDocument.getPublisher());
174                         oleClaimNoticeBo.setEnumeration(oleSerialReceivingHistory.getEnumerationCaption());
175                         oleClaimNoticeBo.setChronology(oleSerialReceivingHistory.getChronologyCaption());
176                         oleClaimNoticeBo.setVendorsLibraryAcctNum("");
177                         oleClaimNoticeBo.setVendorOrderNumber("");
178                         oleClaimNoticeBo.setVendorTitleNumber("");
179                         oleClaimNoticeBo.setLibraryPurchaseOrderNumber(oleSerialReceivingDocument.getPoId());
180                         oleClaimNoticeBo.setUnboundLocation(oleSerialReceivingDocument.getUnboundLocation());
181                         oleClaimNoticeBo.setMailAddress(emailAddress);
182                         oleClaimNoticeBo.setActive(true);
183                         Date now = CoreApiServiceLocator.getDateTimeService().getCurrentSqlDate();
184                         maintenanceDocument.getDocumentHeader().setDocumentDescription("Claim Report"+"[date:"+now+"]");
185                         maintenanceDocument.getNewMaintainableObject().setDataObject(oleClaimNoticeBo);
186                         documentService.routeDocument(maintenanceDocument,null,null);
187                         successRecord++;
188                     }
189                 }
190             }
191         } catch (Exception ex) {
192             LOG.error("Exception occurred while performing generateClaimReportFromSRR", ex);
193         }
194     }
195 
196     public void generateClaimReportFromPO(List<OlePurchaseOrderItem> olePurchaseOrderItems,boolean isBatchMode){
197         try {
198             LOG.info("Start of scheduled job to execute generateClaimReportFromPO.");
199             SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
200             totalCount += olePurchaseOrderItems.size();
201             HashMap<String,List<OLEClaimingByTitle>> hashMap = new HashMap<>();
202             List<OLEClaimingByTitle> claimTitles = null;
203             for(OlePurchaseOrderItem olePurchaseOrderItem : olePurchaseOrderItems){
204                     if(!olePurchaseOrderItem.isDoNotClaim()){
205                         String emailAddress ="";
206                         String claimInterval="";
207                         OlePurchaseOrderDocument olePurchaseOrderDocument = olePurchaseOrderItem.getPurapDocument();
208                         boolean validPO = olePurchaseOrderDocument!=null ? olePurchaseOrderDocument.getPurchaseOrderCurrentIndicatorForSearching() : false;
209                         boolean serialPOLink = olePurchaseOrderItem.getCopyList()!=null && olePurchaseOrderItem.getCopyList().size()>0 ? olePurchaseOrderItem.getCopyList().get(0).getSerialReceivingIdentifier()!=null : false ;
210                         Map purchaseOrderTypeIdMap = new HashMap();
211                         purchaseOrderTypeIdMap.put("purchaseOrderTypeId", olePurchaseOrderDocument.getPurchaseOrderTypeId());
212                         org.kuali.rice.krad.service.BusinessObjectService businessObject = SpringContext.getBean(org.kuali.rice.krad.service.BusinessObjectService.class);
213                         List<PurchaseOrderType> purchaseOrderTypeDocumentList = (List) businessObject.findMatching(PurchaseOrderType.class, purchaseOrderTypeIdMap);
214                         boolean  continuing = purchaseOrderTypeDocumentList!=null && purchaseOrderTypeDocumentList.size()>0?
215                                 purchaseOrderTypeDocumentList.get(0).getPurchaseOrderType().equalsIgnoreCase("Continuing"):false;
216                         if(!serialPOLink && !continuing && validPO){
217                             VendorDetail vendorDetail =olePurchaseOrderDocument.getVendorDetail();
218                             Date date = new Date();
219                             String dateString = dateFormat.format(date);
220                             Date actionDate=olePurchaseOrderItem.getClaimDate();
221                             String actionDateString = actionDate!=null ? dateFormat.format(actionDate) : "";
222                             if( vendorDetail.getVendorContacts()!=null &&  vendorDetail.getVendorContacts().size()>0){
223                                 emailAddress = vendorDetail.getVendorContacts().get(0).getVendorContactEmailAddress();
224                                 claimInterval = vendorDetail.getClaimInterval();
225                             }
226                             if((emailAddress==null || emailAddress.isEmpty() ) && vendorDetail.getVendorAddresses()!=null &&  vendorDetail.getVendorAddresses().size()>0){
227                                 emailAddress = vendorDetail.getVendorAddresses().get(0).getVendorAddressEmailAddress();
228                             }
229                             if(actionDate!=null && (actionDateString.equals(dateString) || actionDate.before(date))){
230                                 if(!isBatchMode){
231                                     for(OlePurchaseOrderItem purchaseOrderItem : (List<OlePurchaseOrderItem>)olePurchaseOrderDocument.getItems()){
232                                            if(purchaseOrderItem.getItemIdentifier().equals(olePurchaseOrderItem.getItemIdentifier())){
233                                                if(purchaseOrderItem.getClaimCount()!=null){
234                                                    Integer count = purchaseOrderItem.getClaimCount().intValue();
235                                                    count++;
236                                                    purchaseOrderItem.setClaimCount(new KualiInteger(count));
237                                                }else {
238                                                    purchaseOrderItem.setClaimCount(new KualiInteger(1));
239                                                }
240                                                break;
241                                            }
242                                     }
243                                 }
244                                 if (hashMap.containsKey(olePurchaseOrderDocument.getVendorName())) {
245                                     claimTitles = hashMap.get(olePurchaseOrderDocument.getVendorName());
246                                     OLEClaimingByTitle oleClaimingByTitle = new OLEClaimingByTitle();
247                                     updateOleClaimingByTitle(oleClaimingByTitle,olePurchaseOrderItem,olePurchaseOrderDocument);
248                                     oleClaimingByTitle.setEmailAddress(emailAddress);
249                                     claimTitles.add(oleClaimingByTitle);
250                                     hashMap.put(olePurchaseOrderDocument.getVendorName(),claimTitles);
251                                 }
252                                 else {
253                                     claimTitles = new ArrayList<>();
254                                     OLEClaimingByTitle oleClaimingByTitle = new OLEClaimingByTitle();
255                                     updateOleClaimingByTitle(oleClaimingByTitle,olePurchaseOrderItem,olePurchaseOrderDocument);
256                                     oleClaimingByTitle.setEmailAddress(emailAddress);
257                                     claimTitles.add(oleClaimingByTitle);
258                                     hashMap.put(olePurchaseOrderDocument.getVendorName(),claimTitles);
259                                 }
260                                 OLEPOClaimHistory claimHistory = new OLEPOClaimHistory();
261                                 claimHistory.setClaimCount(olePurchaseOrderItem.getClaimCount() != null ? olePurchaseOrderItem.getClaimCount().intValue() : 0);
262                                 claimHistory.setClaimDate(new java.sql.Date(System.currentTimeMillis()));
263                                 claimHistory.setReqItemId(olePurchaseOrderItem.getCopyList().get(0).getReqItemId());
264                                 claimHistory.setOperator(GlobalVariables.getUserSession().getPrincipalName());
265                                 olePurchaseOrderItem.getClaimHistories().add(claimHistory);
266 
267                                 if (StringUtils.isNotBlank(claimInterval)) {
268                                     boolean actIntvlFlag = isNumber(claimInterval);
269                                     if (actIntvlFlag) {
270                                         Integer actIntvl = Integer.parseInt(claimInterval);
271                                         actionDate = DateUtils.addDays(new java.util.Date(), actIntvl);
272                                         olePurchaseOrderItem.setClaimDate(new java.sql.Date(actionDate.getTime()));
273                                     }
274                                 } else{
275                                     olePurchaseOrderItem.setClaimDate(null);
276                                 }
277 
278                                 businessObjectService.save(olePurchaseOrderItem);
279                             }
280                         }
281                     }
282                 }
283             Iterator<Map.Entry<String,List<OLEClaimingByTitle>>> entries = hashMap.entrySet().iterator();
284             while (entries.hasNext()) {
285                 Map.Entry<String,List<OLEClaimingByTitle>> entry = entries.next();
286                 List<OLEClaimingByTitle> oleClaimingByTitles = entry.getValue();
287                 OLEClaimingByVendor oleClaimingByVendor = new OLEClaimingByVendor();
288                 oleClaimingByVendor.setVendorName(entry.getKey());
289                 if(oleClaimingByTitles!=null && oleClaimingByTitles.size()>0){
290                     oleClaimingByVendor.setFromAddress(oleClaimingByTitles.get(0).getFromAddress());
291                     oleClaimingByVendor.setToAddress(oleClaimingByTitles.get(0).getToAddress());
292                     oleClaimingByVendor.setVendorTransmissionFormatDetail(oleClaimingByTitles.get(0).getVendorTransmissionFormatDetail());
293                     oleClaimingByVendor.setEmailAddress(oleClaimingByTitles.get(0).getEmailAddress());
294                 }
295                 oleClaimingByVendor.setOleClaimingByTitles(oleClaimingByTitles);
296                 generatePdf(oleClaimingByVendor);
297                 successRecord++;
298             }
299         } catch (Exception ex) {
300             LOG.error("Exception occurred while performing generateClaimReportFromPO", ex);
301         }
302     }
303 
304     public static boolean isNumber(String actionInterval) {
305         String actStr = actionInterval;
306         for (int i = 0; i < actStr.length(); i++) {
307             if (!Character.isDigit(actStr.charAt(i)))
308                 return false;
309         }
310         return true;
311     }
312 
313     private List<WorkBibDocument> getWorkBibDocuments(LinkedHashMap<String, String> bibIdList) {
314         List<LinkedHashMap<String, String>> bibIdMapList = new ArrayList<LinkedHashMap<String, String>>();
315         bibIdMapList.add(bibIdList);
316         QueryService queryService = QueryServiceImpl.getInstance();
317         List<WorkBibDocument> workBibDocuments = new ArrayList<WorkBibDocument>();
318         try {
319             workBibDocuments = queryService.getWorkBibRecords(bibIdMapList);
320         } catch (Exception ex) {
321             ex.printStackTrace();
322         }
323         return workBibDocuments;
324     }
325 
326     public void generatePdf(OLEClaimingByVendor oleClaimingByVendor) throws Exception {
327         Document document = new Document(PageSize.A4);
328         String pdfLocationSystemParam = getParameter(OLEParameterConstants.PDF_LOCATION);
329         if (LOG.isInfoEnabled()) {
330             LOG.info("System Parameter for PDF_Location --> " + pdfLocationSystemParam);
331         }
332         if (pdfLocationSystemParam == null || pdfLocationSystemParam.trim().isEmpty()) {
333             pdfLocationSystemParam = ConfigContext.getCurrentContextConfig().getProperty("staging.directory") + "/";
334             if (LOG.isInfoEnabled()) {
335                 LOG.info("System Parameter for PDF_Location staging dir--> " + pdfLocationSystemParam);
336             }
337         } else {
338             pdfLocationSystemParam = ConfigContext.getCurrentContextConfig().getProperty("homeDirectory") + "/" + pdfLocationSystemParam + "/";
339         }
340         boolean locationExist = new File(pdfLocationSystemParam).exists();
341         boolean fileCreated = false;
342         if (LOG.isInfoEnabled()) {
343             LOG.info("Is directory Exist ::" + locationExist);
344         }
345         try {
346             if (!locationExist) {
347                 fileCreated = new File(pdfLocationSystemParam).mkdirs();
348                 if (!fileCreated) {
349                     throw new RuntimeException("Not Able to create directory :" + pdfLocationSystemParam);
350                 }
351             }
352         } catch (Exception e) {
353             LOG.error("Exception occured while creating the directory : " + e.getMessage(), e);
354             throw e;
355         }
356 
357         String title=oleClaimingByVendor.getVendorName();
358         if (title == null || title .trim().isEmpty()) {
359             title = OLEConstants.ITEM_TITLE;
360         }
361         String fileName = pdfLocationSystemParam + title + "_" + OLEConstants.CLAIM_NOTICE+ "_" +new Date(System.currentTimeMillis()) + ".pdf";
362         fileName = fileName.replace(" ","_");
363         if (LOG.isInfoEnabled()) {
364             LOG.info("File Created :" + title + "file name ::" + fileName + "::");
365         }
366         OutputStream outputStream = new FileOutputStream(fileName);
367         PdfWriter writer = PdfWriter.getInstance(document, outputStream);
368         Font boldFont = new Font(Font.TIMES_ROMAN, 15, Font.BOLD);
369         Font ver_15_normal = FontFactory.getFont("VERDANA", 15, 0);
370         document.open();
371         document.newPage();
372         Paragraph paraGraph = new Paragraph();
373         String institutionName = oleClaimingByVendor.getFromAddress().getInstitutionName();
374         paraGraph.setAlignment(Element.ALIGN_CENTER);
375         paraGraph.add(new Chunk("Purchasing Institution Name : ", boldFont));
376         paraGraph.add(new Chunk(institutionName, boldFont));
377         paraGraph.add(Chunk.NEWLINE);
378         paraGraph.add(Chunk.NEWLINE);
379         document.add(paraGraph);
380         float[] infoWidths = {0.50f, 0.50f};
381         PdfPTable pdfTable = new PdfPTable(infoWidths);
382         pdfTable.setHorizontalAlignment(Element.ALIGN_CENTER);
383         pdfTable.setWidthPercentage(100);
384 
385         Paragraph toPara = new Paragraph();
386         toPara.add(new Chunk("To : "));
387         toPara.add(Chunk.NEWLINE);
388         if(oleClaimingByVendor.getToAddress() != null){
389             OLEClaimingAddress toAddress = oleClaimingByVendor.getToAddress();
390             updateAddress(toAddress,toPara);
391         }
392         PdfPCell pdfPCell = new PdfPCell(toPara);
393         pdfPCell.setBorder(pdfPCell.BOX);
394         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
395         pdfTable.addCell(pdfPCell);
396 
397 
398         Paragraph fromPara = new Paragraph();
399         fromPara.add(new Chunk("From : "));
400         fromPara.add(Chunk.NEWLINE);
401         if(oleClaimingByVendor.getFromAddress() != null){
402             OLEClaimingAddress fromAddress = oleClaimingByVendor.getFromAddress();
403             updateAddress(fromAddress,fromPara);
404         }
405         pdfPCell = new PdfPCell(fromPara);
406         pdfPCell.setBorder(pdfPCell.BOX);
407         pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
408         pdfTable.addCell(pdfPCell);
409         pdfTable.addCell(pdfPCell);
410 
411         document.add(pdfTable);
412 
413         paraGraph = new Paragraph();
414         paraGraph.add(Chunk.NEWLINE);
415         document.add(paraGraph);
416 
417         paraGraph = new Paragraph();
418         paraGraph.add(new Chunk("The following ordered titles have not yet been received by our library.  Please supply or report. thank you."));
419         document.add(paraGraph);
420 
421         paraGraph = new Paragraph();
422         paraGraph.add(Chunk.NEWLINE);
423         document.add(paraGraph);
424 
425         int count = 1;
426         for (OLEClaimingByTitle claimingByTitle : oleClaimingByVendor.getOleClaimingByTitles()) {
427             paraGraph = new Paragraph();
428             paraGraph.setAlignment(Element.ALIGN_LEFT);
429             paraGraph.add(new Chunk("Title" + count++, boldFont));
430             paraGraph.add(Chunk.NEWLINE);
431             document.add(paraGraph);
432 
433             pdfTable = new PdfPTable(3);
434 
435             pdfPCell = new PdfPCell(new Paragraph("Author"));
436             pdfPCell.setBorder(pdfPCell.NO_BORDER);
437             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
438             pdfTable.addCell(pdfPCell);
439             pdfPCell = new PdfPCell(new Paragraph(":"));
440             pdfPCell.setBorder(pdfPCell.NO_BORDER);
441             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
442             pdfTable.addCell(pdfPCell);
443             pdfPCell = new PdfPCell(new Paragraph(new Chunk(claimingByTitle.getAuthor() !=null ? claimingByTitle.getAuthor() : "")));
444             pdfPCell.setBorder(pdfPCell.NO_BORDER);
445             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
446             pdfTable.addCell(pdfPCell);
447 
448             pdfPCell = new PdfPCell(new Paragraph("Title"));
449             pdfPCell.setBorder(pdfPCell.NO_BORDER);
450             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
451             pdfTable.addCell(pdfPCell);
452             pdfPCell = new PdfPCell(new Paragraph(":"));
453             pdfPCell.setBorder(pdfPCell.NO_BORDER);
454             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
455             pdfTable.addCell(pdfPCell);
456             pdfPCell = new PdfPCell(new Paragraph(new Chunk(claimingByTitle.getTitle()!=null ? claimingByTitle.getTitle() : "")));
457             pdfPCell.setBorder(pdfPCell.NO_BORDER);
458             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
459             pdfTable.addCell(pdfPCell);
460 
461             pdfPCell = new PdfPCell(new Paragraph("Place Of Publication"));
462             pdfPCell.setBorder(pdfPCell.NO_BORDER);
463             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
464             pdfTable.addCell(pdfPCell);
465             pdfPCell = new PdfPCell(new Paragraph(":"));
466             pdfPCell.setBorder(pdfPCell.NO_BORDER);
467             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
468             pdfTable.addCell(pdfPCell);
469             pdfPCell = new PdfPCell(new Paragraph(new Chunk(claimingByTitle.getPlaceOfPublication() != null ? claimingByTitle.getPlaceOfPublication() : "")));
470             pdfPCell.setBorder(pdfPCell.NO_BORDER);
471             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
472             pdfTable.addCell(pdfPCell);
473 
474             pdfPCell = new PdfPCell(new Paragraph("Publisher"));
475             pdfPCell.setBorder(pdfPCell.NO_BORDER);
476             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
477             pdfTable.addCell(pdfPCell);
478             pdfPCell = new PdfPCell(new Paragraph(":"));
479             pdfPCell.setBorder(pdfPCell.NO_BORDER);
480             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
481             pdfTable.addCell(pdfPCell);
482             pdfPCell = new PdfPCell(new Paragraph(new Chunk(claimingByTitle.getPublisherName() != null ? claimingByTitle.getPublisherName() : "")));
483             pdfPCell.setBorder(pdfPCell.NO_BORDER);
484             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
485             pdfTable.addCell(pdfPCell);
486 
487             pdfPCell = new PdfPCell(new Paragraph("Publication Date"));
488             pdfPCell.setBorder(pdfPCell.NO_BORDER);
489             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
490             pdfTable.addCell(pdfPCell);
491             pdfPCell = new PdfPCell(new Paragraph(":"));
492             pdfPCell.setBorder(pdfPCell.NO_BORDER);
493             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
494             pdfTable.addCell(pdfPCell);
495             pdfPCell = new PdfPCell(new Paragraph(new Chunk(claimingByTitle.getPublicationDate() != null ? claimingByTitle.getPublicationDate()  : "")));
496             pdfPCell.setBorder(pdfPCell.NO_BORDER);
497             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
498             pdfTable.addCell(pdfPCell);
499 
500             pdfPCell = new PdfPCell(new Paragraph("ISXN"));
501             pdfPCell.setBorder(pdfPCell.NO_BORDER);
502             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
503             pdfTable.addCell(pdfPCell);
504             pdfPCell = new PdfPCell(new Paragraph(":"));
505             pdfPCell.setBorder(pdfPCell.NO_BORDER);
506             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
507             pdfTable.addCell(pdfPCell);
508             pdfPCell = new PdfPCell(new Paragraph(new Chunk(claimingByTitle.getIsxn() != null ? claimingByTitle.getIsxn() : "")));
509             pdfPCell.setBorder(pdfPCell.NO_BORDER);
510             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
511             pdfTable.addCell(pdfPCell);
512 
513             pdfPCell = new PdfPCell(new Paragraph("Vendor Item Identifier"));
514             pdfPCell.setBorder(pdfPCell.NO_BORDER);
515             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
516             pdfTable.addCell(pdfPCell);
517             pdfPCell = new PdfPCell(new Paragraph(":"));
518             pdfPCell.setBorder(pdfPCell.NO_BORDER);
519             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
520             pdfTable.addCell(pdfPCell);
521             pdfPCell = new PdfPCell(new Paragraph(new Chunk(claimingByTitle.getVendorItemIdentifier() != null ? claimingByTitle.getVendorItemIdentifier() : "")));
522             pdfPCell.setBorder(pdfPCell.NO_BORDER);
523             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
524             pdfTable.addCell(pdfPCell);
525 
526             pdfPCell = new PdfPCell(new Paragraph("PO #"));
527             pdfPCell.setBorder(pdfPCell.NO_BORDER);
528             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
529             pdfTable.addCell(pdfPCell);
530             pdfPCell = new PdfPCell(new Paragraph(":"));
531             pdfPCell.setBorder(pdfPCell.NO_BORDER);
532             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
533             pdfTable.addCell(pdfPCell);
534             pdfPCell = new PdfPCell(new Paragraph(new Chunk(claimingByTitle.getPoOrderedNum() != null ? claimingByTitle.getPoOrderedNum() : "")));
535             pdfPCell.setBorder(pdfPCell.NO_BORDER);
536             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
537             pdfTable.addCell(pdfPCell);
538 
539             pdfPCell = new PdfPCell(new Paragraph("PO Date"));
540             pdfPCell.setBorder(pdfPCell.NO_BORDER);
541             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
542             pdfTable.addCell(pdfPCell);
543             pdfPCell = new PdfPCell(new Paragraph(":"));
544             pdfPCell.setBorder(pdfPCell.NO_BORDER);
545             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
546             pdfTable.addCell(pdfPCell);
547             pdfPCell = new PdfPCell(new Paragraph(new Chunk(claimingByTitle.getPoOrderedDate() != null ? claimingByTitle.getPoOrderedDate() : "")));
548             pdfPCell.setBorder(pdfPCell.NO_BORDER);
549             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
550             pdfTable.addCell(pdfPCell);
551 
552             pdfPCell = new PdfPCell(new Paragraph("Claim #"));
553             pdfPCell.setBorder(pdfPCell.NO_BORDER);
554             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
555             pdfTable.addCell(pdfPCell);
556             pdfPCell = new PdfPCell(new Paragraph(":"));
557             pdfPCell.setBorder(pdfPCell.NO_BORDER);
558             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
559             pdfTable.addCell(pdfPCell);
560             pdfPCell = new PdfPCell(new Paragraph(new Chunk(claimingByTitle.getClaimNumber() != null ? claimingByTitle.getClaimNumber() : "")));
561             pdfPCell.setBorder(pdfPCell.NO_BORDER);
562             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
563             pdfTable.addCell(pdfPCell);
564 
565             pdfPCell = new PdfPCell(new Paragraph("Claim Note"));
566             pdfPCell.setBorder(pdfPCell.NO_BORDER);
567             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
568             pdfTable.addCell(pdfPCell);
569             pdfPCell = new PdfPCell(new Paragraph(":"));
570             pdfPCell.setBorder(pdfPCell.NO_BORDER);
571             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT);
572             pdfTable.addCell(pdfPCell);
573             pdfPCell = new PdfPCell(new Paragraph(new Chunk(claimingByTitle.getClaimNote() != null ? claimingByTitle.getClaimNote() : "")));
574             pdfPCell.setBorder(pdfPCell.NO_BORDER);
575             pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_JUSTIFIED);
576             pdfTable.addCell(pdfPCell);
577 
578             document.add(pdfTable);
579             paraGraph = new Paragraph();
580             paraGraph.add(Chunk.NEWLINE);
581             document.add(paraGraph);
582         }
583 
584         outputStream.flush();
585         document.close();
586         outputStream.close();
587 
588         OleTransmissionService transmissionService = SpringContext.getBean(OleTransmissionService.class);
589         VendorTransmissionFormatDetail vendorTransmissionFormatDetail = oleClaimingByVendor.getVendorTransmissionFormatDetail();
590         if(vendorTransmissionFormatDetail!=null){
591             String fileNam = "Claim Notice "+vendorTransmissionFormatDetail.getVendorTransmissionTypes().getVendorTransmissionType() + new Date(System.currentTimeMillis()) + ".pdf";
592             if (vendorTransmissionFormatDetail.getVendorTransmissionTypes().getVendorTransmissionType().equalsIgnoreCase("SFTP")) {
593                 transmissionService.doSFTPUpload(vendorTransmissionFormatDetail, fileName, fileNam);
594             } else if (vendorTransmissionFormatDetail.getVendorTransmissionTypes().getVendorTransmissionType().equalsIgnoreCase("FTP")) {
595                 transmissionService.doFTPUpload(vendorTransmissionFormatDetail, fileName, fileNam);
596             } else if (vendorTransmissionFormatDetail.getVendorTransmissionTypes().getVendorTransmissionType().equalsIgnoreCase("Email") && oleClaimingByVendor.getEmailAddress()!=null && !oleClaimingByVendor.getEmailAddress().isEmpty()) {
597                 OleMailer oleMail = GlobalResourceLoader.getService("oleMailer");
598                 //oleMail.sendEmail(new EmailFrom(getParameter(OLEParameterConstants.NOTICE_FROM_ADDRESS)), new EmailTo(oleClaimingByVendor.getEmailAddress()), new EmailSubject("Claim Notice"), new EmailBody(mailContent(oleClaimingByVendor)), true);
599                 List fileNameList = new ArrayList();
600                 if(fileName != null){
601                     fileNameList.add(fileName);
602                 }
603                 oleMail.SendEMail(oleClaimingByVendor.getEmailAddress(),getParameter(OLEParameterConstants.NOTICE_FROM_ADDRESS),fileNameList,OLEConstants.CLAIM_MAIL_SUBJECT,OLEConstants.CLAIM_MAIL_MSSG_BODY);
604                 LOG.info("Mail send successfully to " + oleClaimingByVendor.getEmailAddress());
605             }
606         }
607     }
608 
609     private Paragraph updateAddress(OLEClaimingAddress address,Paragraph para){
610         if(address.getVendorName() != null){
611             para.add(new Chunk(address.getVendorName()));
612             para.add(Chunk.NEWLINE);
613         }
614         if(address.getAttention() != null){
615             para.add(new Chunk("ATTN: "));
616             para.add(new Chunk(address.getAttention()));
617             para.add(Chunk.NEWLINE);
618         }
619         if(address.getAddress1() != null){
620             para.add(new Chunk(address.getAddress1()));
621             para.add(Chunk.NEWLINE);
622         }
623         if(address.getAddress2() != null){
624             para.add(new Chunk(address.getAddress2()));
625             para.add(Chunk.NEWLINE);
626         }
627         if(address.getCity() != null){
628             para.add(new Chunk(address.getCity()));
629             if (address.getState() != null || address.getPostalCode() != null || address.getProvince() != null) {
630                 para.add(new Chunk(", "));
631             } else {
632                 para.add(Chunk.NEWLINE);
633             }
634         }
635         if(address.getState() != null){
636             para.add(new Chunk(address.getState()));
637             if (address.getPostalCode() != null) {
638                 para.add(new Chunk(" "));
639             } else {
640                 para.add(Chunk.NEWLINE);
641             }
642         }
643         if(address.getPostalCode() != null){
644             para.add(new Chunk(address.getPostalCode()));
645             if (address.getProvince() != null) {
646                 para.add(new Chunk(", "));
647             } else {
648                 para.add(Chunk.NEWLINE);
649             }
650         }
651         if(address.getProvince() != null){
652             para.add(new Chunk(address.getProvince()));
653             para.add(Chunk.NEWLINE);
654         }
655         if(address.getCountry() != null){
656             para.add(new Chunk(address.getCountry()));
657             para.add(Chunk.NEWLINE);
658         }
659         return para;
660     }
661     public void updateOleClaimingByTitle(OLEClaimingByTitle oleClaimingByTitle,OlePurchaseOrderItem olePurchaseOrderItem,OlePurchaseOrderDocument olePurchaseOrderDocument){
662         Bib bib =  new BibMarc();
663         if (olePurchaseOrderItem!=null && olePurchaseOrderItem.getItemTitleId() != null && olePurchaseOrderItem.getItemTitleId() != "") {
664             try {
665                 oleClaimingByTitle.setClaimNumber(olePurchaseOrderItem.getClaimCount()!=null ? olePurchaseOrderItem.getClaimCount().toString() : "");
666                 oleClaimingByTitle.setVendorItemIdentifier(olePurchaseOrderItem.getVendorItemPoNumber()!=null? olePurchaseOrderItem.getVendorItemPoNumber() : "");
667                 bib = getDocstoreClientLocator().getDocstoreClient().retrieveBib(olePurchaseOrderItem.getItemTitleId());
668                 if(bib!=null){
669                     oleClaimingByTitle.setAuthor(bib.getAuthor());
670                     oleClaimingByTitle.setTitle(bib.getTitle());
671                     oleClaimingByTitle.setPlaceOfPublication(bib.getPublisher());
672                     oleClaimingByTitle.setPublicationDate(bib.getPublicationDate());
673                     oleClaimingByTitle.setPublisherName(bib.getPublisher());
674                     String isbn = bib.getIsbn()!=null ? bib.getIsbn() : "" ;
675                     String issn  =bib.getIssn()!=null ? bib.getIssn() : "";
676                     oleClaimingByTitle.setIsxn(isbn + issn);
677                 }
678             }catch (Exception e){
679                 e.printStackTrace();
680                 LOG.error(e.getMessage());
681             }
682         }
683         if(olePurchaseOrderDocument!=null){
684             oleClaimingByTitle.setPoOrderedNum(olePurchaseOrderDocument.getPurapDocumentIdentifier()!=null ?
685                     olePurchaseOrderDocument.getPurapDocumentIdentifier().toString() : "");
686             oleClaimingByTitle.setPoOrderedDate(olePurchaseOrderDocument.getPurchaseOrderInitialOpenTimestamp()!=null ?
687                     olePurchaseOrderDocument.getPurchaseOrderInitialOpenTimestamp().toString() : "");
688             OLEClaimingAddress toAddress = updateClaimingToAddress(olePurchaseOrderDocument);
689             OLEClaimingAddress fromAddress = updateClaimingFromAddress(olePurchaseOrderDocument);
690             oleClaimingByTitle.setToAddress(toAddress);
691             oleClaimingByTitle.setFromAddress(fromAddress);
692             if (olePurchaseOrderDocument.getVendorDetail() != null) {
693                 List<VendorTransmissionFormatDetail> vendorTxFormat = olePurchaseOrderDocument.getVendorDetail().getVendorTransmissionFormat();
694                 if (vendorTxFormat.size() > 0) {
695                     for (int i = 0; i < vendorTxFormat.size(); i++) {
696                         VendorTransmissionFormatDetail vendorTransmissionFormatDetail = vendorTxFormat.get(i);
697                         boolean isPrefferedTransmissionFormat = vendorTransmissionFormatDetail.isVendorPreferredTransmissionFormat();
698                         if (isPrefferedTransmissionFormat ) {
699                             oleClaimingByTitle.setVendorTransmissionFormatDetail(vendorTransmissionFormatDetail);
700                             break;
701                         }
702                     }
703                 }
704 
705             }
706         }
707     }
708 
709     public String mailContent(OLEClaimingByVendor oleClaimingByVendor){
710         StringBuffer stringBuffer = new StringBuffer();
711         stringBuffer.append("<HTML>");
712         stringBuffer.append("<VENDOR><h1>" + oleClaimingByVendor.getVendorName() + "</h1></VENDOR>");
713         stringBuffer.append("<HEAD></HEAD>");
714         stringBuffer.append("<BODY>");
715 
716         int i=1;
717         for(OLEClaimingByTitle claimingByTitle : oleClaimingByVendor.getOleClaimingByTitles()){
718             stringBuffer.append("<table>");
719             stringBuffer.append("<h3>Title"+i+++"</h3>");
720             stringBuffer.append("<TR><TD>Author :</TD><TD>" + (claimingByTitle.getAuthor() !=null ? claimingByTitle.getAuthor() : "") + "</TD></TR>");
721             stringBuffer.append("<TR><TD>Title :</TD><TD>" + (claimingByTitle.getTitle()!=null ? claimingByTitle.getTitle() : "") + "</TD></TR>");
722             stringBuffer.append("<TR><TD>Place Of Publication :</TD><TD>" + (claimingByTitle.getPlaceOfPublication() != null ? claimingByTitle.getPlaceOfPublication() : "") + "</TD></TR>");
723             stringBuffer.append("<TR><TD>Publisher :</TD><TD>" + (claimingByTitle.getPublisherName() != null ? claimingByTitle.getPublisherName() : "") + "</TD></TR>");
724             stringBuffer.append("<TR><TD>Publication Date :</TD><TD>" + ( claimingByTitle.getPublicationDate() != null ? claimingByTitle.getPublicationDate()  : "" )+ "</TD></TR>");
725             stringBuffer.append("<TR><TD>ISXN :</TD><TD>" + ( claimingByTitle.getIsxn() != null ? claimingByTitle.getIsxn() : "" )+ "</TD></TR>");
726             stringBuffer.append("<TR><TD>Vendor Item Identifier :</TD><TD>" + ( claimingByTitle.getVendorItemIdentifier() != null ? claimingByTitle.getVendorItemIdentifier() : "" )+ "</TD></TR>");
727             stringBuffer.append("<TR><TD>PO # :</TD><TD>" + ( claimingByTitle.getPoOrderedNum() != null ? claimingByTitle.getPoOrderedNum() : "" )+ "</TD></TR>");
728             stringBuffer.append("<TR><TD>PO Date :</TD><TD>" + ( claimingByTitle.getPublicationDate() != null ? claimingByTitle.getPublicationDate()  : "" )+ "</TD></TR>");
729             stringBuffer.append("<TR><TD>Claim # :</TD><TD>" + ( claimingByTitle.getClaimNumber() != null ? claimingByTitle.getClaimNumber() : "" )+ "</TD></TR>");
730             stringBuffer.append("<TR><TD>Claim Note :</TD><TD>" + ( claimingByTitle.getClaimNote() != null ? claimingByTitle.getClaimNote() : "" )+ "</TD></TR>");
731 
732             stringBuffer.append("<TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>");
733             stringBuffer.append("</table>");
734         }
735         return stringBuffer.toString();
736     }
737 
738 
739     public OLEClaimNoticeForm populateOLEClaimNoticeForm(OLEClaimNoticeForm oleClaimNoticeForm){
740         List<File> claimNoticeList = new ArrayList<File>();
741         String pdfLocationSystemParam = getParameter(OLEParameterConstants.PDF_LOCATION);
742         if (pdfLocationSystemParam == null || pdfLocationSystemParam.trim().isEmpty()) {
743             pdfLocationSystemParam = ConfigContext.getCurrentContextConfig().getProperty("staging.directory") + "/";
744         } else{
745             pdfLocationSystemParam = ConfigContext.getCurrentContextConfig().getProperty("homeDirectory")+ "/" + pdfLocationSystemParam +"/";
746         }
747         LOG.info("PDF LOCATION : " + pdfLocationSystemParam);
748         File directory = new File(pdfLocationSystemParam);
749         File[] fList = directory.listFiles();
750         if (fList != null && fList.length > 0) {
751             for (File file : fList) {
752                 if (file.isFile()) {
753 
754                    if (file.getName().contains(OLEConstants.CLAIM_NOTICE)) {
755                         claimNoticeList.add(file);
756                    }
757                 }
758             }
759         }
760         oleClaimNoticeForm.setOleClaimNoticeList(generateClaimNoticeList(claimNoticeList));
761         return oleClaimNoticeForm;
762     }
763 
764     public List<OLEClaimNotice> generateClaimNoticeList(List<File> claimNoticeList) {
765         List<OLEClaimNotice>  oleClaimNotices = new ArrayList<OLEClaimNotice>();
766         OLEClaimNotice oleClaimNotice ;
767         for(File file :claimNoticeList){
768             oleClaimNotice= new OLEClaimNotice();
769             oleClaimNotice.setFileName(file.getName());
770             oleClaimNotice.setFileLocation(file.getAbsolutePath());
771             oleClaimNotices.add(oleClaimNotice);
772         }
773         LOG.info("No of OLEClaimNotice : " +oleClaimNotices.size());
774         return oleClaimNotices;
775     }
776 
777    public String getParameter(String name){
778        ParameterKey parameterKey = ParameterKey.create(OLEConstants.APPL_ID, OLEConstants.SELECT_NMSPC, OLEConstants.SELECT_CMPNT,name);
779        Parameter parameter = CoreServiceApiServiceLocator.getParameterRepositoryService().getParameter(parameterKey);
780        return parameter!=null?parameter.getValue():null;
781    }
782 
783     public OLEClaimingAddress updateClaimingToAddress(OlePurchaseOrderDocument olePurchaseOrderDocument){
784         OLEClaimingAddress oleClaimingAddress = new OLEClaimingAddress();
785         oleClaimingAddress.setVendorName(olePurchaseOrderDocument.getVendorName());
786         oleClaimingAddress.setAttention(olePurchaseOrderDocument.getVendorAttentionName());
787         oleClaimingAddress.setAddress1(olePurchaseOrderDocument.getVendorLine1Address());
788         oleClaimingAddress.setAddress2(olePurchaseOrderDocument.getVendorLine2Address());
789         oleClaimingAddress.setCity(olePurchaseOrderDocument.getVendorCityName());
790         oleClaimingAddress.setPostalCode(olePurchaseOrderDocument.getVendorPostalCode());
791         String vendorHeaderGeneratedIdentifier = olePurchaseOrderDocument.getVendorHeaderGeneratedIdentifier().toString();
792         String vendorDetailAssignedIdentifier = olePurchaseOrderDocument.getVendorDetailAssignedIdentifier().toString();
793         Map vendorNameMap = new HashMap();
794         vendorNameMap.put(org.kuali.ole.sys.OLEConstants.VENDOR_HEADER_IDENTIFIER,vendorHeaderGeneratedIdentifier);
795         vendorNameMap.put(org.kuali.ole.sys.OLEConstants.VENDOR_DETAIL_IDENTIFIER,vendorDetailAssignedIdentifier);
796         VendorDetail vendorDetail = getBusinessObjectService().findByPrimaryKey(VendorDetail.class, vendorNameMap);
797         if(vendorDetail != null) {
798             if(vendorDetail.getVendorHeader().getVendorForeignIndicator()){
799                 if (olePurchaseOrderDocument.getVendorCountry()!=null) {
800                     if (StringUtils.isNotBlank(olePurchaseOrderDocument.getVendorCountry().getName())) {
801                         oleClaimingAddress.setCountry(olePurchaseOrderDocument.getVendorCountry().getName());
802                     }
803                 }
804                 for (int vendorAddress=0; vendorAddress<vendorDetail.getVendorAddresses().size(); vendorAddress++) {
805                     if (vendorDetail.getVendorAddresses().get(vendorAddress).getVendorAddressType().getVendorDefaultIndicator()
806                             && StringUtils.isNotBlank(vendorDetail.getVendorAddresses().get(vendorAddress).getVendorAddressInternationalProvinceName())) {
807                         oleClaimingAddress.setProvince(vendorDetail.getVendorAddresses().get(vendorAddress).getVendorAddressInternationalProvinceName());
808                     }
809                 }
810             } else {
811                 if (StringUtils.isNotBlank(olePurchaseOrderDocument.getVendorStateCode())) {
812                     oleClaimingAddress.setState(olePurchaseOrderDocument.getVendorStateCode());
813                 }
814             }
815         }
816         return oleClaimingAddress;
817     }
818 
819     public OLEClaimingAddress updateClaimingFromAddress(OlePurchaseOrderDocument olePurchaseOrderDocument){
820         OLEClaimingAddress oleClaimingAddress = new OLEClaimingAddress();
821         oleClaimingAddress.setAddress1(olePurchaseOrderDocument.getDeliveryBuildingLine1Address());
822         oleClaimingAddress.setAddress2(olePurchaseOrderDocument.getDeliveryBuildingLine2Address());
823         oleClaimingAddress.setCity(olePurchaseOrderDocument.getDeliveryCityName());
824         oleClaimingAddress.setState(olePurchaseOrderDocument.getDeliveryStateCode());
825         oleClaimingAddress.setPostalCode(olePurchaseOrderDocument.getDeliveryPostalCode());
826         oleClaimingAddress.setInstitutionName(olePurchaseOrderDocument.getDeliveryCampus() != null ? olePurchaseOrderDocument.getDeliveryCampus().getPurchasingInstitutionName() : null);
827         return oleClaimingAddress;
828     }
829 }