Switched from Date to Instant

Was causing issues with json parsing in desktop client
This commit is contained in:
Rohan Sircar 2020-06-16 19:12:25 +05:30
parent 91986d5386
commit 6378f4b225
7 changed files with 12 additions and 15 deletions

View File

@ -52,7 +52,7 @@ public class AdminRESTController {
public List<ChatMessageDTO> sendNewMessages(@PathVariable String userName, public List<ChatMessageDTO> sendNewMessages(@PathVariable String userName,
@PathVariable Instant lastMessageTime, Principal principal) { @PathVariable Instant lastMessageTime, Principal principal) {
List<ChatMessageDTO> chatMessageDTOs = chatService.getNewMessages( List<ChatMessageDTO> chatMessageDTOs = chatService.getNewMessages(
principal.getName(), userName, Date.from(lastMessageTime)); principal.getName(), userName, lastMessageTime);
return chatMessageDTOs; return chatMessageDTOs;
} }

View File

@ -2,7 +2,6 @@ package org.ros.chatto.controller;
import java.security.Principal; import java.security.Principal;
import java.time.Instant; import java.time.Instant;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -91,7 +90,7 @@ public class ChatMessageController {
@PathVariable final Instant lastMessageTime, @PathVariable final Instant lastMessageTime,
final Principal principal) { final Principal principal) {
final List<ChatMessageDTO> chatMessageDTOs = chatService.getNewMessages( final List<ChatMessageDTO> chatMessageDTOs = chatService.getNewMessages(
principal.getName(), userName, Date.from(lastMessageTime)); principal.getName(), userName, lastMessageTime);
return chatMessageDTOs; return chatMessageDTOs;
} }

View File

@ -1,10 +1,10 @@
package org.ros.chatto.dto; package org.ros.chatto.dto;
import java.util.Date;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern; import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import java.time.Instant;
import lombok.Data; import lombok.Data;
@ -18,5 +18,5 @@ public class ChatMessageDTO {
@Size(max=15) @Size(max=15)
private String fromUser; private String fromUser;
private MessageCipherDTO messageCipher; private MessageCipherDTO messageCipher;
private Date messageTime; private Instant messageTime;
} }

View File

@ -12,8 +12,7 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Temporal; import java.time.Instant;
import javax.persistence.TemporalType;
import lombok.Data; import lombok.Data;
@ -38,6 +37,5 @@ public class ChatMessage {
@JoinColumn(name = "message") @JoinColumn(name = "message")
private MessageCipher messageCipher; private MessageCipher messageCipher;
@Temporal(TemporalType.TIMESTAMP) private Instant messageTime;
private Date messageTime;
} }

View File

@ -1,6 +1,5 @@
package org.ros.chatto.repository; package org.ros.chatto.repository;
import java.util.Date;
import java.util.List; import java.util.List;
import org.ros.chatto.model.ChatMessage; import org.ros.chatto.model.ChatMessage;
@ -8,6 +7,7 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.time.Instant;
@Repository @Repository
public interface ChatMessageRepository extends JpaRepository<ChatMessage, Long> { public interface ChatMessageRepository extends JpaRepository<ChatMessage, Long> {
@ -19,7 +19,7 @@ public interface ChatMessageRepository extends JpaRepository<ChatMessage, Long>
@Query("select m from ChatMessage m join fetch m.messageCipher mc join fetch m.toUser tu join fetch m.fromUser fu " @Query("select m from ChatMessage m join fetch m.messageCipher mc join fetch m.toUser tu join fetch m.fromUser fu "
+ "where (tu.userName = ?1 or tu.userName = ?2) and " + "where (tu.userName = ?1 or tu.userName = ?2) and "
+ "(fu.userName = ?1 or fu.userName = ?2) and (m.messageTime > ?3) order by m.messageTime asc") + "(fu.userName = ?1 or fu.userName = ?2) and (m.messageTime > ?3) order by m.messageTime asc")
public List<ChatMessage> getNewMessages(String fromUser, String toUser, Date lastMessageTime); public List<ChatMessage> getNewMessages(String fromUser, String toUser, Instant lastMessageTime);
@Query("select m from ChatMessage m join fetch m.messageCipher mc join fetch m.toUser tu join fetch m.fromUser fu " @Query("select m from ChatMessage m join fetch m.messageCipher mc join fetch m.toUser tu join fetch m.fromUser fu "
+ "where (tu.userName = ?1 or tu.userName = ?2) and " + "where (tu.userName = ?1 or tu.userName = ?2) and "

View File

@ -1,11 +1,11 @@
package org.ros.chatto.service; package org.ros.chatto.service;
import java.util.Date;
import java.util.List; import java.util.List;
import org.ros.chatto.dto.ChatMessageDTO; import org.ros.chatto.dto.ChatMessageDTO;
import org.ros.chatto.dto.MessageCipherDTO; import org.ros.chatto.dto.MessageCipherDTO;
import org.ros.chatto.dto.ReencryptionDTO; import org.ros.chatto.dto.ReencryptionDTO;
import java.time.Instant;
public interface ChatService { public interface ChatService {
public ChatMessageDTO createMessage(String fromUser, String toUser, public ChatMessageDTO createMessage(String fromUser, String toUser,
@ -17,7 +17,7 @@ public interface ChatService {
int page, int size); int page, int size);
public List<ChatMessageDTO> getNewMessages(String fromUser, String toUser, public List<ChatMessageDTO> getNewMessages(String fromUser, String toUser,
Date lastMessageTime); Instant lastMessageTime);
public void reencryptMessages(List<ReencryptionDTO> reencryptionDTOs); public void reencryptMessages(List<ReencryptionDTO> reencryptionDTOs);

View File

@ -1,6 +1,6 @@
package org.ros.chatto.service; package org.ros.chatto.service;
import java.util.Date; import java.time.Instant;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -87,7 +87,7 @@ public class ChatServiceImpl implements ChatService {
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public List<ChatMessageDTO> getNewMessages(final String fromUser, public List<ChatMessageDTO> getNewMessages(final String fromUser,
final String toUser, final Date lastMessageTime) { final String toUser, final Instant lastMessageTime) {
final List<ChatMessage> chatMessages = chatMessageRepository final List<ChatMessage> chatMessages = chatMessageRepository
.getNewMessages(fromUser, toUser, lastMessageTime); .getNewMessages(fromUser, toUser, lastMessageTime);
return myConversionService.convertToChatMessageDTOs(chatMessages); return myConversionService.convertToChatMessageDTOs(chatMessages);