use of com.redhat.cloud.notifications.models.EndpointType in project notifications-backend by RedHatInsights.
the class EndpointResource method disableEndpoint.
@DELETE
@Path("/{id}/enable")
@RolesAllowed(ConsoleIdentityProvider.RBAC_WRITE_INTEGRATIONS_ENDPOINTS)
@APIResponse(responseCode = "204", description = "The integration has been disabled", content = @Content(schema = @Schema(type = SchemaType.STRING)))
@Transactional
public Response disableEndpoint(@Context SecurityContext sec, @PathParam("id") UUID id) {
RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
EndpointType endpointType = endpointRepository.getEndpointTypeById(principal.getAccount(), id);
checkSystemEndpoint(endpointType);
endpointRepository.disableEndpoint(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 enableEndpoint.
@PUT
@Path("/{id}/enable")
@Produces(TEXT_PLAIN)
@RolesAllowed(ConsoleIdentityProvider.RBAC_WRITE_INTEGRATIONS_ENDPOINTS)
@APIResponse(responseCode = "200", content = @Content(schema = @Schema(type = SchemaType.STRING)))
@Transactional
public Response enableEndpoint(@Context SecurityContext sec, @PathParam("id") UUID id) {
RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
EndpointType endpointType = endpointRepository.getEndpointTypeById(principal.getAccount(), id);
checkSystemEndpoint(endpointType);
endpointRepository.enableEndpoint(principal.getAccount(), id);
return Response.ok().build();
}
use of com.redhat.cloud.notifications.models.EndpointType in project notifications-backend by RedHatInsights.
the class EndpointProcessor method process.
public void process(Event event) {
processedItems.increment();
List<Endpoint> endpoints = endpointRepository.getTargetEndpoints(event.getAccountId(), event.getEventType());
// Target endpoints are grouped by endpoint type.
endpointTargeted.increment(endpoints.size());
Map<EndpointType, List<Endpoint>> endpointsByType = endpoints.stream().collect(Collectors.groupingBy(Endpoint::getType));
for (Map.Entry<EndpointType, List<Endpoint>> entry : endpointsByType.entrySet()) {
/*
* For each endpoint type, the list of target endpoints is sent alongside with the action to the relevant processor.
* Each processor returns a list of history entries. All of the returned lists are flattened into a single list.
*/
EndpointTypeProcessor processor = endpointTypeToProcessor(entry.getKey());
List<NotificationHistory> historyEntries = processor.process(event, entry.getValue());
// Now each history entry is persisted.
for (NotificationHistory history : historyEntries) {
try {
notificationHistoryRepository.createNotificationHistory(history);
} catch (Exception e) {
LOGGER.errorf("Notification history creation failed for %s", history.getEndpoint());
}
}
}
}
use of com.redhat.cloud.notifications.models.EndpointType in project notifications-backend by RedHatInsights.
the class EndpointRepository method loadTypedProperties.
private <T extends EndpointProperties> void loadTypedProperties(Class<T> typedEndpointClass, Set<Endpoint> endpoints, EndpointType type) {
Map<UUID, Endpoint> endpointsMap = endpoints.stream().filter(e -> e.getType().equals(type)).collect(Collectors.toMap(Endpoint::getId, Function.identity()));
if (endpointsMap.size() > 0) {
String hql = "FROM " + typedEndpointClass.getSimpleName() + " WHERE id IN (:endpointIds)";
List<T> propList = statelessSessionFactory.getCurrentSession().createQuery(hql, typedEndpointClass).setParameter("endpointIds", endpointsMap.keySet()).getResultList();
for (T props : propList) {
if (props != null) {
Endpoint endpoint = endpointsMap.get(props.getId());
endpoint.setProperties(props);
// Todo: NOTIF-429 backward compatibility change - Remove soon.
if (typedEndpointClass.equals(CamelProperties.class)) {
endpoint.getProperties(CamelProperties.class).setSubType(endpoint.getSubType());
}
}
}
}
}
use of com.redhat.cloud.notifications.models.EndpointType in project notifications-backend by RedHatInsights.
the class EndpointRepository method getOrCreateDefaultEmailSubscription.
/**
* The purpose of this method is to find or create an EMAIL_SUBSCRIPTION endpoint with empty properties. This
* endpoint is used to aggregate and store in the DB the email actions outcome, which will be used later by the
* event log. The recipients of the current email action have already been resolved before this step, possibly from
* multiple endpoints and recipients settings. The properties created below have no impact on the resolution of the
* action recipients.
*/
public Endpoint getOrCreateDefaultEmailSubscription(String accountId) {
String query = "FROM Endpoint WHERE accountId = :accountId AND compositeType.type = :endpointType";
List<Endpoint> emailEndpoints = statelessSessionFactory.getCurrentSession().createQuery(query, Endpoint.class).setParameter("accountId", accountId).setParameter("endpointType", EMAIL_SUBSCRIPTION).getResultList();
loadProperties(emailEndpoints);
EmailSubscriptionProperties properties = new EmailSubscriptionProperties();
Optional<Endpoint> endpointOptional = emailEndpoints.stream().filter(endpoint -> properties.hasSameProperties(endpoint.getProperties(EmailSubscriptionProperties.class))).findFirst();
if (endpointOptional.isPresent()) {
return endpointOptional.get();
}
Endpoint endpoint = new Endpoint();
endpoint.setProperties(properties);
endpoint.setAccountId(accountId);
endpoint.setEnabled(true);
endpoint.setDescription("System email endpoint");
endpoint.setName("Email endpoint");
endpoint.setType(EMAIL_SUBSCRIPTION);
endpoint.prePersist();
properties.setEndpoint(endpoint);
statelessSessionFactory.getCurrentSession().insert(endpoint);
statelessSessionFactory.getCurrentSession().insert(endpoint.getProperties());
return endpoint;
}
Aggregations