[Trunk | Admin Tools]:
1. CuratorResponse.java: Remove "email" field. 2. EmailController.java: a.Replace methods "notifyNewManagers()" (/notifyForNewManagers/{pid}) and "notifyForNewSubscribers()" (/notifyForNewSuscribers/{pid}) with "notifyManagers()" (/notifyManagers/{pid}/{newRoleType}), where newRoleType is "manager" or "subscriber". b. Method notifyManagers() finds manager emails by calling registry service - stop getting them from portals inside Email object.
This commit is contained in:
parent
946c099fee
commit
ac370aa055
|
@ -1,13 +1,16 @@
|
||||||
package eu.dnetlib.uoaadmintools.controllers;
|
package eu.dnetlib.uoaadmintools.controllers;
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintools.dao.NotificationsDAO;
|
import eu.dnetlib.uoaadmintools.dao.NotificationsDAO;
|
||||||
|
import eu.dnetlib.uoaadmintools.entities.Manager;
|
||||||
import eu.dnetlib.uoaadmintools.entities.Notifications;
|
import eu.dnetlib.uoaadmintools.entities.Notifications;
|
||||||
|
import eu.dnetlib.uoaadmintools.services.ManagerService;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.dao.PortalDAO;
|
import eu.dnetlib.uoaadmintoolslibrary.dao.PortalDAO;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.emailSender.EmailSender;
|
import eu.dnetlib.uoaadmintoolslibrary.emailSender.EmailSender;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.entities.email.Email;
|
import eu.dnetlib.uoaadmintoolslibrary.entities.email.Email;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.entities.email.EmailRecaptcha;
|
import eu.dnetlib.uoaadmintoolslibrary.entities.email.EmailRecaptcha;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
|
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.InvalidReCaptchaException;
|
import eu.dnetlib.uoaadmintoolslibrary.handlers.InvalidReCaptchaException;
|
||||||
|
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.recaptcha.VerifyRecaptcha;
|
import eu.dnetlib.uoaadmintoolslibrary.recaptcha.VerifyRecaptcha;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -28,6 +31,10 @@ public class EmailController {
|
||||||
private PortalDAO portalDAO;
|
private PortalDAO portalDAO;
|
||||||
@Autowired
|
@Autowired
|
||||||
private VerifyRecaptcha verifyRecaptcha;
|
private VerifyRecaptcha verifyRecaptcha;
|
||||||
|
@Autowired
|
||||||
|
private ManagerService managerService;
|
||||||
|
@Autowired
|
||||||
|
private RolesUtils rolesUtils;
|
||||||
|
|
||||||
@RequestMapping(value = "/contact", method = RequestMethod.POST)
|
@RequestMapping(value = "/contact", method = RequestMethod.POST)
|
||||||
public Boolean contact(@RequestBody EmailRecaptcha form) throws InvalidReCaptchaException {
|
public Boolean contact(@RequestBody EmailRecaptcha form) throws InvalidReCaptchaException {
|
||||||
|
@ -66,41 +73,38 @@ public class EmailController {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/notifyForNewManagers/{pid}", method = RequestMethod.POST)
|
@RequestMapping(value = "/notifyManagers/{pid}/{newRoleType}", method = RequestMethod.POST)
|
||||||
public Boolean notifyNewManagers(@PathVariable(value = "pid") String pid,@RequestBody Email email ) throws Exception {
|
public Boolean notifyManagers(@PathVariable(value = "pid") String pid,
|
||||||
|
@PathVariable(value = "newRoleType") String newRoleType,
|
||||||
|
@RequestBody Email email ) throws Exception {
|
||||||
List<String> notifyrecipients = new ArrayList<String>();
|
List<String> notifyrecipients = new ArrayList<String>();
|
||||||
if(portalDAO.findByPid(pid) == null){
|
if(portalDAO.findByPid(pid) == null){
|
||||||
throw new ContentNotFoundException("Portal not found");
|
throw new ContentNotFoundException("Portal not found");
|
||||||
}
|
}
|
||||||
for(String user:email.getRecipients()){
|
|
||||||
Notifications userNotifications = notificationsDAO.findByManagerEmailAndPortalPid(user,pid);
|
|
||||||
|
|
||||||
if(userNotifications == null || userNotifications.getNotifyForNewManagers()){
|
Manager[] managers = managerService.getManagers(pid);
|
||||||
notifyrecipients.add(user);
|
List<String> emails = new ArrayList();
|
||||||
}
|
|
||||||
}
|
for(Manager manager:managers){
|
||||||
if(notifyrecipients.size() > 0){
|
String userEmail = manager.getEmail();
|
||||||
return emailSender.send(notifyrecipients,email.getSubject(),email.getBody(), false);
|
emails.add(userEmail);
|
||||||
}else{
|
|
||||||
log.debug("There are no users to notify ");
|
// Do not send the notification to the new manager/ subscriber.
|
||||||
}
|
if(userEmail.equals(rolesUtils.getEmail())) {
|
||||||
|
continue;
|
||||||
return true;
|
}
|
||||||
}
|
|
||||||
@RequestMapping(value = "/notifyForNewSubscribers/{pid}", method = RequestMethod.POST)
|
Notifications userNotifications = notificationsDAO.findByManagerEmailAndPortalPid(userEmail,pid);
|
||||||
public Boolean notifyNewSubscribers(@PathVariable(value = "pid") String pid,@RequestBody Email email ) throws Exception {
|
|
||||||
List<String> notifyrecipients = new ArrayList<String>();
|
if(userNotifications == null
|
||||||
if(portalDAO.findByPid(pid) == null){
|
|| (newRoleType.equals("manager") && userNotifications.getNotifyForNewManagers())
|
||||||
throw new ContentNotFoundException("Portal not found");
|
|| (newRoleType.equals("subscriber") && userNotifications.getNotifyForNewSubscribers())){
|
||||||
}
|
notifyrecipients.add(userEmail);
|
||||||
for(String user:email.getRecipients()){
|
|
||||||
Notifications userNotifications = notificationsDAO.findByManagerEmailAndPortalPid(user,pid);
|
|
||||||
|
|
||||||
if(userNotifications == null || userNotifications.getNotifyForNewSubscribers()){
|
|
||||||
notifyrecipients.add(user);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(notifyrecipients.size() > 0){
|
if(notifyrecipients.size() > 0){
|
||||||
|
email.setBody(email.getBody().replace("((__managers__))", String.join(", ", emails)));
|
||||||
|
|
||||||
return emailSender.send(notifyrecipients,email.getSubject(),email.getBody(), false);
|
return emailSender.send(notifyrecipients,email.getSubject(),email.getBody(), false);
|
||||||
}else{
|
}else{
|
||||||
log.debug("There are no users to notify ");
|
log.debug("There are no users to notify ");
|
||||||
|
@ -108,6 +112,27 @@ public class EmailController {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
// @RequestMapping(value = "/notifyForNewSubscribers/{pid}", method = RequestMethod.POST)
|
||||||
|
// public Boolean notifyNewSubscribers(@PathVariable(value = "pid") String pid,@RequestBody Email email ) throws Exception {
|
||||||
|
// List<String> notifyrecipients = new ArrayList<String>();
|
||||||
|
// if(portalDAO.findByPid(pid) == null){
|
||||||
|
// throw new ContentNotFoundException("Portal not found");
|
||||||
|
// }
|
||||||
|
// for(String user:email.getRecipients()){
|
||||||
|
// Notifications userNotifications = notificationsDAO.findByManagerEmailAndPortalPid(user,pid);
|
||||||
|
//
|
||||||
|
// if(userNotifications == null || userNotifications.getNotifyForNewSubscribers()){
|
||||||
|
// notifyrecipients.add(user);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if(notifyrecipients.size() > 0){
|
||||||
|
// return emailSender.send(notifyrecipients,email.getSubject(),email.getBody(), false);
|
||||||
|
// }else{
|
||||||
|
// log.debug("There are no users to notify ");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
@RequestMapping(value = "/test", method = RequestMethod.GET)
|
@RequestMapping(value = "/test", method = RequestMethod.GET)
|
||||||
public String test() throws Exception {
|
public String test() throws Exception {
|
||||||
log.debug("Test mail");
|
log.debug("Test mail");
|
||||||
|
@ -121,11 +146,11 @@ public class EmailController {
|
||||||
email.setBody("Test body");
|
email.setBody("Test body");
|
||||||
email.setSubject("Test theme");
|
email.setSubject("Test theme");
|
||||||
String response = "";
|
String response = "";
|
||||||
response+=this.notifyNewManagers("ee", email);
|
response+=this.notifyManagers("ee", "manager", email);
|
||||||
log.debug("Notify managers "+response);
|
log.debug("Notify managers "+response);
|
||||||
|
|
||||||
response+=" ";
|
response+=" ";
|
||||||
response+=this.notifyNewSubscribers("ee", email);
|
response+=this.notifyManagers("ee", "subscriber", email);
|
||||||
log.debug("Notify for subscr "+response);
|
log.debug("Notify for subscr "+response);
|
||||||
return response;
|
return response;
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ import java.util.List;
|
||||||
|
|
||||||
public class CuratorResponse {
|
public class CuratorResponse {
|
||||||
|
|
||||||
private String email;
|
|
||||||
private String name;
|
private String name;
|
||||||
private List<Affiliation> affiliations;
|
private List<Affiliation> affiliations;
|
||||||
private String photo;
|
private String photo;
|
||||||
|
@ -16,21 +15,12 @@ public class CuratorResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
public CuratorResponse(Curator curator) {
|
public CuratorResponse(Curator curator) {
|
||||||
this.email = curator.getEmail();
|
|
||||||
this.name = curator.getName();
|
this.name = curator.getName();
|
||||||
this.affiliations = curator.getAffiliations();
|
this.affiliations = curator.getAffiliations();
|
||||||
this.photo = curator.getPhoto();
|
this.photo = curator.getPhoto();
|
||||||
this.bio = curator.getBio();
|
this.bio = curator.getBio();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEmail() {
|
|
||||||
return email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEmail(String email) {
|
|
||||||
this.email = email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue