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

import java.net.HttpURLConnection;
import java.util.Collection;

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.PathParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.example.beer.dao.ProjectDAO;
import com.example.beer.model.Project;
import com.example.beer.model.User;

@Stateless
@Path("project")
public class ProjectManager {
	@Inject
	ProjectDAO projectDAO;
	
	@Inject
	UserContext userContext;
	
	@GET
	@javax.ws.rs.Produces(MediaType.APPLICATION_JSON)
	public Collection<Project> getAllProjects() {
		return projectDAO.getAllProjects();
	}
	
	@GET
	@Path("projectId")
	public Response getTasksForProject(@PathParam("projectId") int projectId) {
		Project project = projectDAO.findProjectById(projectId);
		
		if (project == null) {
			return Response.status(HttpURLConnection.HTTP_NOT_FOUND).build();
		}
		
		return Response.ok(project.getTasks(), MediaType.APPLICATION_JSON).build();
	}
	
	@POST
	@Consumes(MediaType.APPLICATION_JSON)
	public Response createProject(Project project) {
		User currentUser = userContext.getCurrentUser();
		if (currentUser == null || !currentUser.isAdmin()) {
			return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).build();
		}
		
        if (projectDAO.addProject(project)) {
			return Response.status(HttpURLConnection.HTTP_OK).build();
        }
        
        return Response.status(HttpURLConnection.HTTP_CONFLICT).build();
	}
}
<commit_msg>Add get projects for a particular user functionality to REST service<commit_after>package com.example.beer.services;

import java.net.HttpURLConnection;
import java.util.Collection;

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.PathParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.example.beer.dao.ProjectDAO;
import com.example.beer.model.Project;
import com.example.beer.model.User;

@Stateless
@Path("project")
public class ProjectManager {
	@Inject
	ProjectDAO projectDAO;
	
	@Inject
	UserContext userContext;
	
	@GET
	@javax.ws.rs.Produces(MediaType.APPLICATION_JSON)
	public Collection<Project> getAllProjects() {
		return projectDAO.getAllProjects();
	}
	
	@GET
	@Path("projectId")
	public Response getTasksForProject(@PathParam("projectId") int projectId) {
		Project project = projectDAO.findProjectById(projectId);
		
		if (project == null) {
			return Response.status(HttpURLConnection.HTTP_NOT_FOUND).build();
		}
		
		return Response.ok(project.getTasks(), MediaType.APPLICATION_JSON).build();
	}
	
	@POST
	@Consumes(MediaType.APPLICATION_JSON)
	public Response createProject(Project project) {
		User currentUser = userContext.getCurrentUser();
		if (currentUser == null || !currentUser.isAdmin()) {
			return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).build();
		}
		
        if (projectDAO.addProject(project)) {
			return Response.status(HttpURLConnection.HTTP_OK).build();
        }
        
        return Response.status(HttpURLConnection.HTTP_CONFLICT).build();
	}

	@GET
	@Path("user")
	@Consumes(MediaType.APPLICATION_JSON)
	public Collection<Project> getProjectsForUser(String username) {
		return projectDAO.getProjectsForUser(username);
	}
}

{'fraction_non_alphanumeric': 0.11948051948051948, 'fraction_numerical': 0.0, 'mean_word_length': 4.996539792387543, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '819666', 'n_tokens_mistral': 1175, 'n_tokens_neox': 1120, 'n_words': 193}