FrameworkComponentImpl.java
8.89 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap
* org.apache.commons.collections.Factory
* org.apache.commons.collections.map.MultiValueMap
* org.apache.commons.lang.ArrayUtils
* org.apache.commons.lang.StringUtils
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.commons.json.JSONArray
*/
package com.day.cq.analytics.sitecatalyst.impl;
import com.day.cq.analytics.impl.AnalyticsComponent;
import com.day.cq.analytics.impl.AnalyticsComponentService;
import com.day.cq.analytics.sitecatalyst.FrameworkComponent;
import com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.collections.Factory;
import org.apache.commons.collections.map.MultiValueMap;
import org.apache.commons.lang.ArrayUtils;
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.ValueMap;
import org.apache.sling.commons.json.JSONArray;
public class FrameworkComponentImpl
extends HierarchyNodeInheritanceValueMap
implements FrameworkComponent {
private static final String RT_TARGET_CONTEXTHUB_STORE = "cq/analytics/components/mappings/cbcontexthubmappings";
private static final String RT_ANALYTICS_CONTEXTHUB_STORE = "cq/analytics/components/mappings/cqcontexthubmappings";
private MultiValueMap cqMappings = null;
protected String[] storeTypes = new String[0];
protected String[] trackedVars = new String[0];
protected String[] trackedEvents = new String[0];
protected String[] trackedVarsEvents = new String[0];
protected String defaultStore;
protected String defaultEventStore;
protected Resource resource;
protected ValueMap cqComp;
private Set<String> keySet = null;
private final Factory factory;
private AnalyticsComponentService componentService;
public FrameworkComponentImpl(Resource mappingComp, String[] storeTypes, AnalyticsComponentService componentService) {
super(mappingComp);
this.factory = new Factory(){
public Object create() {
return new HashSet<String>(){
@Override
public String toString() {
return StringUtils.join((Collection)this, (String)",");
}
};
}
};
this.resource = mappingComp;
this.storeTypes = storeTypes;
this.componentService = componentService;
this.initFramework();
this.trackedVarsEvents = (String[])ArrayUtils.addAll((Object[])this.qualifyCqVars(this.trackedVars, this.defaultStore), (Object[])this.qualifyCqVars(this.trackedEvents, this.defaultEventStore));
}
private void initFramework() {
if (this.isContextHubStore(this.resource)) {
this.defaultStore = (String)this.get("cq:defaultStore", (Object)"eventdata");
this.defaultEventStore = (String)this.get("cq:defaultEventStore", (Object)"eventdata.events");
this.trackedVars = (String[])this.get("cq:trackvars", (Object)new String[0]);
this.trackedEvents = new String[0];
this.cqComp = this.resource.getValueMap();
} else {
AnalyticsComponent component = this.componentService.getAnalyticsComponent((String)this.get("cq:componentPath", String.class));
if (component != null) {
this.defaultStore = component.getDefaultStore();
this.defaultEventStore = component.getDefaultEventStore();
this.trackedVars = component.getTrackedVars();
this.trackedEvents = component.getTrackedEvents();
this.cqComp = component.getAnalyticsProps();
}
}
}
private boolean isContextHubStore(Resource resource) {
return resource.isResourceType("cq/analytics/components/mappings/cbcontexthubmappings") || resource.isResourceType("cq/analytics/components/mappings/cqcontexthubmappings");
}
protected String[] qualifyCqVars(String[] vars, String defaultStore) {
String[] qualified = (String[])ArrayUtils.clone((Object[])vars);
for (int i = 0; i < qualified.length; ++i) {
String[] valueParts = qualified[i].split("\\.");
if (valueParts.length != 0 && ArrayUtils.contains((Object[])this.storeTypes, (Object)qualified[i].split("\\.")[0])) continue;
qualified[i] = defaultStore + "." + qualified[i].trim();
}
return qualified;
}
@Override
public String getType() {
return this.resource.getResourceType();
}
@Override
public String getPath() {
return this.resource.getPath();
}
@Override
public String[] getTrackedVarsEvents() {
return this.trackedVarsEvents;
}
@Override
public MultiValueMap getCqMappings() {
if (this.cqMappings == null) {
this.cqMappings = MultiValueMap.decorate(new HashMap(), (Factory)this.factory);
for (String scVar : this.inheritedKeySet()) {
String cqVar = (String)this.getInherited(scVar, (Object)"");
if (cqVar.length() > 0) {
this.cqMappings.put((Object)cqVar, (Object)scVar);
continue;
}
for (String var : this.getTrackedVarsEvents()) {
if (!this.cqMappings.containsValue((Object)var, (Object)scVar)) continue;
this.cqMappings.remove((Object)var, (Object)scVar);
}
}
}
return this.cqMappings;
}
@Override
public JSONArray getScVars(String cqVar) {
return new JSONArray((Collection)this.getCqMappings().get((Object)cqVar));
}
public <T> T getInherited(String scKey, Class<T> type) {
Object value = super.getInherited(scKey, type);
if (value == null) {
value = this.cqComp.get((Object)scKey);
}
String[] valueParts = ((String)value).split("\\.");
if (!(scKey.contains(":") || valueParts.length != 0 && ArrayUtils.contains((Object[])this.storeTypes, (Object)valueParts[0]))) {
if (ArrayUtils.contains((Object[])this.trackedVars, (Object)value)) {
value = this.defaultStore + "." + value;
} else if (ArrayUtils.contains((Object[])this.trackedEvents, (Object)value)) {
value = this.defaultEventStore + "." + value;
}
}
return (T)((String)value).trim();
}
public Object get(Object key) {
String cqVar = (String)super.get(key);
if (cqVar == null) {
return null;
}
String[] valueParts = cqVar.split("\\.");
if (!(((String)key).contains(":") || valueParts.length != 0 && ArrayUtils.contains((Object[])this.storeTypes, (Object)cqVar.split("\\.")[0]))) {
if (ArrayUtils.contains((Object[])this.trackedVars, (Object)cqVar)) {
cqVar = this.defaultStore + "." + cqVar;
} else if (ArrayUtils.contains((Object[])this.trackedEvents, (Object)cqVar)) {
cqVar = this.defaultEventStore + "." + cqVar;
}
}
return cqVar.trim();
}
public Set<String> keySet() {
if (this.keySet == null) {
this.keySet = new HashSet<String>(super.keySet());
for (String key : super.keySet()) {
if (!key.contains(":")) continue;
this.keySet.remove(key);
}
}
return this.keySet;
}
@Override
public Set<String> inheritedKeySet() {
String innerResource = FrameworkComponentImpl.getInnerPath((Resource)this.resource);
HashSet<String> keySet = new HashSet<String>(this.keySet());
keySet.addAll(this.cqComp.keySet());
for (String key : this.cqComp.keySet()) {
if (!key.contains(":")) continue;
keySet.remove(key);
}
String fwPath = this.resource.getPath().split("jcr:content/" + innerResource)[0];
Resource fwResource = this.resource.getResourceResolver().getResource(fwPath);
if (fwResource != null) {
Resource parentComp = null;
for (Resource parentFw = fwResource.getParent(); parentFw != null && (parentComp = this.resource.getResourceResolver().getResource(parentFw.getPath() + "/" + "jcr:content" + "/" + innerResource)) == null; parentFw = parentFw.getParent()) {
}
if (parentComp != null) {
keySet.addAll(new FrameworkComponentImpl(parentComp, this.storeTypes, this.componentService).inheritedKeySet());
}
}
return keySet;
}
@Override
public ValueMap getAnalyticsProperties() {
return this.cqComp;
}
}