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