1 |
51837
|
tsampikos.
|
package eu.dnetlib.statsapi.repositories;
|
2 |
|
|
|
3 |
|
|
import eu.dnetlib.statsapi.domain.Funder;
|
4 |
|
|
import eu.dnetlib.statsapi.domain.Result;
|
5 |
|
|
|
6 |
|
|
import org.apache.log4j.Logger;
|
7 |
|
|
import org.springframework.data.redis.core.HashOperations;
|
8 |
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
9 |
|
|
import org.springframework.stereotype.Repository;
|
10 |
|
|
|
11 |
|
|
import java.util.ArrayList;
|
12 |
|
|
import java.util.List;
|
13 |
|
|
|
14 |
|
|
@Repository
|
15 |
|
|
public class FunderRepository {
|
16 |
|
|
|
17 |
|
|
private RedisTemplate<String, String> redisTemplate;
|
18 |
|
|
|
19 |
|
|
private HashOperations<String, String, String> jedis;
|
20 |
|
|
|
21 |
|
|
private final Logger log = Logger.getLogger(this.getClass());
|
22 |
|
|
|
23 |
|
|
public FunderRepository(RedisTemplate<String, String> redisTemplate) {
|
24 |
|
|
this.redisTemplate = redisTemplate;
|
25 |
|
|
this.jedis = this.redisTemplate.opsForHash();
|
26 |
|
|
}
|
27 |
|
|
|
28 |
|
|
public Result getFunder(String funder) {
|
29 |
|
|
Boolean not_found = true;
|
30 |
|
|
ArrayList<String> items = new ArrayList<>();
|
31 |
|
|
items.add(funder.toLowerCase() + "pubstotal");
|
32 |
|
|
items.add(funder.toLowerCase() + "oapubs");
|
33 |
|
|
items.add(funder.toLowerCase() + "embpubs");
|
34 |
|
|
items.add(funder.toLowerCase() + "respubs");
|
35 |
|
|
items.add(funder.toLowerCase() + "projtotal");
|
36 |
|
|
items.add(funder.toLowerCase() + "projpubs");
|
37 |
|
|
|
38 |
|
|
List<String> result = jedis.multiGet("STATS_NUMBERS", items);
|
39 |
|
|
int pubs = 0, oa = 0, emb = 0, res = 0, proj = 0, proj_pubs = 0;
|
40 |
|
|
if (result.get(0) != null) {
|
41 |
|
|
pubs = Integer.parseInt(result.get(0).replaceAll(",", ""));
|
42 |
|
|
not_found = false;
|
43 |
|
|
}
|
44 |
|
|
if (result.get(1) != null) {
|
45 |
|
|
oa = Integer.parseInt(result.get(1).replaceAll(",", ""));
|
46 |
|
|
not_found = false;
|
47 |
|
|
}
|
48 |
|
|
if (result.get(2) != null) {
|
49 |
|
|
emb = Integer.parseInt(result.get(2).replaceAll(",", ""));
|
50 |
|
|
not_found = false;
|
51 |
|
|
}
|
52 |
|
|
if (result.get(3) != null) {
|
53 |
|
|
res = Integer.parseInt(result.get(3).replaceAll(",", ""));
|
54 |
|
|
not_found = false;
|
55 |
|
|
}
|
56 |
|
|
if (result.get(4) != null) {
|
57 |
|
|
proj = Integer.parseInt(result.get(4).replaceAll(",", ""));
|
58 |
|
|
not_found = false;
|
59 |
|
|
}
|
60 |
|
|
if (result.get(5) != null) {
|
61 |
|
|
proj_pubs = Integer.parseInt(result.get(5).replaceAll(",", ""));
|
62 |
|
|
not_found = false;
|
63 |
|
|
}
|
64 |
|
|
|
65 |
|
|
if (not_found) {
|
66 |
|
|
return new Result("Not Found", "400", null);
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
return new Result("OK", "200", new Funder(pubs, oa, emb, res, proj, proj_pubs));
|
70 |
|
|
}
|
71 |
|
|
}
|