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 );
114 public void removeFileTypePattern( String fileTypeId, String pattern, AuditInformation auditInformation )
115 throws RepositoryAdminException
117 Configuration configuration = getArchivaConfiguration().getConfiguration();
119 org.apache.maven.archiva.configuration.FileType fileType = getFileTypeById( fileTypeId, configuration );
120 if ( fileType == null )
124 fileType.removePattern( pattern );
126 saveConfiguration( configuration );
129 public FileType getFileType( String fileTypeId )
130 throws RepositoryAdminException
132 org.apache.maven.archiva.configuration.FileType fileType =
133 getFileTypeById( fileTypeId, getArchivaConfiguration().getConfiguration() );
134 if ( fileType == null )
138 return new BeanReplicator().replicateBean( fileType, FileType.class );
141 public void addFileType( FileType fileType, AuditInformation auditInformation )
142 throws RepositoryAdminException
144 Configuration configuration = getArchivaConfiguration().getConfiguration();
145 if ( getFileTypeById( fileType.getId(), configuration ) != null )
147 throw new RepositoryAdminException(
148 "impossible to FileType with id " + fileType.getId() + " already exists" );
151 configuration.getRepositoryScanning().addFileType(
152 new BeanReplicator().replicateBean( fileType, org.apache.maven.archiva.configuration.FileType.class ) );
153 saveConfiguration( configuration );
156 public void removeFileType( String fileTypeId, AuditInformation auditInformation )
157 throws RepositoryAdminException
159 Configuration configuration = getArchivaConfiguration().getConfiguration();
160 org.apache.maven.archiva.configuration.FileType fileType =
161 new org.apache.maven.archiva.configuration.FileType();
162 fileType.setId( fileTypeId );
163 configuration.getRepositoryScanning().removeFileType( fileType );
164 saveConfiguration( configuration );
167 public void addKnownContentConsumer( String knownContentConsumer, AuditInformation auditInformation )
168 throws RepositoryAdminException
170 Configuration configuration = getArchivaConfiguration().getConfiguration();
171 configuration.getRepositoryScanning().addKnownContentConsumer( knownContentConsumer );
172 saveConfiguration( configuration );
173 triggerAuditEvent( "", "", AuditEvent.ENABLE_REPO_CONSUMER, auditInformation );
176 public void removeKnownContentConsumer( String knownContentConsumer, AuditInformation auditInformation )
177 throws RepositoryAdminException
179 Configuration configuration = getArchivaConfiguration().getConfiguration();
180 configuration.getRepositoryScanning().removeKnownContentConsumer( knownContentConsumer );
181 saveConfiguration( configuration );
182 triggerAuditEvent( "", "", AuditEvent.DISABLE_REPO_CONSUMER, auditInformation );
185 public void addInvalidContentConsumer( String invalidContentConsumer, AuditInformation auditInformation )
186 throws RepositoryAdminException
188 Configuration configuration = getArchivaConfiguration().getConfiguration();
189 configuration.getRepositoryScanning().addInvalidContentConsumer( invalidContentConsumer );
190 saveConfiguration( configuration );
191 triggerAuditEvent( "", "", AuditEvent.ENABLE_REPO_CONSUMER, auditInformation );
194 public void removeInvalidContentConsumer( String invalidContentConsumer, AuditInformation auditInformation )
195 throws RepositoryAdminException
197 Configuration configuration = getArchivaConfiguration().getConfiguration();
198 configuration.getRepositoryScanning().removeInvalidContentConsumer( invalidContentConsumer );
199 saveConfiguration( configuration );
200 triggerAuditEvent( "", "", AuditEvent.DISABLE_REPO_CONSUMER, auditInformation );
203 //-------------------------
205 //-------------------------
207 private org.apache.maven.archiva.configuration.FileType getFileTypeById( String id, Configuration configuration )
209 for ( org.apache.maven.archiva.configuration.FileType fileType : configuration.getRepositoryScanning().getFileTypes() )
211 if ( StringUtils.equals( id, fileType.getId() ) )