1
|
package eu.dnetlib.data.mapreduce.hbase.broker;
|
2
|
|
3
|
import static eu.dnetlib.data.mapreduce.hbase.broker.mapping.EventFactory.asEvent;
|
4
|
|
5
|
import java.io.IOException;
|
6
|
|
7
|
import org.apache.commons.lang.StringUtils;
|
8
|
import org.apache.hadoop.io.Text;
|
9
|
import org.apache.hadoop.mapreduce.Reducer.Context;
|
10
|
import org.dom4j.DocumentException;
|
11
|
|
12
|
import eu.dnetlib.broker.objects.OpenAireEventPayload;
|
13
|
import eu.dnetlib.data.mapreduce.hbase.broker.mapping.HighlightFactory;
|
14
|
import eu.dnetlib.data.mapreduce.hbase.broker.mapping.OpenAireEventPayloadFactory;
|
15
|
import eu.dnetlib.data.mapreduce.hbase.broker.model.EventMessage;
|
16
|
import eu.dnetlib.data.proto.FieldTypeProtos.StringField;
|
17
|
import eu.dnetlib.data.proto.OafProtos.Oaf;
|
18
|
import eu.dnetlib.data.proto.ResultProtos.Result.Metadata;
|
19
|
|
20
|
/**
|
21
|
* Created by claudio on 26/07/16.
|
22
|
*/
|
23
|
public class PublicationDateEventFactory {
|
24
|
|
25
|
protected Text tKey = new Text("");
|
26
|
|
27
|
public static void process(final Context context, final Oaf current, final Oaf other, final float trust)
|
28
|
throws IOException, InterruptedException, DocumentException {
|
29
|
new PublicationDateEventFactory().processPublicationDate(context, current, other, trust);
|
30
|
}
|
31
|
|
32
|
private void processPublicationDate(final Context context, final Oaf current, final Oaf other, final float trust)
|
33
|
throws IOException, InterruptedException, DocumentException {
|
34
|
if (hasPubDate(other)) {
|
35
|
// doProcessPublicationDate(context, current, other, Topic.MORE_PUBLICATION_DATE);
|
36
|
|
37
|
if (!hasPubDate(current)) {
|
38
|
doProcessPublicationDate(context, current, other, Topic.ENRICH_MISSING_PUBLICATION_DATE, trust);
|
39
|
}
|
40
|
}
|
41
|
}
|
42
|
|
43
|
private void doProcessPublicationDate(final Context context, final Oaf current, final Oaf other, final Topic topic, final float trust)
|
44
|
throws IOException, InterruptedException, DocumentException {
|
45
|
final Oaf.Builder prototype = Oaf.newBuilder(current);
|
46
|
|
47
|
final StringField date = other.getEntity().getResult().getMetadata().getDateofacceptance();
|
48
|
prototype.getEntityBuilder().getResultBuilder().getMetadataBuilder().setDateofacceptance(date);
|
49
|
|
50
|
final Oaf oaf = prototype.build();
|
51
|
|
52
|
final OpenAireEventPayload payload =
|
53
|
HighlightFactory.highlightEnrichPublicationDate(OpenAireEventPayloadFactory.fromOAF(oaf.getEntity(), other.getEntity(), trust), date);
|
54
|
final EventMessage event = asEvent(oaf.getEntity(), topic, payload, other.getEntity(), trust);
|
55
|
|
56
|
context.write(tKey, new Text(event.toString()));
|
57
|
context.getCounter("event", topic.getValue()).increment(1);
|
58
|
}
|
59
|
|
60
|
private boolean hasPubDate(final Oaf current) {
|
61
|
final Metadata m = current.getEntity().getResult().getMetadata();
|
62
|
return StringUtils.isNotBlank(m.getDateofacceptance().getValue());
|
63
|
}
|
64
|
|
65
|
}
|