<commit_before>package controllers;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import models.User;

import java.util.List;

/**
 * Created by clezio on 18/03/16.
 */

public class Users extends BaseController{

    public static void add(){
        User userDTO = new GsonBuilder().create().fromJson(request.params.get("body"), User.class);
        if(userDTO == null){
            userDTO = new User();
        }
        User user = new User(userDTO.getName());
        validation.valid(user);
        if (validation.hasErrors()) {
            error(HTTP_UNPROCESSABLE_ENTITY, new Gson().toJson(getListErrors(validation.errorsMap())));
        }
        user.save();
        renderJSON(user);
    }

    public static void edit(){
        User userDTO = new GsonBuilder().create().fromJson(request.params.get("body"), User.class);
        User user = User.findById(userDTO.getId());
        user.setName(userDTO.getName());
        if (validation.hasErrors()) {
            error(HTTP_UNPROCESSABLE_ENTITY, new Gson().toJson(getListErrors(validation.errorsMap())));
        }
        user.save();
        renderJSON(user);
    }

    public static void list(){
        List<User> users = User.findAll();
        renderJSON(users);
    }

    public static void delete(Long id){<commit_msg>Adicionada validação para a rotina de edição do usuário<commit_after>package controllers;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import models.User;

import java.util.List;

/**
 * Created by clezio on 18/03/16.
 */

public class Users extends BaseController{

    public static void add(){
        User userDTO = new GsonBuilder().create().fromJson(request.params.get("body"), User.class);
        if(userDTO == null){
            userDTO = new User();
        }
        User user = new User(userDTO.getName());
        validation.valid(user);
        if (validation.hasErrors()) {
            error(HTTP_UNPROCESSABLE_ENTITY, new Gson().toJson(getListErrors(validation.errorsMap())));
        }
        user.save();
        renderJSON(user);
    }

    public static void edit(){
        User userDTO = new GsonBuilder().create().fromJson(request.params.get("body"), User.class);
        User user = User.findById(userDTO.getId());
        user.setName(userDTO.getName());
        validation.valid(user);
        if (validation.hasErrors()) {
            error(HTTP_UNPROCESSABLE_ENTITY, new Gson().toJson(getListErrors(validation.errorsMap())));
        }
        user.save();
        renderJSON(user);
     }

    public static void list(){
        List<User> users = User.findAll();
        renderJSON(users);
    }

    public static void delete(Long id){
{'fraction_non_alphanumeric': 0.13476490188818957, 'fraction_numerical': 0.004442798963346909, 'mean_word_length': 2.721763085399449, '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': '5971141', 'n_tokens_mistral': 799, 'n_tokens_neox': 795, 'n_words': 166}