Cq61StartupCodeUpgrade.java
6.47 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.security.user.UserManagementService
* javax.jcr.Session
* 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.jcr.api.SlingRepository
* org.apache.sling.jcr.contentloader.ContentImporter
* org.osgi.service.component.ComponentContext
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.compat.codeupgrade.impl.cq61;
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.cq61.Cq61CloudServicesContentUpgrade;
import com.day.cq.compat.codeupgrade.impl.cq61.Cq61CloudSettingsContentUpgrade;
import com.day.cq.compat.codeupgrade.impl.cq61.Cq61ConfContentUpgrade;
import com.day.cq.compat.codeupgrade.internal.api.ProgressInfoProvider;
import java.util.Dictionary;
import javax.jcr.Session;
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.jcr.api.SlingRepository;
import org.apache.sling.jcr.contentloader.ContentImporter;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(immediate=1, metatype=1, label="%Cq61StartupCodeUpgrade.name", description="%Cq61StartupCodeUpgrade.description")
@Service
@Property(name="service.ranking", intValue={610})
public class Cq61StartupCodeUpgrade
implements CodeUpgradeTask {
private final Logger log;
private StatusNode statusNode;
private ProgressInfoProvider infoProvider;
@Reference
private SlingRepository repository;
@Reference
private ContentImporter slingContentImporter;
@Reference
private UserManagementService userManagerService;
@Property(value={"/var/upgrade/status"})
public static final String PROP_STATUS_NODE_PATH = "status.node.path";
@Property(value={"Cq61StartupCodeUpgrade"})
public static final String PROP_STATUS_PROPERTY_NAME = "status.property.name";
public Cq61StartupCodeUpgrade() {
this.log = LoggerFactory.getLogger(this.getClass());
this.repository = null;
this.slingContentImporter = null;
this.userManagerService = null;
}
public String toString() {
return this.getClass().getSimpleName();
}
public 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 s = null;
try {
Cq61StartupCodeUpgrade cq61StartupCodeUpgrade;
s = this.repository.loginService("compat-codeupgrade", null);
try {
Cq61CloudServicesContentUpgrade wcu = new Cq61CloudServicesContentUpgrade();
cq61StartupCodeUpgrade = this;
synchronized (cq61StartupCodeUpgrade) {
this.infoProvider = wcu;
}
wcu.doUpgrade(s);
}
catch (Exception e) {
this.log.warn("Exception trying to execute " + Cq61CloudServicesContentUpgrade.class.getSimpleName() + ".doUpgrade()", (Throwable)e);
}
try {
Cq61CloudSettingsContentUpgrade wcu = new Cq61CloudSettingsContentUpgrade();
cq61StartupCodeUpgrade = this;
synchronized (cq61StartupCodeUpgrade) {
this.infoProvider = wcu;
}
wcu.doUpgrade(s);
}
catch (Exception e) {
this.log.warn("Exception trying to execute " + Cq61CloudSettingsContentUpgrade.class.getSimpleName() + ".doUpgrade()", (Throwable)e);
}
try {
Cq61ConfContentUpgrade wcu = new Cq61ConfContentUpgrade();
cq61StartupCodeUpgrade = this;
synchronized (cq61StartupCodeUpgrade) {
this.infoProvider = wcu;
}
wcu.doUpgrade(s);
}
catch (Exception e3) {
this.log.warn("Exception trying to execute " + Cq61ConfContentUpgrade.class.getSimpleName() + ".doUpgrade()", (Throwable)e3);
}
Cq61StartupCodeUpgrade 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 (s != null) {
s.logout();
}
}
}
@Override
public boolean upgradeNeeded() {
return this.statusNode.upgradeNeeded(this.repository);
}
protected void bindRepository(SlingRepository slingRepository) {
this.repository = slingRepository;
}
protected void unbindRepository(SlingRepository slingRepository) {
if (this.repository == slingRepository) {
this.repository = null;
}
}
protected void bindSlingContentImporter(ContentImporter contentImporter) {
this.slingContentImporter = contentImporter;
}
protected void unbindSlingContentImporter(ContentImporter contentImporter) {
if (this.slingContentImporter == contentImporter) {
this.slingContentImporter = null;
}
}
protected void bindUserManagerService(UserManagementService userManagementService) {
this.userManagerService = userManagementService;
}
protected void unbindUserManagerService(UserManagementService userManagementService) {
if (this.userManagerService == userManagementService) {
this.userManagerService = null;
}
}
}