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.Policy;
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 Policy for Stapler.
37 */
38 public final class PolicyWeb extends ObjectWeb<Policy> {
39 private final Policy subject;
40
41 public PolicyWeb(final Policy c) {
42 if (c == null) {
43 throw new IllegalStateException(Messages.error_1010());
44 }
45
46 this.subject = c;
47 }
48
49 protected Policy 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 public boolean isActive() {
67 return this.subject.isActive();
68 }
69
70 @Exported
71 public Boolean getActive() {
72 return this.subject.getActive();
73 }
74
75 @Exported
76 public Date getCreated() {
77 return subject.getCreated();
78 }
79
80 @Exported
81 public String getCreatedBy() {
82 return subject.getCreatedBy();
83 }
84
85 @Exported
86 public Date getLastModified() {
87 return subject.getLastModified();
88 }
89
90 @Exported
91 public String getLastModifiedBy() {
92 return subject.getLastModifiedBy();
93 }
94
95 @Exported(visibility = 1)
96 public CodelineCollectionWeb getCodelines() {
97 Collection<Codeline> allCodelines = this.subject.getCodelines();
98
99
100 if (((allCodelines != null) && !allCodelines.isEmpty())) {
101 return new CodelineCollectionWeb(allCodelines, Messages._Codelines());
102 } else {
103 return null;
104 }
105 }
106
107 @RolesAllowed(RoleNames.ADMIN)
108 public void doDelete(final StaplerRequest request, final StaplerResponse response) throws Exception {
109
110 subject.delete();
111 response.sendRedirect(request.getContextPath());
112 }
113
114
115 @RolesAllowed(RoleNames.ADMIN)
116 public void doUpdate(final StaplerRequest request, final StaplerResponse response) throws Exception {
117 request.bindParameters(subject, "policy.");
118 subject.update();
119 gotoMyIndex(request, response);
120 }
121 }