1 package org.apache.archiva.admin.repository.admin;
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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
21 import net.sf.beanlib.provider.replicator.BeanReplicator;
22 import org.apache.archiva.admin.model.AuditInformation;
23 import org.apache.archiva.admin.model.RepositoryAdminException;
24 import org.apache.archiva.admin.model.admin.ArchivaAdministration;
25 import org.apache.archiva.admin.model.beans.FileType;
26 import org.apache.archiva.admin.model.beans.LegacyArtifactPath;
27 import org.apache.archiva.admin.model.beans.NetworkConfiguration;
28 import org.apache.archiva.admin.model.beans.OrganisationInformation;
29 import org.apache.archiva.admin.model.beans.UiConfiguration;
30 import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
31 import org.apache.archiva.audit.AuditEvent;
32 import org.apache.archiva.configuration.Configuration;
33 import org.apache.archiva.configuration.UserInterfaceOptions;
34 import org.apache.archiva.configuration.WebappConfiguration;
35 import org.apache.commons.lang.StringUtils;
36 import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
37 import org.apache.maven.wagon.providers.http.HttpWagon;
38 import org.springframework.stereotype.Service;
40 import javax.annotation.PostConstruct;
41 import java.util.ArrayList;
42 import java.util.Collections;
43 import java.util.List;
46 * @author Olivier Lamy
48 @Service( "archivaAdministration#default" )
49 public class DefaultArchivaAdministration
50 extends AbstractRepositoryAdmin
51 implements ArchivaAdministration
55 public void initialize()
56 throws RepositoryAdminException
58 // setup wagon on start with initial values
59 NetworkConfiguration networkConfiguration = getNetworkConfiguration();
60 setupWagon( networkConfiguration );
64 public List<LegacyArtifactPath> getLegacyArtifactPaths()
65 throws RepositoryAdminException
67 List<LegacyArtifactPath> legacyArtifactPaths = new ArrayList<LegacyArtifactPath>();
68 for ( org.apache.archiva.configuration.LegacyArtifactPath legacyArtifactPath : getArchivaConfiguration().getConfiguration().getLegacyArtifactPaths() )
70 legacyArtifactPaths.add(
71 new BeanReplicator().replicateBean( legacyArtifactPath, LegacyArtifactPath.class ) );
73 return legacyArtifactPaths;
76 public void addLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath, AuditInformation auditInformation )
77 throws RepositoryAdminException
79 Configuration configuration = getArchivaConfiguration().getConfiguration();
81 configuration.addLegacyArtifactPath( new BeanReplicator().replicateBean( legacyArtifactPath,
82 org.apache.archiva.configuration.LegacyArtifactPath.class ) );
84 saveConfiguration( configuration );
85 triggerAuditEvent( "", "", AuditEvent.ADD_LEGACY_PATH, auditInformation );
88 public void deleteLegacyArtifactPath( String path, AuditInformation auditInformation )
89 throws RepositoryAdminException
91 Configuration configuration = getArchivaConfiguration().getConfiguration();
92 org.apache.archiva.configuration.LegacyArtifactPath legacyArtifactPath =
93 new org.apache.archiva.configuration.LegacyArtifactPath();
95 legacyArtifactPath.setPath( path );
96 configuration.removeLegacyArtifactPath( legacyArtifactPath );
98 saveConfiguration( configuration );
99 triggerAuditEvent( "", "", AuditEvent.REMOVE_LEGACY_PATH, auditInformation );
103 public void addFileTypePattern( String fileTypeId, String pattern, AuditInformation auditInformation )
104 throws RepositoryAdminException
106 Configuration configuration = getArchivaConfiguration().getConfiguration();
108 org.apache.archiva.configuration.FileType fileType = getFileTypeById( fileTypeId, configuration );
109 if ( fileType == null )
113 fileType.addPattern( pattern );
115 saveConfiguration( configuration );
116 triggerAuditEvent( "", "", AuditEvent.ADD_PATTERN, auditInformation );
119 public void removeFileTypePattern( String fileTypeId, String pattern, AuditInformation auditInformation )
120 throws RepositoryAdminException
122 Configuration configuration = getArchivaConfiguration().getConfiguration();
124 org.apache.archiva.configuration.FileType fileType = getFileTypeById( fileTypeId, configuration );
125 if ( fileType == null )
129 fileType.removePattern( pattern );
131 saveConfiguration( configuration );
132 triggerAuditEvent( "", "", AuditEvent.REMOVE_PATTERN, auditInformation );
135 public FileType getFileType( String fileTypeId )
136 throws RepositoryAdminException
138 org.apache.archiva.configuration.FileType fileType =
139 getFileTypeById( fileTypeId, getArchivaConfiguration().getConfiguration() );
140 if ( fileType == null )
144 return new BeanReplicator().replicateBean( fileType, FileType.class );
147 public void addFileType( FileType fileType, AuditInformation auditInformation )
148 throws RepositoryAdminException
150 Configuration configuration = getArchivaConfiguration().getConfiguration();
151 if ( getFileTypeById( fileType.getId(), configuration ) != null )
153 throw new RepositoryAdminException(
154 "impossible to FileType with id " + fileType.getId() + " already exists" );
157 configuration.getRepositoryScanning().addFileType(
158 new BeanReplicator().replicateBean( fileType, org.apache.archiva.configuration.FileType.class ) );
159 saveConfiguration( configuration );
162 public void removeFileType( String fileTypeId, AuditInformation auditInformation )
163 throws RepositoryAdminException
165 Configuration configuration = getArchivaConfiguration().getConfiguration();
166 org.apache.archiva.configuration.FileType fileType = new org.apache.archiva.configuration.FileType();
167 fileType.setId( fileTypeId );
168 configuration.getRepositoryScanning().removeFileType( fileType );
169 saveConfiguration( configuration );
172 public void addKnownContentConsumer( String knownContentConsumer, AuditInformation auditInformation )
173 throws RepositoryAdminException
175 Configuration configuration = getArchivaConfiguration().getConfiguration();
176 if ( configuration.getRepositoryScanning().getKnownContentConsumers().contains( knownContentConsumer ) )
178 log.warn( "skip adding knownContentConsumer {} as already here", knownContentConsumer );
181 configuration.getRepositoryScanning().addKnownContentConsumer( knownContentConsumer );
182 saveConfiguration( configuration );
183 triggerAuditEvent( "", "", AuditEvent.ENABLE_REPO_CONSUMER, auditInformation );
186 public void removeKnownContentConsumer( String knownContentConsumer, AuditInformation auditInformation )
187 throws RepositoryAdminException
189 Configuration configuration = getArchivaConfiguration().getConfiguration();
190 configuration.getRepositoryScanning().removeKnownContentConsumer( knownContentConsumer );
191 saveConfiguration( configuration );
192 triggerAuditEvent( "", "", AuditEvent.DISABLE_REPO_CONSUMER, auditInformation );
195 public void addInvalidContentConsumer( String invalidContentConsumer, AuditInformation auditInformation )
196 throws RepositoryAdminException
198 Configuration configuration = getArchivaConfiguration().getConfiguration();
199 if ( configuration.getRepositoryScanning().getInvalidContentConsumers().contains( invalidContentConsumer ) )
201 log.warn( "skip adding invalidContentConsumer {} as already here", invalidContentConsumer );
204 configuration.getRepositoryScanning().addInvalidContentConsumer( invalidContentConsumer );
205 saveConfiguration( configuration );
206 triggerAuditEvent( "", "", AuditEvent.ENABLE_REPO_CONSUMER, auditInformation );
209 public void removeInvalidContentConsumer( String invalidContentConsumer, AuditInformation auditInformation )
210 throws RepositoryAdminException
212 Configuration configuration = getArchivaConfiguration().getConfiguration();
213 configuration.getRepositoryScanning().removeInvalidContentConsumer( invalidContentConsumer );
214 saveConfiguration( configuration );
215 triggerAuditEvent( "", "", AuditEvent.DISABLE_REPO_CONSUMER, auditInformation );
218 public void setKnownContentConsumers( List<String> knownContentConsumers, AuditInformation auditInformation )
219 throws RepositoryAdminException
221 if ( knownContentConsumers == null )
225 for ( String knowContentConsumer : knownContentConsumers )
227 addKnownContentConsumer( knowContentConsumer, auditInformation );
231 public void setInvalidContentConsumers( List<String> invalidContentConsumers, AuditInformation auditInformation )
232 throws RepositoryAdminException
234 if ( invalidContentConsumers == null )
238 for ( String invalidContentConsumer : invalidContentConsumers )
240 addKnownContentConsumer( invalidContentConsumer, auditInformation );
244 public List<FileType> getFileTypes()
245 throws RepositoryAdminException
247 List<org.apache.archiva.configuration.FileType> configFileTypes =
248 getArchivaConfiguration().getConfiguration().getRepositoryScanning().getFileTypes();
249 if ( configFileTypes == null || configFileTypes.isEmpty() )
251 return Collections.emptyList();
253 List<FileType> fileTypes = new ArrayList<FileType>();
254 for ( org.apache.archiva.configuration.FileType fileType : configFileTypes )
256 fileTypes.add( new BeanReplicator().replicateBean( fileType, FileType.class ) );
261 public List<String> getKnownContentConsumers()
262 throws RepositoryAdminException
264 return new ArrayList<String>(
265 getArchivaConfiguration().getConfiguration().getRepositoryScanning().getKnownContentConsumers() );
268 public List<String> getInvalidContentConsumers()
269 throws RepositoryAdminException
271 return new ArrayList<String>(
272 getArchivaConfiguration().getConfiguration().getRepositoryScanning().getInvalidContentConsumers() );
275 public OrganisationInformation getOrganisationInformation()
276 throws RepositoryAdminException
278 org.apache.archiva.configuration.OrganisationInformation organisationInformation =
279 getArchivaConfiguration().getConfiguration().getOrganisationInfo();
280 if ( organisationInformation == null )
284 return new BeanReplicator().replicateBean( organisationInformation, OrganisationInformation.class );
287 public void setOrganisationInformation( OrganisationInformation organisationInformation )
288 throws RepositoryAdminException
290 Configuration configuration = getArchivaConfiguration().getConfiguration();
291 if ( organisationInformation != null )
293 org.apache.archiva.configuration.OrganisationInformation organisationInformationModel =
294 new BeanReplicator().replicateBean( organisationInformation,
295 org.apache.archiva.configuration.OrganisationInformation.class );
296 configuration.setOrganisationInfo( organisationInformationModel );
300 configuration.setOrganisationInfo( null );
302 saveConfiguration( configuration );
305 public UiConfiguration getUiConfiguration()
306 throws RepositoryAdminException
308 WebappConfiguration webappConfiguration = getArchivaConfiguration().getConfiguration().getWebapp();
309 if ( webappConfiguration == null )
313 UserInterfaceOptions userInterfaceOptions = webappConfiguration.getUi();
314 if ( userInterfaceOptions == null )
318 return new BeanReplicator().replicateBean( userInterfaceOptions, UiConfiguration.class );
321 public void updateUiConfiguration( UiConfiguration uiConfiguration )
322 throws RepositoryAdminException
324 Configuration configuration = getArchivaConfiguration().getConfiguration();
325 if ( uiConfiguration != null )
328 UserInterfaceOptions userInterfaceOptions =
329 new BeanReplicator().replicateBean( uiConfiguration, UserInterfaceOptions.class );
330 configuration.getWebapp().setUi( userInterfaceOptions );
334 configuration.getWebapp().setUi( null );
336 saveConfiguration( configuration );
340 public NetworkConfiguration getNetworkConfiguration()
341 throws RepositoryAdminException
343 org.apache.archiva.configuration.NetworkConfiguration networkConfiguration =
344 getArchivaConfiguration().getConfiguration().getNetworkConfiguration();
346 if ( networkConfiguration == null )
350 return new BeanReplicator().replicateBean( networkConfiguration, NetworkConfiguration.class );
353 public void setNetworkConfiguration( NetworkConfiguration networkConfiguration )
354 throws RepositoryAdminException
356 Configuration configuration = getArchivaConfiguration().getConfiguration();
357 if ( networkConfiguration == null )
359 configuration.setNetworkConfiguration( null );
363 configuration.setNetworkConfiguration( new BeanReplicator().replicateBean( networkConfiguration,
364 org.apache.archiva.configuration.NetworkConfiguration.class ) );
366 setupWagon( networkConfiguration );
367 saveConfiguration( configuration );
370 protected void setupWagon( NetworkConfiguration networkConfiguration )
372 if ( networkConfiguration == null )
374 // back to default values
375 HttpWagon.setUseClientManagerPooled( true );
376 ThreadSafeClientConnManager threadSafeClientConnManager = new ThreadSafeClientConnManager();
377 threadSafeClientConnManager.setDefaultMaxPerRoute( 30 );
378 threadSafeClientConnManager.setMaxTotal( 30 );
379 HttpWagon.setConnectionManagerPooled( threadSafeClientConnManager );
384 HttpWagon.setUseClientManagerPooled( networkConfiguration.isUsePooling() );
385 ThreadSafeClientConnManager threadSafeClientConnManager = new ThreadSafeClientConnManager();
386 threadSafeClientConnManager.setDefaultMaxPerRoute( networkConfiguration.getMaxTotalPerHost() );
387 threadSafeClientConnManager.setMaxTotal( networkConfiguration.getMaxTotal() );
388 HttpWagon.setConnectionManagerPooled( threadSafeClientConnManager );
392 //-------------------------
394 //-------------------------
396 private org.apache.archiva.configuration.FileType getFileTypeById( String id, Configuration configuration )
398 for ( org.apache.archiva.configuration.FileType fileType : configuration.getRepositoryScanning().getFileTypes() )
400 if ( StringUtils.equals( id, fileType.getId() ) )