Project

General

Profile

1
package eu.dnetlib.repo.manager.controllers;
2

    
3
import eu.dnetlib.repo.manager.domain.BrokerSummary;
4
import eu.dnetlib.repo.manager.domain.CollectionMonitorSummary;
5
import eu.dnetlib.repo.manager.domain.RepositorySummaryInfo;
6
import eu.dnetlib.repo.manager.domain.UsageSummary;
7
import eu.dnetlib.repo.manager.service.BrokerService;
8
import eu.dnetlib.repo.manager.service.DashboardService;
9
import eu.dnetlib.repo.manager.service.PiWikService;
10
import eu.dnetlib.repo.manager.service.RepositoryService;
11
import eu.dnetlib.repo.manager.domain.AggregationDetails;
12
import eu.dnetlib.repo.manager.domain.BrokerException;
13
import eu.dnetlib.repo.manager.domain.RepositoryServiceException;
14
import io.swagger.annotations.Api;
15
import org.json.JSONException;
16
import org.springframework.beans.factory.annotation.Autowired;
17
import org.springframework.http.MediaType;
18
import org.springframework.security.access.prepost.PreAuthorize;
19
import org.springframework.web.bind.annotation.*;
20

    
21
import java.util.List;
22

    
23
@RestController
24
@RequestMapping(value = "/dashboard")
25
@Api(description = "Dashboard API",  tags = {"dashboard"})
26
public class DashboardController {
27

    
28
    @Autowired
29
    private DashboardService dashboardService;
30

    
31
    @Autowired
32
    private RepositoryService repositoryService;
33

    
34
    @Autowired
35
    private BrokerService brokerService;
36

    
37
    @Autowired
38
    private PiWikService piWikService;
39

    
40
    @RequestMapping(value = "/getRepositoriesSummary/{userEmail}/{page}/{size}" , method = RequestMethod.GET,
41
            produces = MediaType.APPLICATION_JSON_VALUE)
42
    @ResponseBody
43
    @PreAuthorize("hasRole('ROLE_USER')")
44
    public List<RepositorySummaryInfo> getRepositoriesSummaryInfo(@PathVariable("userEmail") String userEmail,
45
                                                                  @PathVariable("page") String page,
46
                                                                  @PathVariable("size") String size) throws JSONException {
47
        return dashboardService.getRepositoriesSummaryInfo(userEmail, page, size);
48
    }
49

    
50
    @RequestMapping(value = "/collectionMonitorSummary/{repoId}" , method = RequestMethod.GET,
51
            produces = MediaType.APPLICATION_JSON_VALUE)
52
    @ResponseBody
53
    @PreAuthorize("hasRole('ROLE_USER')")
54
    public CollectionMonitorSummary getCollectionMonitorSummary(
55
            @PathVariable("repoId") String repoId,
56
            @RequestParam(name = "size", required = false, defaultValue = "20") int size) throws JSONException {
57

    
58
        List<AggregationDetails> aggregationDetails = repositoryService.getRepositoryAggregations(repoId,0,size);
59
        CollectionMonitorSummary collectionMonitorSummary = new CollectionMonitorSummary();
60
        collectionMonitorSummary.setAggregationDetails(aggregationDetails);
61
        size=0;
62
        do {
63
            aggregationDetails = repositoryService.getRepositoryAggregations(repoId,size,size+50);
64
            for(AggregationDetails aggregationDetail : aggregationDetails){
65
                if(aggregationDetail.getIndexedVersion()){
66
                    collectionMonitorSummary.setLastIndexedVersion(aggregationDetail);
67
                    break;
68
                }
69
            }
70
            size+=30;
71
        }while (aggregationDetails.size() != 0 && collectionMonitorSummary.getLastIndexedVersion()==null);
72

    
73
        return collectionMonitorSummary;
74
    }
75

    
76
    @RequestMapping(value = "/usageSummary/{repoId}" , method = RequestMethod.GET,
77
            produces = MediaType.APPLICATION_JSON_VALUE)
78
    @ResponseBody
79
    @PreAuthorize("hasRole('ROLE_USER')")
80
    public UsageSummary getUsageSummary(
81
            @PathVariable("repoId") String repoId
82
    ) throws RepositoryServiceException {
83
        return new UsageSummary(repositoryService.getMetricsInfoForRepository(repoId), piWikService.getPiwikSiteForRepo(repoId));
84
    }
85

    
86
    @RequestMapping(value = "/brokerSummary/{email}/{ds_name}" , method = RequestMethod.GET,
87
            produces = MediaType.APPLICATION_JSON_VALUE)
88
    @ResponseBody
89
    @PreAuthorize("hasRole('ROLE_USER')")
90
    public BrokerSummary getBrokerSummary(
91
            @PathVariable("email") String email,
92
            @PathVariable("ds_name") String datasourceName) throws BrokerException {
93
        return new BrokerSummary(brokerService.getSimpleSubscriptionsOfUser(email), brokerService.getTopicsForDatasource(datasourceName));
94
    }
95

    
96

    
97

    
98

    
99
}
(2-2/11)