This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new ba520d5 [CAMEL-15024] Add support for ZonedDateTime in camel-bindy
(#3810)
ba520d5 is described below
commit ba520d5da4a3a2f4e7d16354899be502b789ba06
Author: abiuan <[email protected]>
AuthorDate: Fri May 8 09:27:18 2020 +0200
[CAMEL-15024] Add support for ZonedDateTime in camel-bindy (#3810)
* CAMEL-15024: Add support for ZonedDateTime
* [CAMEL-15024] Add support for ZonedDateTime after codestyle fixes
* [CAMEL-15024] Removed commented code
Co-authored-by: Alberto <[email protected]>
---
.../format/factories/DefaultFactoryRegistry.java | 1 +
.../factories/ZonedDateTimeFormatFactory.java | 91 ++++++++++++++++++++++
.../date/BindyDatePatternCsvUnmarshallTest.java | 16 +++-
3 files changed, 106 insertions(+), 2 deletions(-)
diff --git
a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/DefaultFactoryRegistry.java
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/DefaultFactoryRegistry.java
index 0fb3b95..8afb66a 100644
---
a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/DefaultFactoryRegistry.java
+++
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/DefaultFactoryRegistry.java
@@ -46,6 +46,7 @@ public final class DefaultFactoryRegistry implements
FactoryRegistry {
.register(new LocalTimeFormatFactory())
.register(new LocalDateTimeFormatFactory())
.register(new LocalDateFormatFactory())
+ .register(new ZonedDateTimeFormatFactory())
.register(new CharacterFormatFactory())
.register(new EnumFormatFactory())
.register(new BigDecimalFormatFactory())
diff --git
a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/ZonedDateTimeFormatFactory.java
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/ZonedDateTimeFormatFactory.java
new file mode 100644
index 0000000..e03967a
--- /dev/null
+++
b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/format/factories/ZonedDateTimeFormatFactory.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dataformat.bindy.format.factories;
+
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.Locale;
+
+import org.apache.camel.dataformat.bindy.Format;
+import org.apache.camel.dataformat.bindy.FormattingOptions;
+import org.apache.camel.dataformat.bindy.PatternFormat;
+import org.apache.camel.util.ObjectHelper;
+
+public class ZonedDateTimeFormatFactory extends AbstractFormatFactory {
+
+ {
+ supportedClasses.add(ZonedDateTime.class);
+ }
+
+ @Override
+ public Format<?> build(FormattingOptions formattingOptions) {
+ return new ZonedDateTimePatternFormat(formattingOptions.getPattern(),
+ formattingOptions.getLocale());
+ }
+
+ private static class ZonedDateTimePatternFormat implements
PatternFormat<ZonedDateTime> {
+
+ private String pattern;
+ private Locale locale;
+
+ ZonedDateTimePatternFormat(String pattern, Locale locale) {
+ this.pattern = pattern;
+ this.locale = locale;
+ }
+
+ @Override
+ public String format(ZonedDateTime object) throws Exception {
+ ObjectHelper.notNull(this.pattern, "pattern");
+ return this.getDateFormat().format(object);
+ }
+
+ @Override
+ public ZonedDateTime parse(String string) throws Exception {
+
+ DateTimeFormatter df = this.getDateFormat();
+
+ ObjectHelper.notNull(this.pattern, "pattern");
+
+ return ZonedDateTime.parse(string, df);
+ }
+
+ DateTimeFormatter getDateFormat() {
+ DateTimeFormatter result;
+ if (locale != null) {
+ result = DateTimeFormatter.ofPattern(pattern, locale);
+ } else {
+ result = DateTimeFormatter.ofPattern(pattern);
+ }
+ return result;
+ }
+
+ @Override
+ public String getPattern() {
+ return pattern;
+ }
+
+ /**
+ * Sets the pattern
+ *
+ * @param pattern the pattern
+ */
+ public void setPattern(String pattern) {
+ this.pattern = pattern;
+ }
+ }
+
+}
diff --git
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/date/BindyDatePatternCsvUnmarshallTest.java
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/date/BindyDatePatternCsvUnmarshallTest.java
index 829e71f..5fcd598 100644
---
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/date/BindyDatePatternCsvUnmarshallTest.java
+++
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/date/BindyDatePatternCsvUnmarshallTest.java
@@ -19,6 +19,7 @@ package org.apache.camel.dataformat.bindy.model.date;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
+import java.time.ZonedDateTime;
import java.util.Date;
import org.apache.camel.EndpointInject;
@@ -55,7 +56,7 @@ public class BindyDatePatternCsvUnmarshallTest extends
AbstractJUnit4SpringConte
@Test
@DirtiesContext
public void testUnMarshallMessage() throws Exception {
- expected = "10,Christian,Mueller,12-24-2013,12-26-2015,01-06-2016
12:14:49,13:15:01,broken";
+ expected = "10,Christian,Mueller,12-24-2013,12-26-2015,01-06-2016
12:14:49,13:15:01,03-23-2017 11:17:43Z,broken";
result.expectedBodiesReceived(expected + "\r\n");
@@ -103,7 +104,10 @@ public class BindyDatePatternCsvUnmarshallTest extends
AbstractJUnit4SpringConte
@DataField(pos = 7, pattern = "HH:mm:ss")
private LocalTime receivedTime;
- @DataField(pos = 8)
+ @DataField(pos = 8, pattern = "MM-dd-yyyy HH:mm:ssX")
+ private ZonedDateTime deletedDateTime;
+
+ @DataField(pos = 9)
private ReturnReason returnReason;
public OrderNumber getOrderNr() {
@@ -167,6 +171,14 @@ public class BindyDatePatternCsvUnmarshallTest extends
AbstractJUnit4SpringConte
this.receivedTime = receivedTime;
}
+ public ZonedDateTime getDeletedDateTime() {
+ return deletedDateTime;
+ }
+
+ public void setDeletedDateTime(ZonedDateTime deletedDateTime) {
+ this.deletedDateTime = deletedDateTime;
+ }
+
public ReturnReason getReturnReason() {
return returnReason;
}