This is an automated email from the ASF dual-hosted git repository.
ilgrosso pushed a commit to branch 4_0_X
in repository https://gitbox.apache.org/repos/asf/syncope.git
The following commit(s) were added to refs/heads/4_0_X by this push:
new d8ffba55a8 [SYNCOPE-1873] - Add LocalDateTime support to DateOps
(#1059)
d8ffba55a8 is described below
commit d8ffba55a837d1f415ed51e0b97bf14d26ed3f41
Author: Matteo Tatoni <[email protected]>
AuthorDate: Thu Apr 24 15:52:04 2025 +0200
[SYNCOPE-1873] - Add LocalDateTime support to DateOps (#1059)
---
.../apache/syncope/client/ui/commons/DateOps.java | 38 +++++++++++++++++++---
.../syncope/client/console/panels/BeanPanel.java | 4 +++
.../repeater/data/table/DatePropertyColumn.java | 3 ++
3 files changed, 41 insertions(+), 4 deletions(-)
diff --git
a/client/idrepo/common-ui/src/main/java/org/apache/syncope/client/ui/commons/DateOps.java
b/client/idrepo/common-ui/src/main/java/org/apache/syncope/client/ui/commons/DateOps.java
index 17216b409b..4e0d591cb2 100644
---
a/client/idrepo/common-ui/src/main/java/org/apache/syncope/client/ui/commons/DateOps.java
+++
b/client/idrepo/common-ui/src/main/java/org/apache/syncope/client/ui/commons/DateOps.java
@@ -19,6 +19,7 @@
package org.apache.syncope.client.ui.commons;
import java.io.Serializable;
+import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
@@ -52,6 +53,10 @@ public final class DateOps {
public String format(final ZonedDateTime date) {
return Optional.ofNullable(date).map(v ->
fdf.format(convert(date))).orElse(StringUtils.EMPTY);
}
+
+ public String format(final LocalDateTime date) {
+ return Optional.ofNullable(date).map(v ->
fdf.format(convert(v))).orElse(StringUtils.EMPTY);
+ }
}
public static final class WrappedDateModel implements IModel<Date>,
Serializable {
@@ -70,6 +75,14 @@ public final class DateOps {
return instance;
}
+ public static WrappedDateModel ofLocal(final IModel<LocalDateTime>
local) {
+ WrappedDateModel instance = new WrappedDateModel();
+ instance.local = local;
+ return instance;
+ }
+
+ private IModel<LocalDateTime> local;
+
private IModel<OffsetDateTime> offset;
private IModel<ZonedDateTime> zoned;
@@ -80,15 +93,24 @@ public final class DateOps {
@Override
public Date getObject() {
- return offset == null ? convert(zoned.getObject()) :
convert(offset.getObject());
+ if (offset != null) {
+ return convert(offset.getObject());
+ } else if (zoned != null) {
+ return convert(zoned.getObject());
+ } else if (local != null) {
+ return convert(local.getObject());
+ }
+ return null;
}
@Override
public void setObject(final Date object) {
- if (offset == null) {
- zoned.setObject(toZonedDateTime(object));
- } else {
+ if (offset != null) {
offset.setObject(toOffsetDateTime(object));
+ } else if (zoned != null) {
+ zoned.setObject(toZonedDateTime(object));
+ } else if (local != null) {
+ local.setObject(toLocalDateTime(object));
}
}
}
@@ -105,6 +127,10 @@ public final class DateOps {
return Optional.ofNullable(date).map(v -> new
Date(v.toInstant().toEpochMilli())).orElse(null);
}
+ public static Date convert(final LocalDateTime date) {
+ return Optional.ofNullable(date).map(v ->
Date.from(v.atZone(DEFAULT_ZONE).toInstant())).orElse(null);
+ }
+
public static OffsetDateTime toOffsetDateTime(final Date date) {
return Optional.ofNullable(date).map(v ->
v.toInstant().atOffset(DEFAULT_OFFSET)).orElse(null);
}
@@ -113,6 +139,10 @@ public final class DateOps {
return Optional.ofNullable(date).map(v ->
ZonedDateTime.ofInstant(v.toInstant(), DEFAULT_ZONE)).orElse(null);
}
+ public static LocalDateTime toLocalDateTime(final Date date) {
+ return Optional.ofNullable(date).map(v ->
LocalDateTime.ofInstant(v.toInstant(), DEFAULT_ZONE)).orElse(null);
+ }
+
private DateOps() {
// private constructor for static utility class
}
diff --git
a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/BeanPanel.java
b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/BeanPanel.java
index da2d1ea029..7fe73bef1b 100644
---
a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/BeanPanel.java
+++
b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/BeanPanel.java
@@ -26,6 +26,7 @@ import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.time.Duration;
+import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZonedDateTime;
import java.util.ArrayList;
@@ -306,6 +307,9 @@ public class BeanPanel<T extends Serializable> extends
Panel {
} else if (ZonedDateTime.class.equals(type)) {
panel = new AjaxDateTimeFieldPanel(id, fieldName,
DateOps.WrappedDateModel.ofZoned(model),
DateFormatUtils.ISO_8601_EXTENDED_DATETIME_TIME_ZONE_FORMAT);
+ } else if (LocalDateTime.class.equals(type)) {
+ panel = new AjaxDateTimeFieldPanel(id, fieldName,
DateOps.WrappedDateModel.ofLocal(model),
+
DateFormatUtils.ISO_8601_EXTENDED_DATETIME_TIME_ZONE_FORMAT);
} else if (type.isEnum()) {
panel = new AjaxDropDownChoicePanel(id, fieldName, model).
setChoices(List.of(type.getEnumConstants()));
diff --git
a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wicket/extensions/markup/html/repeater/data/table/DatePropertyColumn.java
b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wicket/extensions/markup/html/repeater/data/table/DatePropertyColumn.java
index 8dd39b0b3a..de3c99c11a 100644
---
a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wicket/extensions/markup/html/repeater/data/table/DatePropertyColumn.java
+++
b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wicket/extensions/markup/html/repeater/data/table/DatePropertyColumn.java
@@ -18,6 +18,7 @@
*/
package
org.apache.syncope.client.console.wicket.extensions.markup.html.repeater.data.table;
+import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZonedDateTime;
import java.util.Date;
@@ -52,6 +53,8 @@ public class DatePropertyColumn<T> extends PropertyColumn<T,
String> {
convertedDate =
SyncopeConsoleSession.get().getDateFormat().format(offsetDateTime);
} else if (date.getObject() instanceof final ZonedDateTime
zonedDateTime) {
convertedDate =
SyncopeConsoleSession.get().getDateFormat().format(zonedDateTime);
+ } else if (date.getObject() instanceof final LocalDateTime
localDateTime) {
+ convertedDate =
SyncopeConsoleSession.get().getDateFormat().format(localDateTime);
} else if (date.getObject() instanceof final Date date1) {
convertedDate =
SyncopeConsoleSession.get().getDateFormat().format(date1);
}