LiveRelationshipManagerBridge.java 12.7 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.day.cq.wcm.api.Page
 *  com.day.cq.wcm.api.WCMException
 *  com.day.cq.wcm.api.msm.LiveCopy
 *  com.day.cq.wcm.api.msm.LiveRelationship
 *  com.day.cq.wcm.api.msm.LiveRelationshipManager
 *  com.day.cq.wcm.api.msm.LiveStatus
 *  com.day.cq.wcm.api.msm.RolloutManager
 *  com.day.cq.wcm.api.msm.RolloutManager$Trigger
 *  com.day.cq.wcm.msm.api.Blueprint
 *  com.day.cq.wcm.msm.api.BlueprintManager
 *  com.day.cq.wcm.msm.api.BlueprintManagerFactory
 *  com.day.cq.wcm.msm.api.LiveCopy
 *  com.day.cq.wcm.msm.api.LiveRelationship
 *  com.day.cq.wcm.msm.api.LiveRelationshipManager
 *  com.day.cq.wcm.msm.api.RolloutConfig
 *  com.day.cq.wcm.msm.api.RolloutManager
 *  com.day.cq.wcm.msm.api.RolloutManager$Trigger
 *  com.day.text.Text
 *  org.apache.felix.scr.annotations.Component
 *  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.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.day.cq.wcm.msm.impl.compat;

import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.WCMException;
import com.day.cq.wcm.api.msm.LiveRelationship;
import com.day.cq.wcm.api.msm.LiveRelationshipManager;
import com.day.cq.wcm.api.msm.LiveStatus;
import com.day.cq.wcm.api.msm.RolloutManager;
import com.day.cq.wcm.msm.api.Blueprint;
import com.day.cq.wcm.msm.api.BlueprintManager;
import com.day.cq.wcm.msm.api.BlueprintManagerFactory;
import com.day.cq.wcm.msm.api.LiveCopy;
import com.day.cq.wcm.msm.api.RolloutConfig;
import com.day.cq.wcm.msm.api.RolloutManager;
import com.day.cq.wcm.msm.impl.compat.LiveCopyAdaptor;
import com.day.cq.wcm.msm.impl.compat.LiveRelationshipAdaptor;
import com.day.text.Text;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.felix.scr.annotations.Component;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component
@Service
public class LiveRelationshipManagerBridge
implements LiveRelationshipManager {
    @Reference
    private com.day.cq.wcm.msm.api.LiveRelationshipManager liveRelationMgr = null;
    @Reference
    private BlueprintManagerFactory blueprintManagerFactory;
    private final Logger log = LoggerFactory.getLogger(LiveRelationshipManagerBridge.class);

    public boolean isLiveCopy(Resource target) {
        return this.liveRelationMgr.isLiveCopy(target);
    }

    public Map<String, com.day.cq.wcm.api.msm.LiveCopy> getLiveCopies() {
        HashMap<String, com.day.cq.wcm.api.msm.LiveCopy> ret = new HashMap<String, com.day.cq.wcm.api.msm.LiveCopy>();
        try {
            for (Map.Entry entry : this.liveRelationMgr.getLiveCopies().entrySet()) {
                ret.put((String)entry.getKey(), new LiveCopyAdaptor((LiveCopy)entry.getValue()));
            }
        }
        catch (WCMException e) {
            this.log.error("Failed to access LiveCopies: {}", (Throwable)e);
        }
        return ret;
    }

    public void reenablePropertyRelationship(ResourceResolver resolver, LiveRelationship relation, String[] names, boolean autoSave) throws WCMException {
        com.day.cq.wcm.msm.api.LiveRelationship adapted = this.adapt(relation, resolver);
        if (adapted != null) {
            this.liveRelationMgr.reenablePropertyRelationship(resolver, adapted, names, autoSave);
        } else {
            this.log.debug("Didn't find relation from {} to {}, no execution of reenablePropertyRelation", (Object)relation.getSourcePath(), (Object)relation.getTargetPath());
        }
    }

    public void cancelPropertyRelationship(ResourceResolver resolver, LiveRelationship relation, String[] names, boolean autoSave) throws WCMException {
        com.day.cq.wcm.msm.api.LiveRelationship adapted = this.adapt(relation, resolver);
        if (adapted != null) {
            this.liveRelationMgr.cancelPropertyRelationship(resolver, adapted, names, autoSave);
        } else {
            this.log.debug("Didn't find relation from {} to {}, no execution of cancelPropertyRelation", (Object)relation.getSourcePath(), (Object)relation.getTargetPath());
        }
    }

    public Collection<LiveRelationship> getLiveRelationships(Page source, RolloutManager.Trigger trigger, String[] targets, boolean advancedStatus) throws WCMException {
        HashSet<LiveRelationship> ret = new HashSet<LiveRelationship>();
        RolloutManager.Trigger adaptedTrigger = trigger == null ? null : RolloutManager.Trigger.fromName((String)trigger.name());
        ResourceResolver resolver = ((Resource)source.adaptTo(Resource.class)).getResourceResolver();
        for (com.day.cq.wcm.msm.api.LiveRelationship rel : this.liveRelationMgr.getLiveRelationships(source, adaptedTrigger, targets, advancedStatus)) {
            List<RolloutConfig> blueprintActions = this.getBlueprintRolloutConfig(rel.getLiveCopy().getBlueprintPath(), resolver);
            ret.add(new LiveRelationshipAdaptor(rel, blueprintActions));
        }
        return ret;
    }

    public Collection<LiveRelationship> getLiveRelationships(Resource source, RolloutManager.Trigger trigger, String[] targets, boolean advancedStatus) throws WCMException {
        HashSet<LiveRelationship> ret = new HashSet<LiveRelationship>();
        RolloutManager.Trigger adaptedTrigger = trigger == null ? null : RolloutManager.Trigger.fromName((String)trigger.name());
        for (com.day.cq.wcm.msm.api.LiveRelationship rel : this.liveRelationMgr.getLiveRelationships(source, adaptedTrigger, targets, advancedStatus)) {
            List<RolloutConfig> blueprintActions = this.getBlueprintRolloutConfig(rel.getLiveCopy().getBlueprintPath(), source.getResourceResolver());
            ret.add(new LiveRelationshipAdaptor(rel, blueprintActions));
        }
        return ret;
    }

    public LiveRelationship getLiveRelationship(Resource target, boolean advancedStatus) throws WCMException {
        com.day.cq.wcm.msm.api.LiveRelationship rel = this.liveRelationMgr.getLiveRelationship(target, advancedStatus);
        if (rel != null) {
            List<RolloutConfig> blueprintActions = this.getBlueprintRolloutConfig(rel.getLiveCopy().getBlueprintPath(), target.getResourceResolver());
            return new LiveRelationshipAdaptor(rel, blueprintActions);
        }
        return null;
    }

    public com.day.cq.wcm.api.msm.LiveCopy getLiveCopy(Resource target) {
        LiveCopy lc = null;
        try {
            lc = this.liveRelationMgr.getLiveCopy(target);
        }
        catch (WCMException e) {
            this.log.error("Failed to access LiveCopy: {}", (Throwable)e);
        }
        if (lc != null) {
            return new LiveCopyAdaptor(lc);
        }
        return null;
    }

    public void cancelRelationship(ResourceResolver resolver, LiveRelationship relation, boolean deep) throws WCMException {
        this.cancelRelationship(resolver, relation, deep, true);
    }

    public void cancelRelationship(ResourceResolver resolver, LiveRelationship relation, boolean deep, boolean autoSave) throws WCMException {
        com.day.cq.wcm.msm.api.LiveRelationship adapted = this.adapt(relation, resolver);
        if (adapted != null) {
            this.liveRelationMgr.cancelRelationship(resolver, adapted, deep, autoSave);
        } else {
            this.log.debug("Didn't find relation from {} to {}, no execution of cancelRelationship", (Object)relation.getSourcePath(), (Object)relation.getTargetPath());
        }
    }

    public void reenableRelationship(ResourceResolver resolver, LiveRelationship relation) throws WCMException {
        this.reenableRelationship(resolver, relation, true);
    }

    public void reenableRelationship(ResourceResolver resolver, LiveRelationship relation, boolean autoSave) throws WCMException {
        com.day.cq.wcm.msm.api.LiveRelationship adapted = this.adapt(relation, resolver);
        if (adapted != null) {
            this.liveRelationMgr.reenableRelationship(resolver, adapted, autoSave);
        } else {
            this.log.debug("Didn't find relation from {} to {}, no execution of reenableRelation", (Object)relation.getSourcePath(), (Object)relation.getTargetPath());
        }
    }

    public void toggleRelationship(ResourceResolver resolver, LiveRelationship relation, boolean deep) throws WCMException {
        this.toggleRelationship(resolver, relation, deep, true);
    }

    public void toggleRelationship(ResourceResolver resolver, LiveRelationship relation, boolean deep, boolean autoSave) throws WCMException {
        if (relation != null) {
            if (relation.getStatus().isCancelled()) {
                this.reenableRelationship(resolver, relation, autoSave);
            } else {
                this.cancelRelationship(resolver, relation, deep, autoSave);
            }
        }
    }

    public boolean isInBlueprint(Resource source) {
        return this.liveRelationMgr.isInBlueprint(source);
    }

    public boolean isSource(Resource resource) {
        return this.liveRelationMgr.isSource(resource);
    }

    public Map<String, Page> getSkippedSourcePages(Page parentTargetPage) throws WCMException {
        return this.liveRelationMgr.getSkippedSourcePages(parentTargetPage);
    }

    public void addSkippedPage(Page parentPage, String childName, boolean autoSave) throws WCMException {
        this.liveRelationMgr.addSkippedPages(parentPage, new String[]{childName}, autoSave);
    }

    public void addSkippedPages(Page parentPage, String[] childName, boolean autoSave) throws WCMException {
        this.liveRelationMgr.addSkippedPages(parentPage, childName, autoSave);
    }

    public void removeSkippedPage(Page parentPage, String childName, boolean autoSave) throws WCMException {
        this.liveRelationMgr.removeSkippedPages(parentPage, new String[]{childName}, autoSave);
    }

    public void removeSkippedPages(Page parentPage, String[] childName, boolean autoSave) throws WCMException {
        this.liveRelationMgr.removeSkippedPages(parentPage, childName, autoSave);
    }

    public com.day.cq.wcm.msm.api.LiveRelationship adapt(LiveRelationship relation, ResourceResolver resolver) throws WCMException {
        Iterator rels;
        if (relation == null || resolver == null) {
            return null;
        }
        RolloutManager.Trigger tr3 = relation.getLiveCopy().getTrigger();
        RolloutManager.Trigger trigger = tr3 == null ? null : RolloutManager.Trigger.fromName((String)tr3.name());
        com.day.cq.wcm.msm.api.LiveRelationship rel = null;
        if (relation.getStatus().isTargetExisting()) {
            rel = this.liveRelationMgr.getLiveRelationship(resolver.getResource(relation.getTargetPath()), false);
        } else if (relation.getStatus().isSourceExisting() && (rels = this.liveRelationMgr.getLiveRelationships(resolver.resolve(relation.getSourcePath()), trigger, new String[]{relation.getTargetPath()}, false).iterator()).hasNext()) {
            rel = (com.day.cq.wcm.msm.api.LiveRelationship)rels.next();
        }
        return rel;
    }

    private List<RolloutConfig> getBlueprintRolloutConfig(String blueprintPath, ResourceResolver resolver) throws WCMException {
        Blueprint bp = this.blueprintManagerFactory.getBlueprintManager(resolver).getContainingBlueprint(blueprintPath);
        if (bp != null) {
            String sitePath = bp.getSitePath();
            String relPath = null;
            if (Text.isDescendant((String)(sitePath + "/" + "jcr:content"), (String)blueprintPath)) {
                relPath = blueprintPath.substring((sitePath + "/" + "jcr:content").length() + 1);
            }
            return bp.getBlueprintRolloutConfig(relPath, true);
        }
        return Collections.emptyList();
    }

    protected void bindLiveRelationMgr(com.day.cq.wcm.msm.api.LiveRelationshipManager liveRelationshipManager) {
        this.liveRelationMgr = liveRelationshipManager;
    }

    protected void unbindLiveRelationMgr(com.day.cq.wcm.msm.api.LiveRelationshipManager liveRelationshipManager) {
        if (this.liveRelationMgr == liveRelationshipManager) {
            this.liveRelationMgr = null;
        }
    }

    protected void bindBlueprintManagerFactory(BlueprintManagerFactory blueprintManagerFactory) {
        this.blueprintManagerFactory = blueprintManagerFactory;
    }

    protected void unbindBlueprintManagerFactory(BlueprintManagerFactory blueprintManagerFactory) {
        if (this.blueprintManagerFactory == blueprintManagerFactory) {
            this.blueprintManagerFactory = null;
        }
    }
}