PublishCatalog.java 2.74 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.day.cq.replication.ReplicationActionType
 *  com.scene7.is.catalog.CatalogAttributes
 *  com.scene7.is.catalog.CatalogAttributesBean
 *  com.scene7.is.catalog.service.publish.atomic.PublishingService
 *  com.scene7.is.util.ObjectUtil
 *  javax.jcr.RepositoryException
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 */
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.NodeToCatalogConverter;
import com.day.cq.replication.ReplicationActionType;
import com.scene7.is.catalog.CatalogAttributes;
import com.scene7.is.catalog.CatalogAttributesBean;
import com.scene7.is.catalog.service.publish.atomic.PublishingService;
import com.scene7.is.util.ObjectUtil;
import java.util.Collections;
import java.util.Map;
import javax.jcr.RepositoryException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;

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

    static Replicator instance() {
        return INSTANCE;
    }

    @Override
    void build(ReplicationActionType actionType, ResourceResolver resolver, String path, PublishingService delegate) throws RepositoryException {
        String tenantId = DamLayout.catalogTenantId(path);
        switch (actionType) {
            case DELETE: 
            case DEACTIVATE: {
                CatalogAttributesBean defaultCatalog = new CatalogAttributesBean(tenantId);
                defaultCatalog.setLastModified(Long.valueOf(System.currentTimeMillis()));
                delegate.updateCatalog((CatalogAttributes)defaultCatalog);
                break;
            }
            case ACTIVATE: {
                Resource resource = (Resource)ObjectUtil.notNull((Object)resolver.getResource(path));
                CatalogAttributesBean catalog = PublishCatalog.getCatalog(resource, tenantId);
                catalog.setMacros(Collections.emptyMap());
                catalog.setLastModified(Long.valueOf(System.currentTimeMillis()));
                delegate.updateCatalog((CatalogAttributes)catalog);
                break;
            }
            default: {
                throw new AssertionError((Object)("Unexpected action type: " + (Object)actionType));
            }
        }
    }

    private static CatalogAttributesBean getCatalog(Resource resource, String rootId) throws RepositoryException {
        return (CatalogAttributesBean)NodeToCatalogConverter.toCatalog(resource, rootId);
    }

    private PublishCatalog() {
    }

}