Search in sources :

Example 11 with CreateUserCommand

use of org.asqatasun.webapp.command.CreateUserCommand in project Asqatasun by Asqatasun.

the class AbstractUserAndContractsController method prepateDataAndReturnCreateUserView.

/**
     * 
     * @param model
     * @param user
     * @param successViewName
     * @return 
     */
protected String prepateDataAndReturnCreateUserView(Model model, User user, String successViewName) {
    CreateUserCommand createUserCommand;
    if (user != null) {
        createUserCommand = CreateUserCommandFactory.getInstance().getInitialisedCreateUserCommand(user);
        model.addAttribute(TgolKeyStore.USER_NAME_KEY, createUserCommand.getEmail());
    } else {
        createUserCommand = CreateUserCommandFactory.getInstance().getNewCreateUserCommand();
    }
    model.addAttribute(TgolKeyStore.CREATE_USER_COMMAND_KEY, createUserCommand);
    return successViewName;
}
Also used : CreateUserCommand(org.asqatasun.webapp.command.CreateUserCommand)

Example 12 with CreateUserCommand

use of org.asqatasun.webapp.command.CreateUserCommand in project Asqatasun by Asqatasun.

the class CreateUserCommandFactory method getInitialisedCreateUserCommand.

public CreateUserCommand getInitialisedCreateUserCommand(User user) {
    CreateUserCommand createUserCommand = new CreateUserCommand();
    createUserCommand.setEmail(user.getEmail1());
    createUserCommand.setSiteUrl(user.getWebUrl1());
    createUserCommand.setFirstName(user.getFirstName());
    createUserCommand.setLastName(user.getName());
    createUserCommand.setPhoneNumber(user.getPhoneNumber());
    createUserCommand.setActivated(user.isAccountActivated());
    if (user.getRole().getId().equals(adminRole.getId())) {
        createUserCommand.setAdmin(true);
    } else {
        createUserCommand.setAdmin(false);
    }
    createUserCommand.setActivated(user.isAccountActivated());
    return createUserCommand;
}
Also used : CreateUserCommand(org.asqatasun.webapp.command.CreateUserCommand)

Example 13 with CreateUserCommand

use of org.asqatasun.webapp.command.CreateUserCommand in project Asqatasun by Asqatasun.

the class UserManagementControllerTest method testAddUserAdminPage.

/**
     * Test of addUserAdminPage method, of class UserManagementController.
     */
public void testAddUserAdminPage() {
    System.out.println("addUserAdminPage");
    instance = new UserManagementController();
    setUpMockRoleDataService();
    setUpMockUserDataService(false, false, false, false, false);
    setUpMockAuthenticationContext();
    instance.setUserDataService(mockUserDataService);
    HttpServletResponse response = new MockHttpServletResponse();
    MockHttpServletRequest request = new MockHttpServletRequest();
    Model model = new ExtendedModelMap();
    String result = instance.displayAddUserAdminPage(request, response, model);
    assertEquals(TgolKeyStore.ADD_USER_VIEW_NAME, result);
    assertEquals(1, model.asMap().size());
    CreateUserCommand cuc = ((CreateUserCommand) model.asMap().get(TgolKeyStore.CREATE_USER_COMMAND_KEY));
    assertNotNull(cuc);
    assertFalse(cuc.getActivated());
    assertFalse(cuc.getAdmin());
    assertNull(cuc.getEmail());
    assertEquals("http://", cuc.getSiteUrl());
    assertNull(cuc.getPhoneNumber());
    assertNull(cuc.getLastName());
    assertNull(cuc.getFirstName());
    assertNull(cuc.getPassword());
    assertNull(cuc.getConfirmPassword());
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Model(org.springframework.ui.Model) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) CreateUserCommand(org.asqatasun.webapp.command.CreateUserCommand)

Example 14 with CreateUserCommand

use of org.asqatasun.webapp.command.CreateUserCommand in project Asqatasun by Asqatasun.

the class UserManagementControllerTest method testSubmitEditUserForm.

/**
     * Test of submitEditUserForm method, of class UserManagementController.
     */
public void testSubmitEditUserForm() throws Exception {
    System.out.println("submitEditUserForm");
    instance = new UserManagementController();
    setUpMockRoleDataService();
    setUpMockUserDataService(false, false, false, true, false);
    setUpMockAuthenticationContext();
    instance.setUserDataService(mockUserDataService);
    CreateUserFormValidator createUserFormValidator = new CreateUserFormValidator();
    createUserFormValidator.setUserDataService(mockUserDataService);
    instance.setCreateUserFormValidator(createUserFormValidator);
    // Finally the form is conform and the admin page is returned
    CreateUserCommand createUserCommand = CreateUserCommandFactory.getInstance().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, Long.valueOf(5));
    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.webapp.entity.user.User) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Model(org.springframework.ui.Model) CreateUserFormValidator(org.asqatasun.webapp.validator.CreateUserFormValidator) CreateUserCommand(org.asqatasun.webapp.command.CreateUserCommand)

Example 15 with CreateUserCommand

use of org.asqatasun.webapp.command.CreateUserCommand in project Asqatasun by Asqatasun.

the class CreateUserFormValidator method validate.

@Override
public void validate(Object target, Errors errors) {
    boolean hasMandatoryElementWrong = false;
    CreateUserCommand userSubscriptionCommand = (CreateUserCommand) target;
    if (!checkSiteUrl(userSubscriptionCommand, errors)) {
        hasMandatoryElementWrong = true;
    }
    if (!checkEmail(userSubscriptionCommand, errors)) {
        hasMandatoryElementWrong = true;
    }
    if (!checkPassword(userSubscriptionCommand, errors)) {
        hasMandatoryElementWrong = true;
    }
    //        }
    if (hasMandatoryElementWrong) {
        // if no URL is filled-in
        errors.rejectValue(GENERAL_ERROR_MSG_KEY, MANDATORY_FIELD_MSG_BUNDLE_KEY);
    }
}
Also used : CreateUserCommand(org.asqatasun.webapp.command.CreateUserCommand)

Aggregations

CreateUserCommand (org.asqatasun.webapp.command.CreateUserCommand)16 ExtendedModelMap (org.springframework.ui.ExtendedModelMap)10 Model (org.springframework.ui.Model)10 CreateUserFormValidator (org.asqatasun.webapp.validator.CreateUserFormValidator)6 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)6 BindingResult (org.springframework.validation.BindingResult)6 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 User (org.asqatasun.webapp.entity.user.User)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 ForbiddenUserException (org.asqatasun.webapp.exception.ForbiddenUserException)1