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.cache.setup; |
35 |
|
|
36 |
|
import info.magnolia.jcr.iterator.FilteringPropertyIterator; |
37 |
|
import info.magnolia.jcr.predicate.JCRMgnlPropertyHidingPredicate; |
38 |
|
import info.magnolia.jcr.util.NodeTypes; |
39 |
|
import info.magnolia.module.InstallContext; |
40 |
|
import info.magnolia.module.cache.AbstractListeningFlushPolicy; |
41 |
|
import info.magnolia.module.cache.FlushAllListeningPolicy; |
42 |
|
import info.magnolia.module.delta.NodeVisitorTask; |
43 |
|
import info.magnolia.objectfactory.Components; |
44 |
|
import info.magnolia.repository.RepositoryConstants; |
45 |
|
import info.magnolia.repository.RepositoryManager; |
46 |
|
|
47 |
|
import java.util.ArrayList; |
48 |
|
import java.util.Collection; |
49 |
|
|
50 |
|
import javax.jcr.Node; |
51 |
|
import javax.jcr.PropertyIterator; |
52 |
|
import javax.jcr.RepositoryException; |
53 |
|
|
54 |
|
import org.slf4j.Logger; |
55 |
|
import org.slf4j.LoggerFactory; |
56 |
|
|
57 |
|
|
58 |
|
@link |
59 |
|
|
|
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 7 |
Complexity Density: 0.33 |
|
60 |
|
public class MigrateFlushListeningPolicyTask extends NodeVisitorTask { |
61 |
|
|
62 |
|
private static final Logger log = LoggerFactory.getLogger(MigrateFlushListeningPolicyTask.class); |
63 |
|
|
64 |
|
protected static final String EXCLUDED_WORKSPACES = "excludedWorkspaces"; |
65 |
|
protected static final String REPOSITORIES = "repositories"; |
66 |
|
private static final String TASK_NAME = String.format("Migrate '%s' configuration.", FlushAllListeningPolicy.class.getName()); |
67 |
|
private final String abstractListeningFlushPolicyClassName; |
68 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
69 |
0 |
public MigrateFlushListeningPolicyTask(String path, Class<? extends AbstractListeningFlushPolicy> abstractListeningFlushPolicyClass) {... |
70 |
0 |
super(TASK_NAME, TASK_NAME, RepositoryConstants.CONFIG, "/" + path); |
71 |
0 |
this.abstractListeningFlushPolicyClassName = abstractListeningFlushPolicyClass.getName(); |
72 |
|
} |
73 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
74 |
0 |
@Override... |
75 |
|
protected boolean nodeMatches(Node node) { |
76 |
0 |
try { |
77 |
0 |
return node.hasProperty("class") && abstractListeningFlushPolicyClassName.equals(node.getProperty("class").getString()); |
78 |
|
} catch (RepositoryException e) { |
79 |
0 |
log.error("Cannot check if '{}' matches.", node, e); |
80 |
|
} |
81 |
0 |
return false; |
82 |
|
} |
83 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 4 |
Complexity Density: 0.27 |
|
84 |
0 |
@Override... |
85 |
|
protected void operateOnNode(InstallContext installContext, Node node) { |
86 |
0 |
Collection<String> includedRepositories = new ArrayList<String>(); |
87 |
0 |
Collection<String> includedWorkspaces = Components.getComponent(RepositoryManager.class).getWorkspaceNames(); |
88 |
0 |
try { |
89 |
0 |
if (node.hasNode(REPOSITORIES)) { |
90 |
0 |
Node repositores = node.getNode(REPOSITORIES); |
91 |
0 |
PropertyIterator propertyIterator = new FilteringPropertyIterator(repositores.getProperties(), new JCRMgnlPropertyHidingPredicate()); |
92 |
0 |
while (propertyIterator.hasNext()) { |
93 |
0 |
includedRepositories.add(propertyIterator.nextProperty().getString()); |
94 |
|
} |
95 |
0 |
repositores.remove(); |
96 |
|
} |
97 |
0 |
includedWorkspaces.removeAll(includedRepositories); |
98 |
0 |
Node excludedWorkspaces = node.addNode(EXCLUDED_WORKSPACES, NodeTypes.ContentNode.NAME); |
99 |
|
|
100 |
0 |
for (String workspace : includedWorkspaces) { |
101 |
0 |
excludedWorkspaces.setProperty(workspace, workspace); |
102 |
|
} |
103 |
0 |
installContext.info(String.format("The configuration '%s' was migrated. All workspaces are now registered by default except those defined under '%s'. " |
104 |
|
+ "The obsolete property '%s' was removed.", node, EXCLUDED_WORKSPACES, REPOSITORIES)); |
105 |
|
|
106 |
|
} catch (RepositoryException e) { |
107 |
0 |
installContext.error(String.format("Cannot execute task '%s' for node '%s'", this.getDescription(), node), e); |
108 |
|
} |
109 |
|
} |
110 |
|
} |