1
|
package eu.dnetlib.data.utils;
|
2
|
|
3
|
import java.io.StringWriter;
|
4
|
import java.util.Collection;
|
5
|
import java.util.stream.Collectors;
|
6
|
|
7
|
import org.apache.commons.lang3.StringUtils;
|
8
|
|
9
|
import eu.dnetlib.data.mdstore.plugins.objects.MdRecord;
|
10
|
|
11
|
public class CsvConverter {
|
12
|
|
13
|
public static String asCsv(final MdRecord record) {
|
14
|
|
15
|
final StringWriter sw = new StringWriter();
|
16
|
sw.append(record.getId());
|
17
|
sw.append("\t");
|
18
|
sw.append(record.getTitle());
|
19
|
sw.append("\t");
|
20
|
sw.append(prepareValue(record.getCreators()));
|
21
|
sw.append("\t");
|
22
|
sw.append(record.getPublisher());
|
23
|
sw.append("\t");
|
24
|
sw.append(record.getType());
|
25
|
sw.append("\t");
|
26
|
sw.append("" + record.getDate());
|
27
|
sw.append("\t");
|
28
|
sw.append(prepareValue(record.getDois()));
|
29
|
|
30
|
return sw.toString();
|
31
|
}
|
32
|
|
33
|
private static String prepareValue(final Collection<String> list) {
|
34
|
return list.stream().map(String::trim).filter(StringUtils::isNotBlank).collect(Collectors.joining(", "));
|
35
|
}
|
36
|
|
37
|
}
|