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