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