<commit_before>package com.cineplexnotifier.rest;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import javax.ejb.EJB;
import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

import org.jboss.resteasy.annotations.cache.Cache;

import com.cineplexnotifier.data.MovieRepository;
import com.cineplexnotifier.model.Movie;

@Path("movies")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class MoviesResource {
	@EJB
	private MovieRepository movieDao;

	@GET
	@Path("/")
	@Cache(maxAge = 600)
	public List<Movie> getMovies(@DefaultValue(value="false") @QueryParam("all") boolean available ) {
		return movieDao.selectByAvailability(false);
	}

	@POST
	@Path("/")
	public Response putMovie(Movie m) throws URISyntaxException {
		URI r = new URI(m.getCineplexKey());
		if (m.getId() == 0l && movieDao.insert(m) != 0l) {
			return Response.created(r).build();
		}
		throw new WebApplicationException(Status.BAD_REQUEST);
	}

	@GET
	@Path("{id}")
	public Movie getMovieByCineplexKey(@PathParam("id") String cineplexKey) {
		return movieDao.selectByCineplexKey(cineplexKey);
	}

}<commit_msg>Handle duplicate POSTs of same entry (by overwriting the old entery)<commit_after>package com.cineplexnotifier.rest;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import javax.ejb.EJB;
import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

import org.jboss.resteasy.annotations.cache.Cache;

import com.cineplexnotifier.data.MovieRepository;
import com.cineplexnotifier.model.Movie;

@Path("movies")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class MoviesResource {
	@EJB
	private MovieRepository movieDao;

	@GET
	@Path("/")
	@Cache(maxAge = 600)
	public List<Movie> getMovies(@DefaultValue(value = "false") @QueryParam("all") boolean available) {
		return movieDao.selectByAvailability(false);
	}

	@POST
	@Path("/")
	public Response putMovie(Movie m) throws URISyntaxException {
		URI r = new URI(m.getCineplexKey());
		Movie old = movieDao.selectByCineplexKey(m.getCineplexKey());
		if (old != null) {
			m.setId(old.getId());
			movieDao.update(m);

			// TODO formalize REST conventions used by this app
			return Response.created(r).build();
		} else if (m.getId() == 0l && movieDao.insert(m) != 0l) {
			return Response.created(r).build();
		}
		throw new WebApplicationException(Status.BAD_REQUEST);
	}

	@GET
	@Path("{id}")
	public Movie getMovieByCineplexKey(@PathParam("id") String cineplexKey) {
		return movieDao.selectByCineplexKey(cineplexKey);
	}

}
{'fraction_non_alphanumeric': 0.13382670366944188, 'fraction_numerical': 0.003083564600678384, 'mean_word_length': 5.488, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3436399', 'n_tokens_mistral': 1203, 'n_tokens_neox': 1134, 'n_words': 216}