<commit_before>package com.giannoules.proxstor.location;

import com.giannoules.proxstor.exception.ProxStorGraphDatabaseNotRunningException;
import java.util.Collection;
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.Produces;
import javax.ws.rs.core.MediaType;

@Path("/locations")
public class LocationsResource {
    
    /*
     * returns instance of LocationResource to handle locId specific request 
     */
    @Path("{locid: [0-9]+}")
    public LocationResource getLocationResource(@PathParam("locid") String locId) {
        return new LocationResource(locId);
    }
    
    /*
     * returns all locations system-wide!
     */
    @GET
    @Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN})
    public Collection<Location> getLocations() {
        return LocationDao.instance.getAllLocations();
    }

    /*
     * adds location to database
     *
     * returns instance of added Location
     */
    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public Location postLocation(Location l) {
        return LocationDao.instance.addLocation(l);
    }
}<commit_msg>return proper http response when creating a new location; remove @GET all locations<commit_after>package com.giannoules.proxstor.location;

import com.giannoules.proxstor.exception.ProxStorGraphDatabaseNotRunningException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;
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.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@Path("/locations")
public class LocationsResource {

    /*
     * adds location to database
     *
     * returns instance of added Location
     *
     * success - returns 201 (Created) with URI of new Location and Location JSON in the body
     * failure - returns 400 (Bad Request) if the Location could not be added
     *           returns 500 (Server Error) if the Location could was added and 
     *                                      URI building error occurred
     */
    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public Response postLocation(Location in) {
        Location l = LocationDao.instance.addLocation(in);
        if (l == null) {
            return Response.status(400).build();
        } else {
            try {
                URI createdUri = new URI("locations/" + l.getLocId());
                return Response.created(createdUri).entity(l).build();
            } catch (URISyntaxException ex) {
                Logger.getLogger(LocationsResource.class.getName()).log(Level.SEVERE, null, ex);
                return Response.serverError().build();
            }
        }
    }

    // ---- BEGIN sub-resource locators ----
    
    /*
     * returns instance of LocationResource to handle locId specific request 
     */
    @Path("{locid: [0-9]+}")
    public LocationResource getLocationResource(@PathParam("locid") String locId) {
        return new LocationResource(locId);
    }

}
{'fraction_non_alphanumeric': 0.10491407898703647, 'fraction_numerical': 0.00482363581549593, 'mean_word_length': 2.8761682242990654, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4944847', 'n_tokens_mistral': 983, 'n_tokens_neox': 955, 'n_words': 224}