Refactor the "Statistics" code:
- Merge the Aggregators' code inside "StatsServiceImpl.java". - Remove the Hystrix related code, since it wasn't really used. - Add exceptions-handling and error-checking.
This commit is contained in:
parent
01ba340f47
commit
36b17e4ef1
23
pom.xml
23
pom.xml
|
@ -60,19 +60,13 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-hystrix -->
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
|
||||
<version>2.2.9.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||
<version>3.0.1</version>
|
||||
</dependency>
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||
<version>3.0.1</version>
|
||||
</dependency>
|
||||
-->
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>javax.el</groupId>
|
||||
|
@ -323,11 +317,6 @@
|
|||
<artifactId>cors-filter</artifactId>
|
||||
<version>2.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.netflix.hystrix</groupId>
|
||||
<artifactId>hystrix-core</artifactId>
|
||||
<version>1.5.18</version>
|
||||
</dependency>
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>com.netflix.rxjava</groupId>
|
||||
|
|
|
@ -1,17 +1,26 @@
|
|||
package eu.dnetlib.repo.manager.service;
|
||||
|
||||
import eu.dnetlib.repo.manager.service.customHystrixCommands.*;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@Service("statsService")
|
||||
public class StatsServiceImpl implements StatsService {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(StatsServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
RestTemplate restTemplate;
|
||||
|
||||
|
@ -24,27 +33,288 @@ public class StatsServiceImpl implements StatsService {
|
|||
|
||||
@Override
|
||||
public Map getStatistics() {
|
||||
|
||||
UsageStatsTotalHystrixCommand usageStatsTotalHystrixCommand = new UsageStatsTotalHystrixCommand(usagestatsEvents,restTemplate);
|
||||
DataRepositoriesHystrixCommand dataRepositoriesHystrixCommand = new DataRepositoriesHystrixCommand(baseAddress,restTemplate);
|
||||
AggregatorsHystrixCommand aggregatorsHystrixCommand = new AggregatorsHystrixCommand(baseAddress,restTemplate);
|
||||
LiteratureHystrixCommand literatureHystrixCommand = new LiteratureHystrixCommand(baseAddress,restTemplate);
|
||||
JournalHystrixCommand journalHystrixCommand = new JournalHystrixCommand(baseAddress,restTemplate);
|
||||
PublicationHystrixCommand publicationHystrixCommand = new PublicationHystrixCommand(baseAddress,restTemplate);
|
||||
DatasetsHystrixCommand datasetsHystrixCommand = new DatasetsHystrixCommand(baseAddress,restTemplate);
|
||||
SoftwareHystrixCommand softwareHystrixCommand = new SoftwareHystrixCommand(baseAddress,restTemplate);
|
||||
LastYearUsageStatsHystrixCommand lastYearUsageStatsHystrixCommand = new LastYearUsageStatsHystrixCommand(usagestatsBaseAddress,restTemplate);
|
||||
|
||||
Map<String,Object> stats = new HashMap<>();
|
||||
stats.put("aggregators",aggregatorsHystrixCommand.execute());
|
||||
stats.put("dataRepositories",dataRepositoriesHystrixCommand.execute());
|
||||
stats.put("literature",literatureHystrixCommand.execute());
|
||||
stats.put("journal",journalHystrixCommand.execute());
|
||||
stats.put("publications",publicationHystrixCommand.execute());
|
||||
stats.put("datasets",datasetsHystrixCommand.execute());
|
||||
stats.put("software",softwareHystrixCommand.execute());
|
||||
stats.put("lastYearUsagestats", lastYearUsageStatsHystrixCommand.execute());
|
||||
stats.put("usagestats",usageStatsTotalHystrixCommand.execute());
|
||||
stats.put("aggregators", this.getAggregatorsStats());
|
||||
stats.put("dataRepositories", this.getDataRepositoriesMetadata());
|
||||
stats.put("literature", this.getLiteratureStats());
|
||||
stats.put("journal", this.getJournalsStats());
|
||||
stats.put("publications", this.getPublicationStats());
|
||||
stats.put("datasets", this.getDatasetsStats());
|
||||
stats.put("software", this.getSoftwareStats());
|
||||
stats.put("lastYearUsagestats", this.getLastYearUsageStats());
|
||||
stats.put("usagestats", this.getUsageStatsTotal());
|
||||
return stats;
|
||||
}
|
||||
|
||||
|
||||
private String getAggregatorsStats()
|
||||
{
|
||||
String url = baseAddress + "/resources" +
|
||||
"?query= " +
|
||||
" oaftype exact datasource and " +
|
||||
" ( datasourcetypename exact Institutional Repository Aggregator " +
|
||||
" or datasourcetypename exact Publication Repository Aggregator )";
|
||||
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(url)
|
||||
.queryParam("page", 0)
|
||||
.queryParam("size", 0)
|
||||
.queryParam("format", "json")
|
||||
.build().encode();
|
||||
|
||||
try {
|
||||
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||
Map metadata = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("meta");
|
||||
return String.valueOf(metadata.get("total"));
|
||||
} catch ( RestClientException rce ) {
|
||||
LOGGER.error(rce.getMessage());
|
||||
return null;
|
||||
} catch ( Exception e ) {
|
||||
LOGGER.error("", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getDataRepositoriesMetadata()
|
||||
{
|
||||
String url = baseAddress + "/resources" +
|
||||
"?query= " +
|
||||
" oaftype exact datasource and " +
|
||||
" datasourcetypename exact Data Repository ";
|
||||
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(url)
|
||||
.queryParam("page",0)
|
||||
.queryParam("size",0)
|
||||
.queryParam("format","json")
|
||||
.build().encode();
|
||||
|
||||
try {
|
||||
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||
Map metadata = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("meta");
|
||||
if ( metadata == null ) {
|
||||
LOGGER.error("The metadata was null!");
|
||||
return null;
|
||||
}
|
||||
return String.valueOf(metadata.get("total"));
|
||||
} catch ( RestClientException rce ) {
|
||||
LOGGER.error(rce.getMessage());
|
||||
return null;
|
||||
} catch ( Exception e ) {
|
||||
LOGGER.error("", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getLiteratureStats()
|
||||
{
|
||||
String url = baseAddress + "/resources" +
|
||||
"?query= " +
|
||||
" oaftype exact datasource and " +
|
||||
" ( datasourcetypename exact Institutional Repository " +
|
||||
" or datasourcetypename exact Publication Repository )";
|
||||
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(url)
|
||||
.queryParam("page", 0)
|
||||
.queryParam("size", 0)
|
||||
.queryParam("format", "json")
|
||||
.build().encode();
|
||||
|
||||
try {
|
||||
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||
Map metadata = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("meta");
|
||||
if ( metadata == null ) {
|
||||
LOGGER.error("The metadata was null!");
|
||||
return null;
|
||||
}
|
||||
return String.valueOf(metadata.get("total"));
|
||||
} catch ( RestClientException rce ) {
|
||||
LOGGER.error(rce.getMessage());
|
||||
return null;
|
||||
} catch ( Exception e ) {
|
||||
LOGGER.error("", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getJournalsStats()
|
||||
{
|
||||
String url = baseAddress + "/resources" +
|
||||
"?query= " +
|
||||
" oaftype exact datasource and " +
|
||||
" datasourcetypename exact Journal";
|
||||
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(url)
|
||||
.queryParam("page", 0)
|
||||
.queryParam("size", 0)
|
||||
.queryParam("format", "json")
|
||||
.build().encode();
|
||||
|
||||
try {
|
||||
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||
Map metadata = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("meta");
|
||||
if ( metadata == null ) {
|
||||
LOGGER.error("The metadata was null!");
|
||||
return null;
|
||||
}
|
||||
return String.valueOf(metadata.get("total"));
|
||||
} catch ( RestClientException rce ) {
|
||||
LOGGER.error(rce.getMessage());
|
||||
return null;
|
||||
} catch ( Exception e ) {
|
||||
LOGGER.error("", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getPublicationStats()
|
||||
{
|
||||
String url = baseAddress + "/publications/count";
|
||||
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(url)
|
||||
.queryParam("page", 0)
|
||||
.queryParam("size", 0)
|
||||
.queryParam("format", "json")
|
||||
.build().encode();
|
||||
|
||||
try {
|
||||
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||
Map metadata = (Map<?, ?>) rs.getBody();
|
||||
if ( metadata == null ) {
|
||||
LOGGER.error("The metadata was null!");
|
||||
return null;
|
||||
}
|
||||
return String.valueOf(metadata.get("total"));
|
||||
} catch ( RestClientException rce ) {
|
||||
LOGGER.error(rce.getMessage());
|
||||
return null;
|
||||
} catch ( Exception e ) {
|
||||
LOGGER.error("", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getDatasetsStats()
|
||||
{
|
||||
String url = baseAddress + "/datasets/count";
|
||||
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(url)
|
||||
.queryParam("page", 0)
|
||||
.queryParam("size", 0)
|
||||
.queryParam("format", "json")
|
||||
.build().encode();
|
||||
|
||||
try {
|
||||
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||
Map metadata = (Map<?, ?>) rs.getBody();
|
||||
if ( metadata == null ) {
|
||||
LOGGER.error("The metadata was null!");
|
||||
return null;
|
||||
}
|
||||
return String.valueOf(metadata.get("total"));
|
||||
} catch ( RestClientException rce ) {
|
||||
LOGGER.error(rce.getMessage());
|
||||
return null;
|
||||
} catch ( Exception e ) {
|
||||
LOGGER.error("", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getSoftwareStats()
|
||||
{
|
||||
String url = baseAddress + "/software/count";
|
||||
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(url)
|
||||
.queryParam("page", 0)
|
||||
.queryParam("size", 0)
|
||||
.queryParam("format", "json")
|
||||
.build().encode();
|
||||
|
||||
try {
|
||||
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||
Map metadata = (Map<?, ?>) rs.getBody();
|
||||
if ( metadata == null ) {
|
||||
LOGGER.error("The metadata was null!");
|
||||
return null;
|
||||
}
|
||||
return String.valueOf(metadata.get("total"));
|
||||
} catch ( RestClientException rce ) {
|
||||
LOGGER.error(rce.getMessage());
|
||||
return null;
|
||||
} catch ( Exception e ) {
|
||||
LOGGER.error("", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Map<String,Object> getLastYearUsageStats()
|
||||
{
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(usagestatsBaseAddress + "/totals")
|
||||
.build().encode();
|
||||
|
||||
try {
|
||||
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||
|
||||
List yearly_stats = (List) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("yearly_stats");
|
||||
Map lastYear = (Map) yearly_stats.get(yearly_stats.size() - 2);
|
||||
Integer downloads = (Integer) lastYear.get("downloads");
|
||||
Integer views = (Integer) lastYear.get("views");
|
||||
Integer year = (Integer) lastYear.get("year");
|
||||
|
||||
Map<String, Object> usagestats = new HashMap<>();
|
||||
usagestats.put("number", String.valueOf(downloads + views));
|
||||
usagestats.put("year", year);
|
||||
return usagestats;
|
||||
} catch ( RestClientException rce ) {
|
||||
LOGGER.error(rce.getMessage());
|
||||
return null;
|
||||
} catch ( Exception e ) {
|
||||
LOGGER.error("", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Integer getUsageStatsTotal()
|
||||
{
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(usagestatsEvents)
|
||||
.build().encode();
|
||||
|
||||
try {
|
||||
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||
Map metadata = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("totals");
|
||||
if ( metadata == null ) {
|
||||
LOGGER.error("The metadata was null!");
|
||||
return null;
|
||||
}
|
||||
|
||||
// String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
|
||||
// JSONObject resultSet = new JSONObject(rs);
|
||||
// JSONObject totals = resultSet.getJSONObject("totals");
|
||||
|
||||
return (Integer) metadata.get("events");
|
||||
} catch ( RestClientException rce ) {
|
||||
LOGGER.error(rce.getMessage());
|
||||
return null;
|
||||
} catch ( Exception e ) {
|
||||
LOGGER.error("", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
package eu.dnetlib.repo.manager.service.customHystrixCommands;
|
||||
|
||||
import com.netflix.hystrix.HystrixCommand;
|
||||
import com.netflix.hystrix.HystrixCommandGroupKey;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class AggregatorsHystrixCommand extends HystrixCommand<String> {
|
||||
|
||||
RestTemplate restTemplate;
|
||||
String baseAddress;
|
||||
|
||||
public AggregatorsHystrixCommand(String baseAddress, RestTemplate restTemplate) {
|
||||
super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
|
||||
this.baseAddress = baseAddress;
|
||||
this.restTemplate = restTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String run() throws Exception {
|
||||
String url = baseAddress + "/resources" +
|
||||
"?query= " +
|
||||
" oaftype exact datasource and " +
|
||||
" ( datasourcetypename exact Institutional Repository Aggregator " +
|
||||
" or datasourcetypename exact Publication Repository Aggregator )";
|
||||
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(url)
|
||||
.queryParam("page", 0)
|
||||
.queryParam("size", 0)
|
||||
.queryParam("format", "json")
|
||||
.build().encode();
|
||||
|
||||
ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||
Map metadata = (Map) ((Map) rs.getBody()).get("meta");
|
||||
return String.valueOf(metadata.get("total"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFallback() {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
package eu.dnetlib.repo.manager.service.customHystrixCommands;
|
||||
|
||||
import com.netflix.hystrix.HystrixCommand;
|
||||
import com.netflix.hystrix.HystrixCommandGroupKey;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class DataRepositoriesHystrixCommand extends HystrixCommand<String> {
|
||||
|
||||
RestTemplate restTemplate ;
|
||||
private String baseAddress;
|
||||
|
||||
public DataRepositoriesHystrixCommand(String baseAddress,RestTemplate restTemplate) {
|
||||
super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
|
||||
this.baseAddress = baseAddress;
|
||||
this.restTemplate = restTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String run() {
|
||||
String url = baseAddress+"/resources" +
|
||||
"?query= " +
|
||||
" oaftype exact datasource and " +
|
||||
" datasourcetypename exact Data Repository ";
|
||||
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(url)
|
||||
.queryParam("page",0)
|
||||
.queryParam("size",0)
|
||||
.queryParam("format","json")
|
||||
.build().encode();
|
||||
|
||||
ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET,null,Map.class);
|
||||
Map metadata = (Map) ((Map)rs.getBody()).get("meta");
|
||||
return String.valueOf(metadata.get("total"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFallback() {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
package eu.dnetlib.repo.manager.service.customHystrixCommands;
|
||||
|
||||
import com.netflix.hystrix.HystrixCommand;
|
||||
import com.netflix.hystrix.HystrixCommandGroupKey;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class DatasetsHystrixCommand extends HystrixCommand<String> {
|
||||
|
||||
RestTemplate restTemplate;
|
||||
String baseAddress;
|
||||
|
||||
public DatasetsHystrixCommand(String baseAddress,RestTemplate restTemplate) {
|
||||
super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
|
||||
this.restTemplate = restTemplate;
|
||||
this.baseAddress = baseAddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String run() throws Exception {
|
||||
String url = baseAddress+"/datasets/count";
|
||||
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(url)
|
||||
.queryParam("page", 0)
|
||||
.queryParam("size", 0)
|
||||
.queryParam("format", "json")
|
||||
.build().encode();
|
||||
|
||||
ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||
Map metadata = (Map) (rs.getBody());
|
||||
return String.valueOf(metadata.get("total"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFallback() {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
package eu.dnetlib.repo.manager.service.customHystrixCommands;
|
||||
|
||||
import com.netflix.hystrix.HystrixCommand;
|
||||
import com.netflix.hystrix.HystrixCommandGroupKey;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class JournalHystrixCommand extends HystrixCommand<String> {
|
||||
|
||||
RestTemplate restTemplate;
|
||||
private String baseAddress;
|
||||
|
||||
public JournalHystrixCommand(String baseAddress, RestTemplate restTemplate) {
|
||||
super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
|
||||
this.baseAddress = baseAddress;
|
||||
this.restTemplate = restTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String run() throws Exception {
|
||||
String url = baseAddress+"/resources"+
|
||||
"?query= " +
|
||||
" oaftype exact datasource and " +
|
||||
" datasourcetypename exact Journal";
|
||||
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(url)
|
||||
.queryParam("page", 0)
|
||||
.queryParam("size", 0)
|
||||
.queryParam("format", "json")
|
||||
.build().encode();
|
||||
|
||||
ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||
Map metadata = (Map) ((Map) rs.getBody()).get("meta");
|
||||
return String.valueOf(metadata.get("total"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFallback() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
package eu.dnetlib.repo.manager.service.customHystrixCommands;
|
||||
|
||||
import com.netflix.hystrix.HystrixCommand;
|
||||
import com.netflix.hystrix.HystrixCommandGroupKey;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class LastYearUsageStatsHystrixCommand extends HystrixCommand<Map> {
|
||||
|
||||
RestTemplate restTemplate;
|
||||
String usagestatsBaseAddress;
|
||||
|
||||
public LastYearUsageStatsHystrixCommand(String usagestatsBaseAddress,RestTemplate restTemplate) {
|
||||
super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
|
||||
this.usagestatsBaseAddress = usagestatsBaseAddress;
|
||||
this.restTemplate = restTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map run() throws Exception {
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(usagestatsBaseAddress + "/totals")
|
||||
.build().encode();
|
||||
|
||||
ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET,null,Map.class);
|
||||
|
||||
List yearly_stats = (List) ((Map)rs.getBody()).get("yearly_stats");
|
||||
Map lastYear = (Map) yearly_stats.get(yearly_stats.size()-1);
|
||||
Integer downloads = (Integer) lastYear.get("downloads");
|
||||
Integer views = (Integer) lastYear.get("views");
|
||||
Integer year = (Integer) lastYear.get("year");
|
||||
|
||||
Map<String,Object> usagestats = new HashMap<>();
|
||||
usagestats.put("number",String.valueOf(downloads+views));
|
||||
usagestats.put("year",year);
|
||||
|
||||
return usagestats;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map getFallback() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
package eu.dnetlib.repo.manager.service.customHystrixCommands;
|
||||
|
||||
import com.netflix.hystrix.HystrixCommand;
|
||||
import com.netflix.hystrix.HystrixCommandGroupKey;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class LiteratureHystrixCommand extends HystrixCommand<String> {
|
||||
|
||||
RestTemplate restTemplate;
|
||||
private String baseAddress;
|
||||
|
||||
public LiteratureHystrixCommand(String baseAddress , RestTemplate restTemplate) {
|
||||
super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
|
||||
this.baseAddress = baseAddress;
|
||||
this.restTemplate = restTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String run() throws Exception {
|
||||
String url = baseAddress+"/resources"+
|
||||
"?query= " +
|
||||
" oaftype exact datasource and " +
|
||||
" ( datasourcetypename exact Institutional Repository " +
|
||||
" or datasourcetypename exact Publication Repository )";
|
||||
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(url)
|
||||
.queryParam("page", 0)
|
||||
.queryParam("size", 0)
|
||||
.queryParam("format", "json")
|
||||
.build().encode();
|
||||
|
||||
ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||
Map metadata = (Map) ((Map) rs.getBody()).get("meta");
|
||||
return String.valueOf(metadata.get("total"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFallback() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
package eu.dnetlib.repo.manager.service.customHystrixCommands;
|
||||
|
||||
import com.netflix.hystrix.HystrixCommand;
|
||||
import com.netflix.hystrix.HystrixCommandGroupKey;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class PublicationHystrixCommand extends HystrixCommand<String> {
|
||||
|
||||
RestTemplate restTemplate;
|
||||
private String baseAddress;
|
||||
|
||||
public PublicationHystrixCommand(String baseAddress, RestTemplate restTemplate) {
|
||||
super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
|
||||
this.baseAddress = baseAddress;
|
||||
this.restTemplate = restTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String run() throws Exception {
|
||||
String url = baseAddress + "/publications/count";
|
||||
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(url)
|
||||
.queryParam("page", 0)
|
||||
.queryParam("size", 0)
|
||||
.queryParam("format", "json")
|
||||
.build().encode();
|
||||
|
||||
ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||
Map metadata = (Map) (rs.getBody());
|
||||
return String.valueOf(metadata.get("total"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFallback() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
package eu.dnetlib.repo.manager.service.customHystrixCommands;
|
||||
|
||||
import com.netflix.hystrix.HystrixCommand;
|
||||
import com.netflix.hystrix.HystrixCommandGroupKey;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class SoftwareHystrixCommand extends HystrixCommand<String> {
|
||||
|
||||
String baseAddress;
|
||||
RestTemplate restTemplate;
|
||||
|
||||
public SoftwareHystrixCommand(String baseAddress, RestTemplate restTemplate) {
|
||||
super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
|
||||
this.baseAddress = baseAddress;
|
||||
this.restTemplate = restTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String run() {
|
||||
String url = baseAddress + "/software/count";
|
||||
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(url)
|
||||
.queryParam("page", 0)
|
||||
.queryParam("size", 0)
|
||||
.queryParam("format", "json")
|
||||
.build().encode();
|
||||
|
||||
ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
|
||||
Map metadata = (Map) (rs.getBody());
|
||||
return String.valueOf(metadata.get("total"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFallback() {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package eu.dnetlib.repo.manager.service.customHystrixCommands;
|
||||
|
||||
import com.netflix.hystrix.HystrixCommand;
|
||||
import com.netflix.hystrix.HystrixCommandGroupKey;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class UsageStatsTotalHystrixCommand extends HystrixCommand<Integer> {
|
||||
|
||||
RestTemplate restTemplate ;
|
||||
String usagestatsEvents;
|
||||
|
||||
public UsageStatsTotalHystrixCommand(String usagestatsEvents,RestTemplate restTemplate) {
|
||||
super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
|
||||
this.usagestatsEvents = usagestatsEvents;
|
||||
this.restTemplate = restTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Integer run() {
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(usagestatsEvents)
|
||||
.build().encode();
|
||||
|
||||
ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET,null,Map.class);
|
||||
Map metadata = (Map) ((Map)rs.getBody()).get("totals");
|
||||
// String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
|
||||
// JSONObject resultSet = new JSONObject(rs);
|
||||
// JSONObject totals = resultSet.getJSONObject("totals");
|
||||
return (Integer) metadata.get("events");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Integer getFallback() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue