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

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