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.model.Codeline;
22  import tinlizard.model.Dependency;
23  
24  import tinlizard.util.Messages;
25  
26  import java.util.Collection;
27  import java.util.Date;
28  
29  import org.codehaus.plexus.util.StringUtils;
30  
31  import org.kohsuke.stapler.StaplerRequest;
32  import org.kohsuke.stapler.StaplerResponse;
33  import org.kohsuke.stapler.export.Exported;
34  
35  /***
36   * Decorate Dependency for Stapler.
37   */
38  public class DependencyWeb extends ObjectWeb<Dependency> {
39      protected final Dependency subject;
40  
41      public DependencyWeb(final Dependency c) {
42          if (c == null) {
43              throw new IllegalStateException(Messages.error_1018());
44          }
45  
46          this.subject = c;
47      }
48  
49      protected final Dependency getSubject() {
50          return this.subject;
51      }
52  
53      public final Integer getId() {
54          return subject.getId();
55      }
56  
57      public String getName() {
58          return getVersion();
59      }
60  
61      @Exported
62      public String getGroupId() {
63          return subject.getGroupId();
64      }
65  
66      @Exported
67      public String getArtifactId() {
68          return subject.getArtifactId();
69      }
70  
71      @Exported
72      public String getVersion() {
73          return subject.getVersion();
74      }
75  
76      @Exported
77      public Date getCreated() {
78          return subject.getCreated();
79      }
80  
81      @Exported
82      public String getCreatedBy() {
83          return subject.getCreatedBy();
84      }
85  
86      @Exported
87      public Date getLastModified() {
88          return subject.getLastModified();
89      }
90  
91      @Exported
92      public String getLastModifiedBy() {
93          return subject.getLastModifiedBy();
94      }
95  
96      @Exported
97      public final CodelineCollectionWeb getCodelines() {
98          Collection<Codeline> codelines = this.subject.findAllDefiningDependency(true);
99  
100         if (codelines != null) {
101             return new CodelineCollectionWeb(codelines, Messages._Codelines());
102         } else {
103             return null;
104         }
105     }
106 
107     @Exported
108     public final CodelineCollectionWeb getCodelinesAnyVersion() {
109         Collection<Codeline> codelines = this.subject.findAllDefiningDependency(false);
110 
111         if (codelines != null) {
112             return new CodelineCollectionWeb(codelines, Messages._Dependency_CodelinesAnyVersion());
113         } else {
114             return null;
115         }
116     }
117 
118     @Exported
119     public final CodelineCollectionWeb getConsumers() {
120         Collection<Codeline> codelines = this.subject.findAllConsumers(true);
121 
122         if (codelines != null) {
123             return new CodelineCollectionWeb(codelines, Messages._Dependency_ConsumersAnyVersion());
124         } else {
125             return null;
126         }
127     }
128 
129     @Exported
130     public final CodelineCollectionWeb getConsumersAnyVersion() {
131         Collection<Codeline> codelines = this.subject.findAllConsumers(false);
132 
133         if (codelines != null) {
134             return new CodelineCollectionWeb(codelines, Messages._Dependency_ConsumersAnyVersion());
135         } else {
136             return null;
137         }
138     }
139 
140     public Object getDynamic(final String token, final StaplerRequest req, final StaplerResponse rsp) {
141         if (StringUtils.isNotBlank(token)) {
142             if (StringUtils.isBlank(subject.getArtifactId())) {
143                 Dependency dependency = new Dependency();
144                 dependency.setGroupId(subject.getGroupId());
145                 dependency.setArtifactId(token);
146 
147                 return new DependencyWeb(dependency);
148             } else if (StringUtils.isBlank(subject.getVersion())) {
149                 Dependency dependency = new Dependency();
150                 dependency.setGroupId(subject.getGroupId());
151                 dependency.setArtifactId(subject.getArtifactId());
152                 dependency.setVersion(token);
153 
154                 return new DependencyWeb(dependency);
155             }
156         }
157 
158         return null;
159     }
160 }