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