DeleteCampaignCommand.java
5.64 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.i18n.I18n
* com.day.cq.wcm.webservicesupport.Configuration
* com.day.cq.wcm.webservicesupport.ConfigurationManager
* com.day.cq.wcm.webservicesupport.ConfigurationManagerFactory
* javax.servlet.ServletException
* javax.servlet.http.HttpServletRequest
* 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.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.io.JSONWriter
* 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.TestandtargetProxyService;
import com.day.cq.i18n.I18n;
import com.day.cq.wcm.webservicesupport.Configuration;
import com.day.cq.wcm.webservicesupport.ConfigurationManager;
import com.day.cq.wcm.webservicesupport.ConfigurationManagerFactory;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
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.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.io.JSONWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
@Service
public class DeleteCampaignCommand
implements TestandtargetCommand {
private static final Logger log = LoggerFactory.getLogger(DeleteCampaignCommand.class);
private static final String PARAM_CFG = "cfgPath";
private static final String PARAM_CAMPAIGN_ID = "campaignID";
@Reference
private ConfigurationManagerFactory configurationManagerFactory;
@Reference
private TestandtargetProxyService service;
@Override
public String getName() {
return "deleteCampaign";
}
@Override
public HtmlResponse performCommand(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
JSONWriter out = new JSONWriter((Writer)response.getWriter());
String configPath = request.getParameter("cfgPath");
String campID = request.getParameter("campaignID");
try {
try {
if (StringUtils.isEmpty((String)campID) || Long.parseLong(campID) <= 0) {
out.object();
out.key("error").value((Object)"Invalid arguments");
out.endObject();
return null;
}
}
catch (NumberFormatException e) {
out.object();
out.key("error").value((Object)"Invalid arguments");
out.endObject();
return null;
}
Configuration config = null;
if (configPath != null) {
config = this.configurationManagerFactory.getConfigurationManager(request.getResourceResolver()).getConfiguration(configPath);
}
if (config == null) {
out.object();
String msg = I18n.get((HttpServletRequest)request, (String)"Configuration '{0}' not found", (String)configPath);
out.key("error").value((Object)msg);
out.endObject();
return null;
}
try {
this.service.deleteCampaign(config, Long.parseLong(campID));
out.object();
out.key("status").value(true);
out.endObject();
}
catch (TestandtargetException e) {
out.object();
out.key("status").value(false);
out.endObject();
}
}
catch (Exception e) {
log.error(e.getMessage(), (Throwable)e);
try {
out.object();
out.key("error").value((Object)e.getMessage());
out.endObject();
}
catch (JSONException je) {
log.error(je.getMessage(), (Throwable)je);
}
}
return null;
}
protected void bindConfigurationManagerFactory(ConfigurationManagerFactory configurationManagerFactory) {
this.configurationManagerFactory = configurationManagerFactory;
}
protected void unbindConfigurationManagerFactory(ConfigurationManagerFactory configurationManagerFactory) {
if (this.configurationManagerFactory == configurationManagerFactory) {
this.configurationManagerFactory = null;
}
}
protected void bindService(TestandtargetProxyService testandtargetProxyService) {
this.service = testandtargetProxyService;
}
protected void unbindService(TestandtargetProxyService testandtargetProxyService) {
if (this.service == testandtargetProxyService) {
this.service = null;
}
}
}