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.client.registry; |
35 |
|
|
36 |
|
import info.magnolia.cms.util.ModuleConfigurationObservingManager; |
37 |
|
import info.magnolia.jcr.util.NodeTypes; |
38 |
|
import info.magnolia.jcr.util.NodeUtil; |
39 |
|
import info.magnolia.jcr.util.NodeVisitor; |
40 |
|
import info.magnolia.module.ModuleRegistry; |
41 |
|
import info.magnolia.objectfactory.ComponentProvider; |
42 |
|
import info.magnolia.rest.client.RestClientDefinition; |
43 |
|
|
44 |
|
import java.util.ArrayList; |
45 |
|
import java.util.HashSet; |
46 |
|
import java.util.List; |
47 |
|
import java.util.Set; |
48 |
|
|
49 |
|
import javax.inject.Inject; |
50 |
|
import javax.inject.Singleton; |
51 |
|
import javax.jcr.Node; |
52 |
|
import javax.jcr.RepositoryException; |
53 |
|
|
54 |
|
import org.apache.jackrabbit.commons.predicate.NodeTypePredicate; |
55 |
|
import org.slf4j.Logger; |
56 |
|
import org.slf4j.LoggerFactory; |
57 |
|
|
58 |
|
|
59 |
|
@link |
60 |
|
|
61 |
|
@Singleton |
|
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 8 |
Complexity Density: 0.42 |
|
62 |
|
public class ConfiguredRestClientManager extends ModuleConfigurationObservingManager { |
63 |
|
|
64 |
|
private static final Logger log = LoggerFactory.getLogger(ConfiguredRestClientManager.class); |
65 |
|
|
66 |
|
private Set<String> registeredIds = new HashSet<String>(); |
67 |
|
private RestClientRegistry restClientDefinitionRegistry; |
68 |
|
private final ComponentProvider componentProvider; |
69 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
70 |
0 |
@Inject... |
71 |
|
public ConfiguredRestClientManager(ModuleRegistry moduleRegistry, RestClientRegistry restClientDefinitionRegistry, ComponentProvider componentProvider) { |
72 |
0 |
super("rest-client", moduleRegistry); |
73 |
0 |
this.restClientDefinitionRegistry = restClientDefinitionRegistry; |
74 |
0 |
this.componentProvider = componentProvider; |
75 |
|
} |
76 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
77 |
0 |
@Override... |
78 |
|
protected void reload(List<Node> nodes) throws RepositoryException { |
79 |
|
|
80 |
0 |
final List<RestClientProvider> providers = new ArrayList<RestClientProvider>(); |
81 |
|
|
82 |
0 |
for (Node node : nodes) { |
83 |
|
|
84 |
0 |
NodeUtil.visit(node, new NodeVisitor() { |
85 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
86 |
0 |
@Override... |
87 |
|
public void visit(Node nodeToVisit) throws RepositoryException { |
88 |
0 |
for (Node configNode : NodeUtil.getNodes(nodeToVisit, NodeTypes.ContentNode.NAME)) { |
89 |
0 |
if (isNotConfigured(configNode)) { |
90 |
0 |
continue; |
91 |
|
} |
92 |
0 |
RestClientProvider provider = createProvider(configNode); |
93 |
0 |
if (provider != null) { |
94 |
0 |
providers.add(provider); |
95 |
|
} |
96 |
|
} |
97 |
|
} |
98 |
|
}, new NodeTypePredicate(NodeTypes.Content.NAME, false)); |
99 |
|
} |
100 |
0 |
this.registeredIds = restClientDefinitionRegistry.unregisterAndRegister(registeredIds, providers); |
101 |
|
} |
102 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
103 |
0 |
protected RestClientProvider createProvider(Node restClientDefinitionNode) throws RepositoryException {... |
104 |
0 |
final String name = restClientDefinitionNode.getName(); |
105 |
|
|
106 |
0 |
try { |
107 |
0 |
return new ConfiguredRestClientProvider(name, restClientDefinitionNode, componentProvider); |
108 |
|
} catch (Exception e) { |
109 |
0 |
log.error("Unable to create provider for rest client definition [" + restClientDefinitionNode.getPath() + "]", e); |
110 |
|
} |
111 |
0 |
return null; |
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
117 |
0 |
private boolean isNotConfigured(Node node) throws RepositoryException {... |
118 |
0 |
return !node.hasProperty(RestClientDefinition.PROPERTY_REST_CLIENT_DEFINITION_CLASS); |
119 |
|
} |
120 |
|
|
121 |
|
} |