MobileAttributesServlet.java 4.6 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.day.cq.wcm.webservicesupport.Configuration
 *  com.day.cq.wcm.webservicesupport.ConfigurationManager
 *  com.day.cq.wcm.webservicesupport.ConfigurationManagerFactory
 *  javax.servlet.ServletException
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.sling.SlingServlet
 *  org.apache.sling.api.SlingHttpServletRequest
 *  org.apache.sling.api.SlingHttpServletResponse
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.apache.sling.api.servlets.SlingSafeMethodsServlet
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.day.cq.analytics.testandtarget.impl.servlets;

import com.day.cq.analytics.testandtarget.impl.TestandtargetPrivateService;
import com.day.cq.wcm.webservicesupport.Configuration;
import com.day.cq.wcm.webservicesupport.ConfigurationManager;
import com.day.cq.wcm.webservicesupport.ConfigurationManagerFactory;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.ServletException;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.sling.SlingServlet;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SlingServlet(generateComponent=1, methods={"GET"}, extensions={"json"}, selectors={"mobile"}, resourceTypes={"cq/analytics/components/testandtargetpage", "cq/analytics/components/cbframework"}, label="Adobe Target Integration Mobile Attributes List Servlet", description="Provides the TnT mobile attributes in JSON format")
public class MobileAttributesServlet
extends SlingSafeMethodsServlet {
    private static final String PARAM_SEARCH_NAME = "paramName";
    private static final String PARAM_SEARCH_TERM = "term";
    private static final String PARAM_SEARCH_TYPE = "searchType";
    private final Logger LOG;
    @Reference
    private ConfigurationManagerFactory cfgManagerFactory;
    @Reference
    private TestandtargetPrivateService tntService;

    public MobileAttributesServlet() {
        this.LOG = LoggerFactory.getLogger(this.getClass());
    }

    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
        Resource tntConfigResource = request.getResource();
        if (tntConfigResource != null) {
            ConfigurationManager cfgManager = this.cfgManagerFactory.getConfigurationManager(tntConfigResource.getResourceResolver());
            Configuration tntConfig = cfgManager.getConfiguration(tntConfigResource.getParent().getPath());
            if (tntConfig != null) {
                try {
                    ArrayList allAtrributes = new ArrayList();
                    String paramName = request.getParameter("paramName");
                    String term = request.getParameter("term");
                    String searchType = request.getParameter("searchType");
                    String mobileSearchResponse = this.tntService.searchMobileAttributes(tntConfig, searchType, paramName, term);
                    response.setContentType("application/json");
                    response.setStatus(200);
                    response.getWriter().write(mobileSearchResponse);
                }
                catch (Exception e) {
                    response.setStatus(500);
                    this.LOG.error("Error getting the TnT profile attributes!", (Throwable)e);
                }
            } else {
                this.LOG.warn("No Test and Target cloud configuration at path " + tntConfigResource.getPath());
            }
        }
    }

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

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

    protected void bindTntService(TestandtargetPrivateService testandtargetPrivateService) {
        this.tntService = testandtargetPrivateService;
    }

    protected void unbindTntService(TestandtargetPrivateService testandtargetPrivateService) {
        if (this.tntService == testandtargetPrivateService) {
            this.tntService = null;
        }
    }
}