001package com.box.sdkgen.managers.events;
002
003import com.box.sdkgen.serialization.json.EnumWrapper;
004import com.box.sdkgen.serialization.json.Valuable;
005import com.fasterxml.jackson.core.JsonGenerator;
006import com.fasterxml.jackson.core.JsonParser;
007import com.fasterxml.jackson.databind.DeserializationContext;
008import com.fasterxml.jackson.databind.JsonDeserializer;
009import com.fasterxml.jackson.databind.JsonNode;
010import com.fasterxml.jackson.databind.JsonSerializer;
011import com.fasterxml.jackson.databind.SerializerProvider;
012import java.io.IOException;
013import java.time.OffsetDateTime;
014import java.util.ArrayList;
015import java.util.List;
016
017public class GetEventStreamQueryParams {
018
019  /**
020   * Defines the type of events that are returned
021   *
022   * <p>* `all` returns everything for a user and is the default * `changes` returns events that may
023   * cause file tree changes such as file updates or collaborations. * `sync` is similar to
024   * `changes` but only applies to synced folders * `admin_logs` returns all events for an entire
025   * enterprise and requires the user making the API call to have admin permissions. This stream
026   * type is for programmatically pulling from a 1 year history of events across all users within
027   * the enterprise and within a `created_after` and `created_before` time frame. The complete
028   * history of events will be returned in chronological order based on the event time, but latency
029   * will be much higher than `admin_logs_streaming`. * `admin_logs_streaming` returns all events
030   * for an entire enterprise and requires the user making the API call to have admin permissions.
031   * This stream type is for polling for recent events across all users within the enterprise.
032   * Latency will be much lower than `admin_logs`, but events will not be returned in chronological
033   * order and may contain duplicates.
034   */
035  public EnumWrapper<GetEventStreamQueryParamsStreamTypeField> streamType;
036
037  /**
038   * The location in the event stream to start receiving events from.
039   *
040   * <p>* `now` will return an empty list events and the latest stream position for initialization.
041   * * `0` or `null` will return all events.
042   */
043  public String streamPosition;
044
045  /**
046   * Limits the number of events returned.
047   *
048   * <p>Note: Sometimes, the events less than the limit requested can be returned even when there
049   * may be more events remaining. This is primarily done in the case where a number of events have
050   * already been retrieved and these retrieved events are returned rather than delaying for an
051   * unknown amount of time to see if there are any more results.
052   */
053  public Long limit;
054
055  /**
056   * A comma-separated list of events to filter by. This can only be used when requesting the events
057   * with a `stream_type` of `admin_logs` or `adming_logs_streaming`. For any other `stream_type`
058   * this value will be ignored.
059   */
060  public List<EnumWrapper<GetEventStreamQueryParamsEventTypeField>> eventType;
061
062  /**
063   * The lower bound date and time to return events for. This can only be used when requesting the
064   * events with a `stream_type` of `admin_logs`. For any other `stream_type` this value will be
065   * ignored.
066   */
067  public OffsetDateTime createdAfter;
068
069  /**
070   * The upper bound date and time to return events for. This can only be used when requesting the
071   * events with a `stream_type` of `admin_logs`. For any other `stream_type` this value will be
072   * ignored.
073   */
074  public OffsetDateTime createdBefore;
075
076  public GetEventStreamQueryParams() {}
077
078  protected GetEventStreamQueryParams(Builder builder) {
079    this.streamType = builder.streamType;
080    this.streamPosition = builder.streamPosition;
081    this.limit = builder.limit;
082    this.eventType = builder.eventType;
083    this.createdAfter = builder.createdAfter;
084    this.createdBefore = builder.createdBefore;
085  }
086
087  public EnumWrapper<GetEventStreamQueryParamsStreamTypeField> getStreamType() {
088    return streamType;
089  }
090
091  public String getStreamPosition() {
092    return streamPosition;
093  }
094
095  public Long getLimit() {
096    return limit;
097  }
098
099  public List<EnumWrapper<GetEventStreamQueryParamsEventTypeField>> getEventType() {
100    return eventType;
101  }
102
103  public OffsetDateTime getCreatedAfter() {
104    return createdAfter;
105  }
106
107  public OffsetDateTime getCreatedBefore() {
108    return createdBefore;
109  }
110
111  public static class Builder {
112
113    protected EnumWrapper<GetEventStreamQueryParamsStreamTypeField> streamType;
114
115    protected String streamPosition;
116
117    protected Long limit;
118
119    protected List<EnumWrapper<GetEventStreamQueryParamsEventTypeField>> eventType;
120
121    protected OffsetDateTime createdAfter;
122
123    protected OffsetDateTime createdBefore;
124
125    public Builder streamType(GetEventStreamQueryParamsStreamTypeField streamType) {
126      this.streamType = new EnumWrapper<GetEventStreamQueryParamsStreamTypeField>(streamType);
127      return this;
128    }
129
130    public Builder streamType(EnumWrapper<GetEventStreamQueryParamsStreamTypeField> streamType) {
131      this.streamType = streamType;
132      return this;
133    }
134
135    public Builder streamPosition(String streamPosition) {
136      this.streamPosition = streamPosition;
137      return this;
138    }
139
140    public Builder limit(Long limit) {
141      this.limit = limit;
142      return this;
143    }
144
145    public Builder eventType(List<? extends Valuable> eventType) {
146      this.eventType =
147          EnumWrapper.wrapValuableEnumList(
148              eventType, GetEventStreamQueryParamsEventTypeField.class);
149      return this;
150    }
151
152    public Builder createdAfter(OffsetDateTime createdAfter) {
153      this.createdAfter = createdAfter;
154      return this;
155    }
156
157    public Builder createdBefore(OffsetDateTime createdBefore) {
158      this.createdBefore = createdBefore;
159      return this;
160    }
161
162    public GetEventStreamQueryParams build() {
163      return new GetEventStreamQueryParams(this);
164    }
165  }
166
167  public static class EventTypeDeserializer
168      extends JsonDeserializer<List<EnumWrapper<GetEventStreamQueryParamsEventTypeField>>> {
169
170    public final JsonDeserializer<EnumWrapper<GetEventStreamQueryParamsEventTypeField>>
171        elementDeserializer;
172
173    public EventTypeDeserializer() {
174      super();
175      this.elementDeserializer =
176          new GetEventStreamQueryParamsEventTypeField
177              .GetEventStreamQueryParamsEventTypeFieldDeserializer();
178    }
179
180    @Override
181    public List<EnumWrapper<GetEventStreamQueryParamsEventTypeField>> deserialize(
182        JsonParser p, DeserializationContext ctxt) throws IOException {
183      JsonNode node = p.getCodec().readTree(p);
184      List<EnumWrapper<GetEventStreamQueryParamsEventTypeField>> elements = new ArrayList<>();
185      for (JsonNode item : node) {
186        JsonParser pa = item.traverse(p.getCodec());
187        pa.nextToken();
188        elements.add(elementDeserializer.deserialize(pa, ctxt));
189      }
190      return elements;
191    }
192  }
193
194  public static class EventTypeSerializer
195      extends JsonSerializer<List<EnumWrapper<GetEventStreamQueryParamsEventTypeField>>> {
196
197    public final JsonSerializer<EnumWrapper<GetEventStreamQueryParamsEventTypeField>>
198        elementSerializer;
199
200    public EventTypeSerializer() {
201      super();
202      this.elementSerializer =
203          new GetEventStreamQueryParamsEventTypeField
204              .GetEventStreamQueryParamsEventTypeFieldSerializer();
205    }
206
207    @Override
208    public void serialize(
209        List<EnumWrapper<GetEventStreamQueryParamsEventTypeField>> value,
210        JsonGenerator gen,
211        SerializerProvider serializers)
212        throws IOException {
213      gen.writeStartArray();
214      for (EnumWrapper<GetEventStreamQueryParamsEventTypeField> item : value) {
215        elementSerializer.serialize(item, gen, serializers);
216      }
217      gen.writeEndArray();
218    }
219  }
220}