You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by zr...@apache.org on 2018/03/23 14:55:21 UTC
[camel] 05/05: CAMEL-12334: change defaults and add support fo...
This is an automated email from the ASF dual-hosted git repository.
zregvart pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 9dbf5eb2e8e2cc0c4b611cbfb564f961e045acec
Author: Zoran Regvart <zr...@apache.org>
AuthorDate: Fri Mar 23 15:43:35 2018 +0100
CAMEL-12334: change defaults and add support fo...
...r OffsetTime
The new defaults when generating Salesforce DTOs are:
- java.time.ZonedDateTime for dateTime
- java.time.OffsetTime for time
- java.time.LocalDate for date
Even though some client code might break because of this change its easy
to use plugins `customTypes` parameter to use the old types.
---
.../salesforce/api/utils/DateTimeHandling.java | 13 +++
.../salesforce/api/utils/OffsetTimeConverter.java | 52 ++++++++++
.../api/utils/OffsetTimeDeserializer.java | 32 ++++++
.../salesforce/api/utils/OffsetTimeSerializer.java | 34 ++++++
.../component/salesforce/api/utils/TimeModule.java | 4 +
.../salesforce/api/utils/XStreamUtils.java | 1 +
.../api/utils/SalesforceTimeFormatsTest.java | 6 +-
.../java/org/apache/camel/maven/GenerateMojo.java | 6 +-
.../src/test/resources/asset.json | 114 +++++++++++++++++++++
.../src/test/resources/generated/Asset.java | 36 ++++++-
.../resources/generated/Asset_LocalDateTime.java | 30 ++++++
11 files changed, 321 insertions(+), 7 deletions(-)
diff --git a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/DateTimeHandling.java b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/DateTimeHandling.java
index 6a262cf..3da6903 100644
--- a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/DateTimeHandling.java
+++ b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/DateTimeHandling.java
@@ -41,6 +41,19 @@ final class DateTimeHandling {
.appendOffset("+HHMM", "Z")//
.toFormatter();
+ static final DateTimeFormatter ISO_OFFSET_TIME = new DateTimeFormatterBuilder()//
+ .parseCaseInsensitive()//
+ .appendValue(HOUR_OF_DAY, 2)//
+ .appendLiteral(':')//
+ .appendValue(MINUTE_OF_HOUR, 2)//
+ .appendLiteral(':')//
+ .appendValue(SECOND_OF_MINUTE, 2)//
+ .optionalStart()//
+ .appendFraction(NANO_OF_SECOND, 3, 3, true)//
+ .optionalEnd()//
+ .appendOffset("+HHMM", "Z")//
+ .toFormatter();
+
private DateTimeHandling() {
}
}
diff --git a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/OffsetTimeConverter.java b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/OffsetTimeConverter.java
new file mode 100644
index 0000000..76c7269
--- /dev/null
+++ b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/OffsetTimeConverter.java
@@ -0,0 +1,52 @@
+/**
+ * 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.component.salesforce.api.utils;
+
+import java.time.OffsetTime;
+
+import com.thoughtworks.xstream.converters.SingleValueConverter;
+
+import static org.apache.camel.component.salesforce.api.utils.DateTimeHandling.ISO_OFFSET_TIME;
+
+final class OffsetTimeConverter implements SingleValueConverter {
+
+ static final SingleValueConverter INSTANCE = new OffsetTimeConverter();
+
+ private OffsetTimeConverter() {
+ }
+
+ @Override
+ public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) {
+ return OffsetTime.class.equals(type);
+ }
+
+ @Override
+ public Object fromString(final String value) {
+ return OffsetTime.parse(value, ISO_OFFSET_TIME);
+ }
+
+ @Override
+ public String toString(final Object value) {
+ if (value == null) {
+ return null;
+ }
+
+ final OffsetTime offsetTime = (OffsetTime) value;
+
+ return ISO_OFFSET_TIME.format(offsetTime);
+ }
+}
diff --git a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/OffsetTimeDeserializer.java b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/OffsetTimeDeserializer.java
new file mode 100644
index 0000000..fc360a0
--- /dev/null
+++ b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/OffsetTimeDeserializer.java
@@ -0,0 +1,32 @@
+/**
+ * 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.component.salesforce.api.utils;
+
+import java.time.OffsetTime;
+
+import com.fasterxml.jackson.databind.JsonDeserializer;
+
+final class OffsetTimeDeserializer extends com.fasterxml.jackson.datatype.jsr310.deser.OffsetTimeDeserializer {
+
+ static final JsonDeserializer<OffsetTime> INSTANCE = new OffsetTimeDeserializer();
+
+ private static final long serialVersionUID = 1L;
+
+ private OffsetTimeDeserializer() {
+ super(DateTimeHandling.ISO_OFFSET_TIME);
+ }
+}
diff --git a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/OffsetTimeSerializer.java b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/OffsetTimeSerializer.java
new file mode 100644
index 0000000..6f0e497
--- /dev/null
+++ b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/OffsetTimeSerializer.java
@@ -0,0 +1,34 @@
+/**
+ * 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.component.salesforce.api.utils;
+
+import java.time.OffsetTime;
+
+import com.fasterxml.jackson.databind.JsonSerializer;
+
+final class OffsetTimeSerializer extends com.fasterxml.jackson.datatype.jsr310.ser.OffsetTimeSerializer {
+
+ static final JsonSerializer<OffsetTime> INSTANCE = new OffsetTimeSerializer();
+
+ private static final long serialVersionUID = 1L;
+
+ private OffsetTimeSerializer() {
+ super(com.fasterxml.jackson.datatype.jsr310.ser.OffsetTimeSerializer.INSTANCE, null,
+ DateTimeHandling.ISO_OFFSET_TIME);
+ }
+
+}
diff --git a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/TimeModule.java b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/TimeModule.java
index bcad059..fcbfc2e 100644
--- a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/TimeModule.java
+++ b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/TimeModule.java
@@ -20,6 +20,7 @@ import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
+import java.time.OffsetTime;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
@@ -61,6 +62,9 @@ public class TimeModule extends SimpleModule {
addSerializer(Instant.class, InstantSerializer.INSTANCE);
addDeserializer(Instant.class, InstantDeserializer.INSTANCE);
+
+ addSerializer(OffsetTime.class, OffsetTimeSerializer.INSTANCE);
+ addDeserializer(OffsetTime.class, OffsetTimeDeserializer.INSTANCE);
}
@Override
diff --git a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/XStreamUtils.java b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/XStreamUtils.java
index 4ec04a8..33d73d2 100644
--- a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/XStreamUtils.java
+++ b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/utils/XStreamUtils.java
@@ -106,6 +106,7 @@ public final class XStreamUtils {
result.registerConverter(OffsetDateTimeConverter.INSTANCE, XStream.PRIORITY_VERY_HIGH);
result.registerConverter(ZonedDateTimeConverter.INSTANCE, XStream.PRIORITY_VERY_HIGH);
result.registerConverter(InstantConverter.INSTANCE, XStream.PRIORITY_VERY_HIGH);
+ result.registerConverter(OffsetTimeConverter.INSTANCE, XStream.PRIORITY_VERY_HIGH);
result.setMarshallingStrategy(new TreeMarshallingStrategy());
diff --git a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/utils/SalesforceTimeFormatsTest.java b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/utils/SalesforceTimeFormatsTest.java
index 2a47013..e4cd63b 100644
--- a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/utils/SalesforceTimeFormatsTest.java
+++ b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/utils/SalesforceTimeFormatsTest.java
@@ -19,6 +19,8 @@ package org.apache.camel.component.salesforce.api.utils;
import java.io.IOException;
import java.time.Instant;
import java.time.LocalDate;
+import java.time.LocalTime;
+import java.time.OffsetTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
@@ -183,7 +185,9 @@ public class SalesforceTimeFormatsTest {
dto(instant,
instant.atZone(ZoneId.systemDefault())
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ"))), // 10
- dto(ZonedDateTime.of(2018, 03, 22, 9, 58, 8, 5000000, ZoneId.of("Z")), "2018-03-22T09:58:08.005Z") // 11
+ dto(ZonedDateTime.of(2018, 03, 22, 9, 58, 8, 5000000, ZoneId.of("Z")), "2018-03-22T09:58:08.005Z"), // 11
+ dto(OffsetTime.of(LocalTime.MIDNIGHT, ZoneOffset.UTC), "00:00:00.000Z"), // 12
+ dto(OffsetTime.of(12, 13, 14, 7000000, ZoneOffset.UTC), "12:13:14.007Z") // 13
);
}
diff --git a/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/java/org/apache/camel/maven/GenerateMojo.java b/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/java/org/apache/camel/maven/GenerateMojo.java
index ef9031c..df2eb9b 100644
--- a/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/java/org/apache/camel/maven/GenerateMojo.java
+++ b/components/camel-salesforce/camel-salesforce-maven-plugin/src/main/java/org/apache/camel/maven/GenerateMojo.java
@@ -484,15 +484,15 @@ public class GenerateMojo extends AbstractSalesforceMojo {
{"double", "Double"}, //
{"boolean", "Boolean"}, //
{"byte", "Byte"}, //
- {"dateTime", "java.time.ZonedDateTime"}, //
// the blob base64Binary type is mapped to String URL for retrieving
// the blob
{"base64Binary", "String"}, //
{"unsignedInt", "Long"}, //
{"unsignedShort", "Integer"}, //
{"unsignedByte", "Short"}, //
- {"time", "java.time.ZonedDateTime"}, //
- {"date", "java.time.ZonedDateTime"}, //
+ {"dateTime", "java.time.ZonedDateTime"}, //
+ {"time", "java.time.OffsetTime"}, //
+ {"date", "java.time.LocalDate"}, //
{"g", "java.time.ZonedDateTime"}, //
// Salesforce maps any types like string, picklist, reference, etc.
// to string
diff --git a/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/resources/asset.json b/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/resources/asset.json
index 2caa54c..9864a8e 100644
--- a/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/resources/asset.json
+++ b/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/resources/asset.json
@@ -122,6 +122,120 @@
"unique": false,
"updateable": true,
"writeRequiresMasterRead": false
+ },
+ {
+ "aggregatable": true,
+ "autoNumber": false,
+ "byteLength": 0,
+ "calculated": false,
+ "calculatedFormula": null,
+ "cascadeDelete": false,
+ "caseSensitive": false,
+ "compoundFieldName": null,
+ "controllerName": null,
+ "createable": true,
+ "custom": true,
+ "defaultValue": null,
+ "defaultValueFormula": null,
+ "defaultedOnCreate": false,
+ "dependentPicklist": false,
+ "deprecatedAndHidden": false,
+ "digits": 0,
+ "displayLocationInDecimal": false,
+ "encrypted": false,
+ "externalId": false,
+ "extraTypeInfo": null,
+ "filterable": true,
+ "filteredLookupInfo": null,
+ "groupable": false,
+ "highScaleNumber": false,
+ "htmlFormatted": false,
+ "idLookup": false,
+ "inlineHelpText": null,
+ "label": "date_time",
+ "length": 0,
+ "mask": null,
+ "maskType": null,
+ "name": "date_time",
+ "nameField": false,
+ "namePointing": false,
+ "nillable": true,
+ "permissionable": true,
+ "picklistValues": [],
+ "polymorphicForeignKey": false,
+ "precision": 0,
+ "queryByDistance": false,
+ "referenceTargetField": null,
+ "referenceTo": [],
+ "relationshipName": null,
+ "relationshipOrder": null,
+ "restrictedDelete": false,
+ "restrictedPicklist": false,
+ "scale": 0,
+ "searchPrefilterable": false,
+ "soapType": "xsd:dateTime",
+ "sortable": true,
+ "type": "datetime",
+ "unique": false,
+ "updateable": true,
+ "writeRequiresMasterRead": false
+ },
+ {
+ "aggregatable": false,
+ "autoNumber": false,
+ "byteLength": 0,
+ "calculated": false,
+ "calculatedFormula": null,
+ "cascadeDelete": false,
+ "caseSensitive": false,
+ "compoundFieldName": null,
+ "controllerName": null,
+ "createable": true,
+ "custom": true,
+ "defaultValue": null,
+ "defaultValueFormula": null,
+ "defaultedOnCreate": false,
+ "dependentPicklist": false,
+ "deprecatedAndHidden": false,
+ "digits": 0,
+ "displayLocationInDecimal": false,
+ "encrypted": false,
+ "externalId": false,
+ "extraTypeInfo": null,
+ "filterable": true,
+ "filteredLookupInfo": null,
+ "groupable": false,
+ "highScaleNumber": false,
+ "htmlFormatted": false,
+ "idLookup": false,
+ "inlineHelpText": null,
+ "label": "time",
+ "length": 0,
+ "mask": null,
+ "maskType": null,
+ "name": "time",
+ "nameField": false,
+ "namePointing": false,
+ "nillable": true,
+ "permissionable": true,
+ "picklistValues": [],
+ "polymorphicForeignKey": false,
+ "precision": 0,
+ "queryByDistance": false,
+ "referenceTargetField": null,
+ "referenceTo": [],
+ "relationshipName": null,
+ "relationshipOrder": null,
+ "restrictedDelete": false,
+ "restrictedPicklist": false,
+ "scale": 0,
+ "searchPrefilterable": false,
+ "soapType": "xsd:time",
+ "sortable": true,
+ "type": "time",
+ "unique": false,
+ "updateable": true,
+ "writeRequiresMasterRead": false
}
],
"hasSubtypes": false,
diff --git a/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/resources/generated/Asset.java b/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/resources/generated/Asset.java
index 00468ec..de25141 100644
--- a/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/resources/generated/Asset.java
+++ b/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/resources/generated/Asset.java
@@ -32,18 +32,44 @@ public class Asset extends AbstractDescribedSObjectBase {
private static final SObjectDescription DESCRIPTION = createSObjectDescription();
// InstallDate
- private java.time.ZonedDateTime InstallDate;
+ private java.time.LocalDate InstallDate;
@JsonProperty("InstallDate")
- public java.time.ZonedDateTime getInstallDate() {
+ public java.time.LocalDate getInstallDate() {
return this.InstallDate;
}
@JsonProperty("InstallDate")
- public void setInstallDate(java.time.ZonedDateTime InstallDate) {
+ public void setInstallDate(java.time.LocalDate InstallDate) {
this.InstallDate = InstallDate;
}
+ // date_time
+ private java.time.ZonedDateTime date_time;
+
+ @JsonProperty("date_time")
+ public java.time.ZonedDateTime getdate_time() {
+ return this.date_time;
+ }
+
+ @JsonProperty("date_time")
+ public void setdate_time(java.time.ZonedDateTime date_time) {
+ this.date_time = date_time;
+ }
+
+ // time
+ private java.time.OffsetTime time;
+
+ @JsonProperty("time")
+ public java.time.OffsetTime gettime() {
+ return this.time;
+ }
+
+ @JsonProperty("time")
+ public void settime(java.time.OffsetTime time) {
+ this.time = time;
+ }
+
@Override
public final SObjectDescription description() {
@@ -96,6 +122,10 @@ public class Asset extends AbstractDescribedSObjectBase {
fields1.add(sObjectField1);
final SObjectField sObjectField2 = createField("InstallDate", "Install Date", "date", "xsd:date", 0, false, true, false, false, false, false, false);
fields1.add(sObjectField2);
+ final SObjectField sObjectField3 = createField("date_time", "date_time", "datetime", "xsd:dateTime", 0, false, true, false, false, true, false, false);
+ fields1.add(sObjectField3);
+ final SObjectField sObjectField4 = createField("time", "time", "time", "xsd:time", 0, false, true, false, false, true, false, false);
+ fields1.add(sObjectField4);
description.setActivateable(false);
description.setLabelPlural("Assets");
diff --git a/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/resources/generated/Asset_LocalDateTime.java b/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/resources/generated/Asset_LocalDateTime.java
index a0c6830..1d9d17a 100644
--- a/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/resources/generated/Asset_LocalDateTime.java
+++ b/components/camel-salesforce/camel-salesforce-maven-plugin/src/test/resources/generated/Asset_LocalDateTime.java
@@ -44,6 +44,32 @@ public class Asset extends AbstractDescribedSObjectBase {
this.InstallDate = InstallDate;
}
+ // date_time
+ private java.time.ZonedDateTime date_time;
+
+ @JsonProperty("date_time")
+ public java.time.ZonedDateTime getdate_time() {
+ return this.date_time;
+ }
+
+ @JsonProperty("date_time")
+ public void setdate_time(java.time.ZonedDateTime date_time) {
+ this.date_time = date_time;
+ }
+
+ // time
+ private java.time.OffsetTime time;
+
+ @JsonProperty("time")
+ public java.time.OffsetTime gettime() {
+ return this.time;
+ }
+
+ @JsonProperty("time")
+ public void settime(java.time.OffsetTime time) {
+ this.time = time;
+ }
+
@Override
public final SObjectDescription description() {
@@ -96,6 +122,10 @@ public class Asset extends AbstractDescribedSObjectBase {
fields1.add(sObjectField1);
final SObjectField sObjectField2 = createField("InstallDate", "Install Date", "date", "xsd:date", 0, false, true, false, false, false, false, false);
fields1.add(sObjectField2);
+ final SObjectField sObjectField3 = createField("date_time", "date_time", "datetime", "xsd:dateTime", 0, false, true, false, false, true, false, false);
+ fields1.add(sObjectField3);
+ final SObjectField sObjectField4 = createField("time", "time", "time", "xsd:time", 0, false, true, false, false, true, false, false);
+ fields1.add(sObjectField4);
description.setActivateable(false);
description.setLabelPlural("Assets");
--
To stop receiving notification emails like this one, please contact
zregvart@apache.org.