SearchFacetUpgrade.java
3.39 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.RepositoryException
* javax.jcr.Session
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.sling.jcr.api.SlingRepository
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.dam.commons.util.impl;
import javax.jcr.Node;
import javax.jcr.Property;
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.Reference;
import org.apache.sling.jcr.api.SlingRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Deprecated
@Component(immediate=1)
public class SearchFacetUpgrade {
private static final Logger logger = LoggerFactory.getLogger(SearchFacetUpgrade.class);
@Reference
private SlingRepository repository;
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Activate
protected void activate() {
Session adminSession = null;
try {
adminSession = this.repository.loginAdministrative(null);
this.fixCustomizedSearchFacets(adminSession);
}
catch (RepositoryException e) {
logger.warn("Unable to execute search facet upgrade", (Throwable)e);
}
finally {
if (adminSession != null && adminSession.isLive()) {
adminSession.logout();
}
}
}
private void fixCustomizedSearchFacets(Session session) {
String customizedSearchFacetsPath = "/apps/dam/gui/content/facets/Assets";
String searchFacetsPath = "/libs/dam/gui/content/facets/assets";
String predicatesConfig = "predicatesConfig";
try {
Node customizedSearchFacetsNode;
if (session.nodeExists(customizedSearchFacetsPath) && (customizedSearchFacetsNode = session.getNode(customizedSearchFacetsPath)) != null) {
Node searchFacetsNode;
this.rename(customizedSearchFacetsNode, "assets");
if (session.nodeExists(searchFacetsPath) && (searchFacetsNode = session.getNode(searchFacetsPath)).hasProperty(predicatesConfig)) {
String predicatesConfigVal = searchFacetsNode.getProperty(predicatesConfig).getString();
if (!customizedSearchFacetsNode.hasProperty(predicatesConfig)) {
customizedSearchFacetsNode.setProperty(predicatesConfig, predicatesConfigVal);
}
}
session.save();
logger.info("Successfully fixed customized search facets");
}
}
catch (RepositoryException e) {
logger.warn("Unable to fix customized search facets", (Throwable)e);
}
}
private void rename(Node node, String newName) throws RepositoryException {
node.getSession().move(node.getPath(), node.getParent().getPath() + "/" + newName);
}
protected void bindRepository(SlingRepository slingRepository) {
this.repository = slingRepository;
}
protected void unbindRepository(SlingRepository slingRepository) {
if (this.repository == slingRepository) {
this.repository = null;
}
}
}