View Javadoc

1   /*
2    * ----------------------------------------------------------------------
3    * Copyright (C) 2009 Enrique Lara (k957@68k.org)
4    *
5    * TinLizard is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU Lesser General Public License
7    * as published by the Free Software Foundation; either version 3.0
8    * of the License, or (at your option) any later version.
9    *
10   * TinLizard is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   * GNU Lesser General Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser General Public License
16   * along with TinLizard. If not, see http://www.gnu.org/licenses/.
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          //ArrayUtils?XXX
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         //XXX add check for matching codelines/views
110         subject.delete();
111         response.sendRedirect(request.getContextPath());
112     }
113 
114     //XXX prevent updating id?
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 }