Class ConversationServiceImpl

All Implemented Interfaces:
ConversationService

public class ConversationServiceImpl extends CommonEngineServiceImpl<EngageEngineConfiguration> implements ConversationService
The default conversation service implementation using commands to provide the necessary functionality.
Author:
Micha Kiener, Filip Hrisafov, Anatolii Balakiriev
  • Field Details

  • Constructor Details

  • Method Details

    • createConversationQuery

      public ConversationQuery createConversationQuery()
      Description copied from interface: ConversationService
      Creates a new conversation query as a builder where you can add predicates in order to query for conversations. If you search by the conversation id only you should better use ConversationService.findById(String) because it takes the cache into account.
      Specified by:
      createConversationQuery in interface ConversationService
      Returns:
      the conversation query builder
    • createConversationBuilder

      public ConversationBuilder createConversationBuilder()
      Description copied from interface: ConversationService
      Returns a conversation builder used to start new Conversation objects. Make sure to always explicitly set the sub type of the conversation as it is a mandatory information.
      Specified by:
      createConversationBuilder in interface ConversationService
      Returns:
      the conversation builder
    • createConversationParticipantBuilder

      public ConversationParticipantBuilder createConversationParticipantBuilder(String conversationId)
      Description copied from interface: ConversationService
      Creates a new participant builder to add or remove participants to / from a conversation with various extended options mainly on message visibility.
      Specified by:
      createConversationParticipantBuilder in interface ConversationService
      Parameters:
      conversationId - the id of the conversation to manage participants through the builder
      Returns:
      a conversation participant builder
    • createConversationUserQuery

      public ConversationUserQuery createConversationUserQuery()
      Description copied from interface: ConversationService
      Creates a new user query to request user ids involved in a specific conversation (e.g. participants or all involved users, etc).
      Specified by:
      createConversationUserQuery in interface ConversationService
      Returns:
      the conversation query builder
    • createConversationStatusQuery

      public ConversationStatusQuery createConversationStatusQuery()
      Description copied from interface: ConversationService
      Creates a new conversation status query, that can be used to get the different unread statuses for a conversation.
      Specified by:
      createConversationStatusQuery in interface ConversationService
      Returns:
      the conversation status query builder
    • unreadMessagesCount

      public long unreadMessagesCount(String userId, String conversationId)
      Description copied from interface: ConversationService
      The unread data count for the user with id userId in the conversation with id conversationId
      Specified by:
      unreadMessagesCount in interface ConversationService
      Parameters:
      userId - the id of the user for which the unread data count is needed
      conversationId - the id of the conversation for which the count is needed
      Returns:
      the number of unread messages for the given user in the given conversation
    • startConversation

      public Conversation startConversation(ConversationBuilderImpl conversationBuilder)
    • startConversationWithReuse

      public ConversationHolder startConversationWithReuse(ConversationBuilderImpl conversationBuilder)
    • exists

      public boolean exists(String conversationId)
      Specified by:
      exists in interface ConversationService
      Returns:
      Checks if the given conversation exists.
    • setReference

      public Conversation setReference(String conversationId, String referenceId, String referenceType, String referenceDefinitionId)
      Description copied from interface: ConversationService
      Set the optional reference for a conversation like a case or process where the conversation is liked to.
      Specified by:
      setReference in interface ConversationService
      Parameters:
      conversationId - the id of the conversation to set its reference
      referenceId - the id of the referenced work item
      referenceType - the type of the referenced work item
      referenceDefinitionId - the optional definition id of the referenced work item
      Returns:
      the modified conversation retrieved from the database
    • updateName

      public Conversation updateName(String conversationId, String name)
      Description copied from interface: ConversationService
      Updates the conversation name (title) for the given conversation.
      Specified by:
      updateName in interface ConversationService
      Parameters:
      conversationId - the id of the conversation to change its name
      name - title of the conversation, it can be also be null or empty
      Returns:
      modified conversation retrieved from database
    • updateDescription

      public Conversation updateDescription(String conversationId, String description)
      Description copied from interface: ConversationService
      Updates the conversation description for the given conversation.
      Specified by:
      updateDescription in interface ConversationService
      Parameters:
      conversationId - the id of the conversation to change its description
      description - the description of the conversation, it can be also be null or empty
      Returns:
      modified conversation retrieved from database
    • updateAvatarId

      public Conversation updateAvatarId(String conversationId, String avatarId)
      Description copied from interface: ConversationService
      Updates the conversation avatar id for the given conversation.
      Specified by:
      updateAvatarId in interface ConversationService
      Parameters:
      conversationId - the id of the conversation to change its description
      avatarId - the avatar id of the conversation, it can be also be null or empty
      Returns:
      modified conversation retrieved from database
    • archive

      public void archive(String conversationId)
      Description copied from interface: ConversationService
      Archives the conversation with the given id. You can't post anything to an archived conversation, the only thing left to do is re-opening it.
      Specified by:
      archive in interface ConversationService
      Parameters:
      conversationId - the id of the conversation to be archived
    • reopen

      public void reopen(String conversationId)
      Description copied from interface: ConversationService
      Reopens the archived conversation with the given id.
      Specified by:
      reopen in interface ConversationService
      Parameters:
      conversationId - the id of the conversation to be reopened
    • addParticipants

      public void addParticipants(String conversationId, Collection<String> participants)
      Description copied from interface: ConversationService
      Adds the given participants to the conversation with the given id
      Specified by:
      addParticipants in interface ConversationService
      Parameters:
      conversationId - the id of the conversation to which the participants needs to be added
      participants - the ids of the participants that need to be added
    • removeParticipants

      public void removeParticipants(String conversationId, Collection<String> participants)
      Description copied from interface: ConversationService
      Removes the given participants to the conversation with the given id
      Specified by:
      removeParticipants in interface ConversationService
      Parameters:
      conversationId - the id of the conversation from which the participants need to be removed
      participants - the ids of the participants that need to be removed
    • assignToGroup

      public void assignToGroup(String conversationId, String assignedGroupId)
      Description copied from interface: ConversationService
      Assigns the conversation to a group of users (set the assignedGroupId property).
      Specified by:
      assignToGroup in interface ConversationService
      Parameters:
      conversationId - the id of the conversation to be assigned to a group
      assignedGroupId - the id of the group to assign the conversation to
    • removeAssignedGroup

      public void removeAssignedGroup(String conversationId)
      Description copied from interface: ConversationService
      Removes an assigned group from a conversation (sets the assignedGroupId proeprty to null).
      Specified by:
      removeAssignedGroup in interface ConversationService
      Parameters:
      conversationId - the id of the conversation to remove the assgined group from
    • assignToUser

      public void assignToUser(String conversationId, String assignedUserId)
      Description copied from interface: ConversationService
      Assigns the conversation to a user (set the assigneeId property).
      Specified by:
      assignToUser in interface ConversationService
      Parameters:
      conversationId - the id of the conversation to be assigned to a user
      assignedUserId - the id of the user to assign the conversation to
    • removeAssignedUser

      public void removeAssignedUser(String conversationId)
      Description copied from interface: ConversationService
      Removes an assigned user from a conversation.
      Specified by:
      removeAssignedUser in interface ConversationService
      Parameters:
      conversationId - the id of the conversatoin to remove the assigned user (set the assigneeId ot null).
    • changeOwner

      public void changeOwner(String conversationId, String ownerUserId)
      Description copied from interface: ConversationService
      Changes an owner of the conversation.
      Specified by:
      changeOwner in interface ConversationService
      Parameters:
      conversationId - the id of the conversation to change an owner in
      ownerUserId - the id of the user to become a new owner of this conversation
    • userTyping

      public void userTyping(String conversationId, String userId)
      Description copied from interface: ConversationService
      Information that a user with id userId is typing in the conversation with id conversationId
      Specified by:
      userTyping in interface ConversationService
      Parameters:
      conversationId - the id of the conversation in which the user is typing
      userId - the id of the user that is doing the typing
    • deleteConversation

      public void deleteConversation(String conversationId)
      Description copied from interface: ConversationService
      Deletes a conversation and all related data (messages, unread counts, etc.).
      Specified by:
      deleteConversation in interface ConversationService
      Parameters:
      conversationId - the id of the conversation which needs to be deleted.
    • addTags

      public void addTags(String conversationId, Collection<String> tags)
      Description copied from interface: ConversationService
      Tag the conversation with provided tags
      Specified by:
      addTags in interface ConversationService
      Parameters:
      conversationId - the id of the conversation to which the tags need to be added
      tags - the tags that should be added to the conversation
    • addTag

      public void addTag(String conversationId, String tag)
      Description copied from interface: ConversationService
      Adds the provided tag to the specified conversation.
      Specified by:
      addTag in interface ConversationService
      Parameters:
      conversationId - the id of the conversation where the tag should be added
      tag - the tag to be added, must not be null or empty
    • removeTags

      public void removeTags(String conversationId, Collection<String> tags)
      Description copied from interface: ConversationService
      Remove the provided tags from the conversation
      Specified by:
      removeTags in interface ConversationService
      Parameters:
      conversationId - the id of the conversation from which tags need to be removed
      tags - the tags that need to be removed from the conversation
    • removeTag

      public void removeTag(String conversationId, String tag)
      Description copied from interface: ConversationService
      Removes the provided tag from the specified conversation, if it exists.
      Specified by:
      removeTag in interface ConversationService
      Parameters:
      conversationId - the id of the conversatoin to remove the provided tag from
      tag - the tag to be removed
    • countConversationsWithLastMessageBetween

      public long countConversationsWithLastMessageBetween(Date from, Date until, boolean includePrivateMessages, boolean includeStickMessages)
      Description copied from interface: ConversationService
      TODO: this might be not the right service Number of conversations which received new messages within a given time frame. If you are only interested in general messages (neither private nor sticky messages) it's better to use ConversationQuery and build a query with ConversationQuery.lastMessageAfter(Date) or ConversationQuery.lastMessageBefore(Date) This method is needed if private or sticky messages are also to be taken account, because Conversation.getLastMessageTime() will not be updated for private or sticky messages.
      Specified by:
      countConversationsWithLastMessageBetween in interface ConversationService
      Parameters:
      from - start of the time frame (optional)
      until - end of the time frame (optional)
      includePrivateMessages - true if private messages should also be considered
      includeStickMessages - true if sticky messages should also be considered
      Returns:
      count of conversations with new messages within given time frame
    • findConversationsWithLastMessageBetween

      public List<Conversation> findConversationsWithLastMessageBetween(Date from, Date until, boolean includePrivateMessages, boolean includeStickMessages)
      Description copied from interface: ConversationService
      TODO: this might be not the right service Finds conversations which received new messages within a given time frame. If you are only interested in general messages (neither private nor sticky messages) it's better to use ConversationQuery and build a query with ConversationQuery.lastMessageAfter(Date) or ConversationQuery.lastMessageBefore(Date) This method is needed if private or sticky messages are also to be taken account, because Conversation.getLastMessageTime() will not be updated for private or sticky messages.
      Specified by:
      findConversationsWithLastMessageBetween in interface ConversationService
      Parameters:
      from - start of the time frame (optional)
      until - end of the time frame (optional)
      includePrivateMessages - true if private messages should also be considered
      includeStickMessages - true if sticky messages should also be considered
      Returns:
      list of conversations with new messages withing given time frame
    • findByIdWithIdentityLinks

      public Conversation findByIdWithIdentityLinks(String conversationId)
      Description copied from interface: ConversationService
      Finds the conversation with the given id, with the identity links already prefetched.
      Specified by:
      findByIdWithIdentityLinks in interface ConversationService
    • findByIdWithIdentityLinksAndVariables

      public Conversation findByIdWithIdentityLinksAndVariables(String conversationId)
      Description copied from interface: ConversationService
      Finds the conversation with the given id, with the identity links and variables already prefetched.
      Specified by:
      findByIdWithIdentityLinksAndVariables in interface ConversationService
    • findById

      public Conversation findById(String conversationId)
      Description copied from interface: ConversationService
      Finds the conversation with the given id. If you are interested in the conversation owner, participants etc. you must call ConversationService.findByIdWithIdentityLinks(String).
      Specified by:
      findById in interface ConversationService
      Parameters:
      conversationId - the conversation id
      Returns:
      the conversation without any identity links
    • linkConversationWithUserAccount

      public void linkConversationWithUserAccount(String conversationId, String userAccountId)
      Description copied from interface: ConversationService
      Set the id of the user account that is linked with this conversation. If a conversation is already linked with a user account then this operation will add another link.
      Specified by:
      linkConversationWithUserAccount in interface ConversationService
      Parameters:
      conversationId - the id of the conversation that should be updated
      userAccountId - the id of the user account that should be linked with the conversation
    • removeUserAccountFromConversation

      @Deprecated public void removeUserAccountFromConversation(String conversationId)
      Deprecated.
      Description copied from interface: ConversationService
      Remove the id of the user account from this conversation. If the conversation is not linked with a user already then this method does nothing. If the conversation is linked to more than one account then this method will throw an exception.
      Specified by:
      removeUserAccountFromConversation in interface ConversationService
      Parameters:
      conversationId - the id of the conversation that should be updated
    • removeUserAccountFromConversation

      public void removeUserAccountFromConversation(String userAccountId, String conversationId)
      Description copied from interface: ConversationService
      Remove the mapping between the user account and the given conversation. If the conversation is not linked with the user account then this method does nothing
      Specified by:
      removeUserAccountFromConversation in interface ConversationService
      Parameters:
      userAccountId - the id of the user account that should be removed
      conversationId - the id of the conversation that should be updated
    • removeUserAccountsFromConversation

      public void removeUserAccountsFromConversation(String conversationId)
      Description copied from interface: ConversationService
      Remove all the user account mappings with this conversation. If the conversation is not linked with a user already then this method does nothing.
      Specified by:
      removeUserAccountsFromConversation in interface ConversationService
      Parameters:
      conversationId - the id of the conversation that should be updated
    • getVariables

      public Map<String,Object> getVariables(String conversationId)
      Description copied from interface: ConversationService
      All variables visible from the given conversation.
      Specified by:
      getVariables in interface ConversationService
      Parameters:
      conversationId - id of the conversation, cannot be null.
      Returns:
      the variables or an empty map if no such variables are found.
    • getVariable

      public Object getVariable(String conversationId, String variableName)
      Description copied from interface: ConversationService
      The variable value. Returns null when no variable value is found with the given name or when the value is set to null.
      Specified by:
      getVariable in interface ConversationService
      Parameters:
      conversationId - id of conversation, cannot be null.
      variableName - name of variable, cannot be null.
      Returns:
      the variable value or null if the variable is undefined or the value of the variable is null.
    • setVariable

      public void setVariable(String conversationId, String variableName, Object value)
      Description copied from interface: ConversationService
      Update or create a variable for a conversation.
      Specified by:
      setVariable in interface ConversationService
      Parameters:
      conversationId - id of conversation to set variable in, cannot be null.
      variableName - name of variable to set, cannot be null.
      value - value to set. When null is passed, the variable is not removed, only it's value will be set to null.
    • setVariables

      public void setVariables(String conversationId, Map<String,Object> variables)
      Description copied from interface: ConversationService
      Update or create given variables for a conversation.
      Specified by:
      setVariables in interface ConversationService
      Parameters:
      conversationId - id of the conversation, cannot be null.
      variables - map containing name (key) and value of variables, can be null.
    • removeVariable

      public void removeVariable(String conversationId, String variableName)
      Description copied from interface: ConversationService
      Removes a variable for a conversation.
      Specified by:
      removeVariable in interface ConversationService
      Parameters:
      conversationId - id of conversation to remove variable in.
      variableName - name of variable to remove.
    • removeVariables

      public void removeVariables(String conversationId, Collection<String> variableNames)
      Description copied from interface: ConversationService
      Removes variables for a conversation.
      Specified by:
      removeVariables in interface ConversationService
      Parameters:
      conversationId - id of conversation to remove variable in.
      variableNames - collection containing name of variables to remove.
    • starConversation

      public void starConversation(String conversationId, String userId)
      Description copied from interface: ConversationService
      Star the conversation with the given conversationId for the user with the given userId
      Specified by:
      starConversation in interface ConversationService
      Parameters:
      conversationId - the id of the conversation that should be starred for the user
      userId - the id of the user
    • unstarConversation

      public void unstarConversation(String conversationId, String userId)
      Description copied from interface: ConversationService
      Un-stars the conversation with the given conversationId for the user with the given userId
      Specified by:
      unstarConversation in interface ConversationService
      Parameters:
      conversationId - the id of the conversation that should be un-starred
      userId - the id of the user
    • muteConversation

      public void muteConversation(String conversationId, String userId)
      Description copied from interface: ConversationService
      Mute the conversation with the given conversationId for the user with the given userId.
      Specified by:
      muteConversation in interface ConversationService
      Parameters:
      conversationId - the id of the conversation that should be muted for the user
      userId - the id of the user
    • unmuteConversation

      public void unmuteConversation(String conversationId, String userId)
      Description copied from interface: ConversationService
      Unmute the conversation with the give conversationId for the user with the give userId.
      Specified by:
      unmuteConversation in interface ConversationService
      Parameters:
      conversationId - the id of the conversation that should be unmuted for the user
      userId - the id of the user