<commit_before>package REST;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityTransaction;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;

import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;

import DataAccessObjects.ClientDAO;
import DataAccessObjects.EM;
import DataAccessObjects.EventDAO;
import DataAccessObjects.EventPlannerDAO;
import ProblemDomain.Client;
import ProblemDomain.Event;
import ProblemDomain.EventPlanner;
import ProblemDomain.EventSystem;
import ProblemDomain.Guest;
import ProblemDomain.Message;
import ProblemDomain.Role;
import ProblemDomain.RoleAssignment;
import ProblemDomain.Token;

@Path("/services")
public class Services {

	@Context
	SecurityContext securityContext;
	static int numberTimesCalled = 0;
	ArrayList<Message> messages = new ArrayList<Message>();

	// Test services
	@GET
	@Path("/hello")
	@Produces(MediaType.TEXT_PLAIN)
	public String hello() {
		numberTimesCalled++;
		return "Hello GET-REST World!\n You've called this method: " + numberTimesCalled + " times.";
	}

	@Context
	ServletContext context;

	@Secured
	@POST
	@Path("/importguests/{id}")
	@Consumes(MediaType.MULTIPART_FORM_DATA)
	@Produces(MediaType.APPLICATION_JSON)
	public Response importGuests(@PathParam("id") String id, @FormDataParam("file") InputStream uploadInputStream,
			@FormDataParam("file") FormDataContentDisposition fileDetail) {

		Event e = EventSystem.findEventById(id);
		// Save the file to the server
		try {
			File tempFile = File.createTempFile("upload" + "001", ".tmp");
			String lastUploadedFile = tempFile.getAbsolutePath();
			try (OutputStream out = new FileOutputStream(tempFile)) {
				// Read the data from the server file
				int read = 0;
				byte[] bytes = new byte[1024];
				while ((read = uploadInputStream.read(bytes)) != -1) {
					out.write(bytes, 0, read);
				}

				// Create a new event and import the guests.
				EntityTransaction eventTransaction = EM.getEM().getTransaction();
				eventTransaction.begin();
				e.importGuests(lastUploadedFile);
				EventDAO.saveEvent(e);
				eventTransaction.commit();
			}
		} catch (IOException ioex) {
			ioex.printStackTrace();
		}
		return Response.status(200).entity(e.printGuestList()).build();
	}

	@POST
	@Path("/login")
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_JSON)
	public Response authenticateUser(EventPlanner user) {

		try {
			// Authenticate the user using the credentials provided
			authenticate(user.getUserName(), user.getPassword());

			// Issue a token for the user
			String token = issueToken(user.getUserName());

			// Return the token on the response
			return Response.ok(token).build();

		} catch (Exception e) {
			return Response.status(Response.Status.UNAUTHORIZED).build();
		}
	}

	@Secured
	@GET
	@Path("/employees/current")
	@Produces(MediaType.APPLICATION_JSON)
	public EventPlanner getEventPlanner() {
		String username = securityContext.getUserPrincipal().getName();
		EventPlanner planner = EventSystem.findEventPlannerByUserName(username);
		return planner;
	}

	@Secured
	@GET
	@Path("/employees")
	@Produces(MediaType.APPLICATION_JSON)
	public List<EventPlanner> getEventPlanner(@DefaultValue("0") @QueryParam("page") String page,
			@DefaultValue("15") @QueryParam("per_page") String perPage) {
		return EventSystem.findAllEventPlanners(Integer.parseInt(page), Integer.parseInt(perPage));
	}

	@Secured({ Role.Admin })
	@GET
	@Path("/employees/{id}")
	@Produces(MediaType.APPLICATION_JSON)
	public EventPlanner getEventPlanner(@PathParam("id") String id) {
		EventPlanner planner = EventSystem.findEventPlannerById(id);
		EM.getEM().refresh(planner);
		return planner;
	}

	@Secured({ Role.Admin })
	@POST
	@Path("/employees")
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_JSON)
	public ArrayList<Message> addEventPlanner(EventPlanner planner, @Context final HttpServletResponse response)<commit_msg>removed the admin requirement to get a single employee<commit_after>package REST;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityTransaction;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;

import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;

import DataAccessObjects.ClientDAO;
import DataAccessObjects.EM;
import DataAccessObjects.EventDAO;
import DataAccessObjects.EventPlannerDAO;
import ProblemDomain.Client;
import ProblemDomain.Event;
import ProblemDomain.EventPlanner;
import ProblemDomain.EventSystem;
import ProblemDomain.Guest;
import ProblemDomain.Message;
import ProblemDomain.Role;
import ProblemDomain.RoleAssignment;
import ProblemDomain.Token;

@Path("/services")
public class Services {

	@Context
	SecurityContext securityContext;
	static int numberTimesCalled = 0;
	ArrayList<Message> messages = new ArrayList<Message>();

	// Test services
	@GET
	@Path("/hello")
	@Produces(MediaType.TEXT_PLAIN)
	public String hello() {
		numberTimesCalled++;
		return "Hello GET-REST World!\n You've called this method: " + numberTimesCalled + " times.";
	}

	@Context
	ServletContext context;

	@Secured
	@POST
	@Path("/importguests/{id}")
	@Consumes(MediaType.MULTIPART_FORM_DATA)
	@Produces(MediaType.APPLICATION_JSON)
	public Response importGuests(@PathParam("id") String id, @FormDataParam("file") InputStream uploadInputStream,
			@FormDataParam("file") FormDataContentDisposition fileDetail) {

		Event e = EventSystem.findEventById(id);
		// Save the file to the server
		try {
			File tempFile = File.createTempFile("upload" + "001", ".tmp");
			String lastUploadedFile = tempFile.getAbsolutePath();
			try (OutputStream out = new FileOutputStream(tempFile)) {
				// Read the data from the server file
				int read = 0;
				byte[] bytes = new byte[1024];
				while ((read = uploadInputStream.read(bytes)) != -1) {
					out.write(bytes, 0, read);
				}

				// Create a new event and import the guests.
				EntityTransaction eventTransaction = EM.getEM().getTransaction();
				eventTransaction.begin();
				e.importGuests(lastUploadedFile);
				EventDAO.saveEvent(e);
				eventTransaction.commit();
			}
		} catch (IOException ioex) {
			ioex.printStackTrace();
		}
		return Response.status(200).entity(e.printGuestList()).build();
	}

	@POST
	@Path("/login")
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_JSON)
	public Response authenticateUser(EventPlanner user) {

		try {
			// Authenticate the user using the credentials provided
			authenticate(user.getUserName(), user.getPassword());

			// Issue a token for the user
			String token = issueToken(user.getUserName());

			// Return the token on the response
			return Response.ok(token).build();

		} catch (Exception e) {
			return Response.status(Response.Status.UNAUTHORIZED).build();
		}
	}

	@Secured
	@GET
	@Path("/employees/current")
	@Produces(MediaType.APPLICATION_JSON)
	public EventPlanner getEventPlanner() {
		String username = securityContext.getUserPrincipal().getName();
		EventPlanner planner = EventSystem.findEventPlannerByUserName(username);
		return planner;
	}

	@Secured
	@GET
	@Path("/employees")
	@Produces(MediaType.APPLICATION_JSON)
	public List<EventPlanner> getEventPlanner(@DefaultValue("0") @QueryParam("page") String page,
			@DefaultValue("15") @QueryParam("per_page") String perPage) {
		return EventSystem.findAllEventPlanners(Integer.parseInt(page), Integer.parseInt(perPage));
	}

	@Secured
	@GET
	@Path("/employees/{id}")
	@Produces(MediaType.APPLICATION_JSON)
	public EventPlanner getEventPlanner(@PathParam("id") String id) {
		EventPlanner planner = EventSystem.findEventPlannerById(id);
		EM.getEM().refresh(planner);
		return planner;
	}

	@Secured({ Role.Admin })
	@POST
	@Path("/employees")
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_JSON)
	public ArrayList<Message> addEventPlanner(EventPlanner planner, @Context final HttpServletResponse response)
{'fraction_non_alphanumeric': 0.11911716975008114, 'fraction_numerical': 0.0036784593746619063, 'mean_word_length': 5.428372739916551, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '919898', 'n_tokens_mistral': 3086, 'n_tokens_neox': 2861, 'n_words': 606}