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
|
import java.util.List;
|
7
|
|
8
|
import org.apache.commons.lang.StringUtils;
|
9
|
import org.dom4j.DocumentException;
|
10
|
|
11
|
import com.google.common.collect.Lists;
|
12
|
|
13
|
import eu.dnetlib.broker.objects.OpenAireEventPayload;
|
14
|
import eu.dnetlib.data.mapreduce.hbase.broker.mapping.HighlightFactory;
|
15
|
import eu.dnetlib.data.mapreduce.hbase.broker.mapping.OpenAireEventPayloadFactory;
|
16
|
import eu.dnetlib.data.mapreduce.hbase.broker.model.EventWrapper;
|
17
|
import eu.dnetlib.data.proto.FieldTypeProtos.StringField;
|
18
|
import eu.dnetlib.data.proto.OafProtos.Oaf;
|
19
|
import eu.dnetlib.data.proto.ResultProtos.Result.Metadata;
|
20
|
|
21
|
/**
|
22
|
* Created by claudio on 26/07/16.
|
23
|
*/
|
24
|
public class PublicationDateEventFactory {
|
25
|
|
26
|
public static List<EventWrapper> process(final Oaf current, final Oaf other, final float trust)
|
27
|
throws IOException, InterruptedException, DocumentException {
|
28
|
return new PublicationDateEventFactory().processPublicationDate(current, other, trust);
|
29
|
}
|
30
|
|
31
|
private List<EventWrapper> processPublicationDate(final Oaf current, final Oaf other, final float trust)
|
32
|
throws IOException, InterruptedException, DocumentException {
|
33
|
final List<EventWrapper> events = Lists.newArrayList();
|
34
|
if (hasPubDate(other)) {
|
35
|
// doProcessPublicationDate(context, current, other, Topic.MORE_PUBLICATION_DATE);
|
36
|
|
37
|
if (!hasPubDate(current)) {
|
38
|
events.add(doProcessPublicationDate(current, other, Topic.ENRICH_MISSING_PUBLICATION_DATE, trust));
|
39
|
}
|
40
|
}
|
41
|
return events;
|
42
|
}
|
43
|
|
44
|
private EventWrapper doProcessPublicationDate(final Oaf current, final Oaf other, final Topic topic, final float trust)
|
45
|
throws IOException, InterruptedException, DocumentException {
|
46
|
final Oaf.Builder prototype = Oaf.newBuilder(current);
|
47
|
|
48
|
final StringField date = other.getEntity().getResult().getMetadata().getDateofacceptance();
|
49
|
prototype.getEntityBuilder().getResultBuilder().getMetadataBuilder().setDateofacceptance(date);
|
50
|
|
51
|
final Oaf oaf = prototype.build();
|
52
|
|
53
|
final OpenAireEventPayload payload =
|
54
|
HighlightFactory.highlightEnrichPublicationDate(OpenAireEventPayloadFactory.fromOAF(oaf.getEntity(), other.getEntity(), trust), date);
|
55
|
|
56
|
return EventWrapper.newInstance(
|
57
|
asEvent(oaf.getEntity(), topic, payload, other.getEntity(), trust),
|
58
|
payload.getHighlight().getPublicationdate(),
|
59
|
topic.getValue());
|
60
|
}
|
61
|
|
62
|
private boolean hasPubDate(final Oaf current) {
|
63
|
final Metadata m = current.getEntity().getResult().getMetadata();
|
64
|
return StringUtils.isNotBlank(m.getDateofacceptance().getValue());
|
65
|
}
|
66
|
|
67
|
}
|