001 /*
002 * ----------------------------------------------------------------------
003 * Copyright (C) 2009 Enrique Lara (k957@68k.org)
004 *
005 * TinLizard is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public License
007 * as published by the Free Software Foundation; either version 3.0
008 * of the License, or (at your option) any later version.
009 *
010 * TinLizard is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU Lesser General Public License for more details.
014 *
015 * You should have received a copy of the GNU Lesser General Public License
016 * along with TinLizard. If not, see http://www.gnu.org/licenses/.
017 * ----------------------------------------------------------------------
018 */
019 package tinlizard.web;
020
021 import tinlizard.model.Codeline;
022 import tinlizard.model.Dependency;
023
024 import tinlizard.util.Messages;
025
026 import java.util.ArrayList;
027 import java.util.Collection;
028 import java.util.HashSet;
029 import java.util.Set;
030
031 import org.codehaus.plexus.util.StringUtils;
032
033 import org.kohsuke.stapler.StaplerRequest;
034 import org.kohsuke.stapler.StaplerResponse;
035
036 /**
037 * Decorate Group for Stapler.
038 */
039 public final class GroupWeb extends DependencyWeb {
040 public GroupWeb(final Dependency c) {
041 super(c);
042
043 if (StringUtils.isBlank(c.getGroupId())) {
044 throw new IllegalStateException(Messages.error_1020());
045 }
046 }
047
048 public String getName() {
049 return getGroupId();
050 }
051
052 public String getArtifactId() {
053 return null;
054 }
055
056 public String getVersion() {
057 return null;
058 }
059
060 //XXX first level collection?
061 public Collection<ArtifactWeb> getArtifacts() {
062 Collection<ArtifactWeb> artifacts = new ArrayList<ArtifactWeb>();
063 Set<String> artifactIds = new HashSet<String>();
064
065 artifactIds.addAll(Dependency.findAllArtifactIds(subject.getGroupId()));
066 artifactIds.addAll(Codeline.findAllArtifactIds(subject.getGroupId()));
067
068 for (String artifactIdId : artifactIds) {
069 Dependency dependency = new Dependency();
070 dependency.setGroupId(subject.getGroupId());
071 dependency.setArtifactId(artifactIdId);
072
073 artifacts.add(new ArtifactWeb(dependency));
074 }
075
076 return artifacts;
077 }
078
079 public Object getDynamic(final String token, final StaplerRequest req, final StaplerResponse rsp) {
080 if (StringUtils.isNotBlank(token)) {
081 Dependency dependency = new Dependency();
082 dependency.setGroupId(subject.getGroupId());
083 dependency.setArtifactId(token);
084
085 return new ArtifactWeb(dependency);
086 }
087
088 return null;
089 }
090 }