TestandtargetProxyServiceImpl.java 7.67 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.granite.crypto.CryptoSupport
 *  com.day.cq.wcm.webservicesupport.Configuration
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 */
package com.day.cq.analytics.testandtarget.impl;

import com.adobe.granite.crypto.CryptoSupport;
import com.day.cq.analytics.testandtarget.TestandtargetException;
import com.day.cq.analytics.testandtarget.TestandtargetHttpClient;
import com.day.cq.analytics.testandtarget.TestandtargetUnsupportedApiOperationException;
import com.day.cq.analytics.testandtarget.impl.RestApiAdapter;
import com.day.cq.analytics.testandtarget.impl.TestandtargetAudience;
import com.day.cq.analytics.testandtarget.impl.TestandtargetProxyService;
import com.day.cq.wcm.webservicesupport.Configuration;
import java.util.Arrays;
import java.util.List;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;

@Component(metatype=0)
@Service
public class TestandtargetProxyServiceImpl
implements TestandtargetProxyService {
    private static final String PN_API_KIND = "apiKind";
    @Reference
    protected CryptoSupport cryptoSupport;
    @Reference
    protected TestandtargetHttpClient client;

    protected ApiKind getApiKind(Configuration configuration) {
        String apiKind = (String)configuration.getInherited("apiKind", (Object)ApiKind.XML.toString());
        if (ApiKind.XML.toString().equals(apiKind)) {
            return ApiKind.XML;
        }
        if (ApiKind.REST.toString().equals(apiKind)) {
            return ApiKind.REST;
        }
        throw new UnsupportedOperationException("Can't handle apiKind " + apiKind + " , valid values are " + Arrays.toString((Object[])ApiKind.values()));
    }

    @Override
    public List<TestandtargetAudience> getAudienceList(Configuration configuration) throws TestandtargetException {
        ApiKind apiKind = this.getApiKind(configuration);
        switch (apiKind) {
            case REST: {
                return new RestApiAdapter(this.client, this.cryptoSupport).getAudienceList(configuration);
            }
        }
        throw new TestandtargetUnsupportedApiOperationException("getAudienceList", apiKind.name());
    }

    @Override
    public void deleteCampaign(Configuration configuration, long campaignID) throws TestandtargetException {
        ApiKind apiKind = this.getApiKind(configuration);
        switch (apiKind) {
            case REST: {
                new RestApiAdapter(this.client, this.cryptoSupport).deleteCampaign(configuration, campaignID);
                break;
            }
            default: {
                throw new TestandtargetUnsupportedApiOperationException("deleteCampaign", apiKind.name());
            }
        }
    }

    @Override
    public String createVisualOffer(Configuration configuration, String offerName, String content) throws TestandtargetException {
        ApiKind apiKind = this.getApiKind(configuration);
        switch (apiKind) {
            case REST: {
                return new RestApiAdapter(this.client, this.cryptoSupport).createVisualOffer(configuration, offerName, content);
            }
        }
        throw new TestandtargetUnsupportedApiOperationException("createVisualOffer", apiKind.name());
    }

    @Override
    public String createSegment(Configuration configuration, String segmentName, String requestBody, boolean isReusable, String modifiedByUser) throws TestandtargetException {
        ApiKind apiKind = this.getApiKind(configuration);
        switch (apiKind) {
            case REST: {
                return new RestApiAdapter(this.client, this.cryptoSupport).createSegment(configuration, segmentName, requestBody, isReusable, modifiedByUser);
            }
        }
        throw new TestandtargetUnsupportedApiOperationException("createSegment", apiKind.name());
    }

    @Override
    public String createCampaign(Configuration configuration, String campaignName, String requestBody) throws TestandtargetException {
        ApiKind apiKind = this.getApiKind(configuration);
        switch (apiKind) {
            case REST: {
                return new RestApiAdapter(this.client, this.cryptoSupport).createCampaign(configuration, campaignName, requestBody);
            }
        }
        throw new TestandtargetUnsupportedApiOperationException("createCampaign", apiKind.name());
    }

    @Override
    public void deleteSegment(Configuration configuration, long segmentID) throws TestandtargetException {
        ApiKind apiKind = this.getApiKind(configuration);
        switch (apiKind) {
            case REST: {
                new RestApiAdapter(this.client, this.cryptoSupport).deleteSegment(configuration, segmentID);
                break;
            }
            default: {
                throw new TestandtargetUnsupportedApiOperationException("deleteSegment", apiKind.name());
            }
        }
    }

    @Override
    public void deleteOffer(Configuration configuration, long offerID) throws TestandtargetException {
        ApiKind apiKind = this.getApiKind(configuration);
        switch (apiKind) {
            case REST: {
                new RestApiAdapter(this.client, this.cryptoSupport).deleteOffer(configuration, offerID);
                break;
            }
            default: {
                throw new TestandtargetUnsupportedApiOperationException("deleteOffer", apiKind.name());
            }
        }
    }

    @Override
    public String updateCampaign(Configuration configuration, long campaignId, String requestBody) throws TestandtargetException {
        ApiKind apiKind = this.getApiKind(configuration);
        switch (apiKind) {
            case REST: {
                return new RestApiAdapter(this.client, this.cryptoSupport).updateCampaign(configuration, campaignId, requestBody);
            }
        }
        throw new TestandtargetUnsupportedApiOperationException("updateCampaign", apiKind.name());
    }

    @Override
    public String getCampaignDetails(Configuration configuration, long campaignId) throws TestandtargetException {
        ApiKind apiKind = this.getApiKind(configuration);
        switch (apiKind) {
            case REST: {
                return new RestApiAdapter(this.client, this.cryptoSupport).getCampaignDetails(configuration, campaignId);
            }
        }
        throw new TestandtargetUnsupportedApiOperationException("getCampaignDetails", apiKind.name());
    }

    @Override
    public String getReportSummary(Configuration configuration, long campaignId) throws TestandtargetException {
        ApiKind apiKind = this.getApiKind(configuration);
        switch (apiKind) {
            case REST: {
                return new RestApiAdapter(this.client, this.cryptoSupport).getReportSummary(configuration, campaignId);
            }
        }
        throw new TestandtargetUnsupportedApiOperationException("getCampaignDetails", apiKind.name());
    }

    protected void bindCryptoSupport(CryptoSupport cryptoSupport) {
        this.cryptoSupport = cryptoSupport;
    }

    protected void unbindCryptoSupport(CryptoSupport cryptoSupport) {
        if (this.cryptoSupport == cryptoSupport) {
            this.cryptoSupport = null;
        }
    }

    protected void bindClient(TestandtargetHttpClient testandtargetHttpClient) {
        this.client = testandtargetHttpClient;
    }

    protected void unbindClient(TestandtargetHttpClient testandtargetHttpClient) {
        if (this.client == testandtargetHttpClient) {
            this.client = null;
        }
    }

    static enum ApiKind {
        XML,
        REST;
        

        private ApiKind() {
        }
    }

}