Cq62PrimaryComponentsUpgrade.java
2.56 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.Node
* javax.jcr.NodeIterator
* javax.jcr.RepositoryException
* javax.jcr.Session
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.compat.codeupgrade.impl.cq62;
import com.day.cq.compat.codeupgrade.internal.api.ProgressInfoProvider;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Cq62PrimaryComponentsUpgrade
implements ProgressInfoProvider {
private final String Primary_Path = "/foundation/components/primary";
private final String Root_Path = "/apps";
private final Logger log;
private String progressInfo;
public Cq62PrimaryComponentsUpgrade() {
this.log = LoggerFactory.getLogger(this.getClass());
}
@Override
public String getProgressInfo() {
return this.progressInfo;
}
void setProgressInfo(String info) {
this.progressInfo = info;
this.log.info(this.progressInfo);
}
void doUpgrade(Session session) {
this.setProgressInfo("Transfering of Resource Started");
this.transferResources(session);
this.setProgressInfo("Transfering of Resource Completed");
}
private void transferResources(Session session) {
try {
this.moveNodes(session, "/apps/foundation/components/primary", "/apps");
this.save(session);
}
catch (RepositoryException e) {
this.log.error("Error while Transferring Resources ", (Throwable)e);
}
}
private void moveNodes(Session session, String sourcePath, String TargetPath) throws RepositoryException {
if (session.nodeExists(sourcePath)) {
Node node = session.getNode(sourcePath);
NodeIterator itr = node.getNodes();
while (itr.hasNext()) {
Node nodeTomove = (Node)itr.next();
String absPath = nodeTomove.getPath().replace(sourcePath, "");
if (session.nodeExists(TargetPath + absPath)) {
this.moveNodes(session, nodeTomove.getPath(), TargetPath + absPath);
session.removeItem(nodeTomove.getPath());
continue;
}
session.move(nodeTomove.getPath(), TargetPath + absPath);
}
}
}
private void save(Session session) throws RepositoryException {
if (session.hasPendingChanges()) {
session.save();
}
}
}