PromoteLaunchCommand.java 3.58 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.cq.launches.api.Launch
 *  com.adobe.cq.launches.api.LaunchManager
 *  com.adobe.cq.launches.api.LaunchManagerFactory
 *  com.adobe.cq.launches.api.LaunchPromotionParameters
 *  com.day.cq.commons.servlets.HtmlStatusResponseHelper
 *  com.day.cq.wcm.api.PageManager
 *  com.day.cq.wcm.api.commands.WCMCommandContext
 *  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.LaunchManager;
import com.adobe.cq.launches.api.LaunchManagerFactory;
import com.adobe.cq.launches.api.LaunchPromotionParameters;
import com.adobe.cq.wcm.launches.impl.RequestLaunchPromotionParameters;
import com.adobe.cq.wcm.launches.impl.commands.LaunchesCommand;
import com.adobe.cq.wcm.launches.utils.LaunchUtils;
import com.day.cq.commons.servlets.HtmlStatusResponseHelper;
import com.day.cq.wcm.api.PageManager;
import com.day.cq.wcm.api.commands.WCMCommandContext;
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 PromoteLaunchCommand
extends LaunchesCommand {
    private final Logger log = LoggerFactory.getLogger(PromoteLaunchCommand.class);
    public static final String PROMOTION_SCOPE_PARAM = "promotionScope";
    public static final String TARGET_PARAM = "target";
    public static final String INCLUDE_SUB_PAGES_PARAM = "includeSubPages";
    public static final String WORKFLOW_PACKAGE_PARAM = "workflowPackage";

    public String getCommandName() {
        return "promoteLaunch";
    }

    public HtmlResponse performCommand(WCMCommandContext ctx, SlingHttpServletRequest request, SlingHttpServletResponse response, PageManager pageManager) {
        try {
            RequestLaunchPromotionParameters params = new RequestLaunchPromotionParameters(request);
            Resource resource = params.getResource();
            LaunchManager launchManager = this.launchesManagerFactory.getLaunchManager(request.getResourceResolver());
            Resource lRes = LaunchUtils.getLaunchResource(resource);
            if (lRes == null) {
                return HtmlStatusResponseHelper.createStatusResponse((boolean)false, (String)("Error during operation. Provided path is not part of a launch: " + resource.getPath()));
            }
            Launch l = (Launch)lRes.adaptTo(Launch.class);
            launchManager.promoteLaunch(l, (LaunchPromotionParameters)params);
            return HtmlStatusResponseHelper.createStatusResponse((boolean)true, (String)"Launch promoted", (String)LaunchUtils.getTargetResource(params.getResource(), params.getTarget()).getPath());
        }
        catch (Exception e) {
            String msg = "Error while promoting launch";
            this.log.error(msg, (Throwable)e);
            return HtmlStatusResponseHelper.createStatusResponse((boolean)false, (String)msg);
        }
    }
}