1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.mobility.writer.entity;
18
19 import java.util.Date;
20
21 import javax.persistence.Column;
22 import javax.persistence.Entity;
23 import javax.persistence.FetchType;
24 import javax.persistence.GeneratedValue;
25 import javax.persistence.GenerationType;
26 import javax.persistence.Id;
27 import javax.persistence.JoinColumn;
28 import javax.persistence.NamedQueries;
29 import javax.persistence.NamedQuery;
30 import javax.persistence.OneToOne;
31 import javax.persistence.Table;
32 import javax.persistence.Version;
33
34
35
36
37
38
39 @NamedQueries({
40
41
42 @NamedQuery(
43 name="Article.getRejectedArticles",
44 query="SELECT a FROM Article a WHERE a.journalistId = :userId AND status = 3 AND a.tool = :tool ORDER BY a.timestamp DESC"),
45
46
47 @NamedQuery(
48 name="Article.getNumRejectedArticles",
49 query="SELECT COUNT(a) FROM Article a WHERE a.journalistId = :userId AND status = 3 AND a.tool = :tool ORDER BY a.timestamp DESC"),
50
51
52 @NamedQuery(
53 name="Article.getSavedArticlesEditor",
54 query="SELECT a FROM Article a WHERE (a.journalistId = :userId AND a.status = 1) OR (a.editorId = :userId AND a.status = 21) AND a.tool = :tool ORDER BY a.timestamp DESC"),
55
56
57 @NamedQuery(
58 name="Article.getNumSavedArticlesEditor",
59 query="SELECT COUNT(a) FROM Article a WHERE (a.journalistId = :userId AND a.status = 1) OR (a.editorId = :userId AND a.status = 21) AND a.tool = :tool ORDER BY a.timestamp DESC"),
60
61
62 @NamedQuery(
63 name="Article.getSavedArticles",
64 query="SELECT a FROM Article a WHERE a.journalistId = :userId AND status = 1 AND a.tool = :tool ORDER BY a.timestamp DESC"),
65
66
67 @NamedQuery(
68 name="Article.getNumSavedArticles",
69 query="SELECT COUNT(a) FROM Article a WHERE a.journalistId = :userId AND status = 1 AND a.tool = :tool ORDER BY a.timestamp DESC"),
70
71
72 @NamedQuery(
73 name="Article.getSubmittedArticles",
74 query="SELECT a FROM Article a WHERE status = 2 AND a.tool = :tool ORDER BY a.timestamp DESC"),
75
76
77 @NamedQuery(
78 name="Article.getNumSubmittedArticles",
79 query="SELECT COUNT(a) FROM Article a WHERE status = 2 AND a.tool = :tool ORDER BY a.timestamp DESC"),
80
81
82 @NamedQuery(
83 name="Article.getNumArticlesTopNews",
84 query="SELECT COUNT(a) from Article a WHERE status = 4 AND a.tool = :tool"),
85
86
87 @NamedQuery(
88 name="Article.getNumArticles",
89 query="SELECT COUNT(a) from Article a WHERE topic.id = :topicId AND status = 4 AND a.tool = :tool"),
90
91
92 @NamedQuery(
93 name="Article.getTopNewsRange",
94 query="SELECT a from Article a WHERE status = 4 AND a.tool = :tool ORDER BY a.timestamp DESC"),
95
96
97 @NamedQuery(
98 name="Article.getNewsRange",
99 query="SELECT a FROM Article a WHERE topic.id = :topicId AND status = 4 AND a.tool = :tool ORDER BY a.timestamp DESC"),
100
101
102 @NamedQuery(
103 name="Article.searchNews",
104 query="SELECT a FROM Article a WHERE (a.text LIKE :text OR a.heading LIKE :text) AND status = 4 AND a.tool = :tool ORDER BY a.timestamp DESC"),
105
106
107 @NamedQuery(
108 name="Article.searchNewsCount",
109 query="SELECT COUNT(a) FROM Article a WHERE (a.text LIKE :text OR a.heading LIKE :text) AND status = 4 AND a.tool = :tool")
110
111 })
112 @Entity
113 @Table(name="WRITER_ARTICLE")
114 public class Article {
115
116
117
118
119 public static final int STATUS_SAVED = 1;
120
121
122 public static final int STATUS_SUBMITTED = 2;
123
124
125 public static final int STATUS_SUBMITTED_SAVED = 21;
126
127
128 public static final int STATUS_REJECTED = 3;
129
130
131 public static final int STATUS_PUBLISHED = 4;
132
133
134 public static final int STATUS_DISCARDED = 5;
135
136
137 public static final int STATUS_DELETED = 6;
138
139
140
141
142
143
144 public static final long CATEGORY_GENERAL = 1;
145
146
147 public static final long CATEGORY_IMPORTANT = 2;
148
149
150 @Id
151
152 @GeneratedValue(strategy = GenerationType.TABLE)
153 @Column(name="ID")
154 private Long id;
155
156
157
158
159 @Column(name="JOURNALIST_ID")
160 private String journalistId;
161
162
163
164
165 @Column(name="LINK_URL")
166 private String linkUrl;
167
168
169
170
171
172
173 @Column(name="EDITOR_ID")
174 private String editorId;
175
176
177
178
179
180
181
182
183
184 @Column(name="STATUS", nullable=false)
185 private int status;
186
187
188 @Column(name="HEADING", nullable=false, length=64)
189 private String heading;
190
191
192 @Column(name="SYNOPSIS", nullable=false, length=250)
193 private String synopsis;
194
195
196 @Column(name="TEXT", nullable=false, length=4000)
197 private String text;
198
199
200 @OneToOne(optional=true)
201 @JoinColumn(name="TOPIC_ID")
202 private Topic topic;
203
204
205 @Column(name="CATEGORY_ID", nullable=false)
206 private long category;
207
208
209 @Column(name="TIMESTAMP", nullable=false)
210 private Date timestamp;
211
212
213 @Column(name="JOURNALIST", nullable=false, length=255)
214 private String journalist;
215
216
217
218
219 @OneToOne(optional=true)
220 @JoinColumn(name="REJECTION_ID")
221 private ArticleRejection rejection;
222
223
224
225
226 @OneToOne(optional=true)
227 @JoinColumn(name="IMAGE_ID")
228 private Media image;
229
230
231
232
233 @OneToOne(optional=true)
234 @JoinColumn(name="VIDEO_ID")
235 private Media video;
236
237 @Version
238 @Column(name="VER_NBR")
239 protected Long versionNumber;
240
241
242
243
244 @Column(name="TOOL")
245 private String tool;
246
247
248
249
250 public Media getImage() {
251 return image;
252 }
253
254
255
256
257 public void setImage(Media image) {
258 this.image = image;
259 }
260
261
262
263
264 public Media getVideo() {
265 return video;
266 }
267
268
269
270
271 public void setVideo(Media video) {
272 this.video = video;
273 }
274
275
276
277
278 public int getStatus() {
279 return status;
280 }
281
282
283
284
285 public void setStatus(int status) {
286 this.status = status;
287 }
288
289
290
291
292 public ArticleRejection getRejection() {
293 return rejection;
294 }
295
296
297
298
299 public void setRejection(ArticleRejection rejection) {
300 this.rejection = rejection;
301 }
302
303
304
305
306
307
308 public String getJournalistId() {
309 return journalistId;
310 }
311
312
313
314
315 public void setJournalistId(String journalistId) {
316 this.journalistId = journalistId;
317 }
318
319
320
321
322 public String getJournalist() {
323 return journalist;
324 }
325
326
327
328
329 public void setJournalist(String journalist) {
330 this.journalist = journalist;
331 }
332
333
334
335
336
337 public Date getTimestamp() {
338 return timestamp;
339 }
340
341
342
343
344
345 public void setTimestamp(Date timestamp) {
346 this.timestamp = timestamp;
347 }
348
349
350
351
352
353 public Long getId() {
354 return id;
355 }
356
357
358
359
360
361 public void setId(Long id) {
362 this.id = id;
363 }
364
365
366
367
368
369 public String getHeading() {
370 return heading;
371 }
372
373
374
375
376
377 public void setHeading(String heading) {
378 this.heading = heading;
379 }
380
381
382
383
384
385 public String getSynopsis() {
386 return synopsis;
387 }
388
389
390
391
392
393 public void setSynopsis(String synopsis) {
394 this.synopsis = synopsis;
395 }
396
397
398
399
400
401 public String getText() {
402 return text;
403 }
404
405
406
407
408
409 public void setText(String text) {
410 this.text = text;
411 }
412
413
414
415
416
417 public Topic getTopic() {
418 return topic;
419 }
420
421
422
423
424
425 public void setTopic(Topic topic) {
426 this.topic = topic;
427 }
428
429
430
431
432
433 public long getCategory() {
434 return category;
435 }
436
437
438
439
440
441 public void setCategory(long category) {
442 this.category = category;
443 }
444
445
446
447
448
449 public String getEditorId() {
450 return editorId;
451 }
452
453
454
455
456
457 public void setEditorId(String editorId) {
458 this.editorId = editorId;
459 }
460
461
462
463
464
465 public Long getVersionNumber() {
466 return versionNumber;
467 }
468
469
470
471
472
473
474 public void setVersionNumber(Long versionNumber) {
475 this.versionNumber = versionNumber;
476 }
477
478
479
480
481
482
483 public String getToolInstance() {
484 return tool;
485 }
486
487
488
489
490
491 public void setToolInstance(String tool) {
492 this.tool = tool;
493 }
494
495
496
497
498
499 public String getLinkUrl() {
500 return linkUrl;
501 }
502
503
504
505
506
507 public void setLinkUrl(String linkUrl) {
508 this.linkUrl = linkUrl;
509 }
510
511
512 public String toString(){
513 StringBuilder sb = new StringBuilder(256);
514 sb.append("Article[");
515 sb.append("category=").append(this.category);
516 sb.append(",heading=").append(this.heading);
517 sb.append(",id=").append(this.id);
518 sb.append(",journalist=").append(this.journalist);
519 sb.append(",synopsis=").append(this.synopsis);
520 sb.append(",text=").append(this.text);
521 sb.append(",timestamp=").append(this.timestamp);
522 sb.append(",topic=").append(this.topic);
523 sb.append(",version=").append(this.versionNumber);
524 sb.append(",link=").append(this.linkUrl);
525 sb.append("]");
526 return sb.toString();
527 }
528 }