1
|
package eu.dnetlib.openaire.community;
|
2
|
|
3
|
import org.apache.commons.logging.Log;
|
4
|
import org.apache.commons.logging.LogFactory;
|
5
|
import org.springframework.beans.factory.annotation.Autowired;
|
6
|
import org.springframework.cache.annotation.CacheEvict;
|
7
|
import org.springframework.cache.annotation.Cacheable;
|
8
|
import org.springframework.stereotype.Component;
|
9
|
|
10
|
import java.text.ParseException;
|
11
|
import java.util.*;
|
12
|
|
13
|
@Component
|
14
|
public class CommunityClientImpl implements CommunityClient {
|
15
|
|
16
|
private static final Log log = LogFactory.getLog(CommunityClient.class);
|
17
|
|
18
|
// @Autowired
|
19
|
// private CommunityApiCore communityApiCore;
|
20
|
|
21
|
@Autowired
|
22
|
private CommunityCommon communityCommon;
|
23
|
|
24
|
// final Map<String, Set<String>> inverseListMap = new HashMap<>();
|
25
|
|
26
|
@Override
|
27
|
@Cacheable("community-cache")
|
28
|
public Map<String, Set<String>> getInverseZenodoCommunityMap () {
|
29
|
log.info("Creating the data structure. Not using cache");
|
30
|
final Map<String, Set<String>> inverseListMap = new HashMap<>();
|
31
|
|
32
|
try {
|
33
|
final List<CommunitySummary> communityList = communityCommon.listCommunities();
|
34
|
|
35
|
for(CommunitySummary cs :communityList){
|
36
|
final String communityId = cs.getId();
|
37
|
List<CommunityZenodoCommunity> czc = communityCommon.getCommunityZenodoCommunities(communityId);
|
38
|
for(CommunityZenodoCommunity zc:czc){
|
39
|
final String zenodoId = zc.getZenodoid();
|
40
|
if(!inverseListMap.containsKey(zenodoId)) {
|
41
|
inverseListMap.put(zc.getZenodoid(),new HashSet<>());
|
42
|
}
|
43
|
inverseListMap.get(zc.getZenodoid()).add(cs.getId());
|
44
|
}
|
45
|
|
46
|
}
|
47
|
} catch (CommunityException e) {
|
48
|
e.printStackTrace();
|
49
|
} catch (CommunityNotFoundException e) {
|
50
|
e.printStackTrace();
|
51
|
}
|
52
|
return inverseListMap;
|
53
|
}
|
54
|
|
55
|
@Override
|
56
|
@CacheEvict(value="community-cache",allEntries = true)
|
57
|
public void dropCache(){
|
58
|
log.info("dropping cache");
|
59
|
}
|
60
|
|
61
|
|
62
|
}
|