Class MessageServiceImpl
- java.lang.Object
-
- co.mastermindcms.modules.services.MessageServiceImpl
-
- All Implemented Interfaces:
MessageService
@Service public class MessageServiceImpl extends java.lang.Object implements MessageService
-
-
Field Summary
Fields Modifier and Type Field Description private ChatRepository
chatRepository
private CommonProperties
commonProperties
private EmailProperties
emailProperties
private EmailSenderService
emailSenderService
private co.mastermindcms.modules.filestorage.services.FileManagerService
fileManagerService
private FrameworkOperationService
frameworkOperationService
static com.fasterxml.jackson.databind.ObjectMapper
mapper
private MessageRepository
messageRepository
private ProfileManagementService
profileManagementService
private SequenceGeneratorService
sequenceGenerator
private MongoStorageService
storageService
private UserManagementService
userManagementService
-
Constructor Summary
Constructors Constructor Description MessageServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
addAttachmentToMessageByLoggedUser(java.lang.String messageId, Attachment attachment)
Adds attachment to message.java.util.Optional<Chat>
clearActiveUsers(java.lang.String chatId)
This method returns a database entity.java.util.Optional<Chat>
closeChat(java.lang.String chatId)
This method returns a database entity.java.util.Optional<Chat>
createChat(Chat chatItem)
This method creates a database entity.java.util.Optional<Chat>
createChat(java.util.LinkedHashMap<java.lang.String,java.lang.Object> chatAsMap)
This method creates a database entity.java.util.Optional<Chat>
createChatAndNotify(Chat chat)
This method creates a database entity.java.util.Optional<Chat>
createChatAndNotify(java.util.LinkedHashMap<java.lang.String,java.lang.Object> chatAsMap)
This method creates a database entity.java.util.Optional<Message>
createMessage(Message messageItem)
This method creates a database entity.java.util.Optional<Message>
createMessage(java.util.LinkedHashMap<java.lang.String,java.lang.Object> messageAsMap)
This method creates a database entity.java.util.Optional<Message>
createMessageAndNotify(Message message)
This method creates a database entity.java.util.Optional<Message>
createMessageAndNotify(java.util.LinkedHashMap<java.lang.String,java.lang.Object> messageAsMap)
This method creates a database entity.java.util.List<Profile>
getActiveContacts(java.lang.String dbName, java.lang.String collection, java.lang.String propertyName, java.lang.String filter)
This method returns list database entities.java.util.List<Attachment>
getChatDocumentUrls(java.lang.String chatId, java.lang.String sellerId)
This method returns data as list.private java.util.stream.Stream<Chat>
getChatsByLoggedUser()
java.util.List<Message>
getConversationByChatId(java.lang.String chatId)
This method returns list database entities.java.util.Map<java.lang.String,java.lang.Object>
getConversationPartner(java.lang.String chatId)
This method returns data as map.private java.util.stream.Stream<Chat>
getInboxChatsByLoggedUser()
private java.util.List<Message>
getInboxMessagesByLoggedUser()
Message
getLastMessageInChat(java.lang.String chatId)
This method returns a database entity.java.util.Map<java.lang.String,java.lang.Object>
getMessagesCountByChat(java.lang.String chatId)
This method does return count a database entities.java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
getMessagesTimeline(java.lang.String queryExpression, java.lang.String searchTerm, java.lang.String sortName, java.lang.Integer offset, java.lang.Integer limit)
This method retrieves a map, which can be processed in a templates.java.util.Deque<java.util.Map<java.lang.String,java.lang.Object>>
getPaginationChats(java.lang.String requestJson)
This method does calculation for a pages based on the request.java.util.Map<java.lang.String,java.lang.String>
getUnreadMessagesCount(java.lang.String chatId)
This method does return count a database entities.java.util.Map<java.lang.String,java.lang.String>
getUnreadMessagesCountForLoggedUser()
This method does return count a database entities.java.util.Map<java.lang.String,java.lang.String>
getUnreadMessagesCountForUser(java.lang.String chatId, java.lang.String profileId)
This method does return count a database entities.boolean
isAttachmentExist(java.lang.String messageId)
This method checks a database entity had attachment.private boolean
isChatBelongsToLoggedUser(java.lang.String chatId)
boolean
isContactOnline(java.lang.String dbName, java.lang.String collection, java.lang.String propertyName, java.lang.String filter)
This method does check a database entity is online.boolean
isContainsInboxUnreadMessages(java.lang.String chatId)
This method does check a database entity contains to other database entity.boolean
isContainsUnreadMessages(java.lang.String chatId)
This method does check a database entity contains to other database entity.private boolean
isFileAllowsToRead(java.io.File file)
private boolean
isMessageBelongsToLoggedUser(java.lang.String messageId)
private boolean
isMessageBelongsToReceiver(Chat c, Message m, Profile profile)
private boolean
isMessageBelongsToSender(Chat c, Message m, Profile profile)
private boolean
isMessageBelongsToUser(Chat c, Message m, Profile profile)
boolean
isNotContactOnline(java.lang.String dbName, java.lang.String collection, java.lang.String propertyName, java.lang.String filter)
This method does check a database entity is not online.boolean
isReplyMessage(java.lang.String loginFromMessage)
This method check a database entity status.boolean
isRightSidedMessageAdmin(java.lang.String messageId)
This method checks a database entity belongs to other database entity.boolean
isSentMessage(java.lang.String loginFromMessage)
This method check a database entity status.private boolean
isShowDivider(java.time.Instant prev, java.time.Instant next)
ChatDTO
mapChatToDto(Chat chat, boolean optimal)
This method does map product entity to dto objectjava.util.Optional<Chat>
readChat(java.lang.String chatId)
This method returns a database entity.void
removeAttachmentFromMessage(java.lang.String messageId)
Deprecated.boolean
removeAttachmentFromMessageByLoggedUser(java.lang.String messageId)
Removes attachment from message.void
removeChatAndClean(java.lang.String chatId)
This method removes a database entity and clean all relationships from another entities.void
removeMessageAndClean(java.lang.String messageId)
This method removes a database entity and clean all relationships from another entities.void
removeMessageFromChatById(java.lang.String messageId)
This method removes database entity.void
removeMessagesFromChat(java.lang.String chatId)
This method removes relationship between database entities.java.util.LinkedHashSet<ChatDTO>
searchAllChats(java.lang.String requestJson)
This method does search requests and returns data as list.org.springframework.data.domain.Page<Chat>
searchAllChatsPaged(java.lang.String requestJson)
This method does search requests and returns data as pages.java.util.List<ChatDTO>
searchChats(java.lang.String requestJson)
This method does search requests and returns data as list.java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
searchMessages(java.lang.String requestJson)
This method retrieves a map, which can be processed in a templates.void
sendNotificationEmail(Profile profile, java.lang.String chatTopic, java.lang.String messageText)
-
-
-
Field Detail
-
messageRepository
@Autowired private MessageRepository messageRepository
-
chatRepository
@Autowired private ChatRepository chatRepository
-
profileManagementService
@Autowired private ProfileManagementService profileManagementService
-
userManagementService
@Autowired private UserManagementService userManagementService
-
emailSenderService
@Autowired private EmailSenderService emailSenderService
-
emailProperties
@Autowired private EmailProperties emailProperties
-
sequenceGenerator
@Autowired private SequenceGeneratorService sequenceGenerator
-
storageService
@Autowired private MongoStorageService storageService
-
fileManagerService
@Autowired private co.mastermindcms.modules.filestorage.services.FileManagerService fileManagerService
-
frameworkOperationService
@Autowired private FrameworkOperationService frameworkOperationService
-
commonProperties
@Autowired private CommonProperties commonProperties
-
mapper
public static final com.fasterxml.jackson.databind.ObjectMapper mapper
-
-
Method Detail
-
getPaginationChats
public java.util.Deque<java.util.Map<java.lang.String,java.lang.Object>> getPaginationChats(java.lang.String requestJson)
Description copied from interface:MessageService
This method does calculation for a pages based on the request.- Specified by:
getPaginationChats
in interfaceMessageService
- Parameters:
requestJson
- JSON-object of request contains an instructions for search queries- Returns:
- map-representation of data
-
searchAllChats
public java.util.LinkedHashSet<ChatDTO> searchAllChats(java.lang.String requestJson)
Description copied from interface:MessageService
This method does search requests and returns data as list.- Specified by:
searchAllChats
in interfaceMessageService
- Parameters:
requestJson
- search request- Returns:
- data transport entities as list
-
searchAllChatsPaged
public org.springframework.data.domain.Page<Chat> searchAllChatsPaged(java.lang.String requestJson)
Description copied from interface:MessageService
This method does search requests and returns data as pages.- Specified by:
searchAllChatsPaged
in interfaceMessageService
- Parameters:
requestJson
- JSON-object of request contains an instructions for search queries- Returns:
- database entities separated to pages
-
searchChats
public java.util.List<ChatDTO> searchChats(java.lang.String requestJson)
Description copied from interface:MessageService
This method does search requests and returns data as list.- Specified by:
searchChats
in interfaceMessageService
- Parameters:
requestJson
- search json- Returns:
- database entities as list
-
searchMessages
public java.util.List<java.util.Map<java.lang.String,java.lang.Object>> searchMessages(java.lang.String requestJson)
Description copied from interface:MessageService
This method retrieves a map, which can be processed in a templates.- Specified by:
searchMessages
in interfaceMessageService
- Parameters:
requestJson
- search json- Returns:
- map-representation of data
-
createChatAndNotify
public java.util.Optional<Chat> createChatAndNotify(Chat chat)
Description copied from interface:MessageService
This method creates a database entity.- Specified by:
createChatAndNotify
in interfaceMessageService
- Parameters:
chat
- database entity- Returns:
- optional value to externally interaction
-
createChatAndNotify
public java.util.Optional<Chat> createChatAndNotify(java.util.LinkedHashMap<java.lang.String,java.lang.Object> chatAsMap)
Description copied from interface:MessageService
This method creates a database entity.- Specified by:
createChatAndNotify
in interfaceMessageService
- Parameters:
chatAsMap
- map-representation of database entity- Returns:
- database entity
-
createChat
public java.util.Optional<Chat> createChat(Chat chatItem)
Description copied from interface:MessageService
This method creates a database entity.- Specified by:
createChat
in interfaceMessageService
- Parameters:
chatItem
- database entity- Returns:
- optional value to externally interaction
-
createChat
@Transactional public java.util.Optional<Chat> createChat(java.util.LinkedHashMap<java.lang.String,java.lang.Object> chatAsMap)
Description copied from interface:MessageService
This method creates a database entity.- Specified by:
createChat
in interfaceMessageService
- Parameters:
chatAsMap
- map-representation of database entity- Returns:
- database entity
-
createMessageAndNotify
public java.util.Optional<Message> createMessageAndNotify(Message message)
Description copied from interface:MessageService
This method creates a database entity.- Specified by:
createMessageAndNotify
in interfaceMessageService
- Parameters:
message
- database entity- Returns:
- optional value to externally interaction
-
createMessageAndNotify
public java.util.Optional<Message> createMessageAndNotify(java.util.LinkedHashMap<java.lang.String,java.lang.Object> messageAsMap)
Description copied from interface:MessageService
This method creates a database entity.- Specified by:
createMessageAndNotify
in interfaceMessageService
- Parameters:
messageAsMap
- map-representation of database entity- Returns:
- database entity
-
createMessage
@Transactional public java.util.Optional<Message> createMessage(java.util.LinkedHashMap<java.lang.String,java.lang.Object> messageAsMap)
Description copied from interface:MessageService
This method creates a database entity.- Specified by:
createMessage
in interfaceMessageService
- Parameters:
messageAsMap
- map-representation of database entity- Returns:
- database entity
-
createMessage
@Transactional public java.util.Optional<Message> createMessage(Message messageItem)
Description copied from interface:MessageService
This method creates a database entity.- Specified by:
createMessage
in interfaceMessageService
- Parameters:
messageItem
- database entity- Returns:
- optional value to externally interaction
-
readChat
public java.util.Optional<Chat> readChat(java.lang.String chatId)
Description copied from interface:MessageService
This method returns a database entity.- Specified by:
readChat
in interfaceMessageService
- Parameters:
chatId
- database entity which will be checked and returned- Returns:
- optional value to externally interaction
-
closeChat
public java.util.Optional<Chat> closeChat(java.lang.String chatId)
Description copied from interface:MessageService
This method returns a database entity.- Specified by:
closeChat
in interfaceMessageService
- Parameters:
chatId
- database entity which will be checked and returned- Returns:
- optional value to externally interaction
-
clearActiveUsers
public java.util.Optional<Chat> clearActiveUsers(java.lang.String chatId)
Description copied from interface:MessageService
This method returns a database entity.- Specified by:
clearActiveUsers
in interfaceMessageService
- Parameters:
chatId
- database entity which will be checked and returned- Returns:
- optional value to externally interaction
-
getConversationByChatId
public java.util.List<Message> getConversationByChatId(java.lang.String chatId)
Description copied from interface:MessageService
This method returns list database entities.- Specified by:
getConversationByChatId
in interfaceMessageService
- Parameters:
chatId
- identification for database entity from which will be filtered and returned other database entity- Returns:
- database entities as list
-
getActiveContacts
public java.util.List<Profile> getActiveContacts(java.lang.String dbName, java.lang.String collection, java.lang.String propertyName, java.lang.String filter)
Description copied from interface:MessageService
This method returns list database entities.- Specified by:
getActiveContacts
in interfaceMessageService
- Parameters:
dbName
- name for database where will be checkedcollection
- name for database collection where will be checkedpropertyName
- field for database entity which will be added in JSON-Object for checkedfilter
- field for database entity which will be filtered- Returns:
- database entities as list
-
getConversationPartner
public java.util.Map<java.lang.String,java.lang.Object> getConversationPartner(java.lang.String chatId)
Description copied from interface:MessageService
This method returns data as map.- Specified by:
getConversationPartner
in interfaceMessageService
- Parameters:
chatId
- identification for filter and return data- Returns:
- data as map
-
getMessagesTimeline
public java.util.List<java.util.Map<java.lang.String,java.lang.Object>> getMessagesTimeline(java.lang.String queryExpression, java.lang.String searchTerm, java.lang.String sortName, java.lang.Integer offset, java.lang.Integer limit)
Description copied from interface:MessageService
This method retrieves a map, which can be processed in a templates.- Specified by:
getMessagesTimeline
in interfaceMessageService
- Parameters:
queryExpression
- search query expressionsearchTerm
- field name for database entity which will be filtered and searchedsortName
- value for database entity which will be sortedoffset
- offset for returned itemslimit
- limit for returned items- Returns:
- map-representation of data
-
getLastMessageInChat
public Message getLastMessageInChat(java.lang.String chatId)
Description copied from interface:MessageService
This method returns a database entity.- Specified by:
getLastMessageInChat
in interfaceMessageService
- Parameters:
chatId
- database entity which will be filtered and returned- Returns:
- database entity
-
isSentMessage
public boolean isSentMessage(java.lang.String loginFromMessage)
Description copied from interface:MessageService
This method check a database entity status.- Specified by:
isSentMessage
in interfaceMessageService
- Parameters:
loginFromMessage
- identification for database entity which will be checked- Returns:
- value as boolean
-
isReplyMessage
public boolean isReplyMessage(java.lang.String loginFromMessage)
Description copied from interface:MessageService
This method check a database entity status.- Specified by:
isReplyMessage
in interfaceMessageService
- Parameters:
loginFromMessage
- identification for database entity which will be checked- Returns:
- value as boolean
-
isAttachmentExist
public boolean isAttachmentExist(java.lang.String messageId)
Description copied from interface:MessageService
This method checks a database entity had attachment.- Specified by:
isAttachmentExist
in interfaceMessageService
- Parameters:
messageId
- identification for database entity which will be checked- Returns:
- value as boolean
-
removeChatAndClean
public void removeChatAndClean(java.lang.String chatId)
Description copied from interface:MessageService
This method removes a database entity and clean all relationships from another entities.- Specified by:
removeChatAndClean
in interfaceMessageService
- Parameters:
chatId
- identification for database entity which will be removed
-
removeAttachmentFromMessage
@Deprecated public void removeAttachmentFromMessage(java.lang.String messageId)
Deprecated.Description copied from interface:MessageService
This method removes relationship between database entities.- Specified by:
removeAttachmentFromMessage
in interfaceMessageService
- Parameters:
messageId
- identification for database entity which will be removed
-
removeMessagesFromChat
public void removeMessagesFromChat(java.lang.String chatId)
Description copied from interface:MessageService
This method removes relationship between database entities.- Specified by:
removeMessagesFromChat
in interfaceMessageService
- Parameters:
chatId
- identification for database entity which will be removed
-
removeMessageFromChatById
public void removeMessageFromChatById(java.lang.String messageId)
Description copied from interface:MessageService
This method removes database entity.- Specified by:
removeMessageFromChatById
in interfaceMessageService
- Parameters:
messageId
- database entity which will be removed
-
removeMessageAndClean
public void removeMessageAndClean(java.lang.String messageId)
Description copied from interface:MessageService
This method removes a database entity and clean all relationships from another entities.- Specified by:
removeMessageAndClean
in interfaceMessageService
- Parameters:
messageId
- identification for database entity which will be removed
-
sendNotificationEmail
@Transactional public void sendNotificationEmail(Profile profile, java.lang.String chatTopic, java.lang.String messageText)
-
isRightSidedMessageAdmin
public boolean isRightSidedMessageAdmin(java.lang.String messageId)
Description copied from interface:MessageService
This method checks a database entity belongs to other database entity.- Specified by:
isRightSidedMessageAdmin
in interfaceMessageService
- Parameters:
messageId
- identification for database entity which will be checked- Returns:
- value as boolean
-
isContainsUnreadMessages
public boolean isContainsUnreadMessages(java.lang.String chatId)
Description copied from interface:MessageService
This method does check a database entity contains to other database entity.- Specified by:
isContainsUnreadMessages
in interfaceMessageService
- Parameters:
chatId
- identification for database entity which will be checked- Returns:
- value as boolean
-
isContainsInboxUnreadMessages
public boolean isContainsInboxUnreadMessages(java.lang.String chatId)
Description copied from interface:MessageService
This method does check a database entity contains to other database entity.- Specified by:
isContainsInboxUnreadMessages
in interfaceMessageService
- Parameters:
chatId
- identification for database entity which will be checked- Returns:
- value as boolean
-
isContactOnline
public boolean isContactOnline(java.lang.String dbName, java.lang.String collection, java.lang.String propertyName, java.lang.String filter)
Description copied from interface:MessageService
This method does check a database entity is online.- Specified by:
isContactOnline
in interfaceMessageService
- Parameters:
dbName
- name for database where will be checkedcollection
- name for database collection where will be checkedpropertyName
- field for database entity which will be added in JSON-Object for checkedfilter
- field for database entity which will be filtered- Returns:
- value as boolean
-
isNotContactOnline
public boolean isNotContactOnline(java.lang.String dbName, java.lang.String collection, java.lang.String propertyName, java.lang.String filter)
Description copied from interface:MessageService
This method does check a database entity is not online.- Specified by:
isNotContactOnline
in interfaceMessageService
- Parameters:
dbName
- name for database where will be checkedcollection
- name for database collection where will be checkedpropertyName
- field for database entity which will be added in JSON-Object for checkedfilter
- field for database entity which will be filtered- Returns:
- value as boolean
-
getUnreadMessagesCount
public java.util.Map<java.lang.String,java.lang.String> getUnreadMessagesCount(java.lang.String chatId)
Description copied from interface:MessageService
This method does return count a database entities.- Specified by:
getUnreadMessagesCount
in interfaceMessageService
- Parameters:
chatId
- identification for database which will be checked and calculated- Returns:
- value as map
-
getUnreadMessagesCountForUser
public java.util.Map<java.lang.String,java.lang.String> getUnreadMessagesCountForUser(java.lang.String chatId, java.lang.String profileId)
Description copied from interface:MessageService
This method does return count a database entities.- Specified by:
getUnreadMessagesCountForUser
in interfaceMessageService
- Parameters:
chatId
- identification for database which will be checked and calculatedprofileId
- identification for database for which will be checked and calculated other database entity- Returns:
- value as map
-
getUnreadMessagesCountForLoggedUser
public java.util.Map<java.lang.String,java.lang.String> getUnreadMessagesCountForLoggedUser()
Description copied from interface:MessageService
This method does return count a database entities.- Specified by:
getUnreadMessagesCountForLoggedUser
in interfaceMessageService
- Returns:
- value as map
-
getMessagesCountByChat
public java.util.Map<java.lang.String,java.lang.Object> getMessagesCountByChat(java.lang.String chatId)
Description copied from interface:MessageService
This method does return count a database entities.- Specified by:
getMessagesCountByChat
in interfaceMessageService
- Parameters:
chatId
- identification for database which will be checked and calculated- Returns:
- value as map
-
mapChatToDto
public ChatDTO mapChatToDto(Chat chat, boolean optimal)
Description copied from interface:MessageService
This method does map product entity to dto object- Specified by:
mapChatToDto
in interfaceMessageService
- Parameters:
chat
- database entity which be used to map to dtooptimal
- this pointer optimises the data transfer object- Returns:
- data transport object
-
addAttachmentToMessageByLoggedUser
public boolean addAttachmentToMessageByLoggedUser(java.lang.String messageId, Attachment attachment)
Description copied from interface:MessageService
Adds attachment to message.- Specified by:
addAttachmentToMessageByLoggedUser
in interfaceMessageService
- Parameters:
messageId
- id of the orderattachment
- attachment- Returns:
- success or not
-
removeAttachmentFromMessageByLoggedUser
public boolean removeAttachmentFromMessageByLoggedUser(java.lang.String messageId)
Description copied from interface:MessageService
Removes attachment from message.- Specified by:
removeAttachmentFromMessageByLoggedUser
in interfaceMessageService
- Parameters:
messageId
- id of the order- Returns:
- success or not
-
getChatDocumentUrls
public java.util.List<Attachment> getChatDocumentUrls(java.lang.String chatId, java.lang.String sellerId)
Description copied from interface:MessageService
This method returns data as list.- Specified by:
getChatDocumentUrls
in interfaceMessageService
- Parameters:
chatId
- identification for database entity which related beans list be returnedsellerId
- identification for seller entity- Returns:
- database beans as list
-
isFileAllowsToRead
private boolean isFileAllowsToRead(java.io.File file)
-
isChatBelongsToLoggedUser
private boolean isChatBelongsToLoggedUser(java.lang.String chatId)
-
isMessageBelongsToReceiver
private boolean isMessageBelongsToReceiver(Chat c, Message m, Profile profile)
-
isMessageBelongsToSender
private boolean isMessageBelongsToSender(Chat c, Message m, Profile profile)
-
isMessageBelongsToLoggedUser
private boolean isMessageBelongsToLoggedUser(java.lang.String messageId)
-
getChatsByLoggedUser
@NotNull private java.util.stream.Stream<Chat> getChatsByLoggedUser()
-
getInboxChatsByLoggedUser
@NotNull private java.util.stream.Stream<Chat> getInboxChatsByLoggedUser()
-
getInboxMessagesByLoggedUser
@NotNull private java.util.List<Message> getInboxMessagesByLoggedUser()
-
isShowDivider
private boolean isShowDivider(java.time.Instant prev, java.time.Instant next)
-
-