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