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
012 * new request like so:
013 *
014 * <pre>{@code
015 * new EnterpriseEventsStreamRequest().position("stream_position").limit(50);
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   * The starting position of the event stream.
026   *
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   *
038   * @param limit the number of entries to be returned in the response.
039   * @return request being created.
040   */
041  public EnterpriseEventsStreamRequest limit(int limit) {
042    this.limit = limit;
043    return this;
044  }
045
046  /**
047   * List of event types to filter by.
048   *
049   * @param types list of event types to filter by.
050   * @return request being created.
051   */
052  public EnterpriseEventsStreamRequest types(EventType... types) {
053    return typeNames(Arrays.stream(types).map(EventType::toJSONString).toArray(String[]::new));
054  }
055
056  /**
057   * List of event type names to filter by.
058   *
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  Collection<String> getTypes() {
076    return types;
077  }
078
079  String getStreamType() {
080    return ADMIN_LOGS_STREAM_TYPE;
081  }
082}