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.TemporalType.*; 016 017import java.util.*; 018 019import javax.persistence.*; 020 021import org.apache.juneau.annotation.*; 022import org.apache.juneau.html.annotation.*; 023import org.apache.juneau.internal.*; 024import org.apache.juneau.jsonschema.annotation.*; 025import org.apache.juneau.transforms.*; 026 027/** 028 * Order bean. 029 * 030 * <ul class='seealso'> 031 * <li class='extlink'>{@source} 032 * </ul> 033 */ 034@Bean(fluentSetters=true, properties="id,petId,username,status,shipDate") 035@Example("{id:123,petId:456,shipDate:'2012-12-21',status:'APPROVED'}") 036@Entity(name="PetstoreOrder") 037public class Order { 038 039 @Column @Id @GeneratedValue 040 @Schema(description="Unique identifier for this order.") 041 @Html(link="servlet:/store/order/{id}") 042 private long id; 043 044 @Column 045 @Schema(description="Pet unique identifier.") 046 @Html(link="servlet:/pet/{id}") 047 private long petId; 048 049 @Column(length=20) 050 @Schema(description="User who created this order.", minLength=3, maxLength=20) 051 @Html(link="servlet:/user/{username}") 052 private String username; 053 054 @Column 055 @Enumerated(EnumType.STRING) 056 @Schema(description="The current order status.") 057 private OrderStatus status; 058 059 @Column @Temporal(TIMESTAMP) 060 @Schema(description="The ship date for this order.", format="date-time") 061 @Swap(TemporalDateSwap.IsoLocalDate.class) 062 private Date shipDate; 063 064 /** 065 * Applies the specified create data to this order. 066 * 067 * @param o The create data to apply. 068 * @return This object. 069 */ 070 public Order apply(CreateOrder o) { 071 this.petId = o.getPetId(); 072 this.username = o.getUsername(); 073 return this; 074 } 075 076 /** 077 * Applies the specified order this order. 078 * 079 * @param o The order to apply. 080 * @return This object. 081 */ 082 public Order apply(Order o) { 083 this.id = o.getId(); 084 this.petId = o.getPetId(); 085 this.username = o.getUsername(); 086 this.status = o.getStatus(); 087 this.shipDate = o.getShipDate(); 088 return this; 089 } 090 091 //----------------------------------------------------------------------------------------------------------------- 092 // Bean properties 093 //----------------------------------------------------------------------------------------------------------------- 094 095 /** 096 * @return The <bc>id</bc> property value. 097 */ 098 public long getId() { 099 return id; 100 } 101 102 /** 103 * @param value The <bc>id</bc> property value. 104 * @return This object (for method chaining). 105 */ 106 public Order id(long value) { 107 this.id = value; 108 return this; 109 } 110 111 /** 112 * @return The <bc>shipDate</bc> property value. 113 */ 114 public Date getShipDate() { 115 return shipDate; 116 } 117 118 /** 119 * @param value The <bc>shipDate</bc> property value. 120 * @return This object (for method chaining). 121 */ 122 public Order shipDate(Date value) { 123 this.shipDate = value; 124 return this; 125 } 126 127 /** 128 * @return The <bc>status</bc> property value. 129 */ 130 public OrderStatus getStatus() { 131 return status; 132 } 133 134 /** 135 * @param value The <bc>status</bc> property value. 136 * @return This object (for method chaining). 137 */ 138 public Order status(OrderStatus value) { 139 this.status = value; 140 return this; 141 } 142 143 /** 144 * @return The <bc>petId</bc> property value. 145 */ 146 public long getPetId() { 147 return petId; 148 } 149 150 /** 151 * @param value The <bc>petId</bc> property value. 152 * @return This object (for method chaining). 153 */ 154 public Order petId(long value) { 155 this.petId = value;; 156 return this; 157 } 158 159 /** 160 * @return The <bc>username</bc> property value. 161 */ 162 public String getUsername() { 163 return username; 164 } 165 166 /** 167 * @param value The <bc>username</bc> property value. 168 * @return This object (for method chaining). 169 */ 170 public Order username(String value) { 171 this.username = value; 172 return this; 173 } 174 175 //----------------------------------------------------------------------------------------------------------------- 176 // Other 177 //----------------------------------------------------------------------------------------------------------------- 178 179 /** 180 * This shows an example generated from a static method. 181 * 182 * @return The example POJO. 183 */ 184 @Example 185 public static Order example() { 186 return new Order() 187 .id(123) 188 .username("sampleuser") 189 .petId(456) 190 .status(OrderStatus.APPROVED) 191 .shipDate(DateUtils.parseISO8601("2020-10-10")) 192 ; 193 } 194}