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@Bean(typeName="User", fluentSetters=true, properties="username,firstName,lastName,email,password,phone,userStatus")
024@Entity(name="PetstoreUser")
025public class User {
026
027   @Id
028   @Column(length=8)
029   @Schema(description="Username.", minLength=3, maxLength=8)
030   @Html(link="servlet:/user/{username}")
031   private String username;
032
033   @Column(length=50)
034   @Schema(description="First name.", maxLength=50)
035   private String firstName;
036
037   @Column(length=50)
038   @Schema(description="First name.", maxLength=50)
039   private String lastName;
040
041   @Column(length=50)
042   @Schema(description="First name.", maxLength=50, pattern="\\S+\\@\\S+")
043   private String email;
044
045   @Column(length=8)
046   @Schema(description="Password.", minLength=3, maxLength=8, pattern="[\\w\\d]{3,8}")
047   private String password;
048
049   @Column
050   @Schema(description="Phone number.", minLength=12, maxLength=12, pattern="\\d{3}\\-\\d{3}\\-\\d{4}")
051   private String phone;
052
053   @Column
054   @Enumerated(STRING)
055   private UserStatus userStatus;
056
057   public User apply(User c) {
058      this.username = c.getUsername();
059      this.firstName = c.getFirstName();
060      this.lastName = c.getLastName();
061      this.email = c.getEmail();
062      this.password = c.getPassword();
063      this.phone = c.getPhone();
064      this.userStatus = c.getUserStatus();
065      return this;
066   }
067
068   //-----------------------------------------------------------------------------------------------------------------
069   // Bean properties
070   //-----------------------------------------------------------------------------------------------------------------
071
072   public String getUsername() {
073      return username;
074   }
075
076   public User username(String username) {
077      this.username = username;
078      return this;
079   }
080
081   public String getFirstName() {
082      return firstName;
083   }
084
085   public User firstName(String firstName) {
086      this.firstName = firstName;
087      return this;
088   }
089
090   public String getLastName() {
091      return lastName;
092   }
093
094   public User lastName(String lastName) {
095      this.lastName = lastName;
096      return this;
097   }
098
099   public String getEmail() {
100      return email;
101   }
102
103   public User email(String email) {
104      this.email = email;
105      return this;
106   }
107
108   public String getPassword() {
109      return password;
110   }
111
112   public User password(String password) {
113      this.password = password;
114      return this;
115   }
116
117   public String getPhone() {
118      return phone;
119   }
120
121   public User phone(String phone) {
122      this.phone = phone;
123      return this;
124   }
125
126   public UserStatus getUserStatus() {
127      return userStatus;
128   }
129
130   public User userStatus(UserStatus userStatus) {
131      this.userStatus = userStatus;
132      return this;
133   }
134
135   //-----------------------------------------------------------------------------------------------------------------
136   // Other
137   //-----------------------------------------------------------------------------------------------------------------
138
139   /**
140    * This shows an example generated from a static method.
141    */
142   @Example
143   public static User EXAMPLE = new User()
144      .username("billy")
145      .firstName("Billy")
146      .lastName("Bob")
147      .email("billy@apache.org")
148      .userStatus(UserStatus.ACTIVE)
149      .phone("111-222-3333");
150
151}