Revision 60034
Added by Konstantina Galouni over 3 years ago
modules/uoa-admin-tools/trunk/src/main/java/eu/dnetlib/uoaadmintools/services/SubscriberService.java | ||
---|---|---|
14 | 14 |
private PortalSubscribersDAO portalSubscribersDAO; |
15 | 15 |
|
16 | 16 |
public void updatePid(String old_pid, String new_pid) { |
17 |
log.debug("subscriber service: updatePid"); |
|
17 | 18 |
PortalSubscribers portalSubscribers = portalSubscribersDAO.findByPid(old_pid); |
18 |
portalSubscribers.setPid(new_pid); |
|
19 |
portalSubscribersDAO.save(portalSubscribers); |
|
19 |
log.debug("subscriber service: portalSubscribers id: "+(portalSubscribers != null ? portalSubscribers.getId() : "not found")); |
|
20 |
if(portalSubscribers != null) { |
|
21 |
portalSubscribers.setPid(new_pid); |
|
22 |
log.debug("subscriber portalSubscribers: new portalSubscribers pid: " + portalSubscribers.getPid()); |
|
23 |
portalSubscribersDAO.save(portalSubscribers); |
|
24 |
log.debug("portalSubscribers saved!"); |
|
25 |
} |
|
20 | 26 |
} |
21 | 27 |
|
22 | 28 |
public void createPortalSubscribers(String pid) { |
modules/uoa-admin-tools/trunk/src/main/java/eu/dnetlib/uoaadmintools/services/NotificationsService.java | ||
---|---|---|
1 |
package eu.dnetlib.uoaadmintools.services; |
|
2 |
|
|
3 |
import eu.dnetlib.uoaadmintools.dao.NotificationsDAO; |
|
4 |
import eu.dnetlib.uoaadmintools.entities.Notifications; |
|
5 |
import org.apache.log4j.Logger; |
|
6 |
import org.springframework.beans.factory.annotation.Autowired; |
|
7 |
import org.springframework.stereotype.Service; |
|
8 |
|
|
9 |
import java.util.List; |
|
10 |
|
|
11 |
@Service |
|
12 |
public class NotificationsService { |
|
13 |
private final Logger log = Logger.getLogger(this.getClass()); |
|
14 |
|
|
15 |
@Autowired |
|
16 |
private NotificationsDAO notificationsDAO; |
|
17 |
|
|
18 |
public void updatePid(String old_pid, String new_pid) { |
|
19 |
log.debug("notifications service: updatePid"); |
|
20 |
List<Notifications> notifications = notificationsDAO.findByPortalPid(old_pid); |
|
21 |
if(notifications != null) { |
|
22 |
notifications.forEach(notification -> { |
|
23 |
notification.setPortalPid(new_pid); |
|
24 |
notificationsDAO.save(notification); |
|
25 |
}); |
|
26 |
log.debug("notifications saved!"); |
|
27 |
} |
|
28 |
} |
|
29 |
|
|
30 |
public void deleteByPid(String pid) { |
|
31 |
// TODO check maybe we can delete by portalId without find first |
|
32 |
List<Notifications> notifications = notificationsDAO.findByPortalPid(pid); |
|
33 |
if(notifications != null) { |
|
34 |
notifications.forEach(notification -> notificationsDAO.delete(notification.getId())); |
|
35 |
} |
|
36 |
} |
|
37 |
} |
modules/uoa-admin-tools/trunk/src/main/java/eu/dnetlib/uoaadmintools/services/StatisticsService.java | ||
---|---|---|
14 | 14 |
private StatisticsDAO statisticsDAO; |
15 | 15 |
|
16 | 16 |
public void updatePid(String old_pid, String new_pid) { |
17 |
log.debug("statistics service: updatePid"); |
|
17 | 18 |
Statistics statistics = statisticsDAO.findByPid(old_pid); |
18 |
statistics.setPid(new_pid); |
|
19 |
statisticsDAO.save(statistics); |
|
19 |
log.debug("statistics service: statistics id: "+(statistics != null ? statistics.getId() : "not found")); |
|
20 |
if(statistics != null) { |
|
21 |
statistics.setPid(new_pid); |
|
22 |
log.debug("statistics service: new statistics pid: " + statistics.getPid()); |
|
23 |
statisticsDAO.save(statistics); |
|
24 |
log.debug("statistics saved!"); |
|
25 |
} |
|
20 | 26 |
} |
21 | 27 |
|
22 | 28 |
public void createPortalStatistics(String pid) { |
modules/uoa-admin-tools/trunk/src/main/java/eu/dnetlib/uoaadmintools/services/LayoutService.java | ||
---|---|---|
14 | 14 |
private LayoutDAO layoutDAO; |
15 | 15 |
|
16 | 16 |
public void updatePid(String old_pid, String new_pid) { |
17 |
log.debug("layout service: updatePid"); |
|
17 | 18 |
Layout layout = layoutDAO.findByPortalPid(old_pid); |
18 |
layout.setPortalPid(new_pid); |
|
19 |
layoutDAO.save(layout); |
|
19 |
log.debug("layout service: layout id: "+(layout != null ? layout.getId() : "not found")); |
|
20 |
if(layout != null) { |
|
21 |
layout.setPortalPid(new_pid); |
|
22 |
log.debug("layout layout: new layout pid: " + layout.getPortalPid()); |
|
23 |
layoutDAO.save(layout); |
|
24 |
log.debug("layout saved!"); |
|
25 |
} |
|
20 | 26 |
} |
21 | 27 |
|
22 | 28 |
public void deleteByPid(String pid) { |
modules/uoa-admin-tools/trunk/src/main/java/eu/dnetlib/uoaadmintools/controllers/CommunityController.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import eu.dnetlib.uoaadmintools.entities.Layout; |
4 | 4 |
import eu.dnetlib.uoaadmintools.services.LayoutService; |
5 |
import eu.dnetlib.uoaadmintools.services.NotificationsService; |
|
5 | 6 |
import eu.dnetlib.uoaadmintools.services.StatisticsService; |
6 | 7 |
import eu.dnetlib.uoaadmintools.services.SubscriberService; |
7 | 8 |
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal; |
... | ... | |
23 | 24 |
private LayoutService layoutService; |
24 | 25 |
|
25 | 26 |
@Autowired |
27 |
private NotificationsService notificationsService; |
|
28 |
|
|
29 |
@Autowired |
|
26 | 30 |
private StatisticsService statisticsService; |
27 | 31 |
|
28 | 32 |
@Autowired |
... | ... | |
44 | 48 |
// @PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.PORTAL_ADMIN)") |
45 | 49 |
@RequestMapping(value = "/update", method = RequestMethod.POST) |
46 | 50 |
public PortalResponse updateCommunity(@RequestBody Portal portal) { |
51 |
String old_pid = portalService.getPortalById(portal.getId()).getPid(); |
|
52 |
String new_pid = portal.getPid(); |
|
53 |
|
|
47 | 54 |
PortalResponse portalResponse = portalService.updatePortal(portal); |
48 | 55 |
|
49 |
String old_pid = portalResponse.getPid(); |
|
50 |
String new_pid = portal.getPid(); |
|
51 | 56 |
if(!old_pid.equals(new_pid)) { |
57 |
log.debug("update portal pid - old: "+old_pid + " - new: "+new_pid); |
|
52 | 58 |
statisticsService.updatePid(old_pid, new_pid); |
53 | 59 |
subscriberService.updatePid(old_pid, new_pid); |
54 | 60 |
layoutService.updatePid(old_pid, new_pid); |
61 |
notificationsService.updatePid(old_pid, new_pid); |
|
55 | 62 |
} |
56 | 63 |
|
57 | 64 |
return portalResponse; |
... | ... | |
78 | 85 |
statisticsService.deleteByPid(pid); |
79 | 86 |
subscriberService.deletePortalSubscribers(pid); |
80 | 87 |
layoutService.deleteByPid(pid); |
88 |
notificationsService.deleteByPid(pid); |
|
81 | 89 |
} |
82 | 90 |
|
83 | 91 |
return true; |
Also available in: Unified diff
[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.