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.setup.for2_1; |
35 |
|
|
36 |
|
import info.magnolia.jcr.util.NodeUtil; |
37 |
|
import info.magnolia.jcr.util.NodeVisitor; |
38 |
|
import info.magnolia.jcr.util.PropertyUtil; |
39 |
|
import info.magnolia.jcr.wrapper.JCRMgnlPropertiesFilteringNodeWrapper; |
40 |
|
import info.magnolia.module.InstallContext; |
41 |
|
import info.magnolia.module.delta.AbstractTask; |
42 |
|
import info.magnolia.module.delta.TaskExecutionException; |
43 |
|
import info.magnolia.module.googlesitemap.GoogleSiteMapConfiguration; |
44 |
|
import info.magnolia.module.googlesitemap.SiteMapNodeTypes.SiteMap; |
45 |
|
|
46 |
|
import java.util.ArrayList; |
47 |
|
import java.util.List; |
48 |
|
|
49 |
|
import javax.jcr.Node; |
50 |
|
import javax.jcr.PropertyIterator; |
51 |
|
import javax.jcr.RepositoryException; |
52 |
|
import javax.jcr.Session; |
53 |
|
|
54 |
|
import org.apache.commons.lang.StringUtils; |
55 |
|
import org.slf4j.Logger; |
56 |
|
import org.slf4j.LoggerFactory; |
57 |
|
|
58 |
|
|
59 |
|
@link |
60 |
|
|
61 |
|
|
62 |
|
@link |
63 |
|
|
|
|
| 80.9% |
Uncovered Elements: 9 (47) |
Complexity: 14 |
Complexity Density: 0.54 |
|
64 |
|
public class UpdatePropertyNamesAndNodeStructure extends AbstractTask { |
65 |
|
private static final Logger log = LoggerFactory.getLogger(UpdatePropertyNamesAndNodeStructure.class); |
66 |
|
private Session siteMapSession; |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
68 |
6 |
public UpdatePropertyNamesAndNodeStructure(String taskName, String taskDescription) {... |
69 |
6 |
super(taskName, taskDescription); |
70 |
|
} |
71 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
72 |
4 |
@Override... |
73 |
|
public void execute(InstallContext ctx) throws TaskExecutionException { |
74 |
4 |
try { |
75 |
4 |
siteMapSession = ctx.getJCRSession(GoogleSiteMapConfiguration.WORKSPACE); |
76 |
4 |
NodeUtil.visit(siteMapSession.getRootNode(), new SiteMapPropertyVisitor()); |
77 |
|
} catch (RepositoryException re) { |
78 |
0 |
ctx.error("Could not update the site map properties ", re); |
79 |
|
} |
80 |
|
|
81 |
|
} |
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
|
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 3 |
Complexity Density: 0.5 |
|
86 |
|
private class SiteMapPropertyVisitor implements NodeVisitor { |
87 |
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
88 |
5 |
@Override... |
89 |
|
public void visit(Node siteMap) throws RepositoryException { |
90 |
5 |
if (!StringUtils.equals(siteMap.getPrimaryNodeType().getName(), SiteMap.NAME)) { |
91 |
4 |
return; |
92 |
|
} |
93 |
|
|
94 |
1 |
renameProperties(siteMap); |
95 |
|
|
96 |
1 |
createDefaultProperties(siteMap); |
97 |
|
|
98 |
1 |
if (siteMap.hasNode("sites")) { |
99 |
1 |
transformSitesNodeIntoMultiValueProperty(siteMap); |
100 |
|
} |
101 |
|
} |
102 |
|
} |
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
|
|
| 75% |
Uncovered Elements: 4 (16) |
Complexity: 5 |
Complexity Density: 0.62 |
|
111 |
1 |
private void renameProperties(Node siteMapNode) throws RepositoryException {... |
112 |
1 |
if (siteMapNode.hasProperty("displayName")) { |
113 |
1 |
PropertyUtil.renameProperty(siteMapNode.getProperty("displayName"), SiteMap.DISPLAY_NAME); |
114 |
|
} |
115 |
1 |
if (siteMapNode.hasProperty("type")) { |
116 |
1 |
PropertyUtil.renameProperty(siteMapNode.getProperty("type"), SiteMap.TYPE); |
117 |
|
} |
118 |
1 |
if (siteMapNode.hasProperty("url")) { |
119 |
1 |
PropertyUtil.renameProperty(siteMapNode.getProperty("url"), SiteMap.URL); |
120 |
|
} |
121 |
1 |
if (siteMapNode.hasProperty("includeVirtualURIMappings")) { |
122 |
1 |
PropertyUtil.renameProperty(siteMapNode.getProperty("includeVirtualURIMappings"), SiteMap.INCLUDE_VIRTUAL_URI); |
123 |
|
} |
124 |
|
} |
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
|
|
| 62.5% |
Uncovered Elements: 3 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
131 |
1 |
private void createDefaultProperties(Node siteMapNode) throws RepositoryException {... |
132 |
1 |
if (!siteMapNode.hasProperty(SiteMap.DEFAULT_CHANGEFREQ)) { |
133 |
1 |
siteMapNode.setProperty(SiteMap.DEFAULT_CHANGEFREQ, GoogleSiteMapConfiguration.DEFAULT_CHANGE_FREQUENCY); |
134 |
|
} |
135 |
1 |
if (!siteMapNode.hasProperty(SiteMap.DEFAULT_PRIORITY)) { |
136 |
0 |
siteMapNode.setProperty(SiteMap.DEFAULT_PRIORITY, GoogleSiteMapConfiguration.DEFAULT_PRIORITY); |
137 |
|
} |
138 |
|
} |
139 |
|
|
|
|
| 92.3% |
Uncovered Elements: 1 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
140 |
1 |
private void transformSitesNodeIntoMultiValueProperty(Node siteMapNode) throws RepositoryException {... |
141 |
1 |
List<String> siteValues = new ArrayList<String>(); |
142 |
|
|
143 |
1 |
Node sitesNode = new JCRMgnlPropertiesFilteringNodeWrapper(siteMapNode.getNode("sites")); |
144 |
1 |
PropertyIterator iterator = sitesNode.getProperties(); |
145 |
3 |
while (iterator.hasNext()) { |
146 |
2 |
siteValues.add(iterator.nextProperty().getString()); |
147 |
|
} |
148 |
1 |
if (!siteValues.isEmpty()) { |
149 |
1 |
siteMapNode.setProperty(SiteMap.PAGES, siteValues.toArray(new String[siteValues.size()])); |
150 |
|
} |
151 |
1 |
log.info("Remove sub node '{}' containing the pages information from '{}' ", sitesNode.getPath(), siteMapNode.getPath()); |
152 |
1 |
sitesNode.remove(); |
153 |
|
} |
154 |
|
|
155 |
|
} |