JsonResponseSegmentIdList.java
3.61 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.commons.lang.StringUtils
* org.apache.sling.commons.json.JSONArray
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.aam.demdex;
import com.adobe.cq.aam.client.spi.AudienceManagerConfiguration;
import com.adobe.cq.aam.client.spi.SegmentService;
import com.adobe.cq.aam.demdex.SegmentListException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.apache.sling.commons.json.JSONArray;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class JsonResponseSegmentIdList
implements Iterable<String> {
private static final Logger LOGGER = LoggerFactory.getLogger(JsonResponseSegmentIdList.class);
private Iterable<String> items;
public JsonResponseSegmentIdList(SegmentService segmentService, AudienceManagerConfiguration config, JSONObject json) throws SegmentListException {
this.items = this.parse(json, config.getDestinationCookieMap());
try {
LOGGER.debug("Items is {} from {} ", this.items, (Object)json.toString(2));
}
catch (JSONException e) {
LOGGER.debug(e.getMessage(), (Throwable)e);
}
}
private Set<String> parse(JSONObject jsonObject, Map<String, String> integrationCookies) throws SegmentListException {
HashSet<String> segmentIds;
block7 : {
segmentIds = new HashSet<String>();
try {
if (jsonObject.has("stuff")) {
JSONArray stuff = jsonObject.getJSONArray("stuff");
boolean found = false;
for (int i = 0; i < stuff.length(); ++i) {
JSONObject v = stuff.getJSONObject(i);
if (!v.has("cv") || !v.has("cn") || !v.has("dmn")) continue;
String cn = v.getString("cn");
String cv = v.getString("cv");
String domain = v.getString("dmn");
LOGGER.debug("Found Cookie ID {} {} ", (Object)domain, (Object)cn);
if (!domain.equals(integrationCookies.get(cn))) continue;
LOGGER.debug("Found Acceptable Cookie {} {} ", (Object)domain, (Object)cn);
found = true;
if (!cv.startsWith("segs=")) continue;
for (String sid : StringUtils.split((String)cv, (String)",")) {
if (sid.startsWith("segs=")) {
sid = sid.substring("segs=".length());
}
LOGGER.debug("Found Segment ID {} ", (Object)sid);
segmentIds.add(sid);
}
}
if (!found) {
throw new SegmentListException("Empty Stuff object found in response, no segments present");
}
break block7;
}
throw new SegmentListException("No Stuff object found in response, no segments present");
}
catch (JSONException e) {
LOGGER.error(e.getMessage(), (Throwable)e);
}
}
return segmentIds;
}
@Override
public Iterator<String> iterator() {
return this.items.iterator();
}
}