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