Revision 46587
Added by Alessia Bardi almost 7 years ago
EntityConfigTable.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.data.mapreduce.hbase.index.config; |
2 | 2 |
|
3 |
import java.util.Collection; |
|
4 |
import java.util.HashMap; |
|
5 |
import java.util.HashSet; |
|
6 |
import java.util.Set; |
|
3 |
import java.util.*; |
|
7 | 4 |
|
5 |
import com.google.common.base.Predicate; |
|
6 |
import com.google.common.base.Predicates; |
|
8 | 7 |
import com.google.common.collect.Lists; |
8 |
import com.google.common.collect.Sets; |
|
9 | 9 |
import eu.dnetlib.data.mapreduce.util.RelDescriptor; |
10 |
import eu.dnetlib.data.proto.TypeProtos; |
|
10 | 11 |
import eu.dnetlib.data.proto.TypeProtos.Type; |
12 |
import org.apache.commons.collections.CollectionUtils; |
|
11 | 13 |
|
12 |
public class EntityConfigTable extends HashMap<Type, EntityConfig> { |
|
14 |
public class EntityConfigTable extends HashMap<TypeProtos.Type, EntityConfig> {
|
|
13 | 15 |
|
14 | 16 |
private static final long serialVersionUID = 6087987206844928698L; |
15 | 17 |
|
16 | 18 |
public Collection<LinkDescriptor> getDescriptors(final Type source) { |
17 | 19 |
final EntityConfig entityConfig = super.get(source); |
18 | 20 |
if (entityConfig == null) return Lists.newArrayList(); |
19 |
return entityConfig.getLinks().values();
|
|
21 |
return Lists.newArrayList(entityConfig.getLinks().values());
|
|
20 | 22 |
} |
21 | 23 |
|
22 | 24 |
public LinkDescriptor getDescriptor(final Type type, final RelDescriptor relDescriptor) { |
... | ... | |
25 | 27 |
|
26 | 28 |
public Set<String> getFilter(final Type type, final RelDescriptor relDescriptor) { |
27 | 29 |
final LinkDescriptor ld = getDescriptor(type, relDescriptor); |
28 |
return ld != null ? ld.getFields() : new HashSet<String>();
|
|
30 |
return ld != null ? Sets.newHashSet(ld.getFields()) : new HashSet<String>();
|
|
29 | 31 |
} |
30 | 32 |
|
31 | 33 |
public boolean includeDuplicates(final Type type) { |
32 | 34 |
return super.get(type).getIndexDuplicates(); |
33 | 35 |
} |
34 | 36 |
|
35 |
} |
|
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 |
} |
Also available in: Unified diff
implemented use of opt in/out rules for entity fields (#2557).
depending on specific solrj version (thus excluding cdh6.X versions)