From 8eb5cfb5c66a7b35c2cd9811c194af47c69091ce Mon Sep 17 00:00:00 2001 From: Antonio Ortega <60252917@liferay.com> Date: Wed, 12 Aug 2020 11:48:13 +0200 Subject: [PATCH 1/3] LPS-118184 Format date according to the same pattern we follow to show this information in search container so it is more consistent, specially with languages like basque --- .../exporter/DDMFormInstanceRecordExporterImpl.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/apps/dynamic-data-mapping/dynamic-data-mapping-service/src/main/java/com/liferay/dynamic/data/mapping/internal/io/exporter/DDMFormInstanceRecordExporterImpl.java b/modules/apps/dynamic-data-mapping/dynamic-data-mapping-service/src/main/java/com/liferay/dynamic/data/mapping/internal/io/exporter/DDMFormInstanceRecordExporterImpl.java index ee9c78099210e3..b2d535a6290d4d 100644 --- a/modules/apps/dynamic-data-mapping/dynamic-data-mapping-service/src/main/java/com/liferay/dynamic/data/mapping/internal/io/exporter/DDMFormInstanceRecordExporterImpl.java +++ b/modules/apps/dynamic-data-mapping/dynamic-data-mapping-service/src/main/java/com/liferay/dynamic/data/mapping/internal/io/exporter/DDMFormInstanceRecordExporterImpl.java @@ -39,6 +39,7 @@ import com.liferay.petra.string.StringPool; import com.liferay.portal.kernel.dao.orm.QueryUtil; import com.liferay.portal.kernel.language.LanguageUtil; +import com.liferay.portal.kernel.util.FastDateFormatFactoryUtil; import com.liferay.portal.kernel.util.HtmlUtil; import com.liferay.portal.kernel.util.ListUtil; import com.liferay.portal.kernel.util.OrderByComparator; @@ -46,6 +47,8 @@ import com.liferay.portal.kernel.util.Validator; import com.liferay.portal.kernel.workflow.WorkflowConstants; +import java.text.Format; + import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; @@ -185,8 +188,6 @@ protected List> getDDMFormFieldValues( List ddmFormInstanceRecords, Locale locale) throws Exception { - DateTimeFormatter dateTimeFormatter = getDateTimeFormatter(locale); - List> ddmFormFieldValues = new ArrayList<>(); for (DDMFormInstanceRecord ddmFormInstanceRecord : @@ -222,11 +223,13 @@ protected List> getDDMFormFieldValues( getStatusMessage( ddmFormInstanceRecordVersion.getStatus(), locale)); + Format dateFormatDateTime = FastDateFormatFactoryUtil.getDateTime( + locale); + ddmFormFieldsValue.put( _MODIFIED_DATE, - formatDate( - ddmFormInstanceRecordVersion.getStatusDate(), - dateTimeFormatter)); + dateFormatDateTime.format( + ddmFormInstanceRecordVersion.getStatusDate())); ddmFormFieldsValue.put( _AUTHOR, ddmFormInstanceRecordVersion.getUserName()); From fb9843ade25e4ddf385cdbd7f9a0fec320a690d6 Mon Sep 17 00:00:00 2001 From: Antonio Ortega <60252917@liferay.com> Date: Thu, 13 Aug 2020 13:39:32 +0200 Subject: [PATCH 2/3] LPS-118184 Fix test --- .../DDMFormInstanceRecordExporterImplTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/modules/apps/dynamic-data-mapping/dynamic-data-mapping-service/src/test/java/com/liferay/dynamic/data/mapping/internal/io/exporter/DDMFormInstanceRecordExporterImplTest.java b/modules/apps/dynamic-data-mapping/dynamic-data-mapping-service/src/test/java/com/liferay/dynamic/data/mapping/internal/io/exporter/DDMFormInstanceRecordExporterImplTest.java index 5217c1cd2e5b56..8beda989211bfe 100644 --- a/modules/apps/dynamic-data-mapping/dynamic-data-mapping-service/src/test/java/com/liferay/dynamic/data/mapping/internal/io/exporter/DDMFormInstanceRecordExporterImplTest.java +++ b/modules/apps/dynamic-data-mapping/dynamic-data-mapping-service/src/test/java/com/liferay/dynamic/data/mapping/internal/io/exporter/DDMFormInstanceRecordExporterImplTest.java @@ -41,6 +41,7 @@ import com.liferay.portal.kernel.dao.orm.QueryUtil; import com.liferay.portal.kernel.language.Language; import com.liferay.portal.kernel.language.LanguageUtil; +import com.liferay.portal.kernel.util.FastDateFormatFactoryUtil; import com.liferay.portal.kernel.util.HashMapBuilder; import com.liferay.portal.kernel.util.Html; import com.liferay.portal.kernel.util.HtmlUtil; @@ -48,6 +49,7 @@ import com.liferay.portal.kernel.util.ListUtil; import com.liferay.portal.kernel.util.OrderByComparator; import com.liferay.portal.kernel.workflow.WorkflowConstants; +import com.liferay.portal.util.FastDateFormatFactoryImpl; import java.time.Instant; import java.time.LocalDate; @@ -84,6 +86,7 @@ public class DDMFormInstanceRecordExporterImplTest extends PowerMockito { public void setUp() throws Exception { setUpHtmlUtil(); setUpLanguageUtil(); + setUpFastDateFormatFactoryUtil(); } @Test @@ -782,6 +785,14 @@ public void testWrite() throws Exception { ); } + protected void setUpFastDateFormatFactoryUtil() { + FastDateFormatFactoryUtil fastDateFormatFactoryUtil = + new FastDateFormatFactoryUtil(); + + fastDateFormatFactoryUtil.setFastDateFormatFactory( + new FastDateFormatFactoryImpl()); + } + protected void setUpHtmlUtil() { HtmlUtil htmlUtil = new HtmlUtil(); From a25689d202392c72bf15747a0649505381db16f1 Mon Sep 17 00:00:00 2001 From: Antonio Ortega <60252917@liferay.com> Date: Fri, 14 Aug 2020 12:32:12 +0200 Subject: [PATCH 3/3] LPS-118184 Remove unused code and fix test according to new logic --- .../DDMFormInstanceRecordExporterImpl.java | 12 ---- ...DDMFormInstanceRecordExporterImplTest.java | 57 ++++--------------- 2 files changed, 11 insertions(+), 58 deletions(-) diff --git a/modules/apps/dynamic-data-mapping/dynamic-data-mapping-service/src/main/java/com/liferay/dynamic/data/mapping/internal/io/exporter/DDMFormInstanceRecordExporterImpl.java b/modules/apps/dynamic-data-mapping/dynamic-data-mapping-service/src/main/java/com/liferay/dynamic/data/mapping/internal/io/exporter/DDMFormInstanceRecordExporterImpl.java index b2d535a6290d4d..55fdb1076f1d76 100644 --- a/modules/apps/dynamic-data-mapping/dynamic-data-mapping-service/src/main/java/com/liferay/dynamic/data/mapping/internal/io/exporter/DDMFormInstanceRecordExporterImpl.java +++ b/modules/apps/dynamic-data-mapping/dynamic-data-mapping-service/src/main/java/com/liferay/dynamic/data/mapping/internal/io/exporter/DDMFormInstanceRecordExporterImpl.java @@ -49,14 +49,11 @@ import java.text.Format; -import java.time.LocalDateTime; -import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; import java.util.ArrayList; import java.util.Collection; -import java.util.Date; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; @@ -115,15 +112,6 @@ type, getDDMFormFieldsLabel(ddmFormFields, locale), return builder.build(); } - protected String formatDate( - Date date, DateTimeFormatter dateTimeFormatter) { - - LocalDateTime localDateTime = LocalDateTime.ofInstant( - date.toInstant(), ZoneId.systemDefault()); - - return dateTimeFormatter.format(localDateTime); - } - protected DateTimeFormatter getDateTimeFormatter(Locale locale) { DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT); diff --git a/modules/apps/dynamic-data-mapping/dynamic-data-mapping-service/src/test/java/com/liferay/dynamic/data/mapping/internal/io/exporter/DDMFormInstanceRecordExporterImplTest.java b/modules/apps/dynamic-data-mapping/dynamic-data-mapping-service/src/test/java/com/liferay/dynamic/data/mapping/internal/io/exporter/DDMFormInstanceRecordExporterImplTest.java index 8beda989211bfe..3df5f2d21ae4fc 100644 --- a/modules/apps/dynamic-data-mapping/dynamic-data-mapping-service/src/test/java/com/liferay/dynamic/data/mapping/internal/io/exporter/DDMFormInstanceRecordExporterImplTest.java +++ b/modules/apps/dynamic-data-mapping/dynamic-data-mapping-service/src/test/java/com/liferay/dynamic/data/mapping/internal/io/exporter/DDMFormInstanceRecordExporterImplTest.java @@ -51,9 +51,8 @@ import com.liferay.portal.kernel.workflow.WorkflowConstants; import com.liferay.portal.util.FastDateFormatFactoryImpl; -import java.time.Instant; -import java.time.LocalDate; -import java.time.ZoneId; +import java.text.Format; + import java.time.format.DateTimeFormatter; import java.util.ArrayList; @@ -232,28 +231,6 @@ public void testExportCatchException() throws Exception { ddmFormInstanceRecordExporterImpl.export(builder.build()); } - @Test - public void testFormatDate() { - DDMFormInstanceRecordExporterImpl ddmFormInstanceRecordExporterImpl = - new DDMFormInstanceRecordExporterImpl(); - - DateTimeFormatter dateTimeFormatter = - ddmFormInstanceRecordExporterImpl.getDateTimeFormatter( - new Locale("pt", "BR")); - - LocalDate localDate = LocalDate.of(2018, 2, 1); - - Instant instant = Instant.from( - localDate.atStartOfDay(ZoneId.systemDefault())); - - Date date = Date.from(instant); - - String actual = ddmFormInstanceRecordExporterImpl.formatDate( - date, dateTimeFormatter); - - Assert.assertEquals("01/02/18 00:00", actual); - } - @Test public void testGetDateTimeFormatter() { DDMFormInstanceRecordExporterImpl ddmFormInstanceRecordExporterImpl = @@ -452,6 +429,13 @@ public void testGetDDMFormFieldValues() throws Exception { DateTimeFormatter dateTimeFormatter = mock(DateTimeFormatter.class); + Date statusDate = new Date(); + + Format dateFormatDateTime = FastDateFormatFactoryUtil.getDateTime( + locale); + + String modifiedDate = dateFormatDateTime.format(statusDate); + when( ddmFormInstanceRecordExporterImpl.getDateTimeFormatter(locale) ).thenReturn( @@ -487,7 +471,7 @@ public void testGetDDMFormFieldValues() throws Exception { when( ddmFormInstanceRecordVersion.getStatusDate() ).thenReturn( - new Date() + statusDate ); when( @@ -503,13 +487,6 @@ public void testGetDDMFormFieldValues() throws Exception { "aprovado" ); - when( - ddmFormInstanceRecordExporterImpl.formatDate( - Matchers.any(Date.class), Matchers.any(DateTimeFormatter.class)) - ).thenReturn( - "01/02/2018 00:00" - ); - when( ddmFormInstanceRecordExporterImpl.getDDMFormFieldValues( ddmFormFields, ddmFormInstanceRecords, locale) @@ -524,19 +501,13 @@ public void testGetDDMFormFieldValues() throws Exception { Assert.assertEquals(StringPool.BLANK, valuesMap.get("field1")); Assert.assertEquals("value", valuesMap.get("field2")); Assert.assertEquals("aprovado", valuesMap.get("status")); - Assert.assertEquals("01/02/2018 00:00", valuesMap.get("modifiedDate")); + Assert.assertEquals(modifiedDate, valuesMap.get("modifiedDate")); Assert.assertEquals("User Name", valuesMap.get("author")); InOrder inOrder = Mockito.inOrder( ddmFormInstanceRecordExporterImpl, ddmFormInstanceRecord, ddmFormInstanceRecordVersion); - inOrder.verify( - ddmFormInstanceRecordExporterImpl, Mockito.times(1) - ).getDateTimeFormatter( - locale - ); - inOrder.verify( ddmFormInstanceRecord, Mockito.times(1) ).getDDMFormValues(); @@ -565,12 +536,6 @@ public void testGetDDMFormFieldValues() throws Exception { inOrder.verify( ddmFormInstanceRecordVersion, Mockito.times(1) ).getStatusDate(); - - inOrder.verify( - ddmFormInstanceRecordExporterImpl, Mockito.times(1) - ).formatDate( - Matchers.any(Date.class), Matchers.any(DateTimeFormatter.class) - ); } @Test