Rev 1452 | Rev 1661 | 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; |
||
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; |
358 | jmachado | 14 | import pt.estgp.estgweb.web.utils.DatesUtils; |
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 | |
1426 | jmachado | 217 | 1.5.0/docs/api/java/lang/String.html">String fullMessage = 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 | |
1426 | jmachado | 281 | private static 1.5.0/docs/api/java/lang/String.html">String getEmailTextMessage(Email email) |
282 | { |
||
283 | return getEmailTextMessage( email.getEmailTemplateName(), email.getArguments().toArray()); |
||
284 | } |
||
285 | |||
286 | 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) |
||
287 | { |
||
288 | return getEmailTextMessage(template, arguments.toArray()); |
||
289 | } |
||
290 | 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) |
||
291 | { |
||
292 | 1.5.0/docs/api/java/lang/String.html">String content = TemplateUtils.getOrLoadTemplate(Globals.TEMPLATE_EMAIL_PATH + "/" +template); |
||
293 | // Format the mail message |
||
294 | return 1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat.format(content, arguments); |
||
295 | } |
||
296 | |||
236 | jmachado | 297 | 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) |
298 | { |
||
299 | List<String> arguments = new ArrayList<String>(); |
||
300 | arguments.add(from); |
||
301 | arguments.add(url); |
||
302 | 1.5.0/docs/api/java/lang/String.html">String subjectTxt; |
||
303 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
304 | |||
305 | if(langEnum == LangEnum.PORTUGUESE) |
||
306 | { |
||
307 | template = Globals.EMAIL_SEND_URL_FRIEND_TEMPLATE_PT; |
||
237 | jmachado | 308 | subjectTxt = Globals.EMAIL_SEND_URL_FRIEND_SUBJECT_PT; |
236 | jmachado | 309 | } |
310 | else |
||
311 | { |
||
312 | template = Globals.EMAIL_SEND_URL_FRIEND_TEMPLATE_EN; |
||
237 | jmachado | 313 | subjectTxt = Globals.EMAIL_SEND_URL_FRIEND_SUBJECT_EN; |
236 | jmachado | 314 | } |
315 | |||
316 | 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}); |
||
317 | return new Email(subject ,recipients, Globals.SYSTEM_EMAIL_BOX,template,arguments); |
||
318 | } |
||
319 | |||
320 | 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) |
||
321 | { |
||
322 | try |
||
323 | { |
||
324 | sendEmail(getSendUrlToFriendEmail(url,from,langEnum,recipients)); |
||
325 | return true; |
||
326 | } |
||
327 | catch (ServiceException e) |
||
328 | { |
||
329 | return false; |
||
330 | } |
||
331 | } |
||
332 | |||
237 | jmachado | 333 | public boolean sendCourseUnitAnnouncement(CourseUnitAnnouncement announcement, LangEnum langEnum, 1.5.0/docs/api/java/lang/String.html">String from, List<User> users) |
334 | { |
||
335 | try |
||
336 | { |
||
337 | sendEmail(getCourseUnitAnnouncementEmail(announcement,langEnum,from,users)); |
||
338 | return true; |
||
339 | } |
||
340 | catch (ServiceException e) |
||
341 | { |
||
342 | return false; |
||
343 | } |
||
344 | } |
||
236 | jmachado | 345 | |
1585 | jmachado | 346 | /** |
347 | * Envio de Notificação aos operadores do CI |
||
348 | * @param subject |
||
349 | * @param cause |
||
350 | */ |
||
351 | 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) |
||
352 | { |
||
353 | List<String> emails = ConfigProperties.getListValues("admin.email"); |
||
354 | for(1.5.0/docs/api/java/lang/String.html">String email:emails) |
||
355 | { |
||
356 | logger.warn(">>>>>>>>ENVIANDO NOTIFICACAO A ADMINISTRACAO: " + email); |
||
357 | } |
||
358 | List<String> arguments = new ArrayList<String>(); |
||
359 | arguments.add(cause.replace("\n","<br/>")); |
||
360 | Email email = new Email(subject,emails,Globals.SYSTEM_EMAIL_BOX,"messageToAdmin_pt.txt",arguments); |
||
361 | email.setHtml(true); |
||
362 | try { |
||
363 | new SendEmailService().sendEmail(email); |
||
364 | } catch (ServiceException e) { |
||
365 | e.printStackTrace(); |
||
366 | } |
||
367 | } |
||
368 | |||
1089 | jmachado | 369 | public static class SendTo |
512 | jmachado | 370 | { |
1089 | jmachado | 371 | public 1.5.0/docs/api/java/lang/String.html">String name; |
372 | public 1.5.0/docs/api/java/lang/String.html">String email; |
||
373 | public 1.5.0/docs/api/java/lang/String.html">String outEmail; |
||
374 | } |
||
375 | |||
376 | 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) |
||
377 | { |
||
1260 | jmachado | 378 | return getMessageEmailAdulteredFromEmail(null,from,subject,text,langEnum,target,emails,user); |
379 | } |
||
380 | |||
381 | 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) |
||
382 | { |
||
512 | jmachado | 383 | // # 0 : From |
384 | // # 1 : Subject |
||
385 | // # 2 : Text |
||
386 | // # 3 : person |
||
387 | // # 4 : target |
||
388 | List<String> arguments = new ArrayList<String>(); |
||
389 | arguments.add(from); |
||
390 | arguments.add(subject); |
||
391 | arguments.add(text); |
||
392 | arguments.add(user.getName()); |
||
393 | arguments.add(target); |
||
1260 | jmachado | 394 | arguments.add(fromEmail); |
512 | jmachado | 395 | |
396 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
397 | |||
398 | if(langEnum == LangEnum.PORTUGUESE) |
||
399 | { |
||
400 | template = Globals.EMAIL_MESSAGE_TEMPLATE_PT; |
||
401 | } |
||
402 | else |
||
403 | { |
||
404 | template = Globals.EMAIL_MESSAGE_TEMPLATE_EN; |
||
405 | } |
||
406 | |||
407 | List<String> recipients = new ArrayList<String>(); |
||
1089 | jmachado | 408 | for(1.5.0/docs/api/java/lang/String.html">String e: emails) |
409 | { |
||
410 | if(Email.validEmail(e)) |
||
411 | recipients.add(e); |
||
412 | } |
||
413 | logger.info("subject: " + subject); |
||
1260 | jmachado | 414 | if(fromEmail == null) |
415 | logger.info("user: " + user.getEmail()); |
||
416 | else |
||
417 | logger.info("user altered to: " + fromEmail); |
||
1089 | jmachado | 418 | logger.info("template: " + template); |
419 | logger.info("arguments:"); |
||
420 | for(1.5.0/docs/api/java/lang/String.html">String arg: arguments) |
||
421 | logger.info(arg); |
||
422 | logger.info("recipients:"); |
||
423 | for(1.5.0/docs/api/java/lang/String.html">String rec: recipients) |
||
424 | logger.info(rec); |
||
425 | logger.info("arguments end"); |
||
1260 | jmachado | 426 | fromEmail = fromEmail == null ? user.getEmail() : fromEmail; |
427 | Email email = new Email(subject ,recipients,fromEmail,template,arguments,Message.RecipientType.BCC); |
||
1089 | jmachado | 428 | email.setFromName(from + " (ESTG)"); |
429 | return email; |
||
430 | } |
||
431 | |||
1425 | jmachado | 432 | 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) |
433 | { |
||
434 | // # 0 : From |
||
435 | // # 1 : Subject |
||
436 | // # 2 : Text |
||
1429 | jmachado | 437 | // # 3 : FromEmail Adultered in message |
438 | // # 4 : URL todo with certificate |
||
1425 | jmachado | 439 | List<String> arguments = new ArrayList<String>(); |
440 | arguments.add(from); |
||
441 | arguments.add(subject); |
||
442 | arguments.add(text); |
||
443 | arguments.add(fromEmail); |
||
444 | |||
445 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
446 | |||
447 | template = Globals.EMAIL_MESSAGE_IPP_TEMPLATE_PT; |
||
448 | |||
449 | |||
450 | List<String> recipients = new ArrayList<String>(); |
||
451 | for(1.5.0/docs/api/java/lang/String.html">String e: emails) |
||
452 | { |
||
453 | if(Email.validEmail(e)) |
||
454 | recipients.add(e); |
||
455 | } |
||
1426 | jmachado | 456 | |
1425 | jmachado | 457 | logger.info("subject: " + subject); |
458 | if(fromEmail == null) |
||
459 | logger.info("user: " + user.getEmail()); |
||
460 | else |
||
461 | logger.info("user altered to: " + fromEmail); |
||
462 | logger.info("template: " + template); |
||
463 | logger.info("arguments:"); |
||
464 | for(1.5.0/docs/api/java/lang/String.html">String arg: arguments) |
||
465 | logger.info(arg); |
||
466 | logger.info("recipients:"); |
||
467 | for(1.5.0/docs/api/java/lang/String.html">String rec: recipients) |
||
468 | logger.info(rec); |
||
469 | logger.info("arguments end"); |
||
470 | fromEmail = fromEmail == null ? user.getEmail() : fromEmail; |
||
1429 | jmachado | 471 | Email email = new Email(subject ,recipients,fromEmail,template,arguments,Message.RecipientType.TO); |
1425 | jmachado | 472 | email.setFromName(from + " (PAE-IPP)"); |
473 | return email; |
||
474 | } |
||
475 | |||
1585 | jmachado | 476 | |
477 | /** |
||
478 | * PRIMARY ENTRY SERVICE |
||
479 | * |
||
480 | * Create an EMAIL TO SEND IN NAME OF PAE WITH A TEMPLATE READY FOR CERTIFICATE AND USER TARGETING |
||
481 | * @param fromEmail |
||
482 | * @param from |
||
483 | * @param subject |
||
484 | * @param text |
||
485 | * @param user only used to get email from if not defined |
||
486 | * @param userIds |
||
487 | * @param url |
||
488 | * @return |
||
489 | */ |
||
490 | |||
1429 | jmachado | 491 | public EmailPersonalizedCertificated getMessageEmailAdulteredFromEmailIppCertificated( |
492 | 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, |
||
493 | List<Long> userIds, |
||
494 | 1.5.0/docs/api/java/lang/String.html">String url |
||
495 | ) |
||
496 | { |
||
497 | // # 0 : From |
||
498 | // # 1 : Subject |
||
499 | // # 2 : Text |
||
500 | // # 3 : FromEmail Adultered in message |
||
501 | // # 4 : URL todo with certificate |
||
502 | List<String> arguments = new ArrayList<String>(); |
||
503 | arguments.add(from); |
||
504 | arguments.add(subject); |
||
505 | arguments.add(text); |
||
506 | arguments.add(fromEmail); |
||
1426 | jmachado | 507 | |
1429 | jmachado | 508 | 1.5.0/docs/api/java/lang/String.html">String template; |
1426 | jmachado | 509 | |
1429 | jmachado | 510 | template = Globals.EMAIL_MESSAGE_IPP_TEMPLATE_PT_CERTIFICATED; |
511 | |||
512 | |||
513 | logger.info("Preparing batch work for Personalized Emails Certificated"); |
||
514 | logger.info("subject: " + subject); |
||
515 | if(fromEmail == null) |
||
516 | logger.info("user: " + user.getEmail()); |
||
517 | else |
||
518 | logger.info("user altered to: " + fromEmail); |
||
519 | logger.info("template: " + template); |
||
520 | logger.info("arguments:"); |
||
521 | for(1.5.0/docs/api/java/lang/String.html">String arg: arguments) |
||
522 | logger.info(arg); |
||
523 | logger.info("userIds:" + userIds); |
||
524 | logger.info("arguments end"); |
||
525 | fromEmail = fromEmail == null ? user.getEmail() : fromEmail; |
||
526 | EmailPersonalizedCertificated email = new EmailPersonalizedCertificated(subject ,fromEmail,template,arguments, |
||
527 | url, |
||
528 | userIds); |
||
529 | email.setFromName(from + " (PAE-IPP)"); |
||
530 | |||
531 | return email; |
||
532 | } |
||
533 | |||
534 | |||
535 | |||
1089 | jmachado | 536 | 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) |
537 | { |
||
538 | // # 0 : From |
||
539 | // # 1 : Subject |
||
540 | // # 2 : Text |
||
541 | // # 3 : person |
||
542 | // # 4 : target |
||
543 | List<String> arguments = new ArrayList<String>(); |
||
544 | arguments.add(from); |
||
545 | arguments.add(subject); |
||
546 | arguments.add(text); |
||
547 | arguments.add(user.getName()); |
||
548 | arguments.add(target); |
||
549 | |||
550 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
551 | |||
552 | if(langEnum == LangEnum.PORTUGUESE) |
||
553 | { |
||
554 | template = Globals.EMAIL_MESSAGE_TEMPLATE_PT; |
||
555 | } |
||
556 | else |
||
557 | { |
||
558 | template = Globals.EMAIL_MESSAGE_TEMPLATE_EN; |
||
559 | } |
||
560 | |||
561 | List<String> recipients = new ArrayList<String>(); |
||
512 | jmachado | 562 | for(User u: users) |
563 | { |
||
564 | if(Email.validEmail(u.getEmail())) |
||
565 | recipients.add(u.getEmail()); |
||
566 | if(Email.validEmail(u.getOutEmail())) |
||
567 | recipients.add(u.getOutEmail()); |
||
568 | } |
||
810 | jmachado | 569 | logger.info("subject: " + subject); |
570 | logger.info("user: " + user.getEmail()); |
||
571 | logger.info("template: " + template); |
||
572 | logger.info("arguments:"); |
||
573 | for(1.5.0/docs/api/java/lang/String.html">String arg: arguments) |
||
574 | logger.info(arg); |
||
575 | logger.info("recipients:"); |
||
576 | for(1.5.0/docs/api/java/lang/String.html">String rec: recipients) |
||
577 | logger.info(rec); |
||
578 | logger.info("arguments end"); |
||
872 | jmachado | 579 | Email email = new Email(subject ,recipients,user.getEmail(),template,arguments,Message.RecipientType.BCC); |
580 | email.setFromName(from + " (ESTG)"); |
||
581 | return email; |
||
512 | jmachado | 582 | } |
583 | |||
237 | jmachado | 584 | public Email getCourseUnitAnnouncementEmail(CourseUnitAnnouncement announcement, LangEnum langEnum, 1.5.0/docs/api/java/lang/String.html">String from, List<User> users) |
585 | { |
||
586 | List<String> arguments = new ArrayList<String>(); |
||
587 | arguments.add(announcement.getCourseUnit().getName()); |
||
588 | arguments.add(announcement.getTitle()); |
||
589 | arguments.add(announcement.getText()); |
||
590 | arguments.add(from); |
||
591 | |||
592 | 1.5.0/docs/api/java/lang/String.html">String subjectTxt; |
||
593 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
594 | |||
595 | if(langEnum == LangEnum.PORTUGUESE) |
||
596 | { |
||
597 | template = Globals.EMAIL_COURSEUNIT_ANNOUNCEMENT_TEMPLATE_PT; |
||
598 | subjectTxt = Globals.EMAIL_COURSEUNIT_ANNOUNCEMENT_SUBJECT_PT; |
||
599 | } |
||
600 | else |
||
601 | { |
||
602 | template = Globals.EMAIL_COURSEUNIT_ANNOUNCEMENT_TEMPLATE_EN; |
||
603 | subjectTxt = Globals.EMAIL_COURSEUNIT_ANNOUNCEMENT_SUBJECT_EN; |
||
604 | } |
||
605 | |||
606 | List<String> recipients = new ArrayList<String>(); |
||
607 | for(User u: users) |
||
608 | { |
||
298 | jmachado | 609 | if(Email.validEmail(u.getEmail())) |
610 | recipients.add(u.getEmail()); |
||
419 | jmachado | 611 | if(Email.validEmail(u.getOutEmail())) |
612 | recipients.add(u.getOutEmail()); |
||
237 | jmachado | 613 | } |
614 | |||
615 | 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 | 616 | 1.5.0/docs/api/java/lang/String.html">String fromEmail = Globals.SYSTEM_EMAIL_BOX; |
617 | if(announcement.getOwner() != null && Email.validEmail(announcement.getOwner().getEmail())) |
||
618 | fromEmail = announcement.getOwner().getEmail(); |
||
619 | return new Email(subject ,recipients,fromEmail,template,arguments,Message.RecipientType.BCC); |
||
237 | jmachado | 620 | } |
621 | |||
363 | jmachado | 622 | public Email getCourseUnitBlogPostEmail(BlogPost post, LangEnum langEnum, 1.5.0/docs/api/java/lang/String.html">String from, List<User> users) |
623 | { |
||
624 | List<String> arguments = new ArrayList<String>(); |
||
625 | arguments.add(((CourseUnitBlog)post.getBlog()).getCourseUnit().getName()); |
||
626 | arguments.add(post.getTitle()); |
||
627 | arguments.add(post.getText()); |
||
628 | arguments.add(from); |
||
237 | jmachado | 629 | |
363 | jmachado | 630 | 1.5.0/docs/api/java/lang/String.html">String subjectTxt; |
631 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
632 | |||
633 | if(langEnum == LangEnum.PORTUGUESE) |
||
634 | { |
||
635 | template = Globals.EMAIL_COURSEUNIT_BLOGPOST_TEMPLATE_PT; |
||
636 | subjectTxt = Globals.EMAIL_COURSEUNIT_BLOGPOST_SUBJECT_PT; |
||
637 | } |
||
638 | else |
||
639 | { |
||
640 | template = Globals.EMAIL_COURSEUNIT_BLOGPOST_TEMPLATE_EN; |
||
641 | subjectTxt = Globals.EMAIL_COURSEUNIT_BLOGPOST_SUBJECT_EN; |
||
642 | } |
||
643 | |||
644 | List<String> recipients = new ArrayList<String>(); |
||
645 | for(User u: users) |
||
646 | { |
||
647 | if(Email.validEmail(u.getEmail())) |
||
648 | recipients.add(u.getEmail()); |
||
419 | jmachado | 649 | if(Email.validEmail(u.getOutEmail())) |
650 | recipients.add(u.getOutEmail()); |
||
363 | jmachado | 651 | } |
652 | |||
653 | 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 | 654 | 1.5.0/docs/api/java/lang/String.html">String fromEmail = Globals.SYSTEM_EMAIL_BOX; |
655 | if(post.getOwner() != null && Email.validEmail(post.getOwner().getEmail())) |
||
656 | fromEmail = post.getOwner().getEmail(); |
||
657 | return new Email(subject ,recipients, fromEmail, template,arguments,Message.RecipientType.BCC); |
||
363 | jmachado | 658 | } |
659 | |||
440 | jmachado | 660 | public Email getCourseUnitWorkEmail(CourseUnitAssignement assignement, LangEnum langEnum, UserSession userSession, List<User> users, boolean newWork) |
419 | jmachado | 661 | { |
662 | List<String> arguments = new ArrayList<String>(); |
||
663 | arguments.add(assignement.getCourseUnit().getName()); |
||
664 | arguments.add(assignement.getTitle()); |
||
665 | arguments.add(assignement.getDescription()); |
||
440 | jmachado | 666 | |
419 | jmachado | 667 | if(userSession != null && userSession.getName() != null) |
668 | arguments.add(userSession.getName()); |
||
669 | else |
||
670 | arguments.add("unknown"); |
||
363 | jmachado | 671 | |
440 | jmachado | 672 | arguments.add( DatesUtils.getStringFromDate(assignement.getDeliverDate())); |
492 | jmachado | 673 | |
1353 | jmachado | 674 | //String directUrl = Globals.EMAIL_COURSEUNIT_WORK_RELATIVE_URL; |
675 | //directUrl = Globals.SITE_URL + MessageFormat.format(directUrl,assignement.getCourseUnit().getId()); |
||
676 | |||
419 | jmachado | 677 | 1.5.0/docs/api/java/lang/String.html">String subjectTxt; |
678 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
679 | |||
680 | if(langEnum == LangEnum.PORTUGUESE) |
||
681 | { |
||
440 | jmachado | 682 | if(newWork) |
683 | template = Globals.EMAIL_COURSEUNIT_WORK_TEMPLATE_PT; |
||
684 | else |
||
685 | template = Globals.EMAIL_COURSEUNIT_WORK_CHANGE_TEMPLATE_PT; |
||
419 | jmachado | 686 | subjectTxt = Globals.EMAIL_COURSEUNIT_WORK_SUBJECT_PT; |
687 | } |
||
688 | else |
||
689 | { |
||
440 | jmachado | 690 | if(newWork) |
691 | template = Globals.EMAIL_COURSEUNIT_WORK_TEMPLATE_EN; |
||
692 | else |
||
693 | template = Globals.EMAIL_COURSEUNIT_WORK_CHANGE_TEMPLATE_EN; |
||
419 | jmachado | 694 | subjectTxt = Globals.EMAIL_COURSEUNIT_WORK_SUBJECT_EN; |
695 | } |
||
696 | |||
697 | List<String> recipients = new ArrayList<String>(); |
||
698 | for(User u: users) |
||
699 | { |
||
700 | if(Email.validEmail(u.getEmail())) |
||
701 | recipients.add(u.getEmail()); |
||
702 | if(Email.validEmail(u.getOutEmail())) |
||
703 | recipients.add(u.getOutEmail()); |
||
704 | } |
||
705 | |||
706 | 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()}); |
||
707 | |||
708 | 1.5.0/docs/api/java/lang/String.html">String fromEmail = Globals.SYSTEM_EMAIL_BOX; |
||
709 | if(userSession!= null && userSession.getUser() != null && Email.validEmail(userSession.getUser().getEmail())) |
||
710 | fromEmail = userSession.getUser().getEmail(); |
||
711 | return new Email(subject ,recipients,fromEmail,template,arguments,Message.RecipientType.BCC); |
||
712 | } |
||
713 | |||
714 | |||
715 | |||
236 | jmachado | 716 | 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) |
717 | { |
||
718 | List<String> arguments = new ArrayList<String>(); |
||
719 | |||
720 | 1.5.0/docs/api/java/lang/String.html">String subject; |
||
721 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
722 | |||
723 | if(langEnum == LangEnum.PORTUGUESE) |
||
724 | { |
||
725 | template = Globals.EMAIL_NEW_GRADES_TEMPLATE_PT; |
||
237 | jmachado | 726 | subject = Globals.EMAIL_NEW_GRADES_SUBJECT_PT; |
236 | jmachado | 727 | } |
728 | else |
||
729 | { |
||
730 | template = Globals.EMAIL_NEW_GRADES_TEMPLATE_EN; |
||
237 | jmachado | 731 | subject = Globals.EMAIL_NEW_GRADES_SUBJECT_EN; |
236 | jmachado | 732 | } |
733 | |||
734 | 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder gradesBuilder = new 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder(); |
||
735 | for(1.5.0/docs/api/java/lang/String.html">String[] grade: grades) |
||
736 | { |
||
737 | 1.5.0/docs/api/java/lang/String.html">String gradeTxt = TemplateUtils.formatMessageTemplate(gradeUnitTemplate,grade); |
||
738 | gradesBuilder.append(gradeTxt); |
||
739 | } |
||
740 | |||
741 | arguments.add(studentName); |
||
742 | arguments.add(gradesBuilder.toString()); |
||
743 | |||
744 | List<String> recipients = new ArrayList<String>(); |
||
745 | recipients.add(studentEmail); |
||
746 | return new Email(subject ,recipients, Globals.SYSTEM_EMAIL_BOX,template,arguments); |
||
747 | } |
||
748 | |||
358 | jmachado | 749 | public Email getSummaryEmail(List<String> emails, CourseUnitSummary cUS, CourseUnit c, LangEnum langEnum) |
750 | { |
||
751 | List<String> arguments = new ArrayList<String>(); |
||
752 | |||
753 | 1.5.0/docs/api/java/lang/String.html">String data = DatesUtils.getStringFromDate(cUS.getDataAula()); |
||
754 | 1.5.0/docs/api/java/lang/String.html">String subject; |
||
755 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
756 | |||
757 | if(langEnum == LangEnum.PORTUGUESE) |
||
758 | { |
||
759 | template = Globals.EMAIL_SUMMARY_TEMPLATE_PT; |
||
760 | subject = Globals.EMAIL_SUMMARY_SUBJECT_PT; |
||
761 | } |
||
762 | else |
||
763 | { |
||
764 | template = Globals.EMAIL_SUMMARY_TEMPLATE_EN; |
||
765 | subject = Globals.EMAIL_SUMMARY_SUBJECT_EN; |
||
766 | } |
||
767 | subject = TemplateUtils.formatMessageTemplate(subject,new 1.5.0/docs/api/java/lang/String.html">String[]{c.getName()}); |
||
768 | |||
769 | arguments.add(c.getName()); |
||
770 | arguments.add(""+cUS.getNumeroAula()); |
||
771 | arguments.add(data); |
||
772 | arguments.add(cUS.getTitulo()); |
||
773 | arguments.add(cUS.getDescricao()); |
||
774 | |||
775 | List<String> recipients = new ArrayList<String>(); |
||
776 | for(1.5.0/docs/api/java/lang/String.html">String email:emails) |
||
777 | recipients.add(email); |
||
778 | return new Email(subject ,recipients, Globals.SYSTEM_EMAIL_BOX,template,arguments); |
||
779 | } |
||
780 | |||
995 | jmachado | 781 | |
782 | //TODO TESTAR |
||
783 | public Email getSummariesEmail(List<String> emails, List<CourseUnitSummary> cUS, CourseUnit c, LangEnum langEnum) |
||
784 | { |
||
785 | |||
786 | |||
787 | 1.5.0/docs/api/java/lang/String.html">String ultimaData = DatesUtils.getStringFromDate(cUS.get(cUS.size() - 1).getDataAula()); |
||
788 | 1.5.0/docs/api/java/lang/String.html">String subject; |
||
789 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
790 | 1.5.0/docs/api/java/lang/String.html">String templateFragment; |
||
791 | |||
792 | if(langEnum == LangEnum.PORTUGUESE) |
||
793 | { |
||
794 | template = Globals.EMAIL_SUMMARIES_TEMPLATE_PT; |
||
795 | templateFragment = Globals.EMAIL_SUMMARIES_FRAGMENT_TEMPLATE_PT; |
||
796 | subject = Globals.EMAIL_SUMMARY_SUBJECT_PT; |
||
797 | } |
||
798 | else |
||
799 | { |
||
800 | template = Globals.EMAIL_SUMMARIES_TEMPLATE_EN; |
||
801 | templateFragment = Globals.EMAIL_SUMMARIES_FRAGMENT_TEMPLATE_EN; |
||
802 | subject = Globals.EMAIL_SUMMARY_SUBJECT_EN; |
||
803 | } |
||
804 | subject = TemplateUtils.formatMessageTemplate(subject,new 1.5.0/docs/api/java/lang/String.html">String[]{c.getName()}); |
||
805 | |||
806 | 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder fragments = new 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder(); |
||
807 | |||
808 | List<String> arguments = new ArrayList<String>(); |
||
809 | 1.5.0/docs/api/java/lang/String.html">String fragmentSummaryTemplate = TemplateUtils.getOrLoadTemplate(Globals.TEMPLATE_EMAIL_PATH + "/" + templateFragment); |
||
810 | for(CourseUnitSummary summary: cUS) |
||
811 | { |
||
812 | List<String> argumentsFrag = new ArrayList<String>(); |
||
813 | argumentsFrag.add(summary.getTitulo()); |
||
814 | argumentsFrag.add(DatesUtils.getStringFromDate(summary.getDataAula())); |
||
815 | argumentsFrag.add(summary.getDescricao()); |
||
816 | 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()); |
||
817 | fragments.append("\n").append(fullMessage); |
||
818 | } |
||
819 | |||
820 | arguments.add(c.getName()); |
||
821 | arguments.add(ultimaData); |
||
822 | arguments.add(fragments.toString()); |
||
823 | |||
824 | List<String> recipients = new ArrayList<String>(); |
||
825 | for(1.5.0/docs/api/java/lang/String.html">String email:emails) |
||
826 | recipients.add(email); |
||
827 | return new Email(subject ,recipients, Globals.SYSTEM_EMAIL_BOX,template,arguments); |
||
828 | } |
||
829 | |||
751 | jmachado | 830 | public Email getUnidadeEdicaoEmail(List<String> emails, CourseUnit c, LangEnum langEnum) |
831 | { |
||
832 | List<String> arguments = new ArrayList<String>(); |
||
833 | |||
834 | |||
835 | 1.5.0/docs/api/java/lang/String.html">String subject; |
||
836 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
837 | |||
838 | if(langEnum == LangEnum.PORTUGUESE) |
||
839 | { |
||
840 | template = Globals.EMAIL_UNDADE_EDICAO_TEMPLATE_PT; |
||
841 | subject = Globals.EMAIL_UNDADE_EDICAO_SUBJECT_PT; |
||
842 | } |
||
843 | else |
||
844 | { |
||
845 | template = Globals.EMAIL_UNDADE_EDICAO_TEMPLATE_EN; |
||
846 | subject = Globals.EMAIL_UNDADE_EDICAO_SUBJECT_EN; |
||
847 | } |
||
848 | 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()}); |
||
849 | |||
850 | arguments.add(c.getName()); |
||
851 | |||
852 | List<String> recipients = new ArrayList<String>(); |
||
853 | for(1.5.0/docs/api/java/lang/String.html">String email:emails) |
||
854 | recipients.add(email); |
||
855 | return new Email(subject ,recipients, Globals.SYSTEM_EMAIL_BOX,template,arguments); |
||
856 | } |
||
857 | |||
858 | public Email getUnidadeValidadaEmail(List<String> emails, CourseUnit c, LangEnum langEnum) |
||
859 | { |
||
860 | List<String> arguments = new ArrayList<String>(); |
||
861 | |||
862 | |||
863 | 1.5.0/docs/api/java/lang/String.html">String subject; |
||
864 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
865 | |||
866 | if(langEnum == LangEnum.PORTUGUESE) |
||
867 | { |
||
868 | template = Globals.EMAIL_UNDADE_VALIDADA_TEMPLATE_PT; |
||
869 | subject = Globals.EMAIL_UNDADE_VALIDADA_SUBJECT_PT; |
||
870 | } |
||
871 | else |
||
872 | { |
||
873 | template = Globals.EMAIL_UNDADE_VALIDADA_TEMPLATE_EN; |
||
874 | subject = Globals.EMAIL_UNDADE_VALIDADA_SUBJECT_EN; |
||
875 | } |
||
876 | 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()}); |
||
877 | |||
878 | arguments.add(c.getName()); |
||
879 | |||
880 | List<String> recipients = new ArrayList<String>(); |
||
881 | for(1.5.0/docs/api/java/lang/String.html">String email:emails) |
||
882 | recipients.add(email); |
||
883 | return new Email(subject ,recipients, Globals.SYSTEM_EMAIL_BOX,template,arguments); |
||
884 | } |
||
885 | |||
886 | public Email getUnidadeEditadaEmail(List<String> emails, CourseUnit c, LangEnum langEnum) |
||
887 | { |
||
888 | List<String> arguments = new ArrayList<String>(); |
||
889 | |||
890 | |||
891 | 1.5.0/docs/api/java/lang/String.html">String subject; |
||
892 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
893 | |||
894 | if(langEnum == LangEnum.PORTUGUESE) |
||
895 | { |
||
896 | template = Globals.EMAIL_UNDADE_EDITADA_TEMPLATE_PT; |
||
897 | subject = Globals.EMAIL_UNDADE_EDITADA_SUBJECT_PT; |
||
898 | } |
||
899 | else |
||
900 | { |
||
901 | template = Globals.EMAIL_UNDADE_EDITADA_TEMPLATE_EN; |
||
902 | subject = Globals.EMAIL_UNDADE_EDITADA_SUBJECT_EN; |
||
903 | } |
||
904 | 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()}); |
||
905 | |||
906 | arguments.add(c.getCourseName()); |
||
907 | arguments.add(c.getName()); |
||
908 | |||
909 | List<String> recipients = new ArrayList<String>(); |
||
910 | for(1.5.0/docs/api/java/lang/String.html">String email:emails) |
||
911 | recipients.add(email); |
||
912 | return new Email(subject ,recipients, Globals.SYSTEM_EMAIL_BOX,template,arguments); |
||
913 | } |
||
914 | |||
1033 | jmachado | 915 | public Email getRelatorioAvaliacaoUnidadeEditadaEmail(List<String> emails, CourseUnit c, LangEnum langEnum,1.5.0/docs/api/java/lang/String.html">String estado) |
916 | { |
||
917 | List<String> arguments = new ArrayList<String>(); |
||
918 | |||
919 | |||
920 | 1.5.0/docs/api/java/lang/String.html">String subject; |
||
921 | 1.5.0/docs/api/java/lang/String.html">String template; |
||
922 | |||
923 | if(langEnum == LangEnum.PORTUGUESE) |
||
924 | { |
||
925 | template = Globals.EMAIL_RELATORIO_AVALIACAO_UNDADE_EDITADA_TEMPLATE_PT; |
||
926 | subject = Globals.EMAIL_RELATORIO_AVALIACAO_UNDADE_EDITADA_SUBJECT_PT; |
||
927 | } |
||
928 | else |
||
929 | { |
||
930 | template = Globals.EMAIL_RELATORIO_AVALIACAO_UNDADE_EDITADA_TEMPLATE_EN; |
||
931 | subject = Globals.EMAIL_RELATORIO_AVALIACAO_UNDADE_EDITADA_SUBJECT_EN; |
||
932 | } |
||
933 | 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()}); |
||
934 | |||
935 | arguments.add(c.getCourseName()); |
||
936 | arguments.add(c.getName()); |
||
937 | arguments.add(estado); |
||
938 | |||
939 | List<String> recipients = new ArrayList<String>(); |
||
940 | for(1.5.0/docs/api/java/lang/String.html">String email:emails) |
||
941 | recipients.add(email); |
||
942 | return new Email(subject ,recipients, Globals.SYSTEM_EMAIL_BOX,template,arguments); |
||
943 | } |
||
944 | |||
236 | jmachado | 945 | 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) |
946 | { |
||
947 | try |
||
948 | { |
||
949 | sendEmail(getNewGradesEmail(grades,langEnum,studentEmail,studentName)); |
||
950 | return true; |
||
951 | } |
||
952 | catch (ServiceException e) |
||
953 | { |
||
954 | return false; |
||
955 | } |
||
956 | |||
957 | } |
||
958 | |||
959 | public static void main(1.5.0/docs/api/java/lang/String.html">String [] args) |
||
960 | { |
||
440 | jmachado | 961 | 1.5.0/docs/api/java/lang/System.html">System.out.println( DatesUtils.getStringFromDate(new 5+0%2Fdocs%2Fapi+Date">Date())); |
962 | // List<String[]> grades = new ArrayList<String[]>(); |
||
963 | // grades.add(new String[]{"Teste","3"}); |
||
964 | // grades.add(new String[]{"Teste2","4"}); |
||
965 | // new SendEmailService().sendNewGrades(grades,LangEnum.PORTUGUESE,"jmachado@estgp.pt","jorge Machado"); |
||
236 | jmachado | 966 | } |
967 | |||
29 | jmachado | 968 | } |