Class MessagesRepository
java.lang.Object
com.inesm.KeyManager.repositories.MessagesRepository
This class provides all the interactions with the messages database.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongcreateReceipt(Receipt receipt) Adds a receipt object to the database.voiddeleteReceiptByMessageIDSource(long id, String source) Removes all receipts associated with a given message.Gets all messages from the databasegetMessagebyIDSource(long id, String source) Gets a message from the database, using its messageID and source.longgetMessagesForStation(String source) Gets the number of messages for a given source.getReceiptByMessage(Message message, String station) Gets a receipt associated with a given message, and issued by a given station.Gets all messages with status waiting from the database.Gets all receipt from the database with the waiting flag set to true.voidinsertMessage(Message message) Inserts a new message in the database.voidsetDataSource(DataSource dataSource) Binds the jdbcTemplate to the specified data source.voidupdateMessageStatus(Receipt receipt) Updates the status of a message with the received receipt.voidupdateReceipt(Receipt receipt, boolean waiting) Updates the waiting status of a receipt.
-
Constructor Details
-
MessagesRepository
public MessagesRepository()
-
-
Method Details
-
setDataSource
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
Gets a message from the database, using its messageID and source.- Parameters:
id- the messageID of the messagesource- 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
Gets the number of messages for a given source.- Parameters:
source- the path of the source station- Returns:
- the number of messages
-
getAllMessages
Gets all messages from the database- Returns:
- the list containing all the messages in the database, not null, maybe empty
-
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
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
Removes all receipts associated with a given message.- Parameters:
id- the messageID of the messagesource- the path of the source station of the message
-
getReceiptByMessage
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 setstation- 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 setwaiting- the waiting flag to be updated- Throws:
ObjectNotFoundException- if the receipt was not foundorg.springframework.dao.DataIntegrityViolationException- if violation of an integrity constraint occurs
-