Project

General

Profile

1
package eu.dnetlib.dli.proto;
2

    
3
import java.awt.image.VolatileImage;
4
import java.util.List;
5
import java.util.Set;
6

    
7
import com.google.common.collect.Sets;
8
import eu.dnetlib.data.proto.DNGFProtos;
9
import eu.dnetlib.data.proto.FieldTypeProtos;
10
import eu.dnetlib.data.proto.PersonProtos.Person;
11
import org.apache.commons.lang3.StringUtils;
12

    
13
/**
14
 * Created by claudio on 14/03/2017.
15
 */
16
public class DngfDliUtils {
17

    
18
	public static void extractContributor(final Set<String> authors, final DNGFProtos.DNGFEntity entity)  {
19
		List<FieldTypeProtos.StringField> contributorList = null;
20
		switch (entity.getType()) {
21
			case publication:
22
				contributorList = entity.getDataset().getMetadata().getContributorList();
23
				break;
24
			case dataset:
25
				contributorList = entity.getDataset().getMetadata().getContributorList();
26
				break;
27
		}
28
		if (contributorList != null) {
29
			contributorList.forEach(c -> authors.add(c.getValue()));
30
		}
31
	}
32

    
33

    
34
	public static Set<String> parseAuthor(final DNGFProtos.DNGFEntity entity) {
35

    
36
		final Set<String> authors = Sets.newHashSet();
37
		extractContributor(authors, entity);
38
		if (entity.getChildrenList() != null && entity.getChildrenList().size() >0) {
39
			entity.getChildrenList().forEach(dedupItem -> {
40
				List<Person> personList = null;
41
				switch (dedupItem.getType()) {
42
				case publication:
43
					personList = dedupItem.getPublication().getAuthorList();
44
					break;
45
				case dataset:
46
					personList = dedupItem.getDataset().getAuthorList();
47
					break;
48
				}
49
				if (personList != null) {
50
					personList.forEach(person -> authors.add(person.getMetadata().getFullname().getValue()));
51
				}
52
			});
53
		}
54
		return authors;
55
	}
56

    
57

    
58
	public static Set<String> parsePublishers(final DNGFProtos.DNGFEntity entity) {
59
		final Set<String> publishers = Sets.newHashSet();
60
		switch (entity.getType()) {
61
			case dataset:
62
				final String publisherDataset = entity.getDataset().getMetadata().getPublisher().getValue();
63
				if (StringUtils.isNotBlank(publisherDataset)) {
64
					publishers.add(publisherDataset);
65
				}
66
				break;
67
			case publication:
68
				final String publisherPublication = entity.getPublication().getMetadata().getPublisher().getValue();
69
				if (StringUtils.isNotBlank(publisherPublication)) {
70
					publishers.add(publisherPublication);
71
				}
72
				break;
73
		}
74
		if (entity.getChildrenList() != null) {
75
			entity.getChildrenList().forEach(dedupItem -> {
76
				switch (dedupItem.getType()) {
77
					case publication:
78
						final String publisherPublication = dedupItem.getPublication().getMetadata().getPublisher().getValue();
79
						if (StringUtils.isNotBlank(publisherPublication)) {
80
							publishers.add(publisherPublication);
81
						}
82
						break;
83
					case dataset:
84
						final String publisherDataset = dedupItem.getDataset().getMetadata().getPublisher().getValue();
85
						if (StringUtils.isNotBlank(publisherDataset)) {
86
							publishers.add(publisherDataset);
87
						}
88
						break;
89
				}
90
			});
91
		}
92
		return publishers;
93
	}
94

    
95
}
(3-3/6)