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.cms.core.Content;
37 import info.magnolia.cms.core.NodeData;
38 import info.magnolia.module.InstallContext;
39 import info.magnolia.repository.RepositoryConstants;
40
41 import javax.jcr.RepositoryException;
42
43
44
45
46
47 @Deprecated
48 public class PropertyValueDelegateTask extends NodeCheckDelegateTask {
49 private final String expectedValue;
50 private final boolean propertyMustExist;
51
52 public PropertyValueDelegateTask(String taskName, String parentPath, String propertyName, String expectedValue, boolean propertyMustExist, Task ifTrue) {
53 this(taskName, parentPath, propertyName, expectedValue, propertyMustExist, ifTrue, null);
54 }
55
56 public PropertyValueDelegateTask(String taskName, String parentPath, String propertyName, String expectedValue, boolean propertyMustExist, Task ifTrue, Task ifFalse) {
57 this(taskName, String.format("Execute task [%s] if property '%s' has value '%s' or [%s] if not.",
58 ifTrue == null ? DO_NOTHING : ifTrue.getDescription(),
59 parentPath + "/" + propertyName, expectedValue,
60 ifFalse == null ? DO_NOTHING : ifFalse.getDescription()),
61 RepositoryConstants.CONFIG, parentPath, propertyName, expectedValue, propertyMustExist, ifTrue, ifFalse);
62 }
63
64 public PropertyValueDelegateTask(String taskName, String taskDescription, String workspaceName, String nodePath, String propertyName, String expectedValue, boolean propertyMustExist, Task ifTrue) {
65 this(taskName, taskDescription, workspaceName, nodePath, propertyName, expectedValue, propertyMustExist, ifTrue, null);
66 }
67
68
69
70
71
72 public PropertyValueDelegateTask(String taskName, String taskDescription, String workspaceName, String nodePath, String propertyName, String expectedValue, boolean propertyMustExist, Task ifTrue, Task ifFalse) {
73 super(taskName, taskDescription, workspaceName, nodePath, propertyName, ifTrue, ifFalse);
74 this.expectedValue = expectedValue;
75 this.propertyMustExist = propertyMustExist;
76 }
77
78 @Override
79 protected boolean checkNode(Content node, InstallContext ctx) throws TaskExecutionException, RepositoryException {
80 if (node.hasNodeData(propertyName)) {
81 final NodeData prop = node.getNodeData(propertyName);
82 return expectedValue.equals(prop.getString());
83 } else if (propertyMustExist) {
84 throw new TaskExecutionException("Property \"" + propertyName + "\" was expected to exist at " + nodePath);
85 } else {
86 ctx.warn("Property \"" + propertyName + "\" was expected to be found at " + nodePath + " but does not exist.");
87 return false;
88 }
89 }
90 }