This project has retired. For details please refer to its
Attic page.
AbstractRepositoryAdmin xref
1 package org.apache.archiva.admin.repository;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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.configuration.ArchivaConfiguration;
25 import org.apache.archiva.configuration.Configuration;
26 import org.apache.archiva.configuration.IndeterminateConfigurationException;
27 import org.apache.archiva.metadata.model.facets.AuditEvent;
28 import org.apache.archiva.redback.users.User;
29 import org.apache.archiva.redback.components.registry.Registry;
30 import org.apache.archiva.repository.events.AuditListener;
31 import org.modelmapper.ModelMapper;
32 import org.modelmapper.convention.MatchingStrategies;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import org.springframework.beans.factory.annotation.Autowired;
36
37 import javax.inject.Inject;
38 import javax.inject.Named;
39 import java.util.ArrayList;
40 import java.util.List;
41
42
43
44
45
46 public abstract class AbstractRepositoryAdmin
47 {
48 protected Logger log = LoggerFactory.getLogger( getClass() );
49
50 @Inject
51 @Autowired(required = false)
52 private List<AuditListener> auditListeners = new ArrayList<>();
53
54 @Inject
55 private RepositoryCommonValidator repositoryCommonValidator;
56
57 @Inject
58 private ArchivaConfiguration archivaConfiguration;
59
60 @Inject
61 @Named(value = "commons-configuration")
62 private Registry registry;
63
64 protected void triggerAuditEvent( String repositoryId, String resource, String action,
65 AuditInformation auditInformation )
66 {
67 User user = auditInformation == null ? null : auditInformation.getUser();
68 AuditEvent event = new AuditEvent( repositoryId, user == null ? "null" : user.getUsername(), resource, action );
69 event.setRemoteIP( auditInformation == null ? "null" : auditInformation.getRemoteAddr() );
70
71 for ( AuditListener listener : getAuditListeners() )
72 {
73 listener.auditEvent( event );
74 }
75
76 }
77
78 protected void saveConfiguration( Configuration config )
79 throws RepositoryAdminException
80 {
81 try
82 {
83 getArchivaConfiguration().save( config );
84 }
85 catch ( org.apache.archiva.redback.components.registry.RegistryException e )
86 {
87 throw new RepositoryAdminException( "Error occurred in the registry: " + e.getLocalizedMessage(), e );
88 }
89 catch ( IndeterminateConfigurationException e )
90 {
91 throw new RepositoryAdminException(
92 "Error occurred while saving the configuration: " + e.getLocalizedMessage(), e );
93 }
94 }
95
96 private static class ModelMapperHolder
97 {
98 private static ModelMapper MODEL_MAPPER = new ModelMapper();
99
100 static
101 {
102 MODEL_MAPPER.getConfiguration().setMatchingStrategy( MatchingStrategies.STRICT );
103 }
104
105 }
106
107 protected ModelMapper getModelMapper()
108 {
109 return ModelMapperHolder.MODEL_MAPPER;
110 }
111
112 public List<AuditListener> getAuditListeners()
113 {
114 return auditListeners;
115 }
116
117 public void setAuditListeners( List<AuditListener> auditListeners )
118 {
119 this.auditListeners = auditListeners;
120 }
121
122 public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
123 {
124 this.archivaConfiguration = archivaConfiguration;
125 }
126
127 public ArchivaConfiguration getArchivaConfiguration()
128 {
129 return archivaConfiguration;
130 }
131
132 public RepositoryCommonValidator getRepositoryCommonValidator()
133 {
134 return repositoryCommonValidator;
135 }
136
137 public void setRepositoryCommonValidator( RepositoryCommonValidator repositoryCommonValidator )
138 {
139 this.repositoryCommonValidator = repositoryCommonValidator;
140 }
141
142 public Registry getRegistry()
143 {
144 return registry;
145 }
146
147 public void setRegistry( org.apache.archiva.redback.components.registry.Registry registry )
148 {
149 this.registry = registry;
150 }
151 }