Revision 52897
Added by Argiro Kokogiannaki over 5 years ago
EmailController.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.uoaadmintools.controllers; |
2 | 2 |
|
3 |
import eu.dnetlib.uoaadmintools.dao.CommunityDAO; |
|
4 |
import eu.dnetlib.uoaadmintools.dao.NotificationsDAO; |
|
3 | 5 |
import eu.dnetlib.uoaadmintools.emailSender.EmailSender; |
6 |
import eu.dnetlib.uoaadmintools.entities.Email; |
|
7 |
import eu.dnetlib.uoaadmintools.entities.Notifications; |
|
8 |
import eu.dnetlib.uoaadmintools.handlers.NotFoundException; |
|
4 | 9 |
import org.apache.log4j.Logger; |
5 | 10 |
import org.springframework.beans.factory.annotation.Autowired; |
6 | 11 |
import org.springframework.web.bind.annotation.*; |
7 | 12 |
|
13 |
import java.util.ArrayList; |
|
8 | 14 |
import java.util.List; |
9 | 15 |
|
10 | 16 |
@RestController |
... | ... | |
14 | 20 |
|
15 | 21 |
@Autowired |
16 | 22 |
private EmailSender emailSender; |
23 |
@Autowired |
|
24 |
private NotificationsDAO notificationsDAO; |
|
25 |
@Autowired |
|
26 |
private CommunityDAO communityDAO; |
|
27 |
//invitation // no check |
|
28 |
//welcome new manager - no check |
|
29 |
//notify about new manager - check manager option |
|
30 |
//notify about new subscribers - check manager option |
|
31 |
//notify for claims - check manager option --> claim API |
|
32 |
@RequestMapping(value = "/email", method = RequestMethod.POST) |
|
33 |
public Boolean sendEmail(@RequestBody Email email ) throws Exception { |
|
34 |
for(String userMail:email.getRecipients()){ |
|
35 |
ArrayList<String> sendTo = new ArrayList<>(); |
|
36 |
sendTo.add(userMail); |
|
37 |
emailSender.send(sendTo,email.getSubject(),email.getBody()); |
|
38 |
} |
|
17 | 39 |
|
18 |
@RequestMapping(value = "/invite", method = RequestMethod.POST) |
|
19 |
public Boolean inviteReciptients(@RequestBody List<String> reciptients) throws Exception { |
|
20 |
emailSender.send(reciptients); |
|
21 | 40 |
return true; |
22 | 41 |
} |
42 |
|
|
43 |
@RequestMapping(value = "/notifyNewManagers/{pid}", method = RequestMethod.POST) |
|
44 |
public Boolean notifyNewManagers(@PathVariable(value = "pid") String pid,@RequestBody Email email ) throws Exception { |
|
45 |
List<String> notifyrecipients = new ArrayList<String>(); |
|
46 |
if(communityDAO.findByPid(pid) == null){ |
|
47 |
throw new NotFoundException("Community not found"); |
|
48 |
} |
|
49 |
for(String user:email.getRecipients()){ |
|
50 |
Notifications userNotifications = notificationsDAO.findByManagerEmailAndCommunityPid(user,pid); |
|
51 |
|
|
52 |
if(userNotifications == null || userNotifications.getNotifyForNewManagers()){ |
|
53 |
notifyrecipients.add(user); |
|
54 |
} |
|
55 |
} |
|
56 |
if(notifyrecipients.size() > 0){ |
|
57 |
emailSender.send(notifyrecipients,email.getSubject(),email.getBody()); |
|
58 |
}else{ |
|
59 |
log.debug("There are no users to notify "); |
|
60 |
} |
|
61 |
|
|
62 |
return true; |
|
63 |
} |
|
64 |
@RequestMapping(value = "/notifyNewSubscribers/{pid}", method = RequestMethod.POST) |
|
65 |
public Boolean notifyNewSubscribers(@PathVariable(value = "pid") String pid,@RequestBody Email email ) throws Exception { |
|
66 |
List<String> notifyrecipients = new ArrayList<String>(); |
|
67 |
if(communityDAO.findByPid(pid) == null){ |
|
68 |
throw new NotFoundException("Community not found"); |
|
69 |
} |
|
70 |
for(String user:email.getRecipients()){ |
|
71 |
Notifications userNotifications = notificationsDAO.findByManagerEmailAndCommunityPid(user,pid); |
|
72 |
|
|
73 |
if(userNotifications == null || userNotifications.getNotifyForNewSubscribers()){ |
|
74 |
notifyrecipients.add(user); |
|
75 |
} |
|
76 |
} |
|
77 |
if(notifyrecipients.size() > 0){ |
|
78 |
emailSender.send(notifyrecipients,email.getSubject(),email.getBody()); |
|
79 |
}else{ |
|
80 |
log.debug("There are no users to notify "); |
|
81 |
} |
|
82 |
|
|
83 |
return true; |
|
84 |
} |
|
85 |
|
|
23 | 86 |
} |
Also available in: Unified diff
add deployments info file
remove content page from init script
update names of communities
update html for pages with htmlPageContent
Subscribers: don't subscribe again if already subscribed
Notifications: add entity, DAO, controller
Add Email entity
Change emailSender to be more generic