<commit_before>package com.philihp.weblabora.action;

import javax.persistence.EntityManager;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import com.philihp.weblabora.form.GameForm;
import com.philihp.weblabora.jpa.Game;
import com.philihp.weblabora.jpa.User;

public class LeaveGame extends BaseAction {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
			HttpServletResponse response, User user) throws Exception {
		
		GameForm form = (GameForm)actionForm; 
		EntityManager em = (EntityManager)request.getAttribute("em");
		
		Game game = em.find(Game.class, form.getGameId());
		
		if(game == null) {
			ActionMessages messages = getMessages(request);
			messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("messages.invalidGameId", form.getGameId()));
			saveMessages(request.getSession(), messages);
		}
		else {
			for(Game.Player player : game.getAllPlayers()) {
				if(user.equals(player.getUser())) {
					player.setUser(null);
				}
			}
		}
		
		return mapping.findForward("root");
	}
<commit_msg>leave game sets game stage back to recruiting so people can join it<commit_after>package com.philihp.weblabora.action;

import javax.persistence.EntityManager;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import com.philihp.weblabora.form.GameForm;
import com.philihp.weblabora.jpa.Game;
import com.philihp.weblabora.jpa.User;

public class LeaveGame extends BaseAction {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
			HttpServletResponse response, User user) throws Exception {
		
		GameForm form = (GameForm)actionForm; 
		EntityManager em = (EntityManager)request.getAttribute("em");
		
		Game game = em.find(Game.class, form.getGameId());
		
		if(game == null) {
			ActionMessages messages = getMessages(request);
			messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("messages.invalidGameId", form.getGameId()));
			saveMessages(request.getSession(), messages);
		}
		else {
			for(Game.Player player : game.getAllPlayers()) {
				if(user.equals(player.getUser())) {
					player.setUser(null);
					if(game.getStage() == Game.Stage.IN_PROGRESS)
						game.setStage(Game.Stage.RECRUITING);
				}
			}
		}
		
		return mapping.findForward("root");
	}

{'fraction_non_alphanumeric': 0.11180339217722396, 'fraction_numerical': 0.0, 'mean_word_length': 5.201716738197425, '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': '6538219', 'n_tokens_mistral': 960, 'n_tokens_neox': 870, 'n_words': 161}