001package com.box.sdk;
002
003import static com.box.sdk.EventLog.ENTERPRISE_LIMIT;
004
005import com.box.sdk.BoxEvent.EventType;
006import java.util.ArrayList;
007import java.util.Arrays;
008import java.util.Collection;
009
010/**
011 * Class describing request to get Admin Logs Streaming. You can use it's fluent interface to create new request like so:
012 * <pre>
013 * {@code
014 * new EnterpriseEventsStreamRequest().position("stream_position").limit(50);
015 * }
016 * </pre>
017 */
018public final class EnterpriseEventsStreamRequest {
019    private static final String ADMIN_LOGS_STREAM_TYPE = "admin_logs_streaming";
020    private String position;
021    private int limit = ENTERPRISE_LIMIT;
022    private Collection<String> types = new ArrayList<>();
023
024
025    /**
026     * The starting position of the event stream.
027     * @param position the starting position of the event stream.
028     * @return request being created.
029     */
030    public EnterpriseEventsStreamRequest position(String position) {
031        this.position = position;
032        return this;
033    }
034
035    /**
036     * The number of entries to be returned in the response.
037     * @param limit the number of entries to be returned in the response.
038     * @return request being created.
039     */
040    public EnterpriseEventsStreamRequest limit(int limit) {
041        this.limit = limit;
042        return this;
043    }
044
045    /**
046     * List of event types to filter by.
047     * @param types list of event types to filter by.
048     * @return request being created.
049     */
050    public EnterpriseEventsStreamRequest types(EventType... types) {
051        return typeNames(Arrays.stream(types)
052            .map(EventType::toJSONString)
053            .toArray(String[]::new)
054        );
055    }
056
057    /**
058     * List of event type names to filter by.
059     * @param typeNames list of event type names to filter by.
060     * @return request being created.
061     */
062    public EnterpriseEventsStreamRequest typeNames(String... typeNames) {
063        this.types = Arrays.asList(typeNames);
064        return this;
065    }
066
067    String getPosition() {
068        return position;
069    }
070
071    int getLimit() {
072        return limit;
073    }
074
075
076    Collection<String> getTypes() {
077        return types;
078    }
079
080    String getStreamType() {
081        return ADMIN_LOGS_STREAM_TYPE;
082    }
083}