Class KeyRepository
java.lang.Object
com.inesm.KeyManager.repositories.KeyRepository
This class provides all the interactions with the key management database.
It provides functions to interact with the database's keys, missions, stations and mission sharing tables.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongAdds a new key to the database.longcreateMission(Mission mission) Adds a mission to the database.longcreateStation(Station station) Adds a station to the databasevoiddeleteAllKeysByMission(long missionID) Removes all keys associated with a mission.voiddeleteAllMissionSharing(long missionID) Deletes all mission sharing for a given mission.voiddeleteAllStationSharing(long stationID) Deletes all station sharing information for a given station.voidDeletes a key from the database by key_id.voiddeleteKeyByUUID(String uuid) Deletes a key from the database by key_uuid.voiddeleteMission(long id) Removes a mission from the database.voiddeleteMissionSharing(long missionID, long stationID) Removes a station from the shared stations of a given mission.voiddeleteStationbyPath(String path) Removes a station from the database by path.Gets the current station from the database.getKeyByID(long id) Gets a key from the database by key_id.getKeyByUUID(String uuid) Gets key from the database by key_uuid.getKeys()Gets all the keys from the database.getKeysByMission(long missionID) Gets all keys for a given mission.getMissionByID(long id) Gets a mission from the database.getMissionByUUID(String uuid) Gets a mission from the database.Gets all missions from the database.getSharedStations(long missionID) Gets the shared stations for a given mission.getStationByID(long id) Gets a station from the database.getStationByName(String name) Gets a station by name from the database.getStationByPath(String path) Gets a station by path.Gets all stations from the database.voidinsertMissionSharing(long missionID, long stationID) Adds a station to the shared stations of a given mission.voidsetDataSource(DataSource dataSource) Binds the jdbcTemplate to the specified data source.voidUpdates a key in the database.voidupdateMission(Mission mission) Updates a mission in the database.voidupdateStation(Station station) Updates a station in database.
-
Constructor Details
-
KeyRepository
public KeyRepository()
-
-
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
-
getKeyByID
Gets a key from the database by key_id.- Parameters:
id- the keyID field of the key, not negative- Returns:
- the key object containing the information from the database, not null
- Throws:
ObjectNotFoundException- if the key was not found in the database
-
getKeyByUUID
Gets key from the database by key_uuid.- Parameters:
uuid- the keyUUID field of the key, not null- Returns:
- the key object containing the information from the database, not null
- Throws:
ObjectNotFoundException- if the key was not found in the database
-
getKeys
Gets all the keys from the database.- Returns:
- the list containing all keys, not null, maybe empty
-
getKeysByMission
Gets all keys for a given mission.- Parameters:
missionID- the missionID field of the mission.- Returns:
- the list containing all the keys inside a mission, not null, maybe empty if the mission contains no keys or if the mission was not found
-
createKey
Adds a new key to the database. Uses the following key fields to create the database object:- missionID
- type
- state
- creationDate
- expirationDate
- activationDate
- cryptoPeriod
- algorithm
- size
- reference
- format
- keyUUID
- Parameters:
key- the key object- Returns:
- the keyID of the key created in the database
- Throws:
org.springframework.dao.DataIntegrityViolationException- if violation of an integrity constraint occurs
-
updateKey
public void updateKey(Key key) throws ObjectNotFoundException, org.springframework.dao.DataIntegrityViolationException Updates a key in the database. Will replace all the database fields with the received key object fields. The following fields are replaced:- missionID
- type
- state
- creationDate
- expirationDate
- activationDate
- cryptoPeriod
- algorithm
- size
- reference
- format
- keyUUID
- Parameters:
key- the key object, not null, must have the keyID set- Throws:
ObjectNotFoundException- if the key was not foundorg.springframework.dao.DataIntegrityViolationException- if violation of an integrity constraint occurs
-
deleteKey
Deletes a key from the database by key_id.- Parameters:
id- the keyID field of the key to be deleted- Throws:
ObjectNotFoundException- if the key was not found in the database
-
deleteKeyByUUID
Deletes a key from the database by key_uuid.- Parameters:
uuid- the keyUUID field of the key- Throws:
ObjectNotFoundException- if the key was not found in the database
-
deleteAllKeysByMission
public void deleteAllKeysByMission(long missionID) Removes all keys associated with a mission.- Parameters:
missionID- the missionID of the mission
-
getMissionByID
Gets a mission from the database.- Parameters:
id- the missionID field of the mission to retrieve- Returns:
- the mission object containing the information from the database, not null
- Throws:
ObjectNotFoundException- if the mission was not found in the database
-
getMissionByUUID
Gets a mission from the database.- Parameters:
uuid- the missionUUID field of the mission- Returns:
- the mission object containing the mission information from the database, not null
- Throws:
ObjectNotFoundException- if the mission was not found
-
getMissions
Gets all missions from the database.- Returns:
- the list containing all the mission, not null, maybe empty if no mission are in the database
-
updateMission
public void updateMission(Mission mission) throws ObjectNotFoundException, org.springframework.dao.DataIntegrityViolationException Updates a mission in the database. Will replace all the database fields with the received mission fields.- Parameters:
mission- the mission object, not null, must have the missionID set- Throws:
ObjectNotFoundException- if the mission was not foundorg.springframework.dao.DataIntegrityViolationException- if violation of an integrity constraint occurs
-
createMission
public long createMission(Mission mission) throws org.springframework.dao.DataIntegrityViolationException Adds a mission to the database.- Parameters:
mission- the mission object with the fields set, not null- Returns:
- the missionID of the added mission
- Throws:
org.springframework.dao.DataIntegrityViolationException- if violation of an integrity constraint occurs
-
deleteMission
public void deleteMission(long id) throws ObjectNotFoundException, org.springframework.dao.DataIntegrityViolationException Removes a mission from the database.- Parameters:
id- the missionID field of the mission to be removed.- Throws:
ObjectNotFoundException- if the mission was not found in the databaseorg.springframework.dao.DataIntegrityViolationException- if violation of an integrity constraint occurs
-
getStations
Gets all stations from the database.- Returns:
- the list containing all the stations inside the database, not null, maybe empty if no stations present
-
getCurrentStation
Gets the current station from the database. Will retrieve the first station found in the database with the current field set to true.- Returns:
- the station object containing the current station
- Throws:
ObjectNotFoundException- if no station with the field current set to true was found
-
getStationByID
Gets a station from the database.- Parameters:
id- the stationID field of the station inside the database.- Returns:
- the station object retrieved from the database
- Throws:
ObjectNotFoundException- if no station was found with the received station_id
-
getStationByPath
Gets a station by path.- Parameters:
path- the path field of the station- Returns:
- the station object retrieved from the database
- Throws:
ObjectNotFoundException- if the station was not found
-
getStationByName
Gets a station by name from the database.- Parameters:
name- the name of the station- Returns:
- the station object retrieved from the database
- Throws:
ObjectNotFoundException- if the station was not found
-
createStation
public long createStation(Station station) throws org.springframework.dao.DataIntegrityViolationException Adds a station to the database- Parameters:
station- the station object to be added- Returns:
- the stationID of the added station
- Throws:
org.springframework.dao.DataIntegrityViolationException- if violation of an integrity constraint occurs
-
updateStation
public void updateStation(Station station) throws org.springframework.dao.DataIntegrityViolationException, ObjectNotFoundException Updates a station in database. Will update all database fields with the field from the provided station object. The updated fields are:- name
- path
- location
- keys
- ipAddress
- Parameters:
station- the station object containing the updated fields, not null, must have the stationID set- Throws:
org.springframework.dao.DataIntegrityViolationException- if violation of an integrity constraint occursObjectNotFoundException- if the station was not found in the database
-
deleteStationbyPath
public void deleteStationbyPath(String path) throws ObjectNotFoundException, org.springframework.dao.DataIntegrityViolationException Removes a station from the database by path.- Parameters:
path- the path of the station to be removed- Throws:
ObjectNotFoundException- if a station with the supplied path was not foundorg.springframework.dao.DataIntegrityViolationException- if violation of an integrity constraint occurs
-
insertMissionSharing
public void insertMissionSharing(long missionID, long stationID) throws org.springframework.dao.DataIntegrityViolationException Adds a station to the shared stations of a given mission.- Parameters:
missionID- the missionID field of the missionstationID- the stationID field of the station to be added to the mission.- Throws:
org.springframework.dao.DataIntegrityViolationException- if violation of an integrity constraint occurs
-
deleteMissionSharing
public void deleteMissionSharing(long missionID, long stationID) Removes a station from the shared stations of a given mission.- Parameters:
missionID- the missionID field of the mission.stationID- the stationID field of the station.
-
deleteAllMissionSharing
public void deleteAllMissionSharing(long missionID) throws org.springframework.dao.DataIntegrityViolationException Deletes all mission sharing for a given mission.- Parameters:
missionID- the missionID of the mission- Throws:
org.springframework.dao.DataIntegrityViolationException
-
deleteAllStationSharing
public void deleteAllStationSharing(long stationID) Deletes all station sharing information for a given station. Usually only used when a station is being removed from the database.- Parameters:
stationID- the stationID field of the station
-