Class KeyRepository

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

@Repository public class KeyRepository extends Object
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 Details

    • KeyRepository

      public KeyRepository()
  • 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
    • getKeyByID

      public Key getKeyByID(long id) throws ObjectNotFoundException
      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

      public Key getKeyByUUID(String uuid) throws ObjectNotFoundException
      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

      public List<Key> getKeys()
      Gets all the keys from the database.
      Returns:
      the list containing all keys, not null, maybe empty
    • getKeysByMission

      public List<Key> getKeysByMission(long missionID)
      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

      public long createKey(Key key) throws org.springframework.dao.DataIntegrityViolationException
      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 found
      org.springframework.dao.DataIntegrityViolationException - if violation of an integrity constraint occurs
    • deleteKey

      public void deleteKey(Long id) throws ObjectNotFoundException
      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

      public void deleteKeyByUUID(String uuid) throws ObjectNotFoundException
      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

      public Mission getMissionByID(long id) throws ObjectNotFoundException
      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

      public Mission getMissionByUUID(String uuid) throws ObjectNotFoundException
      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

      public List<Mission> 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 found
      org.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 database
      org.springframework.dao.DataIntegrityViolationException - if violation of an integrity constraint occurs
    • getStations

      public List<Station> 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

      public Station getCurrentStation() throws ObjectNotFoundException
      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

      public Station getStationByID(long id) throws ObjectNotFoundException
      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

      public Station getStationByPath(String path) throws ObjectNotFoundException
      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

      public Station getStationByName(String name) throws ObjectNotFoundException
      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 occurs
      ObjectNotFoundException - 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 found
      org.springframework.dao.DataIntegrityViolationException - if violation of an integrity constraint occurs
    • getSharedStations

      public List<MissionSharing> getSharedStations(long missionID)
      Gets the shared stations for a given mission. The owner station will not show in this list.
      Parameters:
      missionID - the missionID field of the mission
      Returns:
      a list containing the mission sharing objects
    • 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 mission
      stationID - 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