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