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.dam.app.setup.migration;
35
36 import info.magnolia.module.delta.AbstractRepositoryTask;
37
38 import java.util.Arrays;
39
40 import javax.jcr.RepositoryException;
41 import javax.jcr.Session;
42 import javax.jcr.query.Query;
43 import javax.jcr.query.QueryManager;
44 import javax.jcr.query.QueryResult;
45
46 import org.apache.jackrabbit.util.ISO9075;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
49
50
51
52
53
54 public abstract class AbstractPropertyValueSearchDamMigrationTask extends AbstractRepositoryTask {
55
56 private static final Logger log = LoggerFactory.getLogger(AbstractPropertyValueSearchDamMigrationTask.class);
57
58 private String propertyValue;
59
60 public AbstractPropertyValueSearchDamMigrationTask(String name, String description, String propertyValue) {
61 super(name, description);
62 this.propertyValue = propertyValue;
63 }
64
65
66
67
68
69 protected String createQuery(String path) {
70 String encodedPath = ISO9075.encodePath(path);
71 if ("/".equals(encodedPath)) {
72 encodedPath = "";
73 }
74 return "/jcr:root" + encodedPath + "//element(*,nt:base)[jcr:contains(., '" + getPropertyValue() + "')] ";
75 }
76
77
78
79
80 @SuppressWarnings("deprecation")
81 protected QueryResult executeQuery(String statement, Session session) {
82 try {
83 QueryManager jcrQueryManager = session.getWorkspace().getQueryManager();
84
85 Query query = jcrQueryManager.createQuery(statement, Query.XPATH);
86 QueryResult result = query.execute();
87 return result;
88 } catch (RepositoryException e) {
89 log.error("Not able to execute the following JCR-JQOM query '{}' against the following session '{}'. Exception '{}'", Arrays.asList(statement, session.getWorkspace().getName(), e.getMessage()), e);
90 return null;
91 }
92 }
93
94 protected void setPropertyValue(String propertyValue) {
95 this.propertyValue = propertyValue;
96 }
97
98 protected String getPropertyValue() {
99 return this.propertyValue;
100 }
101
102
103
104
105
106
107
108
109
110
111
112
113
114 @Deprecated
115 protected String buildI18nSuffixPropertyName(String propertyName, String propertyNameSuffix) {
116 return DamMigrationUtil.buildI18nSuffixPropertyName(propertyName, propertyNameSuffix);
117 }
118
119
120
121
122 @Deprecated
123 protected boolean isPropertyNameI18nBased(String propertyName) {
124 return DamMigrationUtil.isPropertyNameI18nBased(propertyName);
125 }
126
127
128
129
130
131
132 @Deprecated
133 protected String getI18nLocalBasedOnPropertyName(String propertyName) {
134 return DamMigrationUtil.getI18nLocalBasedOnPropertyName(propertyName);
135 }
136
137
138
139
140 @Deprecated
141 protected String getPropertyNameWithoutLocalSuffix(String propertyName) {
142 return DamMigrationUtil.getPropertyNameWithoutLocalSuffix(propertyName);
143 }
144 }