AccountOptionsUpdater.java
5.03 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.polling.importer.ImportException
* com.day.cq.polling.importer.Importer
* com.day.cq.wcm.webservicesupport.Configuration
* com.day.cq.wcm.webservicesupport.ConfigurationManager
* com.day.cq.wcm.webservicesupport.ConfigurationManagerFactory
* 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.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.commons.osgi.PropertiesUtil
* org.osgi.service.component.ComponentContext
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.analytics.testandtarget.impl;
import com.day.cq.analytics.testandtarget.TestandtargetException;
import com.day.cq.analytics.testandtarget.impl.TestandtargetPrivateService;
import com.day.cq.polling.importer.ImportException;
import com.day.cq.polling.importer.Importer;
import com.day.cq.wcm.webservicesupport.Configuration;
import com.day.cq.wcm.webservicesupport.ConfigurationManager;
import com.day.cq.wcm.webservicesupport.ConfigurationManagerFactory;
import java.util.Dictionary;
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.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=1, label="Adobe Target account options updater", description="Updates the Adobe Target cloud configuration options with the account options from Taget")
@Service
@Property(name="importer.scheme", value={"adobe-target-account-options"}, propertyPrivate=1)
public class AccountOptionsUpdater
implements Importer {
private static final boolean DEFAULT_ENABLED = true;
private static final Logger LOG = LoggerFactory.getLogger(AccountOptionsUpdater.class);
@Property(label="Enabled", description="Controls whether this importer is enabled or not. Defaults to true on author instances and false on publish instances.", boolValue={1})
private static final String PROPERTY_ENABLED = "cq.analytics.testandtarget.accountoptionsupdater.enabled";
@Reference
private TestandtargetPrivateService testandtargetService;
@Reference
private ConfigurationManagerFactory configurationManagerFactory;
private boolean enabled;
protected void activate(ComponentContext ctx) {
this.enabled = PropertiesUtil.toBoolean(ctx.getProperties().get("cq.analytics.testandtarget.accountoptionsupdater.enabled"), (boolean)true);
}
public void importData(String scheme, String dataSource, Resource target) throws ImportException {
if (!this.enabled) {
LOG.debug("Component is not enabled, skipping import.");
return;
}
ResourceResolver resolver = target.getResourceResolver();
LOG.info("Updating account options for Adobe Target cloud config at {}", (Object)dataSource);
Resource cloudConfig = resolver.getResource(dataSource);
if (cloudConfig == null) {
LOG.error("No cloud service configuration found at {}", (Object)dataSource);
return;
}
ConfigurationManager configurationManager = this.configurationManagerFactory.getConfigurationManager(resolver);
Configuration config = configurationManager.getConfiguration(cloudConfig.getPath());
if (config == null) {
LOG.warn("Unable to update account at {} since the resource at {} can not be adapted to a '{}'", new Object[]{target.getPath(), cloudConfig.getPath(), Configuration.class.getName()});
return;
}
try {
this.testandtargetService.updateAccountOptions(config);
LOG.info("Updated account options at {}", (Object)config.getPath());
}
catch (TestandtargetException e) {
LOG.error(e.getMessage(), (Throwable)e);
}
}
protected void bindTestandtargetService(TestandtargetPrivateService testandtargetPrivateService) {
this.testandtargetService = testandtargetPrivateService;
}
protected void unbindTestandtargetService(TestandtargetPrivateService testandtargetPrivateService) {
if (this.testandtargetService == testandtargetPrivateService) {
this.testandtargetService = null;
}
}
protected void bindConfigurationManagerFactory(ConfigurationManagerFactory configurationManagerFactory) {
this.configurationManagerFactory = configurationManagerFactory;
}
protected void unbindConfigurationManagerFactory(ConfigurationManagerFactory configurationManagerFactory) {
if (this.configurationManagerFactory == configurationManagerFactory) {
this.configurationManagerFactory = null;
}
}
}