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 org.apache.commons.lang.StringUtils;
26 import org.apache.maven.archiva.common.utils.VersionUtil;
27 import org.apache.maven.archiva.database.ArchivaDatabaseException;
28 import org.apache.maven.archiva.database.ObjectNotFoundException;
29 import org.apache.maven.archiva.database.browsing.RepositoryBrowsing;
30 import org.apache.maven.archiva.model.ArchivaProjectModel;
31 import org.apache.maven.archiva.model.Dependency;
32 import org.apache.maven.archiva.model.MailingList;
33 import org.apache.maven.archiva.security.AccessDeniedException;
34 import org.apache.maven.archiva.security.ArchivaSecurityException;
35 import org.apache.maven.archiva.security.PrincipalNotFoundException;
36 import org.apache.maven.archiva.security.UserRepositories;
37 import org.apache.maven.archiva.security.ArchivaXworkUser;
39 import com.opensymphony.xwork2.ActionContext;
40 import com.opensymphony.xwork2.Validateable;
43 * Browse the repository.
45 * TODO change name to ShowVersionedAction to conform to terminology.
47 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="showArtifactAction" instantiation-strategy="per-lookup"
49 public class ShowArtifactAction
50 extends PlexusActionSupport
51 implements Validateable
53 /* .\ Not Exposed \._____________________________________________ */
56 * @plexus.requirement role-hint="default"
58 private RepositoryBrowsing repoBrowsing;
63 private UserRepositories userRepositories;
68 private ArchivaXworkUser archivaXworkUser;
70 /* .\ Input Parameters \.________________________________________ */
72 private String groupId;
74 private String artifactId;
76 private String version;
78 private String repositoryId;
80 /* .\ Exposed Output Objects \.__________________________________ */
83 * The model of this versioned project.
85 private ArchivaProjectModel model;
88 * The list of artifacts that depend on this versioned project.
90 private List<ArchivaProjectModel> dependees;
92 private List<MailingList> mailingLists;
94 private List<Dependency> dependencies;
96 private List<String> snapshotVersions;
99 * Show the versioned project information tab. TODO: Change name to 'project'
101 public String artifact()
102 throws ObjectNotFoundException, ArchivaDatabaseException
106 if( VersionUtil.isSnapshot( version ) )
109 repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
111 this.snapshotVersions =
112 repoBrowsing.getOtherSnapshotVersions( getObservableRepos(), groupId, artifactId, version );
113 if( this.snapshotVersions.contains( version ) )
115 this.snapshotVersions.remove( version );
121 repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
125 repoBrowsing.getRepositoryId( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
127 catch ( ObjectNotFoundException e )
129 log.debug( e.getMessage(), e );
130 addActionError( e.getMessage() );
138 * Show the artifact information tab.
140 public String dependencies()
141 throws ObjectNotFoundException, ArchivaDatabaseException
143 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
145 this.dependencies = model.getDependencies();
151 * Show the mailing lists information tab.
153 public String mailingLists()
154 throws ObjectNotFoundException, ArchivaDatabaseException
156 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
157 this.mailingLists = model.getMailingLists();
163 * Show the reports tab.
165 public String reports()
166 throws ObjectNotFoundException, ArchivaDatabaseException
168 // TODO: hook up reports on project - this.reports = artifactsDatabase.findArtifactResults( groupId, artifactId,
175 * Show the dependees (other artifacts that depend on this project) tab.
177 public String dependees()
178 throws ObjectNotFoundException, ArchivaDatabaseException
180 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
182 this.dependees = repoBrowsing.getUsedBy( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
188 * Show the dependencies of this versioned project tab.
190 public String dependencyTree()
191 throws ObjectNotFoundException, ArchivaDatabaseException
193 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
198 @SuppressWarnings("unchecked")
199 private String getPrincipal()
201 return archivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
204 private List<String> getObservableRepos()
208 return userRepositories.getObservableRepositoryIds( getPrincipal() );
210 catch ( PrincipalNotFoundException e )
212 log.warn( e.getMessage(), e );
214 catch ( AccessDeniedException e )
216 log.warn( e.getMessage(), e );
217 // TODO: pass this onto the screen.
219 catch ( ArchivaSecurityException e )
221 log.warn( e.getMessage(), e );
223 return Collections.emptyList();
227 public void validate()
229 if ( StringUtils.isBlank( groupId ) )
231 addActionError( "You must specify a group ID to browse" );
234 if ( StringUtils.isBlank( artifactId ) )
236 addActionError( "You must specify a artifact ID to browse" );
239 if ( StringUtils.isBlank( version ) )
241 addActionError( "You must specify a version to browse" );
245 public ArchivaProjectModel getModel()
250 public String getGroupId()
255 public void setGroupId( String groupId )
257 this.groupId = groupId;
260 public String getArtifactId()
265 public void setArtifactId( String artifactId )
267 this.artifactId = artifactId;
270 public String getVersion()
275 public void setVersion( String version )
277 this.version = version;
280 public List<MailingList> getMailingLists()
285 public List<Dependency> getDependencies()
290 public List<ArchivaProjectModel> getDependees()
295 public String getRepositoryId()
300 public void setRepositoryId( String repositoryId )
302 this.repositoryId = repositoryId;
305 public List<String> getSnapshotVersions()
307 return snapshotVersions;
310 public void setSnapshotVersions( List<String> snapshotVersions )
312 this.snapshotVersions = snapshotVersions;