This project has retired. For details please refer to its
Attic page.
DefaultProxyConnectorRuleService xref
1 package org.apache.archiva.rest.services;
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.RepositoryAdminException;
22 import org.apache.archiva.admin.model.beans.ProxyConnectorRule;
23 import org.apache.archiva.admin.model.proxyconnectorrule.ProxyConnectorRuleAdmin;
24 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
25 import org.apache.archiva.rest.api.services.ProxyConnectorRuleService;
26 import org.apache.commons.lang.StringUtils;
27 import org.springframework.stereotype.Service;
28
29 import javax.inject.Inject;
30 import java.util.List;
31
32
33
34
35 @Service ("proxyConnectorRuleService#rest")
36 public class DefaultProxyConnectorRuleService
37 extends AbstractRestService
38 implements ProxyConnectorRuleService
39 {
40
41 @Inject
42 private ProxyConnectorRuleAdmin proxyConnectorRuleAdmin;
43
44 @Override
45 public List<ProxyConnectorRule> getProxyConnectorRules()
46 throws ArchivaRestServiceException
47 {
48 try
49 {
50 return proxyConnectorRuleAdmin.getProxyConnectorRules();
51 }
52 catch ( RepositoryAdminException e )
53 {
54 throw new ArchivaRestServiceException( e.getMessage(), e );
55 }
56 }
57
58 private void validateProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
59 throws ArchivaRestServiceException
60 {
61 if ( StringUtils.isEmpty( proxyConnectorRule.getPattern() ) )
62 {
63 ArchivaRestServiceException e = new ArchivaRestServiceException( "pattern cannot be empty", null );
64 e.setErrorKey( "proxy-connector-rule.pattern.empty" );
65 throw e;
66 }
67
68 if ( proxyConnectorRule.getProxyConnectors() == null || proxyConnectorRule.getProxyConnectors().isEmpty() )
69 {
70 ArchivaRestServiceException e =
71 new ArchivaRestServiceException( "proxyConnector rule must have proxyConnectors.", null );
72 e.setErrorKey( "proxy-connector-rule.pattern.connectors.empty" );
73 throw e;
74 }
75
76 for ( ProxyConnectorRule proxyConnectorRule1 : getProxyConnectorRules() )
77 {
78 if ( StringUtils.equals( proxyConnectorRule.getPattern(), proxyConnectorRule1.getPattern() )
79 && proxyConnectorRule.getProxyConnectorRuleType() == proxyConnectorRule1.getProxyConnectorRuleType() )
80 {
81 ArchivaRestServiceException e =
82 new ArchivaRestServiceException( "same ProxyConnector rule already exists.", null );
83 e.setErrorKey( "proxy-connector-rule.pattern.already.exists" );
84 throw e;
85 }
86 }
87 }
88
89 @Override
90 public Boolean addProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
91 throws ArchivaRestServiceException
92 {
93
94 validateProxyConnectorRule( proxyConnectorRule );
95
96 try
97 {
98 proxyConnectorRuleAdmin.addProxyConnectorRule( proxyConnectorRule, getAuditInformation() );
99 return Boolean.TRUE;
100 }
101 catch ( RepositoryAdminException e )
102 {
103 throw new ArchivaRestServiceException( e.getMessage(), e );
104 }
105 }
106
107 @Override
108 public Boolean deleteProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
109 throws ArchivaRestServiceException
110 {
111 try
112 {
113 proxyConnectorRuleAdmin.deleteProxyConnectorRule( proxyConnectorRule, getAuditInformation() );
114 return Boolean.TRUE;
115 }
116 catch ( RepositoryAdminException e )
117 {
118 throw new ArchivaRestServiceException( e.getMessage(), e );
119 }
120 }
121
122 @Override
123 public Boolean updateProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
124 throws ArchivaRestServiceException
125 {
126 try
127 {
128 proxyConnectorRuleAdmin.updateProxyConnectorRule( proxyConnectorRule, getAuditInformation() );
129 return Boolean.TRUE;
130 }
131 catch ( RepositoryAdminException e )
132 {
133 throw new ArchivaRestServiceException( e.getMessage(), e );
134 }
135 }
136 }