UpdateAccountOptionsCommand.java
5.14 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
/*
* 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.JsonObject
* javax.servlet.ServletException
* org.apache.commons.lang.StringUtils
* org.apache.felix.scr.annotations.Component
* 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.api.resource.ResourceResolver
* org.apache.sling.api.servlets.HtmlResponse
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.analytics.testandtarget.impl.servlets.commands;
import com.day.cq.analytics.testandtarget.TestandtargetCommand;
import com.day.cq.analytics.testandtarget.TestandtargetException;
import com.day.cq.analytics.testandtarget.impl.TestandtargetPrivateService;
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.JsonObject;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import org.apache.commons.lang.StringUtils;
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.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.servlets.HtmlResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
@Service
public class UpdateAccountOptionsCommand
implements TestandtargetCommand {
private static final Logger LOG = LoggerFactory.getLogger(UpdateAccountOptionsCommand.class);
@Reference
private TestandtargetPrivateService testandtargetService;
@Reference
private ConfigurationManagerFactory cfgManagerFactory;
@Override
public String getName() {
return "updateAccountOptions";
}
@Override
public HtmlResponse performCommand(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
String configPath = request.getParameter("configPath");
if (StringUtils.isEmpty((String)"configPath")) {
this.sendError(response, "The required parameter <configPath> is missing from the request", 400);
return null;
}
Configuration configuration = this.cfgManagerFactory.getConfigurationManager(request.getResourceResolver()).getConfiguration(configPath);
if (configuration == null) {
this.sendError(response, "No Adobe Target cloud service configuration found at path " + configPath + ".", 500);
return null;
}
try {
this.testandtargetService.updateAccountOptions(configuration);
this.sendOk(response);
}
catch (TestandtargetException e) {
LOG.error(e.getMessage(), (Throwable)e);
this.sendError(response, "Error occured while updating the account options. Please see server log for details.", 500);
}
return null;
}
private void sendError(SlingHttpServletResponse response, String msg, int status) {
response.setContentType("application/json");
response.setStatus(status);
JsonObject responseJson = new JsonObject();
responseJson.addProperty("status", "error");
responseJson.addProperty("message", msg);
try {
PrintWriter out = response.getWriter();
out.print(responseJson.toString());
}
catch (IOException e) {
LOG.error(e.getMessage(), (Throwable)e);
}
}
private void sendOk(SlingHttpServletResponse response) {
response.setContentType("application/json");
response.setStatus(200);
JsonObject responseJson = new JsonObject();
responseJson.addProperty("status", "success");
try {
PrintWriter out = response.getWriter();
out.print(responseJson.toString());
}
catch (IOException e) {
LOG.error(e.getMessage(), (Throwable)e);
}
}
protected void bindTestandtargetService(TestandtargetPrivateService testandtargetPrivateService) {
this.testandtargetService = testandtargetPrivateService;
}
protected void unbindTestandtargetService(TestandtargetPrivateService testandtargetPrivateService) {
if (this.testandtargetService == testandtargetPrivateService) {
this.testandtargetService = null;
}
}
protected void bindCfgManagerFactory(ConfigurationManagerFactory configurationManagerFactory) {
this.cfgManagerFactory = configurationManagerFactory;
}
protected void unbindCfgManagerFactory(ConfigurationManagerFactory configurationManagerFactory) {
if (this.cfgManagerFactory == configurationManagerFactory) {
this.cfgManagerFactory = null;
}
}
}