Class LogRepository

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

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

    • LogRepository

      public LogRepository()
  • 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
    • getLogByID

      public Log getLogByID(long id) throws ObjectNotFoundException
      Gets a log from the database.
      Parameters:
      id - the logID of the log
      Returns:
      the log object
      Throws:
      ObjectNotFoundException - if the log with the supplied logID was not found
    • insertLog

      public long insertLog(Log log) throws org.springframework.dao.DataIntegrityViolationException

      Inserts a log in the database with the initial operation information. This operation will insert the following fields in the database:

      • username
      • roleName
      • operationName
      • resourceType
      • status
      • timestamp

      The log should then be updated with the function updateLog(Log) in order to be complete.

      Parameters:
      log - the log object to be insert
      Returns:
      the logID of the created log in the database
      Throws:
      org.springframework.dao.DataIntegrityViolationException - if violation of an integrity constraint occurs
    • updateLog

      public void updateLog(Log log) throws ObjectNotFoundException
      Updates a existent log instance from the database with extra information. Will update the following fields:
      • resourceName
      • operationData
      • status
      • statusInfo
      Parameters:
      log - the log object to update the database, not null, must have logID set
      Throws:
      ObjectNotFoundException - if the log was not found in the database
    • getLogsByFilter

      public List<Log> getLogsByFilter(Log filter)
      Fetches all logs from the database that match the filter. The filter is defined as a Log object for simplicity. The following fields are considered by this function:
      • username
      • roleName
      • operationName
      • resourceType
      • status
      • timestamp
      • timestampEnd

      All the fields except the timestamps are checked for equality, the timestamp is used with timestampEnd to define a time interval.

      If some of the log fields are not set, they will not be considered for filtering. Ultimately, an "empty" (not null) log object will provide all the logs inside the database.

      Parameters:
      filter - the log object containing the filtering parameters, not null
      Returns:
      the list containing all logs which matched the filter received, not null, maybe empty