From 5266d1f7ce7236ea57515aefaa6422be1471a873 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Fri, 15 Jun 2018 13:09:53 +0300 Subject: [PATCH 1/5] -fix de/serialization of joda type by: using of jackson joda date type to deserialize local date using a custom serializer for joda date types --- .../rm-public-rest-context.xml | 16 ++++ .../api/util/CustomDateTimeSerializer.java | 73 +++++++++++++++++++ .../api/util/CustomLocalDateSerializer.java | 73 +++++++++++++++++++ 3 files changed, 162 insertions(+) create mode 100644 rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/util/CustomDateTimeSerializer.java create mode 100644 rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/util/CustomLocalDateSerializer.java diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-public-rest-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-public-rest-context.xml index 31ae1964ff..4d147941b0 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-public-rest-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-public-rest-context.xml @@ -215,4 +215,20 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/util/CustomDateTimeSerializer.java b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/util/CustomDateTimeSerializer.java new file mode 100644 index 0000000000..162426bad7 --- /dev/null +++ b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/util/CustomDateTimeSerializer.java @@ -0,0 +1,73 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2018 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.rm.rest.api.util; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer; + +import org.joda.time.DateTime; +import org.joda.time.format.DateTimeFormat; +import org.joda.time.format.DateTimeFormatter; + +/** + * Custom Date Time serializer for formatting org.joda.time.DateTime + * + * @author Rodica Sutu + * @since 3.0 + */ +public class CustomDateTimeSerializer extends StdScalarSerializer +{ + /** Date time format */ + private final static DateTimeFormatter DATE_TIME_FORMAT = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); + + public CustomDateTimeSerializer() + { + super(DateTime.class); + } + + protected CustomDateTimeSerializer(Class t) + { + super(t); + } + + /** + * Custom serialize to convert the org.joda.time.DateTime into string value using the DATE_TIME_FORMAT + * + * @param value datetime value + * @param jgen + * @param provider + * @throws IOException + */ + @Override + public void serialize(DateTime value, JsonGenerator jgen, SerializerProvider provider) throws IOException + { + jgen.writeString(DATE_TIME_FORMAT.print(value)); + } +} diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/util/CustomLocalDateSerializer.java b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/util/CustomLocalDateSerializer.java new file mode 100644 index 0000000000..dfdc5f7afe --- /dev/null +++ b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/util/CustomLocalDateSerializer.java @@ -0,0 +1,73 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2018 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.rm.rest.api.util; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer; + +import org.joda.time.LocalDate; +import org.joda.time.format.DateTimeFormat; +import org.joda.time.format.DateTimeFormatter; + +/** + * Custom Local Date serializer for formatting org.joda.time.LocalDate + * + * @author Rodica Sutu + * @since 3.0 + */ +public class CustomLocalDateSerializer extends StdScalarSerializer +{ + /** Local date format */ + private final static DateTimeFormatter DATE_FORMAT = DateTimeFormat.forPattern("yyyy-MM-dd"); + + public CustomLocalDateSerializer() + { + super(LocalDate.class); + } + + protected CustomLocalDateSerializer(Class t) + { + super(t); + } + + /** + * Custom serialize method to convert the org.joda.time.LocalDate into string value using the DATE_FORMAT + * + * @param value local date value + * @param jgen + * @param provider + * @throws IOException + */ + @Override + public void serialize(LocalDate value, JsonGenerator jgen, SerializerProvider provider) throws IOException + { + jgen.writeString(DATE_FORMAT.print(value)); + } +} \ No newline at end of file From d2f303fab8ab20e7742968b8bd7d04ad4671030f Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Fri, 15 Jun 2018 13:11:19 +0300 Subject: [PATCH 2/5] additional changes for RM-6354 --- .../alfresco/module/org_alfresco_module_rm/module.properties | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/module.properties b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/module.properties index 22d0426b4b..d315370d7b 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/module.properties +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/module.properties @@ -7,5 +7,4 @@ module.aliases=org_alfresco_module_dod5015 module.title=Records Management module.description=Alfresco Record Management Extension module.version=${rm.module.version} - -module.repo.version.min=6.0 \ No newline at end of file +module.repo.version.min=${rm.module.repo.version.min} \ No newline at end of file From 9b16443987ae668dba76e32ccd061af7e5ca2fa9 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Fri, 15 Jun 2018 14:30:33 +0300 Subject: [PATCH 3/5] java docs updates and fix the deserialisation for the LocalDate from topics --- .../module/org_alfresco_module_rm/rm-public-rest-context.xml | 2 +- .../org/alfresco/rm/rest/api/util/CustomDateTimeSerializer.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-public-rest-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-public-rest-context.xml index 4d147941b0..900c93fba3 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-public-rest-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-public-rest-context.xml @@ -216,7 +216,7 @@ - diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/util/CustomDateTimeSerializer.java b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/util/CustomDateTimeSerializer.java index 162426bad7..0df22205ab 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/util/CustomDateTimeSerializer.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/util/CustomDateTimeSerializer.java @@ -58,7 +58,7 @@ public class CustomDateTimeSerializer extends StdScalarSerializer } /** - * Custom serialize to convert the org.joda.time.DateTime into string value using the DATE_TIME_FORMAT + * Custom serialize method to convert the org.joda.time.DateTime into string value using the DATE_TIME_FORMAT * * @param value datetime value * @param jgen From 895fca9455f28703eee56b241a1ff5b15002d0c9 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Mon, 18 Jun 2018 10:58:48 +0300 Subject: [PATCH 4/5] review changes and fix for converting string with time to date using a LocalDateDeserializer --- .../api/util/CustomDateTimeSerializer.java | 4 +- .../api/util/CustomLocalDateDeserializer.java | 86 +++++++++++++++++++ .../api/util/CustomLocalDateSerializer.java | 4 +- 3 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/util/CustomLocalDateDeserializer.java diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/util/CustomDateTimeSerializer.java b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/util/CustomDateTimeSerializer.java index 0df22205ab..2d75f5ec5d 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/util/CustomDateTimeSerializer.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/util/CustomDateTimeSerializer.java @@ -30,7 +30,7 @@ import java.io.IOException; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormat; @@ -42,7 +42,7 @@ import org.joda.time.format.DateTimeFormatter; * @author Rodica Sutu * @since 3.0 */ -public class CustomDateTimeSerializer extends StdScalarSerializer +public class CustomDateTimeSerializer extends StdSerializer { /** Date time format */ private final static DateTimeFormatter DATE_TIME_FORMAT = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/util/CustomLocalDateDeserializer.java b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/util/CustomLocalDateDeserializer.java new file mode 100644 index 0000000000..06980287d4 --- /dev/null +++ b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/util/CustomLocalDateDeserializer.java @@ -0,0 +1,86 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2018 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.rm.rest.api.util; + + +import java.io.IOException; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; + +import org.joda.time.LocalDate; + +/** + * Custom Local Date deserializer for converting a string value with time into a org.joda.time.LocalDate value + * + * @author Rodica Sutu + * @since 3.0 + */ +public class CustomLocalDateDeserializer extends StdDeserializer +{ + /** Local date format */ + private final static DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); + + + public CustomLocalDateDeserializer() + { + super(LocalDate.class); + } + protected CustomLocalDateDeserializer(Class vc) + { + super(vc); + } + + /** + * Custom deserialize method to convert a string value into a org.joda.time.LocalDate value using the DATE_FORMAT + * + * @param p local date value + * @param ctx + * @throws IOException + */ + @Override + public LocalDate deserialize(JsonParser p, DeserializationContext ctx) throws IOException + { + Date date = null; + try + { + // convert the string with time into a date value using the format DATE_FORMAT + date = DATE_FORMAT.parse(p.getText()); + } + catch (ParseException e) + { + e.printStackTrace(); + } + // convert the date into a LocalDate + return LocalDate.fromDateFields(date); + } +} diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/util/CustomLocalDateSerializer.java b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/util/CustomLocalDateSerializer.java index dfdc5f7afe..f10fd69cd4 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/util/CustomLocalDateSerializer.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/util/CustomLocalDateSerializer.java @@ -30,7 +30,7 @@ import java.io.IOException; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; import org.joda.time.LocalDate; import org.joda.time.format.DateTimeFormat; @@ -42,7 +42,7 @@ import org.joda.time.format.DateTimeFormatter; * @author Rodica Sutu * @since 3.0 */ -public class CustomLocalDateSerializer extends StdScalarSerializer +public class CustomLocalDateSerializer extends StdSerializer { /** Local date format */ private final static DateTimeFormatter DATE_FORMAT = DateTimeFormat.forPattern("yyyy-MM-dd"); From 341180024049c1c3b5d4e43849c137d424473435 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Tue, 19 Jun 2018 08:44:10 +0300 Subject: [PATCH 5/5] revert the change for truncating the date with time --- .../api/util/CustomLocalDateDeserializer.java | 86 ------------------- 1 file changed, 86 deletions(-) delete mode 100644 rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/util/CustomLocalDateDeserializer.java diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/util/CustomLocalDateDeserializer.java b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/util/CustomLocalDateDeserializer.java deleted file mode 100644 index 06980287d4..0000000000 --- a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/util/CustomLocalDateDeserializer.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2018 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * - - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ -package org.alfresco.rm.rest.api.util; - - -import java.io.IOException; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.deser.std.StdDeserializer; - -import org.joda.time.LocalDate; - -/** - * Custom Local Date deserializer for converting a string value with time into a org.joda.time.LocalDate value - * - * @author Rodica Sutu - * @since 3.0 - */ -public class CustomLocalDateDeserializer extends StdDeserializer -{ - /** Local date format */ - private final static DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); - - - public CustomLocalDateDeserializer() - { - super(LocalDate.class); - } - protected CustomLocalDateDeserializer(Class vc) - { - super(vc); - } - - /** - * Custom deserialize method to convert a string value into a org.joda.time.LocalDate value using the DATE_FORMAT - * - * @param p local date value - * @param ctx - * @throws IOException - */ - @Override - public LocalDate deserialize(JsonParser p, DeserializationContext ctx) throws IOException - { - Date date = null; - try - { - // convert the string with time into a date value using the format DATE_FORMAT - date = DATE_FORMAT.parse(p.getText()); - } - catch (ParseException e) - { - e.printStackTrace(); - } - // convert the date into a LocalDate - return LocalDate.fromDateFields(date); - } -}