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.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;

@Stateless
@Path("project")
public class ProjectManager {
	@Inject
	ProjectDAO projectDAO;
	
	@Inject
	UserContext userContext;
	
	@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) {
		if (!userContext.getCurrentUser().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();
	}
}

@@ -63,16 +63,45 @@
 nection;
+%0Aimport java.util.Collection;
 %0A%0Aimport
@@ -431,16 +431,52 @@
 Project;
+%0Aimport com.example.beer.model.User;
 %0A%0A@State
@@ -605,16 +605,163 @@
 %09%0A%09@GET%0A
+%09@javax.ws.rs.Produces(MediaType.APPLICATION_JSON)%0A%09public Collection%3CProject%3E getAllProjects() %7B%0A%09%09return projectDAO.getAllProjects();%0A%09%7D%0A%09%0A%09@GET%0A
 %09@Path(%22
@@ -1197,13 +1197,27 @@
 %7B%0A%09%09
-if (!
+User currentUser = 
 user
@@ -1240,16 +1240,59 @@
 ntUser()
+;%0A%09%09if (currentUser == null %7C%7C !currentUser
 .isAdmin

Add get all projects functionality to REST service