Class MessagesRepository

java.lang.Object
com.inesm.KeyManager.repositories.MessagesRepository

@Repository public class MessagesRepository extends Object
This class provides all the interactions with the messages database.
  • Constructor Details

    • MessagesRepository

      public MessagesRepository()
  • Method Details

    • setDataSource

      @Autowired public void setDataSource(DataSource dataSource)
      Binds the jdbcTemplate to the specified data source.
      Parameters:
      dataSource - connection object for the database. Its properties are defined in the application.properties file
    • insertMessage

      public void insertMessage(Message message) throws org.springframework.dao.DataIntegrityViolationException
      Inserts a new message in the database. Will insert the following fields:
      • messageID
      • operationID
      • source
      • destination
      • issuerCitizenCard
      • issuerFullname
      • target
      • status
      • current
      • created
      • data
      • mode
      • groupID
      • signature
      Parameters:
      message - the message to be inserted, not null
      Throws:
      org.springframework.dao.DataIntegrityViolationException - if violation of an integrity constraint occurs
    • getMessagebyIDSource

      public Message getMessagebyIDSource(long id, String source) throws ObjectNotFoundException
      Gets a message from the database, using its messageID and source.
      Parameters:
      id - the messageID of the message
      source - the path of the source station of the message
      Returns:
      the message with the given messsageID and source
      Throws:
      ObjectNotFoundException - if no message was found with the provided messageID source pair
    • getMessagesForStation

      public long getMessagesForStation(String source)
      Gets the number of messages for a given source.
      Parameters:
      source - the path of the source station
      Returns:
      the number of messages
    • getAllMessages

      public List<Message> getAllMessages()
      Gets all messages from the database
      Returns:
      the list containing all the messages in the database, not null, maybe empty
    • getWaitingMessages

      public List<Message> getWaitingMessages()
      Gets all messages with status waiting from the database.
      Returns:
      the list containing all messages with the waiting status, not null, maybe empty
    • updateMessageStatus

      public void updateMessageStatus(Receipt receipt) throws ObjectNotFoundException, org.springframework.dao.DataIntegrityViolationException
      Updates the status of a message with the received receipt. Will update the following message fields (with the receipt fields):
      • status (status)
      • current (source)
      • updated (time)
      Parameters:
      receipt - , not null, must have messageID and destination set
      Throws:
      ObjectNotFoundException - if the message with the receipt's messageID-destination pair was not found.
      org.springframework.dao.DataIntegrityViolationException
    • createReceipt

      public long createReceipt(Receipt receipt) throws org.springframework.dao.DataIntegrityViolationException
      Adds a receipt object to the database. Will add the following fields:
      • messageID
      • source
      • destination
      • status
      • time
      • mode
      • waiting
      • signature
      Parameters:
      receipt - the receipt to be created, not null
      Returns:
      the receiptID of the created receipt
      Throws:
      org.springframework.dao.DataIntegrityViolationException - if violation of an integrity constraint occurs
    • getWaitingReceipts

      public List<Receipt> getWaitingReceipts()
      Gets all receipt from the database with the waiting flag set to true.
      Returns:
      a list containing all waiting receipts, not null, maybe empty
    • deleteReceiptByMessageIDSource

      public void deleteReceiptByMessageIDSource(long id, String source)
      Removes all receipts associated with a given message.
      Parameters:
      id - the messageID of the message
      source - the path of the source station of the message
    • getReceiptByMessage

      public Receipt getReceiptByMessage(Message message, String station) throws ObjectNotFoundException
      Gets a receipt associated with a given message, and issued by a given station.
      Parameters:
      message - the message the receipt refers to, not null, must have messageID and source set
      station - the path of the source station of the receipt
      Returns:
      the receipt found
      Throws:
      ObjectNotFoundException - if the receipt was not found in the database
    • updateReceipt

      public void updateReceipt(Receipt receipt, boolean waiting) throws ObjectNotFoundException, org.springframework.dao.DataIntegrityViolationException
      Updates the waiting status of a receipt.
      Parameters:
      receipt - the receipt to be updated, not null, must have messageID, destination and source set
      waiting - the waiting flag to be updated
      Throws:
      ObjectNotFoundException - if the receipt was not found
      org.springframework.dao.DataIntegrityViolationException - if violation of an integrity constraint occurs