Revision 49096
Added by Claudio Atzori over 6 years ago
OAVersionEventFactory.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.data.mapreduce.hbase.broker; |
2 | 2 |
|
3 |
import static eu.dnetlib.data.mapreduce.hbase.broker.mapping.EventFactory.asEvent; |
|
4 |
import static eu.dnetlib.data.mapreduce.util.OafHbaseUtils.getKey; |
|
5 |
|
|
6 | 3 |
import java.io.IOException; |
7 | 4 |
import java.util.List; |
8 | 5 |
import java.util.Set; |
6 |
import java.util.stream.Collectors; |
|
9 | 7 |
|
10 |
import org.apache.commons.lang.StringUtils; |
|
11 |
import org.apache.hadoop.io.Text; |
|
12 |
import org.apache.hadoop.mapreduce.Reducer.Context; |
|
13 |
import org.dom4j.DocumentException; |
|
14 |
|
|
15 | 8 |
import com.google.common.base.Predicate; |
16 | 9 |
import com.google.common.collect.Iterables; |
17 |
import com.google.common.collect.Lists; |
|
18 |
|
|
19 | 10 |
import eu.dnetlib.broker.objects.OpenAireEventPayload; |
20 | 11 |
import eu.dnetlib.data.mapreduce.hbase.broker.mapping.HighlightFactory; |
21 | 12 |
import eu.dnetlib.data.mapreduce.hbase.broker.mapping.OpenAireEventPayloadFactory; |
22 | 13 |
import eu.dnetlib.data.mapreduce.hbase.broker.model.EventMessage; |
23 | 14 |
import eu.dnetlib.data.proto.OafProtos.Oaf; |
24 | 15 |
import eu.dnetlib.data.proto.ResultProtos.Result.Instance; |
16 |
import org.apache.commons.lang.StringUtils; |
|
17 |
import org.apache.hadoop.io.Text; |
|
18 |
import org.apache.hadoop.mapreduce.Reducer.Context; |
|
19 |
import org.dom4j.DocumentException; |
|
25 | 20 |
|
21 |
import static eu.dnetlib.data.mapreduce.hbase.broker.mapping.EventFactory.asEvent; |
|
22 |
import static eu.dnetlib.data.mapreduce.util.OafHbaseUtils.getKey; |
|
23 |
|
|
26 | 24 |
/** |
27 | 25 |
* Created by claudio on 26/07/16. |
28 | 26 |
*/ |
... | ... | |
59 | 57 |
private void doProcessOAVersion(final Context context, final Oaf current, final Oaf other, final Topic topic, final float trust) |
60 | 58 |
throws IOException, InterruptedException, DocumentException { |
61 | 59 |
final Oaf.Builder prototype = Oaf.newBuilder(current); |
62 |
final Iterable<Instance> i = Iterables.filter(other.getEntity().getResult().getInstanceList(), new Predicate<Instance>() { |
|
63 | 60 |
|
64 |
@Override |
|
65 |
public boolean apply(final Instance i) { |
|
66 |
return "OPEN".equalsIgnoreCase(i.getLicence().getClassid()); |
|
67 |
} |
|
68 |
}); |
|
69 |
prototype.getEntityBuilder().getResultBuilder().addAllInstance(i); |
|
61 |
final List<Instance> instances = |
|
62 |
other.getEntity().getResult().getInstanceList().stream() |
|
63 |
.filter(i ->"OPEN".equalsIgnoreCase(i.getAccessright().getClassid())) |
|
64 |
.collect(Collectors.toList()); |
|
65 |
prototype.getEntityBuilder().getResultBuilder().addAllInstance(instances); |
|
70 | 66 |
|
71 | 67 |
final Oaf oaf = prototype.build(); |
72 | 68 |
|
73 | 69 |
final OpenAireEventPayload payload = |
74 |
HighlightFactory.highlightEnrichOa(OpenAireEventPayloadFactory.fromOAF(oaf.getEntity(), other.getEntity(), trust), Lists.newArrayList(i));
|
|
70 |
HighlightFactory.highlightEnrichOa(OpenAireEventPayloadFactory.fromOAF(oaf.getEntity(), other.getEntity(), trust), instances);
|
|
75 | 71 |
final EventMessage event = asEvent(oaf.getEntity(), topic, payload, other.getEntity(), trust); |
76 | 72 |
|
77 | 73 |
context.write(tKey, new Text(event.toString())); |
... | ... | |
79 | 75 |
} |
80 | 76 |
|
81 | 77 |
private boolean hasAccess(final Oaf oaf, final String access, final boolean strict) { |
82 |
final Predicate<Instance> p = new Predicate<Instance>() { |
|
83 |
|
|
84 |
@Override |
|
85 |
public boolean apply(final Instance i) { |
|
86 |
return access.equalsIgnoreCase(i.getLicence().getClassid()); |
|
87 |
} |
|
88 |
}; |
|
78 |
final Predicate<Instance> p = i -> access.equalsIgnoreCase(i.getAccessright().getClassid()); |
|
89 | 79 |
final List<Instance> i = oaf.getEntity().getResult().getInstanceList(); |
90 | 80 |
return strict ? Iterables.all(i, p) : Iterables.any(i, p); |
91 | 81 |
} |
Also available in: Unified diff
fixing mapping for license vs accessright #3128, cleanup