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