1 |
43443
|
claudio.at
|
package eu.dnetlib.data.mapreduce.hbase.broker;
|
2 |
|
|
|
3 |
52765
|
michele.ar
|
import static eu.dnetlib.data.mapreduce.hbase.broker.mapping.EventFactory.asEvent;
|
4 |
|
|
|
5 |
43443
|
claudio.at
|
import java.io.IOException;
|
6 |
49832
|
claudio.at
|
import java.util.List;
|
7 |
43443
|
claudio.at
|
|
8 |
52765
|
michele.ar
|
import org.apache.commons.lang.StringUtils;
|
9 |
|
|
import org.dom4j.DocumentException;
|
10 |
|
|
|
11 |
49832
|
claudio.at
|
import com.google.common.collect.Lists;
|
12 |
52765
|
michele.ar
|
|
13 |
43558
|
claudio.at
|
import eu.dnetlib.broker.objects.OpenAireEventPayload;
|
14 |
43443
|
claudio.at
|
import eu.dnetlib.data.mapreduce.hbase.broker.mapping.HighlightFactory;
|
15 |
|
|
import eu.dnetlib.data.mapreduce.hbase.broker.mapping.OpenAireEventPayloadFactory;
|
16 |
49832
|
claudio.at
|
import eu.dnetlib.data.mapreduce.hbase.broker.model.EventWrapper;
|
17 |
43443
|
claudio.at
|
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 |
49832
|
claudio.at
|
public static List<EventWrapper> process(final Oaf current, final Oaf other, final float trust)
|
27 |
44085
|
michele.ar
|
throws IOException, InterruptedException, DocumentException {
|
28 |
49832
|
claudio.at
|
return new PublicationDateEventFactory().processPublicationDate(current, other, trust);
|
29 |
43443
|
claudio.at
|
}
|
30 |
|
|
|
31 |
49832
|
claudio.at
|
private List<EventWrapper> processPublicationDate(final Oaf current, final Oaf other, final float trust)
|
32 |
44085
|
michele.ar
|
throws IOException, InterruptedException, DocumentException {
|
33 |
49832
|
claudio.at
|
final List<EventWrapper> events = Lists.newArrayList();
|
34 |
43443
|
claudio.at
|
if (hasPubDate(other)) {
|
35 |
44085
|
michele.ar
|
// doProcessPublicationDate(context, current, other, Topic.MORE_PUBLICATION_DATE);
|
36 |
43443
|
claudio.at
|
|
37 |
|
|
if (!hasPubDate(current)) {
|
38 |
49832
|
claudio.at
|
events.add(doProcessPublicationDate(current, other, Topic.ENRICH_MISSING_PUBLICATION_DATE, trust));
|
39 |
43443
|
claudio.at
|
}
|
40 |
|
|
}
|
41 |
49832
|
claudio.at
|
return events;
|
42 |
43443
|
claudio.at
|
}
|
43 |
|
|
|
44 |
49832
|
claudio.at
|
private EventWrapper doProcessPublicationDate(final Oaf current, final Oaf other, final Topic topic, final float trust)
|
45 |
44085
|
michele.ar
|
throws IOException, InterruptedException, DocumentException {
|
46 |
43443
|
claudio.at
|
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 |
44085
|
michele.ar
|
final OpenAireEventPayload payload =
|
54 |
|
|
HighlightFactory.highlightEnrichPublicationDate(OpenAireEventPayloadFactory.fromOAF(oaf.getEntity(), other.getEntity(), trust), date);
|
55 |
43443
|
claudio.at
|
|
56 |
49832
|
claudio.at
|
return EventWrapper.newInstance(
|
57 |
|
|
asEvent(oaf.getEntity(), topic, payload, other.getEntity(), trust),
|
58 |
52765
|
michele.ar
|
payload.getHighlight().getPublicationdate(),
|
59 |
49832
|
claudio.at
|
topic.getValue());
|
60 |
43443
|
claudio.at
|
}
|
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 |
|
|
}
|