<commit_before>package de.fred4jupiter.fredbet.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import de.fred4jupiter.fredbet.domain.AppUser;
import de.fred4jupiter.fredbet.domain.ImageMetaData;
import de.fred4jupiter.fredbet.props.CacheNames;
import de.fred4jupiter.fredbet.props.FredbetConstants;
import de.fred4jupiter.fredbet.repository.AppUserRepository;
import de.fred4jupiter.fredbet.repository.BetRepository;
import de.fred4jupiter.fredbet.repository.ExtraBetRepository;
import de.fred4jupiter.fredbet.repository.ImageMetaDataRepository;
import de.fred4jupiter.fredbet.repository.SessionTrackingRepository;
import de.fred4jupiter.fredbet.security.SecurityService;
import de.fred4jupiter.fredbet.service.config.RuntimeConfigurationService;
import de.fred4jupiter.fredbet.web.user.UserDto;

@Service
@Transactional
public class UserService {

	private static final Logger LOG = LoggerFactory.getLogger(UserService.class);

	@Autowired
	private AppUserRepository appUserRepository;

	@Autowired
	private PasswordEncoder passwordEncoder;

	@Autowired
	private SecurityService securityService;

	@Autowired
	private ImageMetaDataRepository imageMetaDataRepository;

	@Autowired
	private BetRepository betRepository;

	@Autowired
	private ExtraBetRepository extraBetRepository;

	@Autowired
	private SessionTrackingRepository sessionTrackingRepository;

	@Autowired
	private RuntimeConfigurationService runtimeConfigurationService;

	public List<AppUser> findAll() {
		return appUserRepository.findAll(new Sort(Direction.ASC, "username"));
	}

	public AppUser findByAppUserId(Long userId) {
		return appUserRepository.findOne(userId);
	}

	public AppUser findByUserId(Long userId) {
		return appUserRepository.findOne(userId);
	}

	@CacheEvict(cacheNames = CacheNames.CHILD_RELATION, allEntries = true)
	public void createUser(AppUser appUser) throws UserAlreadyExistsException {
		AppUser foundUser = appUserRepository.findByUsername(appUser.getUsername());
		if (foundUser != null) {
			throw new UserAlreadyExistsException("User with username=" + appUser.getUsername() + " already exists.");
		}

		appUser.setPassword(passwordEncoder.encode(<PASSWORD>.getPassword()));
		appUserRepository.save(appUser);
	}

	@CacheEvict(cacheNames = CacheNames.CHILD_RELATION, allEntries = true)
	public AppUser updateUser(Long userId, boolean passwordReset, boolean isChild) {
		return updateUser(userId, passwordReset, null, isChild);
	}

	@CacheEvict(cacheNames = CacheNames.CHILD_RELATION, allEntries = true)
	public AppUser updateUser(Long userId, boolean passwordReset, Set<String> roles, boolean isChild) {
		Assert.notNull(userId, "userCommand.getUserId() must be given");
		AppUser appUser = appUserRepository.findOne(userId);
		if (appUser == null) {
			throw new IllegalArgumentException("Given user with userId=" + userId + " does not exists.");
		}
		if (roles != null && !roles.isEmpty()) {
			appUser.setRoles(roles);<commit_msg>cleanup<commit_after>package de.fred4jupiter.fredbet.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import de.fred4jupiter.fredbet.domain.AppUser;
import de.fred4jupiter.fredbet.domain.ImageMetaData;
import de.fred4jupiter.fredbet.props.CacheNames;
import de.fred4jupiter.fredbet.props.FredbetConstants;
import de.fred4jupiter.fredbet.repository.AppUserRepository;
import de.fred4jupiter.fredbet.repository.BetRepository;
import de.fred4jupiter.fredbet.repository.ExtraBetRepository;
import de.fred4jupiter.fredbet.repository.ImageMetaDataRepository;
import de.fred4jupiter.fredbet.repository.SessionTrackingRepository;
import de.fred4jupiter.fredbet.security.SecurityService;
import de.fred4jupiter.fredbet.service.config.RuntimeConfigurationService;
import de.fred4jupiter.fredbet.web.user.UserDto;

@Service
@Transactional
public class UserService {

	private static final Logger LOG = LoggerFactory.getLogger(UserService.class);

	@Autowired
	private AppUserRepository appUserRepository;

	@Autowired
	private PasswordEncoder passwordEncoder;

	@Autowired
	private SecurityService securityService;

	@Autowired
	private ImageMetaDataRepository imageMetaDataRepository;

	@Autowired
	private BetRepository betRepository;

	@Autowired
	private ExtraBetRepository extraBetRepository;

	@Autowired
	private SessionTrackingRepository sessionTrackingRepository;

	@Autowired
	private RuntimeConfigurationService runtimeConfigurationService;

	public List<AppUser> findAll() {
		return appUserRepository.findAll(new Sort(Direction.ASC, "username"));
	}

	public AppUser findByAppUserId(Long userId) {
		return appUserRepository.findOne(userId);
	}

	public AppUser findByUserId(Long userId) {
		return appUserRepository.findOne(userId);
	}

	@CacheEvict(cacheNames = CacheNames.CHILD_RELATION, allEntries = true)
	public void createUser(AppUser appUser) throws UserAlreadyExistsException {
		AppUser foundUser = appUserRepository.findByUsername(appUser.getUsername());
		if (foundUser != null) {
			throw new UserAlreadyExistsException("User with username=" + appUser.getUsername() + " already exists.");
		}

		appUser.setPassword(passwordEncoder.encode(appUser.getPassword()));
		appUserRepository.save(appUser);
	}

	@CacheEvict(cacheNames = CacheNames.CHILD_RELATION, allEntries = true)
	public AppUser updateUser(Long userId, boolean passwordReset, boolean isChild) {
		return updateUser(userId, passwordReset, null, isChild);
	}

	@CacheEvict(cacheNames = CacheNames.CHILD_RELATION, allEntries = true)
	public AppUser updateUser(Long userId, boolean passwordReset, Set<String> roles, boolean isChild) {
		Assert.notNull(userId, "userId must be given");
		AppUser appUser = appUserRepository.findOne(userId);
		if (appUser == null) {
			throw new IllegalArgumentException("Given user with userId=" + userId + " does not exists.");
		}
		if (roles != null && !roles.isEmpty()) {
			appUser.setRoles(roles);
{'fraction_non_alphanumeric': 0.09185417260039874, 'fraction_numerical': 0.004272287097692965, 'mean_word_length': 6.838169642857143, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '6986433', 'n_tokens_mistral': 2051, 'n_tokens_neox': 2043, 'n_words': 401}