<commit_before>package com.example.beer.services;

import java.net.HttpURLConnection;

import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.example.beer.dao.ProjectDAO;
import com.example.beer.dao.TaskDAO;
import com.example.beer.dao.UserDAO;
import com.example.beer.model.Project;
import com.example.beer.model.Task;
import com.example.beer.model.Task.TaskStatus;
import com.example.beer.model.User;

@Stateless
@Path("task")
public class TaskManager {
	
	@Inject
	ProjectDAO projectDAO;
	
	@Inject
	TaskDAO taskDAO;
	
	@Inject
	UserDAO userDAO;
	
	@Inject
	UserContext userContext;
	
	@POST
	@Consumes(MediaType.APPLICATION_JSON)
	public Response createTask(Project project, User user, String name, String description) {
		User currentUser = userContext.getCurrentUser();
		if (currentUser == null || !currentUser.isAdmin()) {
			return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).build();
		} 
		
		if (!taskDAO.addTask(name, description, user)) {
			return Response.status(HttpURLConnection.HTTP_NOT_ACCEPTABLE).build();
		}
		
		Task task = taskDAO.findTaskByName(name);
		
		if (taskDAO.addToProject(project, task)) {
			return Response.status(HttpURLConnection.HTTP_OK).build();
        } else {
        	return Response.status(HttpURLConnection.HTTP_NOT_ACCEPTABLE).build();
        }
	}
	
	@POST
	@Consumes(MediaType.APPLICATION_JSON)
	public Response assignUser(User user, Task task) {
		User currentUser = userContext.getCurrentUser();
		if (currentUser == null) {
			return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).build();
		} 
		
		if (taskDAO.assignUser(task, user)) {
			return Response.status(HttpURLConnection.HTTP_OK).build();
		}
		
		return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).build();
	}
	
	@POST
	@Consumes(MediaType.APPLICATION_JSON)<commit_msg>Fix TaskManager.createTask to work with assigneeId:int instead of user:User<commit_after>package com.example.beer.services;

import java.net.HttpURLConnection;

import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.example.beer.dao.ProjectDAO;
import com.example.beer.dao.TaskDAO;
import com.example.beer.dao.UserDAO;
import com.example.beer.model.Project;
import com.example.beer.model.Task;
import com.example.beer.model.Task.TaskStatus;
import com.example.beer.model.User;

@Stateless
@Path("task")
public class TaskManager {
	
	@Inject
	ProjectDAO projectDAO;
	
	@Inject
	TaskDAO taskDAO;
	
	@Inject
	UserDAO userDAO;
	
	@Inject
	UserContext userContext;
	
	@POST
	@Consumes(MediaType.APPLICATION_JSON)
	public Response createTask(Project project, int assigneeId, String name, String description) {
		User currentUser = userContext.getCurrentUser();
		if (currentUser == null || !currentUser.isAdmin()) {
			return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).build();
		} 
	
		User assignee = userDAO.getUserById(assigneeId);
		
		if (assignee == null) {
			return Response.status(HttpURLConnection.HTTP_NOT_FOUND).build();
		}

		if (!taskDAO.addTask(name, description, assignee)) {
			return Response.status(HttpURLConnection.HTTP_NOT_ACCEPTABLE).build();
		}
		
		Task task = taskDAO.findTaskByName(name);
		
		if (taskDAO.addToProject(project, task)) {
			return Response.status(HttpURLConnection.HTTP_OK).build();
        } else {
        	return Response.status(HttpURLConnection.HTTP_NOT_ACCEPTABLE).build();
        }
	}
	
	@POST
	@Consumes(MediaType.APPLICATION_JSON)
	public Response assignUser(User user, Task task) {
		User currentUser = userContext.getCurrentUser();
		if (currentUser == null) {
			return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).build();
		} 
		
		if (taskDAO.assignUser(task, user)) {
			return Response.status(HttpURLConnection.HTTP_OK).build();
		}
		
		return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).build();
	}
	
	@POST
	@Consumes(MediaType.APPLICATION_JSON)
{'fraction_non_alphanumeric': 0.1180327868852459, 'fraction_numerical': 0.0, 'mean_word_length': 4.802989130434782, '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': '1879571', 'n_tokens_mistral': 1529, 'n_tokens_neox': 1433, 'n_words': 247}