50 lines
1.7 KiB
Java
50 lines
1.7 KiB
Java
|
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;
|
||
|
}
|
||
|
|
||
|
}
|