DemdexCookieTraitsServiceImpl.java 3.71 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.apache.felix.scr.annotations.Activate
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.commons.json.JSONArray
 *  org.apache.sling.commons.json.JSONException
 *  org.apache.sling.commons.json.JSONObject
 *  org.osgi.service.component.ComponentContext
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.cq.aam.demdex;

import com.adobe.cq.aam.client.spi.AudienceManagerConfiguration;
import com.adobe.cq.aam.client.spi.AudienceManagerItem;
import com.adobe.cq.aam.client.spi.SegmentService;
import com.adobe.cq.aam.client.spi.TraitsService;
import com.adobe.cq.aam.demdex.JsonResponseSegmentIdList;
import com.adobe.cq.aam.demdex.JsonResponseSegmentList;
import com.adobe.cq.aam.demdex.SegmentListException;
import java.util.ArrayList;
import java.util.List;
import org.apache.felix.scr.annotations.Activate;
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.commons.json.JSONArray;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(immediate=1)
@Service(value={TraitsService.class})
public class DemdexCookieTraitsServiceImpl
implements TraitsService {
    private static final Logger LOGGER = LoggerFactory.getLogger(DemdexCookieTraitsServiceImpl.class);
    @Reference
    private SegmentService segmentService;

    @Activate
    public void activate(ComponentContext componentContext) {
    }

    @Override
    public List<String[]> updateTraits(AudienceManagerConfiguration config, String[] traits) {
        ArrayList<String[]> p = new ArrayList<String[]>();
        for (String t : traits) {
            p.add(new String[]{"d_sid", t});
        }
        return p;
    }

    @Override
    public Iterable<AudienceManagerItem> getSegments(AudienceManagerConfiguration config, JSONObject json) {
        try {
            return new JsonResponseSegmentList(this.segmentService, config, json);
        }
        catch (SegmentListException e) {
            return null;
        }
    }

    @Override
    public Iterable<String> getSegmentIds(AudienceManagerConfiguration config, JSONObject json) {
        try {
            return new JsonResponseSegmentIdList(this.segmentService, config, json);
        }
        catch (SegmentListException e) {
            return null;
        }
    }

    @Override
    public boolean containsDestination(JSONObject response, String destination, String domain) {
        try {
            LOGGER.debug("Got Response {} ", (Object)response.toString(2));
            if (response.has("stuff")) {
                JSONArray stuff = response.getJSONArray("stuff");
                for (int i = 0; i < stuff.length(); ++i) {
                    JSONObject v = stuff.getJSONObject(i);
                    if (!v.has("cn") || !v.has("dmn") || !destination.equals(v.getString("cn")) || !domain.equals(v.getString("dmn"))) continue;
                    return true;
                }
            }
        }
        catch (JSONException e) {
            LOGGER.error(e.getMessage(), (Throwable)e);
        }
        return false;
    }

    protected void bindSegmentService(SegmentService segmentService) {
        this.segmentService = segmentService;
    }

    protected void unbindSegmentService(SegmentService segmentService) {
        if (this.segmentService == segmentService) {
            this.segmentService = null;
        }
    }
}