CloneLaunchCommand.java 4.48 KB
/*
 * 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());
        }
    }
}