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.springframework.stereotype.Service;
30 import java.util.ArrayList;
31 import java.util.Collections;
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 );
82 public void addFileTypePattern( String fileTypeId, String pattern, AuditInformation auditInformation )
83 throws RepositoryAdminException
85 Configuration configuration = getArchivaConfiguration().getConfiguration();
87 org.apache.maven.archiva.configuration.FileType fileType = getFileTypeById( fileTypeId, configuration );
88 if ( fileType == null )
92 fileType.addPattern( pattern );
94 saveConfiguration( configuration );
95 triggerAuditEvent( "", "", AuditEvent.ADD_PATTERN, auditInformation );
98 public void removeFileTypePattern( String fileTypeId, String pattern, AuditInformation auditInformation )
99 throws RepositoryAdminException
101 Configuration configuration = getArchivaConfiguration().getConfiguration();
103 org.apache.maven.archiva.configuration.FileType fileType = getFileTypeById( fileTypeId, configuration );
104 if ( fileType == null )
108 fileType.removePattern( pattern );
110 saveConfiguration( configuration );
111 triggerAuditEvent( "", "", AuditEvent.REMOVE_PATTERN, auditInformation );
114 public FileType getFileType( String fileTypeId )
115 throws RepositoryAdminException
117 org.apache.maven.archiva.configuration.FileType fileType =
118 getFileTypeById( fileTypeId, getArchivaConfiguration().getConfiguration() );
119 if ( fileType == null )
123 return new BeanReplicator().replicateBean( fileType, FileType.class );
126 public void addFileType( FileType fileType, AuditInformation auditInformation )
127 throws RepositoryAdminException
129 Configuration configuration = getArchivaConfiguration().getConfiguration();
130 if ( getFileTypeById( fileType.getId(), configuration ) != null )
132 throw new RepositoryAdminException(
133 "impossible to FileType with id " + fileType.getId() + " already exists" );
136 configuration.getRepositoryScanning().addFileType(
137 new BeanReplicator().replicateBean( fileType, org.apache.maven.archiva.configuration.FileType.class ) );
138 saveConfiguration( configuration );
141 public void removeFileType( String fileTypeId, AuditInformation auditInformation )
142 throws RepositoryAdminException
144 Configuration configuration = getArchivaConfiguration().getConfiguration();
145 org.apache.maven.archiva.configuration.FileType fileType =
146 new org.apache.maven.archiva.configuration.FileType();
147 fileType.setId( fileTypeId );
148 configuration.getRepositoryScanning().removeFileType( fileType );
149 saveConfiguration( configuration );
152 public void addKnownContentConsumer( String knownContentConsumer, AuditInformation auditInformation )
153 throws RepositoryAdminException
155 Configuration configuration = getArchivaConfiguration().getConfiguration();
156 if ( configuration.getRepositoryScanning().getKnownContentConsumers().contains( knownContentConsumer ) )
158 log.warn( "skip adding knownContentConsumer {} as already here", knownContentConsumer );
161 configuration.getRepositoryScanning().addKnownContentConsumer( knownContentConsumer );
162 saveConfiguration( configuration );
163 triggerAuditEvent( "", "", AuditEvent.ENABLE_REPO_CONSUMER, auditInformation );
166 public void removeKnownContentConsumer( String knownContentConsumer, AuditInformation auditInformation )
167 throws RepositoryAdminException
169 Configuration configuration = getArchivaConfiguration().getConfiguration();
170 configuration.getRepositoryScanning().removeKnownContentConsumer( knownContentConsumer );
171 saveConfiguration( configuration );
172 triggerAuditEvent( "", "", AuditEvent.DISABLE_REPO_CONSUMER, auditInformation );
175 public void addInvalidContentConsumer( String invalidContentConsumer, AuditInformation auditInformation )
176 throws RepositoryAdminException
178 Configuration configuration = getArchivaConfiguration().getConfiguration();
179 if ( configuration.getRepositoryScanning().getInvalidContentConsumers().contains( invalidContentConsumer ) )
181 log.warn( "skip adding invalidContentConsumer {} as already here", invalidContentConsumer );
184 configuration.getRepositoryScanning().addInvalidContentConsumer( invalidContentConsumer );
185 saveConfiguration( configuration );
186 triggerAuditEvent( "", "", AuditEvent.ENABLE_REPO_CONSUMER, auditInformation );
189 public void removeInvalidContentConsumer( String invalidContentConsumer, AuditInformation auditInformation )
190 throws RepositoryAdminException
192 Configuration configuration = getArchivaConfiguration().getConfiguration();
193 configuration.getRepositoryScanning().removeInvalidContentConsumer( invalidContentConsumer );
194 saveConfiguration( configuration );
195 triggerAuditEvent( "", "", AuditEvent.DISABLE_REPO_CONSUMER, auditInformation );
198 public void setKnownContentConsumers( List<String> knownContentConsumers, AuditInformation auditInformation )
199 throws RepositoryAdminException
201 if ( knownContentConsumers == null )
205 for ( String knowContentConsumer : knownContentConsumers )
207 addKnownContentConsumer( knowContentConsumer, auditInformation );
211 public void setInvalidContentConsumers( List<String> invalidContentConsumers, AuditInformation auditInformation )
212 throws RepositoryAdminException
214 if ( invalidContentConsumers == null )
218 for ( String invalidContentConsumer : invalidContentConsumers )
220 addKnownContentConsumer( invalidContentConsumer, auditInformation );
224 public List<FileType> getFileTypes()
225 throws RepositoryAdminException
227 List<org.apache.maven.archiva.configuration.FileType> configFileTypes =
228 getArchivaConfiguration().getConfiguration().getRepositoryScanning().getFileTypes();
229 if ( configFileTypes == null || configFileTypes.isEmpty() )
231 return Collections.emptyList();
233 List<FileType> fileTypes = new ArrayList<FileType>();
234 for ( org.apache.maven.archiva.configuration.FileType fileType : configFileTypes )
236 fileTypes.add( new BeanReplicator().replicateBean( fileType, FileType.class ) );
241 public List<String> getKnownContentConsumers()
242 throws RepositoryAdminException
244 return new ArrayList<String>(
245 getArchivaConfiguration().getConfiguration().getRepositoryScanning().getKnownContentConsumers() );
248 public List<String> getInvalidContentConsumers()
249 throws RepositoryAdminException
251 return new ArrayList<String>(
252 getArchivaConfiguration().getConfiguration().getRepositoryScanning().getInvalidContentConsumers() );
255 //-------------------------
257 //-------------------------
259 private org.apache.maven.archiva.configuration.FileType getFileTypeById( String id, Configuration configuration )
261 for ( org.apache.maven.archiva.configuration.FileType fileType : configuration.getRepositoryScanning().getFileTypes() )
263 if ( StringUtils.equals( id, fileType.getId() ) )