1 |
26600
|
sandro.lab
|
package eu.dnetlib.data.mapreduce.hbase.index.config;
|
2 |
|
|
|
3 |
46587
|
alessia.ba
|
import java.util.*;
|
4 |
26600
|
sandro.lab
|
|
5 |
46587
|
alessia.ba
|
import com.google.common.base.Predicate;
|
6 |
|
|
import com.google.common.base.Predicates;
|
7 |
44466
|
claudio.at
|
import com.google.common.collect.Lists;
|
8 |
46587
|
alessia.ba
|
import com.google.common.collect.Sets;
|
9 |
28094
|
claudio.at
|
import eu.dnetlib.data.mapreduce.util.RelDescriptor;
|
10 |
46587
|
alessia.ba
|
import eu.dnetlib.data.proto.TypeProtos;
|
11 |
26600
|
sandro.lab
|
import eu.dnetlib.data.proto.TypeProtos.Type;
|
12 |
46587
|
alessia.ba
|
import org.apache.commons.collections.CollectionUtils;
|
13 |
26600
|
sandro.lab
|
|
14 |
46587
|
alessia.ba
|
public class EntityConfigTable extends HashMap<TypeProtos.Type, EntityConfig> {
|
15 |
26600
|
sandro.lab
|
|
16 |
|
|
private static final long serialVersionUID = 6087987206844928698L;
|
17 |
|
|
|
18 |
|
|
public Collection<LinkDescriptor> getDescriptors(final Type source) {
|
19 |
44466
|
claudio.at
|
final EntityConfig entityConfig = super.get(source);
|
20 |
|
|
if (entityConfig == null) return Lists.newArrayList();
|
21 |
46587
|
alessia.ba
|
return Lists.newArrayList(entityConfig.getLinks().values());
|
22 |
26600
|
sandro.lab
|
}
|
23 |
|
|
|
24 |
28094
|
claudio.at
|
public LinkDescriptor getDescriptor(final Type type, final RelDescriptor relDescriptor) {
|
25 |
|
|
return super.get(type).getLinks().get(relDescriptor);
|
26 |
26600
|
sandro.lab
|
}
|
27 |
|
|
|
28 |
28094
|
claudio.at
|
public Set<String> getFilter(final Type type, final RelDescriptor relDescriptor) {
|
29 |
|
|
final LinkDescriptor ld = getDescriptor(type, relDescriptor);
|
30 |
46587
|
alessia.ba
|
return ld != null ? Sets.newHashSet(ld.getFields()) : new HashSet<String>();
|
31 |
26600
|
sandro.lab
|
}
|
32 |
|
|
|
33 |
|
|
public boolean includeDuplicates(final Type type) {
|
34 |
|
|
return super.get(type).getIndexDuplicates();
|
35 |
|
|
}
|
36 |
|
|
|
37 |
46587
|
alessia.ba
|
public boolean hasIncludeFields(final Type type){
|
38 |
|
|
return CollectionUtils.isNotEmpty(super.get(type).getIncludeFields());
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
public boolean hasExcludeFields(final Type type){
|
42 |
|
|
return CollectionUtils.isNotEmpty(super.get(type).getExcludeFields());
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
public List<String> getIncludeFields(final Type type){
|
46 |
|
|
return super.get(type).getIncludeFields();
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
public List<String> getExcludeFields(final Type type){
|
50 |
|
|
return super.get(type).getExcludeFields();
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
public Predicate<String> getIncludeFilter(final Type type, final RelDescriptor relDescriptor){
|
54 |
|
|
final Set<String> filter = getFilter(type, relDescriptor);
|
55 |
|
|
return fieldName -> filter.contains(fieldName);
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
public Predicate<String> getFilter(final Type type){
|
59 |
|
|
if(hasIncludeFields(type)){
|
60 |
|
|
return getIncludeFilter(type);
|
61 |
|
|
}
|
62 |
|
|
if(hasExcludeFields(type)){
|
63 |
|
|
return getExcludeFilter(type);
|
64 |
|
|
}
|
65 |
|
|
return Predicates.alwaysTrue();
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
private Predicate<String> getIncludeFilter(final Type type) {
|
69 |
|
|
return fieldName -> {
|
70 |
|
|
if(getIncludeFields(type) == null || getIncludeFields(type).isEmpty()) return false;
|
71 |
|
|
return getIncludeFields(type).contains(fieldName);
|
72 |
|
|
};
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
private Predicate<String> getExcludeFilter(final Type type) {
|
76 |
|
|
return fieldName -> {
|
77 |
|
|
if(getExcludeFields(type) == null || getExcludeFields(type).isEmpty()) return true;
|
78 |
|
|
return !getExcludeFields(type).contains(fieldName);
|
79 |
|
|
};
|
80 |
|
|
}
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
}
|