Project

General

Profile

1
package eu.dnetlib.uoaadmintools.services;
2

    
3
import eu.dnetlib.uoaadmintools.dao.PortalSubscribersDAO;
4
import eu.dnetlib.uoaadmintools.entities.subscriber.PortalSubscribers;
5
import org.apache.log4j.Logger;
6
import org.springframework.beans.factory.annotation.Autowired;
7
import org.springframework.stereotype.Service;
8

    
9
@Service
10
public class SubscriberService {
11
    private final Logger log = Logger.getLogger(this.getClass());
12

    
13
    @Autowired
14
    private PortalSubscribersDAO portalSubscribersDAO;
15

    
16
    public void updatePid(String old_pid, String new_pid) {
17
        log.debug("subscriber service: updatePid");
18
        PortalSubscribers portalSubscribers =  portalSubscribersDAO.findByPid(old_pid);
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
        }
26
    }
27

    
28
    public void createPortalSubscribers(String pid) {
29
        PortalSubscribers portalSubscribers =  new PortalSubscribers(pid);
30
        portalSubscribersDAO.save(portalSubscribers);
31
    }
32

    
33
    public void deletePortalSubscribers(String pid) {
34
        PortalSubscribers portalSubscribers = portalSubscribersDAO.findByPid(pid);
35
        if(portalSubscribers != null) {
36
            portalSubscribersDAO.delete(portalSubscribers.getId());
37
        }
38
    }
39
}
(4-4/4)