[Trunk | Admin tools]:
1. NotificationsService.java: [NEW] service for notifications with updatePid and deleteByPid methods. 2. LayoutService.java & StatisticsService.java & SubscriberService.java: Logs added. 3. CommunityController.java: a. [Bug fix] On "updateCommunity()" (/update) method update pid for related notifications, layout, statistics and subscribers (old_pid had the value of new_pid, not the old one). b. Add update pid for notifications when updating portal pid | Delete related notifications by pid when deleting a portal.
This commit is contained in:
parent
f3a33d9044
commit
5f2bc1fdfb
|
@ -2,6 +2,7 @@ package eu.dnetlib.uoaadmintools.controllers;
|
|||
|
||||
import eu.dnetlib.uoaadmintools.entities.Layout;
|
||||
import eu.dnetlib.uoaadmintools.services.LayoutService;
|
||||
import eu.dnetlib.uoaadmintools.services.NotificationsService;
|
||||
import eu.dnetlib.uoaadmintools.services.StatisticsService;
|
||||
import eu.dnetlib.uoaadmintools.services.SubscriberService;
|
||||
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
||||
|
@ -22,6 +23,9 @@ public class CommunityController {
|
|||
@Autowired
|
||||
private LayoutService layoutService;
|
||||
|
||||
@Autowired
|
||||
private NotificationsService notificationsService;
|
||||
|
||||
@Autowired
|
||||
private StatisticsService statisticsService;
|
||||
|
||||
|
@ -44,14 +48,17 @@ public class CommunityController {
|
|||
// @PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN)")
|
||||
@RequestMapping(value = "/update", method = RequestMethod.POST)
|
||||
public PortalResponse updateCommunity(@RequestBody Portal portal) {
|
||||
String old_pid = portalService.getPortalById(portal.getId()).getPid();
|
||||
String new_pid = portal.getPid();
|
||||
|
||||
PortalResponse portalResponse = portalService.updatePortal(portal);
|
||||
|
||||
String old_pid = portalResponse.getPid();
|
||||
String new_pid = portal.getPid();
|
||||
if(!old_pid.equals(new_pid)) {
|
||||
log.debug("update portal pid - old: "+old_pid + " - new: "+new_pid);
|
||||
statisticsService.updatePid(old_pid, new_pid);
|
||||
subscriberService.updatePid(old_pid, new_pid);
|
||||
layoutService.updatePid(old_pid, new_pid);
|
||||
notificationsService.updatePid(old_pid, new_pid);
|
||||
}
|
||||
|
||||
return portalResponse;
|
||||
|
@ -78,6 +85,7 @@ public class CommunityController {
|
|||
statisticsService.deleteByPid(pid);
|
||||
subscriberService.deletePortalSubscribers(pid);
|
||||
layoutService.deleteByPid(pid);
|
||||
notificationsService.deleteByPid(pid);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -14,9 +14,15 @@ public class LayoutService {
|
|||
private LayoutDAO layoutDAO;
|
||||
|
||||
public void updatePid(String old_pid, String new_pid) {
|
||||
log.debug("layout service: updatePid");
|
||||
Layout layout = layoutDAO.findByPortalPid(old_pid);
|
||||
layout.setPortalPid(new_pid);
|
||||
layoutDAO.save(layout);
|
||||
log.debug("layout service: layout id: "+(layout != null ? layout.getId() : "not found"));
|
||||
if(layout != null) {
|
||||
layout.setPortalPid(new_pid);
|
||||
log.debug("layout layout: new layout pid: " + layout.getPortalPid());
|
||||
layoutDAO.save(layout);
|
||||
log.debug("layout saved!");
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteByPid(String pid) {
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package eu.dnetlib.uoaadmintools.services;
|
||||
|
||||
import eu.dnetlib.uoaadmintools.dao.NotificationsDAO;
|
||||
import eu.dnetlib.uoaadmintools.entities.Notifications;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class NotificationsService {
|
||||
private final Logger log = Logger.getLogger(this.getClass());
|
||||
|
||||
@Autowired
|
||||
private NotificationsDAO notificationsDAO;
|
||||
|
||||
public void updatePid(String old_pid, String new_pid) {
|
||||
log.debug("notifications service: updatePid");
|
||||
List<Notifications> notifications = notificationsDAO.findByPortalPid(old_pid);
|
||||
if(notifications != null) {
|
||||
notifications.forEach(notification -> {
|
||||
notification.setPortalPid(new_pid);
|
||||
notificationsDAO.save(notification);
|
||||
});
|
||||
log.debug("notifications saved!");
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteByPid(String pid) {
|
||||
// TODO check maybe we can delete by portalId without find first
|
||||
List<Notifications> notifications = notificationsDAO.findByPortalPid(pid);
|
||||
if(notifications != null) {
|
||||
notifications.forEach(notification -> notificationsDAO.delete(notification.getId()));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,9 +14,15 @@ public class StatisticsService {
|
|||
private StatisticsDAO statisticsDAO;
|
||||
|
||||
public void updatePid(String old_pid, String new_pid) {
|
||||
log.debug("statistics service: updatePid");
|
||||
Statistics statistics = statisticsDAO.findByPid(old_pid);
|
||||
statistics.setPid(new_pid);
|
||||
statisticsDAO.save(statistics);
|
||||
log.debug("statistics service: statistics id: "+(statistics != null ? statistics.getId() : "not found"));
|
||||
if(statistics != null) {
|
||||
statistics.setPid(new_pid);
|
||||
log.debug("statistics service: new statistics pid: " + statistics.getPid());
|
||||
statisticsDAO.save(statistics);
|
||||
log.debug("statistics saved!");
|
||||
}
|
||||
}
|
||||
|
||||
public void createPortalStatistics(String pid) {
|
||||
|
|
|
@ -14,9 +14,15 @@ public class SubscriberService {
|
|||
private PortalSubscribersDAO portalSubscribersDAO;
|
||||
|
||||
public void updatePid(String old_pid, String new_pid) {
|
||||
log.debug("subscriber service: updatePid");
|
||||
PortalSubscribers portalSubscribers = portalSubscribersDAO.findByPid(old_pid);
|
||||
portalSubscribers.setPid(new_pid);
|
||||
portalSubscribersDAO.save(portalSubscribers);
|
||||
log.debug("subscriber service: portalSubscribers id: "+(portalSubscribers != null ? portalSubscribers.getId() : "not found"));
|
||||
if(portalSubscribers != null) {
|
||||
portalSubscribers.setPid(new_pid);
|
||||
log.debug("subscriber portalSubscribers: new portalSubscribers pid: " + portalSubscribers.getPid());
|
||||
portalSubscribersDAO.save(portalSubscribers);
|
||||
log.debug("portalSubscribers saved!");
|
||||
}
|
||||
}
|
||||
|
||||
public void createPortalSubscribers(String pid) {
|
||||
|
|
Loading…
Reference in New Issue