You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BrowseAction.java 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. package org.apache.maven.archiva.web.action;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import java.util.Collections;
  21. import java.util.List;
  22. import com.opensymphony.xwork2.ActionContext;
  23. import org.apache.commons.collections.CollectionUtils;
  24. import org.apache.commons.lang.StringUtils;
  25. import org.apache.maven.archiva.database.browsing.BrowsingResults;
  26. import org.apache.maven.archiva.database.browsing.RepositoryBrowsing;
  27. import org.apache.maven.archiva.security.*;
  28. import org.apache.maven.archiva.security.ArchivaXworkUser;
  29. /**
  30. * Browse the repository.
  31. *
  32. * @todo cache browsing results.
  33. * @todo implement repository selectors (all or specific repository)
  34. * @todo implement security around browse (based on repository id at first)
  35. * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="browseAction"
  36. */
  37. public class BrowseAction
  38. extends PlexusActionSupport
  39. {
  40. /**
  41. * @plexus.requirement role-hint="default"
  42. */
  43. private RepositoryBrowsing repoBrowsing;
  44. /**
  45. * @plexus.requirement
  46. */
  47. private UserRepositories userRepositories;
  48. /**
  49. * @plexus.requirement
  50. */
  51. private ArchivaXworkUser archivaXworkUser;
  52. private BrowsingResults results;
  53. private String groupId;
  54. private String artifactId;
  55. private String repositoryId;
  56. public String browse()
  57. {
  58. List<String> selectedRepos = getObservableRepos();
  59. if ( CollectionUtils.isEmpty( selectedRepos ) )
  60. {
  61. return GlobalResults.ACCESS_TO_NO_REPOS;
  62. }
  63. this.results = repoBrowsing.getRoot( getPrincipal(), selectedRepos );
  64. return SUCCESS;
  65. }
  66. public String browseGroup()
  67. {
  68. if ( StringUtils.isEmpty( groupId ) )
  69. {
  70. // TODO: i18n
  71. addActionError( "You must specify a group ID to browse" );
  72. return ERROR;
  73. }
  74. List<String> selectedRepos = getObservableRepos();
  75. if ( CollectionUtils.isEmpty( selectedRepos ) )
  76. {
  77. return GlobalResults.ACCESS_TO_NO_REPOS;
  78. }
  79. this.results = repoBrowsing.selectGroupId( getPrincipal(), selectedRepos, groupId );
  80. return SUCCESS;
  81. }
  82. public String browseArtifact()
  83. {
  84. if ( StringUtils.isEmpty( groupId ) )
  85. {
  86. // TODO: i18n
  87. addActionError( "You must specify a group ID to browse" );
  88. return ERROR;
  89. }
  90. if ( StringUtils.isEmpty( artifactId ) )
  91. {
  92. // TODO: i18n
  93. addActionError( "You must specify a artifact ID to browse" );
  94. return ERROR;
  95. }
  96. List<String> selectedRepos = getObservableRepos();
  97. if ( CollectionUtils.isEmpty( selectedRepos ) )
  98. {
  99. return GlobalResults.ACCESS_TO_NO_REPOS;
  100. }
  101. this.results = repoBrowsing.selectArtifactId( getPrincipal(), selectedRepos, groupId, artifactId );
  102. return SUCCESS;
  103. }
  104. private String getPrincipal()
  105. {
  106. return archivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
  107. }
  108. private List<String> getObservableRepos()
  109. {
  110. try
  111. {
  112. return userRepositories.getObservableRepositoryIds( getPrincipal() );
  113. }
  114. catch ( PrincipalNotFoundException e )
  115. {
  116. getLogger().warn( e.getMessage(), e );
  117. }
  118. catch ( AccessDeniedException e )
  119. {
  120. getLogger().warn( e.getMessage(), e );
  121. // TODO: pass this onto the screen.
  122. }
  123. catch ( ArchivaSecurityException e )
  124. {
  125. getLogger().warn( e.getMessage(), e );
  126. }
  127. return Collections.emptyList();
  128. }
  129. public String getGroupId()
  130. {
  131. return groupId;
  132. }
  133. public void setGroupId( String groupId )
  134. {
  135. this.groupId = groupId;
  136. }
  137. public String getArtifactId()
  138. {
  139. return artifactId;
  140. }
  141. public void setArtifactId( String artifactId )
  142. {
  143. this.artifactId = artifactId;
  144. }
  145. public BrowsingResults getResults()
  146. {
  147. return results;
  148. }
  149. public String getRepositoryId(){
  150. return repositoryId;
  151. }
  152. public void setRepositoryId(String repositoryId){
  153. this.repositoryId = repositoryId;
  154. }
  155. }