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.reference.jcr; |
35 |
|
|
36 |
|
import info.magnolia.context.Context; |
37 |
|
import info.magnolia.jcr.util.PropertyUtil; |
38 |
|
import info.magnolia.rest.delivery.jcr.decorator.ReadOnlyNode; |
39 |
|
import info.magnolia.rest.reference.ReferenceResolver; |
40 |
|
import info.magnolia.rest.reference.ReferenceResolverDefinition; |
41 |
|
|
42 |
|
import java.util.ArrayList; |
43 |
|
import java.util.Collections; |
44 |
|
import java.util.List; |
45 |
|
import java.util.Optional; |
46 |
|
|
47 |
|
import javax.inject.Inject; |
48 |
|
import javax.inject.Provider; |
49 |
|
import javax.jcr.Node; |
50 |
|
import javax.jcr.Property; |
51 |
|
import javax.jcr.RepositoryException; |
52 |
|
import javax.jcr.Session; |
53 |
|
|
54 |
|
import org.slf4j.Logger; |
55 |
|
import org.slf4j.LoggerFactory; |
56 |
|
|
57 |
|
|
58 |
|
@link |
59 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 5 |
Complexity Density: 0.42 |
|
60 |
|
public class UuidReferenceResolver implements ReferenceResolver<Property, Node> { |
61 |
|
|
62 |
|
private static final Logger log = LoggerFactory.getLogger(UuidReferenceResolver.class); |
63 |
|
private final Provider<Context> contextProvider; |
64 |
|
private final ReferenceResolverDefinition definition; |
65 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
66 |
0 |
@Inject... |
67 |
|
public UuidReferenceResolver(Provider<Context> contextProvider, ReferenceResolverDefinition definition) { |
68 |
0 |
this.contextProvider = contextProvider; |
69 |
0 |
this.definition = definition; |
70 |
|
} |
71 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.4 |
|
72 |
0 |
@Override... |
73 |
|
public Optional<Node> resolve(Property item) { |
74 |
0 |
try { |
75 |
0 |
Session session = contextProvider.get().getJCRSession(definition.getTargetWorkspace()); |
76 |
0 |
if (item.isMultiple() && item.getValues() != null) { |
77 |
0 |
List<Node> nodes = new ArrayList<>(); |
78 |
0 |
for (String uuid : PropertyUtil.getValuesStringList(item.getValues())) { |
79 |
0 |
nodes.add(session.getNodeByIdentifier(uuid)); |
80 |
|
} |
81 |
|
|
82 |
0 |
return Optional.of(new ReadOnlyNode(item.getName(), item.getParent(), nodes, Collections.emptyList())); |
83 |
|
} |
84 |
|
|
85 |
0 |
return Optional.of(session.getNodeByIdentifier(item.getString())); |
86 |
|
} catch (RepositoryException e) { |
87 |
0 |
log.warn("Error on resolving item {}", item, e); |
88 |
|
} |
89 |
|
|
90 |
0 |
return Optional.empty(); |
91 |
|
} |
92 |
|
} |