All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.urbanairship.api.channel.model.open.Channel Maven / Gradle / Ivy

There is a newer version: 9.4.2
Show newest version
package com.urbanairship.api.channel.model.open;


import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.urbanairship.api.channel.model.ChannelType;
import com.urbanairship.api.push.model.PushModelObject;

import java.util.List;
import java.util.Optional;

/**
 * Represents the payload to be used for registering or updating an open channel.
 */
public class Channel extends PushModelObject {

    private final ChannelType type;
    private final Optional optIn;
    private final Optional address;
    private final Optional setTags;
    private final Optional> tags;
    private final Optional timezone;
    private final Optional localeCountry;
    private final Optional localeLanguage;
    private final OpenChannel open;

    private Channel(Builder builder) {
        this.type = builder.type;
        this.open = builder.open;
        this.address = Optional.ofNullable(builder.address);
        this.optIn = Optional.ofNullable(builder.optIn);
        this.setTags = Optional.ofNullable(builder.setTags);
        this.timezone = Optional.ofNullable(builder.timezone);
        this.localeCountry = Optional.ofNullable(builder.locale_country);
        this.localeLanguage = Optional.ofNullable(builder.locale_language);

        if (builder.tags.build().isEmpty()) {
            this.tags = Optional.empty();
        } else {
            this.tags = Optional.of(builder.tags.build());
        }
    }

    /**
     * Get the ChannelType.
     * @return ChannelType type
     */
    public ChannelType getType() {
        return type;
    }

    /**
     * Get the channel opt in status.
     * @return Optional Boolean optIn
     */
    public Optional getOptIn() {
        return optIn;
    }

    /**
     * Get the channel's address, a Unique identifier of the object
     * used as the primary ID in the delivery tier (webhook). One-to-one
     * with Channel ID. New addresses on existing channels will overwrite
     * old associations. Examples: email address, phone number. If
     * missing, channel_id must be present.
     * @return Optional String address
     */
    public Optional getAddress() {
        return address;
    }

    /**
     * Get the setTags flag. Optional, though required if tags is present.
     * If true on update, value of tags overwrites any existing tags.
     * If false, tags are unioned with existing tags.
     * @return Optional Boolean setTags
     */
    public Optional getSetTags() {
        return setTags;
    }

    /**
     * Get the List of String representations of tags.
     * @return Optional ImmutableList of Strings
     */
    public Optional> getTags() {
        return tags;
    }

    /**
     * Get a String representation of the timezone.
     * @return Optional String timezone
     */
    public Optional getTimezone() {
        return timezone;
    }

    /**
     * Get a String representation of the locale country.
     * @return Optional String localeCountry
     */
    public Optional getLocaleCountry() {
        return localeCountry;
    }

    /**
     * Get a String representation of the locale language.
     * @return Optional String localeLanguage
     */
    public Optional getLocaleLanguage() {
        return localeLanguage;
    }

    /**
     * Get open channel specific properties.
     * @return OpenChannel open
     */
    public OpenChannel getOpen() {
        return open;
    }

    /**
     * New Channel Builder.
     *
     * @return Builder
     */
    public static Builder newBuilder() {
        return new Builder();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Channel that = (Channel) o;
        return type == that.type &&
                Objects.equal(optIn, that.optIn) &&
                Objects.equal(address, that.address) &&
                Objects.equal(setTags, that.setTags) &&
                Objects.equal(tags, that.tags) &&
                Objects.equal(timezone, that.timezone) &&
                Objects.equal(localeCountry, that.localeCountry) &&
                Objects.equal(localeLanguage, that.localeLanguage) &&
                Objects.equal(open, that.open);
    }

    @Override
    public String toString() {
        return "Channel{" +
                "type=" + type +
                ", optIn=" + optIn +
                ", address=" + address +
                ", setTags=" + setTags +
                ", tags=" + tags +
                ", timezone=" + timezone +
                ", localeCountry=" + localeCountry +
                ", localeLanguage=" + localeLanguage +
                ", open=" + open +
                '}';
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(type, optIn, address, setTags, tags, timezone, localeCountry, localeLanguage, open);
    }

    /**
     * Channel Builder
     */
    public final static class Builder {
        private ChannelType type;
        private boolean optIn;
        private String address;
        private boolean setTags;
        private ImmutableList.Builder tags = ImmutableList.builder();
        private String timezone;
        private String locale_country;
        private String locale_language;
        private OpenChannel open;

        private Builder() {}

        /**
         * Set the ChannelType. Must be open.
         * @param type ChannelType
         * @return Channel Builder
         */
        public Builder setChannelType(ChannelType type) {
            this.type = type;
            return this;
        }

        /**
         * Set the channel opt in status. If false, no payloads will be
         * delivered for the channel.
         * @param optIn boolean
         * @return Channel Builder
         */
        public Builder setOptIn(boolean optIn) {
            this.optIn = optIn;
            return this;
        }

        /**
         * Set the channel's address, a Unique identifier of the object
         * used as the primary ID in the delivery tier (webhook). One-to-one
         * with Channel ID. New addresses on existing channels will overwrite
         * old associations. Examples: email address, phone number. If
         * missing, channel_id must be present.
         * @param address String
         * @return Channel Builder
         */
        public Builder setAddress(String address) {
            this.address = address;
            return this;
        }

        /**
         * Optional, though required if tags is present.
         * If true on update, value of tags overwrites any existing tags.
         * If false, tags are unioned with existing tags.
         * @param setTags boolean
         * @return Channel Builder
         */
        public Builder setTags(boolean setTags) {
            this.setTags = setTags;
            return this;
        }

        /**
         * Add a List of String representations of tags.
         * @param tags A List of Strings
         * @return Channel Builder
         */
        public Builder addAllTags(List tags) {
            this.tags.addAll(tags);
            return this;
        }

        /**
         * Set a String representation of a tag.
         * @param tag String
         * @return Channel Builder
         */
        public Builder addTag(String tag) {
            tags.add(tag);
            return this;
        }

        /**
         * Set timezone string. An IANA tzdata identifier for the timezone
         * as a string, e.g., "America/Los Angeles". Will set the timezone
         * tag group tag with the specified value.
         * @param timezone String
         * @return Channel Builder
         */
        public Builder setTimeZone(String timezone) {
            this.timezone = timezone;
            return this;
        }

        /**
         * Set a the localeCountry The two-letter country locale shortcode.
         * Will set the ua_locale_country tag group to the specified value.
         * @param locale_country String
         * @return Channel Builder
         */
        public Builder setLocaleCountry(String locale_country) {
            this.locale_country = locale_country;
            return this;
        }

        /**
         * Set a String localeLanguage, the two-letter language locale
         * shortcode. Will set the ua_locale_language tag group to the
         * specified value
         * @param locale_language String
         * @return Channel Builder
         */
        public Builder setLocaleLanguage(String locale_language) {
            this.locale_language = locale_language;
            return this;
        }

        /**
         * Set open channel specific properties.
         * @param open OpenChannel
         * @return Channel Builder
         */
        public Builder setOpenChannel(OpenChannel open) {
            this.open = open;
            return this;
        }

        public Channel build() {
            Preconditions.checkNotNull(type, "'type' cannot be null.");
            Preconditions.checkNotNull(open, "'open' cannot be null.");

            return new Channel(this);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy