LaunchesCommand.java
4.18 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.cq.launches.api.LaunchException
* com.adobe.cq.launches.api.LaunchManagerFactory
* com.day.cq.wcm.api.commands.WCMCommand
* 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.joda.time.DateTime
* org.joda.time.format.DateTimeFormatter
* org.joda.time.format.ISODateTimeFormat
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.wcm.launches.impl.commands;
import com.adobe.cq.launches.api.LaunchException;
import com.adobe.cq.launches.api.LaunchManagerFactory;
import com.day.cq.wcm.api.commands.WCMCommand;
import java.util.Calendar;
import java.util.Locale;
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.joda.time.DateTime;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(componentAbstract=1)
@Service
public abstract class LaunchesCommand
implements WCMCommand {
private static final Logger log = LoggerFactory.getLogger(LaunchesCommand.class);
@Reference
LaunchManagerFactory launchesManagerFactory = null;
protected static DateTimeFormatter TIME_FORMAT = ISODateTimeFormat.dateTime();
protected static final String LIVE_DATE_PARAM = "liveDate";
protected static final String IS_LIVE_COPY_PARAM = "isLiveCopy";
protected static final String SOURCE_ROLLOUT_CONFIGS_PARAM = "sourceRolloutConfigs";
protected static final String PROMOTE_ROLLOUT_CONFIGS_PARAM = "promoteRolloutConfigs";
protected static final String TEMPLATE_PARAM = "template";
protected final String getStringParam(SlingHttpServletRequest request, String name, String description, boolean isMandatory, String defaultValue) throws LaunchException {
String valueAsString = request.getParameter(name);
if (StringUtils.isNotEmpty((String)valueAsString)) {
return valueAsString;
}
if (isMandatory) {
throw new LaunchException("Error during operation. Mandatory parameter is missing: " + description);
}
return defaultValue;
}
protected final Calendar getCalendarParam(SlingHttpServletRequest request, String name, String description, boolean isMandatory, Calendar defaultValue) throws LaunchException {
String valueAsString = request.getParameter(name);
if (StringUtils.isNotEmpty((String)valueAsString)) {
try {
return TIME_FORMAT.parseDateTime(valueAsString).toCalendar(request.getLocale());
}
catch (IllegalArgumentException e) {
throw new LaunchException("Error during operation. Unable to parse " + description + ": " + valueAsString);
}
}
if (isMandatory) {
throw new LaunchException("Error during operation. Mandatory parameter is missing: " + description);
}
return defaultValue;
}
protected final boolean getBooleanParam(SlingHttpServletRequest request, String name, String description, boolean isMandatory, boolean defaultValue) throws LaunchException {
String valueAsString = request.getParameter(name);
if (StringUtils.isNotEmpty((String)valueAsString)) {
return "true".equals(valueAsString);
}
if (isMandatory) {
throw new LaunchException("Error during operation. Mandatory parameter is missing: " + description);
}
return defaultValue;
}
protected void bindLaunchesManagerFactory(LaunchManagerFactory launchManagerFactory) {
this.launchesManagerFactory = launchManagerFactory;
}
protected void unbindLaunchesManagerFactory(LaunchManagerFactory launchManagerFactory) {
if (this.launchesManagerFactory == launchManagerFactory) {
this.launchesManagerFactory = null;
}
}
}