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;
009import java.util.Date;
010
011/**
012 * Class describing request to get Admin Logs. You can use it's fluent interface to create new
013 * request like so:
014 *
015 * <pre>{@code
016 * new EnterpriseEventsRequest().position("stream_position").limit(50);
017 * }</pre>
018 */
019public final class EnterpriseEventsRequest {
020  private static final String ADMIN_LOGS_STREAM_TYPE = "admin_logs";
021  private Date before;
022  private Date after;
023  private String position;
024  private int limit = ENTERPRISE_LIMIT;
025  private Collection<String> types = new ArrayList<>();
026
027  /**
028   * The lower bound on the timestamp of the events returned.
029   *
030   * @param date the lower bound on the timestamp of the events returned.
031   * @return request being created.
032   */
033  public EnterpriseEventsRequest after(Date date) {
034    this.after = date;
035    return this;
036  }
037
038  /**
039   * The upper bound on the timestamp of the events returned.
040   *
041   * @param date the upper bound on the timestamp of the events returned.
042   * @return request being created.
043   */
044  public EnterpriseEventsRequest before(Date date) {
045    this.before = date;
046    return this;
047  }
048
049  /**
050   * The starting position of the event stream.
051   *
052   * @param position the starting position of the event stream.
053   * @return request being created.
054   */
055  public EnterpriseEventsRequest position(String position) {
056    this.position = position;
057    return this;
058  }
059
060  /**
061   * The number of entries to be returned in the response.
062   *
063   * @param limit the number of entries to be returned in the response.
064   * @return request being created.
065   */
066  public EnterpriseEventsRequest limit(int limit) {
067    this.limit = limit;
068    return this;
069  }
070
071  /**
072   * List of event types to filter by.
073   *
074   * @param types list of event types to filter by.
075   * @return request being created.
076   */
077  public EnterpriseEventsRequest types(EventType... types) {
078    return typeNames(Arrays.stream(types).map(EventType::toJSONString).toArray(String[]::new));
079  }
080
081  /**
082   * List of event type names to filter by.
083   *
084   * @param typeNames list of event type names to filter by.
085   * @return request being created.
086   */
087  public EnterpriseEventsRequest typeNames(String... typeNames) {
088    this.types = Arrays.asList(typeNames);
089    return this;
090  }
091
092  Date getAfter() {
093    return after;
094  }
095
096  Date getBefore() {
097    return before;
098  }
099
100  String getPosition() {
101    return position;
102  }
103
104  int getLimit() {
105    return limit;
106  }
107
108  Collection<String> getTypes() {
109    return types;
110  }
111
112  String getStreamType() {
113    return ADMIN_LOGS_STREAM_TYPE;
114  }
115}