From b4c7da88a9a47458301716ec238df4c01c56c438 Mon Sep 17 00:00:00 2001 From: Denis Lobo Date: Tue, 27 Aug 2024 17:38:01 +0200 Subject: [PATCH 1/2] Add resolution support in DateFieldDefinitionBuilder (introduced in Magnolia 6.2.44) --- .../builder/simple/DateFieldDefinitionBuilder.java | 9 +++++++++ .../builder/simple/DateFieldDefinitionBuilderTest.java | 3 +++ 2 files changed, 12 insertions(+) diff --git a/magnolia-builders/src/main/java/com/merkle/oss/magnolia/definition/builder/simple/DateFieldDefinitionBuilder.java b/magnolia-builders/src/main/java/com/merkle/oss/magnolia/definition/builder/simple/DateFieldDefinitionBuilder.java index 155a2c6..6d93516 100644 --- a/magnolia-builders/src/main/java/com/merkle/oss/magnolia/definition/builder/simple/DateFieldDefinitionBuilder.java +++ b/magnolia-builders/src/main/java/com/merkle/oss/magnolia/definition/builder/simple/DateFieldDefinitionBuilder.java @@ -20,6 +20,8 @@ public class DateFieldDefinitionBuilder extends AbstractConfiguredFieldDefinitio private String dateFormat; @Nullable private String timeFormat; + @Nullable + private String resolution; public DateFieldDefinitionBuilder() {} public DateFieldDefinitionBuilder(final DateFieldDefinition definition) { @@ -28,6 +30,7 @@ public DateFieldDefinitionBuilder(final DateFieldDefinition definition) { inISO8061Format(definition.isInISO8061Format()); dateFormat(definition.getDateFormat()); timeFormat(definition.getTimeFormat()); + resolution(definition.getResolution()); } public DateFieldDefinitionBuilder time(final boolean time) { @@ -50,6 +53,11 @@ public DateFieldDefinitionBuilder timeFormat(final String timeFormat) { return self(); } + public DateFieldDefinitionBuilder resolution(final String resolution) { + this.resolution = resolution; + return self(); + } + public DateFieldDefinition build(final String name) { final DateFieldDefinition definition = new DateFieldDefinition(); super.populate(definition, name); @@ -57,6 +65,7 @@ public DateFieldDefinition build(final String name) { Optional.ofNullable(inISO8061Format).ifPresent(definition::setInISO8061Format); Optional.ofNullable(dateFormat).ifPresent(definition::setDateFormat); Optional.ofNullable(timeFormat).ifPresent(definition::setTimeFormat); + Optional.ofNullable(resolution).ifPresent(definition::setResolution); return definition; } } diff --git a/magnolia-builders/src/test/java/com/merkle/oss/magnolia/definition/builder/simple/DateFieldDefinitionBuilderTest.java b/magnolia-builders/src/test/java/com/merkle/oss/magnolia/definition/builder/simple/DateFieldDefinitionBuilderTest.java index ff2374a..879970d 100644 --- a/magnolia-builders/src/test/java/com/merkle/oss/magnolia/definition/builder/simple/DateFieldDefinitionBuilderTest.java +++ b/magnolia-builders/src/test/java/com/merkle/oss/magnolia/definition/builder/simple/DateFieldDefinitionBuilderTest.java @@ -16,9 +16,11 @@ void testBuilder() { .timeFormat("timeFormat") .time(true) .inISO8061Format(true) + .resolution("minute") .build("date"); assertEquals("dateFormat", definition.getDateFormat()); assertEquals("timeFormat", definition.getTimeFormat()); + assertEquals("minute", definition.getResolution()); assertTrue(definition.isTime()); assertTrue(definition.isInISO8061Format()); @@ -26,6 +28,7 @@ void testBuilder() { assertEquals(Date.class, emptyDefinition.getType()); assertEquals("yyyy-MM-dd", emptyDefinition.getDateFormat()); assertEquals("HH:mm", emptyDefinition.getTimeFormat()); + assertNull(emptyDefinition.getResolution()); assertFalse(emptyDefinition.isTime()); assertFalse(emptyDefinition.isInISO8061Format()); } From cd01c41e69c41ba03b876ad5f43ef54274d5eba2 Mon Sep 17 00:00:00 2001 From: eschleb Date: Mon, 16 Sep 2024 07:49:34 +0200 Subject: [PATCH 2/2] Use DateTimeResolution/DateResolution enums instead of string for DateFieldDefinitionBuilder resolution --- .../simple/DateFieldDefinitionBuilder.java | 17 ++++++++++++++--- .../simple/DateFieldDefinitionBuilderTest.java | 6 ++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/magnolia-builders/src/main/java/com/merkle/oss/magnolia/definition/builder/simple/DateFieldDefinitionBuilder.java b/magnolia-builders/src/main/java/com/merkle/oss/magnolia/definition/builder/simple/DateFieldDefinitionBuilder.java index 6d93516..10975c7 100644 --- a/magnolia-builders/src/main/java/com/merkle/oss/magnolia/definition/builder/simple/DateFieldDefinitionBuilder.java +++ b/magnolia-builders/src/main/java/com/merkle/oss/magnolia/definition/builder/simple/DateFieldDefinitionBuilder.java @@ -1,11 +1,14 @@ package com.merkle.oss.magnolia.definition.builder.simple; import info.magnolia.ui.field.DateFieldDefinition; -import info.magnolia.ui.field.TextFieldDefinition; -import javax.annotation.Nullable; import java.util.Optional; +import javax.annotation.Nullable; + +import com.vaadin.shared.ui.datefield.DateResolution; +import com.vaadin.shared.ui.datefield.DateTimeResolution; + /** * builds a {@link DateFieldDefinition} * @see magnolia Docs - Date field @@ -53,11 +56,19 @@ public DateFieldDefinitionBuilder timeFormat(final String timeFormat) { return self(); } - public DateFieldDefinitionBuilder resolution(final String resolution) { + private DateFieldDefinitionBuilder resolution(final String resolution) { this.resolution = resolution; return self(); } + public DateFieldDefinitionBuilder resolution(final DateTimeResolution resolution) { + return resolution(resolution.name()); + } + + public DateFieldDefinitionBuilder resolution(final DateResolution resolution) { + return resolution(resolution.name()); + } + public DateFieldDefinition build(final String name) { final DateFieldDefinition definition = new DateFieldDefinition(); super.populate(definition, name); diff --git a/magnolia-builders/src/test/java/com/merkle/oss/magnolia/definition/builder/simple/DateFieldDefinitionBuilderTest.java b/magnolia-builders/src/test/java/com/merkle/oss/magnolia/definition/builder/simple/DateFieldDefinitionBuilderTest.java index 879970d..0bf59fc 100644 --- a/magnolia-builders/src/test/java/com/merkle/oss/magnolia/definition/builder/simple/DateFieldDefinitionBuilderTest.java +++ b/magnolia-builders/src/test/java/com/merkle/oss/magnolia/definition/builder/simple/DateFieldDefinitionBuilderTest.java @@ -1,6 +1,8 @@ package com.merkle.oss.magnolia.definition.builder.simple; import com.merkle.oss.magnolia.definition.builder.AbstractFieldDefinitionBuilderTestCase; +import com.vaadin.shared.ui.datefield.DateTimeResolution; + import info.magnolia.ui.field.DateFieldDefinition; import org.junit.jupiter.api.Test; @@ -16,11 +18,11 @@ void testBuilder() { .timeFormat("timeFormat") .time(true) .inISO8061Format(true) - .resolution("minute") + .resolution(DateTimeResolution.MINUTE) .build("date"); assertEquals("dateFormat", definition.getDateFormat()); assertEquals("timeFormat", definition.getTimeFormat()); - assertEquals("minute", definition.getResolution()); + assertEquals("MINUTE", definition.getResolution()); assertTrue(definition.isTime()); assertTrue(definition.isInISO8061Format());