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 com.opensymphony.xwork.ActionContext;
26 import org.apache.commons.collections.CollectionUtils;
27 import org.apache.commons.lang.StringUtils;
28 import org.apache.maven.archiva.database.browsing.BrowsingResults;
29 import org.apache.maven.archiva.database.browsing.RepositoryBrowsing;
30 import org.apache.maven.archiva.security.*;
31 import org.apache.maven.archiva.security.ArchivaXworkUser;
32 import org.codehaus.plexus.xwork.action.PlexusActionSupport;
35 * Browse the repository.
37 * @todo cache browsing results.
38 * @todo implement repository selectors (all or specific repository)
39 * @todo implement security around browse (based on repository id at first)
40 * @plexus.component role="com.opensymphony.xwork.Action" role-hint="browseAction"
42 public class BrowseAction
43 extends PlexusActionSupport
46 * @plexus.requirement role-hint="default"
48 private RepositoryBrowsing repoBrowsing;
53 private UserRepositories userRepositories;
58 private ArchivaXworkUser archivaXworkUser;
60 private BrowsingResults results;
62 private String groupId;
64 private String artifactId;
66 private String repositoryId;
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 archivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
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()
179 public String getRepositoryId(){
184 public void setRepositoryId(String repositoryId){
186 this.repositoryId = repositoryId;