<commit_before>package org.udg.pds.simpleapp_javaee.service;

import org.udg.pds.simpleapp_javaee.model.User;
import org.udg.pds.simpleapp_javaee.rest.RESTService;

import javax.ejb.EJBException;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

@Stateless
@LocalBean
public class UserService {

  @PersistenceContext
  private EntityManager em;

  public User matchPassword(String username, String password) {
    Query q = em.createQuery("select u from users u where u.username=:username");
    q.setParameter("username", username);

    User u;
    try {
      u = (User) q.getSingleResult();
    } catch (Exception e) {
      throw new EJBException("No user with this username exists");
    }

    if (u.getPassword().equals(password))
      return u;
    else
      throw new EJBException("Password does not match");
  }

  public User register(String username, String email, String password) {

    Query q = em.createQuery("select u from User u where u.email=:email");
    q.setParameter("email", email);
    try {
      User u = (User) q.getSingleResult();
    } catch (Exception e) {
      throw new EJBException("Email already exist");
    }

    q = em.createQuery("select u from User u where u.username=:username");
    q.setParameter("username", username);
    try {
      User u = (User) q.getSingleResult();
    } catch (Exception e) {
      throw new EJBException("Username already exists");
    }

    User nu = new User(username, email, password);
    em.persist(nu);
    return nu;
  }

  public User getUser(long id) {
    return em.find(User.class, id);
  }

  public RESTService.ID remove(Long userId) {
    User u = getUser(userId);
    em.remove(u);
    return new RESTService.ID(userId);
  }

  public User getUserComplete(Long loggedId) {
    User u = getUser(loggedId);
    u.getTasks().size();
    return u;
  }
}<commit_msg>Added getUserProfile()<commit_after>package org.udg.pds.simpleapp_javaee.service;

import org.udg.pds.simpleapp_javaee.model.Task;
import org.udg.pds.simpleapp_javaee.model.User;
import org.udg.pds.simpleapp_javaee.rest.RESTService;

import javax.ejb.EJBException;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

@Stateless
@LocalBean
public class UserService {

  @PersistenceContext
  private EntityManager em;

  public User matchPassword(String username, String password) {
    Query q = em.createQuery("select u from users u where u.username=:username");
    q.setParameter("username", username);

    User u;
    try {
      u = (User) q.getSingleResult();
    } catch (Exception e) {
      throw new EJBException("No user with this username exists");
    }

    if (u.getPassword().equals(password))
      return u;
    else
      throw new EJBException("Password does not match");
  }

  public User register(String username, String email, String password) {

    Query q = em.createQuery("select u from User u where u.email=:email");
    q.setParameter("email", email);
    try {
      User u = (User) q.getSingleResult();
    } catch (Exception e) {
      throw new EJBException("Email already exist");
    }

    q = em.createQuery("select u from User u where u.username=:username");
    q.setParameter("username", username);
    try {
      User u = (User) q.getSingleResult();
    } catch (Exception e) {
      throw new EJBException("Username already exists");
    }

    User nu = new User(username, email, password);
    em.persist(nu);
    return nu;
  }

  public User getUser(long id) {
    return em.find(User.class, id);
  }

  public User getUserProfile(long id) {
    User u = this.getUser(id);
    for (Task t : u.getTasks())
        t.getTags();
    return u;
  }

  public RESTService.ID remove(Long userId) {
    User u = getUser(userId);
    em.remove(u);
    return new RESTService.ID(userId);
  }

  public User getUserComplete(Long loggedId) {
    User u = getUser(loggedId);
    u.getTasks().size();
    return u;
  }
}
{'fraction_non_alphanumeric': 0.11699566682715455, 'fraction_numerical': 0.0, 'mean_word_length': 3.4249201277955272, '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': '1116311', 'n_tokens_mistral': 1319, 'n_tokens_neox': 1290, 'n_words': 345}