This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Project.java
295 lines (257 loc) · 8.61 KB
/
Project.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
package org.zanata.rest.dto;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.annotate.JsonPropertyOrder;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
import org.hibernate.validator.constraints.NotEmpty;
import org.zanata.common.EntityStatus;
import org.zanata.common.Namespaces;
import org.zanata.common.ProjectType;
import org.zanata.rest.MediaTypes;
import org.zanata.rest.MediaTypes.Format;
/**
* Representation of the data within a Project resource
*
* @author asgeirf
*
*/
@XmlType(name = "projectType", propOrder = { "name", "defaultType",
"description", "sourceViewURL", "sourceCheckoutURL", "links",
"iterations", "status" })
@XmlRootElement(name = "project")
@JsonPropertyOrder({ "id", "defaultType", "name", "description",
"sourceViewURL", "sourceCheckoutURL", "links", "iterations", "status" })
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonSerialize(include = Inclusion.NON_NULL)
public class Project implements Serializable, HasCollectionSample<Project>,
HasMediaType {
private String id;
private String name;
private String defaultType;
private String description;
private String sourceViewURL;
private String sourceCheckoutURL;
private EntityStatus status = EntityStatus.ACTIVE;
private Links links;
private List<ProjectIteration> iterations;
public Project() {
}
public Project(String id, String name, String defaultType) {
this.id = id;
this.name = name;
this.defaultType = defaultType;
}
public Project(String id, String name, String type, String description) {
this(id, name, type);
this.description = description;
}
@XmlAttribute(name = "id", required = true)
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@XmlElement(name = "defaultType", required = true, nillable = false,
namespace = Namespaces.ZANATA_OLD)
public String getDefaultType() {
return defaultType;
}
public void setDefaultType(String defaultType) {
this.defaultType = defaultType;
}
@NotEmpty
@Size(max = 80)
@XmlElement(name = "name", required = true,
namespace = Namespaces.ZANATA_OLD)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Size(max = 80)
@XmlElement(name = "description", required = false,
namespace = Namespaces.ZANATA_OLD)
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@XmlElement(name = "sourceViewURL", required = false, nillable = true,
namespace = Namespaces.ZANATA_API)
public String getSourceViewURL() {
return sourceViewURL;
}
public void setSourceViewURL(String sourceViewURL) {
this.sourceViewURL = sourceViewURL;
}
@XmlElement(name = "sourceCheckoutURL", required = false, nillable = true,
namespace = Namespaces.ZANATA_API)
public String getSourceCheckoutURL() {
return sourceCheckoutURL;
}
public void setSourceCheckoutURL(String sourceCheckoutURL) {
this.sourceCheckoutURL = sourceCheckoutURL;
}
@XmlElement(name = "link", namespace = Namespaces.ZANATA_API)
@JsonProperty("links")
public Links getLinks() {
return links;
}
public void setLinks(Links links) {
this.links = links;
}
@JsonIgnore
public Links getLinks(boolean createIfNull) {
if (createIfNull && links == null)
links = new Links();
return links;
}
@XmlElementWrapper(name = "project-iterations",
namespace = Namespaces.ZANATA_OLD)
@XmlElementRef(namespace = Namespaces.ZANATA_OLD)
@JsonProperty("iterations")
public List<ProjectIteration> getIterations() {
return iterations;
}
public void setIterations(List<ProjectIteration> iterations) {
this.iterations = iterations;
}
public List<ProjectIteration> getIterations(boolean createIfNull) {
if (createIfNull && iterations == null)
iterations = new ArrayList<ProjectIteration>();
return getIterations();
}
@XmlElement(name = "status", required = false,
namespace = Namespaces.ZANATA_OLD)
public EntityStatus getStatus() {
return status;
}
public void setStatus(EntityStatus status) {
this.status = status;
}
@Override
public Project createSample() {
Project entity = new Project();
entity.setId("sample-project");
entity.setName("Sample Project");
entity.setDescription("Sample Project Description");
entity.setDefaultType(ProjectType.Gettext.toString());
entity.getIterations(true).addAll(
new ProjectIteration().createSamples());
return entity;
}
@Override
public Collection<Project> createSamples() {
Collection<Project> entities = new ArrayList<Project>();
entities.add(createSample());
Project p2 = createSample();
p2.setId("another-project");
p2.setName("Another Sample Project");
p2.setDescription("Another Sample Project Description");
p2.setDefaultType(ProjectType.Gettext.toString());
entities.add(p2);
return entities;
}
public static void main(String args[]) {
Project test = new Project();
System.out.println(test.createSample().toString());
}
@Override
public String getMediaType(Format format) {
return MediaTypes.APPLICATION_ZANATA_PROJECT + format;
}
@Override
public String toString() {
return DTOUtil.toXML(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result =
prime * result
+ ((description == null) ? 0 : description.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result =
prime * result
+ ((iterations == null) ? 0 : iterations.hashCode());
result = prime * result + ((links == null) ? 0 : links.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result =
prime * result
+ ((defaultType == null) ? 0 : defaultType.hashCode());
result = prime * result + ((status == null) ? 0 : status.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof Project)) {
return false;
}
Project other = (Project) obj;
if (description == null) {
if (other.description != null) {
return false;
}
} else if (!description.equals(other.description)) {
return false;
}
if (id == null) {
if (other.id != null) {
return false;
}
} else if (!id.equals(other.id)) {
return false;
}
if (iterations == null) {
if (other.iterations != null) {
return false;
}
} else if (!iterations.equals(other.iterations)) {
return false;
}
if (links == null) {
if (other.links != null) {
return false;
}
} else if (!links.equals(other.links)) {
return false;
}
if (name == null) {
if (other.name != null) {
return false;
}
} else if (!name.equals(other.name)) {
return false;
}
if (!defaultType.equals(other.defaultType)) {
return false;
}
if (status != other.status) {
return false;
}
return true;
}
}