FINERACT-1724: Enhance external event datetime precision

This commit is contained in:
Adam Saghy
2023-05-08 12:54:30 +02:00
committed by Arnold Gálovics
parent 0e6f5eab9d
commit f24c9f8084
5 changed files with 98 additions and 7 deletions
@@ -66,9 +66,9 @@ public final class DateUtils {
return OffsetDateTime.now(zone).truncatedTo(ChronoUnit.SECONDS);
}
public static OffsetDateTime getOffsetDateTimeOfTenantWithMilliseconds() {
public static OffsetDateTime getOffsetDateTimeOfTenantWithMostPrecision() {
final ZoneId zone = getDateTimeZoneOfTenant();
return OffsetDateTime.now(zone).truncatedTo(ChronoUnit.MILLIS);
return OffsetDateTime.now(zone);
}
public static LocalDateTime getLocalDateTimeOfSystem() {
@@ -98,7 +98,7 @@ public class SendAsynchronousEventsTasklet implements Tasklet {
}
private void markEventsAsSent(List<Long> eventIds) {
OffsetDateTime sentAt = DateUtils.getOffsetDateTimeOfTenantWithMilliseconds();
OffsetDateTime sentAt = DateUtils.getOffsetDateTimeOfTenantWithMostPrecision();
// Partitioning dataset to avoid exception: PreparedStatement can have at most 65,535 parameters
List<List<Long>> partitions = Lists.partition(eventIds, 5_000);
@@ -80,7 +80,7 @@ public class ExternalEvent extends AbstractPersistableCustom {
this.data = data;
this.idempotencyKey = idempotencyKey;
this.aggregateRootId = aggregateRootId;
this.createdAt = DateUtils.getOffsetDateTimeOfTenantWithMilliseconds();
this.createdAt = DateUtils.getOffsetDateTimeOfTenantWithMostPrecision();
this.status = ExternalEventStatus.TO_BE_SENT;
this.businessDate = DateUtils.getBusinessLocalDate();
}
@@ -18,10 +18,14 @@
*/
package org.apache.fineract.infrastructure.event.external.service.message;
import static java.time.format.DateTimeFormatter.ISO_LOCAL_DATE;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.temporal.ChronoField;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -46,9 +50,21 @@ import org.springframework.stereotype.Component;
@RequiredArgsConstructor
public class MessageFactory implements InitializingBean {
private final ByteBufferConverter byteBufferConverter;
public static final DateTimeFormatter CUSTOM_ISO_LOCAL_DATE_TIME_FORMATTER;
private static final String SOURCE_UUID = UUID.randomUUID().toString();
private static final DateTimeFormatter CUSTOM_ISO_LOCAL_TIME_FORMATTER;
static {
CUSTOM_ISO_LOCAL_TIME_FORMATTER = new DateTimeFormatterBuilder().appendValue(ChronoField.HOUR_OF_DAY, 2).appendLiteral(':')
.appendValue(ChronoField.MINUTE_OF_HOUR, 2).optionalStart().appendLiteral(':').appendValue(ChronoField.SECOND_OF_MINUTE, 2)
.optionalStart().appendFraction(ChronoField.NANO_OF_SECOND, 6, 9, true).toFormatter();
CUSTOM_ISO_LOCAL_DATE_TIME_FORMATTER = new DateTimeFormatterBuilder().parseCaseInsensitive().append(ISO_LOCAL_DATE)
.appendLiteral('T').append(CUSTOM_ISO_LOCAL_TIME_FORMATTER).toFormatter();
}
private final ByteBufferConverter byteBufferConverter;
public MessageV1 createMessage(MessageId id, MessageSource source, MessageType type, MessageCategory category,
MessageCreatedAt createdAt, MessageBusinessDate businessDate, MessageIdempotencyKey idempotencyKey,
MessageDataSchema dataSchema, MessageData data) {
@@ -84,11 +100,11 @@ public class MessageFactory implements InitializingBean {
}
private String getMessageCreatedAt(OffsetDateTime createdAt) {
return createdAt.withOffsetSameInstant(ZoneOffset.UTC).toLocalDateTime().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
return createdAt.withOffsetSameInstant(ZoneOffset.UTC).toLocalDateTime().format(CUSTOM_ISO_LOCAL_DATE_TIME_FORMATTER);
}
private String getMessageBusinessDate(LocalDate businessDate) {
return businessDate.format(DateTimeFormatter.ISO_LOCAL_DATE);
return businessDate.format(ISO_LOCAL_DATE);
}
@Override