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.ArrayList;
27  import java.util.Collection;
28  import java.util.HashSet;
29  import java.util.Set;
30  
31  import org.codehaus.plexus.util.StringUtils;
32  
33  import org.kohsuke.stapler.StaplerRequest;
34  import org.kohsuke.stapler.StaplerResponse;
35  
36  /***
37   * Decorate Group for Stapler.
38   */
39  public final class GroupWeb extends DependencyWeb {
40      public GroupWeb(final Dependency c) {
41          super(c);
42  
43          if (StringUtils.isBlank(c.getGroupId())) {
44              throw new IllegalStateException(Messages.error_1020());
45          }
46      }
47  
48      public String getName() {
49          return getGroupId();
50      }
51  
52      public String getArtifactId() {
53          return null;
54      }
55  
56      public String getVersion() {
57          return null;
58      }
59  
60      //XXX first level collection?
61      public Collection<ArtifactWeb> getArtifacts() {
62          Collection<ArtifactWeb> artifacts = new ArrayList<ArtifactWeb>();
63          Set<String> artifactIds = new HashSet<String>();
64  
65          artifactIds.addAll(Dependency.findAllArtifactIds(subject.getGroupId()));
66          artifactIds.addAll(Codeline.findAllArtifactIds(subject.getGroupId()));
67  
68          for (String artifactIdId : artifactIds) {
69              Dependency dependency = new Dependency();
70              dependency.setGroupId(subject.getGroupId());
71              dependency.setArtifactId(artifactIdId);
72  
73              artifacts.add(new ArtifactWeb(dependency));
74          }
75  
76          return artifacts;
77      }
78  
79      public Object getDynamic(final String token, final StaplerRequest req, final StaplerResponse rsp) {
80          if (StringUtils.isNotBlank(token)) {
81              Dependency dependency = new Dependency();
82              dependency.setGroupId(subject.getGroupId());
83              dependency.setArtifactId(token);
84  
85              return new ArtifactWeb(dependency);
86          }
87  
88          return null;
89      }
90  }