PublishMacro.java 2.09 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.day.cq.replication.ReplicationActionType
 *  com.scene7.is.catalog.service.publish.atomic.PublishingService
 *  com.scene7.is.util.ObjectUtil
 *  javax.jcr.Node
 *  javax.jcr.RepositoryException
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 *  scala.Tuple2
 */
package com.adobe.cq.dam.aod.replication.helpers;

import com.adobe.cq.dam.aod.replication.DamLayout;
import com.adobe.cq.dam.aod.replication.helpers.Replicator;
import com.adobe.cq.dam.s7imaging.impl.catalog.JcrModifierList;
import com.day.cq.replication.ReplicationActionType;
import com.scene7.is.catalog.service.publish.atomic.PublishingService;
import com.scene7.is.util.ObjectUtil;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import scala.Tuple2;

class PublishMacro
extends Replicator {
    private static Replicator INSTANCE = new PublishMacro();

    static Replicator instance() {
        return INSTANCE;
    }

    @Override
    void build(ReplicationActionType actionType, ResourceResolver resolver, String path, PublishingService delegate) throws RepositoryException {
        Tuple2<String, String> parts = DamLayout.macroParts(path);
        String tenantId = (String)parts._1();
        String macroName = (String)parts._2();
        switch (actionType) {
            case DEACTIVATE: 
            case DELETE: {
                delegate.deleteMacro(tenantId, macroName, System.currentTimeMillis());
                break;
            }
            case ACTIVATE: {
                Resource resource = (Resource)ObjectUtil.notNull((Object)resolver.getResource(path + "/jcr:content"));
                Node node = (Node)ObjectUtil.notNull((Object)resource.adaptTo(Node.class));
                String value = JcrModifierList.jcrModifierList(node);
                delegate.updateMacro(tenantId, macroName, value, System.currentTimeMillis());
            }
        }
    }

    private PublishMacro() {
    }

}