View Javadoc
1   package com.srv4pos.server.api.user;
2   
3   import com.srv4pos.server.api.auth.UserRole;
4   import com.srv4pos.server.api.infrastructure.Constraints;
5   import com.srv4pos.server.api.infrastructure.Info;
6   import org.springframework.roo.addon.javabean.RooJavaBean;
7   import org.springframework.roo.addon.json.RooJson;
8   import org.springframework.roo.addon.tostring.RooToString;
9   
10  import javax.validation.constraints.NotNull;
11  import javax.validation.constraints.Pattern;
12  import javax.validation.constraints.Size;
13  
14  /**
15   * Registration information for user.
16   * It has a password unlike {@link UserInfo}.
17   */
18  @RooJavaBean
19  @RooToString
20  @RooJson(deepSerialize = true)
21  public class UserRegistrationInfo implements Info {
22  
23      /**
24       * True if entity was deleted. Only possible if return diff
25       */
26      @NotNull
27      private boolean deleted = Boolean.FALSE;
28  
29      @NotNull
30      @Size(max = 50, min = 1)
31      private String username;
32  
33      @NotNull
34      @Size(max = 50, min = 6)
35      @Pattern(regexp = Constraints.EMAIL_REGEX)
36      private String email;
37  
38      @NotNull
39      private UserRole role;
40  
41      /**
42       * If {@link #role} == ROLE_HYPER_ADMIN or ROLE_REGULAR_USER, then null.<br>
43       * If {@link #role} == ROLE_SOFTWARE_VENDOR_ADMIN, then not null.
44       */
45      private Long softwareVendor;
46  
47      @NotNull
48      @Size(min = 4, max = 16)
49      private String password;
50  
51      /**
52       * Converts into {@link UserInfo}. The same info, but without a password.
53       *
54       * @return the {@link UserInfo}.
55       */
56      public UserInfo toUserInfo() {
57          final UserInfo userInfo = new UserInfo();
58          userInfo.setDeleted(isDeleted());
59          userInfo.setEmail(getEmail());
60          userInfo.setRole(getRole());
61          userInfo.setSoftwareVendor(getSoftwareVendor());
62          userInfo.setUsername(getUsername());
63          return userInfo;
64      }
65  }