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.rssaggregator.setup;
35
36 import info.magnolia.jcr.util.NodeUtil;
37 import info.magnolia.jcr.util.NodeVisitor;
38 import info.magnolia.module.InstallContext;
39 import info.magnolia.module.delta.AbstractTask;
40 import info.magnolia.module.delta.TaskExecutionException;
41
42 import javax.jcr.Node;
43 import javax.jcr.RepositoryException;
44 import javax.jcr.Session;
45
46
47
48
49 public class SetImportTimingSetterPropertyInitialValue extends AbstractTask {
50
51 private static String FIELD_KEY_IMPORTTIMINGSETTER = "importTimingSetter";
52 private static String FIELD_KEY_DISABLED = "Disabled";
53 private static String FIELD_KEY_CRONSTRING = "CronString";
54
55 private static String CONFIG_PROPERTY_NAME_AUTOMATEDIMPORT = "automatedImport";
56
57 private NodeVisitor nodeVisitor = new NodeVisitor() {
58 @Override
59 public void visit(Node node) throws RepositoryException {
60 if (node.getPrimaryNodeType().isNodeType("mgnl:rssAggregator")) {
61 if(node.hasProperty(CONFIG_PROPERTY_NAME_AUTOMATEDIMPORT)){
62 if(node.getProperty(CONFIG_PROPERTY_NAME_AUTOMATEDIMPORT).getBoolean()){
63 node.setProperty(FIELD_KEY_IMPORTTIMINGSETTER,FIELD_KEY_CRONSTRING);
64 } else {
65 node.setProperty(FIELD_KEY_IMPORTTIMINGSETTER,FIELD_KEY_DISABLED);
66 }
67 }
68 }
69 }
70 };
71
72 public SetImportTimingSetterPropertyInitialValue(String taskDescription) {
73 super("Set new property importTimingSetter value for rssAgregators in rss workspace.", taskDescription);
74 }
75
76 @Override
77 public void execute(InstallContext ctx) throws TaskExecutionException {
78 try {
79 Session session = ctx.getJCRSession("rss");
80 Node rootNode = session.getRootNode();
81 NodeUtil.visit(rootNode, nodeVisitor);
82 } catch (RepositoryException e) {
83 throw new TaskExecutionException(e.getMessage(), e);
84 }
85 }
86 }