Class MessageManager

java.lang.Object
com.inesm.KeyManager.services.OperationService
com.inesm.KeyManager.services.MessageManager

@Service public class MessageManager extends OperationService
Service that handles message and receipts logic.
  • Method Details

    • getMessageByIDSource

      public Message getMessageByIDSource(long id, String source) throws ObjectNotFoundException
      Gets a message from the database. Uses the messageID and source in order to uniquely identify a given message.
      Parameters:
      id - the messageID of the message
      source - source of the message
      Returns:
      the retrieved message
      Throws:
      ObjectNotFoundException - if a message with the given messageID source pair could not be found
    • getWaitingResources

      public List<NetworkResource> getWaitingResources(boolean blocking) throws InterruptedException
      Gets all resources waiting to be sent from the database. These resources are message tagged with status 2 and receipts with the field waiting set to true.
      Parameters:
      blocking - the flag used to block and wait for resources in case no waiting resources are available
      Returns:
      a list containing the network resources retrieved or null if no waiting resources are available (if blocking=false)
      Throws:
      InterruptedException - if any thread interrupted the current thread before or while the current thread was waiting (if blocking=true)
    • getMessages

      public List<Message> getMessages()
      Gets all messages from the database.
      Returns:
      a list containing all messages
    • generateMessages

      public void generateMessages(User user, int operationID, SharedResource data, long groupID)
      Generates message(s) from an operation.

      The groupID provided should be obtained from the function getNextGroupID() in order to guarantee coherence. The target use case for this parameter is whenever an operation triggers a second operation, resulting in them both having the same groupID.

      Parameters:
      user - the user that executed the operation, not null
      operationID - the operationID of the operation performed
      data - the input data of the operation
      groupID - the groupID of the message, or zero in order to let the function generate a custom groupID
    • createMessage

      public long createMessage(User user, int operationID, com.inesm.KeyManager.services.KeyManager.MissionInfo info, SharedResource data, long groupID)
      Creates a single message in the database.
      Parameters:
      user - the user that performed the operation
      operationID - the operationID of the operation performed
      info - the distribution information for the message
      data - the input data of the operation
      groupID - the groupID of the message, or zero in order to let the function generate a custom groupID
      Returns:
      the messageID of the created message
    • process

      Processes a network resource. Calls the dedicated processing method of each network resource.
      Parameters:
      resource - the network resource to be processed
      Throws:
      ObjectNotFoundException - if the network resource is a receipt and the corresponding message cannot be found
      ObjectNotMappedException - if the network resource is not recognized
      InvalidParametersException - if the network resource contained invalid parameters
      InvalidSignatureException - if the network resource contained an invalid signature
    • exportMessage

      public Message exportMessage(Message message, User user) throws ObjectNotFoundException, InvalidMessageException
      Exports a message for manual distribution.
      Parameters:
      message - the message to be exported, not null, must have messageID and source set
      user - the user issuing the manual distribution, not null, must have username set
      Returns:
      the updated message with the export status
      Throws:
      ObjectNotFoundException - if the specified message could not be found
      InvalidMessageException - if the message status is not waiting, making it not possible to export the message
    • importMessage

      public void importMessage(Message message) throws InvalidParametersException, InvalidSignatureException
      Imports a message from manual distribution.
      Parameters:
      message - the message being imported
      Throws:
      InvalidParametersException - if the message contained invalid parameters
      InvalidSignatureException - if the message's signature was invalid