View Javadoc
1   package org.kuali.ole.deliver.controller.checkout;
2   
3   import org.apache.commons.collections.CollectionUtils;
4   import org.apache.commons.lang.StringUtils;
5   import org.apache.log4j.Logger;
6   import org.kie.api.runtime.KieSession;
7   import org.kie.api.runtime.rule.Agenda;
8   import org.kie.api.runtime.rule.AgendaGroup;
9   import org.kuali.ole.OLEConstants;
10  import org.kuali.ole.deliver.OleLoanDocumentsFromSolrBuilder;
11  import org.kuali.ole.deliver.bo.OLEDeliverNotice;
12  import org.kuali.ole.deliver.bo.OleItemSearch;
13  import org.kuali.ole.deliver.bo.OleLoanDocument;
14  import org.kuali.ole.deliver.bo.OleNoticeTypeConfiguration;
15  import org.kuali.ole.deliver.controller.notices.*;
16  import org.kuali.ole.deliver.drools.CustomAgendaFilter;
17  import org.kuali.ole.deliver.drools.DroolsKieEngine;
18  import org.kuali.ole.deliver.service.CircDeskLocationResolver;
19  import org.kuali.ole.deliver.util.NoticeInfo;
20  import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
21  import org.kuali.ole.docstore.common.document.Item;
22  import org.kuali.ole.docstore.common.document.ItemOleml;
23  import org.kuali.ole.docstore.common.document.content.enums.DocType;
24  import org.kuali.ole.docstore.common.document.content.instance.*;
25  import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor;
26  import org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.ItemRecord;
27  import org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.LocationsCheckinCountRecord;
28  import org.kuali.ole.sys.context.SpringContext;
29  import org.kuali.ole.util.DocstoreUtil;
30  import org.kuali.rice.krad.service.BusinessObjectService;
31  import org.kuali.rice.krad.service.KRADServiceLocator;
32  import org.kuali.rice.krad.util.GlobalVariables;
33  
34  import java.sql.Timestamp;
35  import java.text.ParseException;
36  import java.text.SimpleDateFormat;
37  import java.util.*;
38  import java.util.regex.Matcher;
39  import java.util.regex.Pattern;
40  
41  /**
42   * Created by pvsubrah on 6/4/15.
43   */
44  public class CircUtilController {
45      private static final Logger LOG = Logger.getLogger(CircUtilController.class);
46      private BusinessObjectService businessObjectService;
47      private ItemOlemlRecordProcessor itemOlemlRecordProcessor;
48      private DocstoreClientLocator docstoreClientLocator;
49      private SimpleDateFormat dateFormatForDocstoreDueDate;
50      private OleLoanDocumentsFromSolrBuilder oleLoanDocumentsFromSolrBuilder;
51  
52      public void fireRules(List<Object> facts, String[] expectedRules, String agendaGroup) {
53          KieSession session = DroolsKieEngine.getInstance().getSession();
54          for (Iterator<Object> iterator = facts.iterator(); iterator.hasNext(); ) {
55              Object fact = iterator.next();
56              session.insert(fact);
57          }
58  
59          if (null != expectedRules && expectedRules.length > 0) {
60              session.fireAllRules(new CustomAgendaFilter(expectedRules));
61          } else {
62              Agenda agenda = session.getAgenda();
63              AgendaGroup group = agenda.getAgendaGroup(agendaGroup);
64              group.setFocus();
65              session.fireAllRules();
66          }
67          session.dispose();
68      }
69  
70      public List<OLEDeliverNotice> processNotices(OleLoanDocument currentLoanDocument, ItemRecord itemRecord) {
71          List<OLEDeliverNotice> deliverNotices = new ArrayList<>();
72  
73          List<NoticeDueDateProcessor> noticeProcessors = getNoticeProcessors();
74  
75          HashMap<String, Object> map = new HashMap<>();
76          map.put("circPolicyId", currentLoanDocument.getCirculationPolicyId());
77          List<OleNoticeTypeConfiguration> oleNoticeTypeConfigurations =
78                  (List<OleNoticeTypeConfiguration>) getBusinessObjectService().findMatching(OleNoticeTypeConfiguration.class, map);
79  
80          OleNoticeTypeConfiguration oleNoticeTypeConfiguration = null;
81          if (CollectionUtils.isNotEmpty(oleNoticeTypeConfigurations)) {
82              oleNoticeTypeConfiguration = oleNoticeTypeConfigurations.get(0);
83              NoticeInfo noticeInfo = new NoticeInfo();
84              noticeInfo.setNoticeType(oleNoticeTypeConfiguration.getNoticeType());
85  
86              ArrayList<Object> facts = new ArrayList<>();
87              facts.add(noticeInfo);
88              facts.add(itemRecord);
89              fireRules(facts, null, "notice generation");
90  
91  
92              Map<String, Map<String, Object>> noticeInfoForTypeMap = noticeInfo.getNoticeInfoForTypeMap();
93  
94              if (null != noticeInfoForTypeMap) {
95                  for (Iterator<String> iterator = noticeInfoForTypeMap.keySet().iterator(); iterator.hasNext(); ) {
96                      String noticeType = iterator.next();
97                      for (Iterator<NoticeDueDateProcessor> objectIterator = noticeProcessors.iterator(); objectIterator.hasNext(); ) {
98                          NoticeDueDateProcessor noticeProcessor = objectIterator.next();
99                          if(noticeProcessor.isInterested(noticeType)){
100                             List<OLEDeliverNotice> oleDeliverNotices = noticeProcessor.generateNotices(noticeInfo, currentLoanDocument);
101                             if(CollectionUtils.isNotEmpty(oleDeliverNotices)){
102                                 deliverNotices.addAll(oleDeliverNotices);
103                             }
104                         }
105                     }
106                 }
107             }
108 
109         } else {
110             LOG.error("No notice coniguration mapping was found for the circulation policy id: " + currentLoanDocument.getCirculationLocationId());
111         }
112 
113         return deliverNotices;
114     }
115 
116     public ItemRecord getItemRecordByBarcode(String itemBarcode) {
117         ItemRecord itemRecord = null;
118         HashMap<String, String> criteriaMap = new HashMap<>();
119         criteriaMap.put("barCode", itemBarcode);
120         List<ItemRecord> itemRecords = (List<ItemRecord>) getBusinessObjectService().findMatching(ItemRecord.class,
121                 criteriaMap);
122         if (null != itemRecords && !itemRecords.isEmpty()) {
123             itemRecord = itemRecords.get(0);
124         }
125 
126         return itemRecord;
127     }
128 
129     public String convertDateToString(Date date, String format) {
130         LOG.info("Date Format : " + format + "Date : " + date);
131         SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
132         String dateValue = "";
133         try {
134             dateValue = simpleDateFormat.format(date);
135         } catch (Exception e) {
136             LOG.error(e, e);
137         }
138         LOG.info("Formatted Date : " + dateValue);
139         return dateValue;
140     }
141 
142     public String convertToString(Timestamp date) {
143         SimpleDateFormat format1 = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
144         SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
145         Date itemDate = null;
146         try {
147             itemDate = format2.parse(date.toString());
148         } catch (ParseException e) {
149             LOG.error("format string to Date " + e);
150         }
151         return format1.format(itemDate).toString();
152     }
153 
154     public String getLoginUserId() {
155         return GlobalVariables.getUserSession().getPrincipalId();
156     }
157 
158 
159     public BusinessObjectService getBusinessObjectService() {
160         if (null == businessObjectService) {
161             businessObjectService = KRADServiceLocator.getBusinessObjectService();
162         }
163         return businessObjectService;
164     }
165 
166     public CircDeskLocationResolver getCircDeskLocationResolver() {
167         return new CircDeskLocationResolver();
168     }
169 
170     public ItemOlemlRecordProcessor getItemOlemlRecordProcessor() {
171         if (itemOlemlRecordProcessor == null) {
172             itemOlemlRecordProcessor = SpringContext.getBean(ItemOlemlRecordProcessor.class);
173         }
174         return itemOlemlRecordProcessor;
175     }
176 
177     public DocstoreClientLocator getDocstoreClientLocator() {
178         if (docstoreClientLocator == null) {
179             docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
180         }
181         return docstoreClientLocator;
182     }
183 
184     public void setDateFormatForDocstoreDueDate(SimpleDateFormat dateFormatForDocstoreDueDate) {
185         this.dateFormatForDocstoreDueDate = dateFormatForDocstoreDueDate;
186     }
187 
188     public SimpleDateFormat getDateFormatForDocstoreDueDate() {
189         if (dateFormatForDocstoreDueDate == null) {
190             dateFormatForDocstoreDueDate = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
191         }
192         return dateFormatForDocstoreDueDate;
193     }
194 
195 
196     public void rollBackSavedLoanRecord(String barcode) {
197         Map<String, String> criteria = new HashMap<String, String>();
198         criteria.put("itemId", barcode);
199         List<OleLoanDocument> oleLoanDocument = (List<OleLoanDocument>) KRADServiceLocator.getBusinessObjectService().findMatching(OleLoanDocument.class, criteria);
200         if (oleLoanDocument.size() > 0) {
201             KRADServiceLocator.getBusinessObjectService().delete(oleLoanDocument.get(0));
202         }
203     }
204 
205     public OleLoanDocument updateLoanDocumentWithItemInformation(ItemRecord itemRecord, OleLoanDocument oleLoanDocument) {
206 
207         OleItemSearch oleItemSearch = new DocstoreUtil().getOleItemSearchListFromLocalClient(itemRecord.getItemId());
208         oleLoanDocument.setTitle(oleItemSearch.getTitle());
209         oleLoanDocument.setAuthor(oleItemSearch.getAuthor());
210         String location = oleItemSearch.getShelvingLocation().split("/")[oleItemSearch.getShelvingLocation().split("/").length - 1];
211         try {
212             getOleLoanDocumentsFromSolrBuilder().getLocationBySolr(location, oleLoanDocument);
213         } catch (Exception e) {
214             e.printStackTrace();
215         }
216         oleLoanDocument.setItemCallNumber(oleItemSearch.getCallNumber());
217         oleLoanDocument.setItemCopyNumber(oleItemSearch.getCopyNumber());
218         oleLoanDocument.setChronology(oleItemSearch.getChronology());
219         oleLoanDocument.setEnumeration(oleItemSearch.getEnumeration());
220         oleLoanDocument.setItemType(oleItemSearch.getItemType());
221         oleLoanDocument.setItemStatus(OLEConstants.ITEM_STATUS_CHECKEDOUT);
222         oleLoanDocument.setItemUuid(itemRecord.getUniqueIdPrefix() + "-" + oleItemSearch.getItemUUID());
223         oleLoanDocument.setInstanceUuid(oleItemSearch.getInstanceUUID());
224         oleLoanDocument.setBibUuid(oleItemSearch.getBibUUID());
225         return oleLoanDocument;
226     }
227 
228 
229     /**
230      * @param map
231      * @param itemUUID
232      * @param updateNulls - This indicates if null values should be updated for the corosponding parameters in SOLR.
233      * @return If SOLR update was successfull.
234      */
235     public Boolean updateItemInfoInSolr(Map map, String itemUUID, boolean updateNulls) {
236         org.kuali.ole.docstore.common.document.content.instance.Item oleItem = getExistingItemFromSolr(itemUUID);
237         if (oleItem != null) {
238             setItemInfoForUpdate(map, oleItem, updateNulls);
239             try {
240                 updateItem(oleItem);
241             } catch (Exception e) {
242                 return false;
243             }
244         }
245         return true;
246     }
247 
248     public Boolean deleteItemInfoInSolr(Map map, String itemUUID) {
249         org.kuali.ole.docstore.common.document.content.instance.Item oleItem = getExistingItemFromSolr(itemUUID);
250         if (oleItem != null) {
251             setItemInfoForDelete(map, oleItem);
252             try {
253                 updateItem(oleItem);
254             } catch (Exception e) {
255                 return false;
256             }
257         }
258         return true;
259     }
260 
261     private void setItemInfoForDelete(Map map, org.kuali.ole.docstore.common.document.content.instance.Item oleItem) {
262         if (map.keySet().contains("checkinNote"))
263             oleItem.setCheckinNote("");
264         if (map.containsKey("deleteClaimsReturn")) {
265             oleItem.setClaimsReturnedFlag(false);
266             oleItem.setClaimsReturnedNote(null);
267             oleItem.setClaimsReturnedFlagCreateDate(null);
268         }
269         if (map.containsKey("deleteDamagedItem")) {
270             oleItem.setItemDamagedStatus(false);
271             oleItem.setDamagedItemNote(null);
272         }
273         if (map.containsKey("deleteMissingPieceItem")) {
274             oleItem.setMissingPieceFlag(false);
275             oleItem.setMissingPieceFlagNote(null);
276             oleItem.setMissingPieceEffectiveDate(null);
277             oleItem.setMissingPiecesCount(null);
278         }
279     }
280 
281     private void setItemInfoForUpdate(Map map, org.kuali.ole.docstore.common.document.content.instance.Item oleItem, boolean updateNulls) {
282         String patronId = null == map.get("patronId") ? null : (String) map.get("patronId");
283         String proxyPatronId = null == map.get("proxyPatronId") ? null : (String) map.get("proxyPatronId");
284         Date itemCheckoutDateTime = null == map.get("itemCheckoutDateTime") ? null : (Date) map.get("itemCheckoutDateTime");
285         Timestamp loanDueDate = null == map.get("loanDueDate") ? null : (Timestamp) map.get("loanDueDate");
286         String numRenewals = null == map.get("numRenewals") ? null : (String) map.get("numRenewals");
287         String itemStatus = null == map.get("itemStatus") ? null : (String) map.get("itemStatus");
288         LocationsCheckinCountRecord locationsCheckinCountRecordToBeUpdated = null == map.get("locationsCheckinCountRecordToBeUpdated") ? null : (LocationsCheckinCountRecord) map.get("locationsCheckinCountRecordToBeUpdated");
289 
290         Boolean itemClaimsReturnedFlag = null == map.get("itemClaimsReturnedFlag") ? null : (Boolean) map.get("itemClaimsReturnedFlag");
291         String claimsReturnNote = null == map.get("claimsReturnNote") ? null : (String) map.get("claimsReturnNote");
292         String ClaimsReturnedDate = null == map.get("ClaimsReturnedDate") ? null : (String) map.get("ClaimsReturnedDate");
293 
294         List<ItemClaimsReturnedRecord> itemClaimsReturnedRecords = null == map.get("itemClaimsReturnedRecords") ? null : (List<ItemClaimsReturnedRecord>) map.get("itemClaimsReturnedRecords");
295 
296         String damagedItemNote = null == map.get("damagedItemNote") ? null : (String) map.get("damagedItemNote");
297         List<ItemDamagedRecord> itemDamagedRecords = null == map.get("itemDamagedRecords") ? null : (List<ItemDamagedRecord>) map.get("itemDamagedRecords");
298 
299         Boolean missingPieceItemFlag = null == map.get("missingPieceItemFlag") ? null : (Boolean) map.get("missingPieceItemFlag");
300         String missingPieceItemNote = null == map.get("missingPieceItemNote") ? null : (String) map.get("missingPieceItemNote");
301         String missingPieceItemCount = null == map.get("missingPieceItemCount") ? null : (String) map.get("missingPieceItemCount");
302         String noOfmissingPiece = null == map.get("noOfmissingPiece") ? null : (String) map.get("noOfmissingPiece");
303         String missingPieceItemDate = null == map.get("missingPieceItemDate") ? null : (String) map.get("missingPieceItemDate");
304         List<MissingPieceItemRecord> itemMissingPieceItemRecords = null == map.get("itemMissingPieceItemRecords") ? null : (List<MissingPieceItemRecord>) map.get("itemMissingPieceItemRecords");
305 
306         if (updateNulls) {
307             oleItem.setCurrentBorrower(patronId);
308             oleItem.setProxyBorrower(proxyPatronId);
309         }
310         if (null != itemCheckoutDateTime) {
311             oleItem.setCheckOutDateTime(convertDateToString(itemCheckoutDateTime, "MM/dd/yyyy HH:mm:ss"));
312         } else if (updateNulls) {
313             oleItem.setCheckOutDateTime(null);
314         }
315 
316         if (loanDueDate != null) {
317             oleItem.setDueDateTime(convertToString(loanDueDate));
318         } else if (updateNulls) {
319             oleItem.setDueDateTime("");
320         }
321 
322         if (updateNulls) {
323             oleItem.setNumberOfRenew(null == numRenewals ? 0 : Integer.parseInt(numRenewals));
324         }
325 
326         if (null != locationsCheckinCountRecordToBeUpdated) {
327             setNumberOfCirculationsCount(oleItem, locationsCheckinCountRecordToBeUpdated);
328         }
329 
330         if (null != itemStatus) {
331             ItemStatus itemSt = new ItemStatus();
332             itemSt.setCodeValue(itemStatus);
333             itemSt.setFullValue(itemStatus);
334             oleItem.setItemStatus(itemSt);
335         }
336 
337         if (CollectionUtils.isNotEmpty(itemClaimsReturnedRecords)) {
338             oleItem.setClaimsReturnedNote(claimsReturnNote);
339             oleItem.setClaimsReturnedFlagCreateDate(ClaimsReturnedDate);
340             oleItem.setClaimsReturnedFlag(itemClaimsReturnedFlag);
341             oleItem.setItemClaimsReturnedRecords(itemClaimsReturnedRecords);
342         }
343 
344         if (CollectionUtils.isNotEmpty(itemDamagedRecords)) {
345             oleItem.setDamagedItemNote(damagedItemNote);
346             oleItem.setItemDamagedStatus(true);
347             oleItem.setItemDamagedRecords(itemDamagedRecords);
348         }
349 
350         if (CollectionUtils.isNotEmpty(itemMissingPieceItemRecords)) {
351             oleItem.setMissingPieceFlagNote(missingPieceItemNote);
352             oleItem.setMissingPieceFlag(missingPieceItemFlag);
353             oleItem.setMissingPiecesCount(missingPieceItemCount);
354             oleItem.setNumberOfPieces(noOfmissingPiece);
355             oleItem.setMissingPieceEffectiveDate(missingPieceItemDate);
356             oleItem.setMissingPieceItemRecordList(itemMissingPieceItemRecords);
357         }
358     }
359 
360     private void setNumberOfCirculationsCount(org.kuali.ole.docstore.common.document.content.instance.Item oleItem, LocationsCheckinCountRecord locationsCheckinCountRecordToBeUpdated) {
361         //TODO: We should really use the LocationsCheckinCountRecord in DocStore rather than using some intermediary pojo like CheckinLocation and then a wrapper NumberOfCirculations;
362         //TODO: Docstore needs to be fixed at some point.
363         NumberOfCirculations numberOfCirculations = new NumberOfCirculations();
364         ArrayList<CheckInLocation> checkInLocations = new ArrayList<>();
365         CheckInLocation checkInLocation = new CheckInLocation();
366         checkInLocation.setCount(locationsCheckinCountRecordToBeUpdated.getLocationCount());
367         checkInLocation.setInHouseCount(locationsCheckinCountRecordToBeUpdated.getLocationInhouseCount());
368         checkInLocation.setName(locationsCheckinCountRecordToBeUpdated.getLocationName());
369         checkInLocations.add(checkInLocation);
370         numberOfCirculations.setCheckInLocation(checkInLocations);
371         oleItem.setNumberOfCirculations(numberOfCirculations);
372     }
373 
374 
375     protected org.kuali.ole.docstore.common.document.content.instance.Item getExistingItemFromSolr(String itemUUID) {
376         ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
377         try {
378             Item item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(itemUUID);
379             return itemOlemlRecordProcessor.fromXML(item.getContent());
380         } catch (Exception e) {
381             e.printStackTrace();
382         }
383         return null;
384     }
385 
386 
387     public void updateItem(org.kuali.ole.docstore.common.document.content.instance.Item oleItem) throws Exception {
388         try {
389             String itemUuid = oleItem.getItemIdentifier();
390             String itemXmlContent = buildItemContent(oleItem);
391             Item item = new ItemOleml();
392             item.setId(itemUuid);
393             item.setContent(itemXmlContent);
394             item.setCategory(OLEConstants.WORK_CATEGORY);
395             item.setType(DocType.ITEM.getCode());
396             item.setFormat(OLEConstants.OLEML_FORMAT);
397             item.setStaffOnly(oleItem.isStaffOnlyFlag());
398             getDocstoreClientLocator().getDocstoreClient().updateItem(item);
399         } catch (Exception e) {
400             LOG.error(OLEConstants.ITM_STS_TO_DOC_FAIL + e, e);
401             throw new Exception(OLEConstants.ITM_STS_TO_DOC_FAIL);
402         }
403     }
404 
405 
406     public String buildItemContent(org.kuali.ole.docstore.common.document.content.instance.Item oleItem) throws Exception {
407         oleItem.setItemStatusEffectiveDate(String.valueOf(new SimpleDateFormat(OLEConstants.DAT_FORMAT_EFFECTIVE).format(new Date())));
408         String itemContent = getItemOlemlRecordProcessor().toXML(oleItem);
409         return itemContent;
410     }
411 
412 
413     public OleLoanDocument getLoanDocumentFromListBasedOnItemUuid(String itemUuid, List<OleLoanDocument> selectedLoanDocumentList) {
414         for (Iterator<OleLoanDocument> iterator = selectedLoanDocumentList.iterator(); iterator.hasNext(); ) {
415             OleLoanDocument oleLoanDocument = iterator.next();
416             if (oleLoanDocument.getItemUuid().equalsIgnoreCase(itemUuid)) {
417                 return oleLoanDocument;
418             }
419         }
420         return null;
421     }
422 
423     public OleLoanDocument getLoanDocumentFromListBasedOnItemBarcode(String itemBarcode, List<OleLoanDocument> selectedLoanDocumentList) {
424         for (Iterator<OleLoanDocument> iterator = selectedLoanDocumentList.iterator(); iterator.hasNext(); ) {
425             OleLoanDocument oleLoanDocument = iterator.next();
426             if (oleLoanDocument.getItemId().equalsIgnoreCase(itemBarcode)) {
427                 return oleLoanDocument;
428             }
429         }
430         return null;
431     }
432 
433 
434     public Item getItemForUpdate(Map<String, Object> parameterMap) {
435         if (parameterMap.size() > 0) {
436             Item item = null;
437             try {
438                 item = getDocstoreClientLocator().getDocstoreClient().retrieveItem((String) parameterMap.get("itemUUID"));
439                 for (Iterator<String> iterator = parameterMap.keySet().iterator(); iterator.hasNext(); ) {
440                     String key = iterator.next();
441                     if (key.equalsIgnoreCase("loanDueDate")) {
442                         Timestamp dueDate = (Timestamp) parameterMap.get(key);
443                         if (null != dueDate) {
444                             item.setField(Item.DUE_DATE_TIME, getDateFormatForDocstoreDueDate().format(dueDate));
445                         } else {
446                             item.setField(Item.DUE_DATE_TIME, null);
447                         }
448                     } else if (key.equalsIgnoreCase("numRenewals")) {
449                         item.setField(Item.NO_OF_RENEWAL, (String) parameterMap.get(key));
450                     }
451                 }
452                 return item;
453             } catch (Exception e) {
454                 e.printStackTrace();
455             }
456 
457         }
458         return null;
459     }
460 
461 
462     public Timestamp processDateAndTimeForAlterDueDate(Date loanDueDateToAlter, String loanDueDateTimeToAlter) throws Exception {
463         boolean timeFlag;
464         Timestamp timestamp;
465         SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OlePatron.PATRON_MAINTENANCE_DATE_FORMAT);
466 
467         if (org.apache.commons.lang3.StringUtils.isNotBlank(loanDueDateTimeToAlter)) {
468             String[] str = loanDueDateTimeToAlter.split(":");
469             timeFlag = validateTime(loanDueDateTimeToAlter);
470             if (timeFlag) {
471                 if (str != null && str.length <= 2) {
472                     loanDueDateTimeToAlter = loanDueDateTimeToAlter + OLEConstants.CHECK_IN_TIME_MS;
473                 }
474                 timestamp = Timestamp.valueOf(new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT).format(loanDueDateToAlter).concat(" ").concat(loanDueDateTimeToAlter));
475             } else {
476                 throw new Exception("Invalid time format");
477             }
478         } else if (fmt.format(loanDueDateToAlter).compareTo(fmt.format(new Date())) == 0) {
479             timestamp = new Timestamp(new Date().getTime());
480         } else {
481             timestamp = Timestamp.valueOf(new SimpleDateFormat(OLEConstants.CHECK_IN_DATE_TIME_FORMAT).format(loanDueDateToAlter).concat(" ").concat(new SimpleDateFormat("HH:mm:ss").format(new Date())));
482         }
483         return timestamp;
484     }
485 
486 
487     public boolean validateTime(String timeString) {
488         if (StringUtils.isNotBlank(timeString)) {
489             Pattern pattern;
490             Matcher matcher;
491             pattern = Pattern.compile(OLEConstants.TIME_24_HR_PATTERN);
492             matcher = pattern.matcher(timeString);
493             boolean validTime = matcher.matches();
494             return validTime;
495         } else {
496             return true;
497         }
498     }
499 
500 
501     private OleLoanDocumentsFromSolrBuilder getOleLoanDocumentsFromSolrBuilder() {
502         if (null == oleLoanDocumentsFromSolrBuilder) {
503             oleLoanDocumentsFromSolrBuilder = new OleLoanDocumentsFromSolrBuilder();
504         }
505         return oleLoanDocumentsFromSolrBuilder;
506     }
507 
508 
509     public void addToFormattedContent(StringBuilder stringBuilder, String content) {
510         if (stringBuilder.length() > 0) {
511             stringBuilder.append("<br/>").append(content);
512         } else {
513             stringBuilder.append(content);
514         }
515     }
516 
517     public void updateNoticesForLoanDocument(OleLoanDocument oleLoanDocument) {
518         ItemRecord itemRecord = getItemRecordByBarcode(oleLoanDocument.getItemId());
519         List<OLEDeliverNotice> oleDeliverNotices = processNotices(oleLoanDocument, itemRecord);
520         oleLoanDocument.setDeliverNotices(oleDeliverNotices);
521     }
522 
523     private List<NoticeDueDateProcessor> getNoticeProcessors() {
524         List<NoticeDueDateProcessor> noticeProcessors = new ArrayList<>();
525         noticeProcessors.add(new OverDueAndLostNoticeDueDateProcessor());
526         noticeProcessors.add(new RecallOverDueAndLostNoticeDueDateProcessor());
527         noticeProcessors.add(new CourtseyNoticeDueDateProcessor());
528         noticeProcessors.add(new RecallCourtseyNoticeDueDateProcessor());
529         return noticeProcessors;
530     }
531 }