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.OrganisationInformation;
28 import org.apache.archiva.admin.model.beans.UiConfiguration;
29 import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
30 import org.apache.archiva.audit.AuditEvent;
31 import org.apache.archiva.configuration.Configuration;
32 import org.apache.archiva.configuration.UserInterfaceOptions;
33 import org.apache.archiva.configuration.WebappConfiguration;
34 import org.apache.commons.lang.StringUtils;
35 import org.springframework.stereotype.Service;
37 import java.util.ArrayList;
38 import java.util.Collections;
39 import java.util.List;
42 * @author Olivier Lamy
44 @Service( "archivaAdministration#default" )
45 public class DefaultArchivaAdministration
46 extends AbstractRepositoryAdmin
47 implements ArchivaAdministration
49 public List<LegacyArtifactPath> getLegacyArtifactPaths()
50 throws RepositoryAdminException
52 List<LegacyArtifactPath> legacyArtifactPaths = new ArrayList<LegacyArtifactPath>();
53 for ( org.apache.archiva.configuration.LegacyArtifactPath legacyArtifactPath : getArchivaConfiguration().getConfiguration().getLegacyArtifactPaths() )
55 legacyArtifactPaths.add(
56 new BeanReplicator().replicateBean( legacyArtifactPath, LegacyArtifactPath.class ) );
58 return legacyArtifactPaths;
62 public void addLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath, AuditInformation auditInformation )
63 throws RepositoryAdminException
65 Configuration configuration = getArchivaConfiguration().getConfiguration();
67 configuration.addLegacyArtifactPath( new BeanReplicator().replicateBean( legacyArtifactPath,
68 org.apache.archiva.configuration.LegacyArtifactPath.class ) );
70 saveConfiguration( configuration );
71 triggerAuditEvent( "", "", AuditEvent.ADD_LEGACY_PATH, auditInformation );
74 public void deleteLegacyArtifactPath( String path, AuditInformation auditInformation )
75 throws RepositoryAdminException
77 Configuration configuration = getArchivaConfiguration().getConfiguration();
78 org.apache.archiva.configuration.LegacyArtifactPath legacyArtifactPath =
79 new org.apache.archiva.configuration.LegacyArtifactPath();
81 legacyArtifactPath.setPath( path );
82 configuration.removeLegacyArtifactPath( legacyArtifactPath );
84 saveConfiguration( configuration );
85 triggerAuditEvent( "", "", AuditEvent.REMOVE_LEGACY_PATH, auditInformation );
89 public void addFileTypePattern( String fileTypeId, String pattern, AuditInformation auditInformation )
90 throws RepositoryAdminException
92 Configuration configuration = getArchivaConfiguration().getConfiguration();
94 org.apache.archiva.configuration.FileType fileType = getFileTypeById( fileTypeId, configuration );
95 if ( fileType == null )
99 fileType.addPattern( pattern );
101 saveConfiguration( configuration );
102 triggerAuditEvent( "", "", AuditEvent.ADD_PATTERN, auditInformation );
105 public void removeFileTypePattern( String fileTypeId, String pattern, AuditInformation auditInformation )
106 throws RepositoryAdminException
108 Configuration configuration = getArchivaConfiguration().getConfiguration();
110 org.apache.archiva.configuration.FileType fileType = getFileTypeById( fileTypeId, configuration );
111 if ( fileType == null )
115 fileType.removePattern( pattern );
117 saveConfiguration( configuration );
118 triggerAuditEvent( "", "", AuditEvent.REMOVE_PATTERN, auditInformation );
121 public FileType getFileType( String fileTypeId )
122 throws RepositoryAdminException
124 org.apache.archiva.configuration.FileType fileType =
125 getFileTypeById( fileTypeId, getArchivaConfiguration().getConfiguration() );
126 if ( fileType == null )
130 return new BeanReplicator().replicateBean( fileType, FileType.class );
133 public void addFileType( FileType fileType, AuditInformation auditInformation )
134 throws RepositoryAdminException
136 Configuration configuration = getArchivaConfiguration().getConfiguration();
137 if ( getFileTypeById( fileType.getId(), configuration ) != null )
139 throw new RepositoryAdminException(
140 "impossible to FileType with id " + fileType.getId() + " already exists" );
143 configuration.getRepositoryScanning().addFileType(
144 new BeanReplicator().replicateBean( fileType, org.apache.archiva.configuration.FileType.class ) );
145 saveConfiguration( configuration );
148 public void removeFileType( String fileTypeId, AuditInformation auditInformation )
149 throws RepositoryAdminException
151 Configuration configuration = getArchivaConfiguration().getConfiguration();
152 org.apache.archiva.configuration.FileType fileType = new org.apache.archiva.configuration.FileType();
153 fileType.setId( fileTypeId );
154 configuration.getRepositoryScanning().removeFileType( fileType );
155 saveConfiguration( configuration );
158 public void addKnownContentConsumer( String knownContentConsumer, AuditInformation auditInformation )
159 throws RepositoryAdminException
161 Configuration configuration = getArchivaConfiguration().getConfiguration();
162 if ( configuration.getRepositoryScanning().getKnownContentConsumers().contains( knownContentConsumer ) )
164 log.warn( "skip adding knownContentConsumer {} as already here", knownContentConsumer );
167 configuration.getRepositoryScanning().addKnownContentConsumer( knownContentConsumer );
168 saveConfiguration( configuration );
169 triggerAuditEvent( "", "", AuditEvent.ENABLE_REPO_CONSUMER, auditInformation );
172 public void removeKnownContentConsumer( String knownContentConsumer, AuditInformation auditInformation )
173 throws RepositoryAdminException
175 Configuration configuration = getArchivaConfiguration().getConfiguration();
176 configuration.getRepositoryScanning().removeKnownContentConsumer( knownContentConsumer );
177 saveConfiguration( configuration );
178 triggerAuditEvent( "", "", AuditEvent.DISABLE_REPO_CONSUMER, auditInformation );
181 public void addInvalidContentConsumer( String invalidContentConsumer, AuditInformation auditInformation )
182 throws RepositoryAdminException
184 Configuration configuration = getArchivaConfiguration().getConfiguration();
185 if ( configuration.getRepositoryScanning().getInvalidContentConsumers().contains( invalidContentConsumer ) )
187 log.warn( "skip adding invalidContentConsumer {} as already here", invalidContentConsumer );
190 configuration.getRepositoryScanning().addInvalidContentConsumer( invalidContentConsumer );
191 saveConfiguration( configuration );
192 triggerAuditEvent( "", "", AuditEvent.ENABLE_REPO_CONSUMER, auditInformation );
195 public void removeInvalidContentConsumer( String invalidContentConsumer, AuditInformation auditInformation )
196 throws RepositoryAdminException
198 Configuration configuration = getArchivaConfiguration().getConfiguration();
199 configuration.getRepositoryScanning().removeInvalidContentConsumer( invalidContentConsumer );
200 saveConfiguration( configuration );
201 triggerAuditEvent( "", "", AuditEvent.DISABLE_REPO_CONSUMER, auditInformation );
204 public void setKnownContentConsumers( List<String> knownContentConsumers, AuditInformation auditInformation )
205 throws RepositoryAdminException
207 if ( knownContentConsumers == null )
211 for ( String knowContentConsumer : knownContentConsumers )
213 addKnownContentConsumer( knowContentConsumer, auditInformation );
217 public void setInvalidContentConsumers( List<String> invalidContentConsumers, AuditInformation auditInformation )
218 throws RepositoryAdminException
220 if ( invalidContentConsumers == null )
224 for ( String invalidContentConsumer : invalidContentConsumers )
226 addKnownContentConsumer( invalidContentConsumer, auditInformation );
230 public List<FileType> getFileTypes()
231 throws RepositoryAdminException
233 List<org.apache.archiva.configuration.FileType> configFileTypes =
234 getArchivaConfiguration().getConfiguration().getRepositoryScanning().getFileTypes();
235 if ( configFileTypes == null || configFileTypes.isEmpty() )
237 return Collections.emptyList();
239 List<FileType> fileTypes = new ArrayList<FileType>();
240 for ( org.apache.archiva.configuration.FileType fileType : configFileTypes )
242 fileTypes.add( new BeanReplicator().replicateBean( fileType, FileType.class ) );
247 public List<String> getKnownContentConsumers()
248 throws RepositoryAdminException
250 return new ArrayList<String>(
251 getArchivaConfiguration().getConfiguration().getRepositoryScanning().getKnownContentConsumers() );
254 public List<String> getInvalidContentConsumers()
255 throws RepositoryAdminException
257 return new ArrayList<String>(
258 getArchivaConfiguration().getConfiguration().getRepositoryScanning().getInvalidContentConsumers() );
261 public OrganisationInformation getOrganisationInformation()
262 throws RepositoryAdminException
264 org.apache.archiva.configuration.OrganisationInformation organisationInformation =
265 getArchivaConfiguration().getConfiguration().getOrganisationInfo();
266 if ( organisationInformation == null )
270 return new BeanReplicator().replicateBean( organisationInformation, OrganisationInformation.class );
273 public void setOrganisationInformation( OrganisationInformation organisationInformation )
274 throws RepositoryAdminException
276 Configuration configuration = getArchivaConfiguration().getConfiguration();
277 if ( organisationInformation != null )
279 org.apache.archiva.configuration.OrganisationInformation organisationInformationModel =
280 new BeanReplicator().replicateBean( organisationInformation,
281 org.apache.archiva.configuration.OrganisationInformation.class );
282 configuration.setOrganisationInfo( organisationInformationModel );
286 configuration.setOrganisationInfo( null );
288 saveConfiguration( configuration );
291 public UiConfiguration getUiConfiguration()
292 throws RepositoryAdminException
294 WebappConfiguration webappConfiguration = getArchivaConfiguration().getConfiguration().getWebapp();
295 if ( webappConfiguration == null )
299 UserInterfaceOptions userInterfaceOptions = webappConfiguration.getUi();
300 if ( userInterfaceOptions == null )
304 return new BeanReplicator().replicateBean( userInterfaceOptions, UiConfiguration.class );
307 public void updateUiConfiguration( UiConfiguration uiConfiguration )
308 throws RepositoryAdminException
310 Configuration configuration = getArchivaConfiguration().getConfiguration();
311 if ( uiConfiguration != null )
314 UserInterfaceOptions userInterfaceOptions =
315 new BeanReplicator().replicateBean( uiConfiguration, UserInterfaceOptions.class );
316 configuration.getWebapp().setUi( userInterfaceOptions );
320 configuration.getWebapp().setUi( null );
322 saveConfiguration( configuration );
326 //-------------------------
328 //-------------------------
330 private org.apache.archiva.configuration.FileType getFileTypeById( String id, Configuration configuration )
332 for ( org.apache.archiva.configuration.FileType fileType : configuration.getRepositoryScanning().getFileTypes() )
334 if ( StringUtils.equals( id, fileType.getId() ) )