TestandtargetOffer.java 3.44 KB
/*
 * Decompiled with CFR 0_118.
 */
package com.day.cq.analytics.testandtarget.impl.model;

import com.day.cq.analytics.testandtarget.SaveOfferRequest;
import com.day.cq.analytics.testandtarget.impl.model.TntMbox;

public class TestandtargetOffer {
    public static final String NAME_DEFAULT = "Default AEM offer";
    public static final String DEFAULT_HTML_OFFER = "<script type=\"text/javascript\">(function() { CQ_Analytics.TestTarget.signalDefaultOffer('${mbox.name}');})();</script>";
    private static final String BASE_CONTENT = "<script type='text/javascript'>(function() { CQ_Analytics.TestTarget.pull('%s','${mbox.name}','1.0.0');})();</script>";
    private long id;
    private String name;
    private String locationName;
    private TntMbox tntMbox;
    private transient String contentPath;
    private transient boolean needsCreating;
    private transient boolean isDefault;
    private transient String pagePath;

    public SaveOfferRequest toSaveOfferRequest() {
        return this.isDefault ? new SaveOfferRequest(this.name, "<script type=\"text/javascript\">(function() { CQ_Analytics.TestTarget.signalDefaultOffer('${mbox.name}');})();</script>") : new SaveOfferRequest(this.name, this.getContentDeliveryPath());
    }

    public TestandtargetOffer(String name, String locationName, String contentPath) {
        this(name, locationName, contentPath, false);
    }

    public TestandtargetOffer(String name, String locationName, String contentPath, boolean isDefault) {
        this.name = name;
        this.locationName = locationName.replaceAll("[/:]", "-");
        this.contentPath = contentPath;
        this.isDefault = isDefault;
    }

    public TestandtargetOffer(long offerId, String name, String locationName, String contentPath, boolean isDefault) {
        this(name, locationName, contentPath, isDefault);
        this.id = offerId;
    }

    public TestandtargetOffer(long offerId, String name, String contentPath, TntMbox locationName) {
        this.name = name;
        this.id = offerId;
        this.tntMbox = locationName;
        this.contentPath = contentPath;
    }

    public void setPagePath(String path) {
        this.pagePath = path;
    }

    public String getPagePath() {
        return this.pagePath;
    }

    public void setOfferId(long id) {
        this.id = id;
    }

    public String getName() {
        return this.name;
    }

    public String getLocationName() {
        return this.locationName;
    }

    public void setTntMbox(TntMbox mbox) {
        this.tntMbox = mbox;
    }

    public String getContentPath() {
        return this.contentPath;
    }

    public String getContentDeliveryPath() {
        return this.contentPath + ".tandt.html";
    }

    public TestandtargetOffer setNeedsCreating(boolean needsCreating) {
        this.needsCreating = needsCreating;
        return this;
    }

    public boolean isNeedsCreating() {
        return this.needsCreating;
    }

    public boolean isDefault() {
        return this.isDefault;
    }

    public long getOfferId() {
        return this.id;
    }

    public TntMbox getTntMbox() {
        return this.tntMbox;
    }

    public static String buildOfferContent(String offerPath) {
        return String.format("<script type='text/javascript'>(function() { CQ_Analytics.TestTarget.pull('%s','${mbox.name}','1.0.0');})();</script>", offerPath + ".tandt.html");
    }

    public String toString() {
        return this.getClass().getName() + " : " + this.contentPath;
    }
}