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 static info.magnolia.rest.registry.EndpointDefinitionRegistryEventType.*; |
37 |
|
|
38 |
|
import info.magnolia.config.registry.AbstractRegistry; |
39 |
|
import info.magnolia.config.registry.DefinitionMetadata; |
40 |
|
import info.magnolia.config.registry.DefinitionMetadataBuilder; |
41 |
|
import info.magnolia.config.registry.DefinitionProvider; |
42 |
|
import info.magnolia.config.registry.DefinitionType; |
43 |
|
import info.magnolia.event.EventBus; |
44 |
|
import info.magnolia.event.SystemEventBus; |
45 |
|
import info.magnolia.module.ModuleRegistry; |
46 |
|
import info.magnolia.objectfactory.Components; |
47 |
|
import info.magnolia.registry.RegistrationException; |
48 |
|
import info.magnolia.rest.EndpointDefinition; |
49 |
|
|
50 |
|
import java.util.Collection; |
51 |
|
import java.util.List; |
52 |
|
import java.util.Set; |
53 |
|
|
54 |
|
import javax.inject.Inject; |
55 |
|
import javax.inject.Named; |
56 |
|
import javax.inject.Singleton; |
57 |
|
|
58 |
|
|
59 |
|
@linkplain |
60 |
|
|
61 |
|
@Singleton |
|
|
| 52.9% |
Uncovered Elements: 16 (34) |
Complexity: 13 |
Complexity Density: 0.57 |
|
62 |
|
public class EndpointDefinitionRegistry extends AbstractRegistry<EndpointDefinition> { |
63 |
|
static final DefinitionType TYPE = new DefinitionType() { |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
64 |
0 |
@Override... |
65 |
|
public String name() { |
66 |
0 |
return "restEndpoint"; |
67 |
|
} |
68 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
69 |
0 |
@Override... |
70 |
|
public Class baseClass() { |
71 |
0 |
return EndpointDefinition.class; |
72 |
|
} |
73 |
|
}; |
74 |
|
|
75 |
|
private EventBus systemEventBus; |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
77 |
9 |
@Inject... |
78 |
|
public EndpointDefinitionRegistry(ModuleRegistry moduleRegistry, @Named(SystemEventBus.NAME) EventBus systemEventBus) { |
79 |
9 |
super(moduleRegistry); |
80 |
9 |
this.systemEventBus = systemEventBus; |
81 |
|
} |
82 |
|
|
83 |
|
|
84 |
|
@deprecated@link |
85 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
86 |
0 |
@Deprecated... |
87 |
|
public EndpointDefinitionRegistry(@Named(SystemEventBus.NAME) EventBus systemEventBus) { |
88 |
0 |
this(Components.getComponent(ModuleRegistry.class), systemEventBus); |
89 |
|
} |
90 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
91 |
0 |
@Override... |
92 |
|
public DefinitionType type() { |
93 |
0 |
return TYPE; |
94 |
|
} |
95 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
96 |
0 |
@Override... |
97 |
|
public DefinitionMetadataBuilder newMetadataBuilder() { |
98 |
0 |
return DefinitionMetadataBuilder.usingNameAsId(); |
99 |
|
} |
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
101 |
28 |
@Override... |
102 |
|
public void register(DefinitionProvider<EndpointDefinition> provider) { |
103 |
28 |
super.register(provider); |
104 |
28 |
systemEventBus.fireEvent(new EndpointDefinitionRegistryEvent(REGISTERED, provider)); |
105 |
|
} |
106 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
107 |
3 |
@Override... |
108 |
|
public Set<DefinitionMetadata> unregisterAndRegister(Collection<DefinitionMetadata> toRemoveIds, Collection<DefinitionProvider<EndpointDefinition>> definitionProviders) { |
109 |
3 |
Set<DefinitionMetadata> registeredIds = super.unregisterAndRegister(toRemoveIds, definitionProviders); |
110 |
|
|
111 |
3 |
toRemoveIds.stream() |
112 |
|
.filter(metadata -> !registeredIds.contains(metadata)) |
113 |
|
.map(DefinitionMetadata::getReferenceId) |
114 |
|
.forEach(referenceId -> systemEventBus.fireEvent(new EndpointDefinitionRegistryEvent(UNREGISTERED, referenceId))); |
115 |
|
|
116 |
3 |
definitionProviders.stream() |
117 |
|
.filter(provider -> toRemoveIds.contains(provider.getMetadata())) |
118 |
|
.filter(provider -> registeredIds.contains(provider.getMetadata())) |
119 |
|
.forEach(provider -> systemEventBus.fireEvent(new EndpointDefinitionRegistryEvent(REREGISTERED, provider))); |
120 |
|
|
121 |
3 |
definitionProviders.stream() |
122 |
|
.filter(provider -> !toRemoveIds.contains(provider.getMetadata())) |
123 |
|
.filter(provider -> registeredIds.contains(provider.getMetadata())) |
124 |
|
.forEach(provider -> systemEventBus.fireEvent(new EndpointDefinitionRegistryEvent(REGISTERED, provider))); |
125 |
|
|
126 |
3 |
return registeredIds; |
127 |
|
} |
128 |
|
|
129 |
|
|
130 |
|
@deprecated@link |
131 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
132 |
2 |
@Deprecated... |
133 |
|
public EndpointDefinition getEndpointDefinition(String name) throws RegistrationException { |
134 |
2 |
final EndpointDefinition endpointDefinition; |
135 |
2 |
try { |
136 |
2 |
endpointDefinition = getProvider(name).get(); |
137 |
|
} catch (NoSuchDefinitionException | InvalidDefinitionException e) { |
138 |
1 |
throw new RegistrationException(e.getMessage(), e); |
139 |
|
} |
140 |
1 |
return endpointDefinition; |
141 |
|
} |
142 |
|
|
143 |
|
|
144 |
|
@deprecated@link |
145 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
146 |
0 |
@Deprecated... |
147 |
|
public Set<String> unregisterAndRegister(Set<String> registeredNames, List<EndpointDefinitionProvider> providers) { |
148 |
0 |
return null; |
149 |
|
} |
150 |
|
|
151 |
|
|
152 |
|
@deprecated@link@link |
153 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
154 |
0 |
@Deprecated... |
155 |
|
public boolean isEndpointDefinitionRegistered(String name) { |
156 |
0 |
try { |
157 |
0 |
return getProvider(name).isValid(); |
158 |
|
} catch (NoSuchDefinitionException e) { |
159 |
0 |
return false; |
160 |
|
} |
161 |
|
} |
162 |
|
|
163 |
|
|
164 |
|
@deprecated@link |
165 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
166 |
|
@Deprecated... |
167 |
|
public Collection<EndpointDefinition> getAllEndpointDefinitions() { |
168 |
|
return getAllDefinitions(); |
169 |
|
} |
170 |
|
} |