1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.rest.registry; |
35 |
|
|
36 |
|
import info.magnolia.event.EventBus; |
37 |
|
import info.magnolia.event.SystemEventBus; |
38 |
|
import info.magnolia.registry.RegistrationException; |
39 |
|
import info.magnolia.registry.RegistryMap; |
40 |
|
import info.magnolia.rest.EndpointDefinition; |
41 |
|
|
42 |
|
import java.util.ArrayList; |
43 |
|
import java.util.Collection; |
44 |
|
import java.util.List; |
45 |
|
import java.util.Set; |
46 |
|
|
47 |
|
import javax.inject.Inject; |
48 |
|
import javax.inject.Named; |
49 |
|
import javax.inject.Singleton; |
50 |
|
|
51 |
|
import org.slf4j.Logger; |
52 |
|
import org.slf4j.LoggerFactory; |
53 |
|
|
54 |
|
|
55 |
|
@link |
56 |
|
|
57 |
|
@see |
58 |
|
@see |
59 |
|
|
60 |
|
@Singleton |
|
|
| 69.2% |
Uncovered Elements: 12 (39) |
Complexity: 12 |
Complexity Density: 0.43 |
|
61 |
|
public class EndpointDefinitionRegistry { |
62 |
|
|
63 |
|
private final Logger log = LoggerFactory.getLogger(getClass()); |
64 |
|
|
65 |
|
private EventBus systemEventBus; |
66 |
|
private final RegistryMap<String, EndpointDefinitionProvider> registry = new RegistryMap<String, EndpointDefinitionProvider>() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
67 |
16 |
@Override... |
68 |
|
protected String keyFromValue(EndpointDefinitionProvider value) { |
69 |
16 |
return value.getName(); |
70 |
|
} |
71 |
|
}; |
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
73 |
9 |
@Inject... |
74 |
|
public EndpointDefinitionRegistry(@Named(SystemEventBus.NAME) EventBus systemEventBus) { |
75 |
9 |
this.systemEventBus = systemEventBus; |
76 |
|
} |
77 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
78 |
3 |
public EndpointDefinition getEndpointDefinition(String name) throws RegistrationException {... |
79 |
3 |
return getProvider(name).getEndpointDefinition(); |
80 |
|
} |
81 |
|
|
|
|
| 73.7% |
Uncovered Elements: 5 (19) |
Complexity: 4 |
Complexity Density: 0.27 |
|
82 |
10 |
public Set<String> unregisterAndRegister(Set<String> registeredNames, List<EndpointDefinitionProvider> providers) {... |
83 |
10 |
Set<String> nowRegisteredNames = registry.removeAndPutAll(registeredNames, providers); |
84 |
|
|
85 |
|
|
86 |
10 |
for (EndpointDefinitionProvider provider : providers) { |
87 |
8 |
String providerName = provider.getName(); |
88 |
8 |
EndpointDefinition endpointDefinition; |
89 |
8 |
try { |
90 |
8 |
endpointDefinition = provider.getEndpointDefinition(); |
91 |
|
} catch (RegistrationException e) { |
92 |
0 |
log.error("Could not read endpoint definition [" + providerName + "]", e); |
93 |
0 |
continue; |
94 |
|
} |
95 |
|
|
96 |
8 |
if (!registeredNames.contains(providerName)) { |
97 |
8 |
systemEventBus.fireEvent(new EndpointDefinitionRegistryEvent(EndpointDefinitionRegistryEventType.REGISTERED, endpointDefinition)); |
98 |
|
} else { |
99 |
0 |
systemEventBus.fireEvent(new EndpointDefinitionRegistryEvent(EndpointDefinitionRegistryEventType.REREGISTERED, endpointDefinition)); |
100 |
|
} |
101 |
|
} |
102 |
|
|
103 |
|
|
104 |
10 |
for (String registeredName : registeredNames) { |
105 |
1 |
if (!nowRegisteredNames.contains(registeredName)) { |
106 |
1 |
systemEventBus.fireEvent(new EndpointDefinitionRegistryEvent(EndpointDefinitionRegistryEventType.UNREGISTERED, registeredName)); |
107 |
|
} |
108 |
|
} |
109 |
|
|
110 |
10 |
return nowRegisteredNames; |
111 |
|
} |
112 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
113 |
5 |
public boolean isEndpointDefinitionRegistered(String name) {... |
114 |
5 |
return registry.get(name) != null; |
115 |
|
} |
116 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
117 |
0 |
public Collection<EndpointDefinition> getAllEndpointDefinitions() {... |
118 |
0 |
List<EndpointDefinition> endpointDefinitions = new ArrayList<EndpointDefinition>(); |
119 |
0 |
for (EndpointDefinitionProvider provider : registry.values()) { |
120 |
0 |
try { |
121 |
0 |
endpointDefinitions.add(provider.getEndpointDefinition()); |
122 |
|
} catch (RegistrationException e) { |
123 |
0 |
log.error("Could not read endpoint definition [" + provider.getName() + "]", e); |
124 |
|
} |
125 |
|
} |
126 |
0 |
return endpointDefinitions; |
127 |
|
} |
128 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
129 |
3 |
private EndpointDefinitionProvider getProvider(String name) throws RegistrationException {... |
130 |
3 |
try { |
131 |
3 |
return registry.getRequired(name); |
132 |
|
} catch (RegistrationException e) { |
133 |
1 |
throw new RegistrationException("No endpoint definition registered with name: " + name, e); |
134 |
|
} |
135 |
|
} |
136 |
|
} |