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.resources.setup; |
35 |
|
|
36 |
|
import info.magnolia.jcr.util.NodeUtil; |
37 |
|
import info.magnolia.module.InstallContext; |
38 |
|
import info.magnolia.module.delta.AbstractRepositoryTask; |
39 |
|
import info.magnolia.module.delta.TaskExecutionException; |
40 |
|
|
41 |
|
import java.util.Iterator; |
42 |
|
|
43 |
|
import javax.jcr.Node; |
44 |
|
import javax.jcr.RepositoryException; |
45 |
|
import javax.jcr.Session; |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 5 |
Complexity Density: 0.42 |
|
50 |
|
public class RemoveResourcePropertyFromAllChildrenRecursivelyTask extends AbstractRepositoryTask { |
51 |
|
|
52 |
|
private String rootPath; |
53 |
|
private String propertyName; |
54 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
55 |
0 |
public RemoveResourcePropertyFromAllChildrenRecursivelyTask(String rootPath, String propertyName) {... |
56 |
0 |
super("Remove "+ propertyName + " property", "Removes " + propertyName + " property from " + rootPath + " children recursively."); |
57 |
0 |
this.rootPath = rootPath; |
58 |
0 |
this.propertyName = propertyName; |
59 |
|
} |
60 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
61 |
0 |
@Override... |
62 |
|
protected void doExecute(InstallContext installContext) throws RepositoryException, TaskExecutionException { |
63 |
0 |
final Session session = installContext.getJCRSession("resources"); |
64 |
|
|
65 |
0 |
if(!session.nodeExists(rootPath)) { |
66 |
0 |
return; |
67 |
|
} |
68 |
0 |
final Node rootOfOperation = session.getNode(rootPath); |
69 |
0 |
Iterator<Node> iterator = NodeUtil.collectAllChildren(rootOfOperation).iterator(); |
70 |
0 |
while (iterator.hasNext()) { |
71 |
0 |
Node childNode = iterator.next(); |
72 |
0 |
if (childNode.hasProperty(propertyName)) { |
73 |
0 |
childNode.getProperty(propertyName).remove(); |
74 |
|
} |
75 |
|
} |
76 |
|
} |
77 |
|
} |
78 |
|
|