use of io.gravitee.management.model.EventEntity in project gravitee-management-rest-api by gravitee-io.
the class PlatformEventsResource method listEvents.
@GET
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.MANAGEMENT_PLATFORM, acls = RolePermissionAction.READ) })
public Page<EventEntity> listEvents(@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());
}
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());
ApiEntity api = apiService.findById(apiId);
properties1.put("api_name", api.getName());
properties1.put("api_version", api.getVersion());
}
});
return events;
}
use of io.gravitee.management.model.EventEntity in project gravitee-management-rest-api by gravitee-io.
the class EventServiceImpl method convert.
private EventEntity convert(Event event) {
EventEntity eventEntity = new EventEntity();
eventEntity.setId(event.getId());
eventEntity.setType(io.gravitee.management.model.EventType.valueOf(event.getType().toString()));
eventEntity.setPayload(event.getPayload());
eventEntity.setParentId(event.getParentId());
eventEntity.setProperties(event.getProperties());
eventEntity.setCreatedAt(event.getCreatedAt());
eventEntity.setUpdatedAt(event.getUpdatedAt());
if (event.getProperties() != null) {
final String userId = event.getProperties().get(Event.EventProperties.USER.getValue());
if (userId != null && !userId.isEmpty()) {
try {
eventEntity.setUser(userService.findById(userId));
} catch (UserNotFoundException unfe) {
UserEntity user = new UserEntity();
user.setSource("system");
user.setId(userId);
user.setUsername("system");
eventEntity.setUser(user);
}
}
}
return eventEntity;
}
use of io.gravitee.management.model.EventEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiService_StartTest method shouldStart.
@Test
public void shouldStart() throws Exception {
objectMapper.addMixIn(Api.class, ApiMixin.class);
when(apiRepository.findById(API_ID)).thenReturn(Optional.of(api));
when(apiRepository.update(api)).thenReturn(api);
final EventEntity event = mockEvent(EventType.PUBLISH_API);
when(eventService.findByApi(API_ID)).thenReturn(Collections.singleton(event));
Membership po = new Membership(USER_NAME, API_ID, MembershipReferenceType.API);
po.setRoles(Collections.singletonMap(RoleScope.API.getId(), SystemRole.PRIMARY_OWNER.name()));
when(membershipRepository.findByReferencesAndRole(any(), any(), any(), any())).thenReturn(Collections.singleton(po));
apiService.start(API_ID, USER_NAME);
verify(api).setUpdatedAt(any());
verify(api).setLifecycleState(LifecycleState.STARTED);
verify(apiRepository).update(api);
verify(eventService).create(EventType.START_API, event.getPayload(), event.getProperties());
}
use of io.gravitee.management.model.EventEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiService_StopTest method mockEvent.
private EventEntity mockEvent(EventType eventType) throws Exception {
final JsonNodeFactory factory = JsonNodeFactory.instance;
ObjectNode node = factory.objectNode();
node.set("id", factory.textNode(API_ID));
Map<String, String> properties = new HashMap<String, String>();
properties.put(Event.EventProperties.API_ID.getValue(), API_ID);
properties.put(Event.EventProperties.USER.getValue(), USER_NAME);
Api api = new Api();
api.setId(API_ID);
EventEntity event = new EventEntity();
event.setType(eventType);
event.setId(UUID.randomUUID().toString());
event.setPayload(objectMapper.writeValueAsString(api));
event.setCreatedAt(new Date());
event.setUpdatedAt(event.getCreatedAt());
event.setProperties(properties);
return event;
}
use of io.gravitee.management.model.EventEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiService_StopTest method shouldStop.
@Test
public void shouldStop() throws Exception {
objectMapper.addMixIn(Api.class, ApiMixin.class);
when(apiRepository.findById(API_ID)).thenReturn(Optional.of(api));
when(apiRepository.update(api)).thenReturn(api);
final EventEntity event = mockEvent(EventType.PUBLISH_API);
when(eventService.findByApi(API_ID)).thenReturn(Collections.singleton(event));
Membership po = new Membership(USER_NAME, API_ID, MembershipReferenceType.API);
po.setRoles(Collections.singletonMap(RoleScope.API.getId(), SystemRole.PRIMARY_OWNER.name()));
when(membershipRepository.findByReferencesAndRole(any(), any(), any(), any())).thenReturn(Collections.singleton(po));
apiService.stop(API_ID, USER_NAME);
verify(api).setUpdatedAt(any());
verify(api).setLifecycleState(LifecycleState.STOPPED);
verify(apiRepository).update(api);
verify(eventService).create(EventType.STOP_API, event.getPayload(), event.getProperties());
}
Aggregations