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.resources.app.utils; |
35 |
|
|
36 |
|
import info.magnolia.context.Context; |
37 |
|
import info.magnolia.resourceloader.jcr.JcrResourceOrigin; |
38 |
|
import info.magnolia.resources.app.workbench.ResourcesContainer; |
39 |
|
import info.magnolia.ui.vaadin.integration.jcr.JcrItemAdapter; |
40 |
|
import info.magnolia.ui.vaadin.integration.jcr.JcrNodeAdapter; |
41 |
|
|
42 |
|
import java.util.Collection; |
43 |
|
import java.util.List; |
44 |
|
|
45 |
|
import javax.jcr.Node; |
46 |
|
import javax.jcr.RepositoryException; |
47 |
|
|
48 |
|
import org.slf4j.Logger; |
49 |
|
import org.slf4j.LoggerFactory; |
50 |
|
|
51 |
|
import com.google.common.collect.Lists; |
52 |
|
import com.vaadin.data.Item; |
53 |
|
import com.vaadin.data.Property; |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
|
|
| 73.9% |
Uncovered Elements: 6 (23) |
Complexity: 8 |
Complexity Density: 0.5 |
|
58 |
|
public final class ResourceUtils { |
59 |
|
|
60 |
|
private static final Logger log = LoggerFactory.getLogger(ResourceUtils.class); |
61 |
|
|
62 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
63 |
0 |
private ResourceUtils() {... |
64 |
|
} |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
|
|
| 62.5% |
Uncovered Elements: 3 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
70 |
23 |
public static JcrNodeAdapter getJcrNodeAdapterFor(Context context, Item resourceItem) {... |
71 |
23 |
try { |
72 |
23 |
Property resourcePathProperty = resourceItem.getItemProperty(ResourcesContainer.RESOURCE_PATH); |
73 |
23 |
if (resourcePathProperty != null) { |
74 |
23 |
return new JcrNodeAdapter(context.getJCRSession(JcrResourceOrigin.RESOURCES_WORKSPACE).getNode(resourcePathProperty.getValue().toString())); |
75 |
|
} else { |
76 |
0 |
throw new RepositoryException(String.format("Required [%s] property cannot be found", ResourcesContainer.RESOURCE_PATH)); |
77 |
|
} |
78 |
|
} catch (RepositoryException e) { |
79 |
0 |
throw new RuntimeException(e); |
80 |
|
} |
81 |
|
} |
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
87 |
14 |
public static List<JcrItemAdapter> getJcrItemAdaptersFor(Context context, Collection<Item> resourceItems) {... |
88 |
14 |
List<JcrItemAdapter> adapters = Lists.newArrayList(); |
89 |
|
|
90 |
14 |
for (Item resourceItem : resourceItems) { |
91 |
15 |
adapters.add(getJcrNodeAdapterFor(context, resourceItem)); |
92 |
|
} |
93 |
14 |
return adapters; |
94 |
|
} |
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
|
|
| 50% |
Uncovered Elements: 2 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
100 |
5 |
public static Node extractParentItem(JcrItemAdapter jcrItemAdapter) {... |
101 |
5 |
try { |
102 |
5 |
return jcrItemAdapter.getJcrItem().getParent(); |
103 |
|
} catch (RepositoryException ignored) { |
104 |
0 |
log.info("Could not extract parent node of the given item {}", jcrItemAdapter); |
105 |
|
} |
106 |
0 |
return null; |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
114 |
4 |
public static boolean isDirectory(Item item) {... |
115 |
4 |
Property itemProperty = item.getItemProperty("directory"); |
116 |
4 |
return itemProperty != null && itemProperty.getValue() != null && Boolean.parseBoolean(itemProperty.getValue().toString()); |
117 |
|
} |
118 |
|
} |