com.pubnub.internal.endpoints.objects_api.members.SetChannelMembersImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pubnub-gson-impl Show documentation
Show all versions of pubnub-gson-impl Show documentation
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!
package com.pubnub.internal.endpoints.objects_api.members;
import com.pubnub.api.endpoints.objects_api.members.SetChannelMembers;
import com.pubnub.api.endpoints.objects_api.utils.Include;
import com.pubnub.api.endpoints.objects_api.utils.ObjectsBuilderSteps;
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.member.PNSetChannelMembersResult;
import com.pubnub.api.models.consumer.objects_api.member.PNUUID;
import com.pubnub.internal.EndpointInterface;
import com.pubnub.internal.PubNubCore;
import com.pubnub.internal.endpoints.DelegatingEndpoint;
import com.pubnub.internal.models.consumer.objects.PNMemberKey;
import com.pubnub.internal.models.consumer.objects.member.MemberInput;
import com.pubnub.internal.models.consumer.objects.member.PNMember;
import com.pubnub.internal.models.consumer.objects.member.PNMemberArrayResult;
import com.pubnub.internal.models.consumer.objects.member.PNUUIDDetailsLevel;
import lombok.AllArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@Setter
@Accessors(chain = true, fluent = true)
public class SetChannelMembersImpl extends DelegatingEndpoint implements SetChannelMembers {
private Integer limit = null;
private PNPage page;
private String filter;
private Collection sort = Collections.emptyList();
private boolean includeTotalCount;
private boolean includeCustom;
private Include.PNUUIDDetailsLevel includeUUID;
private final String channel;
private final Collection uuids;
public SetChannelMembersImpl(final PubNubCore pubnubInstance, String channel, Collection uuids) {
super(pubnubInstance);
this.channel = channel;
this.uuids = uuids;
}
@NotNull
@Override
protected ExtendedRemoteAction mapResult(@NotNull ExtendedRemoteAction action) {
return new MappingRemoteAction<>(action, PNSetChannelMembersResult::from);
}
@Override
@NotNull
protected EndpointInterface createAction() {
List memberInputs = new ArrayList<>(uuids.size());
for (PNUUID uuid : uuids) {
memberInputs.add(new PNMember.Partial(uuid.getUuid().getId(), (uuid instanceof PNUUID.UUIDWithCustom) ? ((PNUUID.UUIDWithCustom) uuid).getCustom() : null, uuid.getStatus()));
}
return pubnub.setChannelMembers(channel, memberInputs, limit, page, filter, toInternal(sort), includeTotalCount, includeCustom, toInternal(includeUUID));
}
static Collection extends com.pubnub.internal.models.consumer.objects.PNSortKey> toInternal(Collection sort) {
List> list = new ArrayList<>(sort.size());
for (PNSortKey pnSortKey : sort) {
PNMemberKey key = null;
switch (pnSortKey.getKey()) {
case ID:
key = PNMemberKey.UUID_ID;
break;
case NAME:
key = PNMemberKey.UUID_NAME;
break;
case UPDATED:
key = PNMemberKey.UUID_UPDATED;
break;
default:
throw new IllegalStateException("Should never happen");
}
if (pnSortKey.getDir().equals(PNSortKey.Dir.ASC)) {
list.add(new com.pubnub.internal.models.consumer.objects.PNSortKey.PNAsc<>(key));
} else {
list.add(new com.pubnub.internal.models.consumer.objects.PNSortKey.PNDesc<>(key));
}
}
return list;
}
@Nullable
static PNUUIDDetailsLevel toInternal(Include.PNUUIDDetailsLevel detailLevel) {
if (detailLevel == null) {
return null;
}
switch (detailLevel) {
case UUID:
return PNUUIDDetailsLevel.UUID;
case UUID_WITH_CUSTOM:
return PNUUIDDetailsLevel.UUID_WITH_CUSTOM;
default:
throw new IllegalStateException("Unknown detail level: " + detailLevel);
}
}
@AllArgsConstructor
public static class Builder implements SetChannelMembers.Builder {
private final PubNubCore pubnubInstance;
@Override
public ObjectsBuilderSteps.UUIDsStep channel(final String channel) {
return new ObjectsBuilderSteps.UUIDsStep() {
@Override
public SetChannelMembers uuids(@NotNull final Collection uuids) {
return new SetChannelMembersImpl(pubnubInstance, channel, uuids);
}
};
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy