RequestLaunchPromotionParameters.java 3.79 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.adobe.cq.launches.api.LaunchPromotionScope
 *  org.apache.commons.lang.StringUtils
 *  org.apache.sling.api.SlingHttpServletRequest
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 */
package com.adobe.cq.wcm.launches.impl;

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.launches.api.LaunchPromotionScope;
import com.adobe.cq.wcm.launches.impl.AbstractLaunchPromotionParameters;
import com.adobe.cq.wcm.launches.utils.LaunchUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;

public class RequestLaunchPromotionParameters
extends AbstractLaunchPromotionParameters {
    private String workflowPackagePath;

    public RequestLaunchPromotionParameters(SlingHttpServletRequest request) throws LaunchException {
        String targetPath;
        String path = request.getParameter("path");
        if (StringUtils.isEmpty((String)path)) {
            throw new LaunchException("Master path needs to be specified.");
        }
        this.resource = request.getResourceResolver().getResource(path);
        if (this.resource == null) {
            throw new LaunchException("Master path does not resolve to a resource.");
        }
        LaunchManager launchManager = (LaunchManager)request.getResourceResolver().adaptTo(LaunchManager.class);
        this.launch = launchManager.getLaunch(LaunchUtils.getLaunchResource(this.resource).getPath());
        String promotionScopeString = request.getParameter("promotionScope");
        if (StringUtils.isEmpty((String)promotionScopeString)) {
            throw new LaunchException("Incomplete request: Launch promotion scope not specified.");
        }
        try {
            this.promotionScope = LaunchPromotionScope.valueOf((String)promotionScopeString.toUpperCase());
        }
        catch (IllegalArgumentException e) {
            throw new LaunchException("Unrecognized launch promotion scope: " + promotionScopeString);
        }
        if (this.promotionScope.equals((Object)LaunchPromotionScope.RESOURCE) && "true".equals(request.getParameter("includeSubPages"))) {
            this.promotionScope = LaunchPromotionScope.DEEP;
        }
        if ((targetPath = request.getParameter("target")) != null) {
            Resource launchResource = request.getResourceResolver().getResource(targetPath);
            if (launchResource == null) {
                throw new LaunchException("Invalid path: " + targetPath);
            }
            this.target = (Launch)launchResource.adaptTo(Launch.class);
            if (this.target == null) {
                throw new LaunchException("Specified target path is not a launch: " + targetPath);
            }
        }
        this.workflowPackagePath = request.getParameter("workflowPackage");
    }

    public String getResourceCollectionPath() {
        return this.workflowPackagePath;
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("LaunchPromotionParameters => {\n");
        sb.append("\tresource: ").append(this.getResource().getPath()).append("\n");
        sb.append("\tpromotionScope: ").append(this.getPromotionScope().getValue()).append("\n");
        sb.append("\tworkflowPackagePath: ").append(this.getResourceCollectionPath()).append("\n");
        sb.append("\tisDeep: ").append(this.isDeep()).append("\n");
        sb.append("}\n");
        return sb.toString();
    }
}