use of io.gravitee.rest.api.model.EventEntity in project gravitee-management-rest-api by gravitee-io.
the class PlatformEventsResource method getPlatformEvents.
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "List platform events", notes = "User must have the MANAGEMENT_PLATFORM[READ] permission to use this service")
@ApiResponses({ @ApiResponse(code = 200, message = "Platform events", response = EventEntity.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.ENVIRONMENT_PLATFORM, acls = RolePermissionAction.READ) })
public Page<EventEntity> getPlatformEvents(@BeanParam EventSearchParam eventSearchParam) {
eventSearchParam.validate();
Map<String, Object> properties = new HashMap<>();
if (eventSearchParam.getApiIdsParam() != null && eventSearchParam.getApiIdsParam().getIds() != null && !eventSearchParam.getApiIdsParam().getIds().isEmpty()) {
properties.put(Event.EventProperties.API_ID.getValue(), eventSearchParam.getApiIdsParam().getIds());
} else if (!isAdmin()) {
properties.put(Event.EventProperties.API_ID.getValue(), apiService.findByUser(getAuthenticatedUser(), null, false).stream().filter(api -> permissionService.hasPermission(API_ANALYTICS, api.getId(), READ)).map(ApiEntity::getId).collect(Collectors.joining(",")));
}
Page<EventEntity> events = eventService.search(eventSearchParam.getEventTypeListParam().getEventTypes(), properties, eventSearchParam.getFrom(), eventSearchParam.getTo(), eventSearchParam.getPage(), eventSearchParam.getSize());
events.getContent().forEach(event -> {
Map<String, String> properties1 = event.getProperties();
// Event relative to API
if (properties1 != null && properties1.containsKey(Event.EventProperties.API_ID.getValue())) {
// Remove payload content from response since it's not required anymore
event.setPayload(null);
// Retrieve additional data
String apiId = properties1.get(Event.EventProperties.API_ID.getValue());
try {
ApiEntity api = apiService.findById(apiId);
properties1.put("api_name", api.getName());
properties1.put("api_version", api.getVersion());
} catch (ApiNotFoundException anfe) {
properties1.put("deleted", Boolean.TRUE.toString());
properties1.put("api_name", "Deleted API");
}
}
});
return events;
}
use of io.gravitee.rest.api.model.EventEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiEventsResource method searchApiEvents.
@GET
@Path("search")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get API's events", notes = "User must have the API_EVENT[READ] permission to use this service")
@ApiResponses({ @ApiResponse(code = 200, message = "Page of API events", response = Page.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.API_EVENT, acls = RolePermissionAction.READ) })
public Page<EventEntity> searchApiEvents(@ApiParam @BeanParam EventSearchParam eventSearchParam) {
ApiEntity apiEntity = apiService.findById(api);
Map<String, Object> properties = new HashMap<>();
properties.put(Event.EventProperties.API_ID.getValue(), Arrays.asList(api));
final Page<EventEntity> apiEvents = eventService.search(eventSearchParam.getEventTypeListParam().getEventTypes(), properties, eventSearchParam.getFrom(), eventSearchParam.getTo(), eventSearchParam.getPage(), eventSearchParam.getSize());
apiEvents.getContent().forEach(event -> {
Map<String, String> properties1 = event.getProperties();
// Remove payload content from response since it's not required anymore
event.setPayload(null);
// complete event with API info
properties1.put("api_name", apiEntity.getName());
properties1.put("api_version", apiEntity.getVersion());
});
return apiEvents;
}
use of io.gravitee.rest.api.model.EventEntity in project gravitee-management-rest-api by gravitee-io.
the class EventServiceTest method shouldFindById.
@Test
public void shouldFindById() throws TechnicalException {
when(event.getType()).thenReturn(EventType.PUBLISH_API);
when(event.getPayload()).thenReturn(EVENT_PAYLOAD);
when(event.getProperties()).thenReturn(EVENT_PROPERTIES);
when(eventRepository.findById(EVENT_ID)).thenReturn(Optional.of(event));
final EventEntity eventEntity = eventService.findById(EVENT_ID);
assertNotNull(eventEntity);
}
use of io.gravitee.rest.api.model.EventEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiEventsResource method getApiEventsEvents.
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get API's events", notes = "User must have the MANAGE_LIFECYCLE permission to use this service")
@ApiResponses({ @ApiResponse(code = 200, message = "API's events"), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.API_EVENT, acls = RolePermissionAction.READ) })
public List<EventEntity> getApiEventsEvents(@ApiParam @DefaultValue("all") @QueryParam("type") EventTypeListParam eventTypeListParam) {
final EventQuery query = new EventQuery();
query.setApi(api);
return eventService.search(query).stream().filter(event -> eventTypeListParam.getEventTypes().contains(event.getType())).sorted((e1, e2) -> e2.getCreatedAt().compareTo(e1.getCreatedAt())).collect(Collectors.toList());
}
use of io.gravitee.rest.api.model.EventEntity in project gravitee-management-rest-api by gravitee-io.
the class EventServiceTest method shouldCreateEventWithPublishApiEventType.
@Test
public void shouldCreateEventWithPublishApiEventType() throws TechnicalException {
when(event.getType()).thenReturn(EventType.PUBLISH_API);
when(event.getPayload()).thenReturn(EVENT_PAYLOAD);
when(event.getProperties()).thenReturn(EVENT_PROPERTIES);
when(eventRepository.create(any())).thenReturn(event);
when(newEvent.getType()).thenReturn(io.gravitee.rest.api.model.EventType.PUBLISH_API);
when(newEvent.getPayload()).thenReturn(EVENT_PAYLOAD);
when(newEvent.getProperties()).thenReturn(EVENT_PROPERTIES);
final EventEntity eventEntity = eventService.create(newEvent);
assertNotNull(eventEntity);
assertEquals(EventType.PUBLISH_API.toString(), eventEntity.getType().toString());
assertEquals(EVENT_PAYLOAD, eventEntity.getPayload());
assertEquals(EVENT_USERNAME, eventEntity.getProperties().get(Event.EventProperties.USER.getValue()));
}
Aggregations