AudienceManagerConfiguration.java
7.63 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.commons.inherit.InheritanceValueMap
* com.day.cq.commons.jcr.JcrUtil
* com.day.cq.wcm.webservicesupport.Configuration
* com.day.cq.wcm.webservicesupport.ConfigurationManager
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.RepositoryException
* javax.jcr.Value
* org.apache.commons.lang.StringUtils
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceUtil
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.aam.client.spi;
import com.day.cq.commons.inherit.InheritanceValueMap;
import com.day.cq.commons.jcr.JcrUtil;
import com.day.cq.wcm.webservicesupport.Configuration;
import com.day.cq.wcm.webservicesupport.ConfigurationManager;
import java.util.HashMap;
import java.util.Map;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
import org.apache.commons.lang.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Deprecated
public class AudienceManagerConfiguration {
public static final String CONFIG_RESOURCE_TYPE = "cq/personalization/audiencemanager/components/cloudservices/audiencemanagerpage";
public static final String PROP_OFFLINE_MODE = "offlineMode";
public static final String PROP_OFFLINE_SET = "offlineSet";
public static final String PROP_SEGMENTATION_TEMPLATE = "segmentationTemplate";
public static final String PROP_TEMPLATE = "template";
public static final String PROP_PARTNER = "partner";
public static final String PROP_CONTAINER = "container";
private static final String PROP_DESTINATION_COOKIES = "destinations";
public static final String PROP_DATA_PROVIDER_ID = "dataProviderId";
public static final String PATH_ETC_SEGMENTATION_AAM = "/etc/segmentation/aam";
public static final String DEFAULT_TEMPLATE = "/libs/cq/personalization/templates/segment";
public static final String PATH_CONFIG_BASE = "/etc/cloudservices/audiencemanager";
private static final Logger LOGGER = LoggerFactory.getLogger(AudienceManagerConfiguration.class);
public static final String CQ_INTEGRATION_DESTINATION_COOKIE_DOMAIN = ".cqclientintegration.adobe.com";
public static final String CQ_INTEGRATION_DESTINATION_COOKIE_NAME = "CQIntegrationDestination";
private static final String[] DEFAULT_COOKIE_MAP_VALUES = new String[]{"CQIntegrationDestination=.cqclientintegration.adobe.com"};
private String target;
private String template;
private String segmentationTemplate;
private String title;
private String name;
private String targetParent;
private boolean offlineTest;
private String offlineTestSet;
private Node configNode;
private Resource resource;
private String partner;
private String containerNSID;
private String dataProviderId;
private Map<String, String> destinationCookieMap = new HashMap<String, String>();
public AudienceManagerConfiguration(Resource configResource) {
if (configResource == null) {
throw new IllegalArgumentException("Resource is null");
}
ConfigurationManager configMgr = (ConfigurationManager)configResource.getResourceResolver().adaptTo(ConfigurationManager.class);
String cloudConfigPath = configResource.getPath();
if ("public".equals(ResourceUtil.getName((String)cloudConfigPath))) {
cloudConfigPath = ResourceUtil.getParent((String)cloudConfigPath);
}
if ("jcr:content".equals(ResourceUtil.getName((String)cloudConfigPath))) {
cloudConfigPath = ResourceUtil.getParent((String)cloudConfigPath);
}
Configuration cfg = configMgr.getConfiguration(cloudConfigPath);
InheritanceValueMap props = cfg.getProperties();
this.resource = configResource;
this.configNode = (Node)configResource.adaptTo(Node.class);
this.partner = (String)props.get("partner", (Object)"partner");
this.containerNSID = (String)props.get("container", (Object)"0");
this.title = this.partner + "_" + this.containerNSID;
this.name = JcrUtil.createValidName((String)this.title);
this.target = "/etc/segmentation/aam/" + this.name;
this.template = (String)props.get("template", (Object)"/libs/cq/personalization/templates/segment");
this.segmentationTemplate = (String)props.get("segmentationTemplate", (Object)"");
this.offlineTest = (Boolean)props.get("offlineMode", (Object)false);
this.offlineTestSet = (String)props.get("offlineSet", (Object)"segment");
this.destinationCookieMap = this.getMapProperty(this.configNode, "destinations", DEFAULT_COOKIE_MAP_VALUES);
this.targetParent = AudienceManagerConfiguration.getParent(this.target);
this.dataProviderId = (String)props.get("dataProviderId", null);
}
private Map<String, String> getMapProperty(Node node, String propname, String[] defaultValues) {
HashMap<String, String> map = new HashMap<String, String>();
try {
if (node.hasProperty(propname)) {
Value[] values;
for (Value v : values = node.getProperty(propname).getValues()) {
String[] nv = StringUtils.split((String)v.getString(), (String)"=", (int)2);
map.put(nv[0].trim(), nv[1].trim());
}
} else {
for (String v : defaultValues) {
String[] nv = StringUtils.split((String)v, (String)"=", (int)2);
map.put(nv[0].trim(), nv[1].trim());
}
}
}
catch (RepositoryException e) {
LOGGER.error("Unable to load Property map from property " + propname);
}
return map;
}
public String getTemplate() {
return this.template;
}
public String getTarget() {
return this.target;
}
public String getTargetParent() {
return this.targetParent;
}
public String getName() {
return this.name;
}
public String getTitle() {
return this.title;
}
public String getSegmentationTemplate() {
return this.segmentationTemplate;
}
public boolean isOfflineTest() {
return this.offlineTest;
}
public String getOfflineTestSet() {
return this.offlineTestSet;
}
public static String getParent(String path) {
if (path == null || path.length() == 0 || path.equals("/")) {
return "/";
}
int i = path.lastIndexOf(47);
if (i == path.length() - 1) {
i = path.lastIndexOf(47, i - 1);
}
return path.substring(0, i);
}
public static String getConfigPath(String partner, String containerNSID) {
if (containerNSID == null) {
containerNSID = "0";
}
return "/etc/cloudservices/audiencemanager/" + JcrUtil.createValidName((String)new StringBuilder().append(partner).append("_").append(containerNSID).toString());
}
public Node getNode() {
return this.configNode;
}
public Resource getResource() {
return this.resource;
}
public String getPartner() {
return this.partner;
}
public String getContainerNSID() {
return this.containerNSID;
}
public String getDataProviderId() {
return this.dataProviderId;
}
public Map<String, String> getDestinationCookieMap() {
return this.destinationCookieMap;
}
}