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