Commit 431a82f0 authored by mness's avatar mness
Browse files

Added support for scope attribute to EventsApi

A 'scope' attribute was added to the Events API that allows retrieval of all events for a user across all the projects that user has access to.  This change adds support for this new attribute.
parent 37617ec3
...@@ -916,5 +916,27 @@ public interface Constants { ...@@ -916,5 +916,27 @@ public interface Constants {
return (enumHelper.toString(this)); return (enumHelper.toString(this));
} }
} }
/** Enum to use for specifying the Event scope. */
public enum EventScope {
ALL;
private static JacksonJsonEnumHelper<EventScope> enumHelper = new JacksonJsonEnumHelper<>(EventScope.class);
@JsonCreator
public static EventScope forValue(String value) {
return enumHelper.forValue(value);
}
@JsonValue
public String toValue() {
return (enumHelper.toString(this));
}
@Override
public String toString() {
return (enumHelper.toString(this));
}
}
} }
...@@ -36,6 +36,24 @@ public class EventsApi extends AbstractApi { ...@@ -36,6 +36,24 @@ public class EventsApi extends AbstractApi {
return (getAuthenticatedUserEvents(action, targetType, before, after, sortOrder, getDefaultPerPage()).all()); return (getAuthenticatedUserEvents(action, targetType, before, after, sortOrder, getDefaultPerPage()).all());
} }
/**
* Get a list of all events for the authenticated user, across all of the user's projects.
*
* <pre><code>GitLab Endpoint: GET /events</code></pre>
*
* @param action include only events of a particular action type, optional
* @param targetType include only events of a particular target type, optional
* @param before include only events created before a particular date, optional
* @param after include only events created after a particular date, optional
* @param sortOrder sort events in ASC or DESC order by created_at. Default is DESC, optional
* @return a list of events for the authenticated user and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
*/
public List<Event> getAllAuthenticatedUserEvents(ActionType action, TargetType targetType,
Date before, Date after, SortOrder sortOrder) throws GitLabApiException {
return (getAuthenticatedUserEvents(action, targetType, before, after, sortOrder, getDefaultPerPage(), EventScope.ALL).all());
}
/** /**
* Get a list of events for the authenticated user and in the specified page range. * Get a list of events for the authenticated user and in the specified page range.
* *
...@@ -53,6 +71,27 @@ public class EventsApi extends AbstractApi { ...@@ -53,6 +71,27 @@ public class EventsApi extends AbstractApi {
*/ */
public List<Event> getAuthenticatedUserEvents(ActionType action, TargetType targetType, public List<Event> getAuthenticatedUserEvents(ActionType action, TargetType targetType,
Date before, Date after, SortOrder sortOrder, int page, int perPage) throws GitLabApiException { Date before, Date after, SortOrder sortOrder, int page, int perPage) throws GitLabApiException {
return (getAuthenticatedUserEvents(action, targetType, before, after, sortOrder, page, perPage, null));
}
/**
* Get a list of events for the authenticated user and in the specified page range.
*
* <pre><code>GitLab Endpoint: GET /events</code></pre>
*
* @param action include only events of a particular action type, optional
* @param targetType include only events of a particular target type, optional
* @param before include only events created before a particular date, optional
* @param after include only events created after a particular date, optional
* @param sortOrder sort events in ASC or DESC order by created_at. Default is DESC, optional
* @param page the page to get
* @param perPage the number of projects per page
* @param scope include all events across a user’s projects, optional
* @return a list of events for the authenticated user and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
*/
public List<Event> getAuthenticatedUserEvents(ActionType action, TargetType targetType,
Date before, Date after, SortOrder sortOrder, int page, int perPage, EventScope scope) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm() GitLabApiForm formData = new GitLabApiForm()
.withParam("action", action) .withParam("action", action)
...@@ -61,7 +100,8 @@ public class EventsApi extends AbstractApi { ...@@ -61,7 +100,8 @@ public class EventsApi extends AbstractApi {
.withParam("after", after) .withParam("after", after)
.withParam("sort", sortOrder) .withParam("sort", sortOrder)
.withParam(PAGE_PARAM, page) .withParam(PAGE_PARAM, page)
.withParam(PER_PAGE_PARAM, perPage); .withParam(PER_PAGE_PARAM, perPage)
.withParam("scope", scope != null ? scope.toValue().toLowerCase() : null);
Response response = get(Response.Status.OK, formData.asMap(), "events"); Response response = get(Response.Status.OK, formData.asMap(), "events");
return (response.readEntity(new GenericType<List<Event>>() {})); return (response.readEntity(new GenericType<List<Event>>() {}));
...@@ -83,13 +123,34 @@ public class EventsApi extends AbstractApi { ...@@ -83,13 +123,34 @@ public class EventsApi extends AbstractApi {
*/ */
public Pager<Event> getAuthenticatedUserEvents(ActionType action, TargetType targetType, Date before, Date after, public Pager<Event> getAuthenticatedUserEvents(ActionType action, TargetType targetType, Date before, Date after,
SortOrder sortOrder, int itemsPerPage) throws GitLabApiException { SortOrder sortOrder, int itemsPerPage) throws GitLabApiException {
return (getAuthenticatedUserEvents(action, targetType, before, after, sortOrder, itemsPerPage, null));
}
/**
* Get a list of events for the authenticated user and in the specified page range.
*
* <pre><code>GitLab Endpoint: GET /events</code></pre>
*
* @param action include only events of a particular action type, optional
* @param targetType include only events of a particular target type, optional
* @param before include only events created before a particular date, optional
* @param after include only events created after a particular date, optional
* @param sortOrder sort events in ASC or DESC order by created_at. Default is DESC, optional
* @param itemsPerPage the number of Event instances that will be fetched per page
* @param scope include all events across a user’s projects, optional
* @return a Pager of events for the authenticated user and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
*/
public Pager<Event> getAuthenticatedUserEvents(ActionType action, TargetType targetType, Date before, Date after,
SortOrder sortOrder, int itemsPerPage, EventScope scope) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm() GitLabApiForm formData = new GitLabApiForm()
.withParam("action", action) .withParam("action", action)
.withParam("target_type", targetType != null ? targetType.toValue().toLowerCase() : null) .withParam("target_type", targetType != null ? targetType.toValue().toLowerCase() : null)
.withParam("before", before) .withParam("before", before)
.withParam("after", after) .withParam("after", after)
.withParam("sort", sortOrder); .withParam("sort", sortOrder)
.withParam("scope", scope != null ? scope.toValue().toLowerCase() : null);
return (new Pager<Event>(this, Event.class, itemsPerPage, formData.asMap(), "events")); return (new Pager<Event>(this, Event.class, itemsPerPage, formData.asMap(), "events"));
} }
...@@ -109,7 +170,25 @@ public class EventsApi extends AbstractApi { ...@@ -109,7 +170,25 @@ public class EventsApi extends AbstractApi {
*/ */
public Stream<Event> getAuthenticatedUserEventsStream(ActionType action, TargetType targetType, public Stream<Event> getAuthenticatedUserEventsStream(ActionType action, TargetType targetType,
Date before, Date after, SortOrder sortOrder) throws GitLabApiException { Date before, Date after, SortOrder sortOrder) throws GitLabApiException {
return (getAuthenticatedUserEvents(action, targetType, before, after, sortOrder, getDefaultPerPage()).stream()); return (getAuthenticatedUserEvents(action, targetType, before, after, sortOrder, getDefaultPerPage(), null).stream());
}
/**
* Get a Stream of all events for the authenticated user, across all of the user's projects.
*
* <pre><code>GitLab Endpoint: GET /events</code></pre>
*
* @param action include only events of a particular action type, optional
* @param targetType include only events of a particular target type, optional
* @param before include only events created before a particular date, optional
* @param after include only events created after a particular date, optional
* @param sortOrder sort events in ASC or DESC order by created_at. Default is DESC, optional
* @return a Stream of events for the authenticated user and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
*/
public Stream<Event> getAllAuthenticatedUserEventsStream(ActionType action, TargetType targetType,
Date before, Date after, SortOrder sortOrder) throws GitLabApiException {
return (getAuthenticatedUserEvents(action, targetType, before, after, sortOrder, getDefaultPerPage(), EventScope.ALL).stream());
} }
/** /**
......
...@@ -65,6 +65,18 @@ public class TestEventsApi extends AbstractIntegrationTest { ...@@ -65,6 +65,18 @@ public class TestEventsApi extends AbstractIntegrationTest {
assertNotNull(events); assertNotNull(events);
} }
@Test
public void testGetAuthenticatedUserEventsWithScope() throws GitLabApiException {
List<Event> events = gitLabApi.getEventsApi().getAuthenticatedUserEvents(null, null, null, null, null, 1, 10, Constants.EventScope.ALL);
assertNotNull(events);
}
@Test
public void testGetAllAuthenticatedUserEvents() throws GitLabApiException {
List<Event> events = gitLabApi.getEventsApi().getAllAuthenticatedUserEvents(null, null, null, null, null);
assertNotNull(events);
}
@Test @Test
public void testGetAuthenticatedUserEventsWithDates() throws GitLabApiException { public void testGetAuthenticatedUserEventsWithDates() throws GitLabApiException {
Date after = new Date(0); Date after = new Date(0);
...@@ -77,6 +89,18 @@ public class TestEventsApi extends AbstractIntegrationTest { ...@@ -77,6 +89,18 @@ public class TestEventsApi extends AbstractIntegrationTest {
assertEquals(0, events.size()); assertEquals(0, events.size());
} }
@Test
public void testGetAuthenticatedUserEventsWithDatesAndScope() throws GitLabApiException {
Date after = new Date(0);
Date now = new Date();
List<Event> events = gitLabApi.getEventsApi().getAuthenticatedUserEvents(null, null, now, after, null, 1, 10, Constants.EventScope.ALL);
assertNotNull(events);
events = gitLabApi.getEventsApi().getAuthenticatedUserEvents(null, null, after, null, null, 1, 10, Constants.EventScope.ALL);
assertNotNull(events);
assertEquals(0, events.size());
}
@Test @Test
public void testGetUserEvents() throws GitLabApiException { public void testGetUserEvents() throws GitLabApiException {
assertNotNull(testUser); assertNotNull(testUser);
...@@ -107,6 +131,12 @@ public class TestEventsApi extends AbstractIntegrationTest { ...@@ -107,6 +131,12 @@ public class TestEventsApi extends AbstractIntegrationTest {
assertNotNull(events); assertNotNull(events);
} }
@Test
public void testPagedGetAuthenticatedUserEventsWithScope() throws GitLabApiException {
Pager<Event> events = gitLabApi.getEventsApi().getAuthenticatedUserEvents(null, null, null, null, null, 10, Constants.EventScope.ALL);
assertNotNull(events);
}
@Test @Test
public void testPagedGetUserEvents() throws GitLabApiException { public void testPagedGetUserEvents() throws GitLabApiException {
assertNotNull(testUser); assertNotNull(testUser);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment