Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

DefaultRepositoryGroupService.java 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package org.apache.archiva.rest.services;
  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.archiva.admin.model.RepositoryAdminException;
  21. import org.apache.archiva.admin.model.beans.RepositoryGroup;
  22. import org.apache.archiva.admin.model.group.RepositoryGroupAdmin;
  23. import org.apache.archiva.rest.api.model.ActionStatus;
  24. import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
  25. import org.apache.archiva.rest.api.services.RepositoryGroupService;
  26. import org.apache.commons.lang3.StringUtils;
  27. import org.springframework.stereotype.Service;
  28. import javax.inject.Inject;
  29. import java.util.ArrayList;
  30. import java.util.List;
  31. /**
  32. * @author Olivier Lamy
  33. */
  34. @Service("repositoryGroupService#rest")
  35. public class DefaultRepositoryGroupService
  36. extends AbstractRestService
  37. implements RepositoryGroupService
  38. {
  39. @Inject
  40. private RepositoryGroupAdmin repositoryGroupAdmin;
  41. @Override
  42. public List<RepositoryGroup> getRepositoriesGroups()
  43. throws ArchivaRestServiceException
  44. {
  45. try
  46. {
  47. List<RepositoryGroup> repositoriesGroups =
  48. new ArrayList<>( repositoryGroupAdmin.getRepositoriesGroups().size() );
  49. for ( org.apache.archiva.admin.model.beans.RepositoryGroup repoGroup : repositoryGroupAdmin.getRepositoriesGroups() )
  50. {
  51. repositoriesGroups.add( new RepositoryGroup( repoGroup.getId(), new ArrayList<>(
  52. repoGroup.getRepositories() ) ).mergedIndexPath( repoGroup.getMergedIndexPath() ).mergedIndexTtl(
  53. repoGroup.getMergedIndexTtl() ).cronExpression( repoGroup.getCronExpression() ) );
  54. }
  55. return repositoriesGroups;
  56. }
  57. catch ( RepositoryAdminException e )
  58. {
  59. throw new ArchivaRestServiceException( e.getMessage(), e );
  60. }
  61. }
  62. @Override
  63. public RepositoryGroup getRepositoryGroup( String repositoryGroupId )
  64. throws ArchivaRestServiceException
  65. {
  66. for ( RepositoryGroup repositoryGroup : getRepositoriesGroups() )
  67. {
  68. if ( StringUtils.equals( repositoryGroupId, repositoryGroup.getId() ) )
  69. {
  70. return repositoryGroup;
  71. }
  72. }
  73. return null;
  74. }
  75. @Override
  76. public ActionStatus addRepositoryGroup( RepositoryGroup repoGroup )
  77. throws ArchivaRestServiceException
  78. {
  79. try
  80. {
  81. return new ActionStatus( repositoryGroupAdmin.addRepositoryGroup(
  82. new org.apache.archiva.admin.model.beans.RepositoryGroup( repoGroup.getId( ), new ArrayList<>(
  83. repoGroup.getRepositories( ) ) ).mergedIndexPath( repoGroup.getMergedIndexPath( ) ).mergedIndexTtl(
  84. repoGroup.getMergedIndexTtl( ) ).cronExpression( repoGroup.getCronExpression( ) ),
  85. getAuditInformation( ) ) );
  86. }
  87. catch ( RepositoryAdminException e )
  88. {
  89. throw new ArchivaRestServiceException( e.getMessage(), e );
  90. }
  91. }
  92. @Override
  93. public ActionStatus updateRepositoryGroup( RepositoryGroup repoGroup )
  94. throws ArchivaRestServiceException
  95. {
  96. try
  97. {
  98. return new ActionStatus( repositoryGroupAdmin.updateRepositoryGroup(
  99. new org.apache.archiva.admin.model.beans.RepositoryGroup( repoGroup.getId( ), new ArrayList<>(
  100. repoGroup.getRepositories( ) ) ).mergedIndexPath( repoGroup.getMergedIndexPath( ) ).mergedIndexTtl(
  101. repoGroup.getMergedIndexTtl( ) ).cronExpression( repoGroup.getCronExpression( ) ),
  102. getAuditInformation( ) ) );
  103. }
  104. catch ( RepositoryAdminException e )
  105. {
  106. throw new ArchivaRestServiceException( e.getMessage(), e );
  107. }
  108. }
  109. @Override
  110. public ActionStatus deleteRepositoryGroup( String repositoryGroupId )
  111. throws ArchivaRestServiceException
  112. {
  113. try
  114. {
  115. return new ActionStatus( repositoryGroupAdmin.deleteRepositoryGroup( repositoryGroupId, getAuditInformation( ) ) );
  116. }
  117. catch ( RepositoryAdminException e )
  118. {
  119. throw new ArchivaRestServiceException( e.getMessage(), e );
  120. }
  121. }
  122. @Override
  123. public ActionStatus addRepositoryToGroup( String repositoryGroupId, String repositoryId )
  124. throws ArchivaRestServiceException
  125. {
  126. try
  127. {
  128. return new ActionStatus( repositoryGroupAdmin.addRepositoryToGroup( repositoryGroupId, repositoryId, getAuditInformation( ) ) );
  129. }
  130. catch ( RepositoryAdminException e )
  131. {
  132. throw new ArchivaRestServiceException( e.getMessage(), e );
  133. }
  134. }
  135. @Override
  136. public ActionStatus deleteRepositoryFromGroup( String repositoryGroupId, String repositoryId )
  137. throws ArchivaRestServiceException
  138. {
  139. try
  140. {
  141. return new ActionStatus( repositoryGroupAdmin.deleteRepositoryFromGroup( repositoryGroupId, repositoryId,
  142. getAuditInformation( ) ) );
  143. }
  144. catch ( RepositoryAdminException e )
  145. {
  146. throw new ArchivaRestServiceException( e.getMessage(), e );
  147. }
  148. }
  149. }