diff --git a/src/main/java/io/getstream/cloud/CloudAggregatedFeed.java b/src/main/java/io/getstream/cloud/CloudAggregatedFeed.java index 66044da4..5c04140f 100644 --- a/src/main/java/io/getstream/cloud/CloudAggregatedFeed.java +++ b/src/main/java/io/getstream/cloud/CloudAggregatedFeed.java @@ -10,698 +10,705 @@ import io.getstream.core.models.Group; import io.getstream.core.options.*; import io.getstream.core.utils.DefaultOptions; + import java.io.IOException; import java.util.List; + import java8.util.concurrent.CompletableFuture; import java8.util.concurrent.CompletionException; public class CloudAggregatedFeed extends CloudFeed { - CloudAggregatedFeed(CloudClient client, FeedID id) { - super(client, id); - } - - public CompletableFuture>> getActivities() - throws StreamException { - return getActivities( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getActivities(Limit limit) - throws StreamException { - return getActivities( - limit, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getActivities(Offset offset) - throws StreamException { - return getActivities( - DefaultOptions.DEFAULT_LIMIT, - offset, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getActivities(Filter filter) - throws StreamException { - return getActivities( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - filter, - DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getActivities( - ActivityMarker marker) throws StreamException { - return getActivities( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - marker); - } - - public CompletableFuture>> getActivities( - Limit limit, Offset offset) throws StreamException { - return getActivities( - limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getActivities( - Limit limit, Filter filter) throws StreamException { - return getActivities( - limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getActivities( - Limit limit, ActivityMarker marker) throws StreamException { - return getActivities( - limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); - } - - public CompletableFuture>> getActivities( - Filter filter, ActivityMarker marker) throws StreamException { - return getActivities( - DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker); - } - - public CompletableFuture>> getActivities( - Offset offset, ActivityMarker marker) throws StreamException { - return getActivities( - DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker); - } - - public CompletableFuture>> getActivities( - Limit limit, Filter filter, ActivityMarker marker) throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, marker); - } - - public CompletableFuture>> getActivities( - Limit limit, Offset offset, ActivityMarker marker) throws StreamException { - return getActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, marker); - } - - CompletableFuture>> getActivities( - Limit limit, Offset offset, Filter filter, ActivityMarker marker) throws StreamException { - return getClient() - .getActivities(getID(), limit, offset, filter, marker) - .thenApply( - (Response response) -> { - try { - return deserializeContainer(response, Group.class, Activity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public CompletableFuture>> getCustomActivities( - Class type) throws StreamException { - return getCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getCustomActivities( - Class type, Limit limit) throws StreamException { - return getCustomActivities( - type, - limit, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getCustomActivities( - Class type, Offset offset) throws StreamException { - return getCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - offset, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getCustomActivities( - Class type, Filter filter) throws StreamException { - return getCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - filter, - DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getCustomActivities( - Class type, ActivityMarker marker) throws StreamException { - return getCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - marker); - } - - public CompletableFuture>> getCustomActivities( - Class type, Limit limit, Offset offset) throws StreamException { - return getCustomActivities( - type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getCustomActivities( - Class type, Limit limit, Filter filter) throws StreamException { - return getCustomActivities( - type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); - } - - public CompletableFuture>> getCustomActivities( - Class type, Limit limit, ActivityMarker marker) throws StreamException { - return getCustomActivities( - type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); - } - - public CompletableFuture>> getCustomActivities( - Class type, Filter filter, ActivityMarker marker) throws StreamException { - return getCustomActivities( - type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker); - } - - public CompletableFuture>> getCustomActivities( - Class type, Offset offset, ActivityMarker marker) throws StreamException { - return getCustomActivities( - type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker); - } - - public CompletableFuture>> getCustomActivities( - Class type, Limit limit, Filter filter, ActivityMarker marker) throws StreamException { - return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, marker); - } - - public CompletableFuture>> getCustomActivities( - Class type, Limit limit, Offset offset, ActivityMarker marker) throws StreamException { - return getCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, marker); - } - - CompletableFuture>> getCustomActivities( - Class type, Limit limit, Offset offset, Filter filter, ActivityMarker marker) - throws StreamException { - return getClient() - .getActivities(getID(), limit, offset, filter, marker) - .thenApply( - (Response response) -> { - try { - return deserializeContainer(response, Group.class, type); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public CompletableFuture>> - getEnrichedActivities() throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities( - Limit limit) throws StreamException { - return getEnrichedActivities( - limit, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities( - EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER, - flags); - } - - public CompletableFuture>> getEnrichedActivities( - Offset offset) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, - offset, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities( - Filter filter) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - filter, - DefaultOptions.DEFAULT_MARKER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities( - ActivityMarker marker) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - marker, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities( - Limit limit, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities( - limit, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER, - flags); - } - - public CompletableFuture>> getEnrichedActivities( - Limit limit, Offset offset) throws StreamException { - return getEnrichedActivities( - limit, - offset, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities( - Limit limit, Filter filter) throws StreamException { - return getEnrichedActivities( - limit, - DefaultOptions.DEFAULT_OFFSET, - filter, - DefaultOptions.DEFAULT_MARKER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities( - Limit limit, ActivityMarker marker) throws StreamException { - return getEnrichedActivities( - limit, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - marker, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities( - Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, - offset, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER, - flags); - } - - public CompletableFuture>> getEnrichedActivities( - Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - filter, - DefaultOptions.DEFAULT_MARKER, - flags); - } - - public CompletableFuture>> getEnrichedActivities( - Filter filter, ActivityMarker marker) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - filter, - marker, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities( - Offset offset, ActivityMarker marker) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, - offset, - DefaultOptions.DEFAULT_FILTER, - marker, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities( - ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - marker, - flags); - } - - public CompletableFuture>> getEnrichedActivities( - Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities( - limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - public CompletableFuture>> getEnrichedActivities( - Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities( - limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); - } - - public CompletableFuture>> getEnrichedActivities( - Limit limit, Filter filter, ActivityMarker marker) throws StreamException { - return getEnrichedActivities( - limit, - DefaultOptions.DEFAULT_OFFSET, - filter, - marker, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities( - Limit limit, Offset offset, ActivityMarker marker) throws StreamException { - return getEnrichedActivities( - limit, - offset, - DefaultOptions.DEFAULT_FILTER, - marker, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedActivities( - Limit limit, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities( - limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - public CompletableFuture>> getEnrichedActivities( - Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); - } - - public CompletableFuture>> getEnrichedActivities( - Offset offset, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - public CompletableFuture>> getEnrichedActivities( - Limit limit, Filter filter, ActivityMarker marker, EnrichmentFlags flags) - throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); - } - - public CompletableFuture>> getEnrichedActivities( - Limit limit, Offset offset, ActivityMarker marker, EnrichmentFlags flags) - throws StreamException { - return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - CompletableFuture>> getEnrichedActivities( - Limit limit, Offset offset, Filter filter, ActivityMarker marker, EnrichmentFlags flags) - throws StreamException { - return getClient() - .getEnrichedActivities(getID(), limit, offset, filter, marker, flags) - .thenApply( - (Response response) -> { - try { - return deserializeContainer(response, Group.class, EnrichedActivity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public CompletableFuture>> getEnrichedCustomActivities( - Class type) throws StreamException { - return getEnrichedCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Limit limit) throws StreamException { - return getEnrichedCustomActivities( - type, - limit, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities( - Class type, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER, - flags); - } - - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Offset offset) throws StreamException { - return getEnrichedCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - offset, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Filter filter) throws StreamException { - return getEnrichedCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - filter, - DefaultOptions.DEFAULT_MARKER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities( - Class type, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - marker, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Limit limit, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities( - type, - limit, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER, - flags); - } - - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Limit limit, Offset offset) throws StreamException { - return getEnrichedCustomActivities( - type, - limit, - offset, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Limit limit, Filter filter) throws StreamException { - return getEnrichedCustomActivities( - type, - limit, - DefaultOptions.DEFAULT_OFFSET, - filter, - DefaultOptions.DEFAULT_MARKER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Limit limit, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities( - type, - limit, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - marker, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - offset, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER, - flags); - } - - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - filter, - DefaultOptions.DEFAULT_MARKER, - flags); - } - - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Filter filter, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - filter, - marker, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Offset offset, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - offset, - DefaultOptions.DEFAULT_FILTER, - marker, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities( - Class type, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - marker, - flags); - } - - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities( - type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities( - type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); - } - - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Limit limit, Filter filter, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities( - type, - limit, - DefaultOptions.DEFAULT_OFFSET, - filter, - marker, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Limit limit, Offset offset, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities( - type, - limit, - offset, - DefaultOptions.DEFAULT_FILTER, - marker, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Limit limit, ActivityMarker marker, EnrichmentFlags flags) - throws StreamException { - return getEnrichedCustomActivities( - type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Filter filter, ActivityMarker marker, EnrichmentFlags flags) - throws StreamException { - return getEnrichedCustomActivities( - type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); - } - - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Offset offset, ActivityMarker marker, EnrichmentFlags flags) - throws StreamException { - return getEnrichedCustomActivities( - type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Limit limit, Filter filter, ActivityMarker marker, EnrichmentFlags flags) - throws StreamException { - return getEnrichedCustomActivities( - type, limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); - } - - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Limit limit, Offset offset, ActivityMarker marker, EnrichmentFlags flags) - throws StreamException { - return getEnrichedCustomActivities( - type, limit, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - CompletableFuture>> getEnrichedCustomActivities( - Class type, - Limit limit, - Offset offset, - Filter filter, - ActivityMarker marker, - EnrichmentFlags flags) - throws StreamException { - return getClient() - .getEnrichedActivities(getID(), limit, offset, filter, marker, flags) - .thenApply( - (Response response) -> { - try { - return deserializeContainer(response, Group.class, type); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } + CloudAggregatedFeed(CloudClient client, FeedID id) { + super(client, id); + } + + CloudAggregatedFeed(CloudClient client, FeedID id, FeedSubscriber subscriber) { + super(client, id, subscriber); + } + + + public CompletableFuture>> getActivities() + throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getActivities(Limit limit) + throws StreamException { + return getActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getActivities(Offset offset) + throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getActivities(Filter filter) + throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getActivities( + ActivityMarker marker) throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker); + } + + public CompletableFuture>> getActivities( + Limit limit, Offset offset) throws StreamException { + return getActivities( + limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getActivities( + Limit limit, Filter filter) throws StreamException { + return getActivities( + limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getActivities( + Limit limit, ActivityMarker marker) throws StreamException { + return getActivities( + limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); + } + + public CompletableFuture>> getActivities( + Filter filter, ActivityMarker marker) throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker); + } + + public CompletableFuture>> getActivities( + Offset offset, ActivityMarker marker) throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker); + } + + public CompletableFuture>> getActivities( + Limit limit, Filter filter, ActivityMarker marker) throws StreamException { + return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, marker); + } + + public CompletableFuture>> getActivities( + Limit limit, Offset offset, ActivityMarker marker) throws StreamException { + return getActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, marker); + } + + CompletableFuture>> getActivities( + Limit limit, Offset offset, Filter filter, ActivityMarker marker) throws StreamException { + return getClient() + .getActivities(getID(), limit, offset, filter, marker) + .thenApply( + (Response response) -> { + try { + return deserializeContainer(response, Group.class, Activity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public CompletableFuture>> getCustomActivities( + Class type) throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getCustomActivities( + Class type, Limit limit) throws StreamException { + return getCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getCustomActivities( + Class type, Offset offset) throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getCustomActivities( + Class type, Filter filter) throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getCustomActivities( + Class type, ActivityMarker marker) throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker); + } + + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, Offset offset) throws StreamException { + return getCustomActivities( + type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, Filter filter) throws StreamException { + return getCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); + } + + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, ActivityMarker marker) throws StreamException { + return getCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); + } + + public CompletableFuture>> getCustomActivities( + Class type, Filter filter, ActivityMarker marker) throws StreamException { + return getCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker); + } + + public CompletableFuture>> getCustomActivities( + Class type, Offset offset, ActivityMarker marker) throws StreamException { + return getCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker); + } + + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, Filter filter, ActivityMarker marker) throws StreamException { + return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, marker); + } + + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, Offset offset, ActivityMarker marker) throws StreamException { + return getCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, marker); + } + + CompletableFuture>> getCustomActivities( + Class type, Limit limit, Offset offset, Filter filter, ActivityMarker marker) + throws StreamException { + return getClient() + .getActivities(getID(), limit, offset, filter, marker) + .thenApply( + (Response response) -> { + try { + return deserializeContainer(response, Group.class, type); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public CompletableFuture>> + getEnrichedActivities() throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + public CompletableFuture>> getEnrichedActivities( + Offset offset) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + Filter filter) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset) throws StreamException { + return getEnrichedActivities( + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, Filter filter) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + public CompletableFuture>> getEnrichedActivities( + Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + public CompletableFuture>> getEnrichedActivities( + Filter filter, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + Offset offset, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + flags); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, Filter filter, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + public CompletableFuture>> getEnrichedActivities( + Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); + } + + public CompletableFuture>> getEnrichedActivities( + Offset offset, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, Filter filter, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); + } + + public CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset, Filter filter, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getClient() + .getEnrichedActivities(getID(), limit, offset, filter, marker, flags) + .thenApply( + (Response response) -> { + try { + return deserializeContainer(response, Group.class, EnrichedActivity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Offset offset) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Filter filter) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Filter filter, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Offset offset, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Filter filter, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Offset offset, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); + } + + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, limit, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + CompletableFuture>> getEnrichedCustomActivities( + Class type, + Limit limit, + Offset offset, + Filter filter, + ActivityMarker marker, + EnrichmentFlags flags) + throws StreamException { + return getClient() + .getEnrichedActivities(getID(), limit, offset, filter, marker, flags) + .thenApply( + (Response response) -> { + try { + return deserializeContainer(response, Group.class, type); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } } diff --git a/src/main/java/io/getstream/cloud/CloudClient.java b/src/main/java/io/getstream/cloud/CloudClient.java index a157869a..c83d02ac 100644 --- a/src/main/java/io/getstream/cloud/CloudClient.java +++ b/src/main/java/io/getstream/cloud/CloudClient.java @@ -1,11 +1,17 @@ package io.getstream.cloud; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; import io.getstream.core.Region; import io.getstream.core.Stream; import io.getstream.core.exceptions.StreamException; +import io.getstream.core.faye.DefaultMessageTransformer; +import io.getstream.core.faye.Message; +import io.getstream.core.faye.client.FayeClient; +import io.getstream.core.faye.subscription.ChannelSubscription; import io.getstream.core.http.HTTPClient; import io.getstream.core.http.OKHTTPClientAdapter; import io.getstream.core.http.Response; @@ -14,261 +20,371 @@ import io.getstream.core.models.Data; import io.getstream.core.models.FeedID; import io.getstream.core.models.OGData; +import io.getstream.core.models.RealtimeMessage; import io.getstream.core.options.RequestOption; -import java.net.MalformedURLException; -import java.net.URL; +import io.getstream.core.utils.Serialization; import java8.util.concurrent.CompletableFuture; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + public final class CloudClient { - private final Token token; - private final String userID; - private final Stream stream; + private final String apiKey; + private final Token token; + private final String appID; + private final String userID; + private final Stream stream; + private final FayeClient faye; + + private CloudClient(String key, Token token, String userID, String appID, URL baseURL, HTTPClient httpClient, URL fayeURL) { + this.apiKey = key; + this.token = token; + this.appID = appID; + this.userID = userID; + this.stream = new Stream(key, baseURL, httpClient); + this.faye = new FayeClient(fayeURL); + this.faye.setMessageTransformer(new FayeMessageTransformer()); + } - private CloudClient(String key, Token token, String userID, URL baseURL, HTTPClient httpClient) { - this.token = token; - this.userID = userID; - this.stream = new Stream(key, baseURL, httpClient); - } + public static Builder builder(String apiKey, String token, String userID) { + return new Builder(apiKey, new Token(token), userID); + } - public static Builder builder(String apiKey, String token, String userID) { - return new Builder(apiKey, new Token(token), userID); - } + public static Builder builder(String apiKey, Token token, String userID) { + return new Builder(apiKey, token, userID); + } - public static Builder builder(String apiKey, Token token, String userID) { - return new Builder(apiKey, token, userID); - } + public static Builder builder(String apiKey, Token token, String userID, String appID) { + return new Builder(apiKey, token, userID, appID); + } - public CompletableFuture openGraph(URL url) throws StreamException { - return stream.openGraph(token, url); - } + public static final class Builder { + private static final String DEFAULT_HOST = "stream-io-api.com"; + private static final String DEFAULT_FAYE_URL = "https://faye-us-east.stream-io-api.com/faye"; + + private final String apiKey; + private final Token token; + private final String userID; + private final String appID; + private HTTPClient httpClient; + + private String scheme = "https"; + private String region = Region.US_EAST.toString(); + private String host = DEFAULT_HOST; + private int port = 443; + + private String fayeURL = DEFAULT_FAYE_URL; + + public Builder(String apiKey, Token token, String userID) { + checkNotNull(apiKey, "API key can't be null"); + checkNotNull(token, "Token can't be null"); + checkNotNull(userID, "User ID can't be null"); + checkArgument(!apiKey.isEmpty(), "API key can't be empty"); + checkArgument(!userID.isEmpty(), "User ID can't be empty"); + this.apiKey = apiKey; + this.token = token; + this.userID = userID; + this.appID = null; + } + + public Builder(String apiKey, Token token, String userID, String appID) { + checkNotNull(apiKey, "API key can't be null"); + checkNotNull(token, "Token can't be null"); + checkNotNull(userID, "User ID can't be null"); + checkArgument(!apiKey.isEmpty(), "API key can't be empty"); + checkArgument(!userID.isEmpty(), "User ID can't be empty"); + this.apiKey = apiKey; + this.token = token; + this.userID = userID; + this.appID = appID; + } + + + public Builder httpClient(HTTPClient httpClient) { + checkNotNull(httpClient, "HTTP client can't be null"); + this.httpClient = httpClient; + return this; + } + + public Builder scheme(String scheme) { + checkNotNull(scheme, "Scheme can't be null"); + checkArgument(!scheme.isEmpty(), "Scheme can't be empty"); + this.scheme = scheme; + return this; + } + + public Builder host(String host) { + checkNotNull(host, "Host can't be null"); + checkArgument(!host.isEmpty(), "Host can't be empty"); + this.host = host; + return this; + } + + public Builder port(int port) { + checkArgument(port > 0, "Port has to be a non-zero positive number"); + this.port = port; + return this; + } + + public Builder region(Region region) { + checkNotNull(region, "Region can't be null"); + this.region = region.toString(); + return this; + } + + public Builder region(String region) { + checkNotNull(region, "Region can't be null"); + checkArgument(!region.isEmpty(), "Region can't be empty"); + this.region = region; + return this; + } + + public Builder fayeURL(String fayeURL) { + checkNotNull(fayeURL, "FayeUrl can't be null"); + checkArgument(!fayeURL.isEmpty(), "FayeUrl can't be empty"); + this.fayeURL = fayeURL; + return this; + } + + private String buildHost() { + final StringBuilder sb = new StringBuilder(); + if (host.equals(DEFAULT_HOST)) { + sb.append(region).append("."); + } + sb.append(host); + return sb.toString(); + } + + public CloudClient build() throws MalformedURLException { + if (httpClient == null) { + httpClient = new OKHTTPClientAdapter(); + } + return new CloudClient( + apiKey, + token, + userID, + appID, + new URL(scheme, buildHost(), port, ""), + httpClient, + new URL(DEFAULT_FAYE_URL) + ); + } + } - public static final class Builder { - private static final String DEFAULT_HOST = "stream-io-api.com"; + private static class FeedSubscription { + private String token; + private String userId; + private ChannelSubscription channelSubscription; + + private FeedSubscription(String token, String userId) { + this.token = token; + this.userId = userId; + } + + private FeedSubscription(String token, String userId, ChannelSubscription subscription) { + this.token = token; + this.userId = userId; + this.channelSubscription = subscription; + } + } - private final String apiKey; - private final Token token; - private final String userID; - private HTTPClient httpClient; + private final Map feedSubscriptions = new HashMap<>(); + + private class FayeMessageTransformer extends DefaultMessageTransformer { + @Override + public Message transformRequest(Message message) { + final String subscription = message.getSubscription(); + if (feedSubscriptions.containsKey(subscription)) { + final FeedSubscription feedSubscription = feedSubscriptions.get(subscription); + final Map ext = new HashMap<>(); + ext.put("user_id", feedSubscription.userId); + ext.put("api_key", apiKey); + ext.put("signature", feedSubscription.token); + message.setExt(ext); + } + return message; + } + } + + + public T getHTTPClientImplementation() { + return stream.getHTTPClientImplementation(); + } + + public CompletableFuture openGraph(URL url) throws StreamException { + return stream.openGraph(token, url); + } + + private CompletableFuture feedSubscriber(FeedID feedId, RealtimeMessageCallback messageCallback) { + final CompletableFuture subscriberCompletion = new CompletableFuture<>(); + try { + checkNotNull(appID, "Missing app id, which is needed in order to subscribe feed"); + final String claim = feedId.getClaim(); + final String notificationChannel = "site" + "-" + appID + "-" + "feed" + "-" + claim; + final FeedSubscription subscription = new FeedSubscription(token.toString(), notificationChannel); + feedSubscriptions.put("/" + notificationChannel, subscription); + + final ChannelSubscription channelSubscription = faye.subscribe("/" + notificationChannel, data -> { + try { + final byte[] payload = Serialization.toJSON(data); + final RealtimeMessage message = Serialization.fromJSON(new String(payload), RealtimeMessage.class); + messageCallback.onMessage(message); + } catch (Exception e) { + e.printStackTrace(); + } + }, () -> feedSubscriptions.remove("/" + notificationChannel)).get(); + + subscription.channelSubscription = channelSubscription; + feedSubscriptions.put("/" + notificationChannel, subscription); + subscriberCompletion.complete(channelSubscription); + } catch (Exception e) { + subscriberCompletion.completeExceptionally(e); + } + return subscriberCompletion; + } - private String scheme = "https"; - private String region = Region.US_EAST.toString(); - private String host = DEFAULT_HOST; - private int port = 443; + // TODO: add personalized feed versions + public CloudFlatFeed flatFeed(String slug) { + return flatFeed(slug, userID); + } - public Builder(String apiKey, Token token, String userID) { - checkNotNull(apiKey, "API key can't be null"); - checkNotNull(token, "Token can't be null"); - checkNotNull(userID, "User ID can't be null"); - checkArgument(!apiKey.isEmpty(), "API key can't be empty"); - checkArgument(!userID.isEmpty(), "User ID can't be empty"); - this.apiKey = apiKey; - this.token = token; - this.userID = userID; + public CloudFlatFeed flatFeed(String slug, CloudUser user) { + return flatFeed(slug, user.getID()); } - public Builder httpClient(HTTPClient httpClient) { - checkNotNull(httpClient, "HTTP client can't be null"); - this.httpClient = httpClient; - return this; + public CloudFlatFeed flatFeed(String slug, String userID) { + return flatFeed(new FeedID(slug, userID)); } - public Builder scheme(String scheme) { - checkNotNull(scheme, "Scheme can't be null"); - checkArgument(!scheme.isEmpty(), "Scheme can't be empty"); - this.scheme = scheme; - return this; + public CloudFlatFeed flatFeed(FeedID id) { + return new CloudFlatFeed(this, id, this::feedSubscriber); } - public Builder host(String host) { - checkNotNull(host, "Host can't be null"); - checkArgument(!host.isEmpty(), "Host can't be empty"); - this.host = host; - return this; + public CloudAggregatedFeed aggregatedFeed(String slug) { + return aggregatedFeed(slug, userID); } - public Builder port(int port) { - checkArgument(port > 0, "Port has to be a non-zero positive number"); - this.port = port; - return this; + public CloudAggregatedFeed aggregatedFeed(String slug, CloudUser user) { + return aggregatedFeed(slug, user.getID()); } - public Builder region(Region region) { - checkNotNull(region, "Region can't be null"); - this.region = region.toString(); - return this; + public CloudAggregatedFeed aggregatedFeed(String slug, String userID) { + return aggregatedFeed(new FeedID(slug, userID)); } - public Builder region(String region) { - checkNotNull(region, "Region can't be null"); - checkArgument(!region.isEmpty(), "Region can't be empty"); - this.region = region; - return this; + public CloudAggregatedFeed aggregatedFeed(FeedID id) { + return new CloudAggregatedFeed(this, id, this::feedSubscriber); } - private String buildHost() { - final StringBuilder sb = new StringBuilder(); - if (host.equals(DEFAULT_HOST)) { - sb.append(region).append("."); - } - sb.append(host); - return sb.toString(); + public CloudNotificationFeed notificationFeed(String slug) { + return notificationFeed(slug, userID); } - public CloudClient build() throws MalformedURLException { - if (httpClient == null) { - httpClient = new OKHTTPClientAdapter(); - } - return new CloudClient( - apiKey, token, userID, new URL(scheme, buildHost(), port, ""), httpClient); + public CloudNotificationFeed notificationFeed(String slug, CloudUser user) { + return notificationFeed(slug, user.getID()); } - } - public T getHTTPClientImplementation() { - return stream.getHTTPClientImplementation(); - } + public CloudNotificationFeed notificationFeed(String slug, String userID) { + return notificationFeed(new FeedID(slug, userID)); + } - // TODO: add personalized feed versions - public CloudFlatFeed flatFeed(String slug) { - return flatFeed(slug, userID); - } - - public CloudFlatFeed flatFeed(String slug, CloudUser user) { - return flatFeed(slug, user.getID()); - } - - public CloudFlatFeed flatFeed(String slug, String userID) { - return flatFeed(new FeedID(slug, userID)); - } - - public CloudFlatFeed flatFeed(FeedID id) { - return new CloudFlatFeed(this, id); - } - - public CloudAggregatedFeed aggregatedFeed(String slug) { - return aggregatedFeed(slug, userID); - } - - public CloudAggregatedFeed aggregatedFeed(String slug, CloudUser user) { - return aggregatedFeed(slug, user.getID()); - } - - public CloudAggregatedFeed aggregatedFeed(String slug, String userID) { - return aggregatedFeed(new FeedID(slug, userID)); - } - - public CloudAggregatedFeed aggregatedFeed(FeedID id) { - return new CloudAggregatedFeed(this, id); - } + public CloudNotificationFeed notificationFeed(FeedID id) { + return new CloudNotificationFeed(this, id, this::feedSubscriber); + } - public CloudNotificationFeed notificationFeed(String slug) { - return notificationFeed(slug, userID); - } + public CloudUser user(String userID) { + return new CloudUser(this, userID); + } - public CloudNotificationFeed notificationFeed(String slug, CloudUser user) { - return notificationFeed(slug, user.getID()); - } + public CloudAnalyticsClient analytics() { + return new CloudAnalyticsClient(token, stream.analytics()); + } + + public CloudCollectionsClient collections() { + return new CloudCollectionsClient(token, userID, stream.collections()); + } - public CloudNotificationFeed notificationFeed(String slug, String userID) { - return notificationFeed(new FeedID(slug, userID)); - } - - public CloudNotificationFeed notificationFeed(FeedID id) { - return new CloudNotificationFeed(this, id); - } - - public CloudUser user(String userID) { - return new CloudUser(this, userID); - } - - public CloudAnalyticsClient analytics() { - return new CloudAnalyticsClient(token, stream.analytics()); - } - - public CloudCollectionsClient collections() { - return new CloudCollectionsClient(token, userID, stream.collections()); - } - - public CloudReactionsClient reactions() { - return new CloudReactionsClient(token, userID, stream.reactions()); - } - - public CloudFileStorageClient files() { - return new CloudFileStorageClient(token, stream.files()); - } - - public CloudImageStorageClient images() { - return new CloudImageStorageClient(token, stream.images()); - } - - CompletableFuture getActivities(FeedID feed, RequestOption... options) - throws StreamException { - return stream.getActivities(token, feed, options); - } - - CompletableFuture getEnrichedActivities(FeedID feed, RequestOption... options) - throws StreamException { - return stream.getEnrichedActivities(token, feed, options); - } - - CompletableFuture addActivity(FeedID feed, Activity activity) throws StreamException { - return stream.addActivity(token, feed, activity); - } - - CompletableFuture addActivities(FeedID feed, Activity... activities) - throws StreamException { - return stream.addActivities(token, feed, activities); - } - - CompletableFuture removeActivityByID(FeedID feed, String id) throws StreamException { - return stream.removeActivityByID(token, feed, id); - } - - CompletableFuture removeActivityByForeignID(FeedID feed, String foreignID) - throws StreamException { - return stream.removeActivityByForeignID(token, feed, foreignID); - } - - CompletableFuture follow(FeedID source, FeedID target, int activityCopyLimit) - throws StreamException { - return stream.follow(token, token, source, target, activityCopyLimit); - } - - CompletableFuture getFollowers(FeedID feed, RequestOption... options) - throws StreamException { - return stream.getFollowers(token, feed, options); - } - - CompletableFuture getFollowed(FeedID feed, RequestOption... options) - throws StreamException { - return stream.getFollowed(token, feed, options); - } - - CompletableFuture unfollow(FeedID source, FeedID target, RequestOption... options) - throws StreamException { - return stream.unfollow(token, source, target, options); - } - - CompletableFuture getUser(String id) throws StreamException { - return stream.getUser(token, id, false); - } - - CompletableFuture deleteUser(String id) throws StreamException { - return stream.deleteUser(token, id); - } - - CompletableFuture getOrCreateUser(String id, Data data) throws StreamException { - return stream.createUser(token, id, data, true); - } - - CompletableFuture createUser(String id, Data data) throws StreamException { - return stream.createUser(token, id, data, false); - } - - CompletableFuture updateUser(String id, Data data) throws StreamException { - return stream.updateUser(token, id, data); - } - - CompletableFuture userProfile(String id) throws StreamException { - return stream.getUser(token, id, true); - } + public CloudReactionsClient reactions() { + return new CloudReactionsClient(token, userID, stream.reactions()); + } + + public CloudFileStorageClient files() { + return new CloudFileStorageClient(token, stream.files()); + } + + public CloudImageStorageClient images() { + return new CloudImageStorageClient(token, stream.images()); + } + + CompletableFuture getActivities(FeedID feed, RequestOption... options) + throws StreamException { + return stream.getActivities(token, feed, options); + } + + CompletableFuture getEnrichedActivities(FeedID feed, RequestOption... options) + throws StreamException { + return stream.getEnrichedActivities(token, feed, options); + } + + CompletableFuture addActivity(FeedID feed, Activity activity) throws StreamException { + return stream.addActivity(token, feed, activity); + } + + CompletableFuture addActivities(FeedID feed, Activity... activities) + throws StreamException { + return stream.addActivities(token, feed, activities); + } + + CompletableFuture removeActivityByID(FeedID feed, String id) throws StreamException { + return stream.removeActivityByID(token, feed, id); + } + + CompletableFuture removeActivityByForeignID(FeedID feed, String foreignID) + throws StreamException { + return stream.removeActivityByForeignID(token, feed, foreignID); + } + + CompletableFuture follow(FeedID source, FeedID target, int activityCopyLimit) + throws StreamException { + return stream.follow(token, token, source, target, activityCopyLimit); + } + + CompletableFuture getFollowers(FeedID feed, RequestOption... options) + throws StreamException { + return stream.getFollowers(token, feed, options); + } + + CompletableFuture getFollowed(FeedID feed, RequestOption... options) + throws StreamException { + return stream.getFollowed(token, feed, options); + } + + CompletableFuture unfollow(FeedID source, FeedID target, RequestOption... options) + throws StreamException { + return stream.unfollow(token, source, target, options); + } + + CompletableFuture getUser(String id) throws StreamException { + return stream.getUser(token, id, false); + } + + CompletableFuture deleteUser(String id) throws StreamException { + return stream.deleteUser(token, id); + } + + CompletableFuture getOrCreateUser(String id, Data data) throws StreamException { + return stream.createUser(token, id, data, true); + } + + CompletableFuture createUser(String id, Data data) throws StreamException { + return stream.createUser(token, id, data, false); + } + + CompletableFuture updateUser(String id, Data data) throws StreamException { + return stream.updateUser(token, id, data); + } + + CompletableFuture userProfile(String id) throws StreamException { + return stream.getUser(token, id, true); + } } diff --git a/src/main/java/io/getstream/cloud/CloudFeed.java b/src/main/java/io/getstream/cloud/CloudFeed.java index d45537d0..302483f5 100644 --- a/src/main/java/io/getstream/cloud/CloudFeed.java +++ b/src/main/java/io/getstream/cloud/CloudFeed.java @@ -5,329 +5,350 @@ import static io.getstream.core.utils.Serialization.*; import com.google.common.collect.Iterables; + import io.getstream.core.exceptions.StreamException; +import io.getstream.core.faye.subscription.ChannelSubscription; import io.getstream.core.http.Response; import io.getstream.core.models.Activity; import io.getstream.core.models.FeedID; import io.getstream.core.models.FollowRelation; +import io.getstream.core.models.RealtimeMessage; import io.getstream.core.options.CustomQueryParameter; import io.getstream.core.options.Limit; import io.getstream.core.options.Offset; import io.getstream.core.options.RequestOption; import io.getstream.core.utils.DefaultOptions; import io.getstream.core.utils.Streams; + import java.io.IOException; import java.lang.reflect.ParameterizedType; import java.util.List; + import java8.util.J8Arrays; import java8.util.concurrent.CompletableFuture; import java8.util.concurrent.CompletionException; public class CloudFeed { - private final CloudClient client; - private final FeedID id; - - CloudFeed(CloudClient client, FeedID id) { - checkNotNull(client, "Can't create feed w/o a client"); - checkNotNull(id, "Can't create feed w/o an ID"); - - this.client = client; - this.id = id; - } - - protected final CloudClient getClient() { - return client; - } - - public final FeedID getID() { - return id; - } - - public final String getSlug() { - return id.getSlug(); - } - - public final String getUserID() { - return id.getUserID(); - } - - public final CompletableFuture addActivity(Activity activity) throws StreamException { - return getClient() - .addActivity(id, activity) - .thenApply( - response -> { - try { - return deserialize(response, Activity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture addCustomActivity(T activity) throws StreamException { - return getClient() - .addActivity(id, Activity.builder().fromCustomActivity(activity).build()) - .thenApply( - response -> { - try { - return deserialize(response, (Class) activity.getClass()); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture> addActivities(Iterable activities) - throws StreamException { - return addActivities(Iterables.toArray(activities, Activity.class)); - } - - public final CompletableFuture> addCustomActivities(Iterable activities) - throws StreamException { - final Activity[] custom = - Streams.stream(activities) - .map(activity -> Activity.builder().fromCustomActivity(activity).build()) - .toArray(Activity[]::new); - return getClient() - .addActivities(id, custom) - .thenApply( - (Response response) -> { - try { - Class element = - (Class) - ((ParameterizedType) getClass().getGenericSuperclass()) - .getActualTypeArguments()[0]; - return deserializeContainer(response, "activities", element); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture> addActivities(Activity... activities) - throws StreamException { - return getClient() - .addActivities(id, activities) - .thenApply( - (Response response) -> { - try { - return deserializeContainer(response, "activities", Activity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture> addCustomActivities(T... activities) - throws StreamException { - final Activity[] custom = - J8Arrays.stream(activities) - .map(activity -> Activity.builder().fromCustomActivity(activity).build()) - .toArray(Activity[]::new); - return getClient() - .addActivities(id, custom) - .thenApply( - (Response response) -> { - try { - Class element = (Class) activities.getClass().getComponentType(); - return deserializeContainer(response, "activities", element); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture removeActivityByID(String id) throws StreamException { - return client - .removeActivityByID(this.id, id) - .thenApply( - (Response response) -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture removeActivityByForeignID(String foreignID) - throws StreamException { - return client - .removeActivityByForeignID(id, foreignID) - .thenApply( - (Response response) -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture follow(CloudFlatFeed feed) throws StreamException { - return follow(feed, DefaultOptions.DEFAULT_ACTIVITY_COPY_LIMIT); - } - - public final CompletableFuture follow(CloudFlatFeed feed, int activityCopyLimit) - throws StreamException { - checkArgument( - activityCopyLimit <= DefaultOptions.MAX_ACTIVITY_COPY_LIMIT, - String.format( - "Activity copy limit should be less then %d", DefaultOptions.MAX_ACTIVITY_COPY_LIMIT)); - - return client - .follow(id, feed.getID(), activityCopyLimit) - .thenApply( - (Response response) -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture> getFollowers(Iterable feedIDs) - throws StreamException { - return getFollowers( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - Iterables.toArray(feedIDs, FeedID.class)); - } - - public final CompletableFuture> getFollowers(FeedID... feedIDs) - throws StreamException { - return getFollowers(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, feedIDs); - } - - public final CompletableFuture> getFollowers( - Limit limit, Iterable feedIDs) throws StreamException { - return getFollowers( - limit, DefaultOptions.DEFAULT_OFFSET, Iterables.toArray(feedIDs, FeedID.class)); - } - - public final CompletableFuture> getFollowers(Limit limit, FeedID... feedIDs) - throws StreamException { - return getFollowers(limit, DefaultOptions.DEFAULT_OFFSET, feedIDs); - } - - public final CompletableFuture> getFollowers( - Offset offset, Iterable feedIDs) throws StreamException { - return getFollowers( - DefaultOptions.DEFAULT_LIMIT, offset, Iterables.toArray(feedIDs, FeedID.class)); - } - - public final CompletableFuture> getFollowers( - Offset offset, FeedID... feedIDs) throws StreamException { - return getFollowers(DefaultOptions.DEFAULT_LIMIT, offset, feedIDs); - } - - public final CompletableFuture> getFollowers( - Limit limit, Offset offset, Iterable feedIDs) throws StreamException { - return getFollowers(limit, offset, Iterables.toArray(feedIDs, FeedID.class)); - } - - public final CompletableFuture> getFollowers( - Limit limit, Offset offset, FeedID... feeds) throws StreamException { - checkNotNull(feeds, "No feed ids to filter on"); - - final String[] feedIDs = J8Arrays.stream(feeds).map(id -> id.toString()).toArray(String[]::new); - final RequestOption[] options = - feedIDs.length == 0 - ? new RequestOption[] {limit, offset} - : new RequestOption[] { - limit, offset, new CustomQueryParameter("filter", String.join(",", feedIDs)) - }; - return client - .getFollowers(id, options) - .thenApply( - (Response response) -> { - try { - return deserializeContainer(response, FollowRelation.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture> getFollowed(Iterable feedIDs) - throws StreamException { - return getFollowed( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - Iterables.toArray(feedIDs, FeedID.class)); - } - - public final CompletableFuture> getFollowed(FeedID... feedIDs) - throws StreamException { - return getFollowed(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, feedIDs); - } - - public final CompletableFuture> getFollowed( - Limit limit, Iterable feedIDs) throws StreamException { - return getFollowed( - limit, DefaultOptions.DEFAULT_OFFSET, Iterables.toArray(feedIDs, FeedID.class)); - } - - public final CompletableFuture> getFollowed(Limit limit, FeedID... feedIDs) - throws StreamException { - return getFollowed(limit, DefaultOptions.DEFAULT_OFFSET, feedIDs); - } - - public final CompletableFuture> getFollowed( - Offset offset, Iterable feedIDs) throws StreamException { - return getFollowed( - DefaultOptions.DEFAULT_LIMIT, offset, Iterables.toArray(feedIDs, FeedID.class)); - } - - public final CompletableFuture> getFollowed(Offset offset, FeedID... feedIDs) - throws StreamException { - return getFollowed(DefaultOptions.DEFAULT_LIMIT, offset, feedIDs); - } - - public final CompletableFuture> getFollowed( - Limit limit, Offset offset, Iterable feedIDs) throws StreamException { - return getFollowed(limit, offset, Iterables.toArray(feedIDs, FeedID.class)); - } - - public final CompletableFuture> getFollowed( - Limit limit, Offset offset, FeedID... feeds) throws StreamException { - checkNotNull(feeds, "No feed ids to filter on"); - - final String[] feedIDs = J8Arrays.stream(feeds).map(id -> id.toString()).toArray(String[]::new); - final RequestOption[] options = - feedIDs.length == 0 - ? new RequestOption[] {limit, offset} - : new RequestOption[] { - limit, offset, new CustomQueryParameter("filter", String.join(",", feedIDs)) - }; - return client - .getFollowed(id, options) - .thenApply( - (Response response) -> { - try { - return deserializeContainer(response, FollowRelation.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public final CompletableFuture unfollow(CloudFlatFeed feed) throws StreamException { - return unfollow(feed, io.getstream.core.KeepHistory.NO); - } - - public final CompletableFuture unfollow( - CloudFlatFeed feed, io.getstream.core.KeepHistory keepHistory) throws StreamException { - return client - .unfollow(id, feed.getID(), new io.getstream.core.options.KeepHistory(keepHistory)) - .thenApply( - (Response response) -> { - try { - return deserializeError(response); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } + private final CloudClient client; + private final FeedID id; + private final FeedSubscriber subscriber; + + CloudFeed(CloudClient client, FeedID id) { + checkNotNull(client, "Can't create feed w/o a client"); + checkNotNull(id, "Can't create feed w/o an ID"); + + this.client = client; + this.id = id; + this.subscriber = null; + } + + CloudFeed(CloudClient client, FeedID id, FeedSubscriber subscriber) { + checkNotNull(client, "Can't create feed w/o a client"); + checkNotNull(id, "Can't create feed w/o an ID"); + + this.client = client; + this.id = id; + this.subscriber = subscriber; + } + + protected final CloudClient getClient() { + return client; + } + + public final FeedID getID() { + return id; + } + + public final String getSlug() { + return id.getSlug(); + } + + public final String getUserID() { + return id.getUserID(); + } + + public final CompletableFuture subscribe(RealtimeMessageCallback messageCallback) { + checkNotNull(subscriber, "A subscriber must be provided in order to start listening to a feed"); + return subscriber.subscribe(id, messageCallback); + } + + public final CompletableFuture addActivity(Activity activity) throws StreamException { + return getClient() + .addActivity(id, activity) + .thenApply( + response -> { + try { + return deserialize(response, Activity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture addCustomActivity(T activity) throws StreamException { + return getClient() + .addActivity(id, Activity.builder().fromCustomActivity(activity).build()) + .thenApply( + response -> { + try { + return deserialize(response, (Class) activity.getClass()); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture> addActivities(Iterable activities) + throws StreamException { + return addActivities(Iterables.toArray(activities, Activity.class)); + } + + public final CompletableFuture> addCustomActivities(Iterable activities) + throws StreamException { + final Activity[] custom = + Streams.stream(activities) + .map(activity -> Activity.builder().fromCustomActivity(activity).build()) + .toArray(Activity[]::new); + return getClient() + .addActivities(id, custom) + .thenApply( + (Response response) -> { + try { + Class element = + (Class) + ((ParameterizedType) getClass().getGenericSuperclass()) + .getActualTypeArguments()[0]; + return deserializeContainer(response, "activities", element); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture> addActivities(Activity... activities) + throws StreamException { + return getClient() + .addActivities(id, activities) + .thenApply( + (Response response) -> { + try { + return deserializeContainer(response, "activities", Activity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture> addCustomActivities(T... activities) + throws StreamException { + final Activity[] custom = + J8Arrays.stream(activities) + .map(activity -> Activity.builder().fromCustomActivity(activity).build()) + .toArray(Activity[]::new); + return getClient() + .addActivities(id, custom) + .thenApply( + (Response response) -> { + try { + Class element = (Class) activities.getClass().getComponentType(); + return deserializeContainer(response, "activities", element); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture removeActivityByID(String id) throws StreamException { + return client + .removeActivityByID(this.id, id) + .thenApply( + (Response response) -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture removeActivityByForeignID(String foreignID) + throws StreamException { + return client + .removeActivityByForeignID(id, foreignID) + .thenApply( + (Response response) -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture follow(CloudFlatFeed feed) throws StreamException { + return follow(feed, DefaultOptions.DEFAULT_ACTIVITY_COPY_LIMIT); + } + + public final CompletableFuture follow(CloudFlatFeed feed, int activityCopyLimit) + throws StreamException { + checkArgument( + activityCopyLimit <= DefaultOptions.MAX_ACTIVITY_COPY_LIMIT, + String.format( + "Activity copy limit should be less then %d", DefaultOptions.MAX_ACTIVITY_COPY_LIMIT)); + + return client + .follow(id, feed.getID(), activityCopyLimit) + .thenApply( + (Response response) -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture> getFollowers(Iterable feedIDs) + throws StreamException { + return getFollowers( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + Iterables.toArray(feedIDs, FeedID.class)); + } + + public final CompletableFuture> getFollowers(FeedID... feedIDs) + throws StreamException { + return getFollowers(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, feedIDs); + } + + public final CompletableFuture> getFollowers( + Limit limit, Iterable feedIDs) throws StreamException { + return getFollowers( + limit, DefaultOptions.DEFAULT_OFFSET, Iterables.toArray(feedIDs, FeedID.class)); + } + + public final CompletableFuture> getFollowers(Limit limit, FeedID... feedIDs) + throws StreamException { + return getFollowers(limit, DefaultOptions.DEFAULT_OFFSET, feedIDs); + } + + public final CompletableFuture> getFollowers( + Offset offset, Iterable feedIDs) throws StreamException { + return getFollowers( + DefaultOptions.DEFAULT_LIMIT, offset, Iterables.toArray(feedIDs, FeedID.class)); + } + + public final CompletableFuture> getFollowers( + Offset offset, FeedID... feedIDs) throws StreamException { + return getFollowers(DefaultOptions.DEFAULT_LIMIT, offset, feedIDs); + } + + public final CompletableFuture> getFollowers( + Limit limit, Offset offset, Iterable feedIDs) throws StreamException { + return getFollowers(limit, offset, Iterables.toArray(feedIDs, FeedID.class)); + } + + public final CompletableFuture> getFollowers( + Limit limit, Offset offset, FeedID... feeds) throws StreamException { + checkNotNull(feeds, "No feed ids to filter on"); + + final String[] feedIDs = J8Arrays.stream(feeds).map(id -> id.toString()).toArray(String[]::new); + final RequestOption[] options = + feedIDs.length == 0 + ? new RequestOption[]{limit, offset} + : new RequestOption[]{ + limit, offset, new CustomQueryParameter("filter", String.join(",", feedIDs)) + }; + return client + .getFollowers(id, options) + .thenApply( + (Response response) -> { + try { + return deserializeContainer(response, FollowRelation.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture> getFollowed(Iterable feedIDs) + throws StreamException { + return getFollowed( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + Iterables.toArray(feedIDs, FeedID.class)); + } + + public final CompletableFuture> getFollowed(FeedID... feedIDs) + throws StreamException { + return getFollowed(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, feedIDs); + } + + public final CompletableFuture> getFollowed( + Limit limit, Iterable feedIDs) throws StreamException { + return getFollowed( + limit, DefaultOptions.DEFAULT_OFFSET, Iterables.toArray(feedIDs, FeedID.class)); + } + + public final CompletableFuture> getFollowed(Limit limit, FeedID... feedIDs) + throws StreamException { + return getFollowed(limit, DefaultOptions.DEFAULT_OFFSET, feedIDs); + } + + public final CompletableFuture> getFollowed( + Offset offset, Iterable feedIDs) throws StreamException { + return getFollowed( + DefaultOptions.DEFAULT_LIMIT, offset, Iterables.toArray(feedIDs, FeedID.class)); + } + + public final CompletableFuture> getFollowed(Offset offset, FeedID... feedIDs) + throws StreamException { + return getFollowed(DefaultOptions.DEFAULT_LIMIT, offset, feedIDs); + } + + public final CompletableFuture> getFollowed( + Limit limit, Offset offset, Iterable feedIDs) throws StreamException { + return getFollowed(limit, offset, Iterables.toArray(feedIDs, FeedID.class)); + } + + public final CompletableFuture> getFollowed( + Limit limit, Offset offset, FeedID... feeds) throws StreamException { + checkNotNull(feeds, "No feed ids to filter on"); + + final String[] feedIDs = J8Arrays.stream(feeds).map(id -> id.toString()).toArray(String[]::new); + final RequestOption[] options = + feedIDs.length == 0 + ? new RequestOption[]{limit, offset} + : new RequestOption[]{ + limit, offset, new CustomQueryParameter("filter", String.join(",", feedIDs)) + }; + return client + .getFollowed(id, options) + .thenApply( + (Response response) -> { + try { + return deserializeContainer(response, FollowRelation.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public final CompletableFuture unfollow(CloudFlatFeed feed) throws StreamException { + return unfollow(feed, io.getstream.core.KeepHistory.NO); + } + + public final CompletableFuture unfollow( + CloudFlatFeed feed, io.getstream.core.KeepHistory keepHistory) throws StreamException { + return client + .unfollow(id, feed.getID(), new io.getstream.core.options.KeepHistory(keepHistory)) + .thenApply( + (Response response) -> { + try { + return deserializeError(response); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } } diff --git a/src/main/java/io/getstream/cloud/CloudFlatFeed.java b/src/main/java/io/getstream/cloud/CloudFlatFeed.java index 2b6987f8..827e1be4 100644 --- a/src/main/java/io/getstream/cloud/CloudFlatFeed.java +++ b/src/main/java/io/getstream/cloud/CloudFlatFeed.java @@ -9,653 +9,659 @@ import io.getstream.core.models.FeedID; import io.getstream.core.options.*; import io.getstream.core.utils.DefaultOptions; + import java.io.IOException; import java.util.List; + import java8.util.concurrent.CompletableFuture; import java8.util.concurrent.CompletionException; public final class CloudFlatFeed extends CloudFeed { - CloudFlatFeed(CloudClient client, FeedID id) { - super(client, id); - } - - public CompletableFuture> getActivities() throws StreamException { - return getActivities( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - null); - } - - public CompletableFuture> getActivities(Limit limit) throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, null); - } - - public CompletableFuture> getActivities(String ranking) throws StreamException { - return getActivities( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - ranking); - } - - public CompletableFuture> getActivities(Filter filter) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, null); - } - - public CompletableFuture> getActivities(Offset offset) throws StreamException { - return getActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, null); - } - - public CompletableFuture> getActivities(Limit limit, String ranking) - throws StreamException { - return getActivities( - limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, ranking); - } - - public CompletableFuture> getActivities(Limit limit, Filter filter) - throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, null); - } - - public CompletableFuture> getActivities(Limit limit, Offset offset) - throws StreamException { - return getActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, null); - } - - public CompletableFuture> getActivities(Filter filter, String ranking) - throws StreamException { - return getActivities( - DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, ranking); - } - - public CompletableFuture> getActivities(Offset offset, String ranking) - throws StreamException { - return getActivities( - DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, ranking); - } - - public CompletableFuture> getActivities(Limit limit, Filter filter, String ranking) - throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, ranking); - } - - public CompletableFuture> getActivities(Limit limit, Offset offset, String ranking) - throws StreamException { - return getActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, ranking); - } - - CompletableFuture> getActivities( - Limit limit, Offset offset, Filter filter, String ranking) throws StreamException { - final RequestOption[] options = - ranking == null - ? new RequestOption[] {limit, offset, filter, DefaultOptions.DEFAULT_MARKER} - : new RequestOption[] { - limit, offset, filter, DefaultOptions.DEFAULT_MARKER, new Ranking(ranking) - }; - return getClient() - .getActivities(getID(), options) - .thenApply( - (Response response) -> { - try { - return deserializeContainer(response, Activity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public CompletableFuture> getCustomActivities(Class type) throws StreamException { - return getCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - null); - } - - public CompletableFuture> getCustomActivities(Class type, Limit limit) - throws StreamException { - return getCustomActivities( - type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, null); - } - - public CompletableFuture> getCustomActivities(Class type, String ranking) - throws StreamException { - return getCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - ranking); - } - - public CompletableFuture> getCustomActivities(Class type, Filter filter) - throws StreamException { - return getCustomActivities( - type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, null); - } - - public CompletableFuture> getCustomActivities(Class type, Offset offset) - throws StreamException { - return getCustomActivities( - type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, null); - } - - public CompletableFuture> getCustomActivities( - Class type, Limit limit, String ranking) throws StreamException { - return getCustomActivities( - type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, ranking); - } - - public CompletableFuture> getCustomActivities( - Class type, Limit limit, Filter filter) throws StreamException { - return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, null); - } - - public CompletableFuture> getCustomActivities( - Class type, Limit limit, Offset offset) throws StreamException { - return getCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, null); - } - - public CompletableFuture> getCustomActivities( - Class type, Offset offset, String ranking) throws StreamException { - return getCustomActivities( - type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, ranking); - } - - public CompletableFuture> getCustomActivities( - Class type, Filter filter, String ranking) throws StreamException { - return getCustomActivities( - type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, ranking); - } - - public CompletableFuture> getCustomActivities( - Class type, Limit limit, Offset offset, String ranking) throws StreamException { - return getCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, ranking); - } - - public CompletableFuture> getCustomActivities( - Class type, Limit limit, Filter filter, String ranking) throws StreamException { - return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, ranking); - } - - CompletableFuture> getCustomActivities( - Class type, Limit limit, Offset offset, Filter filter, String ranking) - throws StreamException { - final RequestOption[] options = - ranking == null - ? new RequestOption[] {limit, offset, filter, DefaultOptions.DEFAULT_MARKER} - : new RequestOption[] { - limit, offset, filter, DefaultOptions.DEFAULT_MARKER, new Ranking(ranking) - }; - return getClient() - .getActivities(getID(), options) - .thenApply( - (Response response) -> { - try { - return deserializeContainer(response, type); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public CompletableFuture> getEnrichedActivities() throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, - null); - } - - public CompletableFuture> getEnrichedActivities(Limit limit) - throws StreamException { - return getEnrichedActivities( - limit, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, - null); - } - - public CompletableFuture> getEnrichedActivities(EnrichmentFlags flags) - throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - flags, - null); - } - - public CompletableFuture> getEnrichedActivities( - Limit limit, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities( - limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, null); - } - - public CompletableFuture> getEnrichedActivities(String ranking) - throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, - ranking); - } - - public CompletableFuture> getEnrichedActivities( - Limit limit, String ranking) throws StreamException { - return getEnrichedActivities( - limit, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, - ranking); - } - - public CompletableFuture> getEnrichedActivities( - EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - flags, - ranking); - } - - public CompletableFuture> getEnrichedActivities( - Limit limit, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedActivities( - limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, ranking); - } - - public CompletableFuture> getEnrichedActivities(Filter filter) - throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - filter, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, - null); - } - - public CompletableFuture> getEnrichedActivities(Limit limit, Filter filter) - throws StreamException { - return getEnrichedActivities( - limit, - DefaultOptions.DEFAULT_OFFSET, - filter, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, - null); - } - - public CompletableFuture> getEnrichedActivities( - Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, flags, null); - } - - public CompletableFuture> getEnrichedActivities( - Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, flags, null); - } - - public CompletableFuture> getEnrichedActivities(Offset offset) - throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, - offset, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, - null); - } - - public CompletableFuture> getEnrichedActivities(Limit limit, Offset offset) - throws StreamException { - return getEnrichedActivities( - limit, - offset, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, - null); - } - - public CompletableFuture> getEnrichedActivities( - Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, flags, null); - } - - public CompletableFuture> getEnrichedActivities( - Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, flags, null); - } - - public CompletableFuture> getEnrichedActivities( - Filter filter, String ranking) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - filter, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, - ranking); - } - - public CompletableFuture> getEnrichedActivities( - Limit limit, Filter filter, String ranking) throws StreamException { - return getEnrichedActivities( - limit, - DefaultOptions.DEFAULT_OFFSET, - filter, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, - ranking); - } - - public CompletableFuture> getEnrichedActivities( - Filter filter, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, flags, ranking); - } - - public CompletableFuture> getEnrichedActivities( - Limit limit, Filter filter, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, flags, ranking); - } - - public CompletableFuture> getEnrichedActivities( - Offset offset, String ranking) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, - offset, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, - ranking); - } - - public CompletableFuture> getEnrichedActivities( - Limit limit, Offset offset, String ranking) throws StreamException { - return getEnrichedActivities( - limit, - offset, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, - ranking); - } - - public CompletableFuture> getEnrichedActivities( - Offset offset, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, flags, ranking); - } - - public CompletableFuture> getEnrichedActivities( - Limit limit, Offset offset, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, flags, ranking); - } - - CompletableFuture> getEnrichedActivities( - Limit limit, Offset offset, Filter filter, EnrichmentFlags flags, String ranking) - throws StreamException { - final RequestOption[] options = - ranking == null - ? new RequestOption[] {limit, offset, filter, flags, DefaultOptions.DEFAULT_MARKER} - : new RequestOption[] { - limit, offset, filter, flags, DefaultOptions.DEFAULT_MARKER, new Ranking(ranking) - }; - return getClient() - .getEnrichedActivities(getID(), options) - .thenApply( - (Response response) -> { - try { - return deserializeContainer(response, EnrichedActivity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type) - throws StreamException { - return getEnrichedCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, - null); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit) - throws StreamException { - return getEnrichedCustomActivities( - type, - limit, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, - null); - } - - public CompletableFuture> getEnrichedCustomActivities( - Class type, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - flags, - null); - } - - public CompletableFuture> getEnrichedCustomActivities( - Class type, Limit limit, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities( - type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, null); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, String ranking) - throws StreamException { - return getEnrichedCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, - ranking); - } - - public CompletableFuture> getEnrichedCustomActivities( - Class type, Limit limit, String ranking) throws StreamException { - return getEnrichedCustomActivities( - type, - limit, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, - ranking); - } - - public CompletableFuture> getEnrichedCustomActivities( - Class type, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - flags, - ranking); - } - - public CompletableFuture> getEnrichedCustomActivities( - Class type, Limit limit, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedCustomActivities( - type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, ranking); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Filter filter) - throws StreamException { - return getEnrichedCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - filter, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, - null); - } - - public CompletableFuture> getEnrichedCustomActivities( - Class type, Limit limit, Filter filter) throws StreamException { - return getEnrichedCustomActivities( - type, - limit, - DefaultOptions.DEFAULT_OFFSET, - filter, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, - null); - } - - public CompletableFuture> getEnrichedCustomActivities( - Class type, Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities( - type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, flags, null); - } - - public CompletableFuture> getEnrichedCustomActivities( - Class type, Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities( - type, limit, DefaultOptions.DEFAULT_OFFSET, filter, flags, null); - } - - public CompletableFuture> getEnrichedCustomActivities(Class type, Offset offset) - throws StreamException { - return getEnrichedCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - offset, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, - null); - } - - public CompletableFuture> getEnrichedCustomActivities( - Class type, Limit limit, Offset offset) throws StreamException { - return getEnrichedCustomActivities( - type, - limit, - offset, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, - null); - } - - public CompletableFuture> getEnrichedCustomActivities( - Class type, Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities( - type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, flags, null); - } - - public CompletableFuture> getEnrichedCustomActivities( - Class type, Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities( - type, limit, offset, DefaultOptions.DEFAULT_FILTER, flags, null); - } - - public CompletableFuture> getEnrichedCustomActivities( - Class type, Offset offset, String ranking) throws StreamException { - return getEnrichedCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - offset, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, - ranking); - } - - public CompletableFuture> getEnrichedCustomActivities( - Class type, Limit limit, Offset offset, String ranking) throws StreamException { - return getEnrichedCustomActivities( - type, - limit, - offset, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, - ranking); - } - - public CompletableFuture> getEnrichedCustomActivities( - Class type, Offset offset, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedCustomActivities( - type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, flags, ranking); - } - - public CompletableFuture> getEnrichedCustomActivities( - Class type, Limit limit, Offset offset, EnrichmentFlags flags, String ranking) - throws StreamException { - return getEnrichedCustomActivities( - type, limit, offset, DefaultOptions.DEFAULT_FILTER, flags, ranking); - } - - public CompletableFuture> getEnrichedCustomActivities( - Class type, Filter filter, String ranking) throws StreamException { - return getEnrichedCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - filter, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, - ranking); - } - - public CompletableFuture> getEnrichedCustomActivities( - Class type, Limit limit, Filter filter, String ranking) throws StreamException { - return getEnrichedCustomActivities( - type, - limit, - DefaultOptions.DEFAULT_OFFSET, - filter, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, - ranking); - } - - public CompletableFuture> getEnrichedCustomActivities( - Class type, Filter filter, EnrichmentFlags flags, String ranking) throws StreamException { - return getEnrichedCustomActivities( - type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, flags, ranking); - } - - public CompletableFuture> getEnrichedCustomActivities( - Class type, Limit limit, Filter filter, EnrichmentFlags flags, String ranking) - throws StreamException { - return getEnrichedCustomActivities( - type, limit, DefaultOptions.DEFAULT_OFFSET, filter, flags, ranking); - } - - CompletableFuture> getEnrichedCustomActivities( - Class type, - Limit limit, - Offset offset, - Filter filter, - EnrichmentFlags flags, - String ranking) - throws StreamException { - final RequestOption[] options = - ranking == null - ? new RequestOption[] {limit, offset, filter, flags, DefaultOptions.DEFAULT_MARKER} - : new RequestOption[] { - limit, offset, filter, flags, DefaultOptions.DEFAULT_MARKER, new Ranking(ranking) - }; - return getClient() - .getActivities(getID(), options) - .thenApply( - (Response response) -> { - try { - return deserializeContainer(response, type); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } + CloudFlatFeed(CloudClient client, FeedID id) { + super(client, id); + } + + CloudFlatFeed(CloudClient client, FeedID id, FeedSubscriber subscriber) { + super(client, id, subscriber); + } + + public CompletableFuture> getActivities() throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + null); + } + + public CompletableFuture> getActivities(Limit limit) throws StreamException { + return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, null); + } + + public CompletableFuture> getActivities(String ranking) throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + ranking); + } + + public CompletableFuture> getActivities(Filter filter) throws StreamException { + return getActivities(DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, null); + } + + public CompletableFuture> getActivities(Offset offset) throws StreamException { + return getActivities(DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, null); + } + + public CompletableFuture> getActivities(Limit limit, String ranking) + throws StreamException { + return getActivities( + limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, ranking); + } + + public CompletableFuture> getActivities(Limit limit, Filter filter) + throws StreamException { + return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, null); + } + + public CompletableFuture> getActivities(Limit limit, Offset offset) + throws StreamException { + return getActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, null); + } + + public CompletableFuture> getActivities(Filter filter, String ranking) + throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, ranking); + } + + public CompletableFuture> getActivities(Offset offset, String ranking) + throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, ranking); + } + + public CompletableFuture> getActivities(Limit limit, Filter filter, String ranking) + throws StreamException { + return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, ranking); + } + + public CompletableFuture> getActivities(Limit limit, Offset offset, String ranking) + throws StreamException { + return getActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, ranking); + } + + CompletableFuture> getActivities( + Limit limit, Offset offset, Filter filter, String ranking) throws StreamException { + final RequestOption[] options = + ranking == null + ? new RequestOption[]{limit, offset, filter, DefaultOptions.DEFAULT_MARKER} + : new RequestOption[]{ + limit, offset, filter, DefaultOptions.DEFAULT_MARKER, new Ranking(ranking) + }; + return getClient() + .getActivities(getID(), options) + .thenApply( + (Response response) -> { + try { + return deserializeContainer(response, Activity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public CompletableFuture> getCustomActivities(Class type) throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + null); + } + + public CompletableFuture> getCustomActivities(Class type, Limit limit) + throws StreamException { + return getCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, null); + } + + public CompletableFuture> getCustomActivities(Class type, String ranking) + throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + ranking); + } + + public CompletableFuture> getCustomActivities(Class type, Filter filter) + throws StreamException { + return getCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, null); + } + + public CompletableFuture> getCustomActivities(Class type, Offset offset) + throws StreamException { + return getCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, null); + } + + public CompletableFuture> getCustomActivities( + Class type, Limit limit, String ranking) throws StreamException { + return getCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, ranking); + } + + public CompletableFuture> getCustomActivities( + Class type, Limit limit, Filter filter) throws StreamException { + return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, null); + } + + public CompletableFuture> getCustomActivities( + Class type, Limit limit, Offset offset) throws StreamException { + return getCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, null); + } + + public CompletableFuture> getCustomActivities( + Class type, Offset offset, String ranking) throws StreamException { + return getCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, ranking); + } + + public CompletableFuture> getCustomActivities( + Class type, Filter filter, String ranking) throws StreamException { + return getCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, ranking); + } + + public CompletableFuture> getCustomActivities( + Class type, Limit limit, Offset offset, String ranking) throws StreamException { + return getCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, ranking); + } + + public CompletableFuture> getCustomActivities( + Class type, Limit limit, Filter filter, String ranking) throws StreamException { + return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, ranking); + } + + CompletableFuture> getCustomActivities( + Class type, Limit limit, Offset offset, Filter filter, String ranking) + throws StreamException { + final RequestOption[] options = + ranking == null + ? new RequestOption[]{limit, offset, filter, DefaultOptions.DEFAULT_MARKER} + : new RequestOption[]{ + limit, offset, filter, DefaultOptions.DEFAULT_MARKER, new Ranking(ranking) + }; + return getClient() + .getActivities(getID(), options) + .thenApply( + (Response response) -> { + try { + return deserializeContainer(response, type); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public CompletableFuture> getEnrichedActivities() throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedActivities(Limit limit) + throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedActivities(EnrichmentFlags flags) + throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + flags, + null); + } + + public CompletableFuture> getEnrichedActivities( + Limit limit, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, null); + } + + public CompletableFuture> getEnrichedActivities(String ranking) + throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedActivities( + Limit limit, String ranking) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedActivities( + EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + flags, + ranking); + } + + public CompletableFuture> getEnrichedActivities( + Limit limit, EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedActivities( + limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, ranking); + } + + public CompletableFuture> getEnrichedActivities(Filter filter) + throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedActivities(Limit limit, Filter filter) + throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedActivities( + Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, flags, null); + } + + public CompletableFuture> getEnrichedActivities( + Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, flags, null); + } + + public CompletableFuture> getEnrichedActivities(Offset offset) + throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedActivities(Limit limit, Offset offset) + throws StreamException { + return getEnrichedActivities( + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedActivities( + Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, flags, null); + } + + public CompletableFuture> getEnrichedActivities( + Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, flags, null); + } + + public CompletableFuture> getEnrichedActivities( + Filter filter, String ranking) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedActivities( + Limit limit, Filter filter, String ranking) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedActivities( + Filter filter, EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, flags, ranking); + } + + public CompletableFuture> getEnrichedActivities( + Limit limit, Filter filter, EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, flags, ranking); + } + + public CompletableFuture> getEnrichedActivities( + Offset offset, String ranking) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedActivities( + Limit limit, Offset offset, String ranking) throws StreamException { + return getEnrichedActivities( + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedActivities( + Offset offset, EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, flags, ranking); + } + + public CompletableFuture> getEnrichedActivities( + Limit limit, Offset offset, EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, flags, ranking); + } + + CompletableFuture> getEnrichedActivities( + Limit limit, Offset offset, Filter filter, EnrichmentFlags flags, String ranking) + throws StreamException { + final RequestOption[] options = + ranking == null + ? new RequestOption[]{limit, offset, filter, flags, DefaultOptions.DEFAULT_MARKER} + : new RequestOption[]{ + limit, offset, filter, flags, DefaultOptions.DEFAULT_MARKER, new Ranking(ranking) + }; + return getClient() + .getEnrichedActivities(getID(), options) + .thenApply( + (Response response) -> { + try { + return deserializeContainer(response, EnrichedActivity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + public CompletableFuture> getEnrichedCustomActivities(Class type) + throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedCustomActivities(Class type, Limit limit) + throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + flags, + null); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, null); + } + + public CompletableFuture> getEnrichedCustomActivities(Class type, String ranking) + throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, String ranking) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + flags, + ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, flags, ranking); + } + + public CompletableFuture> getEnrichedCustomActivities(Class type, Filter filter) + throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, flags, null); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, filter, flags, null); + } + + public CompletableFuture> getEnrichedCustomActivities(Class type, Offset offset) + throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + null); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, flags, null); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, limit, offset, DefaultOptions.DEFAULT_FILTER, flags, null); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Offset offset, String ranking) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset, String ranking) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Offset offset, EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, flags, ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset, EnrichmentFlags flags, String ranking) + throws StreamException { + return getEnrichedCustomActivities( + type, limit, offset, DefaultOptions.DEFAULT_FILTER, flags, ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Filter filter, String ranking) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter, String ranking) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS, + ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Filter filter, EnrichmentFlags flags, String ranking) throws StreamException { + return getEnrichedCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, flags, ranking); + } + + public CompletableFuture> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter, EnrichmentFlags flags, String ranking) + throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, filter, flags, ranking); + } + + CompletableFuture> getEnrichedCustomActivities( + Class type, + Limit limit, + Offset offset, + Filter filter, + EnrichmentFlags flags, + String ranking) + throws StreamException { + final RequestOption[] options = + ranking == null + ? new RequestOption[]{limit, offset, filter, flags, DefaultOptions.DEFAULT_MARKER} + : new RequestOption[]{ + limit, offset, filter, flags, DefaultOptions.DEFAULT_MARKER, new Ranking(ranking) + }; + return getClient() + .getActivities(getID(), options) + .thenApply( + (Response response) -> { + try { + return deserializeContainer(response, type); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } } diff --git a/src/main/java/io/getstream/cloud/CloudNotificationFeed.java b/src/main/java/io/getstream/cloud/CloudNotificationFeed.java index 9834d9e2..82853904 100644 --- a/src/main/java/io/getstream/cloud/CloudNotificationFeed.java +++ b/src/main/java/io/getstream/cloud/CloudNotificationFeed.java @@ -10,775 +10,781 @@ import io.getstream.core.models.NotificationGroup; import io.getstream.core.options.*; import io.getstream.core.utils.DefaultOptions; + import java.io.IOException; import java.util.List; + import java8.util.concurrent.CompletableFuture; import java8.util.concurrent.CompletionException; public final class CloudNotificationFeed extends CloudAggregatedFeed { - CloudNotificationFeed(CloudClient client, FeedID id) { - super(client, id); - } - - @Override - public CompletableFuture>> getActivities() - throws StreamException { - return getActivities( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getActivities(Limit limit) - throws StreamException { - return getActivities( - limit, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getActivities(Offset offset) - throws StreamException { - return getActivities( - DefaultOptions.DEFAULT_LIMIT, - offset, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getActivities(Filter filter) - throws StreamException { - return getActivities( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - filter, - DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getActivities(ActivityMarker marker) - throws StreamException { - return getActivities( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - marker); - } - - @Override - public CompletableFuture>> getActivities( - Limit limit, Offset offset) throws StreamException { - return getActivities( - limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getActivities( - Limit limit, Filter filter) throws StreamException { - return getActivities( - limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getActivities( - Limit limit, ActivityMarker marker) throws StreamException { - return getActivities( - limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); - } - - @Override - public CompletableFuture>> getActivities( - Filter filter, ActivityMarker marker) throws StreamException { - return getActivities( - DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker); - } - - @Override - public CompletableFuture>> getActivities( - Offset offset, ActivityMarker marker) throws StreamException { - return getActivities( - DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker); - } - - @Override - public CompletableFuture>> getActivities( - Limit limit, Filter filter, ActivityMarker marker) throws StreamException { - return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, marker); - } - - @Override - public CompletableFuture>> getActivities( - Limit limit, Offset offset, ActivityMarker marker) throws StreamException { - return getActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, marker); - } - - @Override - CompletableFuture>> getActivities( - Limit limit, Offset offset, Filter filter, ActivityMarker marker) throws StreamException { - return getClient() - .getActivities(getID(), limit, offset, filter, marker) - .thenApply( - (Response response) -> { - try { - return deserializeContainer(response, NotificationGroup.class, Activity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - @Override - public CompletableFuture>> getCustomActivities(Class type) - throws StreamException { - return getCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getCustomActivities( - Class type, Limit limit) throws StreamException { - return getCustomActivities( - type, - limit, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getCustomActivities( - Class type, Offset offset) throws StreamException { - return getCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - offset, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getCustomActivities( - Class type, Filter filter) throws StreamException { - return getCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - filter, - DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getCustomActivities( - Class type, ActivityMarker marker) throws StreamException { - return getCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - marker); - } - - @Override - public CompletableFuture>> getCustomActivities( - Class type, Limit limit, Offset offset) throws StreamException { - return getCustomActivities( - type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getCustomActivities( - Class type, Limit limit, Filter filter) throws StreamException { - return getCustomActivities( - type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); - } - - @Override - public CompletableFuture>> getCustomActivities( - Class type, Limit limit, ActivityMarker marker) throws StreamException { - return getCustomActivities( - type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); - } - - @Override - public CompletableFuture>> getCustomActivities( - Class type, Filter filter, ActivityMarker marker) throws StreamException { - return getCustomActivities( - type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker); - } - - @Override - public CompletableFuture>> getCustomActivities( - Class type, Offset offset, ActivityMarker marker) throws StreamException { - return getCustomActivities( - type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker); - } - - @Override - public CompletableFuture>> getCustomActivities( - Class type, Limit limit, Filter filter, ActivityMarker marker) throws StreamException { - return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, marker); - } - - @Override - public CompletableFuture>> getCustomActivities( - Class type, Limit limit, Offset offset, ActivityMarker marker) throws StreamException { - return getCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, marker); - } - - @Override - CompletableFuture>> getCustomActivities( - Class type, Limit limit, Offset offset, Filter filter, ActivityMarker marker) - throws StreamException { - return getClient() - .getActivities(getID(), limit, offset, filter, marker) - .thenApply( - (Response response) -> { - try { - return deserializeContainer(response, NotificationGroup.class, type); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - @Override - public CompletableFuture>> getEnrichedActivities() - throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities( - Limit limit) throws StreamException { - return getEnrichedActivities( - limit, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities( - EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER, - flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities( - Offset offset) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, - offset, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities( - Filter filter) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - filter, - DefaultOptions.DEFAULT_MARKER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities( - ActivityMarker marker) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - marker, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities( - Limit limit, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities( - limit, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER, - flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities( - Limit limit, Offset offset) throws StreamException { - return getEnrichedActivities( - limit, - offset, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities( - Limit limit, Filter filter) throws StreamException { - return getEnrichedActivities( - limit, - DefaultOptions.DEFAULT_OFFSET, - filter, - DefaultOptions.DEFAULT_MARKER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities( - Limit limit, ActivityMarker marker) throws StreamException { - return getEnrichedActivities( - limit, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - marker, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities( - Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, - offset, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER, - flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities( - Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - filter, - DefaultOptions.DEFAULT_MARKER, - flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities( - ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - marker, - flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities( - Filter filter, ActivityMarker marker) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - filter, - marker, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities( - Offset offset, ActivityMarker marker) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, - offset, - DefaultOptions.DEFAULT_FILTER, - marker, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities( - Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities( - limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities( - Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities( - limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities( - Limit limit, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities( - limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities( - Limit limit, Filter filter, ActivityMarker marker) throws StreamException { - return getEnrichedActivities( - limit, - DefaultOptions.DEFAULT_OFFSET, - filter, - marker, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities( - Limit limit, Offset offset, ActivityMarker marker) throws StreamException { - return getEnrichedActivities( - limit, - offset, - DefaultOptions.DEFAULT_FILTER, - marker, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedActivities( - Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities( - Offset offset, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedActivities( - DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities( - Limit limit, Filter filter, ActivityMarker marker, EnrichmentFlags flags) - throws StreamException { - return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); - } - - @Override - public CompletableFuture>> getEnrichedActivities( - Limit limit, Offset offset, ActivityMarker marker, EnrichmentFlags flags) - throws StreamException { - return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - @Override - CompletableFuture>> getEnrichedActivities( - Limit limit, Offset offset, Filter filter, ActivityMarker marker, EnrichmentFlags flags) - throws StreamException { - return getClient() - .getEnrichedActivities(getID(), limit, offset, filter, marker, flags) - .thenApply( - (Response response) -> { - try { - return deserializeContainer( - response, NotificationGroup.class, EnrichedActivity.class); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities( - Class type) throws StreamException { - return getEnrichedCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Limit limit) throws StreamException { - return getEnrichedCustomActivities( - type, - limit, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities( - Class type, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER, - flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Offset offset) throws StreamException { - return getEnrichedCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - offset, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Filter filter) throws StreamException { - return getEnrichedCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - filter, - DefaultOptions.DEFAULT_MARKER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities( - Class type, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - marker, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Limit limit, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities( - type, - limit, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER, - flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Limit limit, Offset offset) throws StreamException { - return getEnrichedCustomActivities( - type, - limit, - offset, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Limit limit, Filter filter) throws StreamException { - return getEnrichedCustomActivities( - type, - limit, - DefaultOptions.DEFAULT_OFFSET, - filter, - DefaultOptions.DEFAULT_MARKER, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Limit limit, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities( - type, - limit, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - marker, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - offset, - DefaultOptions.DEFAULT_FILTER, - DefaultOptions.DEFAULT_MARKER, - flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - filter, - DefaultOptions.DEFAULT_MARKER, - flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities( - Class type, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - DefaultOptions.DEFAULT_FILTER, - marker, - flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Filter filter, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - DefaultOptions.DEFAULT_OFFSET, - filter, - marker, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Offset offset, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities( - type, - DefaultOptions.DEFAULT_LIMIT, - offset, - DefaultOptions.DEFAULT_FILTER, - marker, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities( - type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { - return getEnrichedCustomActivities( - type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Limit limit, ActivityMarker marker, EnrichmentFlags flags) - throws StreamException { - return getEnrichedCustomActivities( - type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Limit limit, Filter filter, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities( - type, - limit, - DefaultOptions.DEFAULT_OFFSET, - filter, - marker, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Limit limit, Offset offset, ActivityMarker marker) throws StreamException { - return getEnrichedCustomActivities( - type, - limit, - offset, - DefaultOptions.DEFAULT_FILTER, - marker, - DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Filter filter, ActivityMarker marker, EnrichmentFlags flags) - throws StreamException { - return getEnrichedCustomActivities( - type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Offset offset, ActivityMarker marker, EnrichmentFlags flags) - throws StreamException { - return getEnrichedCustomActivities( - type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Limit limit, Filter filter, ActivityMarker marker, EnrichmentFlags flags) - throws StreamException { - return getEnrichedCustomActivities( - type, limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); - } - - @Override - public CompletableFuture>> getEnrichedCustomActivities( - Class type, Limit limit, Offset offset, ActivityMarker marker, EnrichmentFlags flags) - throws StreamException { - return getEnrichedCustomActivities( - type, limit, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); - } - - @Override - CompletableFuture>> getEnrichedCustomActivities( - Class type, - Limit limit, - Offset offset, - Filter filter, - ActivityMarker marker, - EnrichmentFlags flags) - throws StreamException { - return getClient() - .getEnrichedActivities(getID(), limit, offset, filter, marker, flags) - .thenApply( - (Response response) -> { - try { - return deserializeContainer(response, NotificationGroup.class, type); - } catch (StreamException | IOException e) { - throw new CompletionException(e); - } - }); - } + CloudNotificationFeed(CloudClient client, FeedID id) { + super(client, id); + } + + CloudNotificationFeed(CloudClient client, FeedID id, FeedSubscriber subscriber) { + super(client, id, subscriber); + } + + @Override + public CompletableFuture>> getActivities() + throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getActivities(Limit limit) + throws StreamException { + return getActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getActivities(Offset offset) + throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getActivities(Filter filter) + throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getActivities(ActivityMarker marker) + throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker); + } + + @Override + public CompletableFuture>> getActivities( + Limit limit, Offset offset) throws StreamException { + return getActivities( + limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getActivities( + Limit limit, Filter filter) throws StreamException { + return getActivities( + limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getActivities( + Limit limit, ActivityMarker marker) throws StreamException { + return getActivities( + limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); + } + + @Override + public CompletableFuture>> getActivities( + Filter filter, ActivityMarker marker) throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker); + } + + @Override + public CompletableFuture>> getActivities( + Offset offset, ActivityMarker marker) throws StreamException { + return getActivities( + DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker); + } + + @Override + public CompletableFuture>> getActivities( + Limit limit, Filter filter, ActivityMarker marker) throws StreamException { + return getActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, marker); + } + + @Override + public CompletableFuture>> getActivities( + Limit limit, Offset offset, ActivityMarker marker) throws StreamException { + return getActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, marker); + } + + @Override + CompletableFuture>> getActivities( + Limit limit, Offset offset, Filter filter, ActivityMarker marker) throws StreamException { + return getClient() + .getActivities(getID(), limit, offset, filter, marker) + .thenApply( + (Response response) -> { + try { + return deserializeContainer(response, NotificationGroup.class, Activity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + @Override + public CompletableFuture>> getCustomActivities(Class type) + throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Limit limit) throws StreamException { + return getCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Offset offset) throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Filter filter) throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, ActivityMarker marker) throws StreamException { + return getCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, Offset offset) throws StreamException { + return getCustomActivities( + type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, Filter filter) throws StreamException { + return getCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, ActivityMarker marker) throws StreamException { + return getCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Filter filter, ActivityMarker marker) throws StreamException { + return getCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Offset offset, ActivityMarker marker) throws StreamException { + return getCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, Filter filter, ActivityMarker marker) throws StreamException { + return getCustomActivities(type, limit, DefaultOptions.DEFAULT_OFFSET, filter, marker); + } + + @Override + public CompletableFuture>> getCustomActivities( + Class type, Limit limit, Offset offset, ActivityMarker marker) throws StreamException { + return getCustomActivities(type, limit, offset, DefaultOptions.DEFAULT_FILTER, marker); + } + + @Override + CompletableFuture>> getCustomActivities( + Class type, Limit limit, Offset offset, Filter filter, ActivityMarker marker) + throws StreamException { + return getClient() + .getActivities(getID(), limit, offset, filter, marker) + .thenApply( + (Response response) -> { + try { + return deserializeContainer(response, NotificationGroup.class, type); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + @Override + public CompletableFuture>> getEnrichedActivities() + throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Offset offset) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Filter filter) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset) throws StreamException { + return getEnrichedActivities( + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, Filter filter) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Filter filter, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Offset offset, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, Filter filter, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset, ActivityMarker marker) throws StreamException { + return getEnrichedActivities( + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Filter filter, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Offset offset, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedActivities( + DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, Filter filter, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedActivities(limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); + } + + @Override + public CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedActivities(limit, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + @Override + CompletableFuture>> getEnrichedActivities( + Limit limit, Offset offset, Filter filter, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getClient() + .getEnrichedActivities(getID(), limit, offset, filter, marker, flags) + .thenApply( + (Response response) -> { + try { + return deserializeContainer( + response, NotificationGroup.class, EnrichedActivity.class); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Offset offset) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Filter filter) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + DefaultOptions.DEFAULT_MARKER, + flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, ActivityMarker marker, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + DefaultOptions.DEFAULT_FILTER, + marker, + flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Filter filter, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + DefaultOptions.DEFAULT_OFFSET, + filter, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Offset offset, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + DefaultOptions.DEFAULT_LIMIT, + offset, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, limit, offset, DefaultOptions.DEFAULT_FILTER, DefaultOptions.DEFAULT_MARKER, flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter, EnrichmentFlags flags) throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, filter, DefaultOptions.DEFAULT_MARKER, flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + DefaultOptions.DEFAULT_OFFSET, + filter, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset, ActivityMarker marker) throws StreamException { + return getEnrichedCustomActivities( + type, + limit, + offset, + DefaultOptions.DEFAULT_FILTER, + marker, + DefaultOptions.DEFAULT_ENRICHMENT_FLAGS); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Filter filter, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Offset offset, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, DefaultOptions.DEFAULT_LIMIT, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Filter filter, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, limit, DefaultOptions.DEFAULT_OFFSET, filter, marker, flags); + } + + @Override + public CompletableFuture>> getEnrichedCustomActivities( + Class type, Limit limit, Offset offset, ActivityMarker marker, EnrichmentFlags flags) + throws StreamException { + return getEnrichedCustomActivities( + type, limit, offset, DefaultOptions.DEFAULT_FILTER, marker, flags); + } + + @Override + CompletableFuture>> getEnrichedCustomActivities( + Class type, + Limit limit, + Offset offset, + Filter filter, + ActivityMarker marker, + EnrichmentFlags flags) + throws StreamException { + return getClient() + .getEnrichedActivities(getID(), limit, offset, filter, marker, flags) + .thenApply( + (Response response) -> { + try { + return deserializeContainer(response, NotificationGroup.class, type); + } catch (StreamException | IOException e) { + throw new CompletionException(e); + } + }); + } } diff --git a/src/main/java/io/getstream/cloud/FeedSubscriber.java b/src/main/java/io/getstream/cloud/FeedSubscriber.java new file mode 100644 index 00000000..66f9fd36 --- /dev/null +++ b/src/main/java/io/getstream/cloud/FeedSubscriber.java @@ -0,0 +1,10 @@ +package io.getstream.cloud; + +import io.getstream.core.faye.subscription.ChannelSubscription; +import io.getstream.core.models.FeedID; +import java8.util.concurrent.CompletableFuture; + + +public interface FeedSubscriber { + CompletableFuture subscribe(FeedID feedID, RealtimeMessageCallback messageCallback); +} diff --git a/src/main/java/io/getstream/cloud/RealtimeMessageCallback.java b/src/main/java/io/getstream/cloud/RealtimeMessageCallback.java new file mode 100644 index 00000000..9ed9255c --- /dev/null +++ b/src/main/java/io/getstream/cloud/RealtimeMessageCallback.java @@ -0,0 +1,7 @@ +package io.getstream.cloud; + +import io.getstream.core.models.RealtimeMessage; + +public interface RealtimeMessageCallback { + void onMessage(RealtimeMessage message); +} diff --git a/src/main/java/io/getstream/core/faye/Advice.java b/src/main/java/io/getstream/core/faye/Advice.java new file mode 100644 index 00000000..dc6d425d --- /dev/null +++ b/src/main/java/io/getstream/core/faye/Advice.java @@ -0,0 +1,69 @@ +package io.getstream.core.faye; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.google.common.base.MoreObjects; + +import java.util.Objects; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Advice { + private final String reconnect; + private final Integer interval; + private final Integer timeout; + + public static final String NONE = "none"; + public static final String HANDSHAKE = "handshake"; + public static final String RETRY = "retry"; + + // for deserialization + public Advice() { + reconnect = null; + interval = null; + timeout = null; + } + + public Advice(String reconnect, Integer interval, Integer timeout) { + this.reconnect = reconnect; + this.interval = interval; + this.timeout = timeout; + } + + public String getReconnect() { + return reconnect; + } + + public Integer getInterval() { + return interval; + } + + public Integer getTimeout() { + return timeout; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Advice that = (Advice) o; + return Objects.equals(reconnect, that.reconnect) + && Objects.equals(interval, that.interval) + && Objects.equals(timeout, that.timeout); + } + + @Override + public int hashCode() { + return Objects.hash(reconnect, interval, timeout); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .omitNullValues() + .add("reconnect", this.reconnect) + .add("interval", this.interval) + .add("timeout", this.timeout) + .toString(); + } +} diff --git a/src/main/java/io/getstream/core/faye/Channel.java b/src/main/java/io/getstream/core/faye/Channel.java new file mode 100644 index 00000000..93fbce1c --- /dev/null +++ b/src/main/java/io/getstream/core/faye/Channel.java @@ -0,0 +1,124 @@ +package io.getstream.core.faye; + +import com.google.common.base.MoreObjects; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; + +import io.getstream.core.faye.emitter.EventEmitter; +import io.getstream.core.faye.emitter.EventListener; + +public class Channel { + + public static final String HANDSHAKE = "/meta/handshake"; + public static final String CONNECT = "/meta/connect"; + public static final String DISCONNECT = "/meta/disconnect"; + public static final String SUBSCRIBE = "/meta/subscribe"; + public static final String UNSUBSCRIBE = "/meta/unsubscribe"; + + private final String name; + + public Channel(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + final EventEmitter eventEmitter = new EventEmitter<>(); + + public void bind(String event, EventListener listener) { + eventEmitter.on(event, listener); + } + + public void unbind(String event, EventListener listener) { + eventEmitter.removeListener(event, listener); + } + + public void trigger(String event, Message message) { + eventEmitter.emit(event, message); + } + + public boolean hasListeners(String event) throws Exception { + return eventEmitter.hasListeners(event); + } + + public static List expand(String name) { + final List channels = new ArrayList<>(Arrays.asList("/**", name)); + final List segments = parse(name); + + if (segments == null) return null; + + List copy = new ArrayList<>(segments); + copy.add(copy.size() - 1, "*"); + channels.add(unparse(copy)); + + for (int i = 1; i < segments.size(); i++) { + copy = segments.subList(0, i); + copy.add("**"); + channels.add(unparse(copy)); + } + + return channels; + } + + public static boolean isValid(String name) { + return Grammar.CHANNEL_NAME.matcher(name).matches() || Grammar.CHANNEL_PATTERN.matcher(name).matches(); + } + + public static List parse(String name) { + if (!isValid(name)) return null; + final String[] splits = name.split("/"); + return Arrays.asList(splits).subList(1, splits.length); + } + + public static String unparse(List segments) { + final String joinedSegments = String.join("/", segments); + return "/" + joinedSegments; + } + + public static Boolean isMeta(String name) { + final List segments = parse(name); + if (segments == null) return null; + return segments.get(0).equals("meta"); + } + + public static Boolean isService(String name) { + final List segments = parse(name); + if (segments == null) return null; + return segments.get(0).equals("service"); + } + + public static Boolean isSubscribable(String name) { + if (!isValid(name)) return null; + final Boolean isMeta = isMeta(name); + final Boolean isService = isService(name); + if (isMeta == null || isService == null) return null; + return !isMeta && !isService; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Channel that = (Channel) o; + return Objects.equals(name, that.name); + } + + @Override + public int hashCode() { + return Objects.hash(name); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .omitNullValues() + .add("name", this.name) + .toString(); + + } +} diff --git a/src/main/java/io/getstream/core/faye/DefaultMessageTransformer.java b/src/main/java/io/getstream/core/faye/DefaultMessageTransformer.java new file mode 100644 index 00000000..b1bef791 --- /dev/null +++ b/src/main/java/io/getstream/core/faye/DefaultMessageTransformer.java @@ -0,0 +1,13 @@ +package io.getstream.core.faye; + +public class DefaultMessageTransformer extends MessageTransformer { + @Override + public Message transformRequest(Message message) { + return message; + } + + @Override + public Message transformResponse(Message message) { + return message; + } +} diff --git a/src/main/java/io/getstream/core/faye/FayeClientError.java b/src/main/java/io/getstream/core/faye/FayeClientError.java new file mode 100644 index 00000000..d3c04f96 --- /dev/null +++ b/src/main/java/io/getstream/core/faye/FayeClientError.java @@ -0,0 +1,58 @@ +package io.getstream.core.faye; + +import com.google.common.base.MoreObjects; + +import java.util.Arrays; +import java.util.List; +import java.util.Objects; + +public class FayeClientError extends Throwable { + private final Integer code; + private final List params; + private final String errorMessage; + + public FayeClientError(Integer code, List params, String errorMessage) { + this.code = code; + this.params = params; + this.errorMessage = errorMessage; + } + + public static FayeClientError parse(String errorMessage) { + if (errorMessage == null) errorMessage = ""; + if (!Grammar.ERROR.matcher(errorMessage).matches()) { + return new FayeClientError(null, null, errorMessage); + } + + final List parts = Arrays.asList(errorMessage.split(":")); + final Integer code = Integer.parseInt(parts.get(0)); + final List params = Arrays.asList(parts.get(1).split(",")); + final String message = parts.get(2); + + return new FayeClientError(code, params, message); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + FayeClientError that = (FayeClientError) o; + return Objects.equals(code, that.code) + && Objects.equals(params, that.params) + && Objects.equals(errorMessage, that.errorMessage); + } + + @Override + public int hashCode() { + return Objects.hash(code, params, errorMessage); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .omitNullValues() + .add("code", this.code) + .add("params", this.params) + .add("errorMessage", this.errorMessage) + .toString(); + } +} diff --git a/src/main/java/io/getstream/core/faye/Grammar.java b/src/main/java/io/getstream/core/faye/Grammar.java new file mode 100644 index 00000000..4eb19d0f --- /dev/null +++ b/src/main/java/io/getstream/core/faye/Grammar.java @@ -0,0 +1,10 @@ +package io.getstream.core.faye; + +import java.util.regex.Pattern; + +public class Grammar { + static final Pattern CHANNEL_NAME = Pattern.compile("^\\/(((([a-z]|[A-Z])|[0-9])|(\\-|\\_|\\!|\\~|\\(|\\)|\\$|\\@)))+(\\/(((([a-z]|[A-Z])|[0-9])|(\\-|\\_|\\!|\\~|\\(|\\)|\\$|\\@)))+)*$", Pattern.MULTILINE); + static final Pattern CHANNEL_PATTERN = Pattern.compile("^(\\/(((([a-z]|[A-Z])|[0-9])|(\\-|\\_|\\!|\\~|\\(|\\)|\\$|\\@)))+)*\\/\\*{1,2}$"); + static final Pattern ERROR = Pattern.compile("^([0-9][0-9][0-9]:(((([a-z]|[A-Z])|[0-9])|(\\-|\\_|\\!|\\~|\\(|\\)|\\$|\\@)| |\\/|\\*|\\.))*(,(((([a-z]|[A-Z])|[0-9])|(\\-|\\_|\\!|\\~|\\(|\\)|\\$|\\@)| |\\/|\\*|\\.))*)*:(((([a-z]|[A-Z])|[0-9])|(\\-|\\_|\\!|\\~|\\(|\\)|\\$|\\@)| |\\/|\\*|\\.))*|[0-9][0-9][0-9]::(((([a-z]|[A-Z])|[0-9])|(\\-|\\_|\\!|\\~|\\(|\\)|\\$|\\@)| |\\/|\\*|\\.))*)$"); + static final Pattern VERSION = Pattern.compile("^([0-9])+(\\.(([a-z]|[A-Z])|[0-9])(((([a-z]|[A-Z])|[0-9])|\\-|\\_))*)*$"); +} \ No newline at end of file diff --git a/src/main/java/io/getstream/core/faye/Message.java b/src/main/java/io/getstream/core/faye/Message.java new file mode 100644 index 00000000..474aea1c --- /dev/null +++ b/src/main/java/io/getstream/core/faye/Message.java @@ -0,0 +1,170 @@ +package io.getstream.core.faye; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.google.common.base.MoreObjects; + +import java.util.Map; +import java.util.Objects; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Message { + private String id; + private final String channel; + private String clientId; + private String connectionType; + private String version; + private String minimumVersion; + private String[] supportedConnectionTypes; + private Advice advice; + private Boolean successful; + private String subscription; + private Map data; + private Map ext; + private String error; + + // for deserialization + public Message() { + this.channel = null; + } + + + public Message(String channel) { + this.channel = channel; + } + + public void setId(String id) { + this.id = id; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public void setConnectionType(String connectionType) { + this.connectionType = connectionType; + } + + public void setVersion(String version) { + this.version = version; + } + + public void setMinimumVersion(String minimumVersion) { + this.minimumVersion = minimumVersion; + } + + public void setSupportedConnectionTypes(String[] supportedConnectionTypes) { + this.supportedConnectionTypes = supportedConnectionTypes; + } + + public void setAdvice(Advice advice) { + this.advice = advice; + } + + public void setSuccessful(Boolean successful) { + this.successful = successful; + } + + public void setSubscription(String subscription) { + this.subscription = subscription; + } + + public void setData(Map data) { + this.data = data; + } + + public void setExt(Map ext) { + this.ext = ext; + } + + public void setError(String error) { + this.error = error; + } + + public String getId() { + return id; + } + + public String getChannel() { + return channel; + } + + public String getClientId() { + return clientId; + } + + public String getConnectionType() { + return connectionType; + } + + public String getVersion() { + return version; + } + + public String getMinimumVersion() { + return minimumVersion; + } + + public String[] getSupportedConnectionTypes() { + return supportedConnectionTypes; + } + + public Advice getAdvice() { + return advice; + } + + public Boolean isSuccessful() { + return successful; + } + + public String getSubscription() { + return subscription; + } + + public Map getData() { + return data; + } + + public Map getExt() { + return ext; + } + + public String getError() { + return error; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Message that = (Message) o; + return Objects.equals(id, that.id) + && Objects.equals(channel, that.channel) + && Objects.equals(clientId, that.clientId); + } + + @Override + public int hashCode() { + return Objects.hash(id, channel, clientId); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .omitNullValues() + .add("id", this.id) + .add("channel", this.channel) + .add("clientId", this.clientId) + .add("connectionType", this.connectionType) + .add("version", this.version) + .add("minimumVersion", this.minimumVersion) + .add("supportedConnectionTypes", this.supportedConnectionTypes) + .add("advice", this.advice) + .add("successful", this.successful) + .add("data", this.data) + .add("ext", this.ext) + .add("error", this.error) + .toString(); + } +} diff --git a/src/main/java/io/getstream/core/faye/MessageTransformer.java b/src/main/java/io/getstream/core/faye/MessageTransformer.java new file mode 100644 index 00000000..178c55ea --- /dev/null +++ b/src/main/java/io/getstream/core/faye/MessageTransformer.java @@ -0,0 +1,7 @@ +package io.getstream.core.faye; + +public abstract class MessageTransformer { + public abstract Message transformRequest(Message message); + + public abstract Message transformResponse(Message message); +} diff --git a/src/main/java/io/getstream/core/faye/client/Callback.java b/src/main/java/io/getstream/core/faye/client/Callback.java new file mode 100644 index 00000000..3b6d4a7a --- /dev/null +++ b/src/main/java/io/getstream/core/faye/client/Callback.java @@ -0,0 +1,5 @@ +package io.getstream.core.faye.client; + +interface Callback { + void call(); +} \ No newline at end of file diff --git a/src/main/java/io/getstream/core/faye/client/FayeClient.java b/src/main/java/io/getstream/core/faye/client/FayeClient.java new file mode 100644 index 00000000..79a4899a --- /dev/null +++ b/src/main/java/io/getstream/core/faye/client/FayeClient.java @@ -0,0 +1,440 @@ +package io.getstream.core.faye.client; + +import java.io.IOException; +import java.net.URL; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.Timer; +import java.util.TimerTask; +import java.util.concurrent.CompletableFuture; + +import io.getstream.core.faye.Advice; +import io.getstream.core.faye.Channel; +import io.getstream.core.faye.DefaultMessageTransformer; +import io.getstream.core.faye.FayeClientError; +import io.getstream.core.faye.Message; +import io.getstream.core.faye.MessageTransformer; +import io.getstream.core.faye.subscription.ChannelDataCallback; +import io.getstream.core.faye.subscription.ChannelSubscription; +import io.getstream.core.faye.subscription.SubscriptionCancelledCallback; +import io.getstream.core.utils.Serialization; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import okhttp3.WebSocket; +import okhttp3.WebSocketListener; + + +public class FayeClient extends WebSocketListener { + + private static final String BAYEUX_VERSION = "1.0"; + private static final int DEFAULT_TIMEOUT = 60; // seconds + private static final int DEFAULT_INTERVAL = 0; // seconds + + private final String baseURL; + private final int timeout; + private final int interval; + + private Advice advice; + + public FayeClient(URL baseURL) { + String url = baseURL.toString(); + if (url.startsWith("http")) { + url = url.replace("http", "ws"); + } else if (url.startsWith("https")) { + url = url.replace("https", "wss"); + } + this.baseURL = url; + this.timeout = DEFAULT_TIMEOUT; + this.interval = DEFAULT_INTERVAL; + this.advice = new Advice(Advice.RETRY, 1000 * interval, 1000 * timeout); + } + + private String clientId; + private final Map channels = new HashMap<>(); + private final Map responseCallbacks = new HashMap<>(); + + + private MessageTransformer messageTransformer = new DefaultMessageTransformer(); + + public void setMessageTransformer(MessageTransformer messageTransformer) { + this.messageTransformer = messageTransformer; + } + + private FayeClientState state = FayeClientState.UNCONNECTED; + + private void setState(FayeClientState state) { + this.state = state; + if (stateChangeListener != null) stateChangeListener.onStateChanged(state); + } + + private StateChangeListener stateChangeListener; + + public void setStateChangeListener(StateChangeListener stateChangeListener) { + this.stateChangeListener = stateChangeListener; + } + + private WebSocket webSocket; + private final OkHttpClient httpClient = new OkHttpClient(); + + private Timer timer = new Timer(); + + private void initWebSocket() { + // Initiating connection with $baseUrl + if (webSocket != null) { + closeWebSocket(); + } + final Request request = new Request.Builder().url(baseURL).build(); + webSocket = httpClient.newWebSocket(request, this); + } + + private void closeWebSocket() { + // Cancelling all timer tasks + if (timer != null) { + timer.cancel(); + timer = null; + } + + // Closing connection for $baseUrl + if (webSocket != null) { + webSocket.close(1000, "Connection closed by client"); + webSocket = null; + } + } + + @Override + public void onMessage(WebSocket webSocket, String text) { + List messages = null; + try { + messages = Serialization.fromJSONList(text, Message.class); + } catch (IOException ignored) { + } + + if (messages == null) return; + + for (Message message : messages) { + receiveMessage(message); + } + } + + @Override + public void onFailure(WebSocket webSocket, Throwable t, Response response) { + // 'Error occurred', error, stacktrace); + closeWebSocket(); + initWebSocket(); + } + + private boolean manuallyClosed = false; + + @Override + public void onClosed(WebSocket webSocket, int code, String reason) { + closeWebSocket(); + + // Checking if we manually closed the connection + if (manuallyClosed) return; + initWebSocket(); + } + + private void scheduleTimerTask(Callback callback, long duration) { + if (timer == null) timer = new Timer(); + timer.schedule(new TimerTask() { + @Override + public void run() { + callback.call(); + } + }, duration); + } + + public void handshake() { + handshake(null); + } + + private void handshake(Callback callback) { + if (Objects.equals(advice.getReconnect(), Advice.NONE)) return; + if (state != FayeClientState.UNCONNECTED) return; + + setState(FayeClientState.CONNECTING); + + initWebSocket(); + + // Initiating handshake with $baseUrl + + final String[] connectionTypes = {"websocket"}; + final Message message = new Message(Channel.HANDSHAKE); + message.setVersion(BAYEUX_VERSION); + message.setSupportedConnectionTypes(connectionTypes); + sendMessage(message, response -> { + if (response.isSuccessful() != null && response.isSuccessful()) { + setState(FayeClientState.CONNECTED); + clientId = response.getClientId(); + + // Handshake successful: $clientId + final Set keys = channels.keySet(); + subscribeChannels(keys.toArray(new String[0])); + if (callback != null) callback.call(); + } else { + // Handshake unsuccessful + scheduleTimerTask(() -> handshake(callback), 1000); + setState(FayeClientState.UNCONNECTED); + } + }); + } + + private boolean connectRequestInProgress = false; + + public void connect() { + connect(null); + } + + private void connect(Callback callback) { + if (Objects.equals(advice.getReconnect(), Advice.NONE)) return; + if (state == FayeClientState.DISCONNECTED) return; + + if (state == FayeClientState.UNCONNECTED) { + handshake(() -> connect(callback)); + return; + } + + if (callback != null) callback.call(); + if (state != FayeClientState.CONNECTED) return; + + if (connectRequestInProgress) return; + connectRequestInProgress = true; + + // Initiating connection for $clientId + + final Message message = new Message(Channel.CONNECT); + message.setClientId(clientId); + message.setConnectionType("websocket"); + sendMessage(message, response -> cycleConnection()); + } + + public CompletableFuture disconnect() { + final CompletableFuture disconnectionCompleter = new CompletableFuture<>(); + + if (state != FayeClientState.CONNECTED) disconnectionCompleter.complete(null); + setState(FayeClientState.DISCONNECTED); + + // Disconnecting $clientId + + final Message message = new Message(Channel.DISCONNECT); + message.setClientId(clientId); + sendMessage(message, response -> { + if (response.isSuccessful() != null && response.isSuccessful()) { + manuallyClosed = true; + closeWebSocket(); + disconnectionCompleter.complete(null); + } else { + final FayeClientError error = FayeClientError.parse(response.getError()); + disconnectionCompleter.completeExceptionally(error); + } + }); + + // Clearing channel listeners for $clientId + channels.clear(); + + return disconnectionCompleter; + } + + private void subscribeChannels(String[] channels) { + for (String channel : channels) { + subscribe(channel, true); + } + } + + public CompletableFuture subscribe(String channel, ChannelDataCallback callback) { + return subscribe(channel, callback, null, null); + } + + private CompletableFuture subscribe(String channel, Boolean force) { + return subscribe(channel, null, null, force); + } + + public CompletableFuture subscribe(String channel, ChannelDataCallback callback, SubscriptionCancelledCallback onCancelled) { + return subscribe(channel, callback, onCancelled, null); + } + + private CompletableFuture subscribe(String channel, ChannelDataCallback onData, SubscriptionCancelledCallback onCancelled, Boolean force) { + // default value + if (force == null) force = false; + + final CompletableFuture subscriptionCompleter = new CompletableFuture<>(); + + final ChannelSubscription channelSubscription = new ChannelSubscription(this, channel, onData, onCancelled); + final boolean hasSubscribe = channels.containsKey(channel); + + if (hasSubscribe && !force) { + subscribeChannel(channel, channelSubscription); + subscriptionCompleter.complete(channelSubscription); + } else { + Boolean finalForce = force; + connect(() -> { + // Client $clientId attempting to subscribe to $channel + if (!finalForce) subscribeChannel(channel, channelSubscription); + final Message message = new Message(Channel.SUBSCRIBE); + message.setClientId(clientId); + message.setSubscription(channel); + sendMessage( + message, response -> { + if (response.isSuccessful() != null && response.isSuccessful()) { + final String subscribedChannel = response.getSubscription(); + // Subscription acknowledged for $channel to $clientId + subscriptionCompleter.complete(channelSubscription); + } else { + unsubscribeChannel(channel, channelSubscription); + final FayeClientError error = FayeClientError.parse(response.getError()); + subscriptionCompleter.completeExceptionally(error); + } + } + ); + }); + } + + return subscriptionCompleter; + } + + public void unsubscribe(String channel, ChannelSubscription channelSubscription) { + final boolean dead = unsubscribeChannel(channel, channelSubscription); + if (!dead) return; + + connect(() -> { + // Client $clientId attempting to unsubscribe from $channel + final Message message = new Message(Channel.UNSUBSCRIBE); + message.setClientId(clientId); + message.setSubscription(channel); + sendMessage(message, response -> { + if (response.isSuccessful() != null && response.isSuccessful()) { + final String unsubscribedChannel = response.getSubscription(); + // Un-subscription acknowledged for $clientId from $channel + } + }); + }); + } + + public CompletableFuture publish(String channel, Map data) { + final CompletableFuture publishCompleter = new CompletableFuture<>(); + + connect(() -> { + // Client $clientId queuing published message to $channel: $data + final Message message = new Message(channel); + message.setData(data); + message.setClientId(clientId); + sendMessage(message, response -> { + if (response.isSuccessful() != null && response.isSuccessful()) { + publishCompleter.complete(null); + } else { + final FayeClientError error = FayeClientError.parse(response.getError()); + publishCompleter.completeExceptionally(error); + } + }); + }); + + return publishCompleter; + } + + private final String EVENT_MESSAGE = "message"; + + private void subscribeChannel(String name, ChannelSubscription channelSubscription) { + Channel channel; + if (channels.containsKey(name)) { + channel = channels.get(name); + } else { + channel = new Channel(name); + channels.put(name, channel); + } + channel.bind(EVENT_MESSAGE, channelSubscription::call); + } + + private boolean unsubscribeChannel(String name, ChannelSubscription channelSubscription) { + final Channel channel = channels.get(name); + if (channel == null) return false; + channel.unbind(EVENT_MESSAGE, channelSubscription::call); + try { + if (channel.hasListeners(EVENT_MESSAGE)) { + channels.remove(name); + return true; + } + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + private void distributeChannelMessage(Message message) { + final List expandedChannels = Channel.expand(message.getChannel()); + if (expandedChannels == null) return; + for (String c : expandedChannels) { + final Channel channel = this.channels.get(c); + if (channel != null) channel.trigger(EVENT_MESSAGE, message); + } + } + + private int messageId = 0; + + private String generateMessageId() { + messageId += 1; + if (messageId >= Math.pow(2, 32)) messageId = 0; + return Integer.toString(messageId, 36); + } + + private void sendMessage(Message message) { + sendMessage(message, null); + } + + private void sendMessage(Message message, MessageCallback onResponse) { + final String id = generateMessageId(); + message.setId(id); + message = messageTransformer.transformRequest(message); + // Sending Message: $message + if (onResponse != null) responseCallbacks.put(id, onResponse); + try { + final byte[] payload = Serialization.toJSON(message); + webSocket.send(new String(payload)); + } catch (Exception ignored) { + + } + } + + private void receiveMessage(Message message) { + final String id = message.getId(); + MessageCallback callback = null; + if (message.isSuccessful() != null) { + callback = responseCallbacks.remove(id); + } + message = messageTransformer.transformResponse(message); + // Received message: $message + if (message.getAdvice() != null) handleAdvice(message.getAdvice()); + deliverMessage(message); + if (callback != null) callback.onMessage(message); + } + + private void handleAdvice(Advice advice) { + this.advice = advice; + if (Objects.equals(advice.getReconnect(), Advice.HANDSHAKE) + && state != FayeClientState.DISCONNECTED + ) { + setState(FayeClientState.UNCONNECTED); + clientId = null; + cycleConnection(); + } + } + + private void deliverMessage(Message message) { + if (message.getChannel() == null || message.getData() == null) return; + // Client $clientId calling listeners for ${message.channel} with ${message.data} + distributeChannelMessage(message); + } + + private void cycleConnection() { + if (connectRequestInProgress) { + connectRequestInProgress = false; + // Closed connection for $clientId + } + scheduleTimerTask(this::connect, advice.getInterval()); + } +} + + diff --git a/src/main/java/io/getstream/core/faye/client/FayeClientState.java b/src/main/java/io/getstream/core/faye/client/FayeClientState.java new file mode 100644 index 00000000..bd3a4582 --- /dev/null +++ b/src/main/java/io/getstream/core/faye/client/FayeClientState.java @@ -0,0 +1,8 @@ +package io.getstream.core.faye.client; + +public enum FayeClientState { + UNCONNECTED, + CONNECTING, + CONNECTED, + DISCONNECTED, +} \ No newline at end of file diff --git a/src/main/java/io/getstream/core/faye/client/MessageCallback.java b/src/main/java/io/getstream/core/faye/client/MessageCallback.java new file mode 100644 index 00000000..d19e6960 --- /dev/null +++ b/src/main/java/io/getstream/core/faye/client/MessageCallback.java @@ -0,0 +1,7 @@ +package io.getstream.core.faye.client; + +import io.getstream.core.faye.Message; + +interface MessageCallback { + void onMessage(Message message); +} diff --git a/src/main/java/io/getstream/core/faye/client/StateChangeListener.java b/src/main/java/io/getstream/core/faye/client/StateChangeListener.java new file mode 100644 index 00000000..18993b16 --- /dev/null +++ b/src/main/java/io/getstream/core/faye/client/StateChangeListener.java @@ -0,0 +1,5 @@ +package io.getstream.core.faye.client; + +public interface StateChangeListener { + void onStateChanged(FayeClientState clientState); +} \ No newline at end of file diff --git a/src/main/java/io/getstream/core/faye/emitter/ErrorListener.java b/src/main/java/io/getstream/core/faye/emitter/ErrorListener.java new file mode 100644 index 00000000..d511c701 --- /dev/null +++ b/src/main/java/io/getstream/core/faye/emitter/ErrorListener.java @@ -0,0 +1,5 @@ +package io.getstream.core.faye.emitter; + +public interface ErrorListener { + void onError(Exception error); +} diff --git a/src/main/java/io/getstream/core/faye/emitter/EventEmitter.java b/src/main/java/io/getstream/core/faye/emitter/EventEmitter.java new file mode 100644 index 00000000..028eceaf --- /dev/null +++ b/src/main/java/io/getstream/core/faye/emitter/EventEmitter.java @@ -0,0 +1,118 @@ +package io.getstream.core.faye.emitter; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +public class EventEmitter { + + private final Map>> events = new HashMap<>(); + + private ErrorListener errorListener; + + public void setErrorListener(ErrorListener errorListener) { + this.errorListener = errorListener; + } + + private boolean mounted = true; + + public boolean isMounted() { + return mounted; + } + + private void assertMounted() { + assert isMounted() : "Tried to use " + this.getClass().getSimpleName() + " after `dispose` was called. Consider checking `isMounted`"; + } + + public void emit(String event, T data) { + assertMounted(); + final LinkedList> listeners = events.get(event); + if (listeners == null) return; + boolean didThrow = false; + final List> removables = new ArrayList<>(); + for (ListenerEntry entry : listeners) { + try { + entry.getListener().onData(data); + Integer limit = entry.getLimit(); + if (limit != null) { + if (limit > 0) { + limit -= 1; + entry.setLimit(limit); + } + if (limit == 0) { + removables.add(entry); + } + } + } catch (Exception e) { + didThrow = true; + if (errorListener != null) { + errorListener.onError(e); + } + } + } + for (ListenerEntry entry : removables) { + listeners.remove(entry); + } + if (didThrow) throw new Error(); + } + + public void on(String event, EventListener listener) { + addListener(event, listener); + } + + public void on(String event, EventListener listener, int limit) { + addListener(event, listener, limit); + } + + public void addListener(String event, EventListener listener) { + _addListener(event, listener, null); + } + + public void addListener(String event, EventListener listener, int limit) { + _addListener(event, listener, limit); + } + + void _addListener(String event, EventListener listener, Integer limit) { + assertMounted(); + final ListenerEntry entry = new ListenerEntry(listener, limit); + LinkedList> listeners = events.get(event); + if (listeners == null) listeners = new LinkedList<>(); + listeners.add(entry); + events.put(event, listeners); + } + + public void off(String event) { + assertMounted(); + events.put(event, new LinkedList<>()); + } + + public void removeListener(String event, EventListener listener) { + assertMounted(); + final LinkedList> listeners = events.get(event); + if (listeners == null) return; + listeners.removeIf(curr -> curr.getListener() == listener); + } + + public void removeAllListeners() { + assertMounted(); + events.clear(); + } + + public boolean hasListeners(String event) throws Exception { + assertMounted(); + final LinkedList> listeners = events.get(event); + if (listeners == null) { + throw new Exception("Event not available"); + } + return !listeners.isEmpty(); + } + + public void dispose() { + assertMounted(); + events.values().forEach(LinkedList::clear); + mounted = false; + } + +} diff --git a/src/main/java/io/getstream/core/faye/emitter/EventListener.java b/src/main/java/io/getstream/core/faye/emitter/EventListener.java new file mode 100644 index 00000000..b0791c4d --- /dev/null +++ b/src/main/java/io/getstream/core/faye/emitter/EventListener.java @@ -0,0 +1,5 @@ +package io.getstream.core.faye.emitter; + +public interface EventListener { + void onData(T data); +} diff --git a/src/main/java/io/getstream/core/faye/emitter/ListenerEntry.java b/src/main/java/io/getstream/core/faye/emitter/ListenerEntry.java new file mode 100644 index 00000000..f6745b09 --- /dev/null +++ b/src/main/java/io/getstream/core/faye/emitter/ListenerEntry.java @@ -0,0 +1,25 @@ +package io.getstream.core.faye.emitter; + + +class ListenerEntry { + + public ListenerEntry(EventListener listener, Integer limit) { + this.listener = listener; + this.limit = limit; + } + + private Integer limit; + private final EventListener listener; + + public Integer getLimit() { + return limit; + } + + public void setLimit(int limit) { + this.limit = limit; + } + + public EventListener getListener() { + return listener; + } +} diff --git a/src/main/java/io/getstream/core/faye/subscription/ChannelDataCallback.java b/src/main/java/io/getstream/core/faye/subscription/ChannelDataCallback.java new file mode 100644 index 00000000..b8eb2107 --- /dev/null +++ b/src/main/java/io/getstream/core/faye/subscription/ChannelDataCallback.java @@ -0,0 +1,7 @@ +package io.getstream.core.faye.subscription; + +import java.util.Map; + +public interface ChannelDataCallback { + void onData(Map data); +} \ No newline at end of file diff --git a/src/main/java/io/getstream/core/faye/subscription/ChannelSubscription.java b/src/main/java/io/getstream/core/faye/subscription/ChannelSubscription.java new file mode 100644 index 00000000..df53ec56 --- /dev/null +++ b/src/main/java/io/getstream/core/faye/subscription/ChannelSubscription.java @@ -0,0 +1,47 @@ +package io.getstream.core.faye.subscription; + +import io.getstream.core.faye.Message; +import io.getstream.core.faye.client.FayeClient; + +public class ChannelSubscription { + private final FayeClient client; + private final String channel; + private final ChannelDataCallback channelDataCallback; + private final SubscriptionCancelledCallback onCancelledCallback; + private WithChannelDataCallback withChannel; + + private boolean cancelled = false; + + public ChannelSubscription(FayeClient client, String channel) { + this.client = client; + this.channel = channel; + this.channelDataCallback = null; + this.onCancelledCallback = null; + } + + public ChannelSubscription(FayeClient client, String channel, ChannelDataCallback channelDataCallback, SubscriptionCancelledCallback onCancelledCallback) { + this.client = client; + this.channel = channel; + this.channelDataCallback = channelDataCallback; + this.onCancelledCallback = onCancelledCallback; + } + + public ChannelSubscription setWithChannel(WithChannelDataCallback withChannel) { + this.withChannel = withChannel; + return this; + } + + public void call(Message message) { + if (channelDataCallback != null) channelDataCallback.onData(message.getData()); + if (withChannel != null) withChannel.onData(message.getChannel(), message.getData()); + } + + public void cancel() { + if (cancelled) return; + client.unsubscribe(channel, this); + if (onCancelledCallback != null) onCancelledCallback.onCancelled(); + cancelled = true; + } +} + + diff --git a/src/main/java/io/getstream/core/faye/subscription/SubscriptionCancelledCallback.java b/src/main/java/io/getstream/core/faye/subscription/SubscriptionCancelledCallback.java new file mode 100644 index 00000000..39e40ccd --- /dev/null +++ b/src/main/java/io/getstream/core/faye/subscription/SubscriptionCancelledCallback.java @@ -0,0 +1,5 @@ +package io.getstream.core.faye.subscription; + +public interface SubscriptionCancelledCallback { + void onCancelled(); +} diff --git a/src/main/java/io/getstream/core/faye/subscription/WithChannelDataCallback.java b/src/main/java/io/getstream/core/faye/subscription/WithChannelDataCallback.java new file mode 100644 index 00000000..dabd744f --- /dev/null +++ b/src/main/java/io/getstream/core/faye/subscription/WithChannelDataCallback.java @@ -0,0 +1,7 @@ +package io.getstream.core.faye.subscription; + +import java.util.Map; + +public interface WithChannelDataCallback { + void onData(String channel, Map data); +} diff --git a/src/main/java/io/getstream/core/models/FeedID.java b/src/main/java/io/getstream/core/models/FeedID.java index 0af7a5ae..7dd62199 100644 --- a/src/main/java/io/getstream/core/models/FeedID.java +++ b/src/main/java/io/getstream/core/models/FeedID.java @@ -5,56 +5,61 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; + import java.util.Objects; @JsonSerialize(using = ToStringSerializer.class) public final class FeedID { - private final String slug; - private final String userID; - - public FeedID(String slug, String userID) { - checkNotNull(slug, "Feed slug can't be null"); - checkArgument(!slug.contains(":"), "Invalid slug"); - checkNotNull(userID, "Feed user ID can't be null"); - checkArgument(!userID.contains(":"), "Invalid user ID"); - - this.slug = slug; - this.userID = userID; - } - - public FeedID(String id) { - checkNotNull(id, "Feed ID can't be null"); - checkArgument(id.contains(":"), "Invalid feed ID"); - - String[] parts = id.split(":"); - checkArgument(parts.length == 2, "Invalid feed ID"); - this.slug = parts[0]; - this.userID = parts[1]; - } - - public String getSlug() { - return slug; - } - - public String getUserID() { - return userID; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - FeedID feedID = (FeedID) o; - return Objects.equals(slug, feedID.slug) && Objects.equals(userID, feedID.userID); - } - - @Override - public int hashCode() { - return Objects.hash(slug, userID); - } - - @Override - public String toString() { - return slug + ':' + userID; - } + private final String slug; + private final String userID; + + public FeedID(String slug, String userID) { + checkNotNull(slug, "Feed slug can't be null"); + checkArgument(!slug.contains(":"), "Invalid slug"); + checkNotNull(userID, "Feed user ID can't be null"); + checkArgument(!userID.contains(":"), "Invalid user ID"); + + this.slug = slug; + this.userID = userID; + } + + public FeedID(String id) { + checkNotNull(id, "Feed ID can't be null"); + checkArgument(id.contains(":"), "Invalid feed ID"); + + String[] parts = id.split(":"); + checkArgument(parts.length == 2, "Invalid feed ID"); + this.slug = parts[0]; + this.userID = parts[1]; + } + + public String getSlug() { + return slug; + } + + public String getUserID() { + return userID; + } + + public String getClaim() { + return slug + userID; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + FeedID feedID = (FeedID) o; + return Objects.equals(slug, feedID.slug) && Objects.equals(userID, feedID.userID); + } + + @Override + public int hashCode() { + return Objects.hash(slug, userID); + } + + @Override + public String toString() { + return slug + ':' + userID; + } } diff --git a/src/main/java/io/getstream/core/models/RealtimeMessage.java b/src/main/java/io/getstream/core/models/RealtimeMessage.java new file mode 100644 index 00000000..21b8e1cb --- /dev/null +++ b/src/main/java/io/getstream/core/models/RealtimeMessage.java @@ -0,0 +1,101 @@ +package io.getstream.core.models; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.OptBoolean; +import com.google.common.base.MoreObjects; + +import java.util.Date; +import java.util.List; +import java.util.Objects; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class RealtimeMessage { + private final FeedID feed; + private final String appID; + private final List deleted; + private final List newActivities; + private final Date publishedAt; + + @JsonCreator + public RealtimeMessage( + @JsonProperty("feed") FeedID feed, + @JsonProperty("app_id") String appID, + @JsonProperty("deleted") List deleted, + @JsonProperty("new") List newActivities, + @JsonProperty("published_at") Date publishedAt + ) { + this.feed = feed; + this.appID = appID; + this.deleted = deleted; + this.newActivities = newActivities; + this.publishedAt = publishedAt; + } + + + public FeedID getFeed() { + return feed; + } + + @JsonProperty("app_id") + public String getAppID() { + return appID; + } + + @JsonFormat( + shape = JsonFormat.Shape.STRING, + pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS", + lenient = OptBoolean.FALSE, + timezone = "UTC") + public List getDeleted() { + return deleted; + } + + @JsonProperty("new") + public List getNewActivities() { + return newActivities; + } + + @JsonProperty("published_at") + public Date getPublishedAt() { + return publishedAt; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + RealtimeMessage message = (RealtimeMessage) o; + return Objects.equals(feed, message.feed) + && Objects.equals(appID, message.appID) + && Objects.equals(deleted, message.deleted) + && Objects.equals(newActivities, message.newActivities) + && Objects.equals(publishedAt, message.publishedAt); + } + + @Override + public int hashCode() { + return Objects.hash( + feed, + appID, + deleted, + newActivities, + publishedAt + ); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("feed", this.feed) + .add("appID", this.appID) + .add("deleted", this.deleted) + .add("new", this.newActivities) + .add("publishedAt", this.publishedAt) + .toString(); + } +} diff --git a/src/main/java/io/getstream/core/utils/Serialization.java b/src/main/java/io/getstream/core/utils/Serialization.java index 976b53e0..bbb7231d 100644 --- a/src/main/java/io/getstream/core/utils/Serialization.java +++ b/src/main/java/io/getstream/core/utils/Serialization.java @@ -9,142 +9,154 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.type.CollectionType; import com.google.common.collect.Range; + import io.getstream.core.exceptions.StreamAPIException; import io.getstream.core.exceptions.StreamException; import io.getstream.core.http.Response; + import java.io.IOException; import java.io.InputStream; import java.io.PushbackInputStream; import java.util.List; public final class Serialization { - private static ObjectMapper mapper = new ObjectMapper(); + private static ObjectMapper mapper = new ObjectMapper(); + + public ObjectMapper getObjectMapper() { + return mapper; + } - public ObjectMapper getObjectMapper() { - return mapper; - } + public void setObjectMapper(ObjectMapper mapper) { + this.mapper = checkNotNull(mapper, "Missing object mapper"); + } - public void setObjectMapper(ObjectMapper mapper) { - this.mapper = checkNotNull(mapper, "Missing object mapper"); - } + private Serialization() { + /* nothing to see here */ + } - private Serialization() { - /* nothing to see here */ - } + public static byte[] toJSON(T obj) throws JsonProcessingException { + return mapper.writeValueAsBytes(obj); + } - public static byte[] toJSON(T obj) throws JsonProcessingException { - return mapper.writeValueAsBytes(obj); - } + public static T fromJSON(InputStream json, Class type) throws IOException { + return mapper.readValue(json, type); + } - public static T fromJSON(InputStream json, Class type) throws IOException { - return mapper.readValue(json, type); - } + public static T fromJSON(InputStream json, TypeReference type) throws IOException { + return mapper.readValue(json, type); + } - public static T fromJSON(InputStream json, TypeReference type) throws IOException { - return mapper.readValue(json, type); - } + public static T fromJSON(InputStream json, String wrapper, JavaType type) throws IOException { + JsonNode tree = mapper.readTree(json); + for (String path : wrapper.split("\\.")) { + tree = tree.findPath(path); + } - public static T fromJSON(InputStream json, String wrapper, JavaType type) throws IOException { - JsonNode tree = mapper.readTree(json); - for (String path : wrapper.split("\\.")) { - tree = tree.findPath(path); + return mapper.readValue(mapper.treeAsTokens(tree), type); } - return mapper.readValue(mapper.treeAsTokens(tree), type); - } + public static T fromJSON(String json, Class type) throws IOException { + return mapper.readValue(json, type); + } - public static T convert(U obj, Class type) { - return mapper.convertValue(obj, type); - } + public static List fromJSONList(String json, Class type) throws IOException { + final CollectionType collection = + mapper.getTypeFactory().constructCollectionType(List.class, type); + return mapper.readValue(json, collection); + } - public static T convert(U obj, TypeReference type) { - return mapper.convertValue(obj, type); - } + public static T convert(U obj, Class type) { + return mapper.convertValue(obj, type); + } - // TODO: move this to a more specialised utility class? - private static final Range normalResponseCodes = Range.closed(200, 299); + public static T convert(U obj, TypeReference type) { + return mapper.convertValue(obj, type); + } - // TODO: catch deserialization errors and give a nice suggestion about wrong feed slug type - public static List deserializeContainer(Response response, Class type) - throws IOException, StreamException { - return deserializeContainer(response, "results", type); - } + // TODO: move this to a more specialised utility class? + private static final Range normalResponseCodes = Range.closed(200, 299); - public static T deserializeContainer( - Response response, Class wrapperType, Class... types) - throws IOException, StreamException { - final JavaType wrappedType = - mapper.getTypeFactory().constructParametricType(wrapperType, types); - return deserializeContainer(response, "results", wrappedType); - } + // TODO: catch deserialization errors and give a nice suggestion about wrong feed slug type + public static List deserializeContainer(Response response, Class type) + throws IOException, StreamException { + return deserializeContainer(response, "results", type); + } - public static List deserializeContainer( - Response response, String wrapper, Class element) throws IOException, StreamException { - if (normalResponseCodes.contains(response.getCode())) { - final CollectionType collection = - mapper.getTypeFactory().constructCollectionType(List.class, element); - return fromJSON( - response.getBody(), wrapper, mapper.getTypeFactory().constructType(collection)); + public static T deserializeContainer( + Response response, Class wrapperType, Class... types) + throws IOException, StreamException { + final JavaType wrappedType = + mapper.getTypeFactory().constructParametricType(wrapperType, types); + return deserializeContainer(response, "results", wrappedType); } - throw deserializeException(response); - } + public static List deserializeContainer( + Response response, String wrapper, Class element) throws IOException, StreamException { + if (normalResponseCodes.contains(response.getCode())) { + final CollectionType collection = + mapper.getTypeFactory().constructCollectionType(List.class, element); + return fromJSON( + response.getBody(), wrapper, mapper.getTypeFactory().constructType(collection)); + } - public static T deserializeContainer(Response response, String wrapper, JavaType element) - throws IOException, StreamException { - if (normalResponseCodes.contains(response.getCode())) { - final CollectionType collection = - mapper.getTypeFactory().constructCollectionType(List.class, element); - return fromJSON( - response.getBody(), wrapper, mapper.getTypeFactory().constructType(collection)); + throw deserializeException(response); } - throw deserializeException(response); - } + public static T deserializeContainer(Response response, String wrapper, JavaType element) + throws IOException, StreamException { + if (normalResponseCodes.contains(response.getCode())) { + final CollectionType collection = + mapper.getTypeFactory().constructCollectionType(List.class, element); + return fromJSON( + response.getBody(), wrapper, mapper.getTypeFactory().constructType(collection)); + } - public static T deserialize(Response response, String wrapper, Class type) - throws IOException, StreamException { - if (normalResponseCodes.contains(response.getCode())) { - return fromJSON(response.getBody(), wrapper, mapper.getTypeFactory().constructType(type)); + throw deserializeException(response); } - throw deserializeException(response); - } + public static T deserialize(Response response, String wrapper, Class type) + throws IOException, StreamException { + if (normalResponseCodes.contains(response.getCode())) { + return fromJSON(response.getBody(), wrapper, mapper.getTypeFactory().constructType(type)); + } - public static T deserialize(Response response, Class type) - throws IOException, StreamException { - if (normalResponseCodes.contains(response.getCode())) { - return fromJSON(response.getBody(), type); + throw deserializeException(response); } - throw deserializeException(response); - } + public static T deserialize(Response response, Class type) + throws IOException, StreamException { + if (normalResponseCodes.contains(response.getCode())) { + return fromJSON(response.getBody(), type); + } - public static T deserialize(Response response, TypeReference type) - throws IOException, StreamException { - if (normalResponseCodes.contains(response.getCode())) { - return fromJSON(response.getBody(), type); + throw deserializeException(response); } - throw deserializeException(response); - } + public static T deserialize(Response response, TypeReference type) + throws IOException, StreamException { + if (normalResponseCodes.contains(response.getCode())) { + return fromJSON(response.getBody(), type); + } + + throw deserializeException(response); + } - public static Void deserializeError(Response response) throws IOException, StreamException { - if (!normalResponseCodes.contains(response.getCode())) { - throw deserializeException(response); + public static Void deserializeError(Response response) throws IOException, StreamException { + if (!normalResponseCodes.contains(response.getCode())) { + throw deserializeException(response); + } + return null; } - return null; - } - private static StreamAPIException deserializeException(Response response) throws IOException { - // XXX: a hack to avoid reading empty stream - try (PushbackInputStream wrapper = new PushbackInputStream(response.getBody())) { - int read = wrapper.read(); - if (read == -1) { - return new StreamAPIException(null, 0, response.getCode(), "API Error"); - } - wrapper.unread(read); - return fromJSON(wrapper, StreamAPIException.class); + private static StreamAPIException deserializeException(Response response) throws IOException { + // XXX: a hack to avoid reading empty stream + try (PushbackInputStream wrapper = new PushbackInputStream(response.getBody())) { + int read = wrapper.read(); + if (read == -1) { + return new StreamAPIException(null, 0, response.getCode(), "API Error"); + } + wrapper.unread(read); + return fromJSON(wrapper, StreamAPIException.class); + } } - } }