uoa-repository-manager-service/src/main/java/eu/dnetlib/repo/manager/controllers/DashboardController.java

79 lines
3.3 KiB
Java

package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.repo.manager.domain.BrokerSummary;
import eu.dnetlib.repo.manager.domain.RepositorySummaryInfo;
import eu.dnetlib.repo.manager.service.BrokerService;
import eu.dnetlib.repo.manager.service.DashboardService;
import eu.dnetlib.repo.manager.service.PiWikService;
import eu.dnetlib.repo.manager.service.RepositoryService;
import eu.dnetlib.repo.manager.shared.AggregationDetails;
import eu.dnetlib.repo.manager.shared.BrokerException;
import eu.dnetlib.repo.manager.shared.MetricsInfo;
import eu.dnetlib.repo.manager.shared.RepositoryServiceException;
import io.swagger.annotations.Api;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping(value = "/dashboard")
@Api(description = "Dashboard API", tags = {"dashboard"})
public class DashboardController {
@Autowired
private DashboardService dashboardService;
@Autowired
private RepositoryService repositoryService;
@Autowired
private BrokerService brokerService;
@RequestMapping(value = "/getRepositoriesSummary/{userEmail}/{page}/{size}" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
public List<RepositorySummaryInfo> getRepositoriesSummaryInfo(@PathVariable("userEmail") String userEmail,
@PathVariable("page") String page,
@PathVariable("size") String size) throws JSONException {
return dashboardService.getRepositoriesSummaryInfo(userEmail, page, size);
}
@RequestMapping(value = "/collectionMonitorSummary/{repoId}" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
public List<AggregationDetails> getCollectionMonitorSummary(
@PathVariable("repoId") String repoId,
@RequestParam(name = "size", required = false, defaultValue = "20") int size) throws JSONException {
return repositoryService.getRepositoryAggregations(repoId,size);
}
@RequestMapping(value = "/usageSummary/{repoId}" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
public MetricsInfo getUsageSummary(
@PathVariable("repoId") String repoId) throws RepositoryServiceException {
return repositoryService.getMetricsInfoForRepository(repoId);
}
@RequestMapping(value = "/brokerSummary/{email}/{ds_name}" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
public BrokerSummary getBrokerSummary(
@PathVariable("email") String email,
@PathVariable("ds_name") String datasourceName) throws BrokerException {
return new BrokerSummary(brokerService.getSimpleSubscriptionsOfUser(email), brokerService.getTopicsForDatasource(datasourceName));
}
}