CloneLaunchCommand.java
4.48 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.cq.launches.api.Launch
* com.adobe.cq.launches.api.LaunchException
* com.adobe.cq.launches.api.LaunchManager
* com.day.cq.commons.servlets.HtmlStatusResponseHelper
* com.day.cq.i18n.I18n
* com.day.cq.wcm.api.PageManager
* com.day.cq.wcm.api.commands.WCMCommandContext
* javax.servlet.http.HttpServletRequest
* org.apache.commons.lang.StringUtils
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Service
* 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.HtmlResponse
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.wcm.launches.impl.commands;
import com.adobe.cq.launches.api.Launch;
import com.adobe.cq.launches.api.LaunchException;
import com.adobe.cq.launches.api.LaunchManager;
import com.adobe.cq.wcm.launches.impl.commands.LaunchesCommand;
import com.day.cq.commons.servlets.HtmlStatusResponseHelper;
import com.day.cq.i18n.I18n;
import com.day.cq.wcm.api.PageManager;
import com.day.cq.wcm.api.commands.WCMCommandContext;
import java.util.Calendar;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
import org.apache.felix.scr.annotations.Component;
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.Resource;
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 CloneLaunchCommand
extends LaunchesCommand {
private final Logger log = LoggerFactory.getLogger(CloneLaunchCommand.class);
public String getCommandName() {
return "cloneLaunch";
}
public HtmlResponse performCommand(WCMCommandContext ctx, SlingHttpServletRequest request, SlingHttpServletResponse response, PageManager pageManager) {
String path = null;
try {
Calendar liveDate;
String title;
boolean isLiveCopy;
path = request.getParameter("path");
if (StringUtils.isEmpty((String)path)) {
return HtmlStatusResponseHelper.createStatusResponse((boolean)false, (String)"Incomplete request: Path of launch to clone was not specified.");
}
LaunchManager launchManager = (LaunchManager)request.getResourceResolver().adaptTo(LaunchManager.class);
Launch launch = launchManager.getLaunch(path);
if (launch == null) {
return HtmlStatusResponseHelper.createStatusResponse((boolean)false, (String)("Error during operation. Provided path is not a launch: " + path));
}
String defaultTitle = I18n.get((HttpServletRequest)request, (String)"Clone of {0}", (String)"Default title to use when cloning a launch", (Object[])new Object[]{launch.getTitle()});
try {
title = this.getStringParam(request, "title", "Clone title", false, defaultTitle);
}
catch (LaunchException e) {
return HtmlStatusResponseHelper.createStatusResponse((boolean)false, (String)e.getMessage());
}
try {
liveDate = this.getCalendarParam(request, "liveDate", "Target live date", false, null);
}
catch (LaunchException e) {
return HtmlStatusResponseHelper.createStatusResponse((boolean)false, (String)e.getMessage());
}
try {
isLiveCopy = this.getBooleanParam(request, "isLiveCopy", "Live copy", false, launch.isLiveCopy());
}
catch (LaunchException e) {
return HtmlStatusResponseHelper.createStatusResponse((boolean)false, (String)e.getMessage());
}
Launch clone = launchManager.cloneLaunch(launch, title, liveDate, isLiveCopy);
return HtmlStatusResponseHelper.createStatusResponse((boolean)true, (String)("Launch cloned: " + clone.getResource().getPath()));
}
catch (Exception e) {
this.log.error("Error during deletion of launch: {}.", (Object)path, (Object)e);
return HtmlStatusResponseHelper.createStatusResponse((boolean)false, (String)e.getMessage());
}
}
}