Cq62StartupCodeUpgrade.java
12.5 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.security.user.UserManagementService
* javax.jcr.RepositoryException
* javax.jcr.Session
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceResolverFactory
* org.apache.sling.jcr.api.SlingRepository
* org.osgi.service.component.ComponentContext
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.compat.codeupgrade.impl.cq62;
import com.adobe.granite.security.user.UserManagementService;
import com.day.cq.compat.codeupgrade.CodeUpgradeTask;
import com.day.cq.compat.codeupgrade.impl.StatusNode;
import com.day.cq.compat.codeupgrade.impl.cq62.CQ62Html5SmartFileUpgrade;
import com.day.cq.compat.codeupgrade.impl.cq62.CQ62SearchFacetsConfigUpdate;
import com.day.cq.compat.codeupgrade.impl.cq62.Cq62ConfContentUpgrade;
import com.day.cq.compat.codeupgrade.impl.cq62.Cq62FormsContentUpgrade;
import com.day.cq.compat.codeupgrade.impl.cq62.Cq62MediaContentUpgrade;
import com.day.cq.compat.codeupgrade.impl.cq62.Cq62MobileContentUpgrade;
import com.day.cq.compat.codeupgrade.impl.cq62.Cq62PrimaryComponentsUpgrade;
import com.day.cq.compat.codeupgrade.impl.cq62.Cq62ProjectsCodeUpgrade;
import com.day.cq.compat.codeupgrade.impl.cq62.Cq62TargetCampaignsContentUpgrade;
import com.day.cq.compat.codeupgrade.impl.cq62.Cq62TargetContentUpgrade;
import com.day.cq.compat.codeupgrade.impl.cq62.Cq62WorkflowContentUpgrade;
import com.day.cq.compat.codeupgrade.internal.api.ProgressInfoProvider;
import java.util.Collections;
import java.util.Dictionary;
import java.util.Map;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.jcr.api.SlingRepository;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(immediate=1, metatype=1, label="Adobe CQ 6.2 upgrader", description="Runs the CodeUpgrader service the first time CQ 6.2 starts.")
@Service
@Property(name="service.ranking", intValue={620})
public class Cq62StartupCodeUpgrade
implements CodeUpgradeTask {
private final Logger log;
private StatusNode statusNode;
private ProgressInfoProvider infoProvider;
@Reference
private SlingRepository repository;
@Reference
private UserManagementService userManagerService;
@Reference
private ResourceResolverFactory resourceResolverFactory;
@Property(value={"/var/upgrade/status"})
public static final String PROP_STATUS_NODE_PATH = "status.node.path";
@Property(value={"Cq62StartupCodeUpgrade"})
public static final String PROP_STATUS_PROPERTY_NAME = "status.property.name";
public Cq62StartupCodeUpgrade() {
this.log = LoggerFactory.getLogger(this.getClass());
this.repository = null;
this.userManagerService = null;
this.resourceResolverFactory = null;
}
public String toString() {
return this.getClass().getSimpleName();
}
@Activate
protected void activate(ComponentContext ctx) throws Exception {
Dictionary properties = ctx.getProperties();
this.statusNode = new StatusNode((String)properties.get("status.node.path"), (String)properties.get("status.property.name"));
}
@Override
public void cancelUpgrade() {
}
@Override
public synchronized String getProgressInfo() {
if (this.infoProvider == null) {
return "No info from " + this.getClass().getName();
}
return this.infoProvider.getProgressInfo();
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Override
public void run() {
Session session = null;
try {
Cq62StartupCodeUpgrade cq62StartupCodeUpgrade;
Object pcu;
session = this.repository.loginService("compat-codeupgrade", null);
try {
Cq62WorkflowContentUpgrade wcu = new Cq62WorkflowContentUpgrade(this.userManagerService);
cq62StartupCodeUpgrade = this;
synchronized (cq62StartupCodeUpgrade) {
this.infoProvider = wcu;
}
wcu.doUpgrade(session);
}
catch (Exception e) {
this.log.warn("Exception trying to execute " + Cq62WorkflowContentUpgrade.class.getSimpleName() + ".doUpgrade()", (Throwable)e);
this.discardPendingChanges(session);
}
try {
Cq62TargetContentUpgrade wcu = new Cq62TargetContentUpgrade();
cq62StartupCodeUpgrade = this;
synchronized (cq62StartupCodeUpgrade) {
this.infoProvider = wcu;
}
wcu.doUpgrade(session);
}
catch (Exception e) {
this.log.warn("Exception trying to execute " + Cq62TargetContentUpgrade.class.getSimpleName() + ".doUpgrade()", (Throwable)e);
this.discardPendingChanges(session);
}
try {
Cq62TargetCampaignsContentUpgrade wcu = new Cq62TargetCampaignsContentUpgrade();
cq62StartupCodeUpgrade = this;
synchronized (cq62StartupCodeUpgrade) {
this.infoProvider = wcu;
}
wcu.doUpgrade(session);
}
catch (Exception e) {
this.log.warn("Exception trying to execute " + Cq62TargetCampaignsContentUpgrade.class.getSimpleName() + ".doUpgrade()", (Throwable)e);
this.discardPendingChanges(session);
}
try {
Cq62MediaContentUpgrade mcu = new Cq62MediaContentUpgrade();
cq62StartupCodeUpgrade = this;
synchronized (cq62StartupCodeUpgrade) {
this.infoProvider = mcu;
}
mcu.doUpgrade(session);
}
catch (Exception e) {
this.log.warn("Exception trying to execute " + Cq62MediaContentUpgrade.class.getSimpleName() + ".doUpgrade()", (Throwable)e);
this.discardPendingChanges(session);
}
try {
Cq62MobileContentUpgrade mobcu = new Cq62MobileContentUpgrade();
cq62StartupCodeUpgrade = this;
synchronized (cq62StartupCodeUpgrade) {
this.infoProvider = mobcu;
}
mobcu.doUpgrade(session);
}
catch (Exception e) {
this.log.warn("Exception trying to execute " + Cq62MobileContentUpgrade.class.getSimpleName() + ".doUpgrade()", (Throwable)e);
this.discardPendingChanges(session);
}
try {
Cq62PrimaryComponentsUpgrade wcu = new Cq62PrimaryComponentsUpgrade();
cq62StartupCodeUpgrade = this;
synchronized (cq62StartupCodeUpgrade) {
this.infoProvider = wcu;
}
wcu.doUpgrade(session);
}
catch (Exception e) {
this.log.warn("Exception trying to execute " + Cq62PrimaryComponentsUpgrade.class.getSimpleName() + ".doUpgrade()", (Throwable)e);
this.discardPendingChanges(session);
}
try {
CQ62Html5SmartFileUpgrade wcu = new CQ62Html5SmartFileUpgrade();
cq62StartupCodeUpgrade = this;
synchronized (cq62StartupCodeUpgrade) {
this.infoProvider = wcu;
}
wcu.doUpgrade(session);
}
catch (Exception e) {
this.log.warn("Exception trying to execute " + CQ62Html5SmartFileUpgrade.class.getSimpleName() + ".doUpgrade()", (Throwable)e);
this.discardPendingChanges(session);
}
try {
ResourceResolver resolver = this.resourceResolverFactory.getResourceResolver(Collections.singletonMap("user.jcr.session", session));
pcu = new Cq62ProjectsCodeUpgrade();
Cq62StartupCodeUpgrade cq62StartupCodeUpgrade2 = this;
synchronized (cq62StartupCodeUpgrade2) {
this.infoProvider = pcu;
}
pcu.doUpgrade(session, resolver);
}
catch (Exception e) {
this.log.warn("Exception trying to execute {}.doUpgrade()", (Object)Cq62ProjectsCodeUpgrade.class.getSimpleName(), (Object)e);
this.discardPendingChanges(session);
}
try {
CQ62SearchFacetsConfigUpdate wcu = new CQ62SearchFacetsConfigUpdate();
pcu = this;
synchronized (pcu) {
this.infoProvider = wcu;
}
wcu.doUpgrade(session);
}
catch (Exception e) {
this.log.warn("Exception trying to execute " + CQ62SearchFacetsConfigUpdate.class.getSimpleName() + ".doUpgrade()", (Throwable)e);
this.discardPendingChanges(session);
}
try {
Cq62ConfContentUpgrade ccu = new Cq62ConfContentUpgrade();
pcu = this;
synchronized (pcu) {
this.infoProvider = ccu;
}
ccu.doUpgrade(session);
}
catch (Exception e) {
this.log.warn("Exception trying to execute " + Cq62ConfContentUpgrade.class.getSimpleName() + ".doUpgrade()", (Throwable)e);
this.discardPendingChanges(session);
}
try {
Cq62FormsContentUpgrade fcu = new Cq62FormsContentUpgrade();
pcu = this;
synchronized (pcu) {
this.infoProvider = fcu;
}
fcu.doUpgrade(session);
}
catch (Exception e3) {
this.log.warn("Exception trying to execute " + Cq62ConfContentUpgrade.class.getSimpleName() + ".doUpgrade()", (Throwable)e3);
this.discardPendingChanges(session);
}
Cq62StartupCodeUpgrade e3 = this;
synchronized (e3) {
this.infoProvider = null;
}
this.statusNode.recordUpgrade(this.repository);
}
catch (Exception e) {
this.log.warn("Exception in " + this.getClass().getSimpleName() + ".run()", (Throwable)e);
}
finally {
if (session != null) {
session.logout();
}
}
}
@Override
public boolean upgradeNeeded() {
return this.statusNode.upgradeNeeded(this.repository);
}
private void discardPendingChanges(Session session) {
try {
if (session.hasPendingChanges()) {
session.refresh(false);
}
}
catch (RepositoryException e) {
this.log.error("Exception trying to discard pending changes", (Throwable)e);
}
}
protected void bindRepository(SlingRepository slingRepository) {
this.repository = slingRepository;
}
protected void unbindRepository(SlingRepository slingRepository) {
if (this.repository == slingRepository) {
this.repository = null;
}
}
protected void bindUserManagerService(UserManagementService userManagementService) {
this.userManagerService = userManagementService;
}
protected void unbindUserManagerService(UserManagementService userManagementService) {
if (this.userManagerService == userManagementService) {
this.userManagerService = null;
}
}
protected void bindResourceResolverFactory(ResourceResolverFactory resourceResolverFactory) {
this.resourceResolverFactory = resourceResolverFactory;
}
protected void unbindResourceResolverFactory(ResourceResolverFactory resourceResolverFactory) {
if (this.resourceResolverFactory == resourceResolverFactory) {
this.resourceResolverFactory = null;
}
}
}