Class LogRepository
java.lang.Object
com.inesm.KeyManager.repositories.LogRepository
This class provides all the interactions with the logs database.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetLogByID(long id) Gets a log from the database.getLogsByFilter(Log filter) Fetches all logs from the database that match the filter.longInserts a log in the database with the initial operation information.voidsetDataSource(DataSource dataSource) Binds the jdbcTemplate to the specified data source.voidUpdates a existent log instance from the database with extra information.
-
Constructor Details
-
LogRepository
public LogRepository()
-
-
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
-
getLogByID
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
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
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
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
-