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.NodeTypes; |
37 |
|
import info.magnolia.jcr.util.NodeUtil; |
38 |
|
import info.magnolia.jcr.util.PropertyUtil; |
39 |
|
import info.magnolia.module.InstallContext; |
40 |
|
import info.magnolia.module.delta.AbstractRepositoryTask; |
41 |
|
import info.magnolia.module.delta.TaskExecutionException; |
42 |
|
import info.magnolia.module.googlesitemap.SiteMapNodeTypes.GoogleSiteMap; |
43 |
|
import info.magnolia.repository.RepositoryConstants; |
44 |
|
|
45 |
|
import java.util.Arrays; |
46 |
|
import java.util.List; |
47 |
|
|
48 |
|
import javax.jcr.Node; |
49 |
|
import javax.jcr.NodeIterator; |
50 |
|
import javax.jcr.RepositoryException; |
51 |
|
import javax.jcr.Session; |
52 |
|
import javax.jcr.query.Query; |
53 |
|
import javax.jcr.query.QueryManager; |
54 |
|
|
55 |
|
import org.apache.commons.lang3.StringUtils; |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
|
|
| 94.6% |
Uncovered Elements: 2 (37) |
Complexity: 11 |
Complexity Density: 0.52 |
|
60 |
|
public class RenameSiteMapeSitePagesPropertyName extends AbstractRepositoryTask { |
61 |
|
|
62 |
|
private Session siteSession; |
63 |
|
private final String workspace; |
64 |
|
private final List<String> propertiesToRename = Arrays.asList("googleSitemapChangefreq", "googleSitemapHide", "googleSitemapPriority", "googleSitemapHideChildren"); |
65 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
66 |
12 |
public RenameSiteMapeSitePagesPropertyName(String name, String description, String workspace) {... |
67 |
12 |
super(name, description); |
68 |
12 |
this.workspace = StringUtils.isNotBlank(workspace) ? workspace : RepositoryConstants.WEBSITE; |
69 |
|
} |
70 |
|
|
|
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
71 |
5 |
@Override... |
72 |
|
protected void doExecute(InstallContext ctx) throws RepositoryException, TaskExecutionException { |
73 |
5 |
try { |
74 |
5 |
siteSession = ctx.getJCRSession(workspace); |
75 |
5 |
for (String toRename : propertiesToRename) { |
76 |
20 |
NodeIterator nodesToHandle = search(toRename); |
77 |
24 |
while (nodesToHandle.hasNext()) { |
78 |
4 |
renameProperties(nodesToHandle.nextNode()); |
79 |
|
} |
80 |
|
} |
81 |
|
|
82 |
|
} catch (RepositoryException re) { |
83 |
0 |
ctx.error("Could not update the siteMap site properties ", re); |
84 |
|
} |
85 |
|
} |
86 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
87 |
20 |
private NodeIterator search(String toRename) throws RepositoryException {... |
88 |
20 |
final String statement = "SELECT * FROM [" + NodeTypes.Page.NAME + "] AS t WHERE t." + toRename + " is not null"; |
89 |
20 |
QueryManager manager = siteSession.getWorkspace().getQueryManager(); |
90 |
20 |
Query query = manager.createQuery(statement, Query.JCR_SQL2); |
91 |
20 |
return NodeUtil.filterDuplicates(query.execute().getNodes()); |
92 |
|
} |
93 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 5 |
Complexity Density: 0.62 |
|
94 |
4 |
private void renameProperties(Node page) throws RepositoryException {... |
95 |
4 |
if (page.hasProperty("googleSitemapChangefreq")) { |
96 |
1 |
PropertyUtil.renameProperty(page.getProperty("googleSitemapChangefreq"), GoogleSiteMap.SITEMAP_CHANGEFREQ); |
97 |
|
} |
98 |
4 |
if (page.hasProperty("googleSitemapHide")) { |
99 |
1 |
PropertyUtil.renameProperty(page.getProperty("googleSitemapHide"), GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP); |
100 |
|
} |
101 |
4 |
if (page.hasProperty("googleSitemapPriority")) { |
102 |
1 |
PropertyUtil.renameProperty(page.getProperty("googleSitemapPriority"), GoogleSiteMap.SITEMAP_PRIORITY); |
103 |
|
} |
104 |
4 |
if (page.hasProperty("googleSitemapHideChildren")) { |
105 |
1 |
PropertyUtil.renameProperty(page.getProperty("googleSitemapHideChildren"), GoogleSiteMap.SITEMAP_HIDE_IN_GOOGLESITEMAP_CHILDREN); |
106 |
|
} |
107 |
|
} |
108 |
|
|
109 |
|
} |