EntityUnlinkOperation.java 3.71 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.granite.ui.components.HtmlResponse
 *  com.day.cq.i18n.I18n
 *  javax.servlet.http.HttpServletRequest
 *  org.apache.commons.lang.StringUtils
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Properties
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.api.SlingHttpServletRequest
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.servlets.post.Modification
 *  org.slf4j.Logger
 */
package com.adobe.cq.mobile.dps.impl.operations;

import com.adobe.cq.mobile.dps.DPSException;
import com.adobe.cq.mobile.dps.DPSObject;
import com.adobe.cq.mobile.dps.DPSProject;
import com.adobe.cq.mobile.dps.impl.DPSPageManager;
import com.adobe.cq.mobile.dps.impl.operations.MobilePublishAbstractOperation;
import com.adobe.granite.ui.components.HtmlResponse;
import com.day.cq.i18n.I18n;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.servlets.post.Modification;
import org.slf4j.Logger;

@Component(metatype=0, label="Experience Manager Mobile Unlink")
@Service
@Properties(value={@Property(name="sling.post.operation", value={"dpsapps:unlink"}), @Property(name="sling.servlet.methods", value={"POST"})})
public class EntityUnlinkOperation
extends MobilePublishAbstractOperation {
    @Override
    protected void perform(SlingHttpServletRequest request, HtmlResponse response, List<Modification> modifications) {
        I18n i18n = new I18n((HttpServletRequest)request);
        Resource resource = request.getResource();
        try {
            DPSObject dpsObject = this.getDPSObject(request);
            if (dpsObject == null) {
                String message = i18n.get("Invalid dps resource {0}", "resource path", new Object[]{resource.getPath()});
                throw new DPSException(message);
            }
            DPSPageManager dpsPageManager = this.getDPSPageManager(request);
            dpsPageManager.unlink(dpsObject);
            String responseTitle = i18n.get("Experience Manager Mobile Item unlinked");
            String responseMessage = i18n.get("{0} has been unlinked.", "entity path", new Object[]{dpsObject.getPath()});
            if (dpsObject instanceof DPSProject) {
                responseTitle = i18n.get("Experience Manager Mobile Items unlinked");
                responseMessage = i18n.get("All content for {0} has been unlinked.", "project path", new Object[]{dpsObject.getPath()});
            }
            response.setPath(resource.getPath());
            this.generateResponse(response, 200, responseMessage, responseTitle, request.getPathInfo(), "");
        }
        catch (Exception ex) {
            String cause = this.getCauseMessage(ex);
            if (StringUtils.isEmpty((String)cause)) {
                cause = ex.getLocalizedMessage();
            }
            if (StringUtils.isEmpty((String)cause)) {
                cause = ex.getClass().getName();
            }
            String resourceName = resource == null ? "" : resource.getName();
            String message = i18n.get("Error unlinking {0}.", "entity name", new Object[]{resourceName, cause});
            this.getLogger().error(message, (Throwable)ex);
            String errorTitle = i18n.get("Error");
            this.generateError(response, message, errorTitle, ex);
        }
    }
}