Search in sources :

Example 11 with User

use of org.asqatasun.webapp.entity.user.User in project Asqatasun by Asqatasun.

the class UserDAOImplTest method testFindUserFromEmail.

public void testFindUserFromEmail() {
    User user = userDAO.findUserFromEmail("test1@test.com");
    assertEquals(Long.valueOf(1), user.getId());
    assertEquals(2, user.getContractSet().size());
    user = userDAO.findUserFromEmail("test@test.com");
    assertNull(user);
}
Also used : User(org.asqatasun.webapp.entity.user.User)

Example 12 with User

use of org.asqatasun.webapp.entity.user.User in project Asqatasun by Asqatasun.

the class ContractDAOImplTest method testFindAllContractsByUser.

/**
     * Test of findAllContractsByUser method, of class ContractDAOImpl.
     */
public void testFindAllContractsByUser() {
    System.out.println("findAllContractsByUser");
    User user = userDAO.read(Long.valueOf(1));
    assertEquals(2, contractDAO.findAllContractsByUser(user).size());
    user = userDAO.read(Long.valueOf(2));
    assertEquals(0, contractDAO.findAllContractsByUser(user).size());
}
Also used : User(org.asqatasun.webapp.entity.user.User)

Example 13 with User

use of org.asqatasun.webapp.entity.user.User in project Asqatasun by Asqatasun.

the class OptionElementDAOImplTest method testFindOptionElementFromUserAndFamilyCode.

/**
     * Test of findOptionElementFromUserAndFamilyCode method, of class OptionElementDAOImpl.
     */
public void testFindOptionElementFromUserAndFamilyCode() {
    User user1 = userDAO.findUserFromEmail("test1@test.com");
    User user2 = userDAO.findUserFromEmail("test2@test.com");
    User user3 = userDAO.findUserFromEmail("test3@test.com");
    Collection<OptionElement> oec = optionElementDAO.findOptionElementFromUserAndFamilyCode(user1, "USER_OPTION");
    assertEquals(2, oec.size());
    oec = optionElementDAO.findOptionElementFromUserAndFamilyCode(user1, "ANOTHER_OPTION");
    assertTrue(oec.isEmpty());
    oec = optionElementDAO.findOptionElementFromUserAndFamilyCode(user2, "USER_OPTION");
    assertEquals(1, oec.size());
    oec = optionElementDAO.findOptionElementFromUserAndFamilyCode(user2, "ANOTHER_OPTION");
    assertTrue(oec.isEmpty());
    oec = optionElementDAO.findOptionElementFromUserAndFamilyCode(user3, "USER_OPTION");
    assertTrue(oec.isEmpty());
    oec = optionElementDAO.findOptionElementFromUserAndFamilyCode(user3, "ANOTHER_OPTION");
    assertTrue(oec.isEmpty());
}
Also used : User(org.asqatasun.webapp.entity.user.User) OptionElement(org.asqatasun.webapp.entity.option.OptionElement)

Example 14 with User

use of org.asqatasun.webapp.entity.user.User in project Asqatasun by Asqatasun.

the class UserDAOImpl method isAccountActivated.

@Override
public boolean isAccountActivated(String email) {
    Query query = entityManager.createQuery("SELECT u FROM " + getEntityClass().getName() + " u" + " WHERE u.email = :email");
    query.setParameter("email", email);
    try {
        return ((User) query.getSingleResult()).isAccountActivated();
    } catch (NoResultException e) {
        return false;
    }
}
Also used : User(org.asqatasun.webapp.entity.user.User) Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Example 15 with User

use of org.asqatasun.webapp.entity.user.User in project Asqatasun by Asqatasun.

the class UserDAOImpl method read.

@Override
public User read(Long key) {
    if (key == null) {
        return null;
    }
    Query query = entityManager.createQuery("SELECT u FROM " + getEntityClass().getName() + " u" + " left join fetch u.contractSet c" + " WHERE u.id = :id");
    query.setParameter("id", key);
    try {
        return (User) query.getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}
Also used : User(org.asqatasun.webapp.entity.user.User) Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Aggregations

User (org.asqatasun.webapp.entity.user.User)15 NoResultException (javax.persistence.NoResultException)4 Query (javax.persistence.Query)4 ForbiddenUserException (org.asqatasun.webapp.exception.ForbiddenUserException)3 Secured (org.springframework.security.access.annotation.Secured)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 OptionElement (org.asqatasun.webapp.entity.option.OptionElement)1