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