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 ChatRepositorychatRepositoryprivate CommonPropertiescommonPropertiesprivate EmailPropertiesemailPropertiesprivate EmailSenderServiceemailSenderServiceprivate co.mastermindcms.modules.filestorage.services.FileManagerServicefileManagerServiceprivate FrameworkOperationServiceframeworkOperationServicestatic com.fasterxml.jackson.databind.ObjectMappermapperprivate MessageRepositorymessageRepositoryprivate ProfileManagementServiceprofileManagementServiceprivate SequenceGeneratorServicesequenceGeneratorprivate MongoStorageServicestorageServiceprivate UserManagementServiceuserManagementService
-
Constructor Summary
Constructors Constructor Description MessageServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanaddAttachmentToMessageByLoggedUser(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()MessagegetLastMessageInChat(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.booleanisAttachmentExist(java.lang.String messageId)This method checks a database entity had attachment.private booleanisChatBelongsToLoggedUser(java.lang.String chatId)booleanisContactOnline(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.booleanisContainsInboxUnreadMessages(java.lang.String chatId)This method does check a database entity contains to other database entity.booleanisContainsUnreadMessages(java.lang.String chatId)This method does check a database entity contains to other database entity.private booleanisFileAllowsToRead(java.io.File file)private booleanisMessageBelongsToLoggedUser(java.lang.String messageId)private booleanisMessageBelongsToReceiver(Chat c, Message m, Profile profile)private booleanisMessageBelongsToSender(Chat c, Message m, Profile profile)private booleanisMessageBelongsToUser(Chat c, Message m, Profile profile)booleanisNotContactOnline(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.booleanisReplyMessage(java.lang.String loginFromMessage)This method check a database entity status.booleanisRightSidedMessageAdmin(java.lang.String messageId)This method checks a database entity belongs to other database entity.booleanisSentMessage(java.lang.String loginFromMessage)This method check a database entity status.private booleanisShowDivider(java.time.Instant prev, java.time.Instant next)ChatDTOmapChatToDto(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.voidremoveAttachmentFromMessage(java.lang.String messageId)Deprecated.booleanremoveAttachmentFromMessageByLoggedUser(java.lang.String messageId)Removes attachment from message.voidremoveChatAndClean(java.lang.String chatId)This method removes a database entity and clean all relationships from another entities.voidremoveMessageAndClean(java.lang.String messageId)This method removes a database entity and clean all relationships from another entities.voidremoveMessageFromChatById(java.lang.String messageId)This method removes database entity.voidremoveMessagesFromChat(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.voidsendNotificationEmail(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:MessageServiceThis method does calculation for a pages based on the request.- Specified by:
getPaginationChatsin 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:MessageServiceThis method does search requests and returns data as list.- Specified by:
searchAllChatsin 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:MessageServiceThis method does search requests and returns data as pages.- Specified by:
searchAllChatsPagedin 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:MessageServiceThis method does search requests and returns data as list.- Specified by:
searchChatsin 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:MessageServiceThis method retrieves a map, which can be processed in a templates.- Specified by:
searchMessagesin interfaceMessageService- Parameters:
requestJson- search json- Returns:
- map-representation of data
-
createChatAndNotify
public java.util.Optional<Chat> createChatAndNotify(Chat chat)
Description copied from interface:MessageServiceThis method creates a database entity.- Specified by:
createChatAndNotifyin 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:MessageServiceThis method creates a database entity.- Specified by:
createChatAndNotifyin interfaceMessageService- Parameters:
chatAsMap- map-representation of database entity- Returns:
- database entity
-
createChat
public java.util.Optional<Chat> createChat(Chat chatItem)
Description copied from interface:MessageServiceThis method creates a database entity.- Specified by:
createChatin 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:MessageServiceThis method creates a database entity.- Specified by:
createChatin interfaceMessageService- Parameters:
chatAsMap- map-representation of database entity- Returns:
- database entity
-
createMessageAndNotify
public java.util.Optional<Message> createMessageAndNotify(Message message)
Description copied from interface:MessageServiceThis method creates a database entity.- Specified by:
createMessageAndNotifyin 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:MessageServiceThis method creates a database entity.- Specified by:
createMessageAndNotifyin 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:MessageServiceThis method creates a database entity.- Specified by:
createMessagein 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:MessageServiceThis method creates a database entity.- Specified by:
createMessagein 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:MessageServiceThis method returns a database entity.- Specified by:
readChatin 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:MessageServiceThis method returns a database entity.- Specified by:
closeChatin 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:MessageServiceThis method returns a database entity.- Specified by:
clearActiveUsersin 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:MessageServiceThis method returns list database entities.- Specified by:
getConversationByChatIdin 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:MessageServiceThis method returns list database entities.- Specified by:
getActiveContactsin 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:MessageServiceThis method returns data as map.- Specified by:
getConversationPartnerin 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:MessageServiceThis method retrieves a map, which can be processed in a templates.- Specified by:
getMessagesTimelinein 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:MessageServiceThis method returns a database entity.- Specified by:
getLastMessageInChatin 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:MessageServiceThis method check a database entity status.- Specified by:
isSentMessagein 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:MessageServiceThis method check a database entity status.- Specified by:
isReplyMessagein 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:MessageServiceThis method checks a database entity had attachment.- Specified by:
isAttachmentExistin 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:MessageServiceThis method removes a database entity and clean all relationships from another entities.- Specified by:
removeChatAndCleanin 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:MessageServiceThis method removes relationship between database entities.- Specified by:
removeAttachmentFromMessagein interfaceMessageService- Parameters:
messageId- identification for database entity which will be removed
-
removeMessagesFromChat
public void removeMessagesFromChat(java.lang.String chatId)
Description copied from interface:MessageServiceThis method removes relationship between database entities.- Specified by:
removeMessagesFromChatin interfaceMessageService- Parameters:
chatId- identification for database entity which will be removed
-
removeMessageFromChatById
public void removeMessageFromChatById(java.lang.String messageId)
Description copied from interface:MessageServiceThis method removes database entity.- Specified by:
removeMessageFromChatByIdin interfaceMessageService- Parameters:
messageId- database entity which will be removed
-
removeMessageAndClean
public void removeMessageAndClean(java.lang.String messageId)
Description copied from interface:MessageServiceThis method removes a database entity and clean all relationships from another entities.- Specified by:
removeMessageAndCleanin 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:MessageServiceThis method checks a database entity belongs to other database entity.- Specified by:
isRightSidedMessageAdminin 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:MessageServiceThis method does check a database entity contains to other database entity.- Specified by:
isContainsUnreadMessagesin 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:MessageServiceThis method does check a database entity contains to other database entity.- Specified by:
isContainsInboxUnreadMessagesin 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:MessageServiceThis method does check a database entity is online.- Specified by:
isContactOnlinein 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:MessageServiceThis method does check a database entity is not online.- Specified by:
isNotContactOnlinein 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:MessageServiceThis method does return count a database entities.- Specified by:
getUnreadMessagesCountin 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:MessageServiceThis method does return count a database entities.- Specified by:
getUnreadMessagesCountForUserin 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:MessageServiceThis method does return count a database entities.- Specified by:
getUnreadMessagesCountForLoggedUserin 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:MessageServiceThis method does return count a database entities.- Specified by:
getMessagesCountByChatin 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:MessageServiceThis method does map product entity to dto object- Specified by:
mapChatToDtoin 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:MessageServiceAdds attachment to message.- Specified by:
addAttachmentToMessageByLoggedUserin interfaceMessageService- Parameters:
messageId- id of the orderattachment- attachment- Returns:
- success or not
-
removeAttachmentFromMessageByLoggedUser
public boolean removeAttachmentFromMessageByLoggedUser(java.lang.String messageId)
Description copied from interface:MessageServiceRemoves attachment from message.- Specified by:
removeAttachmentFromMessageByLoggedUserin 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:MessageServiceThis method returns data as list.- Specified by:
getChatDocumentUrlsin 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)
-
-