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.

DefaultArchivaAdministrationService.java 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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.admin.ArchivaAdministration;
  22. import org.apache.archiva.admin.model.beans.*;
  23. import org.apache.archiva.repository.scanner.RepositoryContentConsumers;
  24. import org.apache.archiva.rest.api.model.AdminRepositoryConsumer;
  25. import org.apache.archiva.rest.api.services.ArchivaAdministrationService;
  26. import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
  27. import org.apache.archiva.rest.services.utils.AddAdminRepoConsumerClosure;
  28. import org.apache.archiva.rest.services.utils.AdminRepositoryConsumerComparator;
  29. import org.apache.commons.collections4.IterableUtils;
  30. import org.apache.commons.lang.StringUtils;
  31. import org.springframework.stereotype.Service;
  32. import javax.inject.Inject;
  33. import java.util.ArrayList;
  34. import java.util.Collections;
  35. import java.util.List;
  36. /**
  37. * @author Olivier Lamy
  38. * @since 1.4-M1
  39. */
  40. @Service ( "archivaAdministrationService#default" )
  41. public class DefaultArchivaAdministrationService
  42. extends AbstractRestService
  43. implements ArchivaAdministrationService
  44. {
  45. @Inject
  46. private ArchivaAdministration archivaAdministration;
  47. @Inject
  48. private RepositoryContentConsumers repoConsumerUtil;
  49. @Override
  50. public List<LegacyArtifactPath> getLegacyArtifactPaths()
  51. throws ArchivaRestServiceException
  52. {
  53. try
  54. {
  55. return archivaAdministration.getLegacyArtifactPaths();
  56. }
  57. catch ( RepositoryAdminException e )
  58. {
  59. throw new ArchivaRestServiceException( e.getMessage(), e );
  60. }
  61. }
  62. @Override
  63. public Boolean deleteLegacyArtifactPath( String path )
  64. throws ArchivaRestServiceException
  65. {
  66. try
  67. {
  68. archivaAdministration.deleteLegacyArtifactPath( path, getAuditInformation() );
  69. return Boolean.TRUE;
  70. }
  71. catch ( RepositoryAdminException e )
  72. {
  73. throw new ArchivaRestServiceException( e.getMessage(), e );
  74. }
  75. }
  76. @Override
  77. public Boolean addFileTypePattern( String fileTypeId, String pattern )
  78. throws ArchivaRestServiceException
  79. {
  80. try
  81. {
  82. archivaAdministration.addFileTypePattern( fileTypeId, pattern, getAuditInformation() );
  83. return Boolean.TRUE;
  84. }
  85. catch ( RepositoryAdminException e )
  86. {
  87. throw new ArchivaRestServiceException( e.getMessage(), e );
  88. }
  89. }
  90. @Override
  91. public Boolean removeFileTypePattern( String fileTypeId, String pattern )
  92. throws ArchivaRestServiceException
  93. {
  94. try
  95. {
  96. archivaAdministration.removeFileTypePattern( fileTypeId, pattern, getAuditInformation() );
  97. return Boolean.TRUE;
  98. }
  99. catch ( RepositoryAdminException e )
  100. {
  101. throw new ArchivaRestServiceException( e.getMessage(), e );
  102. }
  103. }
  104. @Override
  105. public FileType getFileType( String fileTypeId )
  106. throws ArchivaRestServiceException
  107. {
  108. try
  109. {
  110. return archivaAdministration.getFileType( fileTypeId );
  111. }
  112. catch ( RepositoryAdminException e )
  113. {
  114. throw new ArchivaRestServiceException( e.getMessage(), e );
  115. }
  116. }
  117. @Override
  118. public void addFileType( FileType fileType )
  119. throws ArchivaRestServiceException
  120. {
  121. try
  122. {
  123. archivaAdministration.addFileType( fileType, getAuditInformation() );
  124. }
  125. catch ( RepositoryAdminException e )
  126. {
  127. throw new ArchivaRestServiceException( e.getMessage(), e );
  128. }
  129. }
  130. @Override
  131. public Boolean removeFileType( String fileTypeId )
  132. throws ArchivaRestServiceException
  133. {
  134. try
  135. {
  136. archivaAdministration.removeFileType( fileTypeId, getAuditInformation() );
  137. return Boolean.TRUE;
  138. }
  139. catch ( RepositoryAdminException e )
  140. {
  141. throw new ArchivaRestServiceException( e.getMessage(), e );
  142. }
  143. }
  144. @Override
  145. public Boolean enabledKnownContentConsumer( String knownContentConsumer )
  146. throws ArchivaRestServiceException
  147. {
  148. try
  149. {
  150. archivaAdministration.addKnownContentConsumer( knownContentConsumer, getAuditInformation() );
  151. return Boolean.TRUE;
  152. }
  153. catch ( RepositoryAdminException e )
  154. {
  155. throw new ArchivaRestServiceException( e.getMessage(), e );
  156. }
  157. }
  158. @Override
  159. public void enabledKnownContentConsumers( List<String> knownContentConsumers )
  160. throws ArchivaRestServiceException
  161. {
  162. try
  163. {
  164. archivaAdministration.setKnownContentConsumers( knownContentConsumers, getAuditInformation() );
  165. }
  166. catch ( RepositoryAdminException e )
  167. {
  168. throw new ArchivaRestServiceException( e.getMessage(), e );
  169. }
  170. }
  171. @Override
  172. public Boolean disabledKnownContentConsumer( String knownContentConsumer )
  173. throws ArchivaRestServiceException
  174. {
  175. try
  176. {
  177. archivaAdministration.removeKnownContentConsumer( knownContentConsumer, getAuditInformation() );
  178. return Boolean.TRUE;
  179. }
  180. catch ( RepositoryAdminException e )
  181. {
  182. throw new ArchivaRestServiceException( e.getMessage(), e );
  183. }
  184. }
  185. @Override
  186. public Boolean enabledInvalidContentConsumer( String invalidContentConsumer )
  187. throws ArchivaRestServiceException
  188. {
  189. try
  190. {
  191. archivaAdministration.addInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
  192. return Boolean.TRUE;
  193. }
  194. catch ( RepositoryAdminException e )
  195. {
  196. throw new ArchivaRestServiceException( e.getMessage(), e );
  197. }
  198. }
  199. @Override
  200. public void enabledInvalidContentConsumers( List<String> invalidContentConsumers )
  201. throws ArchivaRestServiceException
  202. {
  203. try
  204. {
  205. archivaAdministration.setInvalidContentConsumers( invalidContentConsumers, getAuditInformation() );
  206. }
  207. catch ( RepositoryAdminException e )
  208. {
  209. throw new ArchivaRestServiceException( e.getMessage(), e );
  210. }
  211. }
  212. @Override
  213. public Boolean disabledInvalidContentConsumer( String invalidContentConsumer )
  214. throws ArchivaRestServiceException
  215. {
  216. try
  217. {
  218. archivaAdministration.removeInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
  219. return Boolean.TRUE;
  220. }
  221. catch ( RepositoryAdminException e )
  222. {
  223. throw new ArchivaRestServiceException( e.getMessage(), e );
  224. }
  225. }
  226. @Override
  227. public List<FileType> getFileTypes()
  228. throws ArchivaRestServiceException
  229. {
  230. try
  231. {
  232. List<FileType> modelfileTypes = archivaAdministration.getFileTypes();
  233. if ( modelfileTypes == null || modelfileTypes.isEmpty() )
  234. {
  235. return Collections.emptyList();
  236. }
  237. return modelfileTypes;
  238. }
  239. catch ( RepositoryAdminException e )
  240. {
  241. throw new ArchivaRestServiceException( e.getMessage(), e );
  242. }
  243. }
  244. @Override
  245. public List<String> getKnownContentConsumers()
  246. throws ArchivaRestServiceException
  247. {
  248. try
  249. {
  250. return new ArrayList<>( archivaAdministration.getKnownContentConsumers( ) );
  251. }
  252. catch ( RepositoryAdminException e )
  253. {
  254. throw new ArchivaRestServiceException( e.getMessage(), e );
  255. }
  256. }
  257. @Override
  258. public List<String> getInvalidContentConsumers()
  259. throws ArchivaRestServiceException
  260. {
  261. try
  262. {
  263. return new ArrayList<>( archivaAdministration.getInvalidContentConsumers( ) );
  264. }
  265. catch ( RepositoryAdminException e )
  266. {
  267. throw new ArchivaRestServiceException( e.getMessage(), e );
  268. }
  269. }
  270. @Override
  271. public OrganisationInformation getOrganisationInformation()
  272. throws ArchivaRestServiceException
  273. {
  274. try
  275. {
  276. return archivaAdministration.getOrganisationInformation();
  277. }
  278. catch ( RepositoryAdminException e )
  279. {
  280. throw new ArchivaRestServiceException( e.getMessage(), e );
  281. }
  282. }
  283. @Override
  284. public void setOrganisationInformation( OrganisationInformation organisationInformation )
  285. throws ArchivaRestServiceException
  286. {
  287. try
  288. {
  289. archivaAdministration.setOrganisationInformation( organisationInformation );
  290. }
  291. catch ( RepositoryAdminException e )
  292. {
  293. throw new ArchivaRestServiceException( e.getMessage(), 400, e );
  294. }
  295. }
  296. @Override
  297. public Boolean registrationDisabled()
  298. throws ArchivaRestServiceException
  299. {
  300. return getUiConfiguration().isDisableRegistration();
  301. }
  302. @Override
  303. public UiConfiguration getUiConfiguration()
  304. throws ArchivaRestServiceException
  305. {
  306. try
  307. {
  308. return archivaAdministration.getUiConfiguration();
  309. }
  310. catch ( RepositoryAdminException e )
  311. {
  312. throw new ArchivaRestServiceException( e.getMessage(), e );
  313. }
  314. }
  315. @Override
  316. public void setUiConfiguration( UiConfiguration uiConfiguration )
  317. throws ArchivaRestServiceException
  318. {
  319. try
  320. {
  321. // fix for MRM-1757
  322. // strip any trailing '/' at the end of the url so it won't affect url/link calculations in UI
  323. uiConfiguration.setApplicationUrl(StringUtils.stripEnd(uiConfiguration.getApplicationUrl(), "/"));
  324. archivaAdministration.updateUiConfiguration( uiConfiguration );
  325. }
  326. catch ( RepositoryAdminException e )
  327. {
  328. throw new ArchivaRestServiceException( e.getMessage(), e );
  329. }
  330. }
  331. @Override
  332. public String getApplicationUrl()
  333. throws ArchivaRestServiceException
  334. {
  335. try
  336. {
  337. return archivaAdministration.getUiConfiguration().getApplicationUrl();
  338. }
  339. catch ( RepositoryAdminException e )
  340. {
  341. throw new ArchivaRestServiceException( e.getMessage(), e );
  342. }
  343. }
  344. @Override
  345. public NetworkConfiguration getNetworkConfiguration()
  346. throws ArchivaRestServiceException
  347. {
  348. try
  349. {
  350. return archivaAdministration.getNetworkConfiguration();
  351. }
  352. catch ( RepositoryAdminException e )
  353. {
  354. throw new ArchivaRestServiceException( e.getMessage(), e );
  355. }
  356. }
  357. @Override
  358. public void setNetworkConfiguration( NetworkConfiguration networkConfiguration )
  359. throws ArchivaRestServiceException
  360. {
  361. try
  362. {
  363. archivaAdministration.setNetworkConfiguration( networkConfiguration );
  364. }
  365. catch ( RepositoryAdminException e )
  366. {
  367. throw new ArchivaRestServiceException( e.getMessage(), e );
  368. }
  369. }
  370. @Override
  371. public List<AdminRepositoryConsumer> getKnownContentAdminRepositoryConsumers()
  372. throws ArchivaRestServiceException
  373. {
  374. try
  375. {
  376. AddAdminRepoConsumerClosure addAdminRepoConsumer =
  377. new AddAdminRepoConsumerClosure( archivaAdministration.getKnownContentConsumers() );
  378. IterableUtils.forEach( repoConsumerUtil.getAvailableKnownConsumers(), addAdminRepoConsumer );
  379. List<AdminRepositoryConsumer> knownContentConsumers = addAdminRepoConsumer.getList();
  380. knownContentConsumers.sort( AdminRepositoryConsumerComparator.getInstance( ) );
  381. return knownContentConsumers;
  382. }
  383. catch ( RepositoryAdminException e )
  384. {
  385. throw new ArchivaRestServiceException( e.getMessage(), e );
  386. }
  387. }
  388. @Override
  389. public List<AdminRepositoryConsumer> getInvalidContentAdminRepositoryConsumers()
  390. throws ArchivaRestServiceException
  391. {
  392. try
  393. {
  394. AddAdminRepoConsumerClosure addAdminRepoConsumer =
  395. new AddAdminRepoConsumerClosure( archivaAdministration.getInvalidContentConsumers() );
  396. IterableUtils.forEach( repoConsumerUtil.getAvailableInvalidConsumers(), addAdminRepoConsumer );
  397. List<AdminRepositoryConsumer> invalidContentConsumers = addAdminRepoConsumer.getList();
  398. invalidContentConsumers.sort( AdminRepositoryConsumerComparator.getInstance( ) );
  399. return invalidContentConsumers;
  400. }
  401. catch ( RepositoryAdminException e )
  402. {
  403. throw new ArchivaRestServiceException( e.getMessage(), e );
  404. }
  405. }
  406. }