<commit_before>package com.ba.captwo.eda.demo.resources;

import com.ba.captwo.eda.demo.coreservices.PersonService;
import com.ba.captwo.eda.demo.model.*;
import com.ba.captwo.eda.demo.model.Error;
import org.apache.cxf.jaxrs.ext.MessageContext;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpSession;
import javax.servlet.http.*;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import java.util.ArrayList;

/**
 * Created by u760245 on 05/07/2014.
 */
@Component("PersonResource")
public class PersonResourceImpl implements PersonResource{

    private final Logger log = LoggerFactory.getLogger(PersonResourceImpl.class);

    @Context
    private MessageContext context;

    @Context
    HttpServletRequest request;

    @Autowired
    PersonService personService;

    public Response createPerson(
            String fname,
            String lname,
            String address,
            String city)    {

        log.debug("createPerson");
        log.debug("fname : " + fname);
        log.debug("lname : " + lname);
        log.debug("address : " + address);
        log.debug("city : " + city);

        Response response = null;

        if ((fname == null) || (lname == null) || (address == null))  {
            Error err = new Error();
            err.setMessage("Incomplate Request");
            return Response.status(Response.Status.BAD_REQUEST).entity(err).build();
        }

        Person p = new Person();
        p.setFirstName(fname);
        p.setLastName(lname);
        p.setAddress(address);
        p.setCity(city);

        try {
            p = personService.createPerson(p);
            response = Response.status(Response.Status.OK).entity(p).build();
        }
        catch (Exception e) {
            com.ba.captwo.eda.demo.model.Error err = new Error();
            err.setMessage(e.getMessage());
            response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(err).build();
        }

        return response;
    }


    public Response readPerson(int pid)    {

        Person p = null;

        log.debug("readPerson");
        log.debug("readPerson REQUEST : "+request);
        log.debug("pid : " + pid);

        Response response = null;



        try {
            HttpSession session = (HttpSession)request.getSession();
            log.debug("readPerson SESSION : "+session);

            p = (Person)session.getAttribute("PERSON");

            if (p == null) {
                log.debug("Retrieving Person from DB");
                p = personService.readPerson(pid);
                session.setAttribute("PERSON", p);
            }
            else    {
                log.debug("Retrieving Person from Session");
            }

            response = Response.status(Response.Status.OK).entity(p).build();
        }
        catch (Exception e) {
            e.printStackTrace();
            com.ba.captwo.eda.demo.model.Error err = new Error();
            err.setMessage(e.getMessage());
            response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(err).build();<commit_msg>changes<commit_after>package com.ba.captwo.eda.demo.resources;

import com.ba.captwo.eda.demo.coreservices.PersonService;
import com.ba.captwo.eda.demo.model.*;
import com.ba.captwo.eda.demo.model.Error;
import org.apache.cxf.jaxrs.ext.MessageContext;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpSession;
import javax.servlet.http.*;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import java.util.ArrayList;

/**
 * Created by u760245 on 05/07/2014.
 */
@Component("PersonResource")
public class PersonResourceImpl implements PersonResource{

    private final Logger log = LoggerFactory.getLogger(PersonResourceImpl.class);

    @Context
    HttpServletRequest request;

    @Autowired
    PersonService personService;

    public Response createPerson(
            String fname,
            String lname,
            String address,
            String city)    {

        log.debug("createPerson");
        log.debug("fname : " + fname);
        log.debug("lname : " + lname);
        log.debug("address : " + address);
        log.debug("city : " + city);

        Response response = null;

        if ((fname == null) || (lname == null) || (address == null))  {
            Error err = new Error();
            err.setMessage("Incomplate Request");
            return Response.status(Response.Status.BAD_REQUEST).entity(err).build();
        }

        Person p = new Person();
        p.setFirstName(fname);
        p.setLastName(lname);
        p.setAddress(address);
        p.setCity(city);

        try {
            p = personService.createPerson(p);
            response = Response.status(Response.Status.OK).entity(p).build();
        }
        catch (Exception e) {
            com.ba.captwo.eda.demo.model.Error err = new Error();
            err.setMessage(e.getMessage());
            response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(err).build();
        }

        return response;
    }


    public Response readPerson(int pid)    {

        Person p = null;

        log.debug("readPerson");
        log.debug("readPerson REQUEST : "+request);
        log.debug("pid : " + pid);

        Response response = null;

        try {
            HttpSession session = (HttpSession)request.getSession();
            log.debug("readPerson SESSION : "+session);

            p = (Person)session.getAttribute("PERSON");

            if (p == null) {
                log.debug("Retrieving Person from DB");
                p = personService.readPerson(pid);
                session.setAttribute("PERSON", p);
            }
            else    {
                log.debug("Retrieved Person from Session");
            }

            response = Response.status(Response.Status.OK).entity(p).build();
        }
        catch (Exception e) {
            e.printStackTrace();
            com.ba.captwo.eda.demo.model.Error err = new Error();
            err.setMessage(e.getMessage());
            response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(err).build();
{'fraction_non_alphanumeric': 0.12548173269616156, 'fraction_numerical': 0.004932942808694312, 'mean_word_length': 2.2800808897876643, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3527626', 'n_tokens_mistral': 1855, 'n_tokens_neox': 1784, 'n_words': 341}