ContentDeleteActionFactory.java 9.43 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.day.cq.wcm.api.Page
 *  com.day.cq.wcm.api.PageManager
 *  com.day.cq.wcm.api.WCMException
 *  com.day.cq.wcm.msm.api.LiveAction
 *  com.day.cq.wcm.msm.api.LiveRelationship
 *  com.day.cq.wcm.msm.api.LiveRelationshipManager
 *  com.day.cq.wcm.msm.api.LiveStatus
 *  com.day.cq.wcm.msm.api.RolloutManager
 *  com.day.cq.wcm.msm.commons.BaseActionFactory
 *  com.day.cq.wcm.msm.commons.FilteredAction
 *  com.day.cq.wcm.msm.commons.ItemFilterImpl
 *  com.day.cq.wcm.msm.commons.ItemFilterUtil
 *  javax.jcr.Node
 *  javax.jcr.RepositoryException
 *  org.apache.felix.scr.annotations.Activate
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Modified
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.apache.sling.api.resource.ValueMap
 *  org.osgi.service.component.ComponentContext
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.day.cq.wcm.msm.impl.actions;

import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageManager;
import com.day.cq.wcm.api.WCMException;
import com.day.cq.wcm.msm.api.LiveAction;
import com.day.cq.wcm.msm.api.LiveRelationship;
import com.day.cq.wcm.msm.api.LiveRelationshipManager;
import com.day.cq.wcm.msm.api.LiveStatus;
import com.day.cq.wcm.msm.api.RolloutManager;
import com.day.cq.wcm.msm.commons.BaseActionFactory;
import com.day.cq.wcm.msm.commons.FilteredAction;
import com.day.cq.wcm.msm.commons.ItemFilterImpl;
import com.day.cq.wcm.msm.commons.ItemFilterUtil;
import com.day.cq.wcm.msm.impl.Utils;
import java.util.Calendar;
import java.util.Dictionary;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Modified;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(metatype=1, label="%cq.wcm.msm.impl.actions.contentdelete.label", description="%cq.wcm.msm.impl.actions.contentdelete.description")
@Service
public class ContentDeleteActionFactory
extends BaseActionFactory<FilteredAction> {
    @Deprecated
    @Property(name="cq.wcm.msm.action.rank", propertyPrivate=1)
    private static final int RANK = 304;
    @Deprecated
    @Property(name="cq.wcm.msm.action.title", propertyPrivate=1)
    private static final String TITLE = "Delete content";
    @Deprecated
    @Property(name="cq.wcm.msm.action.parameter", propertyPrivate=1)
    private static final String PARAMETER = "msm:actionContentDelete";
    @Deprecated
    @Property(name="actiontype", propertyPrivate=1)
    private static final String ACTION_TYPE = "contentdelete";
    @Property(name="cq.wcm.msm.action.excludednodetypes")
    private static final String[] DEFAULT_FILTER_NODE_TYPES = ItemFilterUtil.EMPTY_PROPERTIES;
    @Property(name="cq.wcm.msm.action.excludedparagraphitems")
    private static final String[] DEFAULT_EXCLUDED_PARAGRAPH_ITEMS = ItemFilterUtil.EMPTY_PROPERTIES;
    @Property(name="cq.wcm.msm.action.excludedprops")
    private static final String[] DEFAULT_EXCLUDED_PROPERTIES = ItemFilterUtil.EMPTY_PROPERTIES;
    @Property(name="liveActionName", propertyPrivate=1)
    private static final String[] LIVE_ACTION_NAME = new String[]{ContentDeleteAction.class.getSimpleName(), "contentDelete"};
    @Reference
    private LiveRelationshipManager liveRelationshipManager = null;
    @Reference
    private RolloutManager rolloutManager = null;
    private Dictionary properties;

    public String createsAction() {
        return LIVE_ACTION_NAME[0];
    }

    protected ContentDeleteAction newActionInstance(ValueMap config) {
        return new ContentDeleteAction(config, this);
    }

    @Activate
    @Modified
    protected void configure(ComponentContext componentContext) {
        this.properties = componentContext.getProperties();
    }

    protected Dictionary getFactoryConfig() {
        return this.properties;
    }

    private LiveRelationshipManager getLiveRelationshipManager() {
        return this.liveRelationshipManager;
    }

    protected void bindLiveRelationshipManager(LiveRelationshipManager liveRelationshipManager) {
        this.liveRelationshipManager = liveRelationshipManager;
    }

    protected void unbindLiveRelationshipManager(LiveRelationshipManager liveRelationshipManager) {
        if (this.liveRelationshipManager == liveRelationshipManager) {
            this.liveRelationshipManager = null;
        }
    }

    protected void bindRolloutManager(RolloutManager rolloutManager) {
        this.rolloutManager = rolloutManager;
    }

    protected void unbindRolloutManager(RolloutManager rolloutManager) {
        if (this.rolloutManager == rolloutManager) {
            this.rolloutManager = null;
        }
    }

    private static final class ContentDeleteAction
    extends FilteredAction {
        private static final Logger log = LoggerFactory.getLogger(ContentDeleteAction.class);
        private final LiveRelationshipManager relationshipMgr;
        private final boolean skipCancelled;
        public static final String SKIP_CANCELLED_LC_PARAM = "skipCancelledLiveCopy";

        protected ContentDeleteAction(ValueMap config, ContentDeleteActionFactory actionFactory) {
            super(config, ItemFilterUtil.createPageFilter((ValueMap)config, (RolloutManager)actionFactory.rolloutManager), ItemFilterUtil.createComponentFilter((ValueMap)config, (RolloutManager)actionFactory.rolloutManager), (BaseActionFactory)actionFactory);
            this.relationshipMgr = actionFactory.getLiveRelationshipManager();
            this.skipCancelled = config != null && "true".equalsIgnoreCase((String)config.get("skipCancelledLiveCopy", String.class));
        }

        protected boolean doHandle(Resource source, Resource target, LiveRelationship relation, boolean resetRollout) throws RepositoryException, WCMException {
            Node slaveNode;
            if (relation.getStatus().isSourceExisting()) {
                log.debug("Call to delete on existing source at {}: nothing to do for", (Object)relation.getSourcePath(), (Object)relation.getTargetPath());
                return false;
            }
            Node node = slaveNode = target != null ? (Node)target.adaptTo(Node.class) : null;
            if (slaveNode == null) {
                log.debug("Call to delete on non existing Node at {}", (Object)relation.getTargetPath());
                return false;
            }
            return true;
        }

        protected void doExecute(Resource source, Resource target, LiveRelationship relation, boolean resetRollout) throws RepositoryException, WCMException {
            Page page;
            Node slaveNode = Utils.getHierarchyNode((Node)target.adaptTo(Node.class));
            if (slaveNode == null) {
                log.error("Target Node at {} is null, though checked on call to handles", (Object)relation.getTargetPath());
                return;
            }
            ResourceResolver resolver = target.getResourceResolver();
            if (!slaveNode.getPath().equals(target.getPath())) {
                target = resolver.getResource(slaveNode.getPath());
            }
            if (this.skipCancelled && this.hasLCCancelledChildren(relation) && !resetRollout) {
                log.debug("Resource {} LC is cancelled and skipCancelled=true for the ContentDeleteAction, skipping the resource!", (Object)target.getPath());
                return;
            }
            if (relation.getStatus().isPage() && (page = (Page)target.adaptTo(Page.class)) != null) {
                if (this.relationshipMgr != null) {
                    this.relationshipMgr.endRelationship(target, false);
                }
                page.getPageManager().delete(page, false);
                log.debug("Deleted Page for {} at {}", (Object)relation.getSourcePath(), (Object)relation.getTargetPath());
            } else {
                Page containingPage;
                String strSlaveNodePath = slaveNode.getPath();
                slaveNode.remove();
                PageManager pm = (PageManager)resolver.adaptTo(PageManager.class);
                Page page2 = containingPage = pm == null ? null : pm.getContainingPage(relation.getTargetPath());
                if (containingPage != null && !strSlaveNodePath.equals(containingPage.getPath())) {
                    containingPage.getPageManager().touch((Node)containingPage.adaptTo(Node.class), true, Calendar.getInstance(), false);
                }
                log.debug("Deleted Resource for {} at {}", (Object)relation.getSourcePath(), (Object)relation.getTargetPath());
            }
        }

        private boolean hasLCCancelledChildren(LiveRelationship relation) throws WCMException {
            Boolean hasCancelledChild = relation.getStatus().getAdvancedStatus("msm:isTargetCancelledChild");
            if (hasCancelledChild == null) {
                hasCancelledChild = false;
            }
            return relation.getStatus().isCancelled() || hasCancelledChild != false;
        }
    }

}