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 GetEventsQueryParams { 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<GetEventsQueryParamsStreamTypeField> 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<GetEventsQueryParamsEventTypeField>> 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 GetEventsQueryParams() {} 077 078 protected GetEventsQueryParams(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<GetEventsQueryParamsStreamTypeField> 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<GetEventsQueryParamsEventTypeField>> 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<GetEventsQueryParamsStreamTypeField> streamType; 114 115 protected String streamPosition; 116 117 protected Long limit; 118 119 protected List<EnumWrapper<GetEventsQueryParamsEventTypeField>> eventType; 120 121 protected OffsetDateTime createdAfter; 122 123 protected OffsetDateTime createdBefore; 124 125 public Builder streamType(GetEventsQueryParamsStreamTypeField streamType) { 126 this.streamType = new EnumWrapper<GetEventsQueryParamsStreamTypeField>(streamType); 127 return this; 128 } 129 130 public Builder streamType(EnumWrapper<GetEventsQueryParamsStreamTypeField> 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(eventType, GetEventsQueryParamsEventTypeField.class); 148 return this; 149 } 150 151 public Builder createdAfter(OffsetDateTime createdAfter) { 152 this.createdAfter = createdAfter; 153 return this; 154 } 155 156 public Builder createdBefore(OffsetDateTime createdBefore) { 157 this.createdBefore = createdBefore; 158 return this; 159 } 160 161 public GetEventsQueryParams build() { 162 return new GetEventsQueryParams(this); 163 } 164 } 165 166 public static class EventTypeDeserializer 167 extends JsonDeserializer<List<EnumWrapper<GetEventsQueryParamsEventTypeField>>> { 168 169 public final JsonDeserializer<EnumWrapper<GetEventsQueryParamsEventTypeField>> 170 elementDeserializer; 171 172 public EventTypeDeserializer() { 173 super(); 174 this.elementDeserializer = 175 new GetEventsQueryParamsEventTypeField.GetEventsQueryParamsEventTypeFieldDeserializer(); 176 } 177 178 @Override 179 public List<EnumWrapper<GetEventsQueryParamsEventTypeField>> deserialize( 180 JsonParser p, DeserializationContext ctxt) throws IOException { 181 JsonNode node = p.getCodec().readTree(p); 182 List<EnumWrapper<GetEventsQueryParamsEventTypeField>> elements = new ArrayList<>(); 183 for (JsonNode item : node) { 184 JsonParser pa = item.traverse(p.getCodec()); 185 pa.nextToken(); 186 elements.add(elementDeserializer.deserialize(pa, ctxt)); 187 } 188 return elements; 189 } 190 } 191 192 public static class EventTypeSerializer 193 extends JsonSerializer<List<EnumWrapper<GetEventsQueryParamsEventTypeField>>> { 194 195 public final JsonSerializer<EnumWrapper<GetEventsQueryParamsEventTypeField>> elementSerializer; 196 197 public EventTypeSerializer() { 198 super(); 199 this.elementSerializer = 200 new GetEventsQueryParamsEventTypeField.GetEventsQueryParamsEventTypeFieldSerializer(); 201 } 202 203 @Override 204 public void serialize( 205 List<EnumWrapper<GetEventsQueryParamsEventTypeField>> value, 206 JsonGenerator gen, 207 SerializerProvider serializers) 208 throws IOException { 209 gen.writeStartArray(); 210 for (EnumWrapper<GetEventsQueryParamsEventTypeField> item : value) { 211 elementSerializer.serialize(item, gen, serializers); 212 } 213 gen.writeEndArray(); 214 } 215 } 216}