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