Search in sources :

Example 21 with User

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

the class UserDAO method findUserFromName.

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

Example 22 with User

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

the class UserDAO method read.

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.entity.user.User) Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Example 23 with User

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

the class UserDAO method findUserFromEmail.

public User findUserFromEmail(String email) {
    Query query = entityManager.createQuery("SELECT u FROM " + getEntityClass().getName() + " u" + " left join fetch u.contractSet c" + // + " left join fetch c.actSet a"
    " WHERE u.email = :email");
    query.setParameter("email", email);
    try {
        return (User) query.getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}
Also used : User(org.asqatasun.entity.user.User) Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Example 24 with User

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

the class PageListControllerTest method setUpMockUserDataService.

/**
 * Create a user with Id=1, email=test1@test.com and empty name and first name
 */
private void setUpMockUserDataService() {
    mockUser = new User();
    mockUser.setId(1L);
    mockUser.setEmail1("test1@test.com");
    mockUser.setName("");
    mockUser.setFirstName("");
}
Also used : User(org.asqatasun.entity.user.User)

Example 25 with User

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

the class UserManagementControllerTest method testSubmitEditUserForm.

/**
 * Test of submitEditUserForm method, of class UserManagementController.
 */
@Test
public void testSubmitEditUserForm() throws Exception {
    setUpMockRoleDataService();
    setUpMockUserDataService(false, true, false);
    setUpMockAuthenticationContext();
    // Finally the form is conform and the admin page is returned
    CreateUserCommand createUserCommand = createUserCommandFactory.getNewCreateUserCommand();
    createUserCommand.setEmail("user@test.com");
    createUserCommand.setLastName("newName");
    createUserCommand.setFirstName("newFirstName");
    createUserCommand.setPhoneNumber("0102030405");
    createUserCommand.setActivated(false);
    createUserCommand.setAdmin(true);
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.getSession().setAttribute(TgolKeyStore.USER_ID_KEY, 5L);
    BindingResult bindingResult = new BeanPropertyBindingResult(createUserCommand, "createUserCommand");
    Model model = new ExtendedModelMap();
    String result = instance.submitEditUserForm(createUserCommand, bindingResult, request, model);
    assertEquals(TgolKeyStore.ADMIN_VIEW_NAME, result);
    assertFalse(bindingResult.hasErrors());
    assertTrue(bindingResult.getFieldErrors().isEmpty());
    assertEquals(2, model.asMap().size());
    assertEquals("user@test.com", model.asMap().get(TgolKeyStore.UPDATED_USER_NAME_KEY));
    assertTrue(((List<User>) model.asMap().get(TgolKeyStore.USER_LIST_KEY)).isEmpty());
}
Also used : BindingResult(org.springframework.validation.BindingResult) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) User(org.asqatasun.entity.user.User) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Model(org.springframework.ui.Model) CreateUserCommand(org.asqatasun.webapp.command.CreateUserCommand) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

User (org.asqatasun.entity.user.User)40 Secured (org.springframework.security.access.annotation.Secured)14 ForbiddenUserException (org.asqatasun.webapp.exception.ForbiddenUserException)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 Contract (org.asqatasun.entity.contract.Contract)5 ForbiddenPageException (org.asqatasun.webapp.exception.ForbiddenPageException)5 Test (org.junit.Test)5 NoResultException (javax.persistence.NoResultException)4 Query (javax.persistence.Query)4 CreateUserCommand (org.asqatasun.webapp.command.CreateUserCommand)4 Test (org.junit.jupiter.api.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 ExtendedModelMap (org.springframework.ui.ExtendedModelMap)4 Model (org.springframework.ui.Model)4 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)4 BindingResult (org.springframework.validation.BindingResult)4 List (java.util.List)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 ArrayList (java.util.ArrayList)1 OptionElement (org.asqatasun.entity.option.OptionElement)1