use of net.nemerosa.ontrack.model.support.ApplicationLogEntry in project ontrack by nemerosa.
the class ApplicationLogEntriesJdbcRepository method getLogEntries.
@Override
public List<ApplicationLogEntry> getLogEntries(ApplicationLogEntryFilter filter, Page page) {
int total = getTotalCount();
int offset = page.getOffset();
if (offset >= total) {
return Collections.emptyList();
} else {
// Query
MapSqlParameterSource params = noParams();
StringBuilder query = new StringBuilder("SELECT * FROM APPLICATION_LOG_ENTRIES WHERE 1 = 1 ");
// Criteria: level
if (filter.getLevel() != null) {
query.append(" AND LEVEL = :level");
params = params.addValue("level", filter.getLevel().name());
}
// Criteria: before
if (filter.getBefore() != null) {
query.append(" AND TIMESTAMP <= :before");
params = params.addValue("before", dateTimeForDB(filter.getBefore()));
}
// Criteria: after
if (filter.getAfter() != null) {
query.append(" AND TIMESTAMP >= :after");
params = params.addValue("after", dateTimeForDB(filter.getAfter()));
}
// Criteria: authentication
if (StringUtils.isNotBlank(filter.getAuthentication())) {
query.append(" AND AUTHENTICATION = :authentication");
params = params.addValue("authentication", filter.getAuthentication());
}
// Criteria: text
if (StringUtils.isNotBlank(filter.getText())) {
query.append(" AND (NAME LIKE :text OR DESCRIPTION LIKE :text OR INFORMATION LIKE :text OR DETAILS LIKE :text)");
params = params.addValue("text", "%" + filter.getText() + "%");
}
// Ordering
query.append(" ORDER BY ID DESC");
// Limit and offset
query.append(" LIMIT :page OFFSET :offset");
params = params.addValue("page", page.getCount()).addValue("offset", page.getOffset());
// Performing the query
List<ApplicationLogEntry> entries = getNamedParameterJdbcTemplate().query(query.toString(), params, (rs, rowNum) -> new ApplicationLogEntry(getEnum(ApplicationLogEntryLevel.class, rs, "LEVEL"), dateTimeFromDB(rs.getString("TIMESTAMP")), rs.getString("AUTHENTICATION"), NameDescription.nd(rs.getString("NAME"), rs.getString("DESCRIPTION")), rs.getString("INFORMATION"), rs.getString("EXCEPTION"), getDetailsFromJson(rs)));
// OK
return entries;
}
}
use of net.nemerosa.ontrack.model.support.ApplicationLogEntry in project ontrack by nemerosa.
the class ApplicationLogServiceImpl method log.
@Override
@Transactional(propagation = Propagation.NESTED)
public void log(ApplicationLogEntry entry) {
ApplicationLogEntry signedEntry = entry.withAuthentication(securityService.getAccount().map(Account::getName).orElse("anonymous"));
doLog(signedEntry);
}
Aggregations