PerformanceReportSerializer.java
7.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
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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.google.gson.Gson
* com.google.gson.GsonBuilder
* com.google.gson.TypeAdapter
* com.google.gson.TypeAdapterFactory
* com.google.gson.reflect.TypeToken
* com.google.gson.stream.JsonReader
* com.google.gson.stream.JsonToken
* com.google.gson.stream.JsonWriter
*/
package com.day.cq.analytics.testandtarget.impl.serializer;
import com.day.cq.analytics.testandtarget.PerformanceReport;
import com.day.cq.analytics.testandtarget.PerformanceReportItem;
import com.day.cq.analytics.testandtarget.impl.serializer.AbstractSerializer;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
public class PerformanceReportSerializer
extends AbstractSerializer<PerformanceReport> {
public static final String ACTIVITY_TOTALS_NAME = "Activity Totals";
@Override
public String serialize(PerformanceReport o) {
throw new UnsupportedOperationException("Not implemented");
}
@Override
public PerformanceReport deserialize(String json, Class<PerformanceReport> clazz) {
return (PerformanceReport)new GsonBuilder().registerTypeAdapterFactory((TypeAdapterFactory)new Deserializer()).create().fromJson(json, clazz);
}
private static class Adapter
extends TypeAdapter<PerformanceReport> {
private Adapter() {
}
public void write(JsonWriter out, PerformanceReport value) throws IOException {
throw new UnsupportedOperationException("Not implemented");
}
public PerformanceReport read(JsonReader in) throws IOException {
PerformanceReport report = new PerformanceReport();
in.beginObject();
while (in.hasNext()) {
String name = in.nextName();
if ("experiences".equals(name)) {
this.readExperiences(in, report);
continue;
}
if ("winner".equals(name)) {
this.readWinningExperience(in, report);
continue;
}
if ("campaignTotals".equals(name)) {
this.readCampaignTotals(in, report);
continue;
}
in.skipValue();
}
in.endObject();
return report;
}
private void readCampaignTotals(JsonReader in, PerformanceReport report) throws IOException {
in.beginObject();
PerformanceReportItem item = new PerformanceReportItem();
item.setExperienceName("Activity Totals");
while (in.hasNext()) {
String name = in.nextName();
if (name.equals("count")) {
item.setEntryCount(in.nextInt());
continue;
}
if (name.equals("conversionRate")) {
item.setConversionRate(in.nextDouble());
continue;
}
if (name.equals("rpm")) {
item.setRPV(in.nextString());
continue;
}
if (name.equals("aov")) {
item.setAOV(in.nextString());
continue;
}
if (name.equals("sales")) {
item.setTotalSales(in.nextString());
continue;
}
in.skipValue();
}
report.addItem(item);
in.endObject();
}
private void readWinningExperience(JsonReader in, PerformanceReport report) throws IOException {
in.beginObject();
while (in.hasNext()) {
String name = in.nextName();
if (name.equals("winningExperience")) {
report.setWinningExperienceName(in.nextString());
continue;
}
in.skipValue();
}
in.endObject();
}
private void readExperiences(JsonReader in, PerformanceReport report) throws IOException {
in.beginArray();
while (!in.peek().equals((Object)JsonToken.END_ARRAY)) {
if (!in.peek().equals((Object)JsonToken.BEGIN_OBJECT)) continue;
PerformanceReportItem item = new PerformanceReportItem();
in.beginObject();
while (!in.peek().equals((Object)JsonToken.END_OBJECT)) {
if (in.peek().equals((Object)JsonToken.NAME)) {
String name = in.nextName();
if (name.equals("count")) {
item.setEntryCount(in.nextInt());
continue;
}
if (name.equals("conversions")) {
item.setConversionCount(in.nextInt());
continue;
}
if (name.equals("name")) {
item.setExperienceName(in.nextString());
continue;
}
if (name.equals("conversionRate")) {
item.setConversionRate(in.nextDouble());
continue;
}
if (name.equals("lift")) {
item.setLift(in.nextDouble());
continue;
}
if (name.equals("confidence")) {
item.setConfidence(in.nextDouble());
continue;
}
if (name.equals("engagement")) {
item.setEngagement(in.nextDouble());
continue;
}
if (name.equals("engagementTotal")) {
item.setEngagementTotal(in.nextDouble());
continue;
}
if (name.equals("engagementCount")) {
item.setEngagementCount(in.nextInt());
continue;
}
if (name.equals("rpm")) {
item.setRPV(in.nextString());
continue;
}
if (name.equals("aov")) {
item.setAOV(in.nextString());
continue;
}
if (name.equals("sales")) {
item.setTotalSales(in.nextString());
continue;
}
in.skipValue();
continue;
}
in.skipValue();
}
in.endObject();
report.addItem(item);
}
in.endArray();
}
}
private static final class Deserializer
implements TypeAdapterFactory {
private Deserializer() {
}
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
Class rawType = typeToken.getRawType();
if (!PerformanceReport.class.isAssignableFrom(rawType)) {
return null;
}
return new Adapter();
}
}
}