AnalyticsComponentServiceImpl.java 3.42 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.api.resource.LoginException
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.apache.sling.api.resource.ResourceResolverFactory
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.day.cq.analytics.impl;

import com.day.cq.analytics.impl.AnalyticsComponent;
import com.day.cq.analytics.impl.AnalyticsComponentQueryCache;
import com.day.cq.analytics.impl.AnalyticsComponentService;
import java.util.Collections;
import java.util.Map;
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.LoginException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component
@Service
public class AnalyticsComponentServiceImpl
implements AnalyticsComponentService {
    private static final String ANALYTICS_SUBSERVICE = "analytics";
    private final Logger logger;
    @Reference
    private ResourceResolverFactory rrf;
    @Reference
    private AnalyticsComponentQueryCache analyticsComponentQueryCache;

    public AnalyticsComponentServiceImpl() {
        this.logger = LoggerFactory.getLogger(this.getClass());
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    @Override
    public AnalyticsComponent getAnalyticsComponent(String path) {
        ResourceResolver resolver = null;
        try {
            resolver = this.rrf.getServiceResourceResolver(Collections.singletonMap("sling.service.subservice", "analytics"));
            Resource component = resolver.getResource(path + "/analytics");
            if (component == null) {
                AnalyticsComponent analyticsComponent = null;
                return analyticsComponent;
            }
            AnalyticsComponent analyticsComponent = new AnalyticsComponent(component, this.analyticsComponentQueryCache);
            return analyticsComponent;
        }
        catch (LoginException e) {
            this.logger.warn("Unable to read analytics component at path " + path, (Throwable)e);
            AnalyticsComponent analyticsComponent = null;
            return analyticsComponent;
        }
        finally {
            if (resolver != null) {
                resolver.close();
            }
        }
    }

    protected void bindRrf(ResourceResolverFactory resourceResolverFactory) {
        this.rrf = resourceResolverFactory;
    }

    protected void unbindRrf(ResourceResolverFactory resourceResolverFactory) {
        if (this.rrf == resourceResolverFactory) {
            this.rrf = null;
        }
    }

    protected void bindAnalyticsComponentQueryCache(AnalyticsComponentQueryCache analyticsComponentQueryCache) {
        this.analyticsComponentQueryCache = analyticsComponentQueryCache;
    }

    protected void unbindAnalyticsComponentQueryCache(AnalyticsComponentQueryCache analyticsComponentQueryCache) {
        if (this.analyticsComponentQueryCache == analyticsComponentQueryCache) {
            this.analyticsComponentQueryCache = null;
        }
    }
}