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.delta;
35
36 import info.magnolia.module.InstallContext;
37 import info.magnolia.repository.RepositoryConstants;
38
39 import javax.jcr.RepositoryException;
40
41
42
43
44 public class NodeExistsDelegateTask extends ConditionalDelegateTask {
45 private final String workspaceName;
46 private final String pathToCheck;
47
48 public NodeExistsDelegateTask(String name, String pathToCheck, Task ifTrue) {
49 this(name, pathToCheck, ifTrue, null);
50 }
51
52 public NodeExistsDelegateTask(String name, String pathToCheck, Taskef="../../../../info/magnolia/module/delta/Task.html#Task">Task ifTrue, Task ifFalse) {
53 this(name, String.format("Execute task [%s] if node '%s' exists or [%s] if not.",
54 ifTrue == null ? DO_NOTHING : ifTrue.getDescription(),
55 pathToCheck,
56 ifFalse == null ? DO_NOTHING : ifFalse.getDescription()),
57 RepositoryConstants.CONFIG, pathToCheck, ifTrue, ifFalse);
58 }
59
60 public NodeExistsDelegateTask(String name, String description, String workspaceName, String pathToCheck, Task ifTrue) {
61 this(name, description, workspaceName, pathToCheck, ifTrue, null);
62 }
63
64 public NodeExistsDelegateTask(String name, String description, String workspaceName, String pathToCheck, Taskef="../../../../info/magnolia/module/delta/Task.html#Task">Task ifTrue, Task ifFalse) {
65 super(name, description, ifTrue, ifFalse);
66 this.pathToCheck = pathToCheck;
67 this.workspaceName = workspaceName;
68 }
69
70 @Override
71 protected boolean condition(InstallContext ctx) {
72 try {
73 return ctx.getJCRSession(workspaceName).nodeExists(pathToCheck);
74 } catch (RepositoryException e) {
75 ctx.error("There was an error assessing if the node exists.", e);
76 return false;
77 }
78 }
79 }