Rev 1429 | Rev 1433 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
29 | jmachado | 1 | package pt.estgp.estgweb.services.email; |
2 | |||
236 | jmachado | 3 | import jomm.utils.TemplateUtils; |
4 | import org.apache.log4j.Logger; |
||
5 | import pt.estgp.estgweb.Globals; |
||
929 | jmachado | 6 | import pt.estgp.estgweb.domain.*; |
7 | import pt.estgp.estgweb.domain.enums.LangEnum; |
||
8 | import pt.estgp.estgweb.services.expceptions.ServiceException; |
||
751 | jmachado | 9 | import pt.estgp.estgweb.utils.ConfigProperties; |
929 | jmachado | 10 | import pt.estgp.estgweb.utils.Email; |
1429 | jmachado | 11 | import pt.estgp.estgweb.utils.EmailPersonalizedCertificated; |
358 | jmachado | 12 | import pt.estgp.estgweb.web.utils.DatesUtils; |
236 | jmachado | 13 | import pt.utl.ist.berserk.logic.serviceManager.IService; |
14 | |||
929 | jmachado | 15 | import javax.mail.*; |
16 | import javax.mail.internet.InternetAddress; |
||
236 | jmachado | 17 | import javax.mail.internet.MimeMessage; |
872 | jmachado | 18 | import java.io.UnsupportedEncodingException; |
929 | jmachado | 19 | import java.text.MessageFormat; |
1426 | jmachado | 20 | import java.util.*; |
29 | jmachado | 21 | |
22 | /** |
||
23 | * @author Jorge Machado |
||
24 | * @date 20/Mar/2008 |
||
25 | * @time 18:31:00 |
||
26 | * @see pt.estgp.estgweb.services.email |
||
27 | */ |
||
236 | jmachado | 28 | public class SendEmailService implements IService |
29 | jmachado | 29 | { |
236 | jmachado | 30 | private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(SendEmailService.class); |
31 | |||
32 | private static final 1.5.0/docs/api/java/lang/String.html">String gradeUnitTemplate = Globals.TEMPLATE_EMAIL_PATH + "/" + Globals.EMAIL_GRADE_UNIT_TEMPLATE; |
||
33 | |||
1260 | jmachado | 34 | static 1.5.0/docs/api/java/lang/String.html">String[] serverEmails; |
35 | static int serverEmailPos = -1; |
||
36 | |||
37 | static{ |
||
38 | serverEmails = new 1.5.0/docs/api/java/lang/String.html">String[Globals.EMAIL_SERVER_USER_COUNT]; |
||
39 | for(int i = 1;i<= Globals.EMAIL_SERVER_USER_COUNT;i++) |
||
40 | { |
||
41 | serverEmails[i-1] = Globals.EMAIL_SERVER_USER_PREFIX + i + Globals.EMAIL_SERVER_USER_SUFIX; |
||
42 | } |
||
43 | } |
||
44 | private static synchronized 1.5.0/docs/api/java/lang/String.html">String getRoundRobinEmailUser() |
||
45 | { |
||
46 | serverEmailPos++; |
||
47 | if(serverEmailPos >= Globals.EMAIL_SERVER_USER_COUNT) |
||
48 | { |
||
49 | serverEmailPos = 0; |
||
50 | } |
||
51 | return serverEmails[serverEmailPos]; |
||
52 | } |
||
1429 | jmachado | 53 | |
54 | |||
236 | jmachado | 55 | public void sendEmail(Email email) throws ServiceException |
29 | jmachado | 56 | { |
1429 | jmachado | 57 | sendEmail(email,null,null); |
58 | } |
||
59 | public void sendEmail(Email email,1.5.0/docs/api/java/lang/String.html">String url,1.5.0/docs/api/java/lang/String.html">String nome) throws ServiceException |
||
60 | { |
||
1426 | jmachado | 61 | if(Globals.TEST_ENVIRONEMENT && !email.isSystemAssumingTestEmail()) |
1312 | jmachado | 62 | { |
63 | 1.5.0/docs/api/java/lang/String.html">String warn = "System in TEST Environement - will not send EMAIL"; |
||
64 | logger.warn(warn); |
||
65 | return; |
||
66 | } |
||
236 | jmachado | 67 | try{ |
68 | |||
1431 | jmachado | 69 | |
70 | final 1.5.0/docs/api/java/lang/String.html">String sendFromAddress = Globals.SYSTEM_EMAIL_USE_ROUND_ROBIN ? |
||
71 | getRoundRobinEmailUser() : Globals.SYSTEM_EMAIL_BOX; |
||
72 | |||
73 | |||
236 | jmachado | 74 | // Set up properties for mail session |
75 | 1.5.0/docs/api/java/util/Properties.html">Properties props = 1.5.0/docs/api/java/lang/System.html">System.getProperties(); |
||
76 | props.put("mail.smtp.host", Globals.EMAIL_SERVER_HOST); |
||
929 | jmachado | 77 | final 1.5.0/docs/api/java/lang/String.html">String username = Globals.EMAIL_SERVER_USERNAME; |
78 | final 1.5.0/docs/api/java/lang/String.html">String password = Globals.EMAIL_SERVER_PASSWORD; |
||
79 | javax.mail.1.5.0/docs/api/java/net/Authenticator.html">Authenticator authenticator = null; |
||
1431 | jmachado | 80 | if(Globals.SYSTEM_EMAIL_USE_SECURITY && Globals.EMAIL_SERVER_SECURITY != null && Globals.EMAIL_SERVER_SECURITY.compareTo("TLS")==0) |
929 | jmachado | 81 | { |
82 | props.put("mail.smtp.auth", "true"); |
||
83 | props.put("mail.smtp.starttls.enable", "true"); |
||
84 | props.put("mail.smtp.port", ""+ Globals.EMAIL_SERVER_SECURITY_TLS); |
||
85 | authenticator = new javax.mail.1.5.0/docs/api/java/net/Authenticator.html">Authenticator() { |
||
86 | protected 1.5.0/docs/api/java/net/PasswordAuthentication.html">PasswordAuthentication getPasswordAuthentication() { |
||
1260 | jmachado | 87 | return new 1.5.0/docs/api/java/net/PasswordAuthentication.html">PasswordAuthentication(sendFromAddress, password); |
929 | jmachado | 88 | } |
89 | }; |
||
90 | } |
||
1431 | jmachado | 91 | else if(Globals.SYSTEM_EMAIL_USE_SECURITY && Globals.EMAIL_SERVER_SECURITY != null && Globals.EMAIL_SERVER_SECURITY.compareTo("SSL")==0) |
929 | jmachado | 92 | { |
93 | props.put("mail.smtp.socketFactory.port", Globals.EMAIL_SERVER_SECURITY_SSL); |
||
94 | props.put("mail.smtp.socketFactory.class", |
||
95 | "javax.net.ssl.SSLSocketFactory"); |
||
96 | props.put("mail.smtp.auth", "true"); |
||
97 | props.put("mail.smtp.port", Globals.EMAIL_SERVER_SECURITY_SSL); |
||
98 | authenticator = new javax.mail.1.5.0/docs/api/java/net/Authenticator.html">Authenticator() { |
||
99 | protected 1.5.0/docs/api/java/net/PasswordAuthentication.html">PasswordAuthentication getPasswordAuthentication() { |
||
1260 | jmachado | 100 | return new 1.5.0/docs/api/java/net/PasswordAuthentication.html">PasswordAuthentication(sendFromAddress,password); |
929 | jmachado | 101 | } |
102 | }; |
||
103 | } |
||
104 | else |
||
105 | { |
||
236 | jmachado | 106 | |
929 | jmachado | 107 | } |
108 | |||
109 | |||
110 | |||
111 | |||
112 | |||
113 | |||
236 | jmachado | 114 | // Get session |
1431 | jmachado | 115 | Session session = authenticator != null ? |
116 | Session.getDefaultInstance(props, authenticator) |
||
117 | : Session.getDefaultInstance(props) ; |
||
118 | |||
933 | jmachado | 119 | session.setDebug(true); |
120 | session.setDebugOut(1.5.0/docs/api/java/lang/System.html">System.out); |
||
236 | jmachado | 121 | |
122 | // Create message |
||
123 | MimeMessage message = new MimeMessage(session); |
||
124 | // Set the recipients of the message |
||
298 | jmachado | 125 | boolean valid = false; |
126 | for (1.5.0/docs/api/java/lang/String.html">String recipient : email.getRecipients()) |
||
127 | { |
||
128 | if(Email.validEmail(recipient)) |
||
129 | { |
||
130 | valid=true; |
||
1429 | jmachado | 131 | message.addRecipient(Message.RecipientType.TO,new InternetAddress(recipient)); |
1427 | jmachado | 132 | logger.info("Adding recipient (" + email.getType().toString() + ") to transport:"+recipient); |
298 | jmachado | 133 | } |
236 | jmachado | 134 | } |
1429 | jmachado | 135 | |
136 | if(email.getRecipientsCC() != null) |
||
137 | { |
||
138 | for (1.5.0/docs/api/java/lang/String.html">String recipient : email.getRecipientsCC()) |
||
139 | { |
||
140 | if(Email.validEmail(recipient)) |
||
141 | { |
||
142 | //valid=true; |
||
143 | message.addRecipient(Message.RecipientType.CC,new InternetAddress(recipient)); |
||
144 | logger.info("Adding recipient CC (" + email.getType().toString() + ") to transport:"+recipient); |
||
145 | } |
||
146 | } |
||
147 | } |
||
298 | jmachado | 148 | if(valid) |
149 | { |
||
811 | jmachado | 150 | |
1426 | jmachado | 151 | 1.5.0/docs/api/java/lang/String.html">String fullMessage = getEmailTextMessage(email); |
236 | jmachado | 152 | |
1429 | jmachado | 153 | if(url != null && nome != null) |
154 | { |
||
155 | logger.info("Requesting certificated Email, will replace fields in template"); |
||
156 | fullMessage = fullMessage.replaceAll("@USER_NOME@",nome); |
||
157 | fullMessage = fullMessage.replaceAll("@URL@",url); |
||
158 | } |
||
935 | jmachado | 159 | |
160 | |||
1429 | jmachado | 161 | |
1260 | jmachado | 162 | logger.info("FROM:" + email.getFrom() + " but using: " + sendFromAddress); |
932 | jmachado | 163 | //if(email.getFromName() != null) |
872 | jmachado | 164 | try { |
1260 | jmachado | 165 | message.setFrom(new InternetAddress(sendFromAddress,sendFromAddress)); |
872 | jmachado | 166 | } catch (1.5.0/docs/api/java/io/UnsupportedEncodingException.html">UnsupportedEncodingException e) { |
167 | logger.error(e,e); |
||
1260 | jmachado | 168 | //message.setFrom(new InternetAddress(sendFromAddress)); |
872 | jmachado | 169 | } |
932 | jmachado | 170 | //else |
171 | // message.setFrom(new InternetAddress(Globals.SYSTEM_EMAIL_BOX)); |
||
1269 | jmachado | 172 | message.setSubject(email.getSubject() + " - não responda para este endereço","utf-8"); |
936 | jmachado | 173 | |
174 | if(email.isHtml()) |
||
175 | { |
||
176 | |||
992 | jmachado | 177 | fullMessage += email.getFrom() != null && email.getFrom().length()>0 && !email.getFrom().equals(Globals.SYSTEM_EMAIL_BOX) ? "<br/><br/>Responda para " + email.getFrom() : "<br/><br/>Por favor não responda a este email"; |
1425 | jmachado | 178 | fullMessage += " <br/> <br/> <h5> Mensagem Segura - enviada através da Google Apps Api </h5>"; |
936 | jmachado | 179 | |
180 | } |
||
181 | else |
||
182 | { |
||
992 | jmachado | 183 | fullMessage += email.getFrom() != null && email.getFrom().length()>0 && !email.getFrom().equals(Globals.SYSTEM_EMAIL_BOX) ? "\n\nResponda para " + email.getFrom() : "\n\nPor favor não responda a este email"; |
1425 | jmachado | 184 | fullMessage += " \n\n Mensagem Segura - enviada através da Google Apps Api "; |
936 | jmachado | 185 | } |
186 | |||
492 | jmachado | 187 | message.setText(fullMessage,"utf-8"); |
236 | jmachado | 188 | |
490 | jmachado | 189 | |
512 | jmachado | 190 | if(email.isHtml()) |
935 | jmachado | 191 | { |
512 | jmachado | 192 | message.setHeader("Content-Type","text/html; charset=\"utf-8\""); |
935 | jmachado | 193 | } |
512 | jmachado | 194 | else |
935 | jmachado | 195 | { |
512 | jmachado | 196 | message.setHeader("Content-Type","text/plain; charset=\"utf-8\""); |
935 | jmachado | 197 | } |
490 | jmachado | 198 | message.setHeader("Content-Transfer-Encoding", "quoted-printable"); |
811 | jmachado | 199 | logger.info("Sending email to transport:"+fullMessage); |
492 | jmachado | 200 | |
811 | jmachado | 201 | |
933 | jmachado | 202 | |
298 | jmachado | 203 | Transport.send(message); |
204 | } |
||
236 | jmachado | 205 | } |
206 | catch(MessagingException e) |
||
207 | { |
||
208 | logger.error(e,e); |
||
209 | throw new ServiceException(e.toString()); |
||
210 | } |
||
29 | jmachado | 211 | } |
236 | jmachado | 212 | |
1426 | jmachado | 213 | private static 1.5.0/docs/api/java/lang/String.html">String getEmailTextMessage(Email email) |
214 | { |
||
215 | return getEmailTextMessage( email.getEmailTemplateName(), email.getArguments().toArray()); |
||
216 | } |
||
217 | |||
218 | public static 1.5.0/docs/api/java/lang/String.html">String getEmailTextMessage(1.5.0/docs/api/java/lang/String.html">String template,List<String> arguments) |
||
219 | { |
||
220 | return getEmailTextMessage(template, arguments.toArray()); |
||
221 | } |
||
222 | public static 1.5.0/docs/api/java/lang/String.html">String getEmailTextMessage(1.5.0/docs/api/java/lang/String.html">String template,5+0%2Fdocs%2Fapi+Object">Object[] arguments) |
||
223 | { |
||
224 | 1.5.0/docs/api/java/lang/String.html">String content = TemplateUtils.getOrLoadTemplate(Globals.TEMPLATE_EMAIL_PATH + "/" +template); |
||
225 | // Format the mail message |
||
226 | return 1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat.format(content, arguments); |
||
227 | } |
||
228 | |||
236 | jmachado | 229 | public Email getSendUrlToFriendEmail(1.5.0/docs/api/java/lang/String.html">String url, 1.5.0/docs/api/java/lang/String.html">String from, LangEnum langEnum, List<String> recipients) |
230 | { |
||
231 | List<String> arguments = new ArrayList<String>(); |
||
232 | arguments.add(from); |
||
233 | arguments.add(url); |
||
234 | 1.5.0/docs/api/java/lang/String.html">String subjectTxt; |
||
235 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
236 | |||
237 | if(langEnum == LangEnum.PORTUGUESE) |
||
238 | { |
||
239 | template = Globals.EMAIL_SEND_URL_FRIEND_TEMPLATE_PT; |
||
237 | jmachado | 240 | subjectTxt = Globals.EMAIL_SEND_URL_FRIEND_SUBJECT_PT; |
236 | jmachado | 241 | } |
242 | else |
||
243 | { |
||
244 | template = Globals.EMAIL_SEND_URL_FRIEND_TEMPLATE_EN; |
||
237 | jmachado | 245 | subjectTxt = Globals.EMAIL_SEND_URL_FRIEND_SUBJECT_EN; |
236 | jmachado | 246 | } |
247 | |||
248 | 1.5.0/docs/api/java/lang/String.html">String subject = java.text.1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat.format(subjectTxt,new 1.5.0/docs/api/java/lang/String.html">String[]{from}); |
||
249 | return new Email(subject ,recipients, Globals.SYSTEM_EMAIL_BOX,template,arguments); |
||
250 | } |
||
251 | |||
252 | public boolean sendUrlToFriend(1.5.0/docs/api/java/lang/String.html">String url, 1.5.0/docs/api/java/lang/String.html">String from, LangEnum langEnum, List<String> recipients) |
||
253 | { |
||
254 | try |
||
255 | { |
||
256 | sendEmail(getSendUrlToFriendEmail(url,from,langEnum,recipients)); |
||
257 | return true; |
||
258 | } |
||
259 | catch (ServiceException e) |
||
260 | { |
||
261 | return false; |
||
262 | } |
||
263 | } |
||
264 | |||
237 | jmachado | 265 | public boolean sendCourseUnitAnnouncement(CourseUnitAnnouncement announcement, LangEnum langEnum, 1.5.0/docs/api/java/lang/String.html">String from, List<User> users) |
266 | { |
||
267 | try |
||
268 | { |
||
269 | sendEmail(getCourseUnitAnnouncementEmail(announcement,langEnum,from,users)); |
||
270 | return true; |
||
271 | } |
||
272 | catch (ServiceException e) |
||
273 | { |
||
274 | return false; |
||
275 | } |
||
276 | } |
||
236 | jmachado | 277 | |
1089 | jmachado | 278 | public static class SendTo |
512 | jmachado | 279 | { |
1089 | jmachado | 280 | public 1.5.0/docs/api/java/lang/String.html">String name; |
281 | public 1.5.0/docs/api/java/lang/String.html">String email; |
||
282 | public 1.5.0/docs/api/java/lang/String.html">String outEmail; |
||
283 | } |
||
284 | |||
285 | public Email getMessageEmail(1.5.0/docs/api/java/lang/String.html">String from, 1.5.0/docs/api/java/lang/String.html">String subject,1.5.0/docs/api/java/lang/String.html">String text, LangEnum langEnum, 1.5.0/docs/api/java/lang/String.html">String target, List<String> emails, User user) |
||
286 | { |
||
1260 | jmachado | 287 | return getMessageEmailAdulteredFromEmail(null,from,subject,text,langEnum,target,emails,user); |
288 | } |
||
289 | |||
290 | public Email getMessageEmailAdulteredFromEmail(1.5.0/docs/api/java/lang/String.html">String fromEmail, 1.5.0/docs/api/java/lang/String.html">String from, 1.5.0/docs/api/java/lang/String.html">String subject,1.5.0/docs/api/java/lang/String.html">String text, LangEnum langEnum, 1.5.0/docs/api/java/lang/String.html">String target, List<String> emails, User user) |
||
291 | { |
||
512 | jmachado | 292 | // # 0 : From |
293 | // # 1 : Subject |
||
294 | // # 2 : Text |
||
295 | // # 3 : person |
||
296 | // # 4 : target |
||
297 | List<String> arguments = new ArrayList<String>(); |
||
298 | arguments.add(from); |
||
299 | arguments.add(subject); |
||
300 | arguments.add(text); |
||
301 | arguments.add(user.getName()); |
||
302 | arguments.add(target); |
||
1260 | jmachado | 303 | arguments.add(fromEmail); |
512 | jmachado | 304 | |
305 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
306 | |||
307 | if(langEnum == LangEnum.PORTUGUESE) |
||
308 | { |
||
309 | template = Globals.EMAIL_MESSAGE_TEMPLATE_PT; |
||
310 | } |
||
311 | else |
||
312 | { |
||
313 | template = Globals.EMAIL_MESSAGE_TEMPLATE_EN; |
||
314 | } |
||
315 | |||
316 | List<String> recipients = new ArrayList<String>(); |
||
1089 | jmachado | 317 | for(1.5.0/docs/api/java/lang/String.html">String e: emails) |
318 | { |
||
319 | if(Email.validEmail(e)) |
||
320 | recipients.add(e); |
||
321 | } |
||
322 | logger.info("subject: " + subject); |
||
1260 | jmachado | 323 | if(fromEmail == null) |
324 | logger.info("user: " + user.getEmail()); |
||
325 | else |
||
326 | logger.info("user altered to: " + fromEmail); |
||
1089 | jmachado | 327 | logger.info("template: " + template); |
328 | logger.info("arguments:"); |
||
329 | for(1.5.0/docs/api/java/lang/String.html">String arg: arguments) |
||
330 | logger.info(arg); |
||
331 | logger.info("recipients:"); |
||
332 | for(1.5.0/docs/api/java/lang/String.html">String rec: recipients) |
||
333 | logger.info(rec); |
||
334 | logger.info("arguments end"); |
||
1260 | jmachado | 335 | fromEmail = fromEmail == null ? user.getEmail() : fromEmail; |
336 | Email email = new Email(subject ,recipients,fromEmail,template,arguments,Message.RecipientType.BCC); |
||
1089 | jmachado | 337 | email.setFromName(from + " (ESTG)"); |
338 | return email; |
||
339 | } |
||
340 | |||
1425 | jmachado | 341 | public Email getMessageEmailAdulteredFromEmailIpp(1.5.0/docs/api/java/lang/String.html">String fromEmail, 1.5.0/docs/api/java/lang/String.html">String from, 1.5.0/docs/api/java/lang/String.html">String subject,1.5.0/docs/api/java/lang/String.html">String text, List<String> emails, User user) |
342 | { |
||
343 | // # 0 : From |
||
344 | // # 1 : Subject |
||
345 | // # 2 : Text |
||
1429 | jmachado | 346 | // # 3 : FromEmail Adultered in message |
347 | // # 4 : URL todo with certificate |
||
1425 | jmachado | 348 | List<String> arguments = new ArrayList<String>(); |
349 | arguments.add(from); |
||
350 | arguments.add(subject); |
||
351 | arguments.add(text); |
||
352 | arguments.add(fromEmail); |
||
353 | |||
354 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
355 | |||
356 | template = Globals.EMAIL_MESSAGE_IPP_TEMPLATE_PT; |
||
357 | |||
358 | |||
359 | List<String> recipients = new ArrayList<String>(); |
||
360 | for(1.5.0/docs/api/java/lang/String.html">String e: emails) |
||
361 | { |
||
362 | if(Email.validEmail(e)) |
||
363 | recipients.add(e); |
||
364 | } |
||
1426 | jmachado | 365 | |
1425 | jmachado | 366 | logger.info("subject: " + subject); |
367 | if(fromEmail == null) |
||
368 | logger.info("user: " + user.getEmail()); |
||
369 | else |
||
370 | logger.info("user altered to: " + fromEmail); |
||
371 | logger.info("template: " + template); |
||
372 | logger.info("arguments:"); |
||
373 | for(1.5.0/docs/api/java/lang/String.html">String arg: arguments) |
||
374 | logger.info(arg); |
||
375 | logger.info("recipients:"); |
||
376 | for(1.5.0/docs/api/java/lang/String.html">String rec: recipients) |
||
377 | logger.info(rec); |
||
378 | logger.info("arguments end"); |
||
379 | fromEmail = fromEmail == null ? user.getEmail() : fromEmail; |
||
1429 | jmachado | 380 | Email email = new Email(subject ,recipients,fromEmail,template,arguments,Message.RecipientType.TO); |
1425 | jmachado | 381 | email.setFromName(from + " (PAE-IPP)"); |
382 | return email; |
||
383 | } |
||
384 | |||
1429 | jmachado | 385 | public EmailPersonalizedCertificated getMessageEmailAdulteredFromEmailIppCertificated( |
386 | 1.5.0/docs/api/java/lang/String.html">String fromEmail, 1.5.0/docs/api/java/lang/String.html">String from, 1.5.0/docs/api/java/lang/String.html">String subject,1.5.0/docs/api/java/lang/String.html">String text, User user, |
||
387 | List<Long> userIds, |
||
388 | 1.5.0/docs/api/java/lang/String.html">String url |
||
389 | ) |
||
390 | { |
||
391 | // # 0 : From |
||
392 | // # 1 : Subject |
||
393 | // # 2 : Text |
||
394 | // # 3 : FromEmail Adultered in message |
||
395 | // # 4 : URL todo with certificate |
||
396 | List<String> arguments = new ArrayList<String>(); |
||
397 | arguments.add(from); |
||
398 | arguments.add(subject); |
||
399 | arguments.add(text); |
||
400 | arguments.add(fromEmail); |
||
1426 | jmachado | 401 | |
1429 | jmachado | 402 | 1.5.0/docs/api/java/lang/String.html">String template; |
1426 | jmachado | 403 | |
1429 | jmachado | 404 | template = Globals.EMAIL_MESSAGE_IPP_TEMPLATE_PT_CERTIFICATED; |
405 | |||
406 | |||
407 | logger.info("Preparing batch work for Personalized Emails Certificated"); |
||
408 | logger.info("subject: " + subject); |
||
409 | if(fromEmail == null) |
||
410 | logger.info("user: " + user.getEmail()); |
||
411 | else |
||
412 | logger.info("user altered to: " + fromEmail); |
||
413 | logger.info("template: " + template); |
||
414 | logger.info("arguments:"); |
||
415 | for(1.5.0/docs/api/java/lang/String.html">String arg: arguments) |
||
416 | logger.info(arg); |
||
417 | logger.info("userIds:" + userIds); |
||
418 | logger.info("arguments end"); |
||
419 | fromEmail = fromEmail == null ? user.getEmail() : fromEmail; |
||
420 | EmailPersonalizedCertificated email = new EmailPersonalizedCertificated(subject ,fromEmail,template,arguments, |
||
421 | url, |
||
422 | userIds); |
||
423 | email.setFromName(from + " (PAE-IPP)"); |
||
424 | |||
425 | return email; |
||
426 | } |
||
427 | |||
428 | |||
429 | |||
1089 | jmachado | 430 | public Email getMessageEmailOld(1.5.0/docs/api/java/lang/String.html">String from, 1.5.0/docs/api/java/lang/String.html">String subject,1.5.0/docs/api/java/lang/String.html">String text, LangEnum langEnum, 1.5.0/docs/api/java/lang/String.html">String target, List<User> users, User user) |
431 | { |
||
432 | // # 0 : From |
||
433 | // # 1 : Subject |
||
434 | // # 2 : Text |
||
435 | // # 3 : person |
||
436 | // # 4 : target |
||
437 | List<String> arguments = new ArrayList<String>(); |
||
438 | arguments.add(from); |
||
439 | arguments.add(subject); |
||
440 | arguments.add(text); |
||
441 | arguments.add(user.getName()); |
||
442 | arguments.add(target); |
||
443 | |||
444 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
445 | |||
446 | if(langEnum == LangEnum.PORTUGUESE) |
||
447 | { |
||
448 | template = Globals.EMAIL_MESSAGE_TEMPLATE_PT; |
||
449 | } |
||
450 | else |
||
451 | { |
||
452 | template = Globals.EMAIL_MESSAGE_TEMPLATE_EN; |
||
453 | } |
||
454 | |||
455 | List<String> recipients = new ArrayList<String>(); |
||
512 | jmachado | 456 | for(User u: users) |
457 | { |
||
458 | if(Email.validEmail(u.getEmail())) |
||
459 | recipients.add(u.getEmail()); |
||
460 | if(Email.validEmail(u.getOutEmail())) |
||
461 | recipients.add(u.getOutEmail()); |
||
462 | } |
||
810 | jmachado | 463 | logger.info("subject: " + subject); |
464 | logger.info("user: " + user.getEmail()); |
||
465 | logger.info("template: " + template); |
||
466 | logger.info("arguments:"); |
||
467 | for(1.5.0/docs/api/java/lang/String.html">String arg: arguments) |
||
468 | logger.info(arg); |
||
469 | logger.info("recipients:"); |
||
470 | for(1.5.0/docs/api/java/lang/String.html">String rec: recipients) |
||
471 | logger.info(rec); |
||
472 | logger.info("arguments end"); |
||
872 | jmachado | 473 | Email email = new Email(subject ,recipients,user.getEmail(),template,arguments,Message.RecipientType.BCC); |
474 | email.setFromName(from + " (ESTG)"); |
||
475 | return email; |
||
512 | jmachado | 476 | } |
477 | |||
237 | jmachado | 478 | public Email getCourseUnitAnnouncementEmail(CourseUnitAnnouncement announcement, LangEnum langEnum, 1.5.0/docs/api/java/lang/String.html">String from, List<User> users) |
479 | { |
||
480 | List<String> arguments = new ArrayList<String>(); |
||
481 | arguments.add(announcement.getCourseUnit().getName()); |
||
482 | arguments.add(announcement.getTitle()); |
||
483 | arguments.add(announcement.getText()); |
||
484 | arguments.add(from); |
||
485 | |||
486 | 1.5.0/docs/api/java/lang/String.html">String subjectTxt; |
||
487 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
488 | |||
489 | if(langEnum == LangEnum.PORTUGUESE) |
||
490 | { |
||
491 | template = Globals.EMAIL_COURSEUNIT_ANNOUNCEMENT_TEMPLATE_PT; |
||
492 | subjectTxt = Globals.EMAIL_COURSEUNIT_ANNOUNCEMENT_SUBJECT_PT; |
||
493 | } |
||
494 | else |
||
495 | { |
||
496 | template = Globals.EMAIL_COURSEUNIT_ANNOUNCEMENT_TEMPLATE_EN; |
||
497 | subjectTxt = Globals.EMAIL_COURSEUNIT_ANNOUNCEMENT_SUBJECT_EN; |
||
498 | } |
||
499 | |||
500 | List<String> recipients = new ArrayList<String>(); |
||
501 | for(User u: users) |
||
502 | { |
||
298 | jmachado | 503 | if(Email.validEmail(u.getEmail())) |
504 | recipients.add(u.getEmail()); |
||
419 | jmachado | 505 | if(Email.validEmail(u.getOutEmail())) |
506 | recipients.add(u.getOutEmail()); |
||
237 | jmachado | 507 | } |
508 | |||
509 | 1.5.0/docs/api/java/lang/String.html">String subject = java.text.1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat.format(subjectTxt,new 1.5.0/docs/api/java/lang/String.html">String[]{announcement.getCourseUnit().getNormalizedName(),announcement.getTitle()}); |
||
419 | jmachado | 510 | 1.5.0/docs/api/java/lang/String.html">String fromEmail = Globals.SYSTEM_EMAIL_BOX; |
511 | if(announcement.getOwner() != null && Email.validEmail(announcement.getOwner().getEmail())) |
||
512 | fromEmail = announcement.getOwner().getEmail(); |
||
513 | return new Email(subject ,recipients,fromEmail,template,arguments,Message.RecipientType.BCC); |
||
237 | jmachado | 514 | } |
515 | |||
363 | jmachado | 516 | public Email getCourseUnitBlogPostEmail(BlogPost post, LangEnum langEnum, 1.5.0/docs/api/java/lang/String.html">String from, List<User> users) |
517 | { |
||
518 | List<String> arguments = new ArrayList<String>(); |
||
519 | arguments.add(((CourseUnitBlog)post.getBlog()).getCourseUnit().getName()); |
||
520 | arguments.add(post.getTitle()); |
||
521 | arguments.add(post.getText()); |
||
522 | arguments.add(from); |
||
237 | jmachado | 523 | |
363 | jmachado | 524 | 1.5.0/docs/api/java/lang/String.html">String subjectTxt; |
525 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
526 | |||
527 | if(langEnum == LangEnum.PORTUGUESE) |
||
528 | { |
||
529 | template = Globals.EMAIL_COURSEUNIT_BLOGPOST_TEMPLATE_PT; |
||
530 | subjectTxt = Globals.EMAIL_COURSEUNIT_BLOGPOST_SUBJECT_PT; |
||
531 | } |
||
532 | else |
||
533 | { |
||
534 | template = Globals.EMAIL_COURSEUNIT_BLOGPOST_TEMPLATE_EN; |
||
535 | subjectTxt = Globals.EMAIL_COURSEUNIT_BLOGPOST_SUBJECT_EN; |
||
536 | } |
||
537 | |||
538 | List<String> recipients = new ArrayList<String>(); |
||
539 | for(User u: users) |
||
540 | { |
||
541 | if(Email.validEmail(u.getEmail())) |
||
542 | recipients.add(u.getEmail()); |
||
419 | jmachado | 543 | if(Email.validEmail(u.getOutEmail())) |
544 | recipients.add(u.getOutEmail()); |
||
363 | jmachado | 545 | } |
546 | |||
547 | 1.5.0/docs/api/java/lang/String.html">String subject = java.text.1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat.format(subjectTxt,new 1.5.0/docs/api/java/lang/String.html">String[]{((CourseUnitBlog)post.getBlog()).getCourseUnit().getNormalizedName(),post.getTitle()}); |
||
419 | jmachado | 548 | 1.5.0/docs/api/java/lang/String.html">String fromEmail = Globals.SYSTEM_EMAIL_BOX; |
549 | if(post.getOwner() != null && Email.validEmail(post.getOwner().getEmail())) |
||
550 | fromEmail = post.getOwner().getEmail(); |
||
551 | return new Email(subject ,recipients, fromEmail, template,arguments,Message.RecipientType.BCC); |
||
363 | jmachado | 552 | } |
553 | |||
440 | jmachado | 554 | public Email getCourseUnitWorkEmail(CourseUnitAssignement assignement, LangEnum langEnum, UserSession userSession, List<User> users, boolean newWork) |
419 | jmachado | 555 | { |
556 | List<String> arguments = new ArrayList<String>(); |
||
557 | arguments.add(assignement.getCourseUnit().getName()); |
||
558 | arguments.add(assignement.getTitle()); |
||
559 | arguments.add(assignement.getDescription()); |
||
440 | jmachado | 560 | |
419 | jmachado | 561 | if(userSession != null && userSession.getName() != null) |
562 | arguments.add(userSession.getName()); |
||
563 | else |
||
564 | arguments.add("unknown"); |
||
363 | jmachado | 565 | |
440 | jmachado | 566 | arguments.add( DatesUtils.getStringFromDate(assignement.getDeliverDate())); |
492 | jmachado | 567 | |
1353 | jmachado | 568 | //String directUrl = Globals.EMAIL_COURSEUNIT_WORK_RELATIVE_URL; |
569 | //directUrl = Globals.SITE_URL + MessageFormat.format(directUrl,assignement.getCourseUnit().getId()); |
||
570 | |||
419 | jmachado | 571 | 1.5.0/docs/api/java/lang/String.html">String subjectTxt; |
572 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
573 | |||
574 | if(langEnum == LangEnum.PORTUGUESE) |
||
575 | { |
||
440 | jmachado | 576 | if(newWork) |
577 | template = Globals.EMAIL_COURSEUNIT_WORK_TEMPLATE_PT; |
||
578 | else |
||
579 | template = Globals.EMAIL_COURSEUNIT_WORK_CHANGE_TEMPLATE_PT; |
||
419 | jmachado | 580 | subjectTxt = Globals.EMAIL_COURSEUNIT_WORK_SUBJECT_PT; |
581 | } |
||
582 | else |
||
583 | { |
||
440 | jmachado | 584 | if(newWork) |
585 | template = Globals.EMAIL_COURSEUNIT_WORK_TEMPLATE_EN; |
||
586 | else |
||
587 | template = Globals.EMAIL_COURSEUNIT_WORK_CHANGE_TEMPLATE_EN; |
||
419 | jmachado | 588 | subjectTxt = Globals.EMAIL_COURSEUNIT_WORK_SUBJECT_EN; |
589 | } |
||
590 | |||
591 | List<String> recipients = new ArrayList<String>(); |
||
592 | for(User u: users) |
||
593 | { |
||
594 | if(Email.validEmail(u.getEmail())) |
||
595 | recipients.add(u.getEmail()); |
||
596 | if(Email.validEmail(u.getOutEmail())) |
||
597 | recipients.add(u.getOutEmail()); |
||
598 | } |
||
599 | |||
600 | 1.5.0/docs/api/java/lang/String.html">String subject = java.text.1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat.format(subjectTxt,new 1.5.0/docs/api/java/lang/String.html">String[]{assignement.getCourseUnit().getNormalizedName(),assignement.getTitle()}); |
||
601 | |||
602 | 1.5.0/docs/api/java/lang/String.html">String fromEmail = Globals.SYSTEM_EMAIL_BOX; |
||
603 | if(userSession!= null && userSession.getUser() != null && Email.validEmail(userSession.getUser().getEmail())) |
||
604 | fromEmail = userSession.getUser().getEmail(); |
||
605 | return new Email(subject ,recipients,fromEmail,template,arguments,Message.RecipientType.BCC); |
||
606 | } |
||
607 | |||
608 | |||
609 | |||
236 | jmachado | 610 | public Email getNewGradesEmail(List<String[]> grades, LangEnum langEnum, 1.5.0/docs/api/java/lang/String.html">String studentEmail, 1.5.0/docs/api/java/lang/String.html">String studentName) |
611 | { |
||
612 | List<String> arguments = new ArrayList<String>(); |
||
613 | |||
614 | 1.5.0/docs/api/java/lang/String.html">String subject; |
||
615 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
616 | |||
617 | if(langEnum == LangEnum.PORTUGUESE) |
||
618 | { |
||
619 | template = Globals.EMAIL_NEW_GRADES_TEMPLATE_PT; |
||
237 | jmachado | 620 | subject = Globals.EMAIL_NEW_GRADES_SUBJECT_PT; |
236 | jmachado | 621 | } |
622 | else |
||
623 | { |
||
624 | template = Globals.EMAIL_NEW_GRADES_TEMPLATE_EN; |
||
237 | jmachado | 625 | subject = Globals.EMAIL_NEW_GRADES_SUBJECT_EN; |
236 | jmachado | 626 | } |
627 | |||
628 | 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder gradesBuilder = new 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder(); |
||
629 | for(1.5.0/docs/api/java/lang/String.html">String[] grade: grades) |
||
630 | { |
||
631 | 1.5.0/docs/api/java/lang/String.html">String gradeTxt = TemplateUtils.formatMessageTemplate(gradeUnitTemplate,grade); |
||
632 | gradesBuilder.append(gradeTxt); |
||
633 | } |
||
634 | |||
635 | arguments.add(studentName); |
||
636 | arguments.add(gradesBuilder.toString()); |
||
637 | |||
638 | List<String> recipients = new ArrayList<String>(); |
||
639 | recipients.add(studentEmail); |
||
640 | return new Email(subject ,recipients, Globals.SYSTEM_EMAIL_BOX,template,arguments); |
||
641 | } |
||
642 | |||
358 | jmachado | 643 | public Email getSummaryEmail(List<String> emails, CourseUnitSummary cUS, CourseUnit c, LangEnum langEnum) |
644 | { |
||
645 | List<String> arguments = new ArrayList<String>(); |
||
646 | |||
647 | 1.5.0/docs/api/java/lang/String.html">String data = DatesUtils.getStringFromDate(cUS.getDataAula()); |
||
648 | 1.5.0/docs/api/java/lang/String.html">String subject; |
||
649 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
650 | |||
651 | if(langEnum == LangEnum.PORTUGUESE) |
||
652 | { |
||
653 | template = Globals.EMAIL_SUMMARY_TEMPLATE_PT; |
||
654 | subject = Globals.EMAIL_SUMMARY_SUBJECT_PT; |
||
655 | } |
||
656 | else |
||
657 | { |
||
658 | template = Globals.EMAIL_SUMMARY_TEMPLATE_EN; |
||
659 | subject = Globals.EMAIL_SUMMARY_SUBJECT_EN; |
||
660 | } |
||
661 | subject = TemplateUtils.formatMessageTemplate(subject,new 1.5.0/docs/api/java/lang/String.html">String[]{c.getName()}); |
||
662 | |||
663 | arguments.add(c.getName()); |
||
664 | arguments.add(""+cUS.getNumeroAula()); |
||
665 | arguments.add(data); |
||
666 | arguments.add(cUS.getTitulo()); |
||
667 | arguments.add(cUS.getDescricao()); |
||
668 | |||
669 | List<String> recipients = new ArrayList<String>(); |
||
670 | for(1.5.0/docs/api/java/lang/String.html">String email:emails) |
||
671 | recipients.add(email); |
||
672 | return new Email(subject ,recipients, Globals.SYSTEM_EMAIL_BOX,template,arguments); |
||
673 | } |
||
674 | |||
995 | jmachado | 675 | |
676 | //TODO TESTAR |
||
677 | public Email getSummariesEmail(List<String> emails, List<CourseUnitSummary> cUS, CourseUnit c, LangEnum langEnum) |
||
678 | { |
||
679 | |||
680 | |||
681 | 1.5.0/docs/api/java/lang/String.html">String ultimaData = DatesUtils.getStringFromDate(cUS.get(cUS.size() - 1).getDataAula()); |
||
682 | 1.5.0/docs/api/java/lang/String.html">String subject; |
||
683 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
684 | 1.5.0/docs/api/java/lang/String.html">String templateFragment; |
||
685 | |||
686 | if(langEnum == LangEnum.PORTUGUESE) |
||
687 | { |
||
688 | template = Globals.EMAIL_SUMMARIES_TEMPLATE_PT; |
||
689 | templateFragment = Globals.EMAIL_SUMMARIES_FRAGMENT_TEMPLATE_PT; |
||
690 | subject = Globals.EMAIL_SUMMARY_SUBJECT_PT; |
||
691 | } |
||
692 | else |
||
693 | { |
||
694 | template = Globals.EMAIL_SUMMARIES_TEMPLATE_EN; |
||
695 | templateFragment = Globals.EMAIL_SUMMARIES_FRAGMENT_TEMPLATE_EN; |
||
696 | subject = Globals.EMAIL_SUMMARY_SUBJECT_EN; |
||
697 | } |
||
698 | subject = TemplateUtils.formatMessageTemplate(subject,new 1.5.0/docs/api/java/lang/String.html">String[]{c.getName()}); |
||
699 | |||
700 | 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder fragments = new 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder(); |
||
701 | |||
702 | List<String> arguments = new ArrayList<String>(); |
||
703 | 1.5.0/docs/api/java/lang/String.html">String fragmentSummaryTemplate = TemplateUtils.getOrLoadTemplate(Globals.TEMPLATE_EMAIL_PATH + "/" + templateFragment); |
||
704 | for(CourseUnitSummary summary: cUS) |
||
705 | { |
||
706 | List<String> argumentsFrag = new ArrayList<String>(); |
||
707 | argumentsFrag.add(summary.getTitulo()); |
||
708 | argumentsFrag.add(DatesUtils.getStringFromDate(summary.getDataAula())); |
||
709 | argumentsFrag.add(summary.getDescricao()); |
||
710 | 1.5.0/docs/api/java/lang/String.html">String fullMessage = 1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat.format(fragmentSummaryTemplate, argumentsFrag.toArray()); |
||
711 | fragments.append("\n").append(fullMessage); |
||
712 | } |
||
713 | |||
714 | arguments.add(c.getName()); |
||
715 | arguments.add(ultimaData); |
||
716 | arguments.add(fragments.toString()); |
||
717 | |||
718 | List<String> recipients = new ArrayList<String>(); |
||
719 | for(1.5.0/docs/api/java/lang/String.html">String email:emails) |
||
720 | recipients.add(email); |
||
721 | return new Email(subject ,recipients, Globals.SYSTEM_EMAIL_BOX,template,arguments); |
||
722 | } |
||
723 | |||
751 | jmachado | 724 | public Email getUnidadeEdicaoEmail(List<String> emails, CourseUnit c, LangEnum langEnum) |
725 | { |
||
726 | List<String> arguments = new ArrayList<String>(); |
||
727 | |||
728 | |||
729 | 1.5.0/docs/api/java/lang/String.html">String subject; |
||
730 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
731 | |||
732 | if(langEnum == LangEnum.PORTUGUESE) |
||
733 | { |
||
734 | template = Globals.EMAIL_UNDADE_EDICAO_TEMPLATE_PT; |
||
735 | subject = Globals.EMAIL_UNDADE_EDICAO_SUBJECT_PT; |
||
736 | } |
||
737 | else |
||
738 | { |
||
739 | template = Globals.EMAIL_UNDADE_EDICAO_TEMPLATE_EN; |
||
740 | subject = Globals.EMAIL_UNDADE_EDICAO_SUBJECT_EN; |
||
741 | } |
||
742 | subject = 1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat.format(ConfigProperties.getProperty(subject),new 1.5.0/docs/api/java/lang/String.html">String[]{c.getName()}); |
||
743 | |||
744 | arguments.add(c.getName()); |
||
745 | |||
746 | List<String> recipients = new ArrayList<String>(); |
||
747 | for(1.5.0/docs/api/java/lang/String.html">String email:emails) |
||
748 | recipients.add(email); |
||
749 | return new Email(subject ,recipients, Globals.SYSTEM_EMAIL_BOX,template,arguments); |
||
750 | } |
||
751 | |||
752 | public Email getUnidadeValidadaEmail(List<String> emails, CourseUnit c, LangEnum langEnum) |
||
753 | { |
||
754 | List<String> arguments = new ArrayList<String>(); |
||
755 | |||
756 | |||
757 | 1.5.0/docs/api/java/lang/String.html">String subject; |
||
758 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
759 | |||
760 | if(langEnum == LangEnum.PORTUGUESE) |
||
761 | { |
||
762 | template = Globals.EMAIL_UNDADE_VALIDADA_TEMPLATE_PT; |
||
763 | subject = Globals.EMAIL_UNDADE_VALIDADA_SUBJECT_PT; |
||
764 | } |
||
765 | else |
||
766 | { |
||
767 | template = Globals.EMAIL_UNDADE_VALIDADA_TEMPLATE_EN; |
||
768 | subject = Globals.EMAIL_UNDADE_VALIDADA_SUBJECT_EN; |
||
769 | } |
||
770 | subject = 1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat.format(ConfigProperties.getProperty(subject),new 1.5.0/docs/api/java/lang/String.html">String[]{c.getName()}); |
||
771 | |||
772 | arguments.add(c.getName()); |
||
773 | |||
774 | List<String> recipients = new ArrayList<String>(); |
||
775 | for(1.5.0/docs/api/java/lang/String.html">String email:emails) |
||
776 | recipients.add(email); |
||
777 | return new Email(subject ,recipients, Globals.SYSTEM_EMAIL_BOX,template,arguments); |
||
778 | } |
||
779 | |||
780 | public Email getUnidadeEditadaEmail(List<String> emails, CourseUnit c, LangEnum langEnum) |
||
781 | { |
||
782 | List<String> arguments = new ArrayList<String>(); |
||
783 | |||
784 | |||
785 | 1.5.0/docs/api/java/lang/String.html">String subject; |
||
786 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
787 | |||
788 | if(langEnum == LangEnum.PORTUGUESE) |
||
789 | { |
||
790 | template = Globals.EMAIL_UNDADE_EDITADA_TEMPLATE_PT; |
||
791 | subject = Globals.EMAIL_UNDADE_EDITADA_SUBJECT_PT; |
||
792 | } |
||
793 | else |
||
794 | { |
||
795 | template = Globals.EMAIL_UNDADE_EDITADA_TEMPLATE_EN; |
||
796 | subject = Globals.EMAIL_UNDADE_EDITADA_SUBJECT_EN; |
||
797 | } |
||
798 | subject = 1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat.format(ConfigProperties.getProperty(subject),new 1.5.0/docs/api/java/lang/String.html">String[]{c.getName()}); |
||
799 | |||
800 | arguments.add(c.getCourseName()); |
||
801 | arguments.add(c.getName()); |
||
802 | |||
803 | List<String> recipients = new ArrayList<String>(); |
||
804 | for(1.5.0/docs/api/java/lang/String.html">String email:emails) |
||
805 | recipients.add(email); |
||
806 | return new Email(subject ,recipients, Globals.SYSTEM_EMAIL_BOX,template,arguments); |
||
807 | } |
||
808 | |||
1033 | jmachado | 809 | public Email getRelatorioAvaliacaoUnidadeEditadaEmail(List<String> emails, CourseUnit c, LangEnum langEnum,1.5.0/docs/api/java/lang/String.html">String estado) |
810 | { |
||
811 | List<String> arguments = new ArrayList<String>(); |
||
812 | |||
813 | |||
814 | 1.5.0/docs/api/java/lang/String.html">String subject; |
||
815 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
816 | |||
817 | if(langEnum == LangEnum.PORTUGUESE) |
||
818 | { |
||
819 | template = Globals.EMAIL_RELATORIO_AVALIACAO_UNDADE_EDITADA_TEMPLATE_PT; |
||
820 | subject = Globals.EMAIL_RELATORIO_AVALIACAO_UNDADE_EDITADA_SUBJECT_PT; |
||
821 | } |
||
822 | else |
||
823 | { |
||
824 | template = Globals.EMAIL_RELATORIO_AVALIACAO_UNDADE_EDITADA_TEMPLATE_EN; |
||
825 | subject = Globals.EMAIL_RELATORIO_AVALIACAO_UNDADE_EDITADA_SUBJECT_EN; |
||
826 | } |
||
827 | subject = 1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat.format(ConfigProperties.getProperty(subject),new 1.5.0/docs/api/java/lang/String.html">String[]{c.getName()}); |
||
828 | |||
829 | arguments.add(c.getCourseName()); |
||
830 | arguments.add(c.getName()); |
||
831 | arguments.add(estado); |
||
832 | |||
833 | List<String> recipients = new ArrayList<String>(); |
||
834 | for(1.5.0/docs/api/java/lang/String.html">String email:emails) |
||
835 | recipients.add(email); |
||
836 | return new Email(subject ,recipients, Globals.SYSTEM_EMAIL_BOX,template,arguments); |
||
837 | } |
||
838 | |||
236 | jmachado | 839 | public boolean sendNewGrades(List<String[]> grades, LangEnum langEnum, 1.5.0/docs/api/java/lang/String.html">String studentEmail, 1.5.0/docs/api/java/lang/String.html">String studentName) |
840 | { |
||
841 | try |
||
842 | { |
||
843 | sendEmail(getNewGradesEmail(grades,langEnum,studentEmail,studentName)); |
||
844 | return true; |
||
845 | } |
||
846 | catch (ServiceException e) |
||
847 | { |
||
848 | return false; |
||
849 | } |
||
850 | |||
851 | } |
||
852 | |||
853 | public static void main(1.5.0/docs/api/java/lang/String.html">String [] args) |
||
854 | { |
||
440 | jmachado | 855 | 1.5.0/docs/api/java/lang/System.html">System.out.println( DatesUtils.getStringFromDate(new 5+0%2Fdocs%2Fapi+Date">Date())); |
856 | // List<String[]> grades = new ArrayList<String[]>(); |
||
857 | // grades.add(new String[]{"Teste","3"}); |
||
858 | // grades.add(new String[]{"Teste2","4"}); |
||
859 | // new SendEmailService().sendNewGrades(grades,LangEnum.PORTUGUESE,"jmachado@estgp.pt","jorge Machado"); |
||
236 | jmachado | 860 | } |
861 | |||
29 | jmachado | 862 | } |