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.AuditInformation;
23 import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
24 import org.apache.archiva.admin.repository.RepositoryAdminException;
25 import org.apache.archiva.audit.AuditEvent;
26 import org.apache.commons.lang.StringUtils;
27 import org.apache.maven.archiva.configuration.Configuration;
28 import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
29 import org.springframework.stereotype.Service;
31 import java.util.ArrayList;
32 import java.util.List;
35 * @author Olivier Lamy
37 @Service( "archivaAdministration#default" )
38 public class DefaultArchivaAdministration
39 extends AbstractRepositoryAdmin
40 implements ArchivaAdministration
42 public List<LegacyArtifactPath> getLegacyArtifactPaths()
43 throws RepositoryAdminException
45 List<LegacyArtifactPath> legacyArtifactPaths = new ArrayList<LegacyArtifactPath>();
46 for ( org.apache.maven.archiva.configuration.LegacyArtifactPath legacyArtifactPath : getArchivaConfiguration().getConfiguration().getLegacyArtifactPaths() )
48 legacyArtifactPaths.add(
49 new BeanReplicator().replicateBean( legacyArtifactPath, LegacyArtifactPath.class ) );
51 return legacyArtifactPaths;
55 public void addLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath, AuditInformation auditInformation )
56 throws RepositoryAdminException
58 Configuration configuration = getArchivaConfiguration().getConfiguration();
60 configuration.addLegacyArtifactPath( new BeanReplicator().replicateBean( legacyArtifactPath,
61 org.apache.maven.archiva.configuration.LegacyArtifactPath.class ) );
63 saveConfiguration( configuration );
64 triggerAuditEvent( "", "", AuditEvent.ADD_LEGACY_PATH, auditInformation );
67 public void deleteLegacyArtifactPath( String path, AuditInformation auditInformation )
68 throws RepositoryAdminException
70 Configuration configuration = getArchivaConfiguration().getConfiguration();
71 org.apache.maven.archiva.configuration.LegacyArtifactPath legacyArtifactPath =
72 new org.apache.maven.archiva.configuration.LegacyArtifactPath();
74 legacyArtifactPath.setPath( path );
75 configuration.removeLegacyArtifactPath( legacyArtifactPath );
77 saveConfiguration( configuration );
78 triggerAuditEvent( "", "", AuditEvent.REMOVE_LEGACY_PATH, auditInformation );
81 public void updateRepositoryScanning( RepositoryScanning repositoryScanning, AuditInformation auditInformation )
82 throws RepositoryAdminException
84 Configuration configuration = getArchivaConfiguration().getConfiguration();
86 configuration.setRepositoryScanning(
87 new BeanReplicator().replicateBean( repositoryScanning, RepositoryScanningConfiguration.class ) );
89 saveConfiguration( configuration );
92 public RepositoryScanning getRepositoryScanning()
93 throws RepositoryAdminException
95 return new BeanReplicator().replicateBean( getArchivaConfiguration().getConfiguration().getRepositoryScanning(),
96 RepositoryScanning.class );
99 public void addFileTypePattern( String fileTypeId, String pattern, AuditInformation auditInformation )
100 throws RepositoryAdminException
102 Configuration configuration = getArchivaConfiguration().getConfiguration();
104 org.apache.maven.archiva.configuration.FileType fileType = getFileTypeById( fileTypeId, configuration );
105 if ( fileType == null )
109 fileType.addPattern( pattern );
111 saveConfiguration( configuration );
112 triggerAuditEvent( "", "", AuditEvent.ADD_PATTERN, auditInformation );
115 public void removeFileTypePattern( String fileTypeId, String pattern, AuditInformation auditInformation )
116 throws RepositoryAdminException
118 Configuration configuration = getArchivaConfiguration().getConfiguration();
120 org.apache.maven.archiva.configuration.FileType fileType = getFileTypeById( fileTypeId, configuration );
121 if ( fileType == null )
125 fileType.removePattern( pattern );
127 saveConfiguration( configuration );
128 triggerAuditEvent( "", "", AuditEvent.REMOVE_PATTERN, auditInformation );
131 public FileType getFileType( String fileTypeId )
132 throws RepositoryAdminException
134 org.apache.maven.archiva.configuration.FileType fileType =
135 getFileTypeById( fileTypeId, getArchivaConfiguration().getConfiguration() );
136 if ( fileType == null )
140 return new BeanReplicator().replicateBean( fileType, FileType.class );
143 public void addFileType( FileType fileType, AuditInformation auditInformation )
144 throws RepositoryAdminException
146 Configuration configuration = getArchivaConfiguration().getConfiguration();
147 if ( getFileTypeById( fileType.getId(), configuration ) != null )
149 throw new RepositoryAdminException(
150 "impossible to FileType with id " + fileType.getId() + " already exists" );
153 configuration.getRepositoryScanning().addFileType(
154 new BeanReplicator().replicateBean( fileType, org.apache.maven.archiva.configuration.FileType.class ) );
155 saveConfiguration( configuration );
158 public void removeFileType( String fileTypeId, AuditInformation auditInformation )
159 throws RepositoryAdminException
161 Configuration configuration = getArchivaConfiguration().getConfiguration();
162 org.apache.maven.archiva.configuration.FileType fileType =
163 new org.apache.maven.archiva.configuration.FileType();
164 fileType.setId( fileTypeId );
165 configuration.getRepositoryScanning().removeFileType( fileType );
166 saveConfiguration( configuration );
169 public void addKnownContentConsumer( String knownContentConsumer, AuditInformation auditInformation )
170 throws RepositoryAdminException
172 Configuration configuration = getArchivaConfiguration().getConfiguration();
173 configuration.getRepositoryScanning().addKnownContentConsumer( knownContentConsumer );
174 saveConfiguration( configuration );
175 triggerAuditEvent( "", "", AuditEvent.ENABLE_REPO_CONSUMER, auditInformation );
178 public void removeKnownContentConsumer( String knownContentConsumer, AuditInformation auditInformation )
179 throws RepositoryAdminException
181 Configuration configuration = getArchivaConfiguration().getConfiguration();
182 configuration.getRepositoryScanning().removeKnownContentConsumer( knownContentConsumer );
183 saveConfiguration( configuration );
184 triggerAuditEvent( "", "", AuditEvent.DISABLE_REPO_CONSUMER, auditInformation );
187 public void addInvalidContentConsumer( String invalidContentConsumer, AuditInformation auditInformation )
188 throws RepositoryAdminException
190 Configuration configuration = getArchivaConfiguration().getConfiguration();
191 configuration.getRepositoryScanning().addInvalidContentConsumer( invalidContentConsumer );
192 saveConfiguration( configuration );
193 triggerAuditEvent( "", "", AuditEvent.ENABLE_REPO_CONSUMER, auditInformation );
196 public void removeInvalidContentConsumer( String invalidContentConsumer, AuditInformation auditInformation )
197 throws RepositoryAdminException
199 Configuration configuration = getArchivaConfiguration().getConfiguration();
200 configuration.getRepositoryScanning().removeInvalidContentConsumer( invalidContentConsumer );
201 saveConfiguration( configuration );
202 triggerAuditEvent( "", "", AuditEvent.DISABLE_REPO_CONSUMER, auditInformation );
205 public void setKnownContentConsumers( List<String> knownContentConsumers, AuditInformation auditInformation )
206 throws RepositoryAdminException
208 if ( knownContentConsumers == null )
212 for ( String knowContentConsumer : knownContentConsumers )
214 addKnownContentConsumer( knowContentConsumer, auditInformation );
218 public void setInvalidContentConsumers( List<String> invalidContentConsumers, AuditInformation auditInformation )
219 throws RepositoryAdminException
221 if ( invalidContentConsumers == null )
225 for ( String invalidContentConsumer : invalidContentConsumers )
227 addKnownContentConsumer( invalidContentConsumer, auditInformation );
231 //-------------------------
233 //-------------------------
235 private org.apache.maven.archiva.configuration.FileType getFileTypeById( String id, Configuration configuration )
237 for ( org.apache.maven.archiva.configuration.FileType fileType : configuration.getRepositoryScanning().getFileTypes() )
239 if ( StringUtils.equals( id, fileType.getId() ) )