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