1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package tinlizard.web;
20
21 import tinlizard.annotation.security.RolesAllowed;
22
23 import tinlizard.model.Codeline;
24 import tinlizard.model.View;
25
26 import tinlizard.util.Messages;
27
28 import java.util.Collection;
29 import java.util.Date;
30
31 import org.kohsuke.stapler.StaplerRequest;
32 import org.kohsuke.stapler.StaplerResponse;
33 import org.kohsuke.stapler.export.Exported;
34
35 /***
36 * Decorate View for Stapler.
37 */
38 public final class ViewWeb extends ObjectWeb<View> {
39 private final View subject;
40
41 public ViewWeb(final View c) {
42 if (c == null) {
43 throw new IllegalStateException(Messages.error_1010());
44 }
45
46 this.subject = c;
47 }
48
49 protected View getSubject() {
50 return this.subject;
51 }
52
53 public Integer getId() {
54 return subject.getId();
55 }
56
57 public String getName() {
58 return subject.getName();
59 }
60
61 @Exported
62 public String getDescription() {
63 return subject.getDescription();
64 }
65
66 @Exported
67 public Date getCreated() {
68 return subject.getCreated();
69 }
70
71 @Exported
72 public String getCreatedBy() {
73 return subject.getCreatedBy();
74 }
75
76 @Exported
77 public Date getLastModified() {
78 return subject.getLastModified();
79 }
80
81 @Exported
82 public String getLastModifiedBy() {
83 return subject.getLastModifiedBy();
84 }
85
86 @Exported(visibility = 1)
87 public CodelineCollectionWeb getCodelines() {
88 Collection<Codeline> allCodelines = this.subject.getCodelines();
89
90
91 if (((allCodelines != null) && !allCodelines.isEmpty())) {
92 return new CodelineCollectionWeb(allCodelines, Messages._AllCodelines());
93 } else {
94 return null;
95 }
96 }
97
98 public CodelineCollectionWeb getActiveCodelines() {
99 Collection<Codeline> codelines = this.subject.getActiveCodelines();
100
101 if (codelines != null) {
102 return new CodelineCollectionWeb(codelines, Messages._ActiveCodelines());
103 } else {
104 return null;
105 }
106 }
107
108 @RolesAllowed(RoleNames.USER)
109 public void doDelete(final StaplerRequest request, final StaplerResponse response) throws Exception {
110 subject.delete();
111 response.sendRedirect(request.getContextPath());
112 }
113
114
115 @RolesAllowed(RoleNames.USER)
116 public void doUpdate(final StaplerRequest request, final StaplerResponse response) throws Exception {
117 request.bindParameters(subject, "view.");
118
119 subject.update();
120 gotoMyIndex(request, response);
121 }
122 }