<commit_before>package net.nemerosa.ontrack.service.support;

import net.nemerosa.ontrack.common.Time;
import net.nemerosa.ontrack.model.security.Account;
import net.nemerosa.ontrack.model.security.ApplicationManagement;
import net.nemerosa.ontrack.model.security.SecurityService;
import net.nemerosa.ontrack.model.support.ApplicationLogEntry;
import net.nemerosa.ontrack.model.support.ApplicationLogEntryFilter;
import net.nemerosa.ontrack.model.support.ApplicationLogService;
import net.nemerosa.ontrack.model.support.Page;
import net.nemerosa.ontrack.repository.ApplicationLogEntriesRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.metrics.CounterService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Transactional
public class ApplicationLogServiceImpl implements ApplicationLogService {

    private final Logger logger = LoggerFactory.getLogger(ApplicationLogService.class);

    private final SecurityService securityService;
    private final ApplicationLogEntriesRepository entriesRepository;
    private final CounterService counterService;

    @Autowired
    public ApplicationLogServiceImpl(SecurityService securityService, ApplicationLogEntriesRepository entriesRepository, CounterService counterService) {
        this.securityService = securityService;
        this.entriesRepository = entriesRepository;
        this.counterService = counterService;
    }

    @Override
    // FIXME #467 @Transactional(propagation = Propagation.NESTED)
    public void log(ApplicationLogEntry entry) {
        ApplicationLogEntry signedEntry = entry.withAuthentication(
                securityService.getAccount().map(Account::getName).orElse("anonymous")
        );
        doLog(signedEntry);
    }

    @Override
    public void cleanup(int retentionDays) {
        entriesRepository.cleanup(retentionDays);
    }

    @Override
    public void deleteLogEntries() {
        entriesRepository.deleteLogEntries();
    }

    private synchronized void doLog(ApplicationLogEntry entry) {<commit_msg>#467 Log entries - using a nested transaction<commit_after>package net.nemerosa.ontrack.service.support;

import net.nemerosa.ontrack.common.Time;
import net.nemerosa.ontrack.model.security.Account;
import net.nemerosa.ontrack.model.security.ApplicationManagement;
import net.nemerosa.ontrack.model.security.SecurityService;
import net.nemerosa.ontrack.model.support.ApplicationLogEntry;
import net.nemerosa.ontrack.model.support.ApplicationLogEntryFilter;
import net.nemerosa.ontrack.model.support.ApplicationLogService;
import net.nemerosa.ontrack.model.support.Page;
import net.nemerosa.ontrack.repository.ApplicationLogEntriesRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.metrics.CounterService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Transactional
public class ApplicationLogServiceImpl implements ApplicationLogService {

    private final Logger logger = LoggerFactory.getLogger(ApplicationLogService.class);

    private final SecurityService securityService;
    private final ApplicationLogEntriesRepository entriesRepository;
    private final CounterService counterService;

    @Autowired
    public ApplicationLogServiceImpl(SecurityService securityService, ApplicationLogEntriesRepository entriesRepository, CounterService counterService) {
        this.securityService = securityService;
        this.entriesRepository = entriesRepository;
        this.counterService = counterService;
    }

    @Override
    @Transactional(propagation = Propagation.NESTED)
    public void log(ApplicationLogEntry entry) {
        ApplicationLogEntry signedEntry = entry.withAuthentication(
                securityService.getAccount().map(Account::getName).orElse("anonymous")
        );
        doLog(signedEntry);
    }

    @Override
    public void cleanup(int retentionDays) {
        entriesRepository.cleanup(retentionDays);
    }

    @Override
    public void deleteLogEntries() {
        entriesRepository.deleteLogEntries();
    }

    private synchronized void doLog(ApplicationLogEntry entry) {
{'fraction_non_alphanumeric': 0.0777415852334419, 'fraction_numerical': 0.002171552660152009, 'mean_word_length': 5.141333333333334, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '685118', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1157, 'n_words': 214}