<commit_before>package lan.dk.podcastserver.business;

import lan.dk.podcastserver.entity.Tag;
import lan.dk.podcastserver.repository.TagRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Set;
import java.util.UUID;

import static java.util.stream.Collectors.toSet;

/**
 * Created by kevin on 07/06/2014.
 */
@Slf4j
@Component
@Transactional
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class TagBusiness {

    final TagRepository tagRepository;

    public List<Tag> findAll() {
        return tagRepository.findAll();
    }

    public Tag findOne(UUID id) {
        return tagRepository.findOne(id);
    }

    public List<Tag> findByNameLike(String name) {
        return tagRepository.findByNameContainsIgnoreCase(name);
    }

    Set<Tag> getTagListByName(Set<Tag> tagList) {
        return tagList
                .stream()
                .map(t -> findByName(t.getName()))
                .collect(toSet());
    }

    private Tag findByName(String name) {
        return tagRepository.findByNameIgnoreCase(name).orElseGet(() -> tagRepository.save(new Tag().setName(name)));
    }
}
<commit_msg>refactor(tag): should create tag if not found in database when add by podcast<commit_after>package lan.dk.podcastserver.business;

import lan.dk.podcastserver.entity.Tag;
import lan.dk.podcastserver.repository.TagRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Set;
import java.util.UUID;

import static java.util.stream.Collectors.toSet;

/**
 * Created by kevin on 07/06/2014.
 */
@Slf4j
@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class TagBusiness {

    final TagRepository tagRepository;

    public List<Tag> findAll() {
        return tagRepository.findAll();
    }

    public Tag findOne(UUID id) {
        return tagRepository.findOne(id);
    }

    public List<Tag> findByNameLike(String name) {
        return tagRepository.findByNameContainsIgnoreCase(name);
    }

    Set<Tag> getTagListByName(Set<Tag> tagList) {
        return tagList
                .stream()
                .map(t -> findByName(t.getName()))
                .collect(toSet());
    }

    private Tag findByName(String name) {
        return tagRepository.findByNameIgnoreCase(name)
                .orElseGet(() -> tagRepository.save(Tag.builder().name(name).build()));
    }
}

{'fraction_non_alphanumeric': 0.11091040462427745, 'fraction_numerical': 0.007947976878612716, 'mean_word_length': 3.554276315789474, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '2497537', 'n_tokens_mistral': 838, 'n_tokens_neox': 824, 'n_words': 159}