ClassificationsCompatibilityServlet.java
5.21 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.webservicesupport.Configuration
* javax.servlet.ServletException
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.SlingHttpServletResponse
* 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.day.cq.analytics.sitecatalyst.impl.servlets;
import com.day.cq.analytics.sitecatalyst.ClassificationsService;
import com.day.cq.analytics.sitecatalyst.SitecatalystException;
import com.day.cq.analytics.sitecatalyst.impl.servlets.AbstractOptionsServlet;
import com.day.cq.wcm.webservicesupport.Configuration;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
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;
@Component(metatype=0)
@Service
@Properties(value={@Property(name="sling.servlet.extensions", value={"json"}), @Property(name="sling.servlet.selectors", value={"compatibilityoptions"}), @Property(name="sling.servlet.resourceTypes", value={"cq/analytics/components/saintclassificationpage"}), @Property(name="sling.servlet.methods", value={"GET"})})
public class ClassificationsCompatibilityServlet
extends AbstractOptionsServlet {
private final Logger log;
private static final String PARAM_REPORTSUITES = "reportSuites";
@Reference
private ClassificationsService classificationsService;
public ClassificationsCompatibilityServlet() {
this.log = LoggerFactory.getLogger(this.getClass());
}
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
JSONObject options = new JSONObject();
JSONArray elements = new JSONArray();
try {
Configuration configuration = this.getConfiguration(request, "sitecatalyst");
String[] reportSuites = this.getReportSuites(request, configuration);
options.put("elements", (Object)elements);
if (configuration != null && reportSuites != null) {
elements = this.classificationsService.getCompatibilityElements(configuration, reportSuites);
options.put("elements", (Object)this.getElements(elements, reportSuites[0]));
}
out.write(options.toString());
}
catch (SitecatalystException e) {
this.log.error("Unable to get compatibility elements", (Throwable)e);
try {
options.put("elements", (Object)elements);
}
catch (JSONException reportSuites) {
// empty catch block
}
out.write(options.toString());
}
catch (Exception e) {
this.log.error("Exception occured while building compatability metrics", (Throwable)e);
throw new ServletException("Exception occured while building compatability metrics", (Throwable)e);
}
finally {
out.flush();
}
}
private JSONArray getElements(JSONArray result, String rsid) throws JSONException {
JSONArray elements = new JSONArray();
for (int i = 0; i < result.length(); ++i) {
JSONObject compatibility = result.getJSONObject(i);
if (!rsid.equals(compatibility.getString("rsid"))) continue;
elements = compatibility.getJSONArray("compatibility_elements");
return elements;
}
return elements;
}
private String[] getReportSuites(SlingHttpServletRequest request, Configuration configuration) {
String rsids;
String[] reportSuites = request.getParameterValues("reportSuites");
if (configuration != null && reportSuites == null && (rsids = (String)configuration.getInherited("reportsuite", (Object)"")).length() > 0) {
reportSuites = rsids.split(",");
}
return reportSuites;
}
protected void bindClassificationsService(ClassificationsService classificationsService) {
this.classificationsService = classificationsService;
}
protected void unbindClassificationsService(ClassificationsService classificationsService) {
if (this.classificationsService == classificationsService) {
this.classificationsService = null;
}
}
}