1 package org.apache.archiva.admin.repository;
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 org.apache.archiva.admin.model.AuditInformation;
22 import org.apache.archiva.admin.model.RepositoryAdminException;
23 import org.apache.archiva.admin.model.RepositoryCommonValidator;
24 import org.apache.archiva.audit.AuditEvent;
25 import org.apache.archiva.audit.AuditListener;
26 import org.apache.archiva.configuration.ArchivaConfiguration;
27 import org.apache.archiva.configuration.Configuration;
28 import org.apache.archiva.configuration.IndeterminateConfigurationException;
29 import org.apache.archiva.redback.users.User;
30 import org.apache.archiva.redback.components.registry.Registry;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 import javax.inject.Inject;
35 import javax.inject.Named;
36 import java.util.ArrayList;
37 import java.util.List;
40 * @author Olivier Lamy
43 public abstract class AbstractRepositoryAdmin
45 protected Logger log = LoggerFactory.getLogger( getClass() );
48 private List<AuditListener> auditListeners = new ArrayList<AuditListener>();
52 private RepositoryCommonValidator repositoryCommonValidator;
55 private ArchivaConfiguration archivaConfiguration;
58 @Named( value = "commons-configuration" )
59 private Registry registry;
61 protected void triggerAuditEvent( String repositoryId, String resource, String action,
62 AuditInformation auditInformation )
64 User user = auditInformation == null ? null : auditInformation.getUser();
66 new AuditEvent( repositoryId, user == null ? "null" : user.getUsername(), resource, action );
67 event.setRemoteIP( auditInformation == null ? "null" : auditInformation.getRemoteAddr() );
69 for ( AuditListener listener : getAuditListeners() )
71 listener.auditEvent( event );
76 protected void saveConfiguration( Configuration config )
77 throws RepositoryAdminException
81 getArchivaConfiguration().save( config );
83 catch ( org.apache.archiva.redback.components.registry.RegistryException e )
85 throw new RepositoryAdminException( "Error occurred in the registry: " + e.getLocalizedMessage(), e );
87 catch ( IndeterminateConfigurationException e )
89 throw new RepositoryAdminException(
90 "Error occurred while saving the configuration: " + e.getLocalizedMessage(), e );
94 public List<AuditListener> getAuditListeners()
96 return auditListeners;
99 public void setAuditListeners( List<AuditListener> auditListeners )
101 this.auditListeners = auditListeners;
104 public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
106 this.archivaConfiguration = archivaConfiguration;
109 public ArchivaConfiguration getArchivaConfiguration()
111 return archivaConfiguration;
114 public RepositoryCommonValidator getRepositoryCommonValidator()
116 return repositoryCommonValidator;
119 public void setRepositoryCommonValidator( RepositoryCommonValidator repositoryCommonValidator )
121 this.repositoryCommonValidator = repositoryCommonValidator;
124 public Registry getRegistry()
129 public void setRegistry( org.apache.archiva.redback.components.registry.Registry registry )
131 this.registry = registry;