2019-07-19 11:31:23 +02:00
|
|
|
package eu.dnetlib.repo.manager.controllers;
|
|
|
|
|
2024-03-22 10:51:22 +01:00
|
|
|
import eu.dnetlib.openaire.exporter.model.dsm.AggregationInfo;
|
|
|
|
import eu.dnetlib.repo.manager.domain.BrokerSummary;
|
|
|
|
import eu.dnetlib.repo.manager.domain.CollectionMonitorSummary;
|
|
|
|
import eu.dnetlib.repo.manager.domain.RepositorySummaryInfo;
|
|
|
|
import eu.dnetlib.repo.manager.domain.UsageSummary;
|
2022-08-05 10:48:16 +02:00
|
|
|
import eu.dnetlib.repo.manager.exception.BrokerException;
|
|
|
|
import eu.dnetlib.repo.manager.exception.RepositoryServiceException;
|
2022-12-14 16:08:11 +01:00
|
|
|
import eu.dnetlib.repo.manager.service.*;
|
2023-06-01 19:48:01 +02:00
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
2019-07-19 11:31:23 +02:00
|
|
|
import org.json.JSONException;
|
2019-12-18 11:04:22 +01:00
|
|
|
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
|
2019-07-19 11:31:23 +02:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
2019-12-18 11:04:22 +01:00
|
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
2019-07-19 11:31:23 +02:00
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@RequestMapping(value = "/dashboard")
|
2023-06-01 19:48:01 +02:00
|
|
|
@Tag(name="dashboard", description = "Dashboard API")
|
2019-07-19 11:31:23 +02:00
|
|
|
public class DashboardController {
|
|
|
|
|
|
|
|
@Autowired
|
2019-07-22 15:00:51 +02:00
|
|
|
private DashboardService dashboardService;
|
2019-07-19 11:31:23 +02:00
|
|
|
|
2019-09-26 13:09:24 +02:00
|
|
|
@Autowired
|
|
|
|
private RepositoryService repositoryService;
|
|
|
|
|
2022-12-14 16:08:11 +01:00
|
|
|
@Autowired
|
|
|
|
private AggregationService aggregationService;
|
|
|
|
|
2019-09-26 13:09:24 +02:00
|
|
|
@Autowired
|
|
|
|
private BrokerService brokerService;
|
|
|
|
|
2019-09-27 11:46:21 +02:00
|
|
|
@Autowired
|
|
|
|
private PiWikService piWikService;
|
|
|
|
|
2022-08-05 10:48:16 +02:00
|
|
|
@RequestMapping(value = "/getRepositoriesSummary/{page}/{size}", method = RequestMethod.GET,
|
2019-07-19 11:31:23 +02:00
|
|
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
@ResponseBody
|
2021-07-21 13:51:18 +02:00
|
|
|
@PreAuthorize("hasAuthority('REGISTERED_USER')")
|
2020-01-10 13:56:27 +01:00
|
|
|
public List<RepositorySummaryInfo> getRepositoriesSummaryInfo(
|
2022-08-05 10:48:16 +02:00
|
|
|
@PathVariable("page") String page,
|
|
|
|
@PathVariable("size") String size) throws JSONException {
|
2020-01-10 13:56:27 +01:00
|
|
|
return dashboardService.getRepositoriesSummaryInfo(((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail(), page, size);
|
2019-07-19 11:31:23 +02:00
|
|
|
}
|
2019-09-26 13:09:24 +02:00
|
|
|
|
2022-08-05 10:48:16 +02:00
|
|
|
@RequestMapping(value = "/collectionMonitorSummary/{repoId}", method = RequestMethod.GET,
|
2019-09-26 13:09:24 +02:00
|
|
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
@ResponseBody
|
2021-07-21 13:51:18 +02:00
|
|
|
@PreAuthorize("hasAuthority('REGISTERED_USER')")
|
2019-09-27 13:29:40 +02:00
|
|
|
public CollectionMonitorSummary getCollectionMonitorSummary(
|
2019-09-26 13:09:24 +02:00
|
|
|
@PathVariable("repoId") String repoId,
|
2023-02-03 13:19:43 +01:00
|
|
|
@RequestParam(name = "size", required = false, defaultValue = "20") int summarySize) throws JSONException {
|
2019-09-27 13:29:40 +02:00
|
|
|
|
2023-02-03 13:19:43 +01:00
|
|
|
List<AggregationInfo> aggregationInfoList = aggregationService.getRepositoryAggregations(repoId);
|
2023-02-02 17:47:04 +01:00
|
|
|
|
2019-09-27 13:29:40 +02:00
|
|
|
CollectionMonitorSummary collectionMonitorSummary = new CollectionMonitorSummary();
|
2023-02-03 13:19:43 +01:00
|
|
|
// Set the "aggregationInfo" for the first <number of> requested aggregations, in order to create a "summary".
|
|
|
|
collectionMonitorSummary.setAggregationInfo(aggregationInfoList.subList(0, Math.min(summarySize, aggregationInfoList.size())));
|
|
|
|
|
|
|
|
// Search for the last indexed version and set the "collectionMonitorSummary".
|
|
|
|
for ( AggregationInfo aggregationInfo : aggregationInfoList ) {
|
|
|
|
if ( aggregationInfo.isIndexedVersion() ) {
|
|
|
|
collectionMonitorSummary.setLastIndexedVersion(aggregationInfo);
|
|
|
|
break;
|
2019-09-27 13:29:40 +02:00
|
|
|
}
|
2023-02-03 13:19:43 +01:00
|
|
|
}
|
2019-09-27 13:29:40 +02:00
|
|
|
|
|
|
|
return collectionMonitorSummary;
|
2019-09-26 13:09:24 +02:00
|
|
|
}
|
|
|
|
|
2022-08-05 10:48:16 +02:00
|
|
|
@RequestMapping(value = "/usageSummary/{repoId}", method = RequestMethod.GET,
|
2019-09-26 13:09:24 +02:00
|
|
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
@ResponseBody
|
2021-07-21 13:51:18 +02:00
|
|
|
@PreAuthorize("hasAuthority('REGISTERED_USER')")
|
2019-09-27 11:46:21 +02:00
|
|
|
public UsageSummary getUsageSummary(
|
2019-09-27 13:29:40 +02:00
|
|
|
@PathVariable("repoId") String repoId
|
|
|
|
) throws RepositoryServiceException {
|
2019-09-27 11:46:21 +02:00
|
|
|
return new UsageSummary(repositoryService.getMetricsInfoForRepository(repoId), piWikService.getPiwikSiteForRepo(repoId));
|
2019-09-26 13:09:24 +02:00
|
|
|
}
|
|
|
|
|
2022-08-05 10:48:16 +02:00
|
|
|
@RequestMapping(value = "/brokerSummary/{ds_name}", method = RequestMethod.GET,
|
2019-09-26 13:09:24 +02:00
|
|
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
@ResponseBody
|
2021-07-21 13:51:18 +02:00
|
|
|
@PreAuthorize("hasAuthority('REGISTERED_USER')")
|
2019-09-26 13:09:24 +02:00
|
|
|
public BrokerSummary getBrokerSummary(
|
|
|
|
@PathVariable("ds_name") String datasourceName) throws BrokerException {
|
2022-08-05 10:48:16 +02:00
|
|
|
return new BrokerSummary(brokerService.getSimpleSubscriptionsOfUser(((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail()), brokerService.getTopicsForDatasource(datasourceName));
|
2019-09-26 13:09:24 +02:00
|
|
|
}
|
|
|
|
|
2019-07-19 11:31:23 +02:00
|
|
|
}
|