Revision 51857
Added by Michele Artini almost 6 years ago
CsvConverter.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.data.utils; |
2 | 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 |
|
|
3 | 11 |
public class CsvConverter { |
4 | 12 |
|
5 |
public static String asCsv(final String string) { |
|
6 |
// TODO Auto-generated method stub |
|
7 |
return null; |
|
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(); |
|
8 | 31 |
} |
9 | 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 |
|
|
10 | 37 |
} |
Also available in: Unified diff