Project

General

Profile

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
import java.util.stream.Collectors;
8

    
9
import org.apache.commons.lang.StringUtils;
10
import org.dom4j.DocumentException;
11

    
12
import com.google.common.collect.Lists;
13

    
14
import eu.dnetlib.broker.objects.OpenAireEventPayload;
15
import eu.dnetlib.data.mapreduce.hbase.broker.mapping.HighlightFactory;
16
import eu.dnetlib.data.mapreduce.hbase.broker.mapping.OpenAireEventPayloadFactory;
17
import eu.dnetlib.data.mapreduce.hbase.broker.model.EventWrapper;
18
import eu.dnetlib.data.proto.FieldTypeProtos.StringField;
19
import eu.dnetlib.data.proto.OafProtos.Oaf;
20

    
21
/**
22
 * Created by claudio on 26/07/16.
23
 */
24
public class AbstractEventFactory { // Abstract of the publication
25

    
26
	public static List<EventWrapper> process(final Oaf current, final Oaf other, final float trust)
27
			throws IOException, InterruptedException, DocumentException {
28
		return new AbstractEventFactory().processAbstract(current, other, trust);
29
	}
30

    
31
	private List<EventWrapper> processAbstract(final Oaf current, final Oaf other, final float trust)
32
			throws IOException, InterruptedException, DocumentException {
33

    
34
		final List<EventWrapper> events = Lists.newArrayList();
35

    
36
		if (hasAbstract(other)) {
37
			// doProcessAbstract(context, current, other, Topic.MORE_ABSTRACT);
38

    
39
			if (!hasAbstract(current)) {
40
				events.add(doProcessAbstract(current, other, Topic.ENRICH_MISSING_ABSTRACT, trust));
41
			}
42
		}
43

    
44
		return events;
45
	}
46

    
47
	private EventWrapper doProcessAbstract(final Oaf current, final Oaf other, final Topic topic, final float trust)
48
			throws IOException, InterruptedException, DocumentException {
49
		final Oaf.Builder prototype = Oaf.newBuilder(current);
50
		final List<StringField> descriptionList = other.getEntity().getResult().getMetadata().getDescriptionList();
51
		prototype.getEntityBuilder().getResultBuilder().getMetadataBuilder().addAllDescription(descriptionList);
52

    
53
		final Oaf oaf = prototype.build();
54

    
55
		final OpenAireEventPayload payload =
56
				HighlightFactory.highlightEnrichAbstract(OpenAireEventPayloadFactory.fromOAF(oaf.getEntity(), other.getEntity(), trust), descriptionList);
57

    
58
		return EventWrapper.newInstance(
59
				asEvent(oaf.getEntity(), topic, payload, other.getEntity(), trust),
60
				payload.getHighlight().getAbstracts().stream().filter(StringUtils::isNotBlank).sorted().collect(Collectors.joining(", ")),
61
				topic.getValue());
62
	}
63

    
64
	private boolean hasAbstract(final Oaf oaf) {
65
		return oaf.getEntity().getResult().getMetadata().getDescriptionList()
66
				.stream()
67
				.anyMatch(s -> StringUtils.isNotBlank(s.getValue()));
68
	}
69

    
70
}
(1-1/10)