001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.examples.rest.petstore.dto;
014
015import static javax.persistence.EnumType.*;
016
017import javax.persistence.*;
018
019import org.apache.juneau.annotation.*;
020import org.apache.juneau.html.annotation.*;
021import org.apache.juneau.jsonschema.annotation.*;
022
023/**
024 * User bean.
025 *
026 * <ul class='seealso'>
027 *    <li class='extlink'>{@source}
028 * </ul>
029 */
030@Bean(typeName="User", fluentSetters=true, properties="username,firstName,lastName,email,password,phone,userStatus")
031@Entity(name="PetstoreUser")
032public class User {
033
034   @Id
035   @Column(length=8)
036   @Schema(description="Username.", minLength=3, maxLength=8)
037   @Html(link="servlet:/user/{username}")
038   private String username;
039
040   @Column(length=50)
041   @Schema(description="First name.", maxLength=50)
042   private String firstName;
043
044   @Column(length=50)
045   @Schema(description="First name.", maxLength=50)
046   private String lastName;
047
048   @Column(length=50)
049   @Schema(description="First name.", maxLength=50, pattern="\\S+\\@\\S+")
050   private String email;
051
052   @Column(length=8)
053   @Schema(description="Password.", minLength=3, maxLength=8, pattern="[\\w\\d]{3,8}")
054   private String password;
055
056   @Column
057   @Schema(description="Phone number.", minLength=12, maxLength=12, pattern="\\d{3}\\-\\d{3}\\-\\d{4}")
058   private String phone;
059
060   @Column
061   @Enumerated(STRING)
062   private UserStatus userStatus;
063
064   /**
065    * Applies the specified data to this object.
066    *
067    * @param c The data to apply.
068    * @return This object.
069    */
070   public User apply(User c) {
071      this.username = c.getUsername();
072      this.firstName = c.getFirstName();
073      this.lastName = c.getLastName();
074      this.email = c.getEmail();
075      this.password = c.getPassword();
076      this.phone = c.getPhone();
077      this.userStatus = c.getUserStatus();
078      return this;
079   }
080
081   //-----------------------------------------------------------------------------------------------------------------
082   // Bean properties
083   //-----------------------------------------------------------------------------------------------------------------
084
085   /**
086    * @return The <bc>username</jc> property value.
087    */
088   public String getUsername() {
089      return username;
090   }
091
092   /**
093    * @param value The <bc>username</jc> property value.
094    * @return This object (for method chaining).
095    */
096   public User username(String value) {
097      this.username = value;
098      return this;
099   }
100
101   /**
102    * @return The <bc>firstName</jc> property value.
103    */
104   public String getFirstName() {
105      return firstName;
106   }
107
108   /**
109    * @param value The <bc>firstName</jc> property value.
110    * @return This object (for method chaining).
111    */
112   public User firstName(String value) {
113      this.firstName = value;
114      return this;
115   }
116
117   /**
118    * @return The <bc>lastName</jc> property value.
119    */
120   public String getLastName() {
121      return lastName;
122   }
123
124   /**
125    * @param value The <bc>lastName</jc> property value.
126    * @return This object (for method chaining).
127    */
128   public User lastName(String value) {
129      this.lastName = value;
130      return this;
131   }
132
133   /**
134    * @return The <bc>email</jc> property value.
135    */
136   public String getEmail() {
137      return email;
138   }
139
140   /**
141    * @param value The <bc>email</jc> property value.
142    * @return This object (for method chaining).
143    */
144   public User email(String value) {
145      this.email = value;
146      return this;
147   }
148
149   /**
150    * @return The <bc>password</jc> property value.
151    */
152   public String getPassword() {
153      return password;
154   }
155
156   /**
157    * @param value The <bc>password</jc> property value.
158    * @return This object (for method chaining).
159    */
160   public User password(String value) {
161      this.password = value;
162      return this;
163   }
164
165   /**
166    * @return The <bc>phone</jc> property value.
167    */
168   public String getPhone() {
169      return phone;
170   }
171
172   /**
173    * @param value The <bc>phone</jc> property value.
174    * @return This object (for method chaining).
175    */
176   public User phone(String value) {
177      this.phone = value;
178      return this;
179   }
180
181   /**
182    * @return The <bc>userStatus</jc> property value.
183    */
184   public UserStatus getUserStatus() {
185      return userStatus;
186   }
187
188   /**
189    * @param value The <bc>userStatus</jc> property value.
190    * @return This object (for method chaining).
191    */
192   public User userStatus(UserStatus value) {
193      this.userStatus = value;
194      return this;
195   }
196
197   //-----------------------------------------------------------------------------------------------------------------
198   // Other
199   //-----------------------------------------------------------------------------------------------------------------
200
201   /**
202    * This shows an example generated from a static method.
203    */
204   @Example
205   public static User EXAMPLE = new User()
206      .username("billy")
207      .firstName("Billy")
208      .lastName("Bob")
209      .email("billy@apache.org")
210      .userStatus(UserStatus.ACTIVE)
211      .phone("111-222-3333");
212
213}