Project

General

Profile

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
}
(2-2/4)