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