<commit_before>package org.openregistry.core.web.resources;

import org.springframework.stereotype.Component;
import org.springframework.context.annotation.Scope;

import javax.ws.rs.*;
import javax.ws.rs.core.MultivaluedMap;

/**
 * Root RESTful resource representing people in Open Registry.
 * This component is managed and autowired by Spring by means of context-component-scan,
 * and served by Jersey when URI is matched against the @Path definition. This bean is a singleton,
 * and therefore is thread-safe.
 *
 * @author <NAME>
 * @since 1.0
 */
@Path("/people")
@Component
@Scope("singleton")
public class PeopleResource {

    @GET
    @Path("{personId}")
    @Produces("text/plain")
    public String getItem(@PathParam("personId") String personId) {
        return "Yes, this is the representation from a Jersey-managed resource! The person ID is: " + personId;
    }

    @POST
    @Consumes("application/x-www-form-urlencoded")
    public void postSomeData(MultivaluedMap<String, String> formParams) {
        System.out.println("GOT HTTP form POSTed: " + formParams);
    }

}<commit_msg>NOJIRA: Added basic REST support with Jersey<commit_after>package org.openregistry.core.web.resources;

import org.springframework.stereotype.Component;
import org.springframework.context.annotation.Scope;

import javax.ws.rs.*;
import javax.ws.rs.core.*;
import java.net.URI;

/**
 * Root RESTful resource representing people in Open Registry.
 * This component is managed and autowired by Spring by means of context-component-scan,
 * and served by Jersey when URI is matched against the @Path definition. This bean is a singleton,
 * and therefore is thread-safe.
 *
 * @author <NAME>
 * @since 1.0
 */
@Path("/people")
@Component
@Scope("singleton")
public class PeopleResource {

    @Context
    //injected by Jersey
            UriInfo uriInfo;

    @GET
    @Path("{personId}")
    @Produces("text/plain")
    public String getItem(@PathParam("personId") String personId) {
        return "Yes, this is the representation from a Jersey-managed resource! The person ID is: " + personId;
    }

    @POST
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    //resp-type query param is here temporarily, for testing
    public Response postSomeData(@DefaultValue("201") @QueryParam("resp-type") int respType,
                                 MultivaluedMap<String, String> formParams) {

        //NOTE: The real handling of the POSTed representation will be done
        //here by means of marshalling the submitted form data into a Java type
        //and invoking the internal Open Registry API/APIs (TBD), and based on the outcome
        //return the appropriate response.

        //The code bolow is just for testing the Jersey framework
        //and to lay out the foundation for further work.        

        Response response = null;
        UriBuilder uriBuilder = this.uriInfo.getAbsolutePathBuilder();
        URI uri = uriBuilder.path("rcpId").path("1234567").build();

        switch (respType) {
            case 201:
                response = Response.created(uri).build();
                break;
            case 409:
                //Hack! Just to test. Need more robust way of building a list of links
                String entityBody = "<link rel=\"person\" href=\"" + uri.toString() + "\"/>" +
                        "\n<link rel=\"person\" href=\"" + uri.toString() + "\"/>\n";
                response = Response.status(409).entity(entityBody).build();
                break;
            case 307:
                response = Response.temporaryRedirect(uri).build();
            default:
                break;
        }
        System.out.println("GOT HTTP form POSTed: " + formParams);
        return response;
    }
}
{'fraction_non_alphanumeric': 0.10685805422647528, 'fraction_numerical': 0.006911217437533227, 'mean_word_length': 2.755489021956088, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6820878', 'n_tokens_mistral': 1048, 'n_tokens_neox': 994, 'n_words': 332}