Revision 48697
Added by Claudio Atzori over 6 years ago
IndexConfig.java | ||
---|---|---|
6 | 6 |
import java.util.Map; |
7 | 7 |
import java.util.Set; |
8 | 8 |
|
9 |
import com.google.common.base.Function; |
|
10 | 9 |
import com.google.common.collect.Maps; |
11 | 10 |
import com.google.common.collect.Sets; |
12 | 11 |
import com.google.gson.Gson; |
13 | 12 |
import com.typesafe.config.Config; |
14 | 13 |
import com.typesafe.config.ConfigFactory; |
15 | 14 |
import com.typesafe.config.ConfigObject; |
16 |
import com.typesafe.config.ConfigValue; |
|
17 | 15 |
import eu.dnetlib.data.mapreduce.OptionalConfig; |
18 | 16 |
import eu.dnetlib.data.mapreduce.util.RelDescriptor; |
19 | 17 |
import eu.dnetlib.data.proto.TypeProtos.Type; |
... | ... | |
32 | 30 |
@SuppressWarnings("unchecked") |
33 | 31 |
public EntityConfigTable getConfigMap() { |
34 | 32 |
final ConfigObject modelMap = getConfig().getObject("index.conf"); |
35 |
final Map<String, EntityConfig> map = Maps.transformValues(modelMap, new Function<ConfigValue, EntityConfig>() {
|
|
33 |
final Map<String, EntityConfig> map = Maps.transformValues(modelMap, value -> {
|
|
36 | 34 |
|
37 |
@Override |
|
38 |
public EntityConfig apply(final ConfigValue value) { |
|
35 |
final HashMap<RelDescriptor, LinkDescriptor> links = Maps.newHashMap(); |
|
36 |
for (final Object o : (List<?>) ((Map<String, ?>) value.unwrapped()).get("links")) { |
|
37 |
final Map<String, ?> map1 = (Map<String, ?>) o; |
|
39 | 38 |
|
40 |
final HashMap<RelDescriptor, LinkDescriptor> links = Maps.newHashMap(); |
|
41 |
for (final Object o : (List<?>) ((Map<String, ?>) value.unwrapped()).get("links")) { |
|
42 |
final Map<String, ?> map = (Map<String, ?>) o; |
|
39 |
final RelDescriptor relDescriptor = new RelDescriptor((String) map1.get("relType")); |
|
40 |
final Set<String> fields = Sets.newHashSet((List<String>) map1.get("fields")); |
|
41 |
final Type target = Type.valueOf((String) map1.get("targetEntity")); |
|
42 |
final Boolean isChild = ((String) map1.get("expandAs")).equals("child"); |
|
43 |
final Boolean symmetric = (Boolean) map1.get("symmetric"); |
|
43 | 44 |
|
44 |
final RelDescriptor relDescriptor = new RelDescriptor((String) map.get("relType")); |
|
45 |
final Set<String> fields = Sets.newHashSet((List<String>) map.get("fields")); |
|
46 |
final Type target = Type.valueOf((String) map.get("targetEntity")); |
|
47 |
final Boolean isChild = ((String) map.get("expandAs")).equals("child"); |
|
48 |
final Boolean symmetric = (Boolean) map.get("symmetric"); |
|
45 |
final LinkDescriptor ld = new LinkDescriptor(relDescriptor, target, isChild, symmetric, fields); |
|
49 | 46 |
|
50 |
final LinkDescriptor ld = new LinkDescriptor(relDescriptor, target, isChild, symmetric, fields); |
|
47 |
if (map1.containsKey("max")) { |
|
48 |
ld.setMax((Integer) map1.get("max")); |
|
49 |
} |
|
51 | 50 |
|
52 |
if (map.containsKey("max")) { |
|
53 |
ld.setMax((Integer) map.get("max")); |
|
54 |
} |
|
55 |
|
|
56 |
links.put(relDescriptor, ld); |
|
57 |
} |
|
58 |
final List<String> includeFields = (List<String>) ((Map<String, ?>) value.unwrapped()).get("includeFields"); |
|
59 |
final List<String> excludeFields = (List<String>) ((Map<String, ?>) value.unwrapped()).get("excludeFields"); |
|
60 |
if(CollectionUtils.isNotEmpty(includeFields) & CollectionUtils.isNotEmpty(excludeFields)){ |
|
61 |
throw new RuntimeException("Cannot create the index configuration: includeFields and excludeFields are both not null"); |
|
62 |
} |
|
63 |
return new EntityConfig((Boolean) ((Map<String, ?>) value.unwrapped()).get("dups"), links, includeFields, excludeFields); |
|
51 |
links.put(relDescriptor, ld); |
|
64 | 52 |
} |
53 |
final List<String> includeFields = (List<String>) ((Map<String, ?>) value.unwrapped()).get("includeFields"); |
|
54 |
final List<String> excludeFields = (List<String>) ((Map<String, ?>) value.unwrapped()).get("excludeFields"); |
|
55 |
if(CollectionUtils.isNotEmpty(includeFields) & CollectionUtils.isNotEmpty(excludeFields)){ |
|
56 |
throw new RuntimeException("Cannot create the index configuration: includeFields and excludeFields are both not null"); |
|
57 |
} |
|
58 |
return new EntityConfig((Boolean) ((Map<String, ?>) value.unwrapped()).get("dups"), links, includeFields, excludeFields); |
|
65 | 59 |
}); |
66 | 60 |
|
67 | 61 |
final EntityConfigTable res = new EntityConfigTable(); |
Also available in: Unified diff
some java8 refactorings, added more tests for the software entities mapping