SitecatalystWebserviceImpl.java 11.4 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.day.cq.wcm.webservicesupport.Configuration
 *  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
 */
package com.day.cq.analytics.sitecatalyst.impl;

import com.day.cq.analytics.sitecatalyst.SitecatalystException;
import com.day.cq.analytics.sitecatalyst.SitecatalystHttpClient;
import com.day.cq.analytics.sitecatalyst.SitecatalystWebservice;
import com.day.cq.analytics.sitecatalyst.common.AbstractSiteCatalystService;
import com.day.cq.wcm.webservicesupport.Configuration;
import java.util.HashSet;
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;

@Component(metatype=0)
@Service
public class SitecatalystWebserviceImpl
extends AbstractSiteCatalystService
implements SitecatalystWebservice {
    @Reference
    private SitecatalystHttpClient client;

    @Override
    public void checkCredentials(String company, String username, String secret) throws SitecatalystException {
        throw new UnsupportedOperationException("This method is no longer supported.");
    }

    @Override
    public String getLoginKey(String company, String username, String password) throws SitecatalystException {
        return this.getLoginKey(null, company, username, password);
    }

    @Override
    public String getLoginKey(String server, String company, String username, String password) throws SitecatalystException {
        try {
            JSONObject json = new JSONObject();
            json.put("company", (Object)company);
            json.put("login", (Object)username);
            json.put("password", (Object)password);
            String response = this.client.execute(server, "Company.GetLoginKey", json.toString(), null, null, null);
            String error = this.getError(response);
            if (error != null) {
                throw new SitecatalystException(error);
            }
            return response.replaceAll("\"", "");
        }
        catch (JSONException e) {
            throw new SitecatalystException(e.getMessage(), (Throwable)e);
        }
    }

    @Override
    public String getReportSuites(Configuration configuration) throws SitecatalystException {
        try {
            JSONObject json = new JSONObject();
            json.put("rs_type", (Object)new JSONArray("['standard']"));
            json.put("sp", (Object)"");
            return this.client.execute("Company.GetReportSuites", json.toString(), configuration);
        }
        catch (JSONException e) {
            throw new SitecatalystException(e.getMessage(), (Throwable)e);
        }
    }

    @Override
    public String getSegments(String server, String company, String username, String secret) throws SitecatalystException {
        try {
            JSONObject json = new JSONObject();
            json.put("accessLevel", (Object)"all");
            String response = this.client.execute(server, "Segments.Get", json.toString(), company, username, secret);
            String error = this.getError(response);
            if (error != null) {
                throw new SitecatalystException(error);
            }
            return response;
        }
        catch (JSONException e) {
            throw new SitecatalystException(e.getMessage(), (Throwable)e);
        }
    }

    @Override
    public String getTrackingServer(Configuration configuration, String rsid) throws SitecatalystException {
        try {
            JSONObject json = new JSONObject();
            json.put("rsid", (Object)rsid);
            return this.client.execute("Company.GetTrackingServer", json.toString(), configuration);
        }
        catch (JSONException e) {
            throw new SitecatalystException(e.getMessage(), (Throwable)e);
        }
    }

    @Override
    public String getEvars(Configuration configuration, String rsid) throws SitecatalystException {
        try {
            JSONArray rsidList = this.splitToJSONArray(rsid);
            JSONObject json = new JSONObject();
            json.put("rsid_list", (Object)rsidList);
            String result = this.client.execute("ReportSuite.GetEvars", json.toString(), configuration);
            JSONArray array = this.toJSONArray(result);
            this.checkResults(rsidList, array);
            return result;
        }
        catch (JSONException e) {
            throw new SitecatalystException(e.getMessage(), (Throwable)e);
        }
    }

    @Override
    public String getTrafficVars(Configuration configuration, String rsid) throws SitecatalystException {
        try {
            JSONArray rsidList = this.splitToJSONArray(rsid);
            JSONObject json = new JSONObject();
            json.put("rsid_list", (Object)rsidList);
            String result = this.client.execute("ReportSuite.GetProps", json.toString(), configuration);
            JSONArray array = this.toJSONArray(result);
            this.checkResults(rsidList, array);
            return result;
        }
        catch (JSONException e) {
            throw new SitecatalystException(e.getMessage(), (Throwable)e);
        }
    }

    @Override
    public String getSuccessEvents(Configuration configuration, String rsid) throws SitecatalystException {
        try {
            JSONArray rsidList = this.splitToJSONArray(rsid);
            JSONObject json = new JSONObject();
            json.put("rsid_list", (Object)rsidList);
            String result = this.client.execute("ReportSuite.GetEvents", json.toString(), configuration);
            JSONArray array = this.toJSONArray(result);
            this.checkResults(rsidList, array);
            return result;
        }
        catch (JSONException e) {
            throw new SitecatalystException(e.getMessage(), (Throwable)e);
        }
    }

    @Override
    public String queueReport(Configuration configuration, String reportType, JSONObject reportDescription) throws SitecatalystException {
        return this.queueReport(configuration, reportDescription);
    }

    @Override
    public String queueReport(Configuration configuration, JSONObject reportDescription) throws SitecatalystException {
        try {
            JSONObject reportQueue = new JSONObject();
            reportQueue.put("reportDescription", (Object)reportDescription);
            return this.client.execute("Report.Queue", reportQueue.toString(), configuration);
        }
        catch (JSONException e) {
            throw new SitecatalystException(e.getMessage(), (Throwable)e);
        }
    }

    @Override
    public String queuePageViewReport(Configuration configuration, String rsid, String date) throws SitecatalystException {
        try {
            JSONObject reportDescription = new JSONObject();
            reportDescription.put("reportSuiteID", (Object)rsid);
            reportDescription.put("date", (Object)date);
            reportDescription.put("metrics", (Object)new JSONArray("[{\"id\": \"pageViews\"}]"));
            reportDescription.put("elements", (Object)new JSONArray("[{\"id\": \"page\"}]"));
            JSONObject reportQueue = new JSONObject();
            reportQueue.put("reportDescription", (Object)reportDescription);
            return this.client.execute("Report.Queue", reportQueue.toString(), configuration);
        }
        catch (JSONException e) {
            throw new SitecatalystException(e.getMessage(), (Throwable)e);
        }
    }

    @Override
    public String getReportStatus(Configuration configuration, String reportID) throws SitecatalystException {
        return this.getReport(configuration, reportID);
    }

    @Override
    public String getReport(Configuration configuration, String reportID) throws SitecatalystException {
        try {
            JSONObject json = new JSONObject();
            json.put("reportID", (Object)reportID);
            return this.client.execute("Report.Get", json.toString(), configuration);
        }
        catch (JSONException e) {
            throw new SitecatalystException(e.getMessage(), (Throwable)e);
        }
    }

    @Override
    public String getSynchronousReport(Configuration configuration, String reportType, JSONObject reportDescription) throws SitecatalystException {
        throw new UnsupportedOperationException("This method is no longer supported");
    }

    @Override
    public String getMetrics(Configuration configuration, String rsID) throws SitecatalystException {
        try {
            JSONObject getMetricsParameters = new JSONObject();
            getMetricsParameters.put("reportSuiteID", (Object)rsID);
            getMetricsParameters.put("reportType", (Object)"ranked");
            return this.client.execute("Report.GetMetrics", getMetricsParameters.toString(), configuration);
        }
        catch (JSONException e) {
            throw new SitecatalystException(e.getMessage(), (Throwable)e);
        }
    }

    @Override
    public String getPages(Configuration configuration, Integer limit, String pagename, String rsid, Integer start) throws SitecatalystException {
        throw new UnsupportedOperationException("This method is no longer supported");
    }

    @Override
    public JSONArray getClassifications(Configuration configuration, String classificationView, String[] reportSuites, int relationId) throws SitecatalystException {
        throw new UnsupportedOperationException("This method is no longer supported");
    }

    @Override
    public boolean saveClassifications(Configuration configuration, String classificationView, boolean campaignView, String name, int parentDivNum, String[] reportSuites, boolean update) throws SitecatalystException {
        throw new UnsupportedOperationException("This method is no longer supported");
    }

    @Override
    public boolean deleteClassifications(Configuration configuration, String classificationView, String[] reportSuites, int divNum, int parentDivNum) throws SitecatalystException {
        throw new UnsupportedOperationException("This method is no longer supported");
    }

    private final JSONArray splitToJSONArray(String s) {
        JSONArray array = new JSONArray();
        for (String piece : s.split(",")) {
            array.put((Object)piece);
        }
        return array;
    }

    private final void checkResults(JSONArray requestArray, JSONArray resultArray) throws JSONException, SitecatalystException {
        int i;
        HashSet<String> rsidSet = new HashSet<String>();
        for (i = 0; i < resultArray.length(); ++i) {
            rsidSet.add(resultArray.getJSONObject(i).getString("rsid"));
        }
        for (i = 0; i < requestArray.length(); ++i) {
            String rsid = requestArray.getString(i);
            if (rsidSet.contains(rsid)) continue;
            throw new SitecatalystException("Report suite with ID " + rsid + "  was not in result");
        }
    }

    protected void bindClient(SitecatalystHttpClient sitecatalystHttpClient) {
        this.client = sitecatalystHttpClient;
    }

    protected void unbindClient(SitecatalystHttpClient sitecatalystHttpClient) {
        if (this.client == sitecatalystHttpClient) {
            this.client = null;
        }
    }
}