Project

General

Profile

1
package eu.dnetlib.uoaadmintools.services;
2

    
3
import eu.dnetlib.uoaadmintools.dao.StatisticsDAO;
4
import eu.dnetlib.uoaadmintools.entities.statistics.Statistics;
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 StatisticsService {
11
    private final Logger log = Logger.getLogger(this.getClass());
12

    
13
    @Autowired
14
    private StatisticsDAO statisticsDAO;
15

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

    
28
    public void createPortalStatistics(String pid) {
29
        Statistics statistics =  new Statistics(pid);
30
        statisticsDAO.save(statistics);
31
    }
32

    
33
    public void deleteByPid(String pid) {
34
        Statistics stats = statisticsDAO.findByPid(pid);
35
        if(stats != null) {
36
            statisticsDAO.delete(stats.getId());
37
        }
38
    }
39
}
(3-3/4)