<commit_before>package com.github.jbai.service;

import java.io.File;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import com.github.jbai.APIException;
import com.github.jbai.entity.User;
import com.github.jbai.repository.UserRepository;
import com.github.jbai.util.SecurityUtil;

@Service("userService")
public class UserService {
	
	private @Value("${app.image.store.path}") String path;
	
	@Autowired
	private UserRepository userRepository;

	@Transactional
	public User addUser(User u) {
		if (u.getLoginName() == null || u.getName() == null || u.getPassword() == null) {
			throw new APIException(400, "bad request");
		}
		List<User> users = userRepository.findByLoginName(u.getLoginName());
		if (users.size() > 0) {
			throw new APIException(400, "duplicated login name");
		}		
		//Encrypt password for security
		u.setPassword(SecurityUtil.encrypt(u.getName()));		
		return userRepository.saveAndFlush(u);
	}

	public List<User> findAllUsers() {
		return userRepository.findAll();
	}

	public void updateProfile(long userId, MultipartFile file) throws Exception {
		MediaType mediaType = MediaType.parseMediaType(file.getContentType());		
		File f = new File(path + File.separator + System.currentTimeMillis() + "." + mediaType.getSubtype());
		file.transferTo(f);
		User user = userRepository.findOne(userId);
		user.setImagePath(f.getAbsolutePath());
		userRepository.saveAndFlush(user);
	}
}<commit_msg>add transaction for updating <commit_after>package com.github.jbai.service;

import java.io.File;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import com.github.jbai.APIException;
import com.github.jbai.entity.User;
import com.github.jbai.repository.UserRepository;
import com.github.jbai.util.SecurityUtil;

@Service("userService")
public class UserService {
	
	private @Value("${app.image.store.path}") String path;
	
	@Autowired
	private UserRepository userRepository;

	@Transactional
	public User addUser(User u) {
		if (u.getLoginName() == null || u.getName() == null || u.getPassword() == null) {
			throw new APIException(400, "bad request");
		}
		List<User> users = userRepository.findByLoginName(u.getLoginName());
		if (users.size() > 0) {
			throw new APIException(400, "duplicated login name");
		}		
		//Encrypt password for security
		u.setPassword(SecurityUtil.encrypt(u.getName()));		
		return userRepository.saveAndFlush(u);
	}

	public List<User> findAllUsers() {
		return userRepository.findAll();
	}
	
	@Transactional
	public void updateProfile(long userId, MultipartFile file) throws Exception {
		MediaType mediaType = MediaType.parseMediaType(file.getContentType());		
		File f = new File(path + File.separator + System.currentTimeMillis() + "." + mediaType.getSubtype());
		file.transferTo(f);
		User user = userRepository.findOne(userId);
		user.setImagePath(f.getAbsolutePath());
		userRepository.saveAndFlush(user);
	}
}
{'fraction_non_alphanumeric': 0.12517903179604697, 'fraction_numerical': 0.004010312231452306, 'mean_word_length': 5.4907063197026025, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '5447311', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1053, 'n_words': 211}