SitecatalystWebserviceImpl.java
11.4 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.webservicesupport.Configuration
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.commons.json.JSONArray
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
*/
package com.day.cq.analytics.sitecatalyst.impl;
import com.day.cq.analytics.sitecatalyst.SitecatalystException;
import com.day.cq.analytics.sitecatalyst.SitecatalystHttpClient;
import com.day.cq.analytics.sitecatalyst.SitecatalystWebservice;
import com.day.cq.analytics.sitecatalyst.common.AbstractSiteCatalystService;
import com.day.cq.wcm.webservicesupport.Configuration;
import java.util.HashSet;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.json.JSONArray;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
@Component(metatype=0)
@Service
public class SitecatalystWebserviceImpl
extends AbstractSiteCatalystService
implements SitecatalystWebservice {
@Reference
private SitecatalystHttpClient client;
@Override
public void checkCredentials(String company, String username, String secret) throws SitecatalystException {
throw new UnsupportedOperationException("This method is no longer supported.");
}
@Override
public String getLoginKey(String company, String username, String password) throws SitecatalystException {
return this.getLoginKey(null, company, username, password);
}
@Override
public String getLoginKey(String server, String company, String username, String password) throws SitecatalystException {
try {
JSONObject json = new JSONObject();
json.put("company", (Object)company);
json.put("login", (Object)username);
json.put("password", (Object)password);
String response = this.client.execute(server, "Company.GetLoginKey", json.toString(), null, null, null);
String error = this.getError(response);
if (error != null) {
throw new SitecatalystException(error);
}
return response.replaceAll("\"", "");
}
catch (JSONException e) {
throw new SitecatalystException(e.getMessage(), (Throwable)e);
}
}
@Override
public String getReportSuites(Configuration configuration) throws SitecatalystException {
try {
JSONObject json = new JSONObject();
json.put("rs_type", (Object)new JSONArray("['standard']"));
json.put("sp", (Object)"");
return this.client.execute("Company.GetReportSuites", json.toString(), configuration);
}
catch (JSONException e) {
throw new SitecatalystException(e.getMessage(), (Throwable)e);
}
}
@Override
public String getSegments(String server, String company, String username, String secret) throws SitecatalystException {
try {
JSONObject json = new JSONObject();
json.put("accessLevel", (Object)"all");
String response = this.client.execute(server, "Segments.Get", json.toString(), company, username, secret);
String error = this.getError(response);
if (error != null) {
throw new SitecatalystException(error);
}
return response;
}
catch (JSONException e) {
throw new SitecatalystException(e.getMessage(), (Throwable)e);
}
}
@Override
public String getTrackingServer(Configuration configuration, String rsid) throws SitecatalystException {
try {
JSONObject json = new JSONObject();
json.put("rsid", (Object)rsid);
return this.client.execute("Company.GetTrackingServer", json.toString(), configuration);
}
catch (JSONException e) {
throw new SitecatalystException(e.getMessage(), (Throwable)e);
}
}
@Override
public String getEvars(Configuration configuration, String rsid) throws SitecatalystException {
try {
JSONArray rsidList = this.splitToJSONArray(rsid);
JSONObject json = new JSONObject();
json.put("rsid_list", (Object)rsidList);
String result = this.client.execute("ReportSuite.GetEvars", json.toString(), configuration);
JSONArray array = this.toJSONArray(result);
this.checkResults(rsidList, array);
return result;
}
catch (JSONException e) {
throw new SitecatalystException(e.getMessage(), (Throwable)e);
}
}
@Override
public String getTrafficVars(Configuration configuration, String rsid) throws SitecatalystException {
try {
JSONArray rsidList = this.splitToJSONArray(rsid);
JSONObject json = new JSONObject();
json.put("rsid_list", (Object)rsidList);
String result = this.client.execute("ReportSuite.GetProps", json.toString(), configuration);
JSONArray array = this.toJSONArray(result);
this.checkResults(rsidList, array);
return result;
}
catch (JSONException e) {
throw new SitecatalystException(e.getMessage(), (Throwable)e);
}
}
@Override
public String getSuccessEvents(Configuration configuration, String rsid) throws SitecatalystException {
try {
JSONArray rsidList = this.splitToJSONArray(rsid);
JSONObject json = new JSONObject();
json.put("rsid_list", (Object)rsidList);
String result = this.client.execute("ReportSuite.GetEvents", json.toString(), configuration);
JSONArray array = this.toJSONArray(result);
this.checkResults(rsidList, array);
return result;
}
catch (JSONException e) {
throw new SitecatalystException(e.getMessage(), (Throwable)e);
}
}
@Override
public String queueReport(Configuration configuration, String reportType, JSONObject reportDescription) throws SitecatalystException {
return this.queueReport(configuration, reportDescription);
}
@Override
public String queueReport(Configuration configuration, JSONObject reportDescription) throws SitecatalystException {
try {
JSONObject reportQueue = new JSONObject();
reportQueue.put("reportDescription", (Object)reportDescription);
return this.client.execute("Report.Queue", reportQueue.toString(), configuration);
}
catch (JSONException e) {
throw new SitecatalystException(e.getMessage(), (Throwable)e);
}
}
@Override
public String queuePageViewReport(Configuration configuration, String rsid, String date) throws SitecatalystException {
try {
JSONObject reportDescription = new JSONObject();
reportDescription.put("reportSuiteID", (Object)rsid);
reportDescription.put("date", (Object)date);
reportDescription.put("metrics", (Object)new JSONArray("[{\"id\": \"pageViews\"}]"));
reportDescription.put("elements", (Object)new JSONArray("[{\"id\": \"page\"}]"));
JSONObject reportQueue = new JSONObject();
reportQueue.put("reportDescription", (Object)reportDescription);
return this.client.execute("Report.Queue", reportQueue.toString(), configuration);
}
catch (JSONException e) {
throw new SitecatalystException(e.getMessage(), (Throwable)e);
}
}
@Override
public String getReportStatus(Configuration configuration, String reportID) throws SitecatalystException {
return this.getReport(configuration, reportID);
}
@Override
public String getReport(Configuration configuration, String reportID) throws SitecatalystException {
try {
JSONObject json = new JSONObject();
json.put("reportID", (Object)reportID);
return this.client.execute("Report.Get", json.toString(), configuration);
}
catch (JSONException e) {
throw new SitecatalystException(e.getMessage(), (Throwable)e);
}
}
@Override
public String getSynchronousReport(Configuration configuration, String reportType, JSONObject reportDescription) throws SitecatalystException {
throw new UnsupportedOperationException("This method is no longer supported");
}
@Override
public String getMetrics(Configuration configuration, String rsID) throws SitecatalystException {
try {
JSONObject getMetricsParameters = new JSONObject();
getMetricsParameters.put("reportSuiteID", (Object)rsID);
getMetricsParameters.put("reportType", (Object)"ranked");
return this.client.execute("Report.GetMetrics", getMetricsParameters.toString(), configuration);
}
catch (JSONException e) {
throw new SitecatalystException(e.getMessage(), (Throwable)e);
}
}
@Override
public String getPages(Configuration configuration, Integer limit, String pagename, String rsid, Integer start) throws SitecatalystException {
throw new UnsupportedOperationException("This method is no longer supported");
}
@Override
public JSONArray getClassifications(Configuration configuration, String classificationView, String[] reportSuites, int relationId) throws SitecatalystException {
throw new UnsupportedOperationException("This method is no longer supported");
}
@Override
public boolean saveClassifications(Configuration configuration, String classificationView, boolean campaignView, String name, int parentDivNum, String[] reportSuites, boolean update) throws SitecatalystException {
throw new UnsupportedOperationException("This method is no longer supported");
}
@Override
public boolean deleteClassifications(Configuration configuration, String classificationView, String[] reportSuites, int divNum, int parentDivNum) throws SitecatalystException {
throw new UnsupportedOperationException("This method is no longer supported");
}
private final JSONArray splitToJSONArray(String s) {
JSONArray array = new JSONArray();
for (String piece : s.split(",")) {
array.put((Object)piece);
}
return array;
}
private final void checkResults(JSONArray requestArray, JSONArray resultArray) throws JSONException, SitecatalystException {
int i;
HashSet<String> rsidSet = new HashSet<String>();
for (i = 0; i < resultArray.length(); ++i) {
rsidSet.add(resultArray.getJSONObject(i).getString("rsid"));
}
for (i = 0; i < requestArray.length(); ++i) {
String rsid = requestArray.getString(i);
if (rsidSet.contains(rsid)) continue;
throw new SitecatalystException("Report suite with ID " + rsid + " was not in result");
}
}
protected void bindClient(SitecatalystHttpClient sitecatalystHttpClient) {
this.client = sitecatalystHttpClient;
}
protected void unbindClient(SitecatalystHttpClient sitecatalystHttpClient) {
if (this.client == sitecatalystHttpClient) {
this.client = null;
}
}
}