This project has retired. For details please refer to its
Attic page.
DefaultProxyConnectorRuleAdmin xref
1 package org.apache.archiva.admin.repository.proxyconnectorrule;
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.beans.ProxyConnector;
24 import org.apache.archiva.admin.model.beans.ProxyConnectorRule;
25 import org.apache.archiva.admin.model.beans.ProxyConnectorRuleType;
26 import org.apache.archiva.admin.model.proxyconnectorrule.ProxyConnectorRuleAdmin;
27 import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
28 import org.apache.archiva.configuration.Configuration;
29 import org.apache.archiva.configuration.ProxyConnectorConfiguration;
30 import org.apache.archiva.configuration.ProxyConnectorRuleConfiguration;
31 import org.apache.commons.lang.StringUtils;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34 import org.springframework.stereotype.Service;
35
36 import java.util.ArrayList;
37 import java.util.Collections;
38 import java.util.List;
39
40
41
42
43
44 @Service("proxyConnectorRuleAdmin#default")
45 public class DefaultProxyConnectorRuleAdmin
46 extends AbstractRepositoryAdmin
47 implements ProxyConnectorRuleAdmin
48 {
49 private Logger log = LoggerFactory.getLogger( getClass() );
50
51 @Override
52 public List<ProxyConnectorRule> getProxyConnectorRules()
53 throws RepositoryAdminException
54 {
55 List<ProxyConnectorRuleConfiguration> proxyConnectorRuleConfigurations =
56 getArchivaConfiguration().getConfiguration().getProxyConnectorRuleConfigurations();
57 if ( proxyConnectorRuleConfigurations.isEmpty() )
58 {
59 return Collections.emptyList();
60 }
61 List<ProxyConnectorRule> proxyConnectorRules = new ArrayList<>( proxyConnectorRuleConfigurations.size() );
62 for ( ProxyConnectorRuleConfiguration proxyConnectorRuleConfiguration : proxyConnectorRuleConfigurations )
63 {
64
65 ProxyConnectorRule proxyConnectorRule = new ProxyConnectorRule();
66 proxyConnectorRule.setPattern( proxyConnectorRuleConfiguration.getPattern() );
67 proxyConnectorRule.setProxyConnectorRuleType(
68 getProxyConnectorRuleType( proxyConnectorRuleConfiguration.getRuleType() ) );
69 for ( ProxyConnectorConfiguration proxyConnectorConfiguration : proxyConnectorRuleConfiguration.getProxyConnectors() )
70 {
71 ProxyConnector proxyConnector = new ProxyConnector();
72 proxyConnector.setSourceRepoId( proxyConnectorConfiguration.getSourceRepoId() );
73 proxyConnector.setTargetRepoId( proxyConnectorConfiguration.getTargetRepoId() );
74 proxyConnectorRule.getProxyConnectors().add( proxyConnector );
75 }
76 proxyConnectorRules.add( proxyConnectorRule );
77 }
78
79 return proxyConnectorRules;
80 }
81
82
83 private ProxyConnectorRuleType getProxyConnectorRuleType( String type )
84 {
85 if ( StringUtils.equals( ProxyConnectorRuleType.WHITE_LIST.getRuleType(), type ) )
86 {
87 return ProxyConnectorRuleType.WHITE_LIST;
88 }
89 if ( StringUtils.equals( ProxyConnectorRuleType.BLACK_LIST.getRuleType(), type ) )
90 {
91 return ProxyConnectorRuleType.BLACK_LIST;
92 }
93 return null;
94 }
95
96 @Override
97 public void addProxyConnectorRule( ProxyConnectorRule proxyConnectorRule, AuditInformation auditInformation )
98 throws RepositoryAdminException
99 {
100 ProxyConnectorRuleConfiguration proxyConnectorRuleConfiguration = new ProxyConnectorRuleConfiguration();
101 proxyConnectorRuleConfiguration.setPattern( proxyConnectorRule.getPattern() );
102 proxyConnectorRuleConfiguration.setRuleType( proxyConnectorRule.getProxyConnectorRuleType().getRuleType() );
103 for ( ProxyConnector proxyConnector : proxyConnectorRule.getProxyConnectors() )
104 {
105 ProxyConnectorConfiguration proxyConnectorConfiguration = new ProxyConnectorConfiguration();
106 proxyConnectorConfiguration.setSourceRepoId( proxyConnector.getSourceRepoId() );
107 proxyConnectorConfiguration.setTargetRepoId( proxyConnector.getTargetRepoId() );
108 proxyConnectorRuleConfiguration.getProxyConnectors().add( proxyConnectorConfiguration );
109 }
110 Configuration configuration = getArchivaConfiguration().getConfiguration();
111 configuration.getProxyConnectorRuleConfigurations().add( proxyConnectorRuleConfiguration );
112 saveConfiguration( configuration );
113 }
114
115 @Override
116 public void deleteProxyConnectorRule( ProxyConnectorRule proxyConnectorRule, AuditInformation auditInformation )
117 throws RepositoryAdminException
118 {
119 Configuration configuration = getArchivaConfiguration().getConfiguration();
120
121
122
123 boolean toSave = false;
124
125 List<ProxyConnectorRuleConfiguration> proxyConnectorRuleConfigurations = new ArrayList<>();
126
127 for ( ProxyConnectorRuleConfiguration proxyConnectorRuleConfiguration : configuration.getProxyConnectorRuleConfigurations() )
128 {
129 if ( StringUtils.equals( proxyConnectorRuleConfiguration.getPattern(), proxyConnectorRule.getPattern() )
130 && StringUtils.equals( proxyConnectorRuleConfiguration.getRuleType(),
131 proxyConnectorRule.getProxyConnectorRuleType().getRuleType() ) )
132 {
133 toSave = true;
134 }
135 else
136 {
137 proxyConnectorRuleConfigurations.add( proxyConnectorRuleConfiguration );
138 }
139 }
140
141 if ( toSave )
142 {
143 configuration.setProxyConnectorRuleConfigurations( proxyConnectorRuleConfigurations );
144 saveConfiguration( configuration );
145 }
146
147 }
148
149 @Override
150 public void updateProxyConnectorRule( ProxyConnectorRule proxyConnectorRule, AuditInformation auditInformation )
151 throws RepositoryAdminException
152 {
153 Configuration configuration = getArchivaConfiguration().getConfiguration();
154
155 for ( ProxyConnectorRuleConfiguration proxyConnectorRuleConfiguration : configuration.getProxyConnectorRuleConfigurations() )
156 {
157 if ( StringUtils.equals( proxyConnectorRuleConfiguration.getPattern(), proxyConnectorRule.getPattern() )
158 && StringUtils.equals( proxyConnectorRuleConfiguration.getRuleType(),
159 proxyConnectorRule.getProxyConnectorRuleType().getRuleType() ) )
160 {
161 List<ProxyConnectorConfiguration> proxyConnectors =
162 new ArrayList<>( proxyConnectorRule.getProxyConnectors().size() );
163 for ( ProxyConnector proxyConnector : proxyConnectorRule.getProxyConnectors() )
164 {
165 ProxyConnectorConfiguration proxyConnectorConfiguration = new ProxyConnectorConfiguration();
166 proxyConnectorConfiguration.setSourceRepoId( proxyConnector.getSourceRepoId() );
167 proxyConnectorConfiguration.setTargetRepoId( proxyConnector.getTargetRepoId() );
168 proxyConnectors.add( proxyConnectorConfiguration );
169 }
170 proxyConnectorRuleConfiguration.setProxyConnectors( proxyConnectors );
171 saveConfiguration( configuration );
172 }
173 }
174
175 }
176 }