Search in sources :

Example 1 with EndpointProperties

use of com.redhat.cloud.notifications.models.EndpointProperties 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());
                }
            }
        }
    }
}
Also used : CamelProperties(com.redhat.cloud.notifications.models.CamelProperties) EndpointProperties(com.redhat.cloud.notifications.models.EndpointProperties) EmailSubscriptionProperties(com.redhat.cloud.notifications.models.EmailSubscriptionProperties) Endpoint(com.redhat.cloud.notifications.models.Endpoint) Logger(org.jboss.logging.Logger) Set(java.util.Set) EMAIL_SUBSCRIPTION(com.redhat.cloud.notifications.models.EndpointType.EMAIL_SUBSCRIPTION) UUID(java.util.UUID) CAMEL(com.redhat.cloud.notifications.models.EndpointType.CAMEL) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) WEBHOOK(com.redhat.cloud.notifications.models.EndpointType.WEBHOOK) Inject(javax.inject.Inject) HashSet(java.util.HashSet) EventType(com.redhat.cloud.notifications.models.EventType) List(java.util.List) EndpointType(com.redhat.cloud.notifications.models.EndpointType) StatelessSessionFactory(com.redhat.cloud.notifications.db.StatelessSessionFactory) Map(java.util.Map) Optional(java.util.Optional) WebhookProperties(com.redhat.cloud.notifications.models.WebhookProperties) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Endpoint(com.redhat.cloud.notifications.models.Endpoint) CamelProperties(com.redhat.cloud.notifications.models.CamelProperties) UUID(java.util.UUID)

Example 2 with EndpointProperties

use of com.redhat.cloud.notifications.models.EndpointProperties 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();
}
Also used : Endpoint(com.redhat.cloud.notifications.models.Endpoint) RhIdPrincipal(com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal) EndpointType(com.redhat.cloud.notifications.models.EndpointType) CompositeEndpointType(com.redhat.cloud.notifications.models.CompositeEndpointType) CamelProperties(com.redhat.cloud.notifications.models.CamelProperties) EndpointProperties(com.redhat.cloud.notifications.models.EndpointProperties) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) NotFoundException(javax.ws.rs.NotFoundException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RolesAllowed(javax.annotation.security.RolesAllowed) APIResponse(org.eclipse.microprofile.openapi.annotations.responses.APIResponse) Transactional(javax.transaction.Transactional)

Aggregations

CamelProperties (com.redhat.cloud.notifications.models.CamelProperties)2 Endpoint (com.redhat.cloud.notifications.models.Endpoint)2 EndpointProperties (com.redhat.cloud.notifications.models.EndpointProperties)2 EndpointType (com.redhat.cloud.notifications.models.EndpointType)2 RhIdPrincipal (com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal)1 StatelessSessionFactory (com.redhat.cloud.notifications.db.StatelessSessionFactory)1 CompositeEndpointType (com.redhat.cloud.notifications.models.CompositeEndpointType)1 EmailSubscriptionProperties (com.redhat.cloud.notifications.models.EmailSubscriptionProperties)1 CAMEL (com.redhat.cloud.notifications.models.EndpointType.CAMEL)1 EMAIL_SUBSCRIPTION (com.redhat.cloud.notifications.models.EndpointType.EMAIL_SUBSCRIPTION)1 WEBHOOK (com.redhat.cloud.notifications.models.EndpointType.WEBHOOK)1 EventType (com.redhat.cloud.notifications.models.EventType)1 WebhookProperties (com.redhat.cloud.notifications.models.WebhookProperties)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 UUID (java.util.UUID)1 Function (java.util.function.Function)1