ProfileAttributesServlet.java
4.5 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.webservicesupport.Configuration
* com.day.cq.wcm.webservicesupport.ConfigurationManager
* com.day.cq.wcm.webservicesupport.ConfigurationManagerFactory
* com.google.gson.Gson
* javax.servlet.ServletException
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.sling.SlingServlet
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.SlingHttpServletResponse
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.servlets.SlingSafeMethodsServlet
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.analytics.testandtarget.impl.servlets;
import com.day.cq.analytics.testandtarget.impl.TestandtargetPrivateService;
import com.day.cq.analytics.testandtarget.impl.model.TntProfileAttribute;
import com.day.cq.wcm.webservicesupport.Configuration;
import com.day.cq.wcm.webservicesupport.ConfigurationManager;
import com.day.cq.wcm.webservicesupport.ConfigurationManagerFactory;
import com.google.gson.Gson;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.servlet.ServletException;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.sling.SlingServlet;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SlingServlet(generateComponent=1, methods={"GET"}, extensions={"json"}, selectors={"profileattributes"}, resourceTypes={"cq/analytics/components/testandtargetpage", "cq/analytics/components/cbframework"}, label="Adobe Target Integration Profile Attributes List Servlet", description="Provides the TnT provile attributes in JSON format")
public class ProfileAttributesServlet
extends SlingSafeMethodsServlet {
private final Logger LOG;
@Reference
private ConfigurationManagerFactory cfgManagerFactory;
@Reference
private TestandtargetPrivateService tntService;
public ProfileAttributesServlet() {
this.LOG = LoggerFactory.getLogger(this.getClass());
}
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
Resource tntConfigResource = request.getResource();
if (tntConfigResource != null) {
ConfigurationManager cfgManager = this.cfgManagerFactory.getConfigurationManager(tntConfigResource.getResourceResolver());
Configuration tntConfig = cfgManager.getConfiguration(tntConfigResource.getParent().getPath());
if (tntConfig != null) {
try {
ArrayList<TntProfileAttribute> allAtrributes = new ArrayList<TntProfileAttribute>();
allAtrributes.addAll(this.tntService.getProfileAttributes(tntConfig));
allAtrributes.addAll(this.tntService.getCustomProfileAttributes(tntConfig));
response.setContentType("application/json");
response.setStatus(200);
response.getWriter().write(new Gson().toJson(allAtrributes));
}
catch (Exception e) {
response.setStatus(500);
this.LOG.error("Error getting the TnT profile attributes!", (Throwable)e);
}
} else {
this.LOG.warn("No Test and Target cloud configuration at path " + tntConfigResource.getPath());
}
}
}
protected void bindCfgManagerFactory(ConfigurationManagerFactory configurationManagerFactory) {
this.cfgManagerFactory = configurationManagerFactory;
}
protected void unbindCfgManagerFactory(ConfigurationManagerFactory configurationManagerFactory) {
if (this.cfgManagerFactory == configurationManagerFactory) {
this.cfgManagerFactory = null;
}
}
protected void bindTntService(TestandtargetPrivateService testandtargetPrivateService) {
this.tntService = testandtargetPrivateService;
}
protected void unbindTntService(TestandtargetPrivateService testandtargetPrivateService) {
if (this.tntService == testandtargetPrivateService) {
this.tntService = null;
}
}
}