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