1 |
56387
|
stefania.m
|
package eu.dnetlib.repo.manager.controllers;
|
2 |
|
|
|
3 |
57890
|
ioannis.di
|
import eu.dnetlib.repo.manager.domain.*;
|
4 |
57155
|
ioannis.di
|
import eu.dnetlib.repo.manager.service.BrokerService;
|
5 |
56387
|
stefania.m
|
import eu.dnetlib.repo.manager.service.DashboardService;
|
6 |
57155
|
ioannis.di
|
import eu.dnetlib.repo.manager.service.PiWikService;
|
7 |
|
|
import eu.dnetlib.repo.manager.service.RepositoryService;
|
8 |
56387
|
stefania.m
|
import io.swagger.annotations.Api;
|
9 |
|
|
import org.json.JSONException;
|
10 |
57907
|
ioannis.di
|
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
|
11 |
56387
|
stefania.m
|
import org.springframework.beans.factory.annotation.Autowired;
|
12 |
|
|
import org.springframework.http.MediaType;
|
13 |
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
14 |
57907
|
ioannis.di
|
import org.springframework.security.core.context.SecurityContextHolder;
|
15 |
56387
|
stefania.m
|
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 |
56661
|
ioannis.di
|
private DashboardService dashboardService;
|
26 |
56387
|
stefania.m
|
|
27 |
57155
|
ioannis.di
|
@Autowired
|
28 |
|
|
private RepositoryService repositoryService;
|
29 |
|
|
|
30 |
|
|
@Autowired
|
31 |
|
|
private BrokerService brokerService;
|
32 |
|
|
|
33 |
57174
|
ioannis.di
|
@Autowired
|
34 |
|
|
private PiWikService piWikService;
|
35 |
|
|
|
36 |
57966
|
ioannis.di
|
@RequestMapping(value = "/getRepositoriesSummary/{page}/{size}" , method = RequestMethod.GET,
|
37 |
56387
|
stefania.m
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
38 |
|
|
@ResponseBody
|
39 |
|
|
@PreAuthorize("hasRole('ROLE_USER')")
|
40 |
57966
|
ioannis.di
|
public List<RepositorySummaryInfo> getRepositoriesSummaryInfo(
|
41 |
56387
|
stefania.m
|
@PathVariable("page") String page,
|
42 |
|
|
@PathVariable("size") String size) throws JSONException {
|
43 |
57966
|
ioannis.di
|
return dashboardService.getRepositoriesSummaryInfo(((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail(), page, size);
|
44 |
56387
|
stefania.m
|
}
|
45 |
57155
|
ioannis.di
|
|
46 |
|
|
@RequestMapping(value = "/collectionMonitorSummary/{repoId}" , method = RequestMethod.GET,
|
47 |
|
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
48 |
|
|
@ResponseBody
|
49 |
|
|
@PreAuthorize("hasRole('ROLE_USER')")
|
50 |
57176
|
ioannis.di
|
public CollectionMonitorSummary getCollectionMonitorSummary(
|
51 |
57155
|
ioannis.di
|
@PathVariable("repoId") String repoId,
|
52 |
|
|
@RequestParam(name = "size", required = false, defaultValue = "20") int size) throws JSONException {
|
53 |
57176
|
ioannis.di
|
|
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 |
57155
|
ioannis.di
|
}
|
71 |
|
|
|
72 |
|
|
@RequestMapping(value = "/usageSummary/{repoId}" , method = RequestMethod.GET,
|
73 |
|
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
74 |
|
|
@ResponseBody
|
75 |
|
|
@PreAuthorize("hasRole('ROLE_USER')")
|
76 |
57174
|
ioannis.di
|
public UsageSummary getUsageSummary(
|
77 |
57176
|
ioannis.di
|
@PathVariable("repoId") String repoId
|
78 |
|
|
) throws RepositoryServiceException {
|
79 |
57174
|
ioannis.di
|
return new UsageSummary(repositoryService.getMetricsInfoForRepository(repoId), piWikService.getPiwikSiteForRepo(repoId));
|
80 |
57155
|
ioannis.di
|
}
|
81 |
|
|
|
82 |
57966
|
ioannis.di
|
@RequestMapping(value = "/brokerSummary/{ds_name}" , method = RequestMethod.GET,
|
83 |
57155
|
ioannis.di
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
84 |
|
|
@ResponseBody
|
85 |
|
|
@PreAuthorize("hasRole('ROLE_USER')")
|
86 |
|
|
public BrokerSummary getBrokerSummary(
|
87 |
|
|
@PathVariable("ds_name") String datasourceName) throws BrokerException {
|
88 |
57966
|
ioannis.di
|
return new BrokerSummary(brokerService.getSimpleSubscriptionsOfUser( ((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail()), brokerService.getTopicsForDatasource(datasourceName));
|
89 |
57155
|
ioannis.di
|
}
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
|
94 |
56387
|
stefania.m
|
}
|