Revision 58394
Added by Konstantina Galouni about 4 years ago
EmailController.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.uoaadmintools.controllers; |
2 | 2 |
|
3 |
import eu.dnetlib.uoaadmintools.dao.CommunityDAO; |
|
4 | 3 |
import eu.dnetlib.uoaadmintools.dao.NotificationsDAO; |
5 |
import eu.dnetlib.uoaadmintools.emailSender.EmailSender; |
|
6 |
import eu.dnetlib.uoaadmintools.entities.EmailRecaptcha; |
|
7 |
import eu.dnetlib.uoaadmintools.entities.Email; |
|
8 | 4 |
import eu.dnetlib.uoaadmintools.entities.Notifications; |
9 | 5 |
import eu.dnetlib.uoaadmintools.handlers.ContentNotFoundException; |
10 |
import eu.dnetlib.uoaadmintools.handlers.InvalidReCaptchaException; |
|
11 |
import eu.dnetlib.uoaadmintools.recaptcha.VerifyRecaptcha; |
|
6 |
import eu.dnetlib.uoaadmintoolslibrary.dao.PortalDAO; |
|
7 |
import eu.dnetlib.uoaadmintoolslibrary.emailSender.EmailSender; |
|
8 |
import eu.dnetlib.uoaadmintoolslibrary.entities.email.Email; |
|
9 |
import eu.dnetlib.uoaadmintoolslibrary.entities.email.EmailRecaptcha; |
|
10 |
import eu.dnetlib.uoaadmintoolslibrary.handlers.InvalidReCaptchaException; |
|
11 |
import eu.dnetlib.uoaadmintoolslibrary.recaptcha.VerifyRecaptcha; |
|
12 | 12 |
import org.apache.log4j.Logger; |
13 | 13 |
import org.springframework.beans.factory.annotation.Autowired; |
14 | 14 |
import org.springframework.web.bind.annotation.*; |
... | ... | |
25 | 25 |
@Autowired |
26 | 26 |
private NotificationsDAO notificationsDAO; |
27 | 27 |
@Autowired |
28 |
private CommunityDAO communityDAO;
|
|
28 |
private PortalDAO portalDAO;
|
|
29 | 29 |
@Autowired |
30 | 30 |
private VerifyRecaptcha verifyRecaptcha; |
31 | 31 |
|
32 | 32 |
@RequestMapping(value = "/contact", method = RequestMethod.POST) |
33 | 33 |
public Boolean contact(@RequestBody EmailRecaptcha form) throws InvalidReCaptchaException { |
34 |
verifyRecaptcha.processResponse(form.getRecaptcha()); |
|
34 |
if(form.getRecaptcha() != null) { |
|
35 |
verifyRecaptcha.processResponse(form.getRecaptcha()); |
|
36 |
} |
|
35 | 37 |
Email email = form.getEmail(); |
36 | 38 |
ArrayList<String> sendTo = new ArrayList<>(email.getRecipients()); |
37 | 39 |
return emailSender.send(sendTo, email.getSubject(), email.getBody(), false); |
... | ... | |
67 | 69 |
@RequestMapping(value = "/notifyForNewManagers/{pid}", method = RequestMethod.POST) |
68 | 70 |
public Boolean notifyNewManagers(@PathVariable(value = "pid") String pid,@RequestBody Email email ) throws Exception { |
69 | 71 |
List<String> notifyrecipients = new ArrayList<String>(); |
70 |
if(communityDAO.findByPid(pid) == null){
|
|
71 |
throw new ContentNotFoundException("Community not found");
|
|
72 |
if(portalDAO.findByPid(pid) == null){
|
|
73 |
throw new ContentNotFoundException("Portal not found");
|
|
72 | 74 |
} |
73 | 75 |
for(String user:email.getRecipients()){ |
74 |
Notifications userNotifications = notificationsDAO.findByManagerEmailAndCommunityPid(user,pid);
|
|
76 |
Notifications userNotifications = notificationsDAO.findByManagerEmailAndPortalPid(user,pid);
|
|
75 | 77 |
|
76 | 78 |
if(userNotifications == null || userNotifications.getNotifyForNewManagers()){ |
77 | 79 |
notifyrecipients.add(user); |
... | ... | |
88 | 90 |
@RequestMapping(value = "/notifyForNewSubscribers/{pid}", method = RequestMethod.POST) |
89 | 91 |
public Boolean notifyNewSubscribers(@PathVariable(value = "pid") String pid,@RequestBody Email email ) throws Exception { |
90 | 92 |
List<String> notifyrecipients = new ArrayList<String>(); |
91 |
if(communityDAO.findByPid(pid) == null){
|
|
92 |
throw new ContentNotFoundException("Community not found");
|
|
93 |
if(portalDAO.findByPid(pid) == null){
|
|
94 |
throw new ContentNotFoundException("Portal not found");
|
|
93 | 95 |
} |
94 | 96 |
for(String user:email.getRecipients()){ |
95 |
Notifications userNotifications = notificationsDAO.findByManagerEmailAndCommunityPid(user,pid);
|
|
97 |
Notifications userNotifications = notificationsDAO.findByManagerEmailAndPortalPid(user,pid);
|
|
96 | 98 |
|
97 | 99 |
if(userNotifications == null || userNotifications.getNotifyForNewSubscribers()){ |
98 | 100 |
notifyrecipients.add(user); |
Also available in: Unified diff
[use-UoaAdminToolsLibrary | Admin Tools Service]:
REMINDER NOTE: change war name and properties (e.g. in MongoConfig.java) when merging to trunk.
1. Move MongoDBDAOs to folder /dao/MongoDBDAOs.
2. Move entities for Subscriber to folder /entities/subscriber.
3. Move entities for Curator to folder /entities/curator.
4. Add services for Layout, Statistics and Subscribers (to be called by controllers).
5. Rename "CommunitySubscribers" to "PortalSubscribers", "CommunitySubscribersController" to "PortalSubscribersController" and "CommunitySubscribersDAO" to "PortalSubscribersDAO".
6. Update all files to import appropriate files (from library or locally).
7. Create "ConnectController", "ExploreController" and update "CommunityController".
8. UoaAdminToolsApplication.java: scanBasePackages = {"eu.dnetlib.uoaadmintools", "eu.dnetlib.uoaadmintoolslibrary"}
9. MongoConnection.java: basePackages = {"eu.dnetlib.uoaadmintools.dao", "eu.dnetlib.uoaadmintoolslibrary.dao"}
10. Update update_db.js for changing db collections and entries according to new schema.