AMSConfigJSONUpdateHandler.java 3.59 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.day.cq.contentsync.config.ConfigEntry
 *  com.day.cq.wcm.api.Page
 *  com.day.cq.wcm.api.PageManager
 *  com.day.cq.wcm.webservicesupport.Configuration
 *  com.day.cq.wcm.webservicesupport.ConfigurationManager
 *  com.day.cq.wcm.webservicesupport.ConfigurationManagerFactory
 *  javax.jcr.Session
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.apache.sling.commons.json.JSONObject
 *  org.apache.sling.jcr.resource.JcrResourceResolverFactory
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.cq.mobile.mobileservices.impl.contentsync;

import com.adobe.cq.mobile.mobileservices.impl.util.AMSUtils;
import com.adobe.cq.mobile.platform.impl.contentsync.handler.AbstractPagesUpdateHandler;
import com.day.cq.contentsync.config.ConfigEntry;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageManager;
import com.day.cq.wcm.webservicesupport.Configuration;
import com.day.cq.wcm.webservicesupport.ConfigurationManager;
import com.day.cq.wcm.webservicesupport.ConfigurationManagerFactory;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.commons.json.JSONObject;
import org.apache.sling.jcr.resource.JcrResourceResolverFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(metatype=1, factory="com.day.cq.contentsync.handler.ContentUpdateHandler/mobileADBMobileConfigJSON", inherit=1)
public class AMSConfigJSONUpdateHandler
extends AbstractPagesUpdateHandler {
    private static final Logger LOGGER = LoggerFactory.getLogger(AMSConfigJSONUpdateHandler.class);
    private static final String CONFIG_FILE_NAME = "ADBMobileConfig.json";
    @Reference
    private ConfigurationManagerFactory configurationManagerFactory;

    @Override
    public boolean updateCacheEntry(ConfigEntry configEntry, Long lastUpdated, String configCacheRoot, Session admin, Session session) {
        boolean updated = false;
        try {
            JSONObject jsonObject;
            ResourceResolver resolver = this.resolverFactory.getResourceResolver(session);
            Page page = ((PageManager)resolver.adaptTo(PageManager.class)).getPage(this.getResolvedContentPath(configEntry));
            ConfigurationManager configurationManager = this.configurationManagerFactory.getConfigurationManager(resolver);
            Configuration config = AMSUtils.getAMSConfiguration(configurationManager, page);
            if (config != null && (jsonObject = AMSUtils.getADBMobileConfigJSON(config)) != null) {
                updated = super.updateCacheEntry(configEntry, lastUpdated, configCacheRoot, admin, session);
            }
        }
        catch (Exception ex) {
            LOGGER.error("Unexpected error while updating cache for config: " + configEntry.getPath(), (Throwable)ex);
        }
        return updated;
    }

    @Override
    protected String getTargetPath(String path) {
        return "/ADBMobileConfig.json";
    }

    protected void bindConfigurationManagerFactory(ConfigurationManagerFactory configurationManagerFactory) {
        this.configurationManagerFactory = configurationManagerFactory;
    }

    protected void unbindConfigurationManagerFactory(ConfigurationManagerFactory configurationManagerFactory) {
        if (this.configurationManagerFactory == configurationManagerFactory) {
            this.configurationManagerFactory = null;
        }
    }
}