1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.jboss.as.quickstarts.tasksrs.model;
18
19
20
21
22 import static javax.persistence.GenerationType.IDENTITY;
23
24 import java.io.Serializable;
25 import java.io.StringReader;
26
27 import javax.persistence.Entity;
28 import javax.persistence.GeneratedValue;
29 import javax.persistence.Id;
30 import javax.persistence.ManyToOne;
31 import javax.xml.bind.JAXB;
32 import javax.xml.bind.annotation.XmlAttribute;
33 import javax.xml.bind.annotation.XmlElement;
34 import javax.xml.bind.annotation.XmlRootElement;
35 import javax.xml.bind.annotation.XmlTransient;
36
37
38
39
40
41
42
43 @SuppressWarnings("serial")
44 @Entity
45 @XmlRootElement(name = "task")
46 public class Task implements Serializable {
47
48 @Id
49 @GeneratedValue(strategy = IDENTITY)
50 private Long id;
51
52 @ManyToOne
53 private User owner;
54
55 private String title;
56
57 public Task() {
58 }
59
60 public Task(String title) {
61 super();
62 this.title = title;
63 }
64
65 @XmlAttribute
66 public Long getId() {
67 return id;
68 }
69
70 public void setId(Long id) {
71 this.id = id;
72 }
73
74 @XmlTransient
75
76
77 public User getOwner() {
78 return owner;
79 }
80
81 @XmlAttribute
82 public String getOwnerName() {
83 return owner.getUsername();
84 }
85
86 public void setOwner(User owner) {
87 this.owner = owner;
88 }
89
90 @XmlElement
91 public String getTitle() {
92 return title;
93 }
94
95 public void setTitle(String title) {
96 this.title = title;
97 }
98
99 @Override
100 public int hashCode() {
101 final int prime = 31;
102 int result = 1;
103 result = prime * result + ((owner == null) ? 0 : owner.hashCode());
104 result = prime * result + ((title == null) ? 0 : title.hashCode());
105 return result;
106 }
107
108 @Override
109 public boolean equals(Object obj) {
110 if (this == obj) {
111 return true;
112 }
113 if (obj == null) {
114 return false;
115 }
116 if (getClass() != obj.getClass()) {
117 return false;
118 }
119 Task other = (Task) obj;
120 if (owner == null) {
121 if (other.owner != null) {
122 return false;
123 }
124 } else if (!owner.equals(other.owner)) {
125 return false;
126 }
127 if (title == null) {
128 if (other.title != null) {
129 return false;
130 }
131 } else if (!title.equals(other.title)) {
132 return false;
133 }
134 return true;
135 }
136
137 public static Task stringToTask(String content) {
138 return JAXB.unmarshal(new StringReader(content), Task.class);
139 }
140 }