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.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          //ArrayUtils?XXX
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     //XXX prevent updating id?
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 }