use of com.redhat.cloud.notifications.models.EndpointType in project notifications-backend by RedHatInsights.
the class EndpointResource method deleteEndpoint.
@DELETE
@Path("/{id}")
@RolesAllowed(ConsoleIdentityProvider.RBAC_WRITE_INTEGRATIONS_ENDPOINTS)
@APIResponse(responseCode = "204", description = "The integration has been deleted", content = @Content(schema = @Schema(type = SchemaType.STRING)))
@Transactional
public Response deleteEndpoint(@Context SecurityContext sec, @PathParam("id") UUID id) {
RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
EndpointType endpointType = endpointRepository.getEndpointTypeById(principal.getAccount(), id);
checkSystemEndpoint(endpointType);
if (obEnabled) {
Endpoint e = endpointRepository.getEndpoint(principal.getAccount(), id);
if (e != null) {
EndpointProperties properties = e.getProperties();
if (properties instanceof CamelProperties) {
CamelProperties cp = (CamelProperties) properties;
// Special case wrt OpenBridge
if (e.getSubType().equals("slack")) {
String processorId = cp.getExtras().get(OB_PROCESSOR_ID);
if (processorId != null) {
// Should not be null under normal operations.
try {
bridgeApiService.deleteProcessor(bridge.getId(), processorId, bridgeAuth.getToken());
} catch (Exception ex) {
LOGGER.warn("Removal of OB processor failed:" + ex.getMessage());
// Nothing more we can do
}
} else {
LOGGER.warn("ProcessorId was null for endpoint " + id.toString());
}
}
}
}
}
endpointRepository.deleteEndpoint(principal.getAccount(), id);
return Response.noContent().build();
}
use of com.redhat.cloud.notifications.models.EndpointType in project notifications-backend by RedHatInsights.
the class EndpointResource method updateEndpoint.
@PUT
@Path("/{id}")
@Consumes(APPLICATION_JSON)
@Produces(TEXT_PLAIN)
@RolesAllowed(ConsoleIdentityProvider.RBAC_WRITE_INTEGRATIONS_ENDPOINTS)
@APIResponse(responseCode = "200", content = @Content(schema = @Schema(type = SchemaType.STRING)))
@Transactional
public Response updateEndpoint(@Context SecurityContext sec, @PathParam("id") UUID id, @NotNull @Valid Endpoint endpoint) {
// This prevents from updating an endpoint from whatever EndpointType to a system EndpointType
checkSystemEndpoint(endpoint.getType());
RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
endpoint.setAccountId(principal.getAccount());
endpoint.setId(id);
EndpointType endpointType = endpointRepository.getEndpointTypeById(principal.getAccount(), id);
// This prevents from updating an endpoint from system EndpointType to a whatever EndpointType
checkSystemEndpoint(endpointType);
endpointRepository.updateEndpoint(endpoint);
return Response.ok().build();
}
use of com.redhat.cloud.notifications.models.EndpointType 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;
}
Aggregations