1 |
56387
|
stefania.m
|
package eu.dnetlib.repo.manager.service;
|
2 |
|
|
|
3 |
|
|
import eu.dnetlib.domain.data.Repository;
|
4 |
|
|
import eu.dnetlib.repo.manager.domain.RepositorySummaryInfo;
|
5 |
|
|
import eu.dnetlib.repo.manager.shared.AggregationDetails;
|
6 |
|
|
import eu.dnetlib.repo.manager.shared.BrokerException;
|
7 |
|
|
import eu.dnetlib.repo.manager.shared.MetricsInfo;
|
8 |
|
|
import eu.dnetlib.repo.manager.shared.RepositoryServiceException;
|
9 |
|
|
import eu.dnetlib.repo.manager.shared.broker.BrowseEntry;
|
10 |
|
|
import org.apache.log4j.Logger;
|
11 |
|
|
import org.json.JSONException;
|
12 |
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
13 |
56438
|
antonis.le
|
import org.springframework.stereotype.Service;
|
14 |
56387
|
stefania.m
|
import org.springframework.web.bind.annotation.PathVariable;
|
15 |
|
|
|
16 |
56438
|
antonis.le
|
import javax.xml.ws.ServiceMode;
|
17 |
56387
|
stefania.m
|
import java.util.ArrayList;
|
18 |
|
|
import java.util.List;
|
19 |
|
|
|
20 |
56438
|
antonis.le
|
@Service("dashboardService")
|
21 |
56387
|
stefania.m
|
public class DashboardServiceImpl implements DashboardService {
|
22 |
|
|
|
23 |
|
|
private static final Logger logger = Logger.getLogger(DashboardServiceImpl.class);
|
24 |
|
|
|
25 |
|
|
@Autowired
|
26 |
|
|
private EmailUtils emailUtils;
|
27 |
|
|
|
28 |
|
|
@Autowired
|
29 |
|
|
private RepositoryService repositoryService;
|
30 |
|
|
|
31 |
|
|
@Autowired
|
32 |
|
|
private BrokerService brokerService;
|
33 |
|
|
|
34 |
|
|
@Override
|
35 |
56761
|
ioannis.di
|
public List<RepositorySummaryInfo> getRepositoriesSummaryInfo(String userEmail,
|
36 |
|
|
String page,
|
37 |
|
|
String size){
|
38 |
56387
|
stefania.m
|
|
39 |
|
|
List<RepositorySummaryInfo> repositorySummaryInfoList = new ArrayList<>();
|
40 |
|
|
|
41 |
56761
|
ioannis.di
|
try {
|
42 |
56581
|
antonis.le
|
|
43 |
56761
|
ioannis.di
|
List<Repository> repositoriesOfUser = repositoryService.getRepositoriesOfUser(userEmail, page, size);
|
44 |
|
|
for(Repository repository: repositoriesOfUser) {
|
45 |
56387
|
stefania.m
|
|
46 |
56761
|
ioannis.di
|
RepositorySummaryInfo repositorySummaryInfo = new RepositorySummaryInfo();
|
47 |
|
|
repositorySummaryInfo.setId(repository.getId());
|
48 |
|
|
repositorySummaryInfo.setRepositoryName(repository.getOfficialName());
|
49 |
|
|
repositorySummaryInfo.setLogoURL(repository.getLogoUrl());
|
50 |
56387
|
stefania.m
|
|
51 |
56761
|
ioannis.di
|
//TODO getRepositoryAggregations returns only the 20 more recent items. Is it positive that we will find an indexed version there?
|
52 |
57176
|
ioannis.di
|
List<AggregationDetails> aggregationDetailsList = repositoryService.getRepositoryAggregations(repository.getId(),0,20);
|
53 |
56761
|
ioannis.di
|
for(AggregationDetails aggregationDetails: aggregationDetailsList) {
|
54 |
|
|
if(aggregationDetails.getIndexedVersion()) {
|
55 |
|
|
repositorySummaryInfo.setRecordsCollected(aggregationDetails.getNumberOfRecords());
|
56 |
|
|
repositorySummaryInfo.setLastIndexedVersion(aggregationDetails.getDate());
|
57 |
|
|
break;
|
58 |
|
|
}
|
59 |
|
|
}
|
60 |
56387
|
stefania.m
|
|
61 |
56761
|
ioannis.di
|
try {
|
62 |
56387
|
stefania.m
|
|
63 |
56761
|
ioannis.di
|
MetricsInfo metricsInfo = repositoryService.getMetricsInfoForRepository(repository.getId());
|
64 |
|
|
repositorySummaryInfo.setTotalDownloads(metricsInfo.getMetricsNumbers().getTotalDownloads());
|
65 |
|
|
repositorySummaryInfo.setTotalViews(metricsInfo.getMetricsNumbers().getTotalViews());
|
66 |
56387
|
stefania.m
|
|
67 |
56761
|
ioannis.di
|
} catch (RepositoryServiceException e) {
|
68 |
|
|
logger.error("Exception getting metrics info for repository: " + repository.getId(), e);
|
69 |
|
|
}
|
70 |
56387
|
stefania.m
|
|
71 |
56761
|
ioannis.di
|
try {
|
72 |
56387
|
stefania.m
|
|
73 |
56761
|
ioannis.di
|
List<BrowseEntry> events = brokerService.getTopicsForDatasource(repository.getOfficialName());
|
74 |
|
|
Long totalEvents = 0L;
|
75 |
|
|
for(BrowseEntry browseEntry: events)
|
76 |
|
|
totalEvents += browseEntry.getSize();
|
77 |
|
|
repositorySummaryInfo.setEnrichmentEvents(totalEvents);
|
78 |
56387
|
stefania.m
|
|
79 |
|
|
|
80 |
56761
|
ioannis.di
|
} catch (BrokerException e) {
|
81 |
|
|
logger.error("Exception getting broker events for repository: " + repository.getId(), e);
|
82 |
|
|
}
|
83 |
56387
|
stefania.m
|
|
84 |
56761
|
ioannis.di
|
repositorySummaryInfoList.add(repositorySummaryInfo);
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
} catch (Exception e) {
|
88 |
|
|
logger.error("Something baad happened!", e);
|
89 |
56387
|
stefania.m
|
}
|
90 |
|
|
|
91 |
|
|
return repositorySummaryInfoList;
|
92 |
|
|
}
|
93 |
|
|
}
|