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