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 org.apache.commons.collections.CollectionUtils;
23 import org.apache.commons.lang.StringUtils;
24 import org.apache.maven.archiva.database.browsing.BrowsingResults;
25 import org.apache.maven.archiva.database.browsing.RepositoryBrowsing;
26 import org.apache.maven.archiva.security.AccessDeniedException;
27 import org.apache.maven.archiva.security.ArchivaSecurityException;
28 import org.apache.maven.archiva.security.ArchivaUser;
29 import org.apache.maven.archiva.security.PrincipalNotFoundException;
30 import org.apache.maven.archiva.security.UserRepositories;
31 import org.codehaus.plexus.xwork.action.PlexusActionSupport;
33 import java.util.Collections;
34 import java.util.List;
37 * Browse the repository.
39 * @todo cache browsing results.
40 * @todo implement repository selectors (all or specific repository)
41 * @todo implement security around browse (based on repository id at first)
42 * @plexus.component role="com.opensymphony.xwork.Action" role-hint="browseAction"
44 public class BrowseAction
45 extends PlexusActionSupport
48 * @plexus.requirement role-hint="default"
50 private RepositoryBrowsing repoBrowsing;
55 private UserRepositories userRepositories;
58 * @plexus.requirement role-hint="xwork"
60 private ArchivaUser archivaUser;
62 private BrowsingResults results;
64 private String groupId;
66 private String artifactId;
68 public String browse()
70 List<String> selectedRepos = getObservableRepos();
71 if ( CollectionUtils.isEmpty( selectedRepos ) )
73 return GlobalResults.ACCESS_TO_NO_REPOS;
76 this.results = repoBrowsing.getRoot( getPrincipal(), selectedRepos );
80 public String browseGroup()
82 if ( StringUtils.isEmpty( groupId ) )
85 addActionError( "You must specify a group ID to browse" );
89 List<String> selectedRepos = getObservableRepos();
90 if ( CollectionUtils.isEmpty( selectedRepos ) )
92 return GlobalResults.ACCESS_TO_NO_REPOS;
96 this.results = repoBrowsing.selectGroupId( getPrincipal(), selectedRepos, groupId );
100 public String browseArtifact()
102 if ( StringUtils.isEmpty( groupId ) )
105 addActionError( "You must specify a group ID to browse" );
109 if ( StringUtils.isEmpty( artifactId ) )
112 addActionError( "You must specify a artifact ID to browse" );
116 List<String> selectedRepos = getObservableRepos();
117 if ( CollectionUtils.isEmpty( selectedRepos ) )
119 return GlobalResults.ACCESS_TO_NO_REPOS;
123 this.results = repoBrowsing.selectArtifactId( getPrincipal(), selectedRepos, groupId, artifactId );
127 private String getPrincipal()
129 return archivaUser.getActivePrincipal();
132 private List<String> getObservableRepos()
136 return userRepositories.getObservableRepositoryIds( getPrincipal() );
138 catch ( PrincipalNotFoundException e )
140 getLogger().warn( e.getMessage(), e );
142 catch ( AccessDeniedException e )
144 getLogger().warn( e.getMessage(), e );
145 // TODO: pass this onto the screen.
147 catch ( ArchivaSecurityException e )
149 getLogger().warn( e.getMessage(), e );
151 return Collections.emptyList();
154 public String getGroupId()
159 public void setGroupId( String groupId )
161 this.groupId = groupId;
164 public String getArtifactId()
169 public void setArtifactId( String artifactId )
171 this.artifactId = artifactId;
174 public BrowsingResults getResults()