AuditEntryJSONReader#read throws java.lang.IllegalArgumentException here and here if the datetime's string does not contain milliseconds, see stacktrace below:
java.lang.IllegalArgumentException: Invalid format: "2018-09-11T06:29:00Z" is malformed at "Z" at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:899) at org.nuxeo.elasticsearch.audit.io.AuditEntryJSONReader.read(AuditEntryJSONReader.java:105) at cpo.clouddesk.export.audit.log.ExportArchiveAudit.run(ExportArchiveAudit.java:226) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
The customer, who retrieves audit log entries from elasticsearch using java code, found out that datetime serialization in LogEntryImpl generates a string representation without milliseconds if the milliseconds are 0.
See some unit tests below demonstrating the problem:
package org.nuxeo.ecm.core.test; import static org.junit.Assert.assertEquals; import java.io.IOException; import java.util.Date; import org.joda.time.format.ISODateTimeFormat; import org.junit.Test; import org.nuxeo.elasticsearch.audit.io.AuditEntryJSONReader; public class NXP25927Test { @Test public void testDateWithNonZeroMilliSeconds() { String dateString = "2018-09-11T06:29:00.001Z"; // used in AuditEntryJSONReader#read() to parse datetime string Date date = ISODateTimeFormat.dateTime().parseDateTime(dateString).toDate(); // date.toInstant().toString() used in LogEntryImpl.DateSerializer.serialize() assertEquals(dateString + " != " + date.toInstant().toString(), dateString, date.toInstant().toString()); } /** * {@link Date#toInstant()#toString()} does not print millseconds when value is 0. * */ @Test public void testDateWithZeroMilliSeconds() { String dateString = "2018-09-11T06:29:00.000Z"; // used in AuditEntryJSONReader#read() to parse datetime string Date date = ISODateTimeFormat.dateTime().parseDateTime(dateString).toDate(); // date.toInstant().toString() used in LogEntryImpl.DateSerializer.serialize() assertEquals(dateString + " != " + date.toInstant().toString(), dateString, date.toInstant().toString()); } /** * Demonstrates what happens in {@link AuditEntryJSONReader#read(String)} when date string does not contain milliseconds. * */ @Test public void testISODateTimeFormatWithoutMilliSeconds() { String dateString = "2018-09-11T06:29:00Z"; Date date = ISODateTimeFormat.dateTime().parseDateTime(dateString).toDate(); } /** * {@link AuditEntryJSONReader#read(String)} fails when dates are missing millseconds. * @throws IOException */ @Test public void testEsAuditEntryWithMissingMilliSeconds() throws IOException { String logEntryJson = "{\"id\":22226,\"principalName\":\"Administrator\",\"eventId\":\"documentModified\",\"eventDate\":\"2018-08-21T01:58:26Z\",\"logDate\":\"2018-08-21T01:58:27.170Z\",\"docUUID\":\"b10f92d3-1224-45bd-8487-de345c2ff0f0\",\"docType\":\"File\",\"docPath\":\"/default-domain/workspaces/ws1/blank.pdf\",\"category\":\"eventDocumentCategory\",\"comment\":null,\"docLifeCycle\":\"project\",\"repositoryId\":\"default\",\"preprocessedComment\":null,\"entity-type\":\"logEntry\",\"extended\":{}}"; AuditEntryJSONReader.read(logEntryJson); } @Test public void testEsAuditEntryWithMilliSeconds() throws IOException { String logEntryJson = "{\"id\":22226,\"principalName\":\"Administrator\",\"eventId\":\"documentModified\",\"eventDate\":\"2018-08-21T01:58:26.807Z\",\"logDate\":\"2018-08-21T01:58:27.170Z\",\"docUUID\":\"b10f92d3-1224-45bd-8487-de345c2ff0f0\",\"docType\":\"File\",\"docPath\":\"/default-domain/workspaces/ws1/blank.pdf\",\"category\":\"eventDocumentCategory\",\"comment\":null,\"docLifeCycle\":\"project\",\"repositoryId\":\"default\",\"preprocessedComment\":null,\"entity-type\":\"logEntry\",\"extended\":{}}"; AuditEntryJSONReader.read(logEntryJson); } }