Search in sources :

Example 1 with ApplicationLogEntry

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;
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ApplicationLogEntry(net.nemerosa.ontrack.model.support.ApplicationLogEntry)

Example 2 with ApplicationLogEntry

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);
}
Also used : Account(net.nemerosa.ontrack.model.security.Account) ApplicationLogEntry(net.nemerosa.ontrack.model.support.ApplicationLogEntry) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ApplicationLogEntry (net.nemerosa.ontrack.model.support.ApplicationLogEntry)2 Account (net.nemerosa.ontrack.model.security.Account)1 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)1 Transactional (org.springframework.transaction.annotation.Transactional)1