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 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 org.apache.commons.lang.StringUtils;
  21. import org.apache.maven.archiva.database.browsing.BrowsingResults;
  22. import org.apache.maven.archiva.database.browsing.RepositoryBrowsing;
  23. import org.apache.maven.archiva.security.AccessDeniedException;
  24. import org.apache.maven.archiva.security.ArchivaSecurityException;
  25. import org.apache.maven.archiva.security.ArchivaUser;
  26. import org.apache.maven.archiva.security.PrincipalNotFoundException;
  27. import org.apache.maven.archiva.security.UserRepositories;
  28. import org.codehaus.plexus.xwork.action.PlexusActionSupport;
  29. import java.util.Collections;
  30. import java.util.List;
  31. /**
  32. * Browse the repository.
  33. *
  34. * @todo cache browsing results.
  35. * @todo implement repository selectors (all or specific repository)
  36. * @todo implement security around browse (based on repository id at first)
  37. * @plexus.component role="com.opensymphony.xwork.Action" role-hint="browseAction"
  38. */
  39. public class BrowseAction
  40. extends PlexusActionSupport
  41. {
  42. /**
  43. * @plexus.requirement role-hint="default"
  44. */
  45. private RepositoryBrowsing repoBrowsing;
  46. /**
  47. * @plexus.requirement
  48. */
  49. private UserRepositories userRepositories;
  50. /**
  51. * @plexus.requirement role-hint="xwork"
  52. */
  53. private ArchivaUser archivaUser;
  54. private BrowsingResults results;
  55. private String groupId;
  56. private String artifactId;
  57. public String browse()
  58. {
  59. this.results = repoBrowsing.getRoot( getPrincipal(), getObservableRepos() );
  60. return SUCCESS;
  61. }
  62. public String browseGroup()
  63. {
  64. if ( StringUtils.isEmpty( groupId ) )
  65. {
  66. // TODO: i18n
  67. addActionError( "You must specify a group ID to browse" );
  68. return ERROR;
  69. }
  70. this.results = repoBrowsing.selectGroupId( getPrincipal(), getObservableRepos(), groupId );
  71. return SUCCESS;
  72. }
  73. public String browseArtifact()
  74. {
  75. if ( StringUtils.isEmpty( groupId ) )
  76. {
  77. // TODO: i18n
  78. addActionError( "You must specify a group ID to browse" );
  79. return ERROR;
  80. }
  81. if ( StringUtils.isEmpty( artifactId ) )
  82. {
  83. // TODO: i18n
  84. addActionError( "You must specify a artifact ID to browse" );
  85. return ERROR;
  86. }
  87. this.results = repoBrowsing.selectArtifactId( getPrincipal(), getObservableRepos(), groupId, artifactId );
  88. return SUCCESS;
  89. }
  90. private String getPrincipal()
  91. {
  92. return archivaUser.getActivePrincipal();
  93. }
  94. private List<String> getObservableRepos()
  95. {
  96. try
  97. {
  98. return userRepositories.getObservableRepositoryIds( getPrincipal() );
  99. }
  100. catch ( PrincipalNotFoundException e )
  101. {
  102. getLogger().warn( e.getMessage(), e );
  103. }
  104. catch ( AccessDeniedException e )
  105. {
  106. getLogger().warn( e.getMessage(), e );
  107. // TODO: pass this onto the screen.
  108. }
  109. catch ( ArchivaSecurityException e )
  110. {
  111. getLogger().warn( e.getMessage(), e );
  112. }
  113. return Collections.emptyList();
  114. }
  115. public String getGroupId()
  116. {
  117. return groupId;
  118. }
  119. public void setGroupId( String groupId )
  120. {
  121. this.groupId = groupId;
  122. }
  123. public String getArtifactId()
  124. {
  125. return artifactId;
  126. }
  127. public void setArtifactId( String artifactId )
  128. {
  129. this.artifactId = artifactId;
  130. }
  131. public BrowsingResults getResults()
  132. {
  133. return results;
  134. }
  135. }