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.module.googlesitemap.app.subapp.sitemapdetail.util; |
35 |
|
|
36 |
|
import info.magnolia.jcr.util.SessionUtil; |
37 |
|
import info.magnolia.module.googlesitemap.GoogleSiteMapConfiguration; |
38 |
|
import info.magnolia.module.googlesitemap.bean.SiteMapEntry; |
39 |
|
import info.magnolia.module.googlesitemap.service.SiteMapService; |
40 |
|
import info.magnolia.ui.workbench.container.Refreshable; |
41 |
|
|
42 |
|
import java.util.ArrayList; |
43 |
|
import java.util.Collection; |
44 |
|
import java.util.List; |
45 |
|
|
46 |
|
import javax.jcr.Node; |
47 |
|
import javax.jcr.RepositoryException; |
48 |
|
|
49 |
|
import org.slf4j.Logger; |
50 |
|
import org.slf4j.LoggerFactory; |
51 |
|
|
52 |
|
import com.vaadin.data.Container; |
53 |
|
import com.vaadin.data.util.BeanItemContainer; |
54 |
|
|
55 |
|
|
56 |
|
@link |
57 |
|
|
|
|
| 55.3% |
Uncovered Elements: 34 (76) |
Complexity: 21 |
Complexity Density: 0.42 |
|
58 |
|
public class SiteMapEntryContainer extends BeanItemContainer<SiteMapEntry> implements Container.Hierarchical, Refreshable { |
59 |
|
|
60 |
|
private static Logger log = LoggerFactory.getLogger(SiteMapEntryContainer.class); |
61 |
|
|
62 |
|
private int maxLevel = Integer.MIN_VALUE; |
63 |
|
|
64 |
|
private int minLevel = Integer.MAX_VALUE; |
65 |
|
|
66 |
|
private String siteMapPath; |
67 |
|
|
68 |
|
private boolean virtualUris; |
69 |
|
|
70 |
|
private SiteMapService siteMapService; |
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
72 |
8 |
public SiteMapEntryContainer(String siteMapPath, boolean isVirtualUris, SiteMapService siteMapService) {... |
73 |
8 |
super(SiteMapEntry.class); |
74 |
8 |
this.siteMapPath = siteMapPath; |
75 |
8 |
virtualUris = isVirtualUris; |
76 |
8 |
this.siteMapService = siteMapService; |
77 |
8 |
refresh(); |
78 |
|
} |
79 |
|
|
|
|
| 88.9% |
Uncovered Elements: 2 (18) |
Complexity: 4 |
Complexity Density: 0.33 |
|
80 |
1 |
@Override... |
81 |
|
public Collection<?> getChildren(Object itemId) { |
82 |
1 |
SiteMapEntry entry = (SiteMapEntry)itemId; |
83 |
|
|
84 |
1 |
int maxLevel = entry.getLevel() + 1; |
85 |
1 |
List<SiteMapEntry> children = new ArrayList<SiteMapEntry>(); |
86 |
1 |
int index = indexOfId(entry) + 1; |
87 |
12 |
while (index < size()) { |
88 |
11 |
SiteMapEntry childEntry = getIdByIndex(index++); |
89 |
11 |
if (childEntry.getLevel() > maxLevel) { |
90 |
9 |
continue; |
91 |
|
} |
92 |
2 |
if (childEntry.getLevel() < maxLevel) { |
93 |
0 |
break; |
94 |
|
} |
95 |
2 |
children.add(childEntry); |
96 |
|
} |
97 |
1 |
return children; |
98 |
|
} |
99 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.5 |
|
100 |
0 |
@Override... |
101 |
|
public Object getParent(Object itemId) { |
102 |
0 |
SiteMapEntry parent = null; |
103 |
0 |
SiteMapEntry child = (SiteMapEntry)itemId; |
104 |
0 |
int index = indexOfId(itemId); |
105 |
0 |
while (index > 0 && parent == null) { |
106 |
0 |
SiteMapEntry id = getIdByIndex(--index); |
107 |
0 |
if (id.getLevel() < child.getLevel()) { |
108 |
0 |
parent = id; |
109 |
|
} |
110 |
|
} |
111 |
0 |
return parent; |
112 |
|
} |
113 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
114 |
0 |
@Override... |
115 |
|
public Collection<?> rootItemIds() { |
116 |
0 |
List<SiteMapEntry> roots = new ArrayList<SiteMapEntry>(); |
117 |
0 |
for (SiteMapEntry entry : getItemIds()) { |
118 |
0 |
if (entry.getLevel() == minLevel) { |
119 |
0 |
roots.add(entry); |
120 |
|
} |
121 |
|
} |
122 |
0 |
return roots; |
123 |
|
} |
124 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
125 |
0 |
@Override... |
126 |
|
public boolean areChildrenAllowed(Object itemId) { |
127 |
0 |
return getChildren(itemId).size() > 0; |
128 |
|
} |
129 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
130 |
0 |
@Override... |
131 |
|
public boolean isRoot(Object itemId) { |
132 |
0 |
return ((SiteMapEntry)itemId).getLevel() == minLevel; |
133 |
|
} |
134 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
135 |
0 |
@Override... |
136 |
|
public boolean hasChildren(Object itemId) { |
137 |
0 |
return ((SiteMapEntry)itemId).getLevel() < maxLevel; |
138 |
|
} |
139 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
140 |
0 |
@Override... |
141 |
|
public boolean setParent(Object itemId, Object newParentId) throws UnsupportedOperationException { |
142 |
0 |
throw new UnsupportedOperationException(); |
143 |
|
} |
144 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
145 |
0 |
@Override... |
146 |
|
public boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed) throws UnsupportedOperationException { |
147 |
0 |
throw new UnsupportedOperationException(); |
148 |
|
} |
149 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
150 |
10 |
private void calculateBoundLevels() {... |
151 |
10 |
Collection<SiteMapEntry> ids = getItemIds(); |
152 |
10 |
for (SiteMapEntry id : ids) { |
153 |
57 |
int level = id.getLevel(); |
154 |
57 |
maxLevel = Math.max(maxLevel, level); |
155 |
57 |
minLevel = Math.min(minLevel, level); |
156 |
|
} |
157 |
|
} |
158 |
|
|
|
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
159 |
10 |
protected List<SiteMapEntry> fetchSiteMapEntries() {... |
160 |
10 |
List<SiteMapEntry> entries = new ArrayList<SiteMapEntry>(); |
161 |
10 |
try { |
162 |
10 |
Node sitemapNode = SessionUtil.getNode(GoogleSiteMapConfiguration.WORKSPACE, siteMapPath); |
163 |
10 |
if (sitemapNode != null) { |
164 |
9 |
entries.addAll(siteMapService.getSiteMapBeans(sitemapNode, virtualUris, true)); |
165 |
|
} |
166 |
|
} catch (RepositoryException e) { |
167 |
0 |
log.error("Failed to accumulate site map beans for pages", e); |
168 |
|
} |
169 |
10 |
return entries; |
170 |
|
} |
171 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
172 |
10 |
@Override... |
173 |
|
public void refresh() { |
174 |
10 |
removeAllItems(); |
175 |
10 |
addAll(fetchSiteMapEntries()); |
176 |
10 |
calculateBoundLevels(); |
177 |
|
} |
178 |
|
} |