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..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 @@ -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,14 +47,13 @@ import com.liferay.portal.kernel.util.Validator; import com.liferay.portal.kernel.workflow.WorkflowConstants; -import java.time.LocalDateTime; -import java.time.ZoneId; +import java.text.Format; + 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; @@ -112,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); @@ -185,8 +176,6 @@ protected List> getDDMFormFieldValues( List ddmFormInstanceRecords, Locale locale) throws Exception { - DateTimeFormatter dateTimeFormatter = getDateTimeFormatter(locale); - List> ddmFormFieldValues = new ArrayList<>(); for (DDMFormInstanceRecord ddmFormInstanceRecord : @@ -222,11 +211,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()); 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..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 @@ -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,10 +49,10 @@ 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.text.Format; -import java.time.Instant; -import java.time.LocalDate; -import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.ArrayList; @@ -84,6 +85,7 @@ public class DDMFormInstanceRecordExporterImplTest extends PowerMockito { public void setUp() throws Exception { setUpHtmlUtil(); setUpLanguageUtil(); + setUpFastDateFormatFactoryUtil(); } @Test @@ -229,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 = @@ -449,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( @@ -484,7 +471,7 @@ public void testGetDDMFormFieldValues() throws Exception { when( ddmFormInstanceRecordVersion.getStatusDate() ).thenReturn( - new Date() + statusDate ); when( @@ -500,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) @@ -521,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(); @@ -562,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 @@ -782,6 +750,14 @@ public void testWrite() throws Exception { ); } + protected void setUpFastDateFormatFactoryUtil() { + FastDateFormatFactoryUtil fastDateFormatFactoryUtil = + new FastDateFormatFactoryUtil(); + + fastDateFormatFactoryUtil.setFastDateFormatFactory( + new FastDateFormatFactoryImpl()); + } + protected void setUpHtmlUtil() { HtmlUtil htmlUtil = new HtmlUtil();