Class MessageServiceImpl

    • Constructor Detail

      • MessageServiceImpl

        public MessageServiceImpl()
    • 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 interface MessageService
        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 interface MessageService
        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 interface MessageService
        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 interface MessageService
        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 interface MessageService
        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 interface MessageService
        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 interface MessageService
        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 interface MessageService
        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 interface MessageService
        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 interface MessageService
        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 interface MessageService
        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 interface MessageService
        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 interface MessageService
        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 interface MessageService
        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 interface MessageService
        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 interface MessageService
        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 interface MessageService
        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 interface MessageService
        Parameters:
        dbName - name for database where will be checked
        collection - name for database collection where will be checked
        propertyName - field for database entity which will be added in JSON-Object for checked
        filter - 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 interface MessageService
        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 interface MessageService
        Parameters:
        queryExpression - search query expression
        searchTerm - field name for database entity which will be filtered and searched
        sortName - value for database entity which will be sorted
        offset - offset for returned items
        limit - 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 interface MessageService
        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 interface MessageService
        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 interface MessageService
        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 interface MessageService
        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 interface MessageService
        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 interface MessageService
        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 interface MessageService
        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 interface MessageService
        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 interface MessageService
        Parameters:
        messageId - identification for database entity which will be removed
      • sendNotificationEmail

        @Transactional
        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 interface MessageService
        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 interface MessageService
        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 interface MessageService
        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 interface MessageService
        Parameters:
        dbName - name for database where will be checked
        collection - name for database collection where will be checked
        propertyName - field for database entity which will be added in JSON-Object for checked
        filter - 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 interface MessageService
        Parameters:
        dbName - name for database where will be checked
        collection - name for database collection where will be checked
        propertyName - field for database entity which will be added in JSON-Object for checked
        filter - 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 interface MessageService
        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 interface MessageService
        Parameters:
        chatId - identification for database which will be checked and calculated
        profileId - 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 interface MessageService
        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 interface MessageService
        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 interface MessageService
        Parameters:
        chat - database entity which be used to map to dto
        optimal - 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 interface MessageService
        Parameters:
        messageId - id of the order
        attachment - 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 interface MessageService
        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 interface MessageService
        Parameters:
        chatId - identification for database entity which related beans list be returned
        sellerId - 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)
      • isMessageBelongsToUser

        private boolean isMessageBelongsToUser​(Chat c,
                                               Message m,
                                               Profile profile)
      • 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)