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