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.security.AccessDeniedException;
32 import org.apache.maven.archiva.security.ArchivaSecurityException;
33 import org.apache.maven.archiva.security.PrincipalNotFoundException;
34 import org.apache.maven.archiva.security.UserRepositories;
35 import org.apache.maven.archiva.security.ArchivaXworkUser;
37 import com.opensymphony.xwork2.ActionContext;
38 import com.opensymphony.xwork2.Validateable;
41 * Browse the repository.
43 * TODO change name to ShowVersionedAction to conform to terminology.
45 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="showArtifactAction" instantiation-strategy="per-lookup"
47 public class ShowArtifactAction
48 extends PlexusActionSupport
49 implements Validateable
51 /* .\ Not Exposed \._____________________________________________ */
54 * @plexus.requirement role-hint="default"
56 private RepositoryBrowsing repoBrowsing;
61 private UserRepositories userRepositories;
66 private ArchivaXworkUser archivaXworkUser;
68 /* .\ Input Parameters \.________________________________________ */
70 private String groupId;
72 private String artifactId;
74 private String version;
76 private String repositoryId;
78 /* .\ Exposed Output Objects \.__________________________________ */
81 * The model of this versioned project.
83 private ArchivaProjectModel model;
86 * The list of artifacts that depend on this versioned project.
88 private List dependees;
91 * The reports associated with this versioned project.
95 private List mailingLists;
97 private List dependencies;
99 private List<String> snapshotVersions;
102 * Show the versioned project information tab. TODO: Change name to 'project'
104 public String artifact()
105 throws ObjectNotFoundException, ArchivaDatabaseException
109 if( VersionUtil.isSnapshot( version ) )
112 repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
114 this.snapshotVersions =
115 repoBrowsing.getOtherSnapshotVersions( getObservableRepos(), groupId, artifactId, version );
116 if( this.snapshotVersions.contains( version ) )
118 this.snapshotVersions.remove( version );
124 repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
128 repoBrowsing.getRepositoryId( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
130 catch ( ObjectNotFoundException e )
132 getLogger().debug( e.getMessage(), e );
133 addActionError( e.getMessage() );
141 * Show the artifact information tab.
143 public String dependencies()
144 throws ObjectNotFoundException, ArchivaDatabaseException
146 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
148 this.dependencies = model.getDependencies();
154 * Show the mailing lists information tab.
156 public String mailingLists()
157 throws ObjectNotFoundException, ArchivaDatabaseException
159 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
160 this.mailingLists = model.getMailingLists();
166 * Show the reports tab.
168 public String reports()
169 throws ObjectNotFoundException, ArchivaDatabaseException
171 System.out.println( "#### In reports." );
172 // TODO: hook up reports on project - this.reports = artifactsDatabase.findArtifactResults( groupId, artifactId,
174 System.out.println( "#### Found " + reports.size() + " reports." );
180 * Show the dependees (other artifacts that depend on this project) tab.
182 public String dependees()
183 throws ObjectNotFoundException, ArchivaDatabaseException
185 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
187 this.dependees = repoBrowsing.getUsedBy( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
193 * Show the dependencies of this versioned project tab.
195 public String dependencyTree()
196 throws ObjectNotFoundException, ArchivaDatabaseException
198 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
203 private String getPrincipal()
205 return archivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
208 private List<String> getObservableRepos()
212 return userRepositories.getObservableRepositoryIds( getPrincipal() );
214 catch ( PrincipalNotFoundException e )
216 getLogger().warn( e.getMessage(), e );
218 catch ( AccessDeniedException e )
220 getLogger().warn( e.getMessage(), e );
221 // TODO: pass this onto the screen.
223 catch ( ArchivaSecurityException e )
225 getLogger().warn( e.getMessage(), e );
227 return Collections.emptyList();
231 public void validate()
233 if ( StringUtils.isBlank( groupId ) )
235 addActionError( "You must specify a group ID to browse" );
238 if ( StringUtils.isBlank( artifactId ) )
240 addActionError( "You must specify a artifact ID to browse" );
243 if ( StringUtils.isBlank( version ) )
245 addActionError( "You must specify a version to browse" );
249 public ArchivaProjectModel getModel()
254 public String getGroupId()
259 public void setGroupId( String groupId )
261 this.groupId = groupId;
264 public String getArtifactId()
269 public void setArtifactId( String artifactId )
271 this.artifactId = artifactId;
274 public String getVersion()
279 public void setVersion( String version )
281 this.version = version;
284 public List getReports()
289 public List getMailingLists()
294 public List getDependencies()
299 public List getDependees()
304 public String getRepositoryId()
309 public void setRepositoryId( String repositoryId )
311 this.repositoryId = repositoryId;
314 public List<String> getSnapshotVersions()
316 return snapshotVersions;
319 public void setSnapshotVersions( List<String> snapshotVersions )
321 this.snapshotVersions = snapshotVersions;