Implemented dashboard service which gets some summary info for the repositories of the user
This commit is contained in:
parent
4d79978392
commit
a514949c7f
|
@ -0,0 +1,31 @@
|
||||||
|
package eu.dnetlib.repo.manager.controllers;
|
||||||
|
|
||||||
|
import eu.dnetlib.repo.manager.domain.RepositorySummaryInfo;
|
||||||
|
import eu.dnetlib.repo.manager.service.DashboardService;
|
||||||
|
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
|
||||||
|
DashboardService dashboardService;
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,82 @@
|
||||||
|
package eu.dnetlib.repo.manager.domain;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class RepositorySummaryInfo {
|
||||||
|
|
||||||
|
String id;
|
||||||
|
String repositoryName;
|
||||||
|
String logoURL;
|
||||||
|
int recordsCollected;
|
||||||
|
Date lastIndexedVersion;
|
||||||
|
long enrichmentEvents;
|
||||||
|
String totalViews;
|
||||||
|
String totalDownloads;
|
||||||
|
|
||||||
|
public RepositorySummaryInfo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRepositoryName() {
|
||||||
|
return repositoryName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRepositoryName(String repositoryName) {
|
||||||
|
this.repositoryName = repositoryName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLogoURL() {
|
||||||
|
return logoURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLogoURL(String logoURL) {
|
||||||
|
this.logoURL = logoURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRecordsCollected() {
|
||||||
|
return recordsCollected;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRecordsCollected(int recordsCollected) {
|
||||||
|
this.recordsCollected = recordsCollected;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getLastIndexedVersion() {
|
||||||
|
return lastIndexedVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastIndexedVersion(Date lastIndexedVersion) {
|
||||||
|
this.lastIndexedVersion = lastIndexedVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getEnrichmentEvents() {
|
||||||
|
return enrichmentEvents;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnrichmentEvents(long enrichmentEvents) {
|
||||||
|
this.enrichmentEvents = enrichmentEvents;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTotalViews() {
|
||||||
|
return totalViews;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTotalViews(String totalViews) {
|
||||||
|
this.totalViews = totalViews;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTotalDownloads() {
|
||||||
|
return totalDownloads;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTotalDownloads(String totalDownloads) {
|
||||||
|
this.totalDownloads = totalDownloads;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package eu.dnetlib.repo.manager.service;
|
||||||
|
|
||||||
|
import eu.dnetlib.repo.manager.domain.RepositorySummaryInfo;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface DashboardService {
|
||||||
|
|
||||||
|
List<RepositorySummaryInfo> getRepositoriesSummaryInfo(@PathVariable("userEmail") String userEmail,
|
||||||
|
@PathVariable("page") String page,
|
||||||
|
@PathVariable("size") String size) throws JSONException;
|
||||||
|
}
|
|
@ -0,0 +1,84 @@
|
||||||
|
package eu.dnetlib.repo.manager.service;
|
||||||
|
|
||||||
|
import eu.dnetlib.domain.data.Repository;
|
||||||
|
import eu.dnetlib.repo.manager.domain.RepositorySummaryInfo;
|
||||||
|
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 eu.dnetlib.repo.manager.shared.broker.BrowseEntry;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DashboardServiceImpl implements DashboardService {
|
||||||
|
|
||||||
|
private static final Logger logger = Logger.getLogger(DashboardServiceImpl.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EmailUtils emailUtils;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RepositoryService repositoryService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private BrokerService brokerService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<RepositorySummaryInfo> getRepositoriesSummaryInfo(@PathVariable("userEmail") String userEmail,
|
||||||
|
@PathVariable("page") String page,
|
||||||
|
@PathVariable("size") String size) throws JSONException {
|
||||||
|
|
||||||
|
List<RepositorySummaryInfo> repositorySummaryInfoList = new ArrayList<>();
|
||||||
|
|
||||||
|
List<Repository> repositoriesOfUser = repositoryService.getRepositoriesOfUser(userEmail, page, size);
|
||||||
|
for(Repository repository: repositoriesOfUser) {
|
||||||
|
|
||||||
|
RepositorySummaryInfo repositorySummaryInfo = new RepositorySummaryInfo();
|
||||||
|
repositorySummaryInfo.setId(repository.getId());
|
||||||
|
repositorySummaryInfo.setRepositoryName(repository.getOfficialName());
|
||||||
|
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());
|
||||||
|
for(AggregationDetails aggregationDetails: aggregationDetailsList) {
|
||||||
|
if(aggregationDetails.getIndexedVersion()) {
|
||||||
|
repositorySummaryInfo.setRecordsCollected(aggregationDetails.getNumberOfRecords());
|
||||||
|
repositorySummaryInfo.setLastIndexedVersion(aggregationDetails.getDate());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
MetricsInfo metricsInfo = repositoryService.getMetricsInfoForRepository(repository.getId());
|
||||||
|
repositorySummaryInfo.setTotalDownloads(metricsInfo.getMetricsNumbers().getTotalDownloads());
|
||||||
|
repositorySummaryInfo.setTotalViews(metricsInfo.getMetricsNumbers().getTotalViews());
|
||||||
|
|
||||||
|
} catch (RepositoryServiceException e) {
|
||||||
|
logger.error("Exception getting metrics info for repository: " + repository.getId(), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
List<BrowseEntry> events = brokerService.getTopicsForDatasource(repository.getOfficialName());
|
||||||
|
Long totalEvents = 0L;
|
||||||
|
for(BrowseEntry browseEntry: events)
|
||||||
|
totalEvents += browseEntry.getSize();
|
||||||
|
repositorySummaryInfo.setEnrichmentEvents(totalEvents);
|
||||||
|
|
||||||
|
|
||||||
|
} catch (BrokerException e) {
|
||||||
|
logger.error("Exception getting broker events for repository: " + repository.getId(), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
repositorySummaryInfoList.add(repositorySummaryInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
return repositorySummaryInfoList;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue