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 com.opensymphony.xwork.Validateable;
24 import org.apache.commons.lang.StringUtils;
25 import org.apache.maven.archiva.database.ArchivaDatabaseException;
26 import org.apache.maven.archiva.database.ObjectNotFoundException;
27 import org.apache.maven.archiva.database.browsing.RepositoryBrowsing;
28 import org.apache.maven.archiva.model.ArchivaProjectModel;
29 import org.apache.maven.archiva.security.AccessDeniedException;
30 import org.apache.maven.archiva.security.ArchivaSecurityException;
31 import org.apache.maven.archiva.security.ArchivaUser;
32 import org.apache.maven.archiva.security.PrincipalNotFoundException;
33 import org.apache.maven.archiva.security.UserRepositories;
34 import org.codehaus.plexus.xwork.action.PlexusActionSupport;
36 import java.util.Collections;
37 import java.util.List;
40 * Browse the repository.
42 * TODO change name to ShowVersionedAction to conform to terminology.
43 * @plexus.component role="com.opensymphony.xwork.Action" role-hint="showArtifactAction"
45 public class ShowArtifactAction
46 extends PlexusActionSupport
47 implements Validateable
49 /* .\ Not Exposed \._____________________________________________ */
52 * @plexus.requirement role-hint="default"
54 private RepositoryBrowsing repoBrowsing;
59 private UserRepositories userRepositories;
62 * @plexus.requirement role-hint="xwork"
64 private ArchivaUser archivaUser;
66 /* .\ Input Parameters \.________________________________________ */
68 private String groupId;
70 private String artifactId;
72 private String version;
74 /* .\ Exposed Output Objects \.__________________________________ */
77 * The model of this versioned project.
79 private ArchivaProjectModel model;
82 * The list of artifacts that depend on this versioned project.
84 private List dependees;
87 * The reports associated with this versioned project.
91 private List mailingLists;
93 private List dependencies;
96 * Show the versioned project information tab.
98 * TODO: Change name to 'project'
100 public String artifact()
101 throws ObjectNotFoundException, ArchivaDatabaseException
105 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
107 catch ( ObjectNotFoundException oe )
109 addActionError( "Unable to find project model for [" + groupId + ":" + artifactId + ":" + version + "]." );
118 * Show the artifact information tab.
120 public String dependencies()
121 throws ObjectNotFoundException, ArchivaDatabaseException
123 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
125 this.dependencies = model.getDependencies();
131 * Show the mailing lists information tab.
133 public String mailingLists()
134 throws ObjectNotFoundException, ArchivaDatabaseException
136 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
137 this.mailingLists = model.getMailingLists();
143 * Show the reports tab.
145 public String reports()
146 throws ObjectNotFoundException, ArchivaDatabaseException
148 System.out.println( "#### In reports." );
149 // TODO: hook up reports on project - this.reports = artifactsDatabase.findArtifactResults( groupId, artifactId, version );
150 System.out.println( "#### Found " + reports.size() + " reports." );
156 * Show the dependees (other artifacts that depend on this project) tab.
158 public String dependees()
159 throws ObjectNotFoundException, ArchivaDatabaseException
161 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
163 this.dependees = repoBrowsing.getUsedBy( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
169 * Show the dependencies of this versioned project tab.
171 public String dependencyTree()
172 throws ObjectNotFoundException, ArchivaDatabaseException
174 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
179 private String getPrincipal()
181 return archivaUser.getActivePrincipal();
184 private List<String> getObservableRepos()
188 return userRepositories.getObservableRepositoryIds( getPrincipal() );
190 catch ( PrincipalNotFoundException e )
192 getLogger().warn( e.getMessage(), e );
194 catch ( AccessDeniedException e )
196 getLogger().warn( e.getMessage(), e );
197 // TODO: pass this onto the screen.
199 catch ( ArchivaSecurityException e )
201 getLogger().warn( e.getMessage(), e );
203 return Collections.emptyList();
206 public void validate()
208 if ( StringUtils.isBlank( groupId ) )
210 addActionError( "You must specify a group ID to browse" );
213 if ( StringUtils.isBlank( artifactId ) )
215 addActionError( "You must specify a artifact ID to browse" );
218 if ( StringUtils.isBlank( version ) )
220 addActionError( "You must specify a version to browse" );
224 public ArchivaProjectModel getModel()
229 public String getGroupId()
234 public void setGroupId( String groupId )
236 this.groupId = groupId;
239 public String getArtifactId()
244 public void setArtifactId( String artifactId )
246 this.artifactId = artifactId;
249 public String getVersion()
254 public void setVersion( String version )
256 this.version = version;
259 public List getReports()
264 public List getMailingLists()
269 public List getDependencies()
274 public List getDependees()