SearchPromoteIndexCaller.java
5.16 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.cq.scheduled.exporter.ExportException
* com.adobe.cq.scheduled.exporter.Exporter
* com.day.cq.wcm.webservicesupport.Configuration
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.ModifiableValueMap
* org.apache.sling.api.resource.PersistenceException
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ValueMap
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.searchpromote.feed.impl.job;
import com.adobe.cq.scheduled.exporter.ExportException;
import com.adobe.cq.scheduled.exporter.Exporter;
import com.day.cq.searchpromote.SearchPromoteException;
import com.day.cq.searchpromote.SearchPromoteService;
import com.day.cq.wcm.webservicesupport.Configuration;
import java.util.Iterator;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
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.ModifiableValueMap;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(immediate=1, label="Day CQ Search&Promote index caller", description="Calls the remote indexing service from Search&Promote")
@Service
@Properties(value={@Property(name="exporter.type", value={"searchpromote-index-caller"})})
public class SearchPromoteIndexCaller
implements Exporter {
private final Logger log;
private static final String CONFIG_PATH_KEY = "configPath";
private static final String REMOTE_PASS_KEY = "remotectlpass";
private static final String CONFIG_LAST_REQUEST_STATUS_KEY = "lastRequestResult";
@Reference
private SearchPromoteService searchPromoteService;
private String accountNo;
private String remoteCtlPassword;
private String schedulerConfigPath;
public SearchPromoteIndexCaller() {
this.log = LoggerFactory.getLogger(this.getClass());
}
public void exportData(Resource config, Resource resource) throws ExportException {
this.log.debug("Calling the remote indexing service...");
try {
ResourceResolver resolver = config.getResourceResolver();
this.configure(config);
String responseStatus = this.searchPromoteService.callRemoteIndex(this.accountNo, this.remoteCtlPassword, false);
this.log.debug("Server responded: {}", (Object)responseStatus);
this.updateResult(resolver, responseStatus);
}
catch (SearchPromoteException e) {
this.log.error(e.getMessage(), (Throwable)e);
throw new ExportException((Throwable)e);
}
catch (PersistenceException e) {
this.log.error(e.getMessage(), (Throwable)e);
throw new ExportException((Throwable)e);
}
}
private void updateResult(ResourceResolver resolver, String responseStatus) throws PersistenceException {
Resource configurationResource = resolver.getResource(this.schedulerConfigPath + "/jcr:content");
ModifiableValueMap mvm = (ModifiableValueMap)configurationResource.adaptTo(ModifiableValueMap.class);
mvm.put((Object)"lastRequestResult", (Object)responseStatus);
resolver.commit();
}
private void configure(Resource config) throws SearchPromoteException {
ValueMap vm = (ValueMap)config.adaptTo(ValueMap.class);
String configPath = (String)vm.get("configPath", (Object)"");
ResourceResolver resolver = config.getResourceResolver();
Resource configResource = resolver.getResource(configPath);
Configuration confObject = (Configuration)configResource.getParent().adaptTo(Configuration.class);
if (confObject == null) {
this.log.error("Configuration {} not found.", (Object)configPath);
throw new SearchPromoteException("Configuration " + configPath + " not found.");
}
this.accountNo = (String)confObject.get("accountno", (Object)"");
Iterator confIterator = confObject.listChildren();
if (confIterator.hasNext()) {
Configuration schedulerConfig = (Configuration)confIterator.next();
this.schedulerConfigPath = schedulerConfig.getPath();
this.remoteCtlPassword = (String)schedulerConfig.get("remotectlpass", (Object)"");
}
}
protected void bindSearchPromoteService(SearchPromoteService searchPromoteService) {
this.searchPromoteService = searchPromoteService;
}
protected void unbindSearchPromoteService(SearchPromoteService searchPromoteService) {
if (this.searchPromoteService == searchPromoteService) {
this.searchPromoteService = null;
}
}
}