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@Bean(fluentSetters=true, properties="id,petId,username,status,shipDate") 028@Example("{id:123,petId:456,shipDate:'2012-12-21',status:'APPROVED'}") 029@Entity(name="PetstoreOrder") 030public class Order { 031 032 @Column @Id @GeneratedValue 033 @Schema(description="Unique identifier for this order.") 034 @Html(link="servlet:/store/order/{id}") 035 private long id; 036 037 @Column 038 @Schema(description="Pet unique identifier.") 039 @Html(link="servlet:/pet/{id}") 040 private long petId; 041 042 @Column(length=20) 043 @Schema(description="User who created this order.", minLength=3, maxLength=20) 044 @Html(link="servlet:/user/{username}") 045 private String username; 046 047 @Column 048 @Enumerated(EnumType.STRING) 049 @Schema(description="The current order status.") 050 private OrderStatus status; 051 052 @Column @Temporal(TIMESTAMP) 053 @Schema(description="The ship date for this order.", format="date-time") 054 @Swap(DateSwap.ISO8601D.class) 055 private Date shipDate; 056 057 public Order apply(CreateOrder o) { 058 this.petId = o.getPetId(); 059 this.username = o.getUsername(); 060 return this; 061 } 062 063 public Order apply(Order o) { 064 this.id = o.getId(); 065 this.petId = o.getPetId(); 066 this.username = o.getUsername(); 067 this.status = o.getStatus(); 068 this.shipDate = o.getShipDate(); 069 return this; 070 } 071 072 //----------------------------------------------------------------------------------------------------------------- 073 // Bean properties 074 //----------------------------------------------------------------------------------------------------------------- 075 076 public long getId() { 077 return id; 078 } 079 080 public Order id(long id) { 081 this.id = id; 082 return this; 083 } 084 085 public Date getShipDate() { 086 return shipDate; 087 } 088 089 public Order shipDate(Date value) { 090 this.shipDate = value; 091 return this; 092 } 093 094 public OrderStatus getStatus() { 095 return status; 096 } 097 098 public Order status(OrderStatus value) { 099 this.status = value; 100 return this; 101 } 102 103 public long getPetId() { 104 return petId; 105 } 106 107 public Order petId(long value) { 108 this.petId = value;; 109 return this; 110 } 111 112 public String getUsername() { 113 return username; 114 } 115 116 public Order username(String value) { 117 this.username = value; 118 return this; 119 } 120 121 //----------------------------------------------------------------------------------------------------------------- 122 // Other 123 //----------------------------------------------------------------------------------------------------------------- 124 125 /** 126 * This shows an example generated from a static method. 127 */ 128 @Example 129 public static Order example() { 130 return new Order() 131 .id(123) 132 .username("sampleuser") 133 .petId(456) 134 .status(OrderStatus.APPROVED) 135 .shipDate(DateUtils.parseISO8601("2020-10-10")) 136 ; 137 } 138}