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.database.ArchivaDatabaseException;
27 import org.apache.maven.archiva.database.ObjectNotFoundException;
28 import org.apache.maven.archiva.database.browsing.RepositoryBrowsing;
29 import org.apache.maven.archiva.model.ArchivaProjectModel;
30 import org.apache.maven.archiva.security.AccessDeniedException;
31 import org.apache.maven.archiva.security.ArchivaSecurityException;
32 import org.apache.maven.archiva.security.PrincipalNotFoundException;
33 import org.apache.maven.archiva.security.UserRepositories;
34 import org.apache.maven.archiva.security.ArchivaXworkUser;
36 import com.opensymphony.xwork2.ActionContext;
37 import com.opensymphony.xwork2.Validateable;
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"
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;
65 private ArchivaXworkUser archivaXworkUser;
67 /* .\ Input Parameters \.________________________________________ */
69 private String groupId;
71 private String artifactId;
73 private String version;
75 private String repositoryId;
77 /* .\ Exposed Output Objects \.__________________________________ */
80 * The model of this versioned project.
82 private ArchivaProjectModel model;
85 * The list of artifacts that depend on this versioned project.
87 private List dependees;
90 * The reports associated with this versioned project.
94 private List mailingLists;
96 private List dependencies;
99 * Show the versioned project information tab. TODO: Change name to 'project'
101 public String artifact()
102 throws ObjectNotFoundException, ArchivaDatabaseException
107 repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
109 repoBrowsing.getRepositoryId( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
111 catch ( ObjectNotFoundException oe )
113 addActionError( "Unable to find project model for [" + groupId + ":" + artifactId + ":" + version + "]." );
122 * Show the artifact information tab.
124 public String dependencies()
125 throws ObjectNotFoundException, ArchivaDatabaseException
127 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
129 this.dependencies = model.getDependencies();
135 * Show the mailing lists information tab.
137 public String mailingLists()
138 throws ObjectNotFoundException, ArchivaDatabaseException
140 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
141 this.mailingLists = model.getMailingLists();
147 * Show the reports tab.
149 public String reports()
150 throws ObjectNotFoundException, ArchivaDatabaseException
152 System.out.println( "#### In reports." );
153 // TODO: hook up reports on project - this.reports = artifactsDatabase.findArtifactResults( groupId, artifactId,
155 System.out.println( "#### Found " + reports.size() + " reports." );
161 * Show the dependees (other artifacts that depend on this project) tab.
163 public String dependees()
164 throws ObjectNotFoundException, ArchivaDatabaseException
166 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
168 this.dependees = repoBrowsing.getUsedBy( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
174 * Show the dependencies of this versioned project tab.
176 public String dependencyTree()
177 throws ObjectNotFoundException, ArchivaDatabaseException
179 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
184 private String getPrincipal()
186 return archivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
189 private List<String> getObservableRepos()
193 return userRepositories.getObservableRepositoryIds( getPrincipal() );
195 catch ( PrincipalNotFoundException e )
197 getLogger().warn( e.getMessage(), e );
199 catch ( AccessDeniedException e )
201 getLogger().warn( e.getMessage(), e );
202 // TODO: pass this onto the screen.
204 catch ( ArchivaSecurityException e )
206 getLogger().warn( e.getMessage(), e );
208 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 getReports()
269 public List getMailingLists()
274 public List getDependencies()
279 public List getDependees()
284 public String getRepositoryId()
289 public void setRepositoryId( String repositoryId )
291 this.repositoryId = repositoryId;