<commit_before>package ch.uzh.csg.reimbursement.service;

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

import ch.uzh.csg.reimbursement.model.Token;
import ch.uzh.csg.reimbursement.model.User;
import ch.uzh.csg.reimbursement.model.exception.TokenNotFoundException;
import ch.uzh.csg.reimbursement.repository.TokenRepositoryProvider;

@Service
@Transactional
public class MobileService {

	@Autowired
	private UserService userService;

	@Autowired
	private TokenRepositoryProvider repository;

	@Value("${reimbursement.token.signatureMobile.expirationInDays}")
	private int expirationInDays;

	public void createSignature(String tokenString, MultipartFile file) {
		Token token = repository.findByUid(tokenString);
		checkValidity(token);
		// TODO remove previous tokens of that user and type

		User user = token.getUser();
		userService.addSignature(user, file);
	}

	private void checkValidity(Token token) {
		if(token == null) {
			throw new TokenNotFoundException();
		}
		// TODO check token expiration with expirationInDays
		/*if(token.getCreated().before(new Date())) {
			throw new TokenExpiredException();
		}*/
	}
}<commit_msg>delete mobile token after it was used<commit_after>package ch.uzh.csg.reimbursement.service;

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

import ch.uzh.csg.reimbursement.model.Token;
import ch.uzh.csg.reimbursement.model.User;
import ch.uzh.csg.reimbursement.model.exception.TokenNotFoundException;
import ch.uzh.csg.reimbursement.repository.TokenRepositoryProvider;

@Service
@Transactional
public class MobileService {

	@Autowired
	private UserService userService;

	@Autowired
	private TokenRepositoryProvider repository;

	@Value("${reimbursement.token.signatureMobile.expirationInDays}")
	private int expirationInDays;

	public void createSignature(String tokenString, MultipartFile file) {
		Token token = repository.findByUid(tokenString);
		checkValidity(token);

		User user = token.getUser();

		repository.delete(token);

		userService.addSignature(user, file);
	}

	private void checkValidity(Token token) {
		if(token == null) {
			throw new TokenNotFoundException();
		}
		// TODO check token expiration with expirationInDays
		/*if(token.getCreated().before(new Date())) {
			throw new TokenExpiredException();
		}*/
	}
}
{'fraction_non_alphanumeric': 0.10039725532683279, 'fraction_numerical': 0.0, 'mean_word_length': 5.942355889724311, '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': '3750482', 'n_tokens_mistral': 863, 'n_tokens_neox': 809, 'n_words': 160}