Project

General

Profile

« Previous | Next » 

Revision 53916

1. pom.xml: Add commented plugin for surfire (possibly needed in openjdk: bug in their release) | update version of javax.mail.
2. FetchContextHandler.java: bug fix in parsing resultset.
3. QueryGenerator.java: bug fix in query of method 'generateSelectFirstContextByCommunityIdQuery'.
4. TestClass.java: Tests for sending email notifications added.
5. EmailScheduler.java: 'sendEmailNotifications' boolean variable added to control if email scheduler will run or not.
6. EmailSender.java: Fix subject and content of emails | bug fixes | bcc emails to Greece's test mail.
7. springContext-claimsDemo.properties: Add 'services.claims.mail.contactMail', 'services.claims.mail.openaireProjectClaimsPage',
'services.claims.mail.openaireCommunityClaimsPage', 'services.claims.mail.manageCommunityUserNotificationsPage' properties.
8. springContext-claimsDemo.xml: Add missing beans for 'EmailSender' and 'EmailScheduler' classes.

View differences:

EmailSender.java
36 36
    @Autowired
37 37
    private String defaultFrequencyInHours;
38 38

  
39
    private static String openaireClaimsPage;
39
    private static String manageCommunityUserNotificationsPage;
40
    private static String openaireProjectClaimsPage;
41
    private static String openaireCommunityClaimsPage;
40 42
    private static String username;
41 43
    private static String password;
42 44
    private static String host;
43 45
    private static String port;
44 46
    private static String from;
47
    private static String contactMail;
45 48
    private static String specialRecipients;
46 49

  
47 50
    @Override
......
96 99
                // specialRecipients are used currently for testing purposes
97 100
                List<String> tmpManagers = null;
98 101
                if (specialRecipients != null && !specialRecipients.isEmpty()) {
99
                    tmpManagers = Arrays.asList(specialRecipients.split("\\s*,\\s*"));
102
                    tmpManagers = new ArrayList<>(Arrays.asList(specialRecipients.split("\\s*,\\s*")));
100 103
                    logger.debug("Special recipients: " + specialRecipients);
104

  
105
                    if(tmpManagers != null) {
106
                        Iterator itr = tmpManagers.iterator();
107
                        while (itr.hasNext()) {
108
                            String manager = (String) itr.next();
109
                            Notification notification = null;
110
                            try {
111
                                notification = fetchNotificationHandler.fetchNotification(project.getOpenaireId(), manager);
112
                            } catch (Exception e) {
113
                                e.printStackTrace();
114
                            } catch (SQLStoreException e) {
115
                                e.printStackTrace();
116
                            }
117
                            if (notification != null) {
118
                                itr.remove();
119
                            }
120
                        }
121
                    }
122

  
101 123
                    managersOfProject.put(project.getOpenaireId(), tmpManagers);
102 124
                }
103 125

  
104
                /*
105 126
                // Send emails to actual project managers instead of special recipients
106 127
                List<String> managers = null;
107 128
                try {
108 129
                    managers = fetchProjectHandler.fetchContactEmailsByProjectId(project.getOpenaireId());
130
                    logger.debug("All actual Managers of project " + project.getOpenaireId() + ": "+managers);
131

  
109 132
                    if(managers != null) {
110 133
                        Iterator itr = managers.iterator();
111 134
                        while (itr.hasNext()) {
......
123 146
                    e.printStackTrace();
124 147
                }
125 148

  
126
                logger.debug("Managers of project " + project.getOpenaireId() + ": "+managers);
149
                logger.debug("Managers of project (not in notification table) " + project.getOpenaireId() + ": "+managers);
150
                /*
127 151
                managersOfProject.put(project.getOpenaireId(), managers);
128 152
                */
129 153

  
130 154
                if (managersOfProject.get(project.getOpenaireId()) != null &&
131 155
                        !managersOfProject.get(project.getOpenaireId()).isEmpty()) {
132
                    //send(project.getOpenaireId(), project.getName(), "project", managersOfProject.get(project.getOpenaireId()));
156
                    send(project.getOpenaireId(), project.getName(), "project", managersOfProject.get(project.getOpenaireId()));
133 157
                }
134 158
            }
135 159
        }
......
212 236

  
213 237
                if (managersOfCommunity.get(openaireId) != null &&
214 238
                        !managersOfCommunity.get(openaireId).isEmpty()) {
215
                    //send(openaireId, context.getTitle().split(">")[0], "community", managersOfCommunity.get(openaireId));
239
                    send(openaireId, context.getTitle().split(">")[0], "community", managersOfCommunity.get(openaireId));
216 240
                }
217 241
            }
218 242
        }
......
256 280

  
257 281
                                logger.debug("Sending email for project claims between " + last_interaction_date + " and " + dateTo + " to " + notification.getUserMail());
258 282

  
259
                                //send(project.getOpenaireId(), project.getName(), "project", managersByNotification);
283
                                send(project.getOpenaireId(), project.getName(), "project", managersByNotification);
260 284
                            }
261
                            /*Calendar cal = Calendar.getInstance();
262
                            cal.setTime(_dateTo);
263
                            cal.add(Calendar.SECOND, 1);
264
                            _dateTo = cal.getTime();*/
285

  
265 286
                            notificationHandler.updateNotificationLastInteractionDate(notification.getOpenaireId(), notification.getUserMail(), _dateTo);
266
                            //update last interaction date (db)
267 287
                        }
268 288
                    } else {
269 289
                        logger.debug("managers do not contain "+notification.getUserMail());
......
312 332
                        diff = diff / 1000;
313 333

  
314 334
                        if (diff >= (notification.getFrequency() * 3600)) {
315
                            if (fetchClaimHandler.fetchNumberOfClaimsByDateAndOpenaireId(last_interaction_date, dateTo, notification.getOpenaireId(), null, null, "", "source", true, types, false) > 0) {
335
                            if (fetchClaimHandler.fetchNumberOfClaimsByDateAndOpenaireId(last_interaction_date, dateTo, notification.getOpenaireId(), null, null, "", null, true, types, false) > 0) {
316 336
                                List<String> managersByNotification = new ArrayList<>();
317 337
                                managersByNotification.add(notification.getUserMail());
318 338

  
......
321 341

  
322 342
                                logger.debug("Sending email for community claims between " + last_interaction_date + " and " + dateTo + " to " + notification.getUserMail());
323 343

  
324
                                //send(context.getOpenaireId().split("::")[0], context.getTitle().split(">")[0], "community", managersByNotification);
344
                                send(context.getOpenaireId().split("::")[0], context.getTitle().split(">")[0], "community", managersByNotification);
325 345
                            }
326
                            /*Calendar cal = Calendar.getInstance();
327
                            cal.setTime(_dateTo);
328
                            cal.add(Calendar.SECOND, 1);
329
                            _dateTo = cal.getTime();*/
346

  
330 347
                            notificationHandler.updateNotificationLastInteractionDate(notification.getOpenaireId(), notification.getUserMail(), _dateTo);
331
                            //update last interaction date (db)
332 348
                        }
333 349
                    }
334 350
                }
......
340 356
        }
341 357
    }
342 358

  
343
    public void send(String openaire_id, String openaire_name, String type, /*String token,*/ List<String> managers) {
344
        final String openaireClaimsPageUrl = openaireClaimsPage + openaire_id;//token;
359
    public void send(String openaire_id, String openaire_name, String type, List<String> managers) {
360
        logger.debug("Sending email");
361
        String openaireClaimsPageUrl = "";
362
        String manageUserNotificationsPage = "";
363
        String messageContent = "";
364
        String subject = "";
345 365

  
366
        if(type.equals("project")) {
367
            openaireClaimsPageUrl = openaireProjectClaimsPage + openaire_id;
368

  
369
            subject = "[OpenAIRE] Links notification";
370
            messageContent = "There are new Claims for: '" + openaire_name +"' project for which you seem to be a contact person." +
371
                    "<br>Click <a href=\""+openaireClaimsPageUrl+"\">here</a> to curate these Claims.";
372
        } else if(type.equals("community")) {
373
            openaireClaimsPageUrl = openaireCommunityClaimsPage + openaire_id;
374
            manageUserNotificationsPage = manageCommunityUserNotificationsPage + openaire_id;
375

  
376
            subject = "[OpenAIRE-Connect] "+openaire_name+": Links notification";
377
            messageContent =
378
                    " <div style=\"font-size:14px;\">" +
379
                    "    <p>" +
380
                    "       There are new links for '"+openaire_name+"' community. Click  <a href=\""+openaireClaimsPageUrl+"\">here</a> to view the links.\n" +
381
                    "    </p>" +
382
                    "    <p>OpenAIRE team<br/>" +
383
                    "       <a href=\"https://www.openaire.eu\">www.openaire.eu</a>" +
384
                    "    </p>" +
385
                    "    <p style=\"font-size:11px;\">You are receiving this e-mail as manager of the community  <a href=\"https://beta."+openaire_id+".openaire.eu\">"+openaire_name+"</a>." +
386
                    "    If you are not responsible for this community, please <a href=\"mailto:"+contactMail+"\">contact us</a>." +
387
                    "    <br/>" +
388
                    "    Click  <a href=\""+manageUserNotificationsPage+"\">here</a> to manage your notification settings. </p>" +
389
                    "    </div>"
390
                    ;
391
        }
392

  
393
        //logger.debug(messageContent);
394

  
346 395
        // Get system properties
347 396
        Properties properties = System.getProperties();
348 397
        properties.setProperty("mail.smtp.host", host);
......
369 418
                logger.debug(to);
370 419
                message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
371 420
            }
421
            message.addRecipient(Message.RecipientType.BCC, new InternetAddress("openaire.test@gmail.com"));
372 422

  
373 423
            // Set Subject: header field
374
            message.setSubject("Openaire Claims Notification");
424
            message.setSubject(subject);
375 425

  
376 426
            // For simple text setText() can be used instead of setContent()
377 427

  
378 428
            // Send the actual HTML message, as big as you like
379
            message.setContent("There are new Claims for the "+type+": '" + openaire_name +"' for which you seem to be a contact person." +
380
                                        "<br>Click <a href=\""+openaireClaimsPageUrl+"\">here</a> to curate these Claims.", "text/html");
429
            message.setContent(messageContent, "text/html");
381 430

  
382 431
            // Send message
383 432
            Transport.send(message);
......
403 452
        this.fetchNotificationHandler = fetchNotificationHandler;
404 453
    }
405 454

  
455
    public void setNotificationHandler(NotificationHandler notificationHandler) {
456
        this.notificationHandler = notificationHandler;
457
    }
458

  
406 459
    public void setFetchContextHandler(FetchContextHandler fetchContextHandler) {
407 460
        this.fetchContextHandler = fetchContextHandler;
408 461
    }
409 462

  
410
    public static void setOpenaireClaimsPage(String openaireClaimsPage) {
411
        EmailSender.openaireClaimsPage = openaireClaimsPage;
463
    public static void setOpenaireProjectClaimsPage(String openaireProjectClaimsPage) {
464
        EmailSender.openaireProjectClaimsPage = openaireProjectClaimsPage;
412 465
    }
413 466

  
467
    public static void setOpenaireCommunityClaimsPage(String openaireCommunityClaimsPage) {
468
        EmailSender.openaireCommunityClaimsPage = openaireCommunityClaimsPage;
469
    }
470

  
471
    public static void setManageCommunityUserNotificationsPage(String manageCommunityUserNotificationsPage) {
472
        EmailSender.manageCommunityUserNotificationsPage = manageCommunityUserNotificationsPage;
473
    }
474

  
414 475
    public static void setUsername(String username) {
415 476
        EmailSender.username = username;
416 477
    }
......
431 492
        EmailSender.from = from;
432 493
    }
433 494

  
495
    public static void setContactMail(String contactMail) { EmailSender.contactMail = contactMail; }
496

  
434 497
    public static void setSpecialRecipients(String specialRecipients) {
435 498
        EmailSender.specialRecipients = specialRecipients;
436 499
    }
500

  
501
    public void setDefaultFrequencyInHours(String defaultFrequencyInHours) {
502
        this.defaultFrequencyInHours = defaultFrequencyInHours;
503
    }
437 504
}

Also available in: Unified diff