1
|
package eu.dnetlib.repo.manager.controllers;
|
2
|
|
3
|
import eu.dnetlib.repo.manager.domain.*;
|
4
|
import eu.dnetlib.repo.manager.service.BrokerService;
|
5
|
import eu.dnetlib.repo.manager.service.DashboardService;
|
6
|
import eu.dnetlib.repo.manager.service.PiWikService;
|
7
|
import eu.dnetlib.repo.manager.service.RepositoryService;
|
8
|
import io.swagger.annotations.Api;
|
9
|
import org.json.JSONException;
|
10
|
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
|
11
|
import org.springframework.beans.factory.annotation.Autowired;
|
12
|
import org.springframework.http.MediaType;
|
13
|
import org.springframework.security.access.prepost.PreAuthorize;
|
14
|
import org.springframework.security.core.context.SecurityContextHolder;
|
15
|
import org.springframework.web.bind.annotation.*;
|
16
|
|
17
|
import java.util.List;
|
18
|
|
19
|
@RestController
|
20
|
@RequestMapping(value = "/dashboard")
|
21
|
@Api(description = "Dashboard API", tags = {"dashboard"})
|
22
|
public class DashboardController {
|
23
|
|
24
|
@Autowired
|
25
|
private DashboardService dashboardService;
|
26
|
|
27
|
@Autowired
|
28
|
private RepositoryService repositoryService;
|
29
|
|
30
|
@Autowired
|
31
|
private BrokerService brokerService;
|
32
|
|
33
|
@Autowired
|
34
|
private PiWikService piWikService;
|
35
|
|
36
|
@RequestMapping(value = "/getRepositoriesSummary/{page}/{size}" , method = RequestMethod.GET,
|
37
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
38
|
@ResponseBody
|
39
|
@PreAuthorize("hasAuthority('REGISTERED_USER')")
|
40
|
public List<RepositorySummaryInfo> getRepositoriesSummaryInfo(
|
41
|
@PathVariable("page") String page,
|
42
|
@PathVariable("size") String size) throws JSONException {
|
43
|
return dashboardService.getRepositoriesSummaryInfo(((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail(), page, size);
|
44
|
}
|
45
|
|
46
|
@RequestMapping(value = "/collectionMonitorSummary/{repoId}" , method = RequestMethod.GET,
|
47
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
48
|
@ResponseBody
|
49
|
@PreAuthorize("hasAuthority('REGISTERED_USER')")
|
50
|
public CollectionMonitorSummary getCollectionMonitorSummary(
|
51
|
@PathVariable("repoId") String repoId,
|
52
|
@RequestParam(name = "size", required = false, defaultValue = "20") int size) throws JSONException {
|
53
|
|
54
|
List<AggregationDetails> aggregationDetails = repositoryService.getRepositoryAggregations(repoId,0,size);
|
55
|
CollectionMonitorSummary collectionMonitorSummary = new CollectionMonitorSummary();
|
56
|
collectionMonitorSummary.setAggregationDetails(aggregationDetails);
|
57
|
size=0;
|
58
|
do {
|
59
|
aggregationDetails = repositoryService.getRepositoryAggregations(repoId,size,size+50);
|
60
|
for(AggregationDetails aggregationDetail : aggregationDetails){
|
61
|
if(aggregationDetail.getIndexedVersion()){
|
62
|
collectionMonitorSummary.setLastIndexedVersion(aggregationDetail);
|
63
|
break;
|
64
|
}
|
65
|
}
|
66
|
size+=30;
|
67
|
}while (aggregationDetails.size() != 0 && collectionMonitorSummary.getLastIndexedVersion()==null);
|
68
|
|
69
|
return collectionMonitorSummary;
|
70
|
}
|
71
|
|
72
|
@RequestMapping(value = "/usageSummary/{repoId}" , method = RequestMethod.GET,
|
73
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
74
|
@ResponseBody
|
75
|
@PreAuthorize("hasAuthority('REGISTERED_USER')")
|
76
|
public UsageSummary getUsageSummary(
|
77
|
@PathVariable("repoId") String repoId
|
78
|
) throws RepositoryServiceException {
|
79
|
return new UsageSummary(repositoryService.getMetricsInfoForRepository(repoId), piWikService.getPiwikSiteForRepo(repoId));
|
80
|
}
|
81
|
|
82
|
@RequestMapping(value = "/brokerSummary/{ds_name}" , method = RequestMethod.GET,
|
83
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
84
|
@ResponseBody
|
85
|
@PreAuthorize("hasAuthority('REGISTERED_USER')")
|
86
|
public BrokerSummary getBrokerSummary(
|
87
|
@PathVariable("ds_name") String datasourceName) throws BrokerException {
|
88
|
return new BrokerSummary(brokerService.getSimpleSubscriptionsOfUser( ((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail()), brokerService.getTopicsForDatasource(datasourceName));
|
89
|
}
|
90
|
|
91
|
|
92
|
|
93
|
|
94
|
}
|