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.

DefaultRepositoriesService.java 46KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235
  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.ManagedRepository;
  23. import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
  24. import org.apache.archiva.audit.AuditEvent;
  25. import org.apache.archiva.checksum.ChecksumAlgorithm;
  26. import org.apache.archiva.checksum.ChecksummedFile;
  27. import org.apache.archiva.common.plexusbridge.MavenIndexerUtils;
  28. import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
  29. import org.apache.archiva.common.utils.VersionComparator;
  30. import org.apache.archiva.common.utils.VersionUtil;
  31. import org.apache.archiva.maven2.metadata.MavenMetadataReader;
  32. import org.apache.archiva.maven2.model.Artifact;
  33. import org.apache.archiva.metadata.model.ArtifactMetadata;
  34. import org.apache.archiva.metadata.model.maven2.MavenArtifactFacet;
  35. import org.apache.archiva.metadata.repository.MetadataRepository;
  36. import org.apache.archiva.metadata.repository.MetadataRepositoryException;
  37. import org.apache.archiva.metadata.repository.MetadataResolutionException;
  38. import org.apache.archiva.metadata.repository.RepositorySession;
  39. import org.apache.archiva.metadata.repository.RepositorySessionFactory;
  40. import org.apache.archiva.model.ArchivaRepositoryMetadata;
  41. import org.apache.archiva.model.ArtifactReference;
  42. import org.apache.archiva.model.VersionedReference;
  43. import org.apache.archiva.redback.authentication.AuthenticationResult;
  44. import org.apache.archiva.redback.authorization.AuthorizationException;
  45. import org.apache.archiva.redback.components.cache.Cache;
  46. import org.apache.archiva.redback.components.taskqueue.TaskQueueException;
  47. import org.apache.archiva.redback.system.DefaultSecuritySession;
  48. import org.apache.archiva.redback.system.SecuritySession;
  49. import org.apache.archiva.redback.system.SecuritySystem;
  50. import org.apache.archiva.redback.users.User;
  51. import org.apache.archiva.redback.users.UserManagerException;
  52. import org.apache.archiva.redback.users.UserNotFoundException;
  53. import org.apache.archiva.repository.ContentNotFoundException;
  54. import org.apache.archiva.repository.ManagedRepositoryContent;
  55. import org.apache.archiva.repository.RepositoryContentFactory;
  56. import org.apache.archiva.repository.RepositoryException;
  57. import org.apache.archiva.repository.RepositoryNotFoundException;
  58. import org.apache.archiva.repository.events.RepositoryListener;
  59. import org.apache.archiva.repository.metadata.MetadataTools;
  60. import org.apache.archiva.repository.metadata.RepositoryMetadataException;
  61. import org.apache.archiva.repository.metadata.RepositoryMetadataWriter;
  62. import org.apache.archiva.repository.scanner.RepositoryScanStatistics;
  63. import org.apache.archiva.repository.scanner.RepositoryScanner;
  64. import org.apache.archiva.repository.scanner.RepositoryScannerException;
  65. import org.apache.archiva.rest.api.model.ArtifactTransferRequest;
  66. import org.apache.archiva.rest.api.model.StringList;
  67. import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
  68. import org.apache.archiva.rest.api.services.RepositoriesService;
  69. import org.apache.archiva.scheduler.ArchivaTaskScheduler;
  70. import org.apache.archiva.scheduler.indexing.ArchivaIndexingTaskExecutor;
  71. import org.apache.archiva.scheduler.indexing.ArtifactIndexingTask;
  72. import org.apache.archiva.scheduler.indexing.DownloadRemoteIndexException;
  73. import org.apache.archiva.scheduler.indexing.DownloadRemoteIndexScheduler;
  74. import org.apache.archiva.scheduler.repository.model.RepositoryTask;
  75. import org.apache.archiva.security.ArchivaSecurityException;
  76. import org.apache.archiva.security.common.ArchivaRoleConstants;
  77. import org.apache.archiva.xml.XMLException;
  78. import org.apache.commons.io.FilenameUtils;
  79. import org.apache.commons.io.IOUtils;
  80. import org.apache.commons.lang.StringUtils;
  81. import org.apache.maven.index.context.IndexingContext;
  82. import org.slf4j.Logger;
  83. import org.slf4j.LoggerFactory;
  84. import org.springframework.stereotype.Service;
  85. import javax.inject.Inject;
  86. import javax.inject.Named;
  87. import javax.ws.rs.core.Response;
  88. import java.io.File;
  89. import java.io.FileInputStream;
  90. import java.io.FileOutputStream;
  91. import java.io.IOException;
  92. import java.text.DateFormat;
  93. import java.text.SimpleDateFormat;
  94. import java.util.ArrayList;
  95. import java.util.Calendar;
  96. import java.util.Collection;
  97. import java.util.Collections;
  98. import java.util.Date;
  99. import java.util.List;
  100. import java.util.Set;
  101. import java.util.TimeZone;
  102. /**
  103. * @author Olivier Lamy
  104. * @since 1.4-M1
  105. */
  106. @Service( "repositoriesService#rest" )
  107. public class DefaultRepositoriesService
  108. extends AbstractRestService
  109. implements RepositoriesService
  110. {
  111. private Logger log = LoggerFactory.getLogger( getClass() );
  112. @Inject
  113. @Named( value = "taskExecutor#indexing" )
  114. private ArchivaIndexingTaskExecutor archivaIndexingTaskExecutor;
  115. @Inject
  116. private ManagedRepositoryAdmin managedRepositoryAdmin;
  117. @Inject
  118. private PlexusSisuBridge plexusSisuBridge;
  119. @Inject
  120. private MavenIndexerUtils mavenIndexerUtils;
  121. @Inject
  122. private SecuritySystem securitySystem;
  123. @Inject
  124. private RepositoryContentFactory repositoryFactory;
  125. @Inject
  126. @Named( value = "archivaTaskScheduler#repository" )
  127. private ArchivaTaskScheduler scheduler;
  128. @Inject
  129. private DownloadRemoteIndexScheduler downloadRemoteIndexScheduler;
  130. @Inject
  131. @Named( value = "repositorySessionFactory" )
  132. protected RepositorySessionFactory repositorySessionFactory;
  133. @Inject
  134. protected List<RepositoryListener> listeners = new ArrayList<RepositoryListener>();
  135. @Inject
  136. private RepositoryScanner repoScanner;
  137. /**
  138. * Cache used for namespaces
  139. */
  140. @Inject
  141. @Named( value = "cache#namespaces" )
  142. private Cache<String, Collection<String>> namespacesCache;
  143. private ChecksumAlgorithm[] algorithms = new ChecksumAlgorithm[]{ ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 };
  144. public Boolean scanRepository( String repositoryId, boolean fullScan )
  145. {
  146. return doScanRepository( repositoryId, fullScan );
  147. }
  148. public Boolean alreadyScanning( String repositoryId )
  149. {
  150. return repositoryTaskScheduler.isProcessingRepositoryTask( repositoryId );
  151. }
  152. public Boolean removeScanningTaskFromQueue( String repositoryId )
  153. {
  154. RepositoryTask task = new RepositoryTask();
  155. task.setRepositoryId( repositoryId );
  156. try
  157. {
  158. return repositoryTaskScheduler.unQueueTask( task );
  159. }
  160. catch ( TaskQueueException e )
  161. {
  162. log.error( "failed to unschedule scanning of repo with id {}", repositoryId, e );
  163. return false;
  164. }
  165. }
  166. public Boolean scanRepositoryNow( String repositoryId, boolean fullScan )
  167. throws ArchivaRestServiceException
  168. {
  169. try
  170. {
  171. ManagedRepository repository = managedRepositoryAdmin.getManagedRepository( repositoryId );
  172. IndexingContext context = managedRepositoryAdmin.createIndexContext( repository );
  173. ArtifactIndexingTask task =
  174. new ArtifactIndexingTask( repository, null, ArtifactIndexingTask.Action.FINISH, context );
  175. task.setExecuteOnEntireRepo( true );
  176. task.setOnlyUpdate( !fullScan );
  177. archivaIndexingTaskExecutor.executeTask( task );
  178. return Boolean.TRUE;
  179. }
  180. catch ( Exception e )
  181. {
  182. log.error( e.getMessage(), e );
  183. throw new ArchivaRestServiceException( e.getMessage(), e );
  184. }
  185. }
  186. public Boolean scheduleDownloadRemoteIndex( String repositoryId, boolean now, boolean fullDownload )
  187. throws ArchivaRestServiceException
  188. {
  189. try
  190. {
  191. downloadRemoteIndexScheduler.scheduleDownloadRemote( repositoryId, now, fullDownload );
  192. }
  193. catch ( DownloadRemoteIndexException e )
  194. {
  195. log.error( e.getMessage(), e );
  196. throw new ArchivaRestServiceException( e.getMessage(), e );
  197. }
  198. return Boolean.TRUE;
  199. }
  200. public Boolean copyArtifact( ArtifactTransferRequest artifactTransferRequest )
  201. throws ArchivaRestServiceException
  202. {
  203. // check parameters
  204. String userName = getAuditInformation().getUser().getUsername();
  205. if ( StringUtils.isBlank( userName ) )
  206. {
  207. throw new ArchivaRestServiceException( "copyArtifact call: userName not found", null );
  208. }
  209. if ( StringUtils.isBlank( artifactTransferRequest.getRepositoryId() ) )
  210. {
  211. throw new ArchivaRestServiceException( "copyArtifact call: sourceRepositoryId cannot be null", null );
  212. }
  213. if ( StringUtils.isBlank( artifactTransferRequest.getTargetRepositoryId() ) )
  214. {
  215. throw new ArchivaRestServiceException( "copyArtifact call: targetRepositoryId cannot be null", null );
  216. }
  217. ManagedRepository source = null;
  218. try
  219. {
  220. source = managedRepositoryAdmin.getManagedRepository( artifactTransferRequest.getRepositoryId() );
  221. }
  222. catch ( RepositoryAdminException e )
  223. {
  224. throw new ArchivaRestServiceException( e.getMessage(), e );
  225. }
  226. if ( source == null )
  227. {
  228. throw new ArchivaRestServiceException(
  229. "cannot find repository with id " + artifactTransferRequest.getRepositoryId(), null );
  230. }
  231. ManagedRepository target = null;
  232. try
  233. {
  234. target = managedRepositoryAdmin.getManagedRepository( artifactTransferRequest.getTargetRepositoryId() );
  235. }
  236. catch ( RepositoryAdminException e )
  237. {
  238. throw new ArchivaRestServiceException( e.getMessage(), e );
  239. }
  240. if ( target == null )
  241. {
  242. throw new ArchivaRestServiceException(
  243. "cannot find repository with id " + artifactTransferRequest.getTargetRepositoryId(), null );
  244. }
  245. if ( StringUtils.isBlank( artifactTransferRequest.getGroupId() ) )
  246. {
  247. throw new ArchivaRestServiceException( "groupId is mandatory", null );
  248. }
  249. if ( StringUtils.isBlank( artifactTransferRequest.getArtifactId() ) )
  250. {
  251. throw new ArchivaRestServiceException( "artifactId is mandatory", null );
  252. }
  253. if ( StringUtils.isBlank( artifactTransferRequest.getVersion() ) )
  254. {
  255. throw new ArchivaRestServiceException( "version is mandatory", null );
  256. }
  257. if ( VersionUtil.isSnapshot( artifactTransferRequest.getVersion() ) )
  258. {
  259. throw new ArchivaRestServiceException( "copy of SNAPSHOT not supported", null );
  260. }
  261. // end check parameters
  262. User user = null;
  263. try
  264. {
  265. user = securitySystem.getUserManager().findUser( userName );
  266. }
  267. catch ( UserNotFoundException e )
  268. {
  269. throw new ArchivaRestServiceException( "user " + userName + " not found", e );
  270. }
  271. catch ( UserManagerException e )
  272. {
  273. throw new ArchivaRestServiceException( "ArchivaRestServiceException:" + e.getMessage(), e );
  274. }
  275. // check karma on source : read
  276. AuthenticationResult authn = new AuthenticationResult( true, userName, null );
  277. SecuritySession securitySession = new DefaultSecuritySession( authn, user );
  278. try
  279. {
  280. boolean authz =
  281. securitySystem.isAuthorized( securitySession, ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS,
  282. artifactTransferRequest.getRepositoryId() );
  283. if ( !authz )
  284. {
  285. throw new ArchivaRestServiceException(
  286. "not authorized to access repo:" + artifactTransferRequest.getRepositoryId(), null );
  287. }
  288. }
  289. catch ( AuthorizationException e )
  290. {
  291. log.error( "error reading permission: " + e.getMessage(), e );
  292. throw new ArchivaRestServiceException( e.getMessage(), e );
  293. }
  294. // check karma on target: write
  295. try
  296. {
  297. boolean authz =
  298. securitySystem.isAuthorized( securitySession, ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD,
  299. artifactTransferRequest.getTargetRepositoryId() );
  300. if ( !authz )
  301. {
  302. throw new ArchivaRestServiceException(
  303. "not authorized to write to repo:" + artifactTransferRequest.getTargetRepositoryId(), null );
  304. }
  305. }
  306. catch ( AuthorizationException e )
  307. {
  308. log.error( "error reading permission: " + e.getMessage(), e );
  309. throw new ArchivaRestServiceException( e.getMessage(), e );
  310. }
  311. // sounds good we can continue !
  312. ArtifactReference artifactReference = new ArtifactReference();
  313. artifactReference.setArtifactId( artifactTransferRequest.getArtifactId() );
  314. artifactReference.setGroupId( artifactTransferRequest.getGroupId() );
  315. artifactReference.setVersion( artifactTransferRequest.getVersion() );
  316. artifactReference.setClassifier( artifactTransferRequest.getClassifier() );
  317. String packaging = StringUtils.trim( artifactTransferRequest.getPackaging() );
  318. artifactReference.setType( StringUtils.isEmpty( packaging ) ? "jar" : packaging );
  319. try
  320. {
  321. ManagedRepositoryContent sourceRepository =
  322. repositoryFactory.getManagedRepositoryContent( artifactTransferRequest.getRepositoryId() );
  323. String artifactSourcePath = sourceRepository.toPath( artifactReference );
  324. if ( StringUtils.isEmpty( artifactSourcePath ) )
  325. {
  326. log.error( "cannot find artifact " + artifactTransferRequest.toString() );
  327. throw new ArchivaRestServiceException( "cannot find artifact " + artifactTransferRequest.toString(),
  328. null );
  329. }
  330. File artifactFile = new File( source.getLocation(), artifactSourcePath );
  331. if ( !artifactFile.exists() )
  332. {
  333. log.error( "cannot find artifact " + artifactTransferRequest.toString() );
  334. throw new ArchivaRestServiceException( "cannot find artifact " + artifactTransferRequest.toString(),
  335. null );
  336. }
  337. ManagedRepositoryContent targetRepository =
  338. repositoryFactory.getManagedRepositoryContent( artifactTransferRequest.getTargetRepositoryId() );
  339. String artifactPath = targetRepository.toPath( artifactReference );
  340. int lastIndex = artifactPath.lastIndexOf( '/' );
  341. String path = artifactPath.substring( 0, lastIndex );
  342. File targetPath = new File( target.getLocation(), path );
  343. Date lastUpdatedTimestamp = Calendar.getInstance().getTime();
  344. int newBuildNumber = 1;
  345. String timestamp = null;
  346. File versionMetadataFile = new File( targetPath, MetadataTools.MAVEN_METADATA );
  347. ArchivaRepositoryMetadata versionMetadata = getMetadata( versionMetadataFile );
  348. if ( !targetPath.exists() )
  349. {
  350. targetPath.mkdirs();
  351. }
  352. String filename = artifactPath.substring( lastIndex + 1 );
  353. boolean fixChecksums =
  354. !( archivaAdministration.getKnownContentConsumers().contains( "create-missing-checksums" ) );
  355. File targetFile = new File( targetPath, filename );
  356. if ( targetFile.exists() && target.isBlockRedeployments() )
  357. {
  358. throw new ArchivaRestServiceException(
  359. "artifact already exists in target repo: " + artifactTransferRequest.getTargetRepositoryId()
  360. + " and redeployment blocked", null );
  361. }
  362. else
  363. {
  364. copyFile( artifactFile, targetPath, filename, fixChecksums );
  365. queueRepositoryTask( target.getId(), targetFile );
  366. }
  367. // copy source pom to target repo
  368. String pomFilename = filename;
  369. if ( StringUtils.isNotBlank( artifactTransferRequest.getClassifier() ) )
  370. {
  371. pomFilename = StringUtils.remove( pomFilename, "-" + artifactTransferRequest.getClassifier() );
  372. }
  373. pomFilename = FilenameUtils.removeExtension( pomFilename ) + ".pom";
  374. File pomFile = new File(
  375. new File( source.getLocation(), artifactSourcePath.substring( 0, artifactPath.lastIndexOf( '/' ) ) ),
  376. pomFilename );
  377. if ( pomFile != null && pomFile.length() > 0 )
  378. {
  379. copyFile( pomFile, targetPath, pomFilename, fixChecksums );
  380. queueRepositoryTask( target.getId(), new File( targetPath, pomFilename ) );
  381. }
  382. // explicitly update only if metadata-updater consumer is not enabled!
  383. if ( !archivaAdministration.getKnownContentConsumers().contains( "metadata-updater" ) )
  384. {
  385. updateProjectMetadata( targetPath.getAbsolutePath(), lastUpdatedTimestamp, timestamp, newBuildNumber,
  386. fixChecksums, artifactTransferRequest );
  387. }
  388. String msg =
  389. "Artifact \'" + artifactTransferRequest.getGroupId() + ":" + artifactTransferRequest.getArtifactId()
  390. + ":" + artifactTransferRequest.getVersion() + "\' was successfully deployed to repository \'"
  391. + artifactTransferRequest.getTargetRepositoryId() + "\'";
  392. }
  393. catch ( RepositoryException e )
  394. {
  395. log.error( "RepositoryException: " + e.getMessage(), e );
  396. throw new ArchivaRestServiceException( e.getMessage(), e );
  397. }
  398. catch ( RepositoryAdminException e )
  399. {
  400. log.error( "RepositoryAdminException: " + e.getMessage(), e );
  401. throw new ArchivaRestServiceException( e.getMessage(), e );
  402. }
  403. catch ( IOException e )
  404. {
  405. log.error( "IOException: " + e.getMessage(), e );
  406. throw new ArchivaRestServiceException( e.getMessage(), e );
  407. }
  408. return true;
  409. }
  410. private void queueRepositoryTask( String repositoryId, File localFile )
  411. {
  412. RepositoryTask task = new RepositoryTask();
  413. task.setRepositoryId( repositoryId );
  414. task.setResourceFile( localFile );
  415. task.setUpdateRelatedArtifacts( true );
  416. //task.setScanAll( true );
  417. try
  418. {
  419. scheduler.queueTask( task );
  420. }
  421. catch ( TaskQueueException e )
  422. {
  423. log.error( "Unable to queue repository task to execute consumers on resource file ['" + localFile.getName()
  424. + "']." );
  425. }
  426. }
  427. private ArchivaRepositoryMetadata getMetadata( File metadataFile )
  428. throws RepositoryMetadataException
  429. {
  430. ArchivaRepositoryMetadata metadata = new ArchivaRepositoryMetadata();
  431. if ( metadataFile.exists() )
  432. {
  433. try
  434. {
  435. metadata = MavenMetadataReader.read( metadataFile );
  436. }
  437. catch ( XMLException e )
  438. {
  439. throw new RepositoryMetadataException( e.getMessage(), e );
  440. }
  441. }
  442. return metadata;
  443. }
  444. private File getMetadata( String targetPath )
  445. {
  446. String artifactPath = targetPath.substring( 0, targetPath.lastIndexOf( File.separatorChar ) );
  447. return new File( artifactPath, MetadataTools.MAVEN_METADATA );
  448. }
  449. private void copyFile( File sourceFile, File targetPath, String targetFilename, boolean fixChecksums )
  450. throws IOException
  451. {
  452. FileOutputStream out = new FileOutputStream( new File( targetPath, targetFilename ) );
  453. FileInputStream input = new FileInputStream( sourceFile );
  454. try
  455. {
  456. IOUtils.copy( input, out );
  457. }
  458. finally
  459. {
  460. IOUtils.closeQuietly( out );
  461. IOUtils.closeQuietly( input );
  462. }
  463. if ( fixChecksums )
  464. {
  465. fixChecksums( new File( targetPath, targetFilename ) );
  466. }
  467. }
  468. private void fixChecksums( File file )
  469. {
  470. ChecksummedFile checksum = new ChecksummedFile( file );
  471. checksum.fixChecksums( algorithms );
  472. }
  473. private void updateProjectMetadata( String targetPath, Date lastUpdatedTimestamp, String timestamp, int buildNumber,
  474. boolean fixChecksums, ArtifactTransferRequest artifactTransferRequest )
  475. throws RepositoryMetadataException
  476. {
  477. List<String> availableVersions = new ArrayList<>();
  478. String latestVersion = artifactTransferRequest.getVersion();
  479. File projectDir = new File( targetPath ).getParentFile();
  480. File projectMetadataFile = new File( projectDir, MetadataTools.MAVEN_METADATA );
  481. ArchivaRepositoryMetadata projectMetadata = getMetadata( projectMetadataFile );
  482. if ( projectMetadataFile.exists() )
  483. {
  484. availableVersions = projectMetadata.getAvailableVersions();
  485. Collections.sort( availableVersions, VersionComparator.getInstance() );
  486. if ( !availableVersions.contains( artifactTransferRequest.getVersion() ) )
  487. {
  488. availableVersions.add( artifactTransferRequest.getVersion() );
  489. }
  490. latestVersion = availableVersions.get( availableVersions.size() - 1 );
  491. }
  492. else
  493. {
  494. availableVersions.add( artifactTransferRequest.getVersion() );
  495. projectMetadata.setGroupId( artifactTransferRequest.getGroupId() );
  496. projectMetadata.setArtifactId( artifactTransferRequest.getArtifactId() );
  497. }
  498. if ( projectMetadata.getGroupId() == null )
  499. {
  500. projectMetadata.setGroupId( artifactTransferRequest.getGroupId() );
  501. }
  502. if ( projectMetadata.getArtifactId() == null )
  503. {
  504. projectMetadata.setArtifactId( artifactTransferRequest.getArtifactId() );
  505. }
  506. projectMetadata.setLatestVersion( latestVersion );
  507. projectMetadata.setLastUpdatedTimestamp( lastUpdatedTimestamp );
  508. projectMetadata.setAvailableVersions( availableVersions );
  509. if ( !VersionUtil.isSnapshot( artifactTransferRequest.getVersion() ) )
  510. {
  511. projectMetadata.setReleasedVersion( latestVersion );
  512. }
  513. RepositoryMetadataWriter.write( projectMetadata, projectMetadataFile );
  514. if ( fixChecksums )
  515. {
  516. fixChecksums( projectMetadataFile );
  517. }
  518. }
  519. public Boolean removeProjectVersion( String repositoryId, String namespace, String projectId, String version )
  520. throws ArchivaRestServiceException
  521. {
  522. // if not a generic we can use the standard way to delete artifact
  523. if ( !VersionUtil.isGenericSnapshot( version ) )
  524. {
  525. Artifact artifact = new Artifact( namespace, projectId, version );
  526. artifact.setRepositoryId( repositoryId );
  527. artifact.setContext( repositoryId );
  528. return deleteArtifact( artifact );
  529. }
  530. if ( StringUtils.isEmpty( repositoryId ) )
  531. {
  532. throw new ArchivaRestServiceException( "repositoryId cannot be null", 400, null );
  533. }
  534. if ( !isAuthorizedToDeleteArtifacts( repositoryId ) )
  535. {
  536. throw new ArchivaRestServiceException( "not authorized to delete artifacts", 403, null );
  537. }
  538. if ( StringUtils.isEmpty( namespace ) )
  539. {
  540. throw new ArchivaRestServiceException( "groupId cannot be null", 400, null );
  541. }
  542. if ( StringUtils.isEmpty( projectId ) )
  543. {
  544. throw new ArchivaRestServiceException( "artifactId cannot be null", 400, null );
  545. }
  546. if ( StringUtils.isEmpty( version ) )
  547. {
  548. throw new ArchivaRestServiceException( "version cannot be null", 400, null );
  549. }
  550. RepositorySession repositorySession = repositorySessionFactory.createSession();
  551. try
  552. {
  553. ManagedRepositoryContent repository = repositoryFactory.getManagedRepositoryContent( repositoryId );
  554. VersionedReference ref = new VersionedReference();
  555. ref.setArtifactId( projectId );
  556. ref.setGroupId( namespace );
  557. ref.setVersion( version );
  558. repository.deleteVersion( ref );
  559. /*
  560. ProjectReference projectReference = new ProjectReference();
  561. projectReference.setGroupId( namespace );
  562. projectReference.setArtifactId( projectId );
  563. repository.getVersions( )
  564. */
  565. ArtifactReference artifactReference = new ArtifactReference();
  566. artifactReference.setGroupId( namespace );
  567. artifactReference.setArtifactId( projectId );
  568. artifactReference.setVersion( version );
  569. MetadataRepository metadataRepository = repositorySession.getRepository();
  570. Set<ArtifactReference> related = repository.getRelatedArtifacts( artifactReference );
  571. log.debug( "related: {}", related );
  572. for ( ArtifactReference artifactRef : related )
  573. {
  574. repository.deleteArtifact( artifactRef );
  575. }
  576. Collection<ArtifactMetadata> artifacts =
  577. metadataRepository.getArtifacts( repositoryId, namespace, projectId, version );
  578. for ( ArtifactMetadata artifactMetadata : artifacts )
  579. {
  580. metadataRepository.removeArtifact( artifactMetadata, version );
  581. }
  582. metadataRepository.removeProjectVersion( repositoryId, namespace, projectId, version );
  583. }
  584. catch ( MetadataRepositoryException e )
  585. {
  586. throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500, e );
  587. }
  588. catch ( MetadataResolutionException e )
  589. {
  590. throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500, e );
  591. }
  592. catch ( RepositoryException e )
  593. {
  594. throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500, e );
  595. }
  596. finally
  597. {
  598. repositorySession.save();
  599. repositorySession.close();
  600. }
  601. return Boolean.TRUE;
  602. }
  603. public Boolean deleteArtifact( Artifact artifact )
  604. throws ArchivaRestServiceException
  605. {
  606. String repositoryId = artifact.getContext();
  607. // some rest call can use context or repositoryId
  608. // so try both!!
  609. if ( StringUtils.isEmpty( repositoryId ) )
  610. {
  611. repositoryId = artifact.getRepositoryId();
  612. }
  613. if ( StringUtils.isEmpty( repositoryId ) )
  614. {
  615. throw new ArchivaRestServiceException( "repositoryId cannot be null", 400, null );
  616. }
  617. if ( !isAuthorizedToDeleteArtifacts( repositoryId ) )
  618. {
  619. throw new ArchivaRestServiceException( "not authorized to delete artifacts", 403, null );
  620. }
  621. if ( artifact == null )
  622. {
  623. throw new ArchivaRestServiceException( "artifact cannot be null", 400, null );
  624. }
  625. if ( StringUtils.isEmpty( artifact.getGroupId() ) )
  626. {
  627. throw new ArchivaRestServiceException( "artifact.groupId cannot be null", 400, null );
  628. }
  629. if ( StringUtils.isEmpty( artifact.getArtifactId() ) )
  630. {
  631. throw new ArchivaRestServiceException( "artifact.artifactId cannot be null", 400, null );
  632. }
  633. // TODO more control on artifact fields
  634. boolean snapshotVersion =
  635. VersionUtil.isSnapshot( artifact.getVersion() ) | VersionUtil.isGenericSnapshot( artifact.getVersion() );
  636. RepositorySession repositorySession = repositorySessionFactory.createSession();
  637. try
  638. {
  639. Date lastUpdatedTimestamp = Calendar.getInstance().getTime();
  640. TimeZone timezone = TimeZone.getTimeZone( "UTC" );
  641. DateFormat fmt = new SimpleDateFormat( "yyyyMMdd.HHmmss" );
  642. fmt.setTimeZone( timezone );
  643. ManagedRepository repoConfig = managedRepositoryAdmin.getManagedRepository( repositoryId );
  644. VersionedReference ref = new VersionedReference();
  645. ref.setArtifactId( artifact.getArtifactId() );
  646. ref.setGroupId( artifact.getGroupId() );
  647. ref.setVersion( artifact.getVersion() );
  648. ManagedRepositoryContent repository = repositoryFactory.getManagedRepositoryContent( repositoryId );
  649. ArtifactReference artifactReference = new ArtifactReference();
  650. artifactReference.setArtifactId( artifact.getArtifactId() );
  651. artifactReference.setGroupId( artifact.getGroupId() );
  652. artifactReference.setVersion( artifact.getVersion() );
  653. artifactReference.setClassifier( artifact.getClassifier() );
  654. artifactReference.setType( artifact.getPackaging() );
  655. MetadataRepository metadataRepository = repositorySession.getRepository();
  656. String path = repository.toMetadataPath( ref );
  657. if ( StringUtils.isNotBlank( artifact.getClassifier() ) )
  658. {
  659. if ( StringUtils.isBlank( artifact.getPackaging() ) )
  660. {
  661. throw new ArchivaRestServiceException( "You must configure a type/packaging when using classifier",
  662. 400, null );
  663. }
  664. repository.deleteArtifact( artifactReference );
  665. }
  666. else
  667. {
  668. int index = path.lastIndexOf( '/' );
  669. path = path.substring( 0, index );
  670. File targetPath = new File( repoConfig.getLocation(), path );
  671. if ( !targetPath.exists() )
  672. {
  673. //throw new ContentNotFoundException(
  674. // artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() );
  675. log.warn( "targetPath {} not found skip file deletion", targetPath );
  676. }
  677. // TODO: this should be in the storage mechanism so that it is all tied together
  678. // delete from file system
  679. if ( !snapshotVersion )
  680. {
  681. repository.deleteVersion( ref );
  682. }
  683. else
  684. {
  685. Set<ArtifactReference> related = repository.getRelatedArtifacts( artifactReference );
  686. log.debug( "related: {}", related );
  687. for ( ArtifactReference artifactRef : related )
  688. {
  689. repository.deleteArtifact( artifactRef );
  690. }
  691. }
  692. File metadataFile = getMetadata( targetPath.getAbsolutePath() );
  693. ArchivaRepositoryMetadata metadata = getMetadata( metadataFile );
  694. updateMetadata( metadata, metadataFile, lastUpdatedTimestamp, artifact );
  695. }
  696. Collection<ArtifactMetadata> artifacts = Collections.emptyList();
  697. if ( snapshotVersion )
  698. {
  699. String baseVersion = VersionUtil.getBaseVersion( artifact.getVersion() );
  700. artifacts =
  701. metadataRepository.getArtifacts( repositoryId, artifact.getGroupId(), artifact.getArtifactId(),
  702. baseVersion );
  703. }
  704. else
  705. {
  706. artifacts =
  707. metadataRepository.getArtifacts( repositoryId, artifact.getGroupId(), artifact.getArtifactId(),
  708. artifact.getVersion() );
  709. }
  710. log.debug( "artifacts: {}", artifacts );
  711. if ( artifacts.isEmpty() )
  712. {
  713. if ( !snapshotVersion )
  714. {
  715. // verify metata repository doesn't contains anymore the version
  716. Collection<String> projectVersions =
  717. metadataRepository.getProjectVersions( repositoryId, artifact.getGroupId(),
  718. artifact.getArtifactId() );
  719. if ( projectVersions.contains( artifact.getVersion() ) )
  720. {
  721. log.warn( "artifact not found when deleted but version still here ! so force cleanup" );
  722. metadataRepository.removeProjectVersion( repositoryId, artifact.getGroupId(),
  723. artifact.getArtifactId(), artifact.getVersion() );
  724. }
  725. }
  726. }
  727. for ( ArtifactMetadata artifactMetadata : artifacts )
  728. {
  729. // TODO: mismatch between artifact (snapshot) version and project (base) version here
  730. if ( artifactMetadata.getVersion().equals( artifact.getVersion() ) )
  731. {
  732. if ( StringUtils.isNotBlank( artifact.getClassifier() ) )
  733. {
  734. if ( StringUtils.isBlank( artifact.getPackaging() ) )
  735. {
  736. throw new ArchivaRestServiceException(
  737. "You must configure a type/packaging when using classifier", 400, null );
  738. }
  739. // cleanup facet which contains classifier information
  740. MavenArtifactFacet mavenArtifactFacet =
  741. (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
  742. if ( StringUtils.equals( artifact.getClassifier(), mavenArtifactFacet.getClassifier() ) )
  743. {
  744. artifactMetadata.removeFacet( MavenArtifactFacet.FACET_ID );
  745. String groupId = artifact.getGroupId(), artifactId = artifact.getArtifactId(), version =
  746. artifact.getVersion();
  747. MavenArtifactFacet mavenArtifactFacetToCompare = new MavenArtifactFacet();
  748. mavenArtifactFacetToCompare.setClassifier( artifact.getClassifier() );
  749. metadataRepository.removeArtifact( repositoryId, groupId, artifactId, version,
  750. mavenArtifactFacetToCompare );
  751. metadataRepository.save();
  752. }
  753. }
  754. else
  755. {
  756. if ( snapshotVersion )
  757. {
  758. metadataRepository.removeArtifact( artifactMetadata,
  759. VersionUtil.getBaseVersion( artifact.getVersion() ) );
  760. }
  761. else
  762. {
  763. metadataRepository.removeArtifact( artifactMetadata.getRepositoryId(),
  764. artifactMetadata.getNamespace(),
  765. artifactMetadata.getProject(), artifact.getVersion(),
  766. artifactMetadata.getId() );
  767. }
  768. }
  769. // TODO: move into the metadata repository proper - need to differentiate attachment of
  770. // repository metadata to an artifact
  771. for ( RepositoryListener listener : listeners )
  772. {
  773. listener.deleteArtifact( metadataRepository, repository.getId(),
  774. artifactMetadata.getNamespace(), artifactMetadata.getProject(),
  775. artifactMetadata.getVersion(), artifactMetadata.getId() );
  776. }
  777. triggerAuditEvent( repositoryId, path, AuditEvent.REMOVE_FILE );
  778. }
  779. }
  780. }
  781. catch ( ContentNotFoundException e )
  782. {
  783. throw new ArchivaRestServiceException( "Artifact does not exist: " + e.getMessage(), 400, e );
  784. }
  785. catch ( RepositoryNotFoundException e )
  786. {
  787. throw new ArchivaRestServiceException( "Target repository cannot be found: " + e.getMessage(), 400, e );
  788. }
  789. catch ( RepositoryException e )
  790. {
  791. throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500, e );
  792. }
  793. catch ( MetadataResolutionException e )
  794. {
  795. throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500, e );
  796. }
  797. catch ( MetadataRepositoryException e )
  798. {
  799. throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500, e );
  800. }
  801. catch ( RepositoryAdminException e )
  802. {
  803. throw new ArchivaRestServiceException( "RepositoryAdmin exception: " + e.getMessage(), 500, e );
  804. }
  805. finally
  806. {
  807. repositorySession.save();
  808. repositorySession.close();
  809. }
  810. return Boolean.TRUE;
  811. }
  812. public Boolean deleteGroupId( String groupId, String repositoryId )
  813. throws ArchivaRestServiceException
  814. {
  815. if ( StringUtils.isEmpty( repositoryId ) )
  816. {
  817. throw new ArchivaRestServiceException( "repositoryId cannot be null", 400, null );
  818. }
  819. if ( !isAuthorizedToDeleteArtifacts( repositoryId ) )
  820. {
  821. throw new ArchivaRestServiceException( "not authorized to delete artifacts", 403, null );
  822. }
  823. if ( StringUtils.isEmpty( groupId ) )
  824. {
  825. throw new ArchivaRestServiceException( "groupId cannot be null", 400, null );
  826. }
  827. RepositorySession repositorySession = repositorySessionFactory.createSession();
  828. try
  829. {
  830. ManagedRepositoryContent repository = repositoryFactory.getManagedRepositoryContent( repositoryId );
  831. repository.deleteGroupId( groupId );
  832. MetadataRepository metadataRepository = repositorySession.getRepository();
  833. metadataRepository.removeNamespace( repositoryId, groupId );
  834. // just invalidate cache entry
  835. String cacheKey = repositoryId + "-" + groupId;
  836. namespacesCache.remove( cacheKey );
  837. namespacesCache.remove( repositoryId );
  838. metadataRepository.save();
  839. }
  840. catch ( MetadataRepositoryException e )
  841. {
  842. log.error( e.getMessage(), e );
  843. throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500, e );
  844. }
  845. catch ( RepositoryException e )
  846. {
  847. log.error( e.getMessage(), e );
  848. throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500, e );
  849. }
  850. finally
  851. {
  852. repositorySession.close();
  853. }
  854. return true;
  855. }
  856. public Boolean deleteProject( String groupId, String projectId, String repositoryId )
  857. throws ArchivaRestServiceException
  858. {
  859. if ( StringUtils.isEmpty( repositoryId ) )
  860. {
  861. throw new ArchivaRestServiceException( "repositoryId cannot be null", 400, null );
  862. }
  863. if ( !isAuthorizedToDeleteArtifacts( repositoryId ) )
  864. {
  865. throw new ArchivaRestServiceException( "not authorized to delete artifacts", 403, null );
  866. }
  867. if ( StringUtils.isEmpty( groupId ) )
  868. {
  869. throw new ArchivaRestServiceException( "groupId cannot be null", 400, null );
  870. }
  871. if ( StringUtils.isEmpty( projectId ) )
  872. {
  873. throw new ArchivaRestServiceException( "artifactId cannot be null", 400, null );
  874. }
  875. RepositorySession repositorySession = repositorySessionFactory.createSession();
  876. try
  877. {
  878. ManagedRepositoryContent repository = repositoryFactory.getManagedRepositoryContent( repositoryId );
  879. repository.deleteProject( groupId, projectId );
  880. }
  881. catch ( ContentNotFoundException e )
  882. {
  883. log.warn( "skip ContentNotFoundException: {}", e.getMessage() );
  884. }
  885. catch ( RepositoryException e )
  886. {
  887. log.error( e.getMessage(), e );
  888. throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500, e );
  889. }
  890. try
  891. {
  892. MetadataRepository metadataRepository = repositorySession.getRepository();
  893. metadataRepository.removeProject( repositoryId, groupId, projectId );
  894. metadataRepository.save();
  895. }
  896. catch ( MetadataRepositoryException e )
  897. {
  898. log.error( e.getMessage(), e );
  899. throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500, e );
  900. }
  901. finally
  902. {
  903. repositorySession.close();
  904. }
  905. return true;
  906. }
  907. public Boolean isAuthorizedToDeleteArtifacts( String repoId )
  908. throws ArchivaRestServiceException
  909. {
  910. String userName =
  911. getAuditInformation().getUser() == null ? "guest" : getAuditInformation().getUser().getUsername();
  912. try
  913. {
  914. return userRepositories.isAuthorizedToDeleteArtifacts( userName, repoId );
  915. }
  916. catch ( ArchivaSecurityException e )
  917. {
  918. throw new ArchivaRestServiceException( e.getMessage(),
  919. Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
  920. }
  921. }
  922. public RepositoryScanStatistics scanRepositoryDirectoriesNow( String repositoryId )
  923. throws ArchivaRestServiceException
  924. {
  925. long sinceWhen = RepositoryScanner.FRESH_SCAN;
  926. try
  927. {
  928. return repoScanner.scan( getManagedRepositoryAdmin().getManagedRepository( repositoryId ), sinceWhen );
  929. }
  930. catch ( RepositoryScannerException e )
  931. {
  932. log.error( e.getMessage(), e );
  933. throw new ArchivaRestServiceException( "RepositoryScannerException exception: " + e.getMessage(), 500, e );
  934. }
  935. catch ( RepositoryAdminException e )
  936. {
  937. log.error( e.getMessage(), e );
  938. throw new ArchivaRestServiceException( "RepositoryScannerException exception: " + e.getMessage(), 500, e );
  939. }
  940. }
  941. /**
  942. * Update artifact level metadata. Creates one if metadata does not exist after artifact deletion.
  943. *
  944. * @param metadata
  945. */
  946. private void updateMetadata( ArchivaRepositoryMetadata metadata, File metadataFile, Date lastUpdatedTimestamp,
  947. Artifact artifact )
  948. throws RepositoryMetadataException
  949. {
  950. List<String> availableVersions = new ArrayList<>();
  951. String latestVersion = "";
  952. if ( metadataFile.exists() )
  953. {
  954. if ( metadata.getAvailableVersions() != null )
  955. {
  956. availableVersions = metadata.getAvailableVersions();
  957. if ( availableVersions.size() > 0 )
  958. {
  959. Collections.sort( availableVersions, VersionComparator.getInstance() );
  960. if ( availableVersions.contains( artifact.getVersion() ) )
  961. {
  962. availableVersions.remove( availableVersions.indexOf( artifact.getVersion() ) );
  963. }
  964. if ( availableVersions.size() > 0 )
  965. {
  966. latestVersion = availableVersions.get( availableVersions.size() - 1 );
  967. }
  968. }
  969. }
  970. }
  971. if ( metadata.getGroupId() == null )
  972. {
  973. metadata.setGroupId( artifact.getGroupId() );
  974. }
  975. if ( metadata.getArtifactId() == null )
  976. {
  977. metadata.setArtifactId( artifact.getArtifactId() );
  978. }
  979. if ( !VersionUtil.isSnapshot( artifact.getVersion() ) )
  980. {
  981. if ( metadata.getReleasedVersion() != null && metadata.getReleasedVersion().equals(
  982. artifact.getVersion() ) )
  983. {
  984. metadata.setReleasedVersion( latestVersion );
  985. }
  986. }
  987. metadata.setLatestVersion( latestVersion );
  988. metadata.setLastUpdatedTimestamp( lastUpdatedTimestamp );
  989. metadata.setAvailableVersions( availableVersions );
  990. RepositoryMetadataWriter.write( metadata, metadataFile );
  991. ChecksummedFile checksum = new ChecksummedFile( metadataFile );
  992. checksum.fixChecksums( algorithms );
  993. }
  994. @Override
  995. public StringList getRunningRemoteDownloadIds()
  996. {
  997. return new StringList( downloadRemoteIndexScheduler.getRunningRemoteDownloadIds() );
  998. }
  999. public ManagedRepositoryAdmin getManagedRepositoryAdmin()
  1000. {
  1001. return managedRepositoryAdmin;
  1002. }
  1003. public void setManagedRepositoryAdmin( ManagedRepositoryAdmin managedRepositoryAdmin )
  1004. {
  1005. this.managedRepositoryAdmin = managedRepositoryAdmin;
  1006. }
  1007. public RepositoryContentFactory getRepositoryFactory()
  1008. {
  1009. return repositoryFactory;
  1010. }
  1011. public void setRepositoryFactory( RepositoryContentFactory repositoryFactory )
  1012. {
  1013. this.repositoryFactory = repositoryFactory;
  1014. }
  1015. public RepositorySessionFactory getRepositorySessionFactory()
  1016. {
  1017. return repositorySessionFactory;
  1018. }
  1019. public void setRepositorySessionFactory( RepositorySessionFactory repositorySessionFactory )
  1020. {
  1021. this.repositorySessionFactory = repositorySessionFactory;
  1022. }
  1023. public List<RepositoryListener> getListeners()
  1024. {
  1025. return listeners;
  1026. }
  1027. public void setListeners( List<RepositoryListener> listeners )
  1028. {
  1029. this.listeners = listeners;
  1030. }
  1031. public ArchivaAdministration getArchivaAdministration()
  1032. {
  1033. return archivaAdministration;
  1034. }
  1035. public void setArchivaAdministration( ArchivaAdministration archivaAdministration )
  1036. {
  1037. this.archivaAdministration = archivaAdministration;
  1038. }
  1039. }