Search in sources :

Example 1 with Page

use of com.redhat.cloud.notifications.routers.models.Page in project notifications-backend by RedHatInsights.

the class NotificationResource method getEventTypes.

@GET
@Path("/eventTypes")
@Produces(APPLICATION_JSON)
@Operation(summary = "Retrieve all event types. The returned list can be filtered by bundle or application.")
@RolesAllowed(ConsoleIdentityProvider.RBAC_READ_NOTIFICATIONS)
public Page<EventType> getEventTypes(@Context UriInfo uriInfo, @BeanParam Query query, @QueryParam("applicationIds") Set<UUID> applicationIds, @QueryParam("bundleId") UUID bundleId, @QueryParam("eventTypeName") String eventTypeName) {
    List<EventType> eventTypes = applicationRepository.getEventTypes(query, applicationIds, bundleId, eventTypeName);
    Long count = applicationRepository.getEventTypesCount(applicationIds, bundleId, eventTypeName);
    return new Page<>(eventTypes, PageLinksBuilder.build(uriInfo.getPath(), count, query.getLimit().getLimit(), query.getLimit().getOffset()), new Meta(count));
}
Also used : Meta(com.redhat.cloud.notifications.routers.models.Meta) EventType(com.redhat.cloud.notifications.models.EventType) Page(com.redhat.cloud.notifications.routers.models.Page) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(org.eclipse.microprofile.openapi.annotations.Operation)

Example 2 with Page

use of com.redhat.cloud.notifications.routers.models.Page in project notifications-backend by RedHatInsights.

the class EventResource method getEvents.

@GET
@Produces(APPLICATION_JSON)
@RolesAllowed(RBAC_READ_NOTIFICATIONS_EVENTS)
@Operation(summary = "Retrieve the event log entries.")
public Page<EventLogEntry> getEvents(@Context SecurityContext securityContext, @RestQuery Set<UUID> bundleIds, @RestQuery Set<UUID> appIds, @RestQuery String eventTypeDisplayName, @RestQuery LocalDate startDate, @RestQuery LocalDate endDate, @RestQuery Set<String> endpointTypes, @RestQuery Set<Boolean> invocationResults, @RestQuery @DefaultValue("10") int limit, @RestQuery @DefaultValue("0") int offset, @RestQuery String sortBy, @RestQuery boolean includeDetails, @RestQuery boolean includePayload, @RestQuery boolean includeActions) {
    if (limit < 1 || limit > 200) {
        throw new BadRequestException("Invalid 'limit' query parameter, its value must be between 1 and 200");
    }
    if (sortBy != null && !SORT_BY_PATTERN.matcher(sortBy).matches()) {
        throw new BadRequestException("Invalid 'sortBy' query parameter");
    }
    Set<EndpointType> basicTypes = Collections.emptySet();
    Set<CompositeEndpointType> compositeTypes = Collections.emptySet();
    if (endpointTypes != null && endpointTypes.size() > 0) {
        basicTypes = new HashSet<>();
        compositeTypes = new HashSet<>();
        for (String stringEndpointType : endpointTypes) {
            try {
                CompositeEndpointType compositeType = CompositeEndpointType.fromString(stringEndpointType);
                if (compositeType.getSubType() == null) {
                    basicTypes.add(compositeType.getType());
                } else {
                    compositeTypes.add(compositeType);
                }
            } catch (IllegalArgumentException e) {
                throw new BadRequestException("Unknown endpoint type: [" + stringEndpointType + "]", e);
            }
        }
    }
    String accountId = getAccountId(securityContext);
    List<Event> events = eventRepository.getEvents(accountId, bundleIds, appIds, eventTypeDisplayName, startDate, endDate, basicTypes, compositeTypes, invocationResults, includeActions, limit, offset, sortBy);
    List<EventLogEntry> eventLogEntries = events.stream().map(event -> {
        List<EventLogEntryAction> actions;
        if (!includeActions) {
            actions = Collections.emptyList();
        } else {
            actions = event.getHistoryEntries().stream().map(historyEntry -> {
                EventLogEntryAction action = new EventLogEntryAction();
                action.setId(historyEntry.getId());
                action.setEndpointId(historyEntry.getEndpointId());
                action.setEndpointType(historyEntry.getEndpointType());
                action.setEndpointSubType(historyEntry.getEndpointSubType());
                action.setInvocationResult(historyEntry.isInvocationResult());
                if (includeDetails) {
                    action.setDetails(historyEntry.getDetails());
                }
                return action;
            }).collect(Collectors.toList());
        }
        EventLogEntry entry = new EventLogEntry();
        entry.setId(event.getId());
        entry.setCreated(event.getCreated());
        entry.setBundle(event.getBundleDisplayName());
        entry.setApplication(event.getApplicationDisplayName());
        entry.setEventType(event.getEventTypeDisplayName());
        entry.setActions(actions);
        if (includePayload) {
            entry.setPayload(event.getPayload());
        }
        return entry;
    }).collect(Collectors.toList());
    Long count = eventRepository.count(accountId, bundleIds, appIds, eventTypeDisplayName, startDate, endDate, basicTypes, compositeTypes, invocationResults);
    Meta meta = new Meta();
    meta.setCount(count);
    Map<String, String> links = PageLinksBuilder.build(PATH, count, limit, offset);
    Page<EventLogEntry> page = new Page<>();
    page.setData(eventLogEntries);
    page.setMeta(meta);
    page.setLinks(links);
    return page;
}
Also used : CompositeEndpointType(com.redhat.cloud.notifications.models.CompositeEndpointType) API_NOTIFICATIONS_V_1_0(com.redhat.cloud.notifications.Constants.API_NOTIFICATIONS_V_1_0) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) SecurityContext(javax.ws.rs.core.SecurityContext) EventLogEntry(com.redhat.cloud.notifications.routers.models.EventLogEntry) CASE_INSENSITIVE(java.util.regex.Pattern.CASE_INSENSITIVE) Inject(javax.inject.Inject) HashSet(java.util.HashSet) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) SecurityContextUtil.getAccountId(com.redhat.cloud.notifications.routers.SecurityContextUtil.getAccountId) Event(com.redhat.cloud.notifications.models.Event) BadRequestException(javax.ws.rs.BadRequestException) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) RestQuery(org.jboss.resteasy.reactive.RestQuery) PATH(com.redhat.cloud.notifications.routers.EventResource.PATH) Meta(com.redhat.cloud.notifications.routers.models.Meta) Context(javax.ws.rs.core.Context) PageLinksBuilder(com.redhat.cloud.notifications.routers.models.PageLinksBuilder) RBAC_READ_NOTIFICATIONS_EVENTS(com.redhat.cloud.notifications.auth.ConsoleIdentityProvider.RBAC_READ_NOTIFICATIONS_EVENTS) Set(java.util.Set) Operation(org.eclipse.microprofile.openapi.annotations.Operation) UUID(java.util.UUID) EventRepository(com.redhat.cloud.notifications.db.repositories.EventRepository) Collectors(java.util.stream.Collectors) List(java.util.List) EndpointType(com.redhat.cloud.notifications.models.EndpointType) Page(com.redhat.cloud.notifications.routers.models.Page) LocalDate(java.time.LocalDate) EventLogEntryAction(com.redhat.cloud.notifications.routers.models.EventLogEntryAction) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) Meta(com.redhat.cloud.notifications.routers.models.Meta) EventLogEntry(com.redhat.cloud.notifications.routers.models.EventLogEntry) Page(com.redhat.cloud.notifications.routers.models.Page) CompositeEndpointType(com.redhat.cloud.notifications.models.CompositeEndpointType) EventLogEntryAction(com.redhat.cloud.notifications.routers.models.EventLogEntryAction) CompositeEndpointType(com.redhat.cloud.notifications.models.CompositeEndpointType) EndpointType(com.redhat.cloud.notifications.models.EndpointType) BadRequestException(javax.ws.rs.BadRequestException) Event(com.redhat.cloud.notifications.models.Event) List(java.util.List) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(org.eclipse.microprofile.openapi.annotations.Operation)

Aggregations

Meta (com.redhat.cloud.notifications.routers.models.Meta)2 Page (com.redhat.cloud.notifications.routers.models.Page)2 RolesAllowed (javax.annotation.security.RolesAllowed)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Operation (org.eclipse.microprofile.openapi.annotations.Operation)2 API_NOTIFICATIONS_V_1_0 (com.redhat.cloud.notifications.Constants.API_NOTIFICATIONS_V_1_0)1 RBAC_READ_NOTIFICATIONS_EVENTS (com.redhat.cloud.notifications.auth.ConsoleIdentityProvider.RBAC_READ_NOTIFICATIONS_EVENTS)1 EventRepository (com.redhat.cloud.notifications.db.repositories.EventRepository)1 CompositeEndpointType (com.redhat.cloud.notifications.models.CompositeEndpointType)1 EndpointType (com.redhat.cloud.notifications.models.EndpointType)1 Event (com.redhat.cloud.notifications.models.Event)1 EventType (com.redhat.cloud.notifications.models.EventType)1 PATH (com.redhat.cloud.notifications.routers.EventResource.PATH)1 SecurityContextUtil.getAccountId (com.redhat.cloud.notifications.routers.SecurityContextUtil.getAccountId)1 EventLogEntry (com.redhat.cloud.notifications.routers.models.EventLogEntry)1 EventLogEntryAction (com.redhat.cloud.notifications.routers.models.EventLogEntryAction)1 PageLinksBuilder (com.redhat.cloud.notifications.routers.models.PageLinksBuilder)1 LocalDate (java.time.LocalDate)1