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