Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: interfaces/business-logic-interfaces/src/main/java/net/adjudica/interfaces/logic/UserService.java
- ===================================================================
- --- interfaces/business-logic-interfaces/src/main/java/net/adjudica/interfaces/logic/UserService.java (revision 821)
- +++ interfaces/business-logic-interfaces/src/main/java/net/adjudica/interfaces/logic/UserService.java (working copy)
- @@ -14,9 +14,10 @@
- User findByAuthentication(String principal, String password);
- - User registerUser(Serializable registrarUserId, String username,
- - String email, String firstName, String lastName,
- - String subscriberMemberIdentifier);
- + User registerUser(Serializable registrarUserId, String username, String firstName,
- + String lastName, String employeeId, Serializable locationId,
- + String address, String city, String state, String zipCode,
- + String email, String intranetUsername, List<Serializable> roleIds);
- boolean isAcceptablePassword(String password);
- Index: interfaces/entity-interfaces/src/main/java/net/adjudica/interfaces/entity/dao/UserDao.java
- ===================================================================
- --- interfaces/entity-interfaces/src/main/java/net/adjudica/interfaces/entity/dao/UserDao.java (revision 821)
- +++ interfaces/entity-interfaces/src/main/java/net/adjudica/interfaces/entity/dao/UserDao.java (working copy)
- @@ -31,8 +31,11 @@
- /**
- * Persists a new user in the data source using the given parameters.
- */
- - User persistNewUser(String username, String email,
- - String plainTextPassword, String firstName, String lastName);
- + User persistNewUser(String username, String plainTextPassword,
- + String firstName, String lastName, String employeeId,
- + Serializable locationId, String address, String city, String state,
- + String zipCode, String email, String intranetUsername,
- + List<Serializable> roleIds);
- /**
- * Returns true if and only if there exists a <code>User</code> in the data
- Index: services/business-logic-services/src/test/java/net/adjudica/service/logic/SpringUserServiceTest.java
- ===================================================================
- --- services/business-logic-services/src/test/java/net/adjudica/service/logic/SpringUserServiceTest.java (revision 821)
- +++ services/business-logic-services/src/test/java/net/adjudica/service/logic/SpringUserServiceTest.java (working copy)
- @@ -1,5 +1,6 @@
- package net.adjudica.service.logic;
- +import java.io.Serializable;
- import java.util.*;
- import net.adjudica.interfaces.entity.*;
- @@ -32,10 +33,6 @@
- @Mock
- @Bean
- - private MemberDao memberDao;
- -
- - @Mock
- - @Bean
- private EmailService emailService;
- @Mock
- @@ -54,14 +51,22 @@
- final Long registrarUserId = 6L;
- final Long newUserId = 8L;
- final String username = "testUsername";
- - final String email = "testEmail@email.com";
- + final String password = "password";
- final String firstName = "first name";
- final String lastName = "last name";
- - final String subscriberMemberIdentifier = "12345";
- - final String password = "password";
- + final String employeeId = "101";
- + final Long locationId = 1L;
- + final String address = "1 Street";
- + final String city = "City";
- + final String state = "MO";
- + final String zipCode = "63130";
- + final String email = "testEmail@email.com";
- + final String intranetUsername = "foo";
- + final List<Serializable> roleIds = new LinkedList<Serializable>();
- + roleIds.add("10");
- +
- final User registrar = mock(User.class, "registrar");
- final User newUser = mock(User.class, "newUser");
- - final Member subscriber = mock(Member.class);
- expect(new Expectations(){
- {
- @@ -72,19 +77,14 @@
- one(userDao).findById(registrarUserId);
- will(returnValue(registrar));
- - one(userDao).persistNewUser(username, email, password,
- - firstName, lastName);
- + one(userDao).persistNewUser(username, password, firstName,
- + lastName, employeeId, locationId, address, city, state, zipCode,
- + email, intranetUsername, roleIds);
- will(returnValue(newUser));
- - one(memberDao).findByMemberIdentifier(
- - subscriberMemberIdentifier);
- - will(returnValue(subscriber));
- -
- - exactly(2).of(newUser).getId();
- + exactly(1).of(newUser).getId();
- will(returnValue(newUserId));
- - one(userDao).setSubscriber(newUserId, password, subscriber);
- -
- one(eventService).recordRegistration(with(any(Date.class)),
- with(equal(registrarUserId)), with(equal(newUserId)));
- @@ -96,6 +96,8 @@
- }
- });
- - userService.registerUser(registrarUserId, username, email, firstName, lastName, subscriberMemberIdentifier);
- + userService.registerUser(registrarUserId, username, firstName,
- + lastName, employeeId, locationId, address, city, state, zipCode,
- + email, intranetUsername, roleIds);
- }
- }
- Index: services/business-logic-services/src/main/java/net/adjudica/service/logic/SpringUserService.java
- ===================================================================
- --- services/business-logic-services/src/main/java/net/adjudica/service/logic/SpringUserService.java (revision 821)
- +++ services/business-logic-services/src/main/java/net/adjudica/service/logic/SpringUserService.java (working copy)
- @@ -69,35 +69,26 @@
- @Override
- public User registerUser(Serializable registrarUserId, String username,
- - String email, String firstName, String lastName,
- - String subscriberMemberIdentifier)
- + String firstName, String lastName, String employeeId,
- + Serializable locationId, String address, String city, String state,
- + String zipCode, String email, String intranetUsername,
- + List<Serializable> roleIds)
- {
- - username = StringUtils.trimToNull(username);
- - email = StringUtils.trimToNull(email);
- - firstName = StringUtils.trimToNull(firstName);
- - lastName = StringUtils.trimToNull(lastName);
- - subscriberMemberIdentifier = StringUtils
- - .trimToNull(subscriberMemberIdentifier);
- -
- String password = securityService.getRandomString(randomPasswordLength,
- System.currentTimeMillis());
- User registrar = userDao.findById(registrarUserId);
- - User newUser = userDao.persistNewUser(username, email, password,
- - firstName, lastName);
- + User newUser = userDao.persistNewUser(username, password, firstName,
- + lastName, employeeId, locationId, address, city, state, zipCode,
- + email, intranetUsername, roleIds);
- - if (StringUtils.isNotBlank(subscriberMemberIdentifier))
- + if (newUser != null)
- {
- - Member subscriber = memberDao
- - .findByMemberIdentifier(subscriberMemberIdentifier);
- + eventService.recordRegistration(new Date(), registrarUserId,
- + newUser.getId());
- - userDao.setSubscriber(newUser.getId(), password, subscriber);
- + sendRegistrationNotification(newUser, registrar, password);
- }
- -
- - eventService.recordRegistration(new Date(), registrarUserId, newUser
- - .getId());
- -
- - sendRegistrationNotification(newUser, registrar, password);
- -
- +
- return newUser;
- }
- @@ -194,10 +185,6 @@
- .getState(), user.getZipCode(), user.getEmail(), user
- .getIntranetUsername());
- - username = StringUtils.trimToNull(username);
- - email = StringUtils.trimToNull(email);
- - intranetUsername = StringUtils.trimToNull(intranetUsername);
- -
- User updatedUser = userDao.updatePersonalInformation(ServiceUtils
- .convertToLong(targetUserId), username, firstName, lastName,
- employeeId, ServiceUtils.convertToLong(locationId), address,
- Index: services/entity-services/src/main/java/net/adjudica/service/entity/JpaUser.java
- ===================================================================
- --- services/entity-services/src/main/java/net/adjudica/service/entity/JpaUser.java (revision 821)
- +++ services/entity-services/src/main/java/net/adjudica/service/entity/JpaUser.java (working copy)
- @@ -5,6 +5,8 @@
- import javax.annotation.*;
- import javax.persistence.*;
- +import org.apache.commons.lang.StringUtils;
- +
- import net.adjudica.interfaces.entity.*;
- import net.adjudica.service.entity.util.*;
- @@ -74,7 +76,7 @@
- private NotificationMethod notificationMethod;
- @Transient
- - private Member subscriber;
- + private Member subscriber;
- public Long getId()
- {
- @@ -93,7 +95,7 @@
- public void setEmail(String email)
- {
- - this.email = email;
- + this.email = StringUtils.trimToNull(email);
- }
- public List<Role> getRoles()
- @@ -113,7 +115,7 @@
- public void setEncryptedPassword(String encryptedPassword)
- {
- - this.encryptedPassword = encryptedPassword;
- + this.encryptedPassword = StringUtils.trimToNull(encryptedPassword);
- }
- public String getEncryptedPasswordSalt()
- @@ -123,7 +125,7 @@
- public void setEncryptedPasswordSalt(String encryptedPasswordSalt)
- {
- - this.encryptedPasswordSalt = encryptedPasswordSalt;
- + this.encryptedPasswordSalt = StringUtils.trimToNull(encryptedPasswordSalt);
- }
- public String getFirstName()
- @@ -133,7 +135,7 @@
- public void setFirstName(String firstName)
- {
- - this.firstName = firstName;
- + this.firstName = StringUtils.trimToNull(firstName);
- }
- public String getLastName()
- @@ -143,7 +145,7 @@
- public void setLastName(String lastName)
- {
- - this.lastName = lastName;
- + this.lastName = StringUtils.trimToNull(lastName);
- }
- public Member getSubscriber()
- @@ -158,7 +160,7 @@
- public void setUsername(String username)
- {
- - this.username = username;
- + this.username = StringUtils.trimToNull(username);
- }
- public String getUsername()
- @@ -178,7 +180,7 @@
- public void setEmployeeId(String employeeId)
- {
- - this.employeeId = employeeId;
- + this.employeeId = StringUtils.trimToNull(employeeId);
- }
- public String getEmployeeId()
- @@ -208,7 +210,7 @@
- public void setIntranetUsername(String intranetUsername)
- {
- - this.intranetUsername = intranetUsername;
- + this.intranetUsername = StringUtils.trimToNull(intranetUsername);
- }
- public String getActivationCode()
- @@ -218,7 +220,7 @@
- public void setActivationCode(String activationCode)
- {
- - this.activationCode = activationCode;
- + this.activationCode = StringUtils.trimToNull(activationCode);
- }
- public NotificationMethod getNotificationMethod()
- @@ -238,7 +240,7 @@
- public void setAddress(String address)
- {
- - this.address = address;
- + this.address = StringUtils.trimToNull(address);
- }
- public String getCity()
- @@ -248,7 +250,7 @@
- public void setCity(String city)
- {
- - this.city = city;
- + this.city = StringUtils.trimToNull(city);
- }
- public String getState()
- @@ -258,7 +260,7 @@
- public void setState(String state)
- {
- - this.state = state;
- + this.state = StringUtils.trimToNull(state);
- }
- public String getZipCode()
- @@ -268,6 +270,6 @@
- public void setZipCode(String zipCode)
- {
- - this.zipCode = zipCode;
- + this.zipCode = StringUtils.trimToNull(zipCode);
- }
- }
- Index: services/entity-services/src/main/java/net/adjudica/service/entity/dao/SpringUserDao.java
- ===================================================================
- --- services/entity-services/src/main/java/net/adjudica/service/entity/dao/SpringUserDao.java (revision 821)
- +++ services/entity-services/src/main/java/net/adjudica/service/entity/dao/SpringUserDao.java (working copy)
- @@ -4,6 +4,7 @@
- import java.util.*;
- import net.adjudica.interfaces.entity.*;
- +import net.adjudica.interfaces.entity.User.NotificationMethod;
- import net.adjudica.interfaces.entity.dao.*;
- import net.adjudica.interfaces.entity.util.*;
- import net.adjudica.service.entity.*;
- @@ -43,21 +44,35 @@
- }
- @Override
- - public User persistNewUser(String username, String email,
- - String plainTextPassword,
- - String firstName, String lastName)
- + public User persistNewUser(String username, String plainTextPassword,
- + String firstName, String lastName, String employeeId,
- + Serializable locationId, String address, String city, String state,
- + String zipCode, String email, String intranetUsername,
- + List<Serializable> roleIds)
- {
- JpaUser newUser = new JpaUser();
- - if (username == null)
- - username = email;
- + JpaLocation location = (JpaLocation) locationDao.findById(locationId);
- newUser.setUsername(username);
- - newUser.setEmail(email);
- newUser.setFirstName(firstName);
- newUser.setLastName(lastName);
- + newUser.setEmployeeId(employeeId);
- + newUser.setLocation(location);
- + newUser.setAddress(address);
- + newUser.setCity(city);
- + newUser.setState(state);
- + newUser.setZipCode(zipCode);
- + newUser.setEmail(email);
- + newUser.setIntranetUsername(intranetUsername);
- - createAndSetPassword(newUser, plainTextPassword, null);
- + List<Role> roles = roleDao.findByIds(roleIds);
- + newUser.setRoles(roles);
- +
- + // TODO: notification method throws a constraint error without this fix
- + newUser.setNotificationMethod(NotificationMethod.MESSAGE);
- +
- + newUser = createAndSetPassword(newUser, plainTextPassword, null);
- newUser = (JpaUser) merge(newUser);
- @@ -70,10 +85,10 @@
- {
- throw new RuntimeException("Unable to create ID for new user.");
- }
- -
- +
- return newUser;
- }
- -
- +
- @Override
- public User findByPrincipal(String principal)
- {
- @@ -203,8 +218,11 @@
- user.setEncryptedPassword(encryptedPassword);
- user.setEncryptedPasswordSalt(salt);
- +
- + System.out.printf("User: %s", user.toString());
- - persist(user);
- + if(user.getId() != null)
- + persist(user);
- if (subscriber != null)
- {
- Index: user-interface/src/main/java/net/adjudica/ui/controller/registrar/RegistrationController.java
- ===================================================================
- --- user-interface/src/main/java/net/adjudica/ui/controller/registrar/RegistrationController.java (revision 688)
- +++ user-interface/src/main/java/net/adjudica/ui/controller/registrar/RegistrationController.java (working copy)
- @@ -1,100 +0,0 @@
- -package net.adjudica.ui.controller.registrar;
- -
- -import javax.annotation.security.*;
- -
- -import net.adjudica.interfaces.entity.*;
- -import net.adjudica.interfaces.logic.*;
- -import net.adjudica.ui.form.*;
- -import net.adjudica.ui.service.*;
- -import net.adjudica.ui.service.validation.*;
- -import net.adjudica.ui.util.*;
- -
- -import org.apache.commons.lang.*;
- -import org.springframework.beans.factory.annotation.*;
- -import org.springframework.stereotype.*;
- -import org.springframework.ui.*;
- -import org.springframework.validation.*;
- -import org.springframework.web.bind.annotation.*;
- -
- -@Controller
- -public class RegistrationController
- -{
- - private static final String VIEW_NAME = "ui/registrar/register.gsp";
- - private static final String BASE_URL = "register";
- -
- - private static final String MODEL_IS_MEMBER_IDENTIFIER_TAKEN = "is_member_identifier_taken";
- -
- - @Autowired
- - SessionService sessionService;
- -
- - @Autowired
- - RegistrationValidationService validator;
- -
- - @Autowired
- - UserService userService;
- -
- - @Value("Unable to register new account.")
- - private String failureMessage;
- -
- - @ModelAttribute(PARAM.FORM)
- - public RegistrationForm populateForm(RegistrationForm form)
- - {
- - if (form == null)
- - {
- - return new RegistrationForm();
- - }
- -
- - return form;
- - }
- -
- - @RequestMapping(method = RequestMethod.GET, value = "/" + BASE_URL)
- - @RolesAllowed(ROLE.REGISTRAR)
- - public String view()
- - {
- - return VIEW_NAME;
- - }
- -
- - @RequestMapping(method = RequestMethod.POST, value = "/" + BASE_URL)
- - @RolesAllowed(ROLE.REGISTRAR)
- - public String submit(@ModelAttribute(PARAM.FORM) RegistrationForm form,
- - BindingResult result, ModelMap model)
- - {
- - validator.validate(result);
- -
- - if (!result.hasErrors())
- - {
- - if (register(form))
- - {
- - model.addAttribute(PARAM.SUCCESS, "true");
- - return ControllerUtils.getSuccessViewName(BASE_URL);
- - }
- - else
- - {
- - result.reject(failureMessage);
- - }
- - }
- -
- - boolean isMemberIdentifierTaken = ControllerUtils.isErrorCodePresent(
- - UserValidationService.MEMBER_IDENTIFIER_TAKEN, result);
- -
- - model.addAttribute(PARAM.RESULT, result);
- - model.addAttribute(MODEL_IS_MEMBER_IDENTIFIER_TAKEN,
- - isMemberIdentifierTaken);
- -
- - return VIEW_NAME;
- - }
- -
- - private boolean register(RegistrationForm form)
- - {
- - String email = form.getEmail();
- -
- - if (StringUtils.isBlank(email))
- - email = null;
- -
- - User result = userService.registerUser(sessionService.getUserId(), form
- - .getUsername(), form.getEmail(), form.getFirstName(), form
- - .getLastName(), form.getMemberIdentifier());
- -
- - return result != null;
- - }
- -}
- Index: user-interface/src/main/java/net/adjudica/ui/controller/admin/UserAdminController.java
- ===================================================================
- --- user-interface/src/main/java/net/adjudica/ui/controller/admin/UserAdminController.java (revision 821)
- +++ user-interface/src/main/java/net/adjudica/ui/controller/admin/UserAdminController.java (working copy)
- @@ -196,15 +196,8 @@
- }
- else if (TAB_SECURITY.equals(tab))
- {
- - // TODO: change the checkbox naming scheme
- - List<Serializable> roles = new LinkedList<Serializable>();
- - for(Entry <String,String> role : parameters.entrySet())
- - {
- - if(role.getKey().endsWith("checkbox"))
- - roles.add(role.getValue());
- - }
- -
- - User user = userService.updateRoles(userId, roles);
- + User user = userService.updateRoles(userId,
- + getRolesFromParameters(parameters));
- if (user == null)
- throw new RuntimeException("Failed to update user " + userId);
- @@ -213,6 +206,41 @@
- return problems;
- }
- +
- + @RequestMapping(method = RequestMethod.POST, value = "/users/new")
- + @RolesAllowed(ROLE.REGISTRAR)
- + public @ResponseBody Map<String, String> register(
- + HttpServletRequest request)
- + {
- + Map<String, String> parameters = RequestUtils.getParameterMap(request);
- + Map<String, String> problems = validationService.validate(parameters);
- +
- + if (problems.isEmpty())
- + {
- + String username = parameters.get(PARAM.USERNAME);
- + String firstName = parameters.get(PARAM.FIRST_NAME);
- + String lastName = parameters.get(PARAM.LAST_NAME);
- + String employeeId = parameters.get(PARAM.EMPLOYEE_ID);
- + String locationId = parameters.get(PARAM.LOCATION_ID);
- + String address = parameters.get(PARAM.ADDRESS);
- + String city = parameters.get(PARAM.CITY);
- + String state = parameters.get(PARAM.STATE);
- + String zipCode = parameters.get(PARAM.ZIP_CODE);
- + String email = parameters.get(PARAM.EMAIL);
- + String intranetUsername = parameters.get(PARAM.INTRANET_USERNAME);
- + List<Serializable> roleIds = getRolesFromParameters(parameters);
- +
- + User user = userService.registerUser(sessionService.getUserId(),
- + username, firstName, lastName, employeeId, Long.decode(locationId),
- + address, city, state, zipCode, email, intranetUsername, roleIds);
- +
- + if (user == null)
- + throw new RuntimeException("Failed to register new user : " + username);
- + }
- +
- + return problems;
- + }
- +
- private void populate(ModelMap model, Long userId)
- {
- @@ -274,5 +302,18 @@
- if (user == null)
- throw new RuntimeException("Failed to update user " + userId);
- - }
- + }
- +
- + private List<Serializable> getRolesFromParameters(
- + Map<String, String> parameters)
- + {
- + // TODO: change the checkbox naming scheme
- + List<Serializable> roles = new LinkedList<Serializable>();
- + for (Entry<String, String> role : parameters.entrySet())
- + {
- + if (role.getKey().endsWith("checkbox"))
- + roles.add(role.getValue());
- + }
- + return roles;
- + }
- }
Add Comment
Please, Sign In to add comment