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;
}
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;
}
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());
}
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());
}
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);
}
}
Aggregations