SHARE
TWEET

Untitled

a guest May 22nd, 2018 248 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Index: interfaces/business-logic-interfaces/src/main/java/net/adjudica/interfaces/logic/UserService.java
  2. ===================================================================
  3. --- interfaces/business-logic-interfaces/src/main/java/net/adjudica/interfaces/logic/UserService.java   (revision 821)
  4. +++ interfaces/business-logic-interfaces/src/main/java/net/adjudica/interfaces/logic/UserService.java   (working copy)
  5. @@ -14,9 +14,10 @@
  6.  
  7.     User findByAuthentication(String principal, String password);
  8.  
  9. -   User registerUser(Serializable registrarUserId, String username,
  10. -           String email, String firstName, String lastName,
  11. -           String subscriberMemberIdentifier);
  12. +   User registerUser(Serializable registrarUserId, String username, String firstName,
  13. +           String lastName, String employeeId, Serializable locationId,
  14. +           String address, String city, String state, String zipCode,
  15. +           String email, String intranetUsername, List<Serializable> roleIds);
  16.  
  17.     boolean isAcceptablePassword(String password);
  18.  
  19. Index: interfaces/entity-interfaces/src/main/java/net/adjudica/interfaces/entity/dao/UserDao.java
  20. ===================================================================
  21. --- interfaces/entity-interfaces/src/main/java/net/adjudica/interfaces/entity/dao/UserDao.java  (revision 821)
  22. +++ interfaces/entity-interfaces/src/main/java/net/adjudica/interfaces/entity/dao/UserDao.java  (working copy)
  23. @@ -31,8 +31,11 @@
  24.     /**
  25.      * Persists a new user in the data source using the given parameters.
  26.      */
  27. -   User persistNewUser(String username, String email,
  28. -           String plainTextPassword, String firstName, String lastName);
  29. +   User persistNewUser(String username, String plainTextPassword,
  30. +           String firstName, String lastName, String employeeId,
  31. +           Serializable locationId, String address, String city, String state,
  32. +           String zipCode, String email, String intranetUsername,
  33. +           List<Serializable> roleIds);
  34.  
  35.     /**
  36.      * Returns true if and only if there exists a <code>User</code> in the data
  37. Index: services/business-logic-services/src/test/java/net/adjudica/service/logic/SpringUserServiceTest.java
  38. ===================================================================
  39. --- services/business-logic-services/src/test/java/net/adjudica/service/logic/SpringUserServiceTest.java    (revision 821)
  40. +++ services/business-logic-services/src/test/java/net/adjudica/service/logic/SpringUserServiceTest.java    (working copy)
  41. @@ -1,5 +1,6 @@
  42.  package net.adjudica.service.logic;
  43.  
  44. +import java.io.Serializable;
  45.  import java.util.*;
  46.  
  47.  import net.adjudica.interfaces.entity.*;
  48. @@ -32,10 +33,6 @@
  49.  
  50.     @Mock
  51.     @Bean
  52. -   private MemberDao memberDao;
  53. -
  54. -   @Mock
  55. -   @Bean
  56.     private EmailService emailService;
  57.  
  58.     @Mock
  59. @@ -54,14 +51,22 @@
  60.         final Long registrarUserId = 6L;
  61.         final Long newUserId = 8L;
  62.         final String username = "testUsername";
  63. -       final String email = "testEmail@email.com";
  64. +       final String password = "password";
  65.         final String firstName = "first name";
  66.         final String lastName = "last name";
  67. -       final String subscriberMemberIdentifier = "12345";
  68. -       final String password = "password";
  69. +       final String employeeId = "101";
  70. +       final Long locationId = 1L;
  71. +       final String address = "1 Street";
  72. +       final String city = "City";
  73. +       final String state = "MO";
  74. +       final String zipCode = "63130";
  75. +       final String email = "testEmail@email.com";
  76. +       final String intranetUsername = "foo";
  77. +       final List<Serializable> roleIds = new LinkedList<Serializable>();
  78. +       roleIds.add("10");
  79. +      
  80.         final User registrar = mock(User.class, "registrar");
  81.         final User newUser = mock(User.class, "newUser");
  82. -       final Member subscriber = mock(Member.class);
  83.        
  84.         expect(new Expectations(){
  85.             {
  86. @@ -72,19 +77,14 @@
  87.                 one(userDao).findById(registrarUserId);
  88.                 will(returnValue(registrar));
  89.  
  90. -               one(userDao).persistNewUser(username, email, password,
  91. -                       firstName, lastName);
  92. +               one(userDao).persistNewUser(username, password, firstName,
  93. +                   lastName, employeeId, locationId, address, city, state, zipCode,
  94. +                   email, intranetUsername, roleIds);
  95.                 will(returnValue(newUser));
  96.  
  97. -               one(memberDao).findByMemberIdentifier(
  98. -                       subscriberMemberIdentifier);
  99. -               will(returnValue(subscriber));
  100. -
  101. -               exactly(2).of(newUser).getId();
  102. +               exactly(1).of(newUser).getId();
  103.                 will(returnValue(newUserId));
  104.  
  105. -               one(userDao).setSubscriber(newUserId, password, subscriber);
  106. -
  107.                 one(eventService).recordRegistration(with(any(Date.class)),
  108.                         with(equal(registrarUserId)), with(equal(newUserId)));
  109.  
  110. @@ -96,6 +96,8 @@
  111.             }
  112.         });
  113.        
  114. -       userService.registerUser(registrarUserId, username, email, firstName, lastName, subscriberMemberIdentifier);
  115. +       userService.registerUser(registrarUserId, username, firstName,
  116. +           lastName, employeeId, locationId, address, city, state, zipCode,
  117. +           email, intranetUsername, roleIds);
  118.     }
  119.  }
  120. Index: services/business-logic-services/src/main/java/net/adjudica/service/logic/SpringUserService.java
  121. ===================================================================
  122. --- services/business-logic-services/src/main/java/net/adjudica/service/logic/SpringUserService.java    (revision 821)
  123. +++ services/business-logic-services/src/main/java/net/adjudica/service/logic/SpringUserService.java    (working copy)
  124. @@ -69,35 +69,26 @@
  125.  
  126.     @Override
  127.     public User registerUser(Serializable registrarUserId, String username,
  128. -       String email, String firstName, String lastName,
  129. -       String subscriberMemberIdentifier)
  130. +           String firstName, String lastName, String employeeId,
  131. +           Serializable locationId, String address, String city, String state,
  132. +           String zipCode, String email, String intranetUsername,
  133. +           List<Serializable> roleIds)
  134.     {
  135. -       username = StringUtils.trimToNull(username);
  136. -       email = StringUtils.trimToNull(email);
  137. -       firstName = StringUtils.trimToNull(firstName);
  138. -       lastName = StringUtils.trimToNull(lastName);
  139. -       subscriberMemberIdentifier = StringUtils
  140. -               .trimToNull(subscriberMemberIdentifier);
  141. -
  142.         String password = securityService.getRandomString(randomPasswordLength,
  143.                 System.currentTimeMillis());
  144.         User registrar = userDao.findById(registrarUserId);
  145. -       User newUser = userDao.persistNewUser(username, email, password,
  146. -               firstName, lastName);
  147. +       User newUser = userDao.persistNewUser(username, password, firstName,
  148. +           lastName, employeeId, locationId, address, city, state, zipCode,
  149. +           email, intranetUsername, roleIds);
  150.  
  151. -       if (StringUtils.isNotBlank(subscriberMemberIdentifier))
  152. +       if (newUser != null)
  153.         {
  154. -           Member subscriber = memberDao
  155. -                   .findByMemberIdentifier(subscriberMemberIdentifier);
  156. +           eventService.recordRegistration(new Date(), registrarUserId,
  157. +               newUser.getId());
  158.  
  159. -           userDao.setSubscriber(newUser.getId(), password, subscriber);
  160. +           sendRegistrationNotification(newUser, registrar, password);
  161.         }
  162. -
  163. -       eventService.recordRegistration(new Date(), registrarUserId, newUser
  164. -               .getId());
  165. -
  166. -       sendRegistrationNotification(newUser, registrar, password);
  167. -
  168. +      
  169.         return newUser;
  170.     }
  171.  
  172. @@ -194,10 +185,6 @@
  173.                 .getState(), user.getZipCode(), user.getEmail(), user
  174.                 .getIntranetUsername());
  175.  
  176. -       username = StringUtils.trimToNull(username);
  177. -       email = StringUtils.trimToNull(email);
  178. -       intranetUsername = StringUtils.trimToNull(intranetUsername);
  179. -
  180.         User updatedUser = userDao.updatePersonalInformation(ServiceUtils
  181.                 .convertToLong(targetUserId), username, firstName, lastName,
  182.                 employeeId, ServiceUtils.convertToLong(locationId), address,
  183. Index: services/entity-services/src/main/java/net/adjudica/service/entity/JpaUser.java
  184. ===================================================================
  185. --- services/entity-services/src/main/java/net/adjudica/service/entity/JpaUser.java (revision 821)
  186. +++ services/entity-services/src/main/java/net/adjudica/service/entity/JpaUser.java (working copy)
  187. @@ -5,6 +5,8 @@
  188.  import javax.annotation.*;
  189.  import javax.persistence.*;
  190.  
  191. +import org.apache.commons.lang.StringUtils;
  192. +
  193.  import net.adjudica.interfaces.entity.*;
  194.  import net.adjudica.service.entity.util.*;
  195.  
  196. @@ -74,7 +76,7 @@
  197.     private NotificationMethod notificationMethod;
  198.    
  199.     @Transient
  200. -   private Member subscriber; 
  201. +   private Member subscriber;
  202.  
  203.     public Long getId()
  204.     {
  205. @@ -93,7 +95,7 @@
  206.  
  207.     public void setEmail(String email)
  208.     {
  209. -       this.email = email;
  210. +       this.email = StringUtils.trimToNull(email);
  211.     }
  212.  
  213.     public List<Role> getRoles()
  214. @@ -113,7 +115,7 @@
  215.  
  216.     public void setEncryptedPassword(String encryptedPassword)
  217.     {
  218. -       this.encryptedPassword = encryptedPassword;
  219. +       this.encryptedPassword = StringUtils.trimToNull(encryptedPassword);
  220.     }
  221.  
  222.     public String getEncryptedPasswordSalt()
  223. @@ -123,7 +125,7 @@
  224.  
  225.     public void setEncryptedPasswordSalt(String encryptedPasswordSalt)
  226.     {
  227. -       this.encryptedPasswordSalt = encryptedPasswordSalt;
  228. +       this.encryptedPasswordSalt = StringUtils.trimToNull(encryptedPasswordSalt);
  229.     }
  230.  
  231.     public String getFirstName()
  232. @@ -133,7 +135,7 @@
  233.  
  234.     public void setFirstName(String firstName)
  235.     {
  236. -       this.firstName = firstName;
  237. +       this.firstName = StringUtils.trimToNull(firstName);
  238.     }
  239.  
  240.     public String getLastName()
  241. @@ -143,7 +145,7 @@
  242.  
  243.     public void setLastName(String lastName)
  244.     {
  245. -       this.lastName = lastName;
  246. +       this.lastName = StringUtils.trimToNull(lastName);
  247.     }
  248.  
  249.     public Member getSubscriber()
  250. @@ -158,7 +160,7 @@
  251.  
  252.     public void setUsername(String username)
  253.     {
  254. -       this.username = username;
  255. +       this.username = StringUtils.trimToNull(username);
  256.     }
  257.  
  258.     public String getUsername()
  259. @@ -178,7 +180,7 @@
  260.  
  261.     public void setEmployeeId(String employeeId)
  262.     {
  263. -       this.employeeId = employeeId;
  264. +       this.employeeId = StringUtils.trimToNull(employeeId);
  265.     }
  266.  
  267.     public String getEmployeeId()
  268. @@ -208,7 +210,7 @@
  269.  
  270.     public void setIntranetUsername(String intranetUsername)
  271.     {
  272. -       this.intranetUsername = intranetUsername;
  273. +       this.intranetUsername = StringUtils.trimToNull(intranetUsername);
  274.     }
  275.  
  276.     public String getActivationCode()
  277. @@ -218,7 +220,7 @@
  278.  
  279.     public void setActivationCode(String activationCode)
  280.     {
  281. -       this.activationCode = activationCode;
  282. +       this.activationCode = StringUtils.trimToNull(activationCode);
  283.     }
  284.  
  285.     public NotificationMethod getNotificationMethod()
  286. @@ -238,7 +240,7 @@
  287.  
  288.     public void setAddress(String address)
  289.     {
  290. -       this.address = address;
  291. +       this.address = StringUtils.trimToNull(address);
  292.     }
  293.  
  294.     public String getCity()
  295. @@ -248,7 +250,7 @@
  296.  
  297.     public void setCity(String city)
  298.     {
  299. -       this.city = city;
  300. +       this.city = StringUtils.trimToNull(city);
  301.     }
  302.  
  303.     public String getState()
  304. @@ -258,7 +260,7 @@
  305.  
  306.     public void setState(String state)
  307.     {
  308. -       this.state = state;
  309. +       this.state = StringUtils.trimToNull(state);
  310.     }
  311.  
  312.     public String getZipCode()
  313. @@ -268,6 +270,6 @@
  314.  
  315.     public void setZipCode(String zipCode)
  316.     {
  317. -       this.zipCode = zipCode;
  318. +       this.zipCode = StringUtils.trimToNull(zipCode);
  319.     }
  320.  }
  321. Index: services/entity-services/src/main/java/net/adjudica/service/entity/dao/SpringUserDao.java
  322. ===================================================================
  323. --- services/entity-services/src/main/java/net/adjudica/service/entity/dao/SpringUserDao.java   (revision 821)
  324. +++ services/entity-services/src/main/java/net/adjudica/service/entity/dao/SpringUserDao.java   (working copy)
  325. @@ -4,6 +4,7 @@
  326.  import java.util.*;
  327.  
  328.  import net.adjudica.interfaces.entity.*;
  329. +import net.adjudica.interfaces.entity.User.NotificationMethod;
  330.  import net.adjudica.interfaces.entity.dao.*;
  331.  import net.adjudica.interfaces.entity.util.*;
  332.  import net.adjudica.service.entity.*;
  333. @@ -43,21 +44,35 @@
  334.     }
  335.  
  336.     @Override
  337. -   public User persistNewUser(String username, String email,
  338. -           String plainTextPassword,
  339. -           String firstName, String lastName)
  340. +   public User persistNewUser(String username, String plainTextPassword,
  341. +           String firstName, String lastName, String employeeId,
  342. +           Serializable locationId, String address, String city, String state,
  343. +           String zipCode, String email, String intranetUsername,
  344. +           List<Serializable> roleIds)
  345.     {
  346.         JpaUser newUser = new JpaUser();
  347.  
  348. -       if (username == null)
  349. -           username = email;
  350. +       JpaLocation location = (JpaLocation) locationDao.findById(locationId);
  351.  
  352.         newUser.setUsername(username);
  353. -       newUser.setEmail(email);
  354.         newUser.setFirstName(firstName);
  355.         newUser.setLastName(lastName);
  356. +       newUser.setEmployeeId(employeeId);
  357. +       newUser.setLocation(location);
  358. +       newUser.setAddress(address);
  359. +       newUser.setCity(city);
  360. +       newUser.setState(state);
  361. +       newUser.setZipCode(zipCode);
  362. +       newUser.setEmail(email);
  363. +       newUser.setIntranetUsername(intranetUsername);
  364.  
  365. -       createAndSetPassword(newUser, plainTextPassword, null);
  366. +       List<Role> roles = roleDao.findByIds(roleIds);
  367. +       newUser.setRoles(roles);
  368. +      
  369. +       // TODO: notification method throws a constraint error without this fix
  370. +       newUser.setNotificationMethod(NotificationMethod.MESSAGE);
  371. +      
  372. +       newUser = createAndSetPassword(newUser, plainTextPassword, null);
  373.  
  374.         newUser = (JpaUser) merge(newUser);
  375.  
  376. @@ -70,10 +85,10 @@
  377.         {
  378.             throw new RuntimeException("Unable to create ID for new user.");
  379.         }
  380. -
  381. +      
  382.         return newUser;
  383.     }
  384. -
  385. +  
  386.     @Override
  387.     public User findByPrincipal(String principal)
  388.     {
  389. @@ -203,8 +218,11 @@
  390.  
  391.         user.setEncryptedPassword(encryptedPassword);
  392.         user.setEncryptedPasswordSalt(salt);
  393. +  
  394. +       System.out.printf("User: %s", user.toString());
  395.        
  396. -       persist(user);
  397. +       if(user.getId() != null)
  398. +           persist(user);
  399.  
  400.         if (subscriber != null)
  401.         {
  402. Index: user-interface/src/main/java/net/adjudica/ui/controller/registrar/RegistrationController.java
  403. ===================================================================
  404. --- user-interface/src/main/java/net/adjudica/ui/controller/registrar/RegistrationController.java   (revision 688)
  405. +++ user-interface/src/main/java/net/adjudica/ui/controller/registrar/RegistrationController.java   (working copy)
  406. @@ -1,100 +0,0 @@
  407. -package net.adjudica.ui.controller.registrar;
  408. -
  409. -import javax.annotation.security.*;
  410. -
  411. -import net.adjudica.interfaces.entity.*;
  412. -import net.adjudica.interfaces.logic.*;
  413. -import net.adjudica.ui.form.*;
  414. -import net.adjudica.ui.service.*;
  415. -import net.adjudica.ui.service.validation.*;
  416. -import net.adjudica.ui.util.*;
  417. -
  418. -import org.apache.commons.lang.*;
  419. -import org.springframework.beans.factory.annotation.*;
  420. -import org.springframework.stereotype.*;
  421. -import org.springframework.ui.*;
  422. -import org.springframework.validation.*;
  423. -import org.springframework.web.bind.annotation.*;
  424. -
  425. -@Controller
  426. -public class RegistrationController
  427. -{
  428. -   private static final String VIEW_NAME = "ui/registrar/register.gsp";
  429. -   private static final String BASE_URL = "register";
  430. -
  431. -   private static final String MODEL_IS_MEMBER_IDENTIFIER_TAKEN = "is_member_identifier_taken";
  432. -
  433. -   @Autowired
  434. -   SessionService sessionService;
  435. -
  436. -   @Autowired
  437. -   RegistrationValidationService validator;
  438. -
  439. -   @Autowired
  440. -   UserService userService;
  441. -
  442. -   @Value("Unable to register new account.")
  443. -   private String failureMessage;
  444. -
  445. -   @ModelAttribute(PARAM.FORM)
  446. -   public RegistrationForm populateForm(RegistrationForm form)
  447. -   {
  448. -       if (form == null)
  449. -       {
  450. -           return new RegistrationForm();
  451. -       }
  452. -
  453. -       return form;
  454. -   }
  455. -
  456. -   @RequestMapping(method = RequestMethod.GET, value = "/" + BASE_URL)
  457. -   @RolesAllowed(ROLE.REGISTRAR)
  458. -   public String view()
  459. -   {
  460. -       return VIEW_NAME;
  461. -   }
  462. -
  463. -   @RequestMapping(method = RequestMethod.POST, value = "/" + BASE_URL)
  464. -   @RolesAllowed(ROLE.REGISTRAR)
  465. -   public String submit(@ModelAttribute(PARAM.FORM) RegistrationForm form,
  466. -           BindingResult result, ModelMap model)
  467. -   {
  468. -       validator.validate(result);
  469. -
  470. -       if (!result.hasErrors())
  471. -       {
  472. -           if (register(form))
  473. -           {
  474. -               model.addAttribute(PARAM.SUCCESS, "true");
  475. -               return ControllerUtils.getSuccessViewName(BASE_URL);
  476. -           }
  477. -           else
  478. -           {
  479. -               result.reject(failureMessage);
  480. -           }
  481. -       }
  482. -
  483. -       boolean isMemberIdentifierTaken = ControllerUtils.isErrorCodePresent(
  484. -               UserValidationService.MEMBER_IDENTIFIER_TAKEN, result);
  485. -
  486. -       model.addAttribute(PARAM.RESULT, result);
  487. -       model.addAttribute(MODEL_IS_MEMBER_IDENTIFIER_TAKEN,
  488. -               isMemberIdentifierTaken);
  489. -
  490. -       return VIEW_NAME;
  491. -   }
  492. -
  493. -   private boolean register(RegistrationForm form)
  494. -   {
  495. -       String email = form.getEmail();
  496. -
  497. -       if (StringUtils.isBlank(email))
  498. -           email = null;
  499. -
  500. -       User result = userService.registerUser(sessionService.getUserId(), form
  501. -               .getUsername(), form.getEmail(), form.getFirstName(), form
  502. -               .getLastName(), form.getMemberIdentifier());
  503. -
  504. -       return result != null;
  505. -   }
  506. -}
  507. Index: user-interface/src/main/java/net/adjudica/ui/controller/admin/UserAdminController.java
  508. ===================================================================
  509. --- user-interface/src/main/java/net/adjudica/ui/controller/admin/UserAdminController.java  (revision 821)
  510. +++ user-interface/src/main/java/net/adjudica/ui/controller/admin/UserAdminController.java  (working copy)
  511. @@ -196,15 +196,8 @@
  512.             }
  513.             else if (TAB_SECURITY.equals(tab))
  514.             {
  515. -               // TODO: change the checkbox naming scheme
  516. -               List<Serializable> roles = new LinkedList<Serializable>();
  517. -               for(Entry <String,String> role : parameters.entrySet())
  518. -               {
  519. -                   if(role.getKey().endsWith("checkbox"))
  520. -                       roles.add(role.getValue());
  521. -               }  
  522. -
  523. -               User user = userService.updateRoles(userId, roles);
  524. +               User user = userService.updateRoles(userId,
  525. +                   getRolesFromParameters(parameters));
  526.                
  527.                 if (user == null)
  528.                     throw new RuntimeException("Failed to update user " + userId);
  529. @@ -213,6 +206,41 @@
  530.  
  531.         return problems;
  532.     }
  533. +
  534. +   @RequestMapping(method = RequestMethod.POST, value = "/users/new")
  535. +   @RolesAllowed(ROLE.REGISTRAR)
  536. +   public @ResponseBody Map<String, String> register(
  537. +       HttpServletRequest request)
  538. +   {
  539. +       Map<String, String> parameters = RequestUtils.getParameterMap(request);
  540. +       Map<String, String> problems = validationService.validate(parameters);
  541. +
  542. +       if (problems.isEmpty())
  543. +       {
  544. +           String username = parameters.get(PARAM.USERNAME);
  545. +           String firstName = parameters.get(PARAM.FIRST_NAME);
  546. +           String lastName = parameters.get(PARAM.LAST_NAME);
  547. +           String employeeId = parameters.get(PARAM.EMPLOYEE_ID);
  548. +           String locationId = parameters.get(PARAM.LOCATION_ID);
  549. +           String address = parameters.get(PARAM.ADDRESS);
  550. +           String city = parameters.get(PARAM.CITY);
  551. +           String state = parameters.get(PARAM.STATE);
  552. +           String zipCode = parameters.get(PARAM.ZIP_CODE);
  553. +           String email = parameters.get(PARAM.EMAIL);
  554. +           String intranetUsername = parameters.get(PARAM.INTRANET_USERNAME);
  555. +           List<Serializable> roleIds = getRolesFromParameters(parameters);
  556. +
  557. +           User user = userService.registerUser(sessionService.getUserId(),
  558. +               username, firstName, lastName, employeeId, Long.decode(locationId),
  559. +               address, city, state, zipCode, email, intranetUsername, roleIds);
  560. +          
  561. +           if (user == null)
  562. +               throw new RuntimeException("Failed to register new user : " + username);
  563. +       }
  564. +      
  565. +       return problems;
  566. +   }
  567. +
  568.    
  569.     private void populate(ModelMap model, Long userId)
  570.     {
  571. @@ -274,5 +302,18 @@
  572.  
  573.         if (user == null)
  574.             throw new RuntimeException("Failed to update user " + userId);
  575. -   }      
  576. +   }
  577. +
  578. +   private List<Serializable> getRolesFromParameters(
  579. +           Map<String, String> parameters)
  580. +   {
  581. +       // TODO: change the checkbox naming scheme
  582. +       List<Serializable> roles = new LinkedList<Serializable>();
  583. +       for (Entry<String, String> role : parameters.entrySet())
  584. +       {
  585. +           if (role.getKey().endsWith("checkbox"))
  586. +               roles.add(role.getValue());
  587. +       }
  588. +       return roles;
  589. +   }
  590.  }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top