1
|
package eu.dnetlib.data.mapreduce.hbase.index.config;
|
2
|
|
3
|
import java.util.*;
|
4
|
|
5
|
import com.google.common.base.Predicate;
|
6
|
import com.google.common.base.Predicates;
|
7
|
import com.google.common.collect.Lists;
|
8
|
import com.google.common.collect.Sets;
|
9
|
import eu.dnetlib.data.mapreduce.util.RelDescriptor;
|
10
|
import eu.dnetlib.data.proto.TypeProtos;
|
11
|
import eu.dnetlib.data.proto.TypeProtos.Type;
|
12
|
import org.apache.commons.collections.CollectionUtils;
|
13
|
|
14
|
public class EntityConfigTable extends HashMap<TypeProtos.Type, EntityConfig> {
|
15
|
|
16
|
private static final long serialVersionUID = 6087987206844928698L;
|
17
|
|
18
|
public Collection<LinkDescriptor> getDescriptors(final Type source) {
|
19
|
final EntityConfig entityConfig = super.get(source);
|
20
|
if (entityConfig == null) return Lists.newArrayList();
|
21
|
return Lists.newArrayList(entityConfig.getLinks().values());
|
22
|
}
|
23
|
|
24
|
public LinkDescriptor getDescriptor(final Type type, final RelDescriptor relDescriptor) {
|
25
|
return super.get(type).getLinks().get(relDescriptor);
|
26
|
}
|
27
|
|
28
|
public Set<String> getFilter(final Type type, final RelDescriptor relDescriptor) {
|
29
|
final LinkDescriptor ld = getDescriptor(type, relDescriptor);
|
30
|
return ld != null ? Sets.newHashSet(ld.getFields()) : new HashSet<String>();
|
31
|
}
|
32
|
|
33
|
public boolean includeDuplicates(final Type type) {
|
34
|
return super.get(type).getIndexDuplicates();
|
35
|
}
|
36
|
|
37
|
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
|
}
|