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

com.pubnub.internal.endpoints.objects_api.memberships.ManageMembershipsImpl Maven / Gradle / Ivy

Go to download

PubNub is a cross-platform client-to-client (1:1 and 1:many) push service in the cloud, capable of broadcasting real-time messages to millions of web and mobile clients simultaneously, in less than a quarter second!

There is a newer version: 10.3.2
Show newest version
package com.pubnub.internal.endpoints.objects_api.memberships;

import com.pubnub.api.endpoints.objects_api.memberships.ManageMemberships;
import com.pubnub.api.endpoints.objects_api.utils.Include;
import com.pubnub.api.endpoints.objects_api.utils.PNSortKey;
import com.pubnub.api.endpoints.remoteaction.ExtendedRemoteAction;
import com.pubnub.api.endpoints.remoteaction.MappingRemoteAction;
import com.pubnub.api.models.consumer.objects.PNPage;
import com.pubnub.api.models.consumer.objects_api.membership.PNChannelMembership;
import com.pubnub.api.models.consumer.objects_api.membership.PNManageMembershipResult;
import com.pubnub.internal.EndpointInterface;
import com.pubnub.internal.PubNubCore;
import com.pubnub.internal.endpoints.DelegatingEndpoint;
import com.pubnub.internal.models.consumer.objects.membership.ChannelMembershipInput;
import com.pubnub.internal.models.consumer.objects.membership.PNChannelMembershipArrayResult;
import lombok.AllArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

@Setter
@Accessors(chain = true, fluent = true)
public class ManageMembershipsImpl extends DelegatingEndpoint implements ManageMemberships {
    private Collection set;
    private Collection remove;
    private String uuid;
    private Integer limit;
    private PNPage page;
    private String filter;
    private Collection sort = Collections.emptyList();
    private boolean includeTotalCount;
    private boolean includeCustom;
    private Include.PNChannelDetailsLevel includeChannel;

    public ManageMembershipsImpl(Collection channelsToSet, Collection channelsToRemove, final PubNubCore pubnubInstance) {
        super(pubnubInstance);
        set = channelsToSet;
        remove = channelsToRemove;
    }

    @NotNull
    @Override
    protected ExtendedRemoteAction mapResult(@NotNull ExtendedRemoteAction action) {
        return new MappingRemoteAction<>(action, PNManageMembershipResult::from);
    }

    @Override
    @NotNull
    protected EndpointInterface createAction() {
        ArrayList toSet = new ArrayList<>(set.size());
        for (PNChannelMembership channel : set) {
            toSet.add(new com.pubnub.internal.models.consumer.objects.membership.PNChannelMembership.Partial(
                    channel.getChannel().getId(),
                    (channel instanceof PNChannelMembership.ChannelWithCustom)
                            ? ((PNChannelMembership.ChannelWithCustom) channel).getCustom()
                            : null,
                    null
            ));
        }
        ArrayList toRemove = new ArrayList<>(remove.size());
        for (PNChannelMembership channel : remove) {
            toRemove.add(channel.getChannel().getId());
        }

        return
                pubnub.manageMemberships(
                        toSet,
                        toRemove,
                        uuid,
                        limit,
                        page,
                        filter,
                        SetMembershipsImpl.toInternal(sort),
                        includeTotalCount,
                        includeCustom,
                        SetMembershipsImpl.toInternal(includeChannel)
                );
    }

    @AllArgsConstructor
    public static class Builder implements ManageMemberships.Builder {
        private final PubNubCore pubnubInstance;

        @Override
        public RemoveStep set(final Collection channelsToSet) {
            return new RemoveStep() {
                @Override
                public ManageMemberships remove(final Collection channelsToRemove) {
                    return new ManageMembershipsImpl(channelsToSet,
                            channelsToRemove,
                            pubnubInstance);
                }
            };
        }

        @Override
        public SetStep remove(final Collection channelsToRemove) {
            return new SetStep() {
                @Override
                public ManageMemberships set(final Collection channelsToSet) {
                    return new ManageMembershipsImpl(channelsToSet,
                            channelsToRemove,
                            pubnubInstance);
                }
            };
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy