Class KeyManager

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

@Service public class KeyManager extends Object
Provides all key management functionalities.
  • Constructor Details

    • KeyManager

      @Autowired public KeyManager(KeyRepository rep)
      Constructor for the key manager.
      Parameters:
      rep - the key repository
  • Method Details

    • getKeys

      public List<Key> getKeys()
      Gets all keys, and key related information from the database.
      Returns:
      a list containing all the keys inside the database.
    • getKeysForMission

      public List<Key> getKeysForMission(String missionUUID) throws ObjectNotFoundException
      Gets all keys and key related information regarding a specific mission.
      Parameters:
      missionUUID - the missionUUID of the mission
      Returns:
      a list containing all the keys associated with that mission
      Throws:
      ObjectNotFoundException - if the specified mission could not be found
    • getKey

      public Key getKey(String keyUUID) throws ObjectNotFoundException
      Gets a key and related information from the database.
      Parameters:
      keyUUID - the keyUUID of the key
      Returns:
      the object containing all the key information
      Throws:
      ObjectNotFoundException - if the key could not be found in the database
    • createKey

      public Key createKey(Key key) throws InvalidParametersException
      Creates a key in the database.
      Parameters:
      key - the object containing the key information to be stored, not null
      Returns:
      the created key in the database
      Throws:
      InvalidParametersException - if there were invalid parameters in the key creation
    • patchKey

      Patches a key object. Will only update the initialized fields of the key object, the others will remain the one's in the original key object.
      Parameters:
      key - the object containing the patch information, not null, must have keyUUID set
      Returns:
      the result of the patch operation
      Throws:
      InvalidParametersException - if invalid parameters were provided in the patch object
      ObjectNotFoundException - if the object referenced by the patch could not be found
    • updateKeyState

      public Key updateKeyState(Key key) throws InvalidParametersException, ObjectNotFoundException
      Updates the state of a key object in the database.
      Parameters:
      key - the key object to be updated, not null, must have state and keyUUID set
      Returns:
      the updated key object
      Throws:
      InvalidParametersException - if the key contained invalid parameters
      ObjectNotFoundException - if the key referenced could not be found
    • deleteKey

      public void deleteKey(String keyUUID) throws ObjectNotFoundException
      Deletes a key from the database.
      Parameters:
      keyUUID - the keyUUID of the key to be deleted
      Throws:
      ObjectNotFoundException - if the key could not be found
    • getMissions

      public List<Mission> getMissions()
      Gets all missions and related information from the database.
      Returns:
      a list containing the missions
    • getMission

      public Mission getMission(String missionUUID) throws ObjectNotFoundException
      Gets a mission and all related information from the database.
      Parameters:
      missionUUID - the missionUUID of the mission
      Returns:
      the specified mission
      Throws:
      ObjectNotFoundException - if the specified mission is can not be found
    • createMission

      public Mission createMission(Mission mission) throws InvalidParametersException
      Creates a mission in the database.
      Parameters:
      mission - the mission object to be created
      Returns:
      the created mission object
      Throws:
      InvalidParametersException - if the received mission object contained invalid parameters
    • patchMission

      public Mission patchMission(Mission update, List<Station> added, List<Station> removed) throws ObjectNotFoundException, InvalidParametersException
      Patches a mission. Will only update the initialized fields of the mission object, the others will remain the one's in the original mission object.
      Parameters:
      update - the object containing the fields to be updated, not null, must have missionUUID set
      added - list array that will contain the added shared stations, preferably empty
      removed - the list array that will contain the removed shared stations, preferably empty
      Returns:
      the patched mission
      Throws:
      ObjectNotFoundException - if the mission object could not be found
      InvalidParametersException - if the mission contained invalid parameters
    • deleteMission

      public void deleteMission(String missionUUID) throws ObjectNotFoundException
      Deletes a mission from the database. Will also delete all the mission sharing information and constituting keys.
      Parameters:
      missionUUID - the missionUUID of the mission to be deleted
      Throws:
      ObjectNotFoundException - if the mission could not be found
    • getStations

      public List<Station> getStations()
      Gets all station in the database.
      Returns:
      a list containing all the stations
    • createStation

      public Station createStation(Station station) throws InvalidParametersException
      Creates a station in the database
      Parameters:
      station - the station to be created, not null
      Returns:
      the created station object
      Throws:
      InvalidParametersException - if the station object contained invalid parameters
    • patchStation

      public Station patchStation(Station update) throws ObjectNotFoundException, InvalidParametersException
      Patches a station. Will only update the initialized fields of the station object, the others will remain the one's in the original station object.
      Parameters:
      update - the station containing the fields to be updated, not null, must have path set
      Returns:
      the updated station object
      Throws:
      ObjectNotFoundException - if the station to be updated could not be found
      InvalidParametersException - if the station update contained invalid parameters
    • deleteStation

      Deletes a station from the database.
      Parameters:
      path - the path of the station to be deleted
      Throws:
      ObjectNotFoundException - if the station specified could not be found
      StationCurrentlyAssignedException - if the station is owner, or a shared station of a mission
      ResourceLockedException - if the station constitutes a current station
    • getStationbyPath

      public Station getStationbyPath(String path) throws ObjectNotFoundException
      Gets a station from the database.
      Parameters:
      path - the path of the station to be retrieved.
      Returns:
      a station object containing the station information
      Throws:
      ObjectNotFoundException - if the specified station could not be found