Revision 55912
Added by Miriam Baglioni almost 5 years ago
CommunityConfiguration.java | ||
---|---|---|
3 | 3 |
import com.google.common.collect.Lists; |
4 | 4 |
import com.google.common.collect.Maps; |
5 | 5 |
import com.google.gson.Gson; |
6 |
|
|
7 |
import eu.dnetlib.data.bulktag.selectioncriteria.VerbResolver; |
|
6 | 8 |
import org.apache.commons.logging.Log; |
7 | 9 |
import org.apache.commons.logging.LogFactory; |
8 | 10 |
|
11 |
|
|
9 | 12 |
import java.util.ArrayList; |
10 | 13 |
import java.util.HashMap; |
11 | 14 |
import java.util.List; |
12 | 15 |
import java.util.Map; |
13 | 16 |
import java.util.stream.Collectors; |
17 |
import java.util.stream.Stream; |
|
14 | 18 |
|
15 | 19 |
/** |
16 | 20 |
* Created by miriam on 02/08/2018. |
... | ... | |
19 | 23 |
|
20 | 24 |
private static final Log log = LogFactory.getLog(CommunityConfiguration.class); |
21 | 25 |
|
26 |
|
|
22 | 27 |
enum MapModes{ |
23 | 28 |
SUBJECT_MAP, |
24 | 29 |
DATASOURCE_MAP, |
... | ... | |
27 | 32 |
|
28 | 33 |
private Map<String,Community> communities; |
29 | 34 |
|
35 |
|
|
30 | 36 |
//map subject -> communityid |
31 |
private transient Map<String,List<Pair<String,SelectionCriteria>>> subjectMap = new HashMap<>();
|
|
37 |
private transient Map<String,List<Pair<String,SelectionConstraints>>> subjectMap = new HashMap<>();
|
|
32 | 38 |
//map datasourceid -> communityid |
33 |
private transient Map<String,List<Pair<String,SelectionCriteria>>> datasourceMap = new HashMap<>();
|
|
39 |
private transient Map<String,List<Pair<String,SelectionConstraints>>> datasourceMap = new HashMap<>();
|
|
34 | 40 |
//map zenodocommunityid -> communityid |
35 |
private transient Map<String,List<Pair<String,SelectionCriteria>>> zenodocommunityMap = new HashMap<>();
|
|
41 |
private transient Map<String,List<Pair<String,SelectionConstraints>>> zenodocommunityMap = new HashMap<>();
|
|
36 | 42 |
|
37 |
public CommunityConfiguration(final Map<String, Community> communities) {
|
|
43 |
CommunityConfiguration(final Map<String, Community> communities) { |
|
38 | 44 |
this.communities = communities; |
39 | 45 |
init(); |
40 | 46 |
} |
41 | 47 |
|
42 |
public void init() {
|
|
48 |
void init() { |
|
43 | 49 |
|
44 | 50 |
if (subjectMap == null) { |
45 | 51 |
subjectMap = Maps.newHashMap(); |
... | ... | |
55 | 61 |
//get subjects |
56 | 62 |
final String id = c.getId(); |
57 | 63 |
for(String sbj : c.getSubjects()){ |
58 |
Pair<String,SelectionCriteria> p = new Pair<>(id,new SelectionCriteria(null));
|
|
64 |
Pair<String,SelectionConstraints> p = new Pair<>(id,new SelectionConstraints());
|
|
59 | 65 |
add(sbj.toLowerCase().trim() , p, subjectMap); |
60 | 66 |
} |
61 | 67 |
//get datasources |
62 | 68 |
for(Datasource d: c.getDatasources()){ |
69 |
|
|
63 | 70 |
add(d.getOpenaireId(),new Pair<>(id,d.getSelCriteria()),datasourceMap); |
64 | 71 |
} |
65 | 72 |
//get zenodo communities |
... | ... | |
70 | 77 |
} |
71 | 78 |
} |
72 | 79 |
|
73 |
private void add(String key,Pair<String,SelectionCriteria> value, Map<String,List<Pair<String,SelectionCriteria>>> map){
|
|
74 |
List<Pair<String,SelectionCriteria>> values = map.get(key);
|
|
80 |
private void add(String key, Pair<String,SelectionConstraints> value, Map<String,List<Pair<String,SelectionConstraints>>> map){
|
|
81 |
List<Pair<String,SelectionConstraints>> values = map.get(key);
|
|
75 | 82 |
|
76 | 83 |
if (values == null){ |
77 | 84 |
values = new ArrayList<>(); |
... | ... | |
80 | 87 |
values.add(value); |
81 | 88 |
} |
82 | 89 |
|
83 |
public List<Pair<String,SelectionCriteria>> getCommunityForSubject(String sbj){
|
|
90 |
public List<Pair<String,SelectionConstraints>> getCommunityForSubject(String sbj){
|
|
84 | 91 |
return subjectMap.get(sbj); |
85 | 92 |
} |
86 | 93 |
|
87 |
public List<Pair<String,SelectionCriteria>> getCommunityForDatasource(String dts){
|
|
94 |
public List<Pair<String,SelectionConstraints>> getCommunityForDatasource(String dts){
|
|
88 | 95 |
return datasourceMap.get(dts); |
89 | 96 |
} |
90 | 97 |
|
91 |
public List<Pair<String,SelectionCriteria>> getCommunityForZenodoCommunity(String zc){ |
|
98 |
// public List<String> getCommunityForDatasource(String dts, Map<String,String>param){ |
|
99 |
// List<Pair<String,SelectionConstraints>> lp = datasourceMap.get(dts); |
|
100 |
// if (lp==null) |
|
101 |
// return Lists.newArrayList(); |
|
102 |
// return lp.stream().map(p -> { |
|
103 |
// if (p.getSnd() == null) |
|
104 |
// return p.getFst(); |
|
105 |
// if (((SelectionConstraints) p.getSnd()).verifyCriteria(param)) |
|
106 |
// return p.getFst(); |
|
107 |
// else |
|
108 |
// return null; |
|
109 |
// }).collect(Collectors.toList()); |
|
110 |
// |
|
111 |
// } |
|
112 |
|
|
113 |
public List<String> getCommunityForDatasource(String dts, Map<String,List<String>>param){ |
|
114 |
List<Pair<String,SelectionConstraints>> lp = datasourceMap.get(dts); |
|
115 |
if (lp==null) |
|
116 |
return Lists.newArrayList(); |
|
117 |
return lp.stream().map(p -> { |
|
118 |
if (p.getSnd() == null) |
|
119 |
return p.getFst(); |
|
120 |
if (((SelectionConstraints) p.getSnd()).verifyCriteria(param)) |
|
121 |
return p.getFst(); |
|
122 |
else |
|
123 |
return null; |
|
124 |
}).collect(Collectors.toList()); |
|
125 |
|
|
126 |
} |
|
127 |
|
|
128 |
public List<Pair<String,SelectionConstraints>> getCommunityForZenodoCommunity(String zc){ |
|
92 | 129 |
return zenodocommunityMap.get(zc); |
93 | 130 |
} |
94 | 131 |
|
... | ... | |
107 | 144 |
return getContextIds(zenodocommunityMap.get(value.toLowerCase())); |
108 | 145 |
} |
109 | 146 |
|
110 |
private List<String> getContextIds(List<Pair<String, SelectionCriteria>> list) {
|
|
147 |
private List<String> getContextIds(List<Pair<String, SelectionConstraints>> list) {
|
|
111 | 148 |
if (list != null) { |
112 | 149 |
return list.stream().map(p -> p.getFst()).collect(Collectors.toList()); |
113 | 150 |
} |
114 | 151 |
return Lists.newArrayList(); |
115 | 152 |
} |
116 | 153 |
|
154 |
|
|
117 | 155 |
/* |
118 |
public SelectionCriteria getSelCriteria(String value, String community, MapModes map_mode){
|
|
156 |
public Constraints getSelCriteria(String value, String community, MapModes map_mode){
|
|
119 | 157 |
|
120 |
Map<String,List<Pair<String,SelectionCriteria>>> map = null;
|
|
158 |
Map<String,List<Pair<String,Constraints>>> map = null;
|
|
121 | 159 |
if(map_mode == MapModes.DATASOURCE_MAP) |
122 | 160 |
map = datasourceMap; |
123 | 161 |
else |
... | ... | |
126 | 164 |
else |
127 | 165 |
new Throwable("Impossible to have Selection Criteria over subjects"); |
128 | 166 |
|
129 |
List<Pair<String, SelectionCriteria>> lst = map.get(value);
|
|
130 |
List<SelectionCriteria> selectionList = lst.stream().map(p -> {
|
|
167 |
List<Pair<String, Constraints>> lst = map.get(value);
|
|
168 |
List<Constraints> selectionList = lst.stream().map(p -> {
|
|
131 | 169 |
if (p.fst == community) |
132 | 170 |
return p.snd; |
133 | 171 |
return null; |
Also available in: Unified diff
Update for the addition of selection criteria in the community context configuration