Implementing summaries for collection, usage and broker

This commit is contained in:
Ioannis Diplas 2019-09-26 11:09:24 +00:00
parent 61e7696832
commit 8f1e214a6b
7 changed files with 89 additions and 6 deletions

View File

@ -1,7 +1,15 @@
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;
@ -19,6 +27,12 @@ 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
@ -28,4 +42,37 @@ public class DashboardController {
@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));
}
}

View File

@ -80,7 +80,7 @@ public class RepositoryController {
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<AggregationDetails> getRepositoryAggregations(@PathVariable("id") String id) throws JSONException {
return repositoryService.getRepositoryAggregations(id);
return repositoryService.getRepositoryAggregations(id,20);
}
@RequestMapping(value = "/getRepositoryAggregationsByYear/{id}", method = RequestMethod.GET,

View File

@ -0,0 +1,36 @@
package eu.dnetlib.repo.manager.domain;
import eu.dnetlib.repo.manager.shared.broker.BrowseEntry;
import eu.dnetlib.repo.manager.shared.broker.SimpleSubscriptionDesc;
import java.util.List;
import java.util.Map;
public class BrokerSummary {
private Map<String, List<SimpleSubscriptionDesc>> userSubs;
private List<BrowseEntry> topicsForDatasource;
public BrokerSummary(){}
public BrokerSummary(Map<String, List<SimpleSubscriptionDesc>> userSubs, List<BrowseEntry> topicsForDatasource) {
this.userSubs = userSubs;
this.topicsForDatasource = topicsForDatasource;
}
public Map<String, List<SimpleSubscriptionDesc>> getUserSubs() {
return userSubs;
}
public void setUserSubs(Map<String, List<SimpleSubscriptionDesc>> userSubs) {
this.userSubs = userSubs;
}
public List<BrowseEntry> getTopicsForDatasource() {
return topicsForDatasource;
}
public void setTopicsForDatasource(List<BrowseEntry> topicsForDatasource) {
this.topicsForDatasource = topicsForDatasource;
}
}

View File

@ -49,7 +49,7 @@ public class DashboardServiceImpl implements DashboardService {
repositorySummaryInfo.setLogoURL(repository.getLogoUrl());
//TODO getRepositoryAggregations returns only the 20 more recent items. Is it positive that we will find an indexed version there?
List<AggregationDetails> aggregationDetailsList = repositoryService.getRepositoryAggregations(repository.getId());
List<AggregationDetails> aggregationDetailsList = repositoryService.getRepositoryAggregations(repository.getId(),20);
for(AggregationDetails aggregationDetails: aggregationDetailsList) {
if(aggregationDetails.getIndexedVersion()) {
repositorySummaryInfo.setRecordsCollected(aggregationDetails.getNumberOfRecords());

View File

@ -238,7 +238,7 @@ public class EmailUtilsImpl implements EmailUtils {
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
String message = "Dear user,\n" +
String message = "Dear "+SecurityContextHolder.getContext().getAuthentication().getName()+",\n" +
"\n" +
"We received a request to register the " + repository.getDatasourceType() + "[" + repository.getEnglishName() + "]" +
" to the OpenAIRE compliant list of content providers. " +

View File

@ -25,7 +25,7 @@ public interface RepositoryService {
Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException;
List<AggregationDetails> getRepositoryAggregations(String id) throws JSONException;
List<AggregationDetails> getRepositoryAggregations(String id, int size) throws JSONException;
Map<String,List<AggregationDetails>> getRepositoryAggregationsByYear(String id) throws JSONException;

View File

@ -290,7 +290,7 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public List<AggregationDetails> getRepositoryAggregations(String id) throws JSONException {
public List<AggregationDetails> getRepositoryAggregations(String id, int size) throws JSONException {
LOGGER.debug("Retreiving aggregations for repository with id : " + id );
UriComponents uriComponents = searchDatasource("0","100");
@ -308,7 +308,7 @@ public class RepositoryServiceImpl implements RepositoryService {
aggregationHistory.addAll(Converter.getAggregationHistoryFromJson(repository.getJSONArray("datasourceInfo").getJSONObject(0)));
return aggregationHistory.size() == 0? aggregationHistory : aggregationHistory.stream()
.sorted(Comparator.comparing(AggregationDetails::getDate).reversed())
.limit(20)
.limit(size)
.collect(Collectors.toList());
} catch (JSONException e) {
LOGGER.debug("Exception on getRepositoryAggregations" , e);