1 package org.kuali.ole.deliver.notice.executors;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.apache.log4j.Logger;
5 import org.kuali.asr.service.ASRHelperServiceImpl;
6 import org.kuali.ole.OLEConstants;
7 import org.kuali.ole.OLEParameterConstants;
8 import org.kuali.ole.deliver.batch.OleMailer;
9 import org.kuali.ole.deliver.bo.*;
10 import org.kuali.ole.deliver.notice.noticeFormatters.RequestEmailContentFormatter;
11 import org.kuali.ole.deliver.notice.util.NoticeUtil;
12 import org.kuali.ole.deliver.processor.LoanProcessor;
13 import org.kuali.ole.deliver.service.CircDeskLocationResolver;
14 import org.kuali.ole.deliver.service.NoticesExecutor;
15 import org.kuali.ole.deliver.service.ParameterValueResolver;
16 import org.kuali.ole.describe.keyvalue.LocationValuesBuilder;
17 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
18 import org.kuali.ole.docstore.common.document.ItemOleml;
19 import org.kuali.ole.docstore.common.document.content.instance.Item;
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.ole.util.DocstoreUtil;
25 import org.kuali.rice.core.api.config.property.ConfigContext;
26 import org.kuali.rice.core.api.mail.EmailBody;
27 import org.kuali.rice.core.api.mail.EmailFrom;
28 import org.kuali.rice.core.api.mail.EmailSubject;
29 import org.kuali.rice.core.api.mail.EmailTo;
30 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
31 import org.kuali.rice.kim.impl.identity.type.EntityTypeContactInfoBo;
32 import org.kuali.rice.krad.service.BusinessObjectService;
33 import org.kuali.rice.krad.service.KRADServiceLocator;
34 import org.kuali.rice.krad.util.GlobalVariables;
35 import org.kuali.rice.krad.util.KRADConstants;
36
37 import java.sql.Timestamp;
38 import java.util.*;
39
40
41
42
43 public abstract class RequestNoticesExecutor extends NoticesExecutor {
44 private static final Logger LOG = Logger.getLogger(RequestNoticesExecutor.class);
45 protected List<OLEDeliverNotice> deliverNotices;
46 protected List<OLEDeliverNotice> filteredDeliverNotices = new ArrayList<OLEDeliverNotice>();
47 protected RequestEmailContentFormatter requestEmailContentFormatter;
48 protected List<OleDeliverRequestBo> deliverRequestBos = new ArrayList<OleDeliverRequestBo>();
49
50 public void setRequestEmailContentFormatter(RequestEmailContentFormatter requestEmailContentFormatter) {
51 this.requestEmailContentFormatter = requestEmailContentFormatter;
52 }
53
54 public RequestNoticesExecutor(List<OLEDeliverNotice> deliverNotices) {
55 this.deliverNotices = deliverNotices;
56 }
57
58 public abstract RequestEmailContentFormatter getRequestEmailContentFormatter();
59
60
61 public List<OLEDeliverNotice> getDeliverNotices() {
62 return deliverNotices;
63 }
64
65 public void setDeliverNotices(List<OLEDeliverNotice> deliverNotices) {
66 this.deliverNotices = deliverNotices;
67 }
68
69 public List<OleDeliverRequestBo> getDeliverRequestBos() {
70 return deliverRequestBos;
71 }
72
73 public void setDeliverRequestBos(List<OleDeliverRequestBo> deliverRequestBos) {
74 this.deliverRequestBos = deliverRequestBos;
75 }
76
77 public List<OLEDeliverNotice> getFilteredDeliverNotices() {
78 return filteredDeliverNotices;
79 }
80
81 public void setFilteredDeliverNotices(List<OLEDeliverNotice> filteredDeliverNotices) {
82 this.filteredDeliverNotices = filteredDeliverNotices;
83 }
84
85
86 public abstract String getTitle();
87
88 public abstract String getBody();
89
90 public abstract boolean isValidRequestToSendNotice(OleDeliverRequestBo oleDeliverRequestBo);
91
92 protected abstract void postProcess();
93
94
95
96 private void preProcess() {
97 if(deliverNotices !=null && deliverNotices.size()>0){
98 for(OLEDeliverNotice oleDeliverNotice : deliverNotices){
99 setItemInformations(oleDeliverNotice.getOleDeliverRequestBo());
100 if(isValidRequestToSendNotice(oleDeliverNotice.getOleDeliverRequestBo())){
101 deliverRequestBos.add(oleDeliverNotice.getOleDeliverRequestBo());
102 filteredDeliverNotices.add(oleDeliverNotice);
103 }
104 }
105 }
106
107 }
108
109
110 public String generateMailContent() {
111 String mailContent = getRequestEmailContentFormatter().generateRequestMailContentForPatron(deliverRequestBos,getTitle(), getBody());
112 System.out.println(mailContent);
113 return mailContent;
114 }
115
116
117 public void sendMail(String mailContent) {
118 OlePatronDocument olePatron = deliverRequestBos.get(0).getOlePatron();
119 try {
120 EntityTypeContactInfoBo entityTypeContactInfoBo = olePatron.getEntity()
121 .getEntityTypeContactInfos().get(0);
122 String emailAddress = getPatronHomeEmailId(entityTypeContactInfoBo) != null ?
123 getPatronHomeEmailId(entityTypeContactInfoBo) : "";
124
125 if (deliverRequestBos.size() == 1) {
126 sendMailsToPatron(emailAddress, mailContent, deliverRequestBos.get(0).getItemLocation());
127 } else {
128 sendMailsToPatron(emailAddress, mailContent, null);
129 }
130
131 } catch (Exception e) {
132 e.printStackTrace();
133 }
134 }
135
136
137
138
139 @Override
140 public void run() {
141
142 preProcess();
143
144 String mailContent = generateMailContent();
145
146 System.out.println(mailContent);
147
148 sendMail(mailContent);
149
150 deleteNotices(filteredDeliverNotices);
151
152 saveOLEDeliverNoticeHistory(filteredDeliverNotices,mailContent);
153
154 postProcess();
155
156
157 }
158
159
160
161
162
163 }