Revision 55762
Added by Claudio Atzori almost 5 years ago
OpenaireLayoutToRecordStylesheetTest.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.msro.openaireplus.workflows.index; |
2 | 2 |
|
3 |
import com.fasterxml.jackson.databind.ObjectMapper; |
|
4 |
import com.fasterxml.jackson.databind.ObjectWriter; |
|
5 |
import com.google.common.collect.Maps; |
|
6 |
import eu.dnetlib.functionality.index.model.document.IndexDocument; |
|
7 |
import eu.dnetlib.functionality.index.solr.feed.InputDocumentFactory; |
|
3 | 8 |
import eu.dnetlib.functionality.index.solr.feed.StreamingInputDocumentFactory; |
4 | 9 |
import eu.dnetlib.miscutils.datetime.DateUtils; |
5 | 10 |
import eu.dnetlib.miscutils.functional.xml.ApplyXslt; |
... | ... | |
23 | 28 |
import java.io.InputStream; |
24 | 29 |
import java.io.StringReader; |
25 | 30 |
import java.io.StringWriter; |
31 |
import java.text.SimpleDateFormat; |
|
32 |
import java.util.Map; |
|
26 | 33 |
|
27 | 34 |
import static org.junit.Assert.assertFalse; |
28 | 35 |
import static org.junit.Assert.assertNotNull; |
... | ... | |
35 | 42 |
|
36 | 43 |
private static final String OAF_RECORD = "/eu/dnetlib/msro/openaireplus/workflows/index/oafRecord.xml"; |
37 | 44 |
|
45 |
private final static String[] dateFormats = { "yyyy-MM-dd'T'hh:mm:ss", "yyyy-MM-dd", "dd-MM-yyyy", "dd/MM/yyyy", "yyyy" }; |
|
46 |
|
|
38 | 47 |
@Test |
39 | 48 |
public void testConvertRecord() throws IOException, TransformerException, XMLStreamException, DocumentException { |
40 | 49 |
String xsl = prepareXslt("DMF"); |
... | ... | |
58 | 67 |
assertNotNull(doc); |
59 | 68 |
assertFalse(doc.isEmpty()); |
60 | 69 |
|
61 |
// System.out.println(doc);
|
|
70 |
System.out.println("SolrDocument");
|
|
62 | 71 |
|
72 |
System.out.println(doc.values()); |
|
73 |
|
|
74 |
System.out.println("SolrDocument fields"); |
|
75 |
|
|
76 |
Map<String, Object> fields = Maps.newHashMap(); |
|
77 |
|
|
78 |
doc.entrySet().stream() |
|
79 |
.forEach(e -> { |
|
80 |
Object value = e.getValue().getValueCount() == 1 ? e.getValue().getFirstValue() : e.getValue().getValues(); |
|
81 |
fields.put(e.getKey(), value); |
|
82 |
}); |
|
83 |
|
|
84 |
//new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(fields); |
|
85 |
|
|
86 |
final ObjectWriter objectWriter = new ObjectMapper() |
|
87 |
.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")) |
|
88 |
.writerWithDefaultPrettyPrinter(); |
|
89 |
|
|
90 |
System.out.println(objectWriter.writeValueAsString(fields)); |
|
63 | 91 |
} |
64 | 92 |
|
65 | 93 |
protected String prepareXslt(final String format) throws IOException, TransformerException, DocumentException { |
Also available in: Unified diff
reintegrated branch solr75 -r53774:HEAD