Skip to content

Commit

Permalink
Return ZonedDateTime in JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBestPessimist committed Apr 22, 2020
1 parent c90d57b commit cb4e371
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/main/java/de/metas/ui/web/notes/NotesService.java
Expand Up @@ -30,9 +30,9 @@
import de.metas.util.GuavaCollectors;
import de.metas.util.Services;
import lombok.NonNull;
import org.adempiere.util.lang.ITableRecordReference;
import org.adempiere.util.lang.impl.TableRecordReference;
import org.compiere.model.I_CM_ChatEntry;
import org.compiere.util.TimeUtil;
import org.springframework.stereotype.Service;

import java.util.List;
Expand All @@ -48,11 +48,11 @@ public NotesService(final NotesRepository notesRepository)
}

@NonNull
public List<JSONNote> getNotesFor(@NonNull final ITableRecordReference tableRecordReference)
public List<JSONNote> getNotesFor(@NonNull final TableRecordReference tableRecordReference)
{
final IUserDAO userDAO = Services.get(IUserDAO.class);

final List<I_CM_ChatEntry> chatEntries = notesRepository.retrieveAllNotes(tableRecordReference);
final List<I_CM_ChatEntry> chatEntries = notesRepository.retrieveNotes(tableRecordReference, 100);

return chatEntries.stream()
.map(it ->
Expand All @@ -61,7 +61,7 @@ public List<JSONNote> getNotesFor(@NonNull final ITableRecordReference tableReco

return JSONNote.builder()
.text(it.getCharacterData())
.created(it.getCreated().toString())
.created(TimeUtil.asZonedDateTime(it.getCreated()))
.createdBy(user.getName())
.build();
})
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/de/metas/ui/web/notes/json/JSONNote.java
Expand Up @@ -29,6 +29,8 @@
import lombok.NonNull;
import lombok.Value;

import java.time.ZonedDateTime;

@Builder
@Value
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE, isGetterVisibility = JsonAutoDetect.Visibility.NONE, setterVisibility = JsonAutoDetect.Visibility.NONE)
Expand All @@ -37,7 +39,7 @@ public class JSONNote
{
@NonNull String createdBy;

@NonNull String created;
@NonNull ZonedDateTime created;

@NonNull String text;

Expand Down
5 changes: 4 additions & 1 deletion src/test/java/de/metas/ui/web/notes/json/JSONNoteTest.java
Expand Up @@ -25,6 +25,9 @@
import de.metas.util.JSONObjectMapper;
import org.junit.jupiter.api.Test;

import java.time.ZoneId;
import java.time.ZonedDateTime;

import static org.assertj.core.api.Assertions.assertThat;

class JSONNoteTest
Expand All @@ -37,7 +40,7 @@ void testSerialisationDeserialisation()

final JSONNote expectedNote = JSONNote.builder()
.createdBy("who created this?")
.created("time when this was created")
.created(ZonedDateTime.of(2020, 4, 22, 11, 11, 11, 0, ZoneId.of("UTC+3")))
.text("This is a test note.\nTra la la.")
.build();

Expand Down

0 comments on commit cb4e371

Please sign in to comment.