<commit_before>package es.uniovi.asw.voterAcess.webService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import es.uniovi.asw.dbManagement.GetVoter;
import es.uniovi.asw.dbManagement.impl.GetVoterDB;
import es.uniovi.asw.dbManagement.model.Voter;
import es.uniovi.asw.dbManagement.persistence.VoterRepository;
import es.uniovi.asw.voterAcess.GetVoterInfo;
import es.uniovi.asw.voterAcess.webService.responses.VoterInfoResponse;
import es.uniovi.asw.voterAcess.webService.responses.errors.InvalidPasswordErrorResponse;
import es.uniovi.asw.voterAcess.webService.responses.errors.RequiredPasswordErrorResponse;
import es.uniovi.asw.voterAcess.webService.responses.errors.RequiredUserErrorResponse;
import es.uniovi.asw.voterAcess.webService.responses.errors.UserNotFoundErrorResponse;

@RestController
public class GetVoterInfoController implements GetVoterInfo
{
	private static final Logger log = LoggerFactory.getLogger(GetVoterInfoController.class);
	
	private final VoterRepository voterRepository;
	
	@Autowired
	GetVoterInfoController(VoterRepository voterRepository)
	{
		this.voterRepository = voterRepository;
	}
	
	@RequestMapping(value="/user",
			method= RequestMethod.POST,
			headers ="Accept=application/json",
			produces={"application/json","application/xml"})
	public VoterInfoResponse getInfoVoter(@RequestBody Voter voter)
	{
		log.info("Datos peticion: "+voter.getEmail()+" "+voter.getPassword());

		if(voter.getEmail().equals(""))
			throw new RequiredUserErrorResponse();
		if(voter.getPassword().equals(""))
			throw new RequiredPasswordErrorResponse();
		
		GetVoter gv = new GetVoterDB(this.voterRepository);
		Voter user = gv.getVoter(voter.getEmail());
		if(user==null)
			throw new UserNotFoundErrorResponse();
		if(user.getPassword().compareTo(voter.getPassword()) == 0)
			return new VoterInfoResponse(user);
		else
			throw new InvalidPasswordErrorResponse();
	}
	
	
	@ExceptionHandler(UserNotFoundErrorResponse.class)
	@ResponseStatus(value = HttpStatus.NOT_FOUND)
	public String handleErrorResponseNotFound()
	{
		return "{\"reason\": \"User not found\"}";
	}
	
	@ExceptionHandler(InvalidPasswordErrorResponse.class)
	@ResponseStatus(value = HttpStatus.NOT_FOUND)
	public String passwordConflict()
	{
		return "{\"reason\": \"Password incorrect\"}";
	}
	
	@ExceptionHandler(RequiredUserErrorResponse.class)
	@ResponseStatus(value = HttpStatus.NOT_FOUND)
	public String handleErrorResponseRequiredUser()
	{
		return "{\"reason\": \"The field 'User' is required\"}";
	}
	
	@ExceptionHandler(RequiredUserErrorResponse.class)
	@ResponseStatus(value = HttpStatus.NOT_FOUND)
	public String handleErrorResponseRequiredPassword()
	{
		return "{\"reason\": \"The field 'Password' is required\"}";
	}
}<commit_msg>Corregido pequeño error GetVoter<commit_after>package es.uniovi.asw.voterAcess.webService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import es.uniovi.asw.dbManagement.GetVoter;
import es.uniovi.asw.dbManagement.impl.GetVoterDB;
import es.uniovi.asw.dbManagement.model.Voter;
import es.uniovi.asw.dbManagement.persistence.VoterRepository;
import es.uniovi.asw.voterAcess.GetVoterInfo;
import es.uniovi.asw.voterAcess.webService.responses.VoterInfoResponse;
import es.uniovi.asw.voterAcess.webService.responses.errors.InvalidPasswordErrorResponse;
import es.uniovi.asw.voterAcess.webService.responses.errors.RequiredPasswordErrorResponse;
import es.uniovi.asw.voterAcess.webService.responses.errors.RequiredUserErrorResponse;
import es.uniovi.asw.voterAcess.webService.responses.errors.UserNotFoundErrorResponse;

@RestController
public class GetVoterInfoController implements GetVoterInfo
{
	private static final Logger log = LoggerFactory.getLogger(GetVoterInfoController.class);
	
	private final VoterRepository voterRepository;
	
	@Autowired
	GetVoterInfoController(VoterRepository voterRepository)
	{
		this.voterRepository = voterRepository;
	}
	
	@RequestMapping(value="/user",
			method= RequestMethod.POST,
			headers ="Accept=application/json",
			produces={"application/json","application/xml"})
	public VoterInfoResponse getInfoVoter(@RequestBody Voter voter)
	{
		log.info("Datos peticion: "+voter.getEmail()+" "+voter.getPassword());

		if(voter.getEmail().equals(""))
			throw new RequiredUserErrorResponse();
		if(voter.getPassword().equals(""))
			throw new RequiredPasswordErrorResponse();
		
		GetVoter gv = new GetVoterDB(this.voterRepository);
		Voter user = gv.getVoter(voter.getEmail());
		if(user==null)
			throw new UserNotFoundErrorResponse();
		if(user.getPassword().compareTo(voter.getPassword()) == 0)
			return new VoterInfoResponse(user);
		else
			throw new InvalidPasswordErrorResponse();
	}
	
	
	@ExceptionHandler(UserNotFoundErrorResponse.class)
	@ResponseStatus(value = HttpStatus.NOT_FOUND)
	public String handleErrorResponseNotFound()
	{
		return "{\"reason\": \"User not found\"}";
	}
	
	@ExceptionHandler(InvalidPasswordErrorResponse.class)
	@ResponseStatus(value = HttpStatus.NOT_FOUND)
	public String passwordConflict()
	{
		return "{\"reason\": \"Password incorrect\"}";
	}
	
	@ExceptionHandler(RequiredUserErrorResponse.class)
	@ResponseStatus(value = HttpStatus.NOT_FOUND)
	public String handleErrorResponseRequiredUser()
	{
		return "{\"reason\": \"The field 'User' is required\"}";
	}
	
	@ExceptionHandler(RequiredPasswordErrorResponse.class)
	@ResponseStatus(value = HttpStatus.NOT_FOUND)
	public String handleErrorResponseRequiredPassword()
	{
		return "{\"reason\": \"The field 'Password' is required\"}";
	}
}
{'fraction_non_alphanumeric': 0.11462024341395778, 'fraction_numerical': 0.0009243568017254661, 'mean_word_length': 6.601873536299766, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '1921493', 'n_tokens_mistral': 2053, 'n_tokens_neox': 1954, 'n_words': 309}