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;
35 import org.codehaus.plexus.xwork.action.PlexusActionSupport;
37 import com.opensymphony.xwork.ActionContext;
38 import com.opensymphony.xwork.Validateable;
41 * Browse the repository.
43 * TODO change name to ShowVersionedAction to conform to terminology.
45 * @plexus.component role="com.opensymphony.xwork.Action" role-hint="showArtifactAction"
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;
100 * Show the versioned project information tab. TODO: Change name to 'project'
102 public String artifact()
103 throws ObjectNotFoundException, ArchivaDatabaseException
108 repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
110 repoBrowsing.getRepositoryId( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
112 catch ( ObjectNotFoundException oe )
114 addActionError( "Unable to find project model for [" + groupId + ":" + artifactId + ":" + version + "]." );
123 * Show the artifact information tab.
125 public String dependencies()
126 throws ObjectNotFoundException, ArchivaDatabaseException
128 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
130 this.dependencies = model.getDependencies();
136 * Show the mailing lists information tab.
138 public String mailingLists()
139 throws ObjectNotFoundException, ArchivaDatabaseException
141 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
142 this.mailingLists = model.getMailingLists();
148 * Show the reports tab.
150 public String reports()
151 throws ObjectNotFoundException, ArchivaDatabaseException
153 System.out.println( "#### In reports." );
154 // TODO: hook up reports on project - this.reports = artifactsDatabase.findArtifactResults( groupId, artifactId,
156 System.out.println( "#### Found " + reports.size() + " reports." );
162 * Show the dependees (other artifacts that depend on this project) tab.
164 public String dependees()
165 throws ObjectNotFoundException, ArchivaDatabaseException
167 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
169 this.dependees = repoBrowsing.getUsedBy( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
175 * Show the dependencies of this versioned project tab.
177 public String dependencyTree()
178 throws ObjectNotFoundException, ArchivaDatabaseException
180 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
185 private String getPrincipal()
187 return archivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
190 private List<String> getObservableRepos()
194 return userRepositories.getObservableRepositoryIds( getPrincipal() );
196 catch ( PrincipalNotFoundException e )
198 getLogger().warn( e.getMessage(), e );
200 catch ( AccessDeniedException e )
202 getLogger().warn( e.getMessage(), e );
203 // TODO: pass this onto the screen.
205 catch ( ArchivaSecurityException e )
207 getLogger().warn( e.getMessage(), e );
209 return Collections.emptyList();
212 public void validate()
214 if ( StringUtils.isBlank( groupId ) )
216 addActionError( "You must specify a group ID to browse" );
219 if ( StringUtils.isBlank( artifactId ) )
221 addActionError( "You must specify a artifact ID to browse" );
224 if ( StringUtils.isBlank( version ) )
226 addActionError( "You must specify a version to browse" );
230 public ArchivaProjectModel getModel()
235 public String getGroupId()
240 public void setGroupId( String groupId )
242 this.groupId = groupId;
245 public String getArtifactId()
250 public void setArtifactId( String artifactId )
252 this.artifactId = artifactId;
255 public String getVersion()
260 public void setVersion( String version )
262 this.version = version;
265 public List getReports()
270 public List getMailingLists()
275 public List getDependencies()
280 public List getDependees()
285 public String getRepositoryId()
290 public void setRepositoryId( String repositoryId )
292 this.repositoryId = repositoryId;