Skip to content

Commit

Permalink
Changes after review.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-cebo committed Dec 3, 2024
1 parent d2bca86 commit 427052e
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import com.pubnub.api.java.endpoints.objects_api.members.RemoveChannelMembersBui
import com.pubnub.api.java.endpoints.objects_api.members.SetChannelMembers
import com.pubnub.api.java.endpoints.objects_api.members.SetChannelMembersBuilder
import com.pubnub.api.java.endpoints.objects_api.memberships.GetMemberships
import com.pubnub.api.java.endpoints.objects_api.memberships.GetMembershipsBuilder
import com.pubnub.api.java.endpoints.objects_api.memberships.ManageMemberships
import com.pubnub.api.java.endpoints.objects_api.memberships.ManageMembershipsBuilder
import com.pubnub.api.java.endpoints.objects_api.memberships.RemoveMemberships
Expand Down Expand Up @@ -473,19 +472,8 @@ interface PubNub : EventEmitter, StatusEmitter {
/**
* The method returns a list of channel memberships for a user. This method doesn't return a user's subscriptions.
*/
@Deprecated(
message = "This function is deprecated. Use getMemberships(userId: String) for better functionality.",
replaceWith = ReplaceWith(
"getMemberships(userId)"
)
)
fun getMemberships(): GetMemberships

/**
* The method returns a list of channel memberships for a user. This method doesn't return a user's subscriptions.
*/
fun getMemberships(userId: String): GetMembershipsBuilder

/**
* Set channel memberships for a UUID.
*/
Expand All @@ -512,7 +500,7 @@ interface PubNub : EventEmitter, StatusEmitter {
/**
* Remove channel memberships for a UUID.
*/
fun removeMemberships(channelMemberships: Collection<PNChannelMembership>): RemoveMembershipsBuilder
fun removeMemberships(channelMemberships: Collection<String>): RemoveMembershipsBuilder

/**
* Add and/or remove channel memberships for a UUID.
Expand All @@ -528,7 +516,7 @@ interface PubNub : EventEmitter, StatusEmitter {
*/
fun manageMemberships(
channelsToSet: Collection<PNChannelMembership>,
channelsToDelete: Collection<PNChannelMembership>
channelsToDelete: Collection<String>
): ManageMembershipsBuilder

/**
Expand Down Expand Up @@ -573,7 +561,7 @@ interface PubNub : EventEmitter, StatusEmitter {
/**
* Remove members from a Channel.
*/
fun removeChannelMembers(channelId: String, channelMembers: Collection<PNUser>): RemoveChannelMembersBuilder
fun removeChannelMembers(channelId: String, channelMembers: Collection<String>): RemoveChannelMembersBuilder

/**
* Set or remove members in a channel.
Expand All @@ -587,7 +575,7 @@ interface PubNub : EventEmitter, StatusEmitter {
/**
* Set or remove members in a channel.
*/
fun manageChannelMembers(channelId: String, set: Collection<PNUser>, remove: Collection<PNUser>): ManageChannelMembersBuilder
fun manageChannelMembers(channelId: String, set: Collection<PNUser>, remove: Collection<String>): ManageChannelMembersBuilder

/**
* Add an action on a published message. Returns the added action in the response.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,24 @@
import com.pubnub.api.java.endpoints.Endpoint;
import com.pubnub.api.java.endpoints.objects_api.utils.Include;
import com.pubnub.api.java.endpoints.objects_api.utils.PNSortKey;
import com.pubnub.api.java.models.consumer.objects_api.membership.MembershipInclude;
import com.pubnub.api.java.models.consumer.objects_api.membership.PNGetMembershipsResult;

public interface GetMemberships extends Endpoint<PNGetMembershipsResult> {
/**
* Set the user ID for fetching memberships.
*
* @param userId the user ID
* @return the current instance of {@code GetMemberships}
*/
GetMemberships userId(String userId);

/**
* @deprecated Use {@link #userId(String)} instead.
* @param uuid the user ID (previously referred to as UUID)
* @return the current instance of {@code GetMemberships}
*/
@Deprecated()
GetMemberships uuid(String uuid);

GetMemberships limit(Integer limit);
Expand All @@ -16,9 +31,29 @@ public interface GetMemberships extends Endpoint<PNGetMembershipsResult> {

GetMemberships sort(java.util.Collection<PNSortKey> sort);

/**
* @deprecated Use {@link #include(MembershipInclude)} instead.
* @param includeTotalCount specifies in totalCount should be included in response
* @return the current instance of {@code GetMemberships}
*/
@Deprecated()
GetMemberships includeTotalCount(boolean includeTotalCount);

/**
* @deprecated Use {@link #include(MembershipInclude)} instead.
* @param includeCustom specifies in Custom data should be included in response
* @return the current instance of {@code GetMemberships}
*/
@Deprecated()
GetMemberships includeCustom(boolean includeCustom);

/**
* @deprecated Use {@link #include(MembershipInclude)} instead.
* @param includeChannel specifies in ChannelMetadata should be included in response
* @return the current instance of {@code GetMemberships}
*/
@Deprecated()
GetMemberships includeChannel(Include.PNChannelDetailsLevel includeChannel);

GetMemberships include(MembershipInclude include);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

import static com.pubnub.api.integration.util.Utils.random;
import static com.pubnub.api.integration.util.Utils.randomChannel;
Expand Down Expand Up @@ -301,8 +302,9 @@ public void testListeningToSetChannelMembersAndRemoveChannelMembersEventsWithSta
Thread.sleep(2000);

List<PNUser> channelMembers = Arrays.asList(PNUser.builder(pubNub.getConfiguration().getUserId().getValue()).status(status).type(type).build());
List<String> channelMembersIds = channelMembers.stream().map(pnUser -> pnUser.getUserId()).collect(Collectors.toList());
pubNub.setChannelMembers(chan01.getName(), channelMembers).sync();
pubNub.removeChannelMembers(chan01.getName(), channelMembers).sync();
pubNub.removeChannelMembers(chan01.getName(), channelMembersIds).sync();

countDownLatch.await(5, TimeUnit.SECONDS);

Expand Down Expand Up @@ -337,7 +339,7 @@ public void testListeningToSetMembershipAndRemoveMembershipEventsWithStatusAndTy
Thread.sleep(2000);

pubNub.setMemberships(Collections.singletonList(PNChannelMembership.builder(chan01.getName()).status(status).type(type).build())).sync();
pubNub.removeMemberships(Arrays.asList(PNChannelMembership.builder(chan01.getName()).build())).sync();
pubNub.removeMemberships(Arrays.asList(chan01.getName())).sync();

countDownLatch.await(5, TimeUnit.SECONDS);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public void removeChannelMembersHappyPath() throws PubNubException {

//when
final PNRemoveChannelMembersResult removeMembersResult = pubNubUnderTest
.removeChannelMembers(testChannelId, Collections.singletonList(PNUser.builder(TEST_UUID2).build()))
.removeChannelMembers(testChannelId, Collections.singletonList(TEST_UUID2))
.include(MemberInclude.builder()
.includeTotalCount(true)
.includeStatus(true)
Expand Down Expand Up @@ -359,6 +359,7 @@ public void removeChannelMembersHappyPathDeprecated() throws PubNubException {
@Test
public void manageChannelMembersHappyPath() throws PubNubException {
//given
final List<String> channelMembersIdsToRemove = Collections.singletonList(TEST_UUID1);
final List<PNUser> channelMembersToRemove = Collections.singletonList(
PNUser.builder(TEST_UUID1)
.custom(customChannelMembershipObject())
Expand All @@ -377,7 +378,7 @@ public void manageChannelMembersHappyPath() throws PubNubException {

//when
final PNManageChannelMembersResult manageChannelMembersResult = pubNubUnderTest
.manageChannelMembers(testChannelId, channelMembersToSet, channelMembersToRemove)
.manageChannelMembers(testChannelId, channelMembersToSet, channelMembersIdsToRemove)
.include(MemberInclude.builder()
.includeCustom(true)
.includeStatus(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ public void getMembershipsHappyPath() throws PubNubException {
createdMembershipsList.add(setMembershipResult);

//when
final PNGetMembershipsResult getMembershipsResult = pubNubUnderTest.getMemberships(userId)
final PNGetMembershipsResult getMembershipsResult = pubNubUnderTest.getMemberships()
.userId(userId)
.limit(10)
.include(MembershipInclude.builder()
.includeCustom(true)
Expand Down Expand Up @@ -298,7 +299,7 @@ public void removeMembershipsHappyPath() throws PubNubException {
createdMembershipsList.add(setMembershipResult);

//when
List<PNChannelMembership> channelMembershipsToRemove = Collections.singletonList(PNChannelMembership.builder(testChannelId2).build());
List<String> channelMembershipsToRemove = Collections.singletonList(testChannelId2);
final PNRemoveMembershipResult removeMembershipResult = pubNubUnderTest.removeMemberships(channelMembershipsToRemove)
.include(MembershipInclude.builder()
.includeTotalCount(true)
Expand Down Expand Up @@ -353,6 +354,7 @@ public void removeMembershipsHappyPathDeprecated() throws PubNubException {
@Test
public void manageMembershipsHappyPath() throws PubNubException {
//given
final List<String> channelIdsToRemove = Collections.singletonList(testChannelId1);
final List<PNChannelMembership> channelMembershipsToRemove = Collections.singletonList(
PNChannelMembership.channelWithCustom(testChannelId1, customChannelMembershipObject()));

Expand All @@ -367,7 +369,7 @@ public void manageMembershipsHappyPath() throws PubNubException {
.build());

//when
final PNManageMembershipResult manageMembershipResult = pubNubUnderTest.manageMemberships(channelMembershipsToSet, channelMembershipsToRemove)
final PNManageMembershipResult manageMembershipResult = pubNubUnderTest.manageMemberships(channelMembershipsToSet, channelIdsToRemove)
.userId(pubNubUnderTest.getConfiguration().getUserId().getValue())
.include(MembershipInclude.builder()
.includeTotalCount(true)
Expand Down Expand Up @@ -433,14 +435,13 @@ public void manageMembershipsHappyPathDeprecated() throws PubNubException {
public void cleanUp() {
for (final PNSetMembershipResult createdMembership : createdMembershipsList) {
try {
final List<PNChannelMembership> channelMemberships = new ArrayList<>();
final List<String> channelIds = new ArrayList<>();
for (final PNMembership it : createdMembership.getData()) {
final String id = it.getChannel().getId();
final PNChannelMembership pnChannelMembership = PNChannelMembership.channel(id);
channelMemberships.add(pnChannelMembership);
channelIds.add(id);
}

pubNubUnderTest.removeMemberships(channelMemberships).sync();
pubNubUnderTest.removeMemberships(channelIds).sync();

} catch (Exception e) {
LOG.warn("Could not cleanup {}", createdMembership, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import com.pubnub.api.java.endpoints.objects_api.members.RemoveChannelMembersBui
import com.pubnub.api.java.endpoints.objects_api.members.SetChannelMembers
import com.pubnub.api.java.endpoints.objects_api.members.SetChannelMembersBuilder
import com.pubnub.api.java.endpoints.objects_api.memberships.GetMemberships
import com.pubnub.api.java.endpoints.objects_api.memberships.GetMembershipsBuilder
import com.pubnub.api.java.endpoints.objects_api.memberships.ManageMemberships
import com.pubnub.api.java.endpoints.objects_api.memberships.ManageMembershipsBuilder
import com.pubnub.api.java.endpoints.objects_api.memberships.RemoveMemberships
Expand Down Expand Up @@ -286,10 +285,6 @@ open class PubNubForJavaImpl(configuration: PNConfiguration) :
return GetMembershipsImpl(this)
}

override fun getMemberships(userId: String): GetMembershipsBuilder {
return GetMembershipsImpl(this, userId)
}

override fun setMemberships(): SetMemberships.Builder {
return SetMembershipsImpl.BuilderDeprecated(this)
}
Expand All @@ -302,7 +297,7 @@ open class PubNubForJavaImpl(configuration: PNConfiguration) :
return RemoveMembershipsImpl.Builder(this)
}

override fun removeMemberships(channelMemberships: Collection<PNChannelMembership>): RemoveMembershipsBuilder {
override fun removeMemberships(channelMemberships: Collection<String>): RemoveMembershipsBuilder {
return RemoveMembershipsImpl(channelMemberships, this)
}

Expand All @@ -312,7 +307,7 @@ open class PubNubForJavaImpl(configuration: PNConfiguration) :

override fun manageMemberships(
channelsToSet: Collection<PNChannelMembership>,
channelsToDelete: Collection<PNChannelMembership>
channelsToDelete: Collection<String>
): ManageMembershipsBuilder {
return ManageMembershipsImpl(channelsToSet, channelsToDelete, this)
}
Expand All @@ -339,7 +334,7 @@ open class PubNubForJavaImpl(configuration: PNConfiguration) :

override fun removeChannelMembers(
channelId: String,
channelMembers: Collection<PNUser>
channelMembers: Collection<String>
): RemoveChannelMembersBuilder {
return RemoveChannelMembersImpl(this, channelId, channelMembers)
}
Expand All @@ -351,7 +346,7 @@ open class PubNubForJavaImpl(configuration: PNConfiguration) :
override fun manageChannelMembers(
channelId: String,
set: Collection<PNUser>,
remove: Collection<PNUser>
remove: Collection<String>
): ManageChannelMembersBuilder {
return ManageChannelMembersImpl(this, channelId, set, remove)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class ManageChannelMembersImpl extends DelegatingEndpoint<PNMemberArrayRe
private Collection<PNUUID> uuidsToSet; // deprecated
private Collection<PNUUID> uuidsToRemove; // deprecated
private Collection<PNUser> usersToSet;
private Collection<PNUser> usersToRemove;
private List<String> usersIdsToRemove;
private MemberInclude include;

@Deprecated
Expand All @@ -57,11 +57,11 @@ public ManageChannelMembersImpl(String channel, Collection<PNUUID> uuidsToSet, C
this.uuidsToRemove = uuidsToRemove;
}

public ManageChannelMembersImpl(final PubNub pubnubInstance, String channel, Collection<PNUser> usersToSet, Collection<PNUser> usersToRemove) {
public ManageChannelMembersImpl(final PubNub pubnubInstance, String channel, Collection<PNUser> usersToSet, Collection<String> usersIdsToRemove) {
super(pubnubInstance);
this.channel = channel;
this.usersToSet = usersToSet;
this.usersToRemove = usersToRemove;
this.usersIdsToRemove = new ArrayList<>(usersIdsToRemove);
}

@NotNull
Expand All @@ -77,9 +77,9 @@ protected Endpoint<PNMemberArrayResult> createRemoteAction() {
List<String> toRemove;

// new API use
if (usersToSet != null || usersToRemove != null) {
if (usersToSet != null || usersIdsToRemove != null) {
toSet = createMemberInputFromUserToSet();
toRemove = createUserIdsFromUserToRemove();
toRemove = usersIdsToRemove;
} else { // old API used
toSet = createMemberInputFromUUIDToSet();
toRemove = createUserIdsFromUUIDToRemove();
Expand Down Expand Up @@ -171,18 +171,6 @@ private List<MemberInput> createMemberInputFromUUIDToSet() {
return memberInputs;
}

private List<String> createUserIdsFromUserToRemove() {
if (usersToRemove == null) {
return Collections.emptyList();
}

List<String> toRemove = new ArrayList<>();
for (PNUser user: usersToRemove) {
toRemove.add(user.getUserId());
}
return toRemove;
}

private List<String> createUserIdsFromUUIDToRemove() {
if (uuidsToRemove == null) {
return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.pubnub.api.java.models.consumer.objects_api.member.PNRemoveChannelMembersResult;
import com.pubnub.api.java.models.consumer.objects_api.member.PNRemoveChannelMembersResultConverter;
import com.pubnub.api.java.models.consumer.objects_api.member.PNUUID;
import com.pubnub.api.java.models.consumer.objects_api.member.PNUser;
import com.pubnub.api.models.consumer.objects.PNPage;
import com.pubnub.api.models.consumer.objects.member.PNMemberArrayResult;
import com.pubnub.internal.java.endpoints.DelegatingEndpoint;
Expand All @@ -40,7 +39,7 @@ public class RemoveChannelMembersImpl extends DelegatingEndpoint<PNMemberArrayRe
private boolean includeCustom; // deprecated
private boolean includeType; // deprecated
private final String channel;
private final List<String> userIds; // deprecated
private final List<String> userIds;
private Include.PNUUIDDetailsLevel includeUUID; // deprecated
private MemberInclude include;

Expand All @@ -54,13 +53,10 @@ private RemoveChannelMembersImpl(String channel, Collection<PNUUID> uuids, final
}
}

public RemoveChannelMembersImpl(final PubNub pubnubInstance, String channel, Collection<PNUser> users) {
public RemoveChannelMembersImpl(final PubNub pubnubInstance, String channel, Collection<String> userIds) {
super(pubnubInstance);
this.channel = channel;
this.userIds = new ArrayList<>(users.size());
for (PNUser user : users) {
this.userIds.add(user.getUserId());
}
this.userIds = new ArrayList<>(userIds);
}

@NotNull
Expand Down
Loading

0 comments on commit 427052e

Please # to comment.