1 package org.apache.maven.archiva.web.action;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import java.util.Collections;
23 import java.util.List;
25 import com.opensymphony.xwork2.Validateable;
26 import org.apache.commons.lang.StringUtils;
27 import org.apache.maven.archiva.common.utils.VersionUtil;
28 import org.apache.maven.archiva.database.ArchivaDatabaseException;
29 import org.apache.maven.archiva.database.ObjectNotFoundException;
30 import org.apache.maven.archiva.database.browsing.RepositoryBrowsing;
31 import org.apache.maven.archiva.model.ArchivaProjectModel;
32 import org.apache.maven.archiva.model.Dependency;
33 import org.apache.maven.archiva.model.MailingList;
34 import org.apache.maven.archiva.security.AccessDeniedException;
35 import org.apache.maven.archiva.security.ArchivaSecurityException;
36 import org.apache.maven.archiva.security.PrincipalNotFoundException;
37 import org.apache.maven.archiva.security.UserRepositories;
40 * Browse the repository.
42 * TODO change name to ShowVersionedAction to conform to terminology.
44 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="showArtifactAction" instantiation-strategy="per-lookup"
46 public class ShowArtifactAction
47 extends PlexusActionSupport
48 implements Validateable
50 /* .\ Not Exposed \._____________________________________________ */
53 * @plexus.requirement role-hint="default"
55 private RepositoryBrowsing repoBrowsing;
60 private UserRepositories userRepositories;
62 /* .\ Exposed Output Objects \.__________________________________ */
64 private String groupId;
66 private String artifactId;
68 private String version;
70 private String repositoryId;
73 * The model of this versioned project.
75 private ArchivaProjectModel model;
78 * The list of artifacts that depend on this versioned project.
80 private List<ArchivaProjectModel> dependees;
82 private List<MailingList> mailingLists;
84 private List<Dependency> dependencies;
86 private List<String> snapshotVersions;
89 * Show the versioned project information tab. TODO: Change name to 'project'
91 public String artifact()
92 throws ObjectNotFoundException, ArchivaDatabaseException
96 if( VersionUtil.isSnapshot( version ) )
99 repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
101 this.snapshotVersions =
102 repoBrowsing.getOtherSnapshotVersions( getObservableRepos(), groupId, artifactId, version );
103 if( this.snapshotVersions.contains( version ) )
105 this.snapshotVersions.remove( version );
111 repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
115 repoBrowsing.getRepositoryId( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
117 catch ( ObjectNotFoundException e )
119 log.debug( e.getMessage(), e );
120 addActionError( e.getMessage() );
128 * Show the artifact information tab.
130 public String dependencies()
131 throws ObjectNotFoundException, ArchivaDatabaseException
133 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
135 this.dependencies = model.getDependencies();
141 * Show the mailing lists information tab.
143 public String mailingLists()
144 throws ObjectNotFoundException, ArchivaDatabaseException
146 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
147 this.mailingLists = model.getMailingLists();
153 * Show the reports tab.
155 public String reports()
156 throws ObjectNotFoundException, ArchivaDatabaseException
158 // TODO: hook up reports on project - this.reports = artifactsDatabase.findArtifactResults( groupId, artifactId,
165 * Show the dependees (other artifacts that depend on this project) tab.
167 public String dependees()
168 throws ObjectNotFoundException, ArchivaDatabaseException
170 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
172 this.dependees = repoBrowsing.getUsedBy( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
178 * Show the dependencies of this versioned project tab.
180 public String dependencyTree()
181 throws ObjectNotFoundException, ArchivaDatabaseException
183 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
188 private List<String> getObservableRepos()
192 return userRepositories.getObservableRepositoryIds( getPrincipal() );
194 catch ( PrincipalNotFoundException e )
196 log.warn( e.getMessage(), e );
198 catch ( AccessDeniedException e )
200 log.warn( e.getMessage(), e );
201 // TODO: pass this onto the screen.
203 catch ( ArchivaSecurityException e )
205 log.warn( e.getMessage(), e );
207 return Collections.emptyList();
211 public void validate()
213 if ( StringUtils.isBlank( groupId ) )
215 addActionError( "You must specify a group ID to browse" );
218 if ( StringUtils.isBlank( artifactId ) )
220 addActionError( "You must specify a artifact ID to browse" );
223 if ( StringUtils.isBlank( version ) )
225 addActionError( "You must specify a version to browse" );
229 public ArchivaProjectModel getModel()
234 public String getGroupId()
239 public void setGroupId( String groupId )
241 this.groupId = groupId;
244 public String getArtifactId()
249 public void setArtifactId( String artifactId )
251 this.artifactId = artifactId;
254 public String getVersion()
259 public void setVersion( String version )
261 this.version = version;
264 public List<MailingList> getMailingLists()
269 public List<Dependency> getDependencies()
274 public List<ArchivaProjectModel> getDependees()
279 public String getRepositoryId()
284 public void setRepositoryId( String repositoryId )
286 this.repositoryId = repositoryId;
289 public List<String> getSnapshotVersions()
291 return snapshotVersions;
294 public void setSnapshotVersions( List<String> snapshotVersions )
296 this.snapshotVersions = snapshotVersions;