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.xwork2.ActionContext;
26 import org.apache.commons.collections.CollectionUtils;
27 import org.apache.commons.lang.StringUtils;
28 import org.apache.maven.archiva.database.ArchivaDatabaseException;
29 import org.apache.maven.archiva.database.ObjectNotFoundException;
30 import org.apache.maven.archiva.database.browsing.BrowsingResults;
31 import org.apache.maven.archiva.database.browsing.RepositoryBrowsing;
32 import org.apache.maven.archiva.model.ArchivaProjectModel;
33 import org.apache.maven.archiva.security.*;
36 * Browse the repository.
38 * @todo cache browsing results.
39 * @todo implement repository selectors (all or specific repository)
40 * @todo implement security around browse (based on repository id at first)
41 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="browseAction"
43 public class BrowseAction
44 extends PlexusActionSupport
47 * @plexus.requirement role-hint="default"
49 private RepositoryBrowsing repoBrowsing;
54 private UserRepositories userRepositories;
59 private ArchivaXworkUser archivaXworkUser;
61 private BrowsingResults results;
63 private String groupId;
65 private String artifactId;
67 private String repositoryId;
69 private ArchivaProjectModel sharedModel;
71 public String browse()
73 List<String> selectedRepos = getObservableRepos();
74 if ( CollectionUtils.isEmpty( selectedRepos ) )
76 return GlobalResults.ACCESS_TO_NO_REPOS;
79 this.results = repoBrowsing.getRoot( getPrincipal(), selectedRepos );
83 public String browseGroup()
85 if ( StringUtils.isEmpty( groupId ) )
88 addActionError( "You must specify a group ID to browse" );
92 List<String> selectedRepos = getObservableRepos();
93 if ( CollectionUtils.isEmpty( selectedRepos ) )
95 return GlobalResults.ACCESS_TO_NO_REPOS;
99 this.results = repoBrowsing.selectGroupId( getPrincipal(), selectedRepos, groupId );
103 public String browseArtifact()
105 if ( StringUtils.isEmpty( groupId ) )
108 addActionError( "You must specify a group ID to browse" );
112 if ( StringUtils.isEmpty( artifactId ) )
115 addActionError( "You must specify a artifact ID to browse" );
119 List<String> selectedRepos = getObservableRepos();
120 if ( CollectionUtils.isEmpty( selectedRepos ) )
122 return GlobalResults.ACCESS_TO_NO_REPOS;
125 this.results = repoBrowsing.selectArtifactId( getPrincipal(), selectedRepos, groupId, artifactId );
127 populateSharedModel();
132 private void populateSharedModel()
134 sharedModel = new ArchivaProjectModel();
135 sharedModel.setGroupId( groupId );
136 sharedModel.setArtifactId( artifactId );
137 boolean isFirstVersion = true;
139 for( String version : this.results.getVersions() )
143 ArchivaProjectModel model =
144 repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
152 if ( sharedModel.getPackaging() != null &&
153 !StringUtils.equalsIgnoreCase( sharedModel.getPackaging(), model.getPackaging() ) )
155 sharedModel.setPackaging( null );
158 if ( sharedModel.getName() != null &&
159 !StringUtils.equalsIgnoreCase( sharedModel.getName(), model.getName() ) )
161 sharedModel.setName( "" );
164 if ( sharedModel.getDescription() != null &&
165 !StringUtils.equalsIgnoreCase( sharedModel.getDescription(), model.getDescription() ) )
167 sharedModel.setDescription( null );
170 if ( sharedModel.getIssueManagement() != null &&
171 !StringUtils.equalsIgnoreCase( sharedModel.getIssueManagement().getUrl(), model.getIssueManagement().getUrl() ) )
173 sharedModel.setIssueManagement( null );
176 if ( sharedModel.getCiManagement() != null &&
177 !StringUtils.equalsIgnoreCase( sharedModel.getCiManagement().getUrl(), model.getCiManagement().getUrl() ) )
179 sharedModel.setCiManagement( null );
182 if ( sharedModel.getOrganization() != null &&
183 !StringUtils.equalsIgnoreCase( sharedModel.getOrganization().getName(), model.getOrganization().getName() ) )
185 sharedModel.setOrganization( null );
188 if ( sharedModel.getUrl() != null && !StringUtils.equalsIgnoreCase( sharedModel.getUrl(), model.getUrl() ) )
190 sharedModel.setUrl( null );
194 isFirstVersion = false;
196 catch ( ObjectNotFoundException e )
198 getLogger().debug( e.getMessage(), e );
200 catch ( ArchivaDatabaseException e )
202 getLogger().debug( e.getMessage(), e );
207 private String getPrincipal()
209 return archivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
212 private List<String> getObservableRepos()
216 return userRepositories.getObservableRepositoryIds( getPrincipal() );
218 catch ( PrincipalNotFoundException e )
220 getLogger().warn( e.getMessage(), e );
222 catch ( AccessDeniedException e )
224 getLogger().warn( e.getMessage(), e );
225 // TODO: pass this onto the screen.
227 catch ( ArchivaSecurityException e )
229 getLogger().warn( e.getMessage(), e );
231 return Collections.emptyList();
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 BrowsingResults getResults()
259 public String getRepositoryId(){
264 public void setRepositoryId(String repositoryId){
266 this.repositoryId = repositoryId;
269 public ArchivaProjectModel getSharedModel()
274 public void setSharedModel( ArchivaProjectModel sharedModel )
276 this.sharedModel = sharedModel;