Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PatchValue to Java API #281

Merged
merged 4 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.pubnub.api.java.models.consumer.objects_api;

import com.pubnub.api.utils.PatchValue;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.jetbrains.annotations.Nullable;

@Getter
@Accessors(chain = true)
Expand All @@ -16,13 +18,13 @@ public class PNObject {
protected String id;

@Setter
protected Object custom;
protected PatchValue<@Nullable Object> custom;

@Setter
protected String updated;
protected PatchValue<@Nullable String> updated;

@Setter
protected String eTag;
protected PatchValue<@Nullable String> eTag;

protected PNObject(String id) {
this.id = id;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.pubnub.api.java.models.consumer.objects_api.channel;

import com.pubnub.api.java.models.consumer.objects_api.PNObject;
import com.pubnub.api.utils.PatchValue;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -18,23 +20,23 @@
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class PNChannelMetadata extends PNObject {
private String name;
private String description;
private String type;
private String status;
private PatchValue<@Nullable String> name;
private PatchValue<@Nullable String> description;
private PatchValue<@Nullable String> type;
private PatchValue<@Nullable String> status;

public PNChannelMetadata(String id, String name, String description) {
public PNChannelMetadata(String id, PatchValue<@Nullable String> name, PatchValue<@Nullable String> description) {
super(id);
this.name = name;
this.description = description;
}

public PNChannelMetadata(String id, String name) {
public PNChannelMetadata(String id, PatchValue<@Nullable String> name) {
this(id, name, null);
}

@Override
public PNChannelMetadata setCustom(Object custom) {
public PNChannelMetadata setCustom(PatchValue<@Nullable Object> custom) {
super.setCustom(custom);
return this;
}
Expand All @@ -43,14 +45,14 @@ public PNChannelMetadata setCustom(Object custom) {
public static PNChannelMetadata from(@NotNull com.pubnub.api.models.consumer.objects.channel.PNChannelMetadata data) {
PNChannelMetadata newData = new PNChannelMetadata(
data.getId(),
data.getName() != null ? data.getName().getValue() : null,
data.getDescription() != null ? data.getDescription().getValue() : null
data.getName(),
data.getDescription()
);
newData.setETag(data.getETag() != null ? data.getETag().getValue() : null);
newData.setType(data.getType() != null ? data.getType().getValue() : null);
newData.setStatus(data.getStatus() != null ? data.getStatus().getValue() : null);
newData.setCustom(data.getCustom() != null ? data.getCustom().getValue() : null);
newData.setUpdated(data.getUpdated() != null ? data.getUpdated().getValue() : null);
newData.setETag(data.getETag());
newData.setType(data.getType());
newData.setStatus(data.getStatus());
newData.setCustom(data.getCustom() != null ? PatchValue.of(data.getCustom().getValue()) : null);
wkal-pubnub marked this conversation as resolved.
Show resolved Hide resolved
newData.setUpdated(data.getUpdated());
return newData;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.pubnub.api.java.models.consumer.objects_api.uuid.PNUUIDMetadata;
import com.pubnub.api.models.consumer.objects.member.PNMember;
import com.pubnub.api.utils.PatchValue;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand All @@ -23,11 +24,11 @@
public class PNMembers {
private PNUUIDMetadata uuid;

protected Object custom;
protected PatchValue<@Nullable Object> custom;

protected String updated;
protected String eTag;
protected String status;
protected PatchValue<@Nullable String> status;

@Nullable
public static PNMembers from(@Nullable PNMember member) {
Expand All @@ -36,10 +37,10 @@ public static PNMembers from(@Nullable PNMember member) {
}
return new PNMembers()
.setUuid(PNUUIDMetadata.from(member.getUuid()))
.setCustom(member.getCustom() != null ? member.getCustom().getValue() : null)
.setCustom(member.getCustom() != null ? PatchValue.of(member.getCustom().getValue()) : null)
.setUpdated(member.getUpdated())
.setETag(member.getETag())
.setStatus(member.getStatus() != null ? member.getStatus().getValue() : null);
.setStatus(member.getStatus());
}

public static List<PNMembers> from(Collection<PNMember> members) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.pubnub.api.java.models.consumer.objects_api.channel.PNChannelMetadata;
import com.pubnub.api.models.consumer.objects.membership.PNChannelMembership;
import com.pubnub.api.utils.PatchValue;
import lombok.Data;
import lombok.NonNull;
import lombok.experimental.Accessors;
Expand All @@ -20,11 +21,11 @@ public PNMembership(@NotNull PNChannelMetadata channel) {
}
@NonNull
private PNChannelMetadata channel;
private Object custom;
private PatchValue<@Nullable Object> custom;
private String uuid;
private String updated;
private String eTag;
private String status;
private PatchValue<@Nullable String> status;

public static List<PNMembership> from(Collection<PNChannelMembership> members) {
ArrayList<PNMembership> list = new ArrayList<>(members.size());
Expand All @@ -41,11 +42,11 @@ public static PNMembership from(@Nullable PNChannelMembership data) {
}
PNChannelMetadata metadata = PNChannelMetadata.from(data.getChannel());
PNMembership newData = new PNMembership(metadata);
newData.setCustom(data.getCustom() != null ? data.getCustom().getValue() : null);
newData.setCustom(data.getCustom() != null ? PatchValue.of(data.getCustom().getValue()) : null);
// newData.setUuid(data.get) //TODO where to get this? does it even exist in server responses?
newData.setUpdated(data.getUpdated());
newData.setETag(data.getETag());
newData.setStatus(data.getStatus() != null ? data.getStatus().getValue() : null);
newData.setStatus(data.getStatus());
return newData;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.pubnub.api.java.models.consumer.objects_api.uuid;

import com.pubnub.api.java.models.consumer.objects_api.PNObject;
import com.pubnub.api.utils.PatchValue;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -20,20 +21,20 @@
@ToString(callSuper = true)
@NoArgsConstructor
public class PNUUIDMetadata extends PNObject {
private String name;
private String email;
private String externalId;
private String profileUrl;
private String type;
private String status;
private PatchValue<@Nullable String> name;
private PatchValue<@Nullable String> email;
private PatchValue<@Nullable String> externalId;
private PatchValue<@Nullable String> profileUrl;
private PatchValue<@Nullable String> type;
private PatchValue<@Nullable String> status;

public PNUUIDMetadata(String id, String name) {
public PNUUIDMetadata(String id, PatchValue<@Nullable String> name) {
super(id);
this.name = name;
}

@Override
public PNUUIDMetadata setCustom(Object custom) {
public PNUUIDMetadata setCustom(PatchValue<@Nullable Object> custom) {
super.setCustom(custom);
return this;
}
Expand All @@ -51,16 +52,16 @@ public static PNUUIDMetadata from(com.pubnub.api.models.consumer.objects.uuid.PN
if (data == null) {
return null;
}
PNUUIDMetadata newData = new PNUUIDMetadata(data.getId(), data.getName() != null ? data.getName().getValue() : null)
.setProfileUrl(data.getProfileUrl() != null ? data.getProfileUrl().getValue() : null)
.setEmail(data.getEmail() != null ? data.getEmail().getValue() : null)
.setExternalId(data.getExternalId() != null ? data.getExternalId().getValue() : null)
.setStatus(data.getStatus() != null ? data.getStatus().getValue() : null)
.setType(data.getType() != null ? data.getType().getValue() : null)
.setCustom(data.getCustom() != null ? data.getCustom().getValue() : null);
PNUUIDMetadata newData = new PNUUIDMetadata(data.getId(), data.getName())
.setProfileUrl(data.getProfileUrl())
.setEmail(data.getEmail())
.setExternalId(data.getExternalId())
.setStatus(data.getStatus())
.setType(data.getType())
.setCustom(data.getCustom() != null ? PatchValue.of(data.getCustom().getValue()) : null);
wkal-pubnub marked this conversation as resolved.
Show resolved Hide resolved

newData.setETag(data.getETag() != null ? data.getETag().getValue() : null);
newData.setUpdated(data.getUpdated() != null ? data.getUpdated().getValue() : null);
newData.setETag(data.getETag());
newData.setUpdated(data.getUpdated());
return newData;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ public void setChannelHappyPath() throws PubNubException {
assertEquals(HttpStatus.SC_OK, setChannelMetadataResult.getStatus());
createdChannelMetadataList.add(setChannelMetadataResult);
assertEquals(randomChannelMetadataId, setChannelMetadataResult.getData().getId());
assertEquals(setChannelMetadataResult.getData().getDescription(),
setChannelMetadataResult.getData().getDescription());
assertNotNull(setChannelMetadataResult.getData().getCustom());
assertEquals(statusValue, setChannelMetadataResult.getData().getStatus());
assertEquals(typeValue, setChannelMetadataResult.getData().getType());
assertEquals(randomDescription,
setChannelMetadataResult.getData().getDescription().getValue());
assertNotNull(setChannelMetadataResult.getData().getCustom().getValue());
assertEquals(statusValue, setChannelMetadataResult.getData().getStatus().getValue());
assertEquals(typeValue, setChannelMetadataResult.getData().getType().getValue());
}

@Test
Expand Down Expand Up @@ -102,10 +102,10 @@ public void getChannelHappyPath() throws PubNubException {
assertEquals(setChannelMetadataResult.getData().getDescription(),
getChannelMetadataResult.getData().getDescription());
assertNotNull(setChannelMetadataResult.getData().getCustom());
assertEquals(statusValue, setChannelMetadataResult.getData().getStatus());
assertEquals(typeValue, setChannelMetadataResult.getData().getType());
assertEquals(statusValue, getChannelMetadataResult.getData().getStatus());
assertEquals(typeValue, getChannelMetadataResult.getData().getType());
assertEquals(statusValue, setChannelMetadataResult.getData().getStatus().getValue());
assertEquals(typeValue, setChannelMetadataResult.getData().getType().getValue());
assertEquals(statusValue, getChannelMetadataResult.getData().getStatus().getValue());
assertEquals(typeValue, getChannelMetadataResult.getData().getType().getValue());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.pubnub.api.java.models.consumer.objects_api.member.PNSetChannelMembersResult;
import com.pubnub.api.java.models.consumer.objects_api.member.PNUUID;
import com.pubnub.api.java.models.consumer.objects_api.uuid.PNUUIDMetadata;
import com.pubnub.api.utils.PatchValue;
import org.apache.http.HttpStatus;
import org.junit.After;
import org.junit.Test;
Expand Down Expand Up @@ -87,15 +88,16 @@ public void addChannelMembersHappyPath() throws PubNubException {

final List<Object> receivedCustomObjects = new ArrayList<>();
for (final PNMembers it : setChannelMembersResult.getData()) {
final Object custom = it.getCustom();
if (custom != null) {
PatchValue<Object> custom = it.getCustom();
if (custom != null && custom.getValue() != null) {
receivedCustomObjects.add(custom);
}
}

List<String> actualStatusList = setChannelMembersResult.getData()
.stream()
.map(PNMembers::getStatus)
.map(PatchValue::getValue)
.filter(Objects::nonNull)
.collect(Collectors.toList());

Expand Down Expand Up @@ -146,15 +148,16 @@ public void getChannelMembersHappyPath() throws PubNubException {
}
final List<Object> receivedCustomObjects = new ArrayList<>();
for (final PNMembers it : setChannelMembersResult.getData()) {
final Object custom = it.getCustom();
if (custom != null) {
PatchValue<Object> custom = it.getCustom();
if (custom != null && custom.getValue() != null) {
receivedCustomObjects.add(custom);
}
}

List<String> actualStatusList = setChannelMembersResult.getData()
.stream()
.map(PNMembers::getStatus)
.map(PatchValue::getValue)
.filter(Objects::nonNull)
.collect(Collectors.toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.pubnub.api.java.models.consumer.objects_api.member.PNSetChannelMembersResult;
import com.pubnub.api.java.models.consumer.objects_api.member.PNUUID;
import com.pubnub.api.java.models.consumer.objects_api.uuid.PNSetUUIDMetadataResult;
import com.pubnub.api.utils.PatchValue;
import org.junit.After;
import org.junit.Test;

Expand Down Expand Up @@ -84,10 +85,10 @@ public void setMembersCustomHappyPath() throws PubNubException {
hasProperty("uuid", allOf(
allOf(
hasProperty("id", is(testUUID)),
hasProperty("name", is(testName)),
hasProperty("email", is(testEmail)),
hasProperty("externalId", is(testExternalId)),
hasProperty("profileUrl", is(testProfileUrl)),
hasProperty("name", is(PatchValue.of(testName))),
hasProperty("email", is(PatchValue.of(testEmail))),
hasProperty("externalId", is(PatchValue.of(testExternalId))),
hasProperty("profileUrl", is(PatchValue.of(testProfileUrl))),
hasProperty("custom", notNullValue()))))))));
assertThat(getChannelMembersResult, hasProperty("data",
hasItem(
Expand All @@ -96,10 +97,10 @@ public void setMembersCustomHappyPath() throws PubNubException {
hasProperty("uuid", allOf(
allOf(
hasProperty("id", is(testUUID)),
hasProperty("name", is(testName)),
hasProperty("email", is(testEmail)),
hasProperty("externalId", is(testExternalId)),
hasProperty("profileUrl", is(testProfileUrl)),
hasProperty("name", is(PatchValue.of(testName))),
hasProperty("email", is(PatchValue.of(testEmail))),
hasProperty("externalId", is(PatchValue.of(testExternalId))),
hasProperty("profileUrl", is(PatchValue.of(testProfileUrl))),
hasProperty("custom", nullValue()))))))));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.pubnub.api.java.models.consumer.objects_api.membership.PNMembershipResult;
import com.pubnub.api.java.models.consumer.objects_api.membership.PNSetMembershipResult;
import com.pubnub.api.models.consumer.PNStatus;
import com.pubnub.api.utils.PatchValue;
import org.awaitility.core.ThrowingRunnable;
import org.jetbrains.annotations.NotNull;
import org.junit.After;
Expand Down Expand Up @@ -106,8 +107,8 @@ public void setMembershipCustomHappyPath() throws PubNubException {
hasProperty("channel", allOf(
allOf(
hasProperty("id", is(testChannelMetadataId)),
hasProperty("name", is(testChannelName)),
hasProperty("description", is(testDescription)),
hasProperty("name", is(PatchValue.of(testChannelName))),
hasProperty("description", is(PatchValue.of(testDescription))),
hasProperty("custom", notNullValue()))))))));
assertThat(getMembershipsResult, hasProperty("data",
hasItem(
Expand All @@ -116,8 +117,8 @@ public void setMembershipCustomHappyPath() throws PubNubException {
hasProperty("channel", allOf(
allOf(
hasProperty("id", is(testChannelMetadataId)),
hasProperty("name", is(testChannelName)),
hasProperty("description", is(testDescription)),
hasProperty("name", is(PatchValue.of(testChannelName))),
hasProperty("description", is(PatchValue.of(testDescription))),
hasProperty("custom", nullValue()))))))));

String userIdValue = pubNubUnderTest.getConfiguration().getUserId().getValue();
Expand Down
Loading
Loading