Search in sources :

Example 11 with CamelProperties

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

the class CamelTypeProcessor method process.

private NotificationHistory process(Notification item) {
    Endpoint endpoint = item.getEndpoint();
    String subType = endpoint.getSubType();
    Counter processedCount = registry.counter(PROCESSED_COUNTER_NAME, "subType", subType);
    processedCount.increment();
    CamelProperties properties = (CamelProperties) endpoint.getProperties();
    Map<String, String> metaData = new HashMap<>();
    metaData.put("trustAll", String.valueOf(properties.getDisableSslVerification()));
    metaData.put("url", properties.getUrl());
    metaData.put("type", subType);
    if (properties.getSecretToken() != null && !properties.getSecretToken().isBlank()) {
        metaData.put(TOKEN_HEADER, properties.getSecretToken());
    }
    BasicAuthentication basicAuthentication = properties.getBasicAuthentication();
    if (basicAuthentication != null && basicAuthentication.getUsername() != null && basicAuthentication.getPassword() != null) {
        StringBuilder sb = new StringBuilder(basicAuthentication.getUsername());
        sb.append(":");
        sb.append(basicAuthentication.getPassword());
        String b64 = Base64Utils.encode(sb.toString());
        metaData.put("basicAuth", b64);
    }
    metaData.put("extras", new MapConverter().convertToDatabaseColumn(properties.getExtras()));
    String originalEventId = "-not provided-";
    if (item.getEvent().getId() != null) {
        originalEventId = item.getEvent().getId().toString();
    }
    metaData.put("_originalId", originalEventId);
    JsonObject payload = transformer.transform(item.getEvent().getAction());
    UUID historyId = UUID.randomUUID();
    JsonObject metadataAsJson = new JsonObject();
    payload.put(NOTIF_METADATA_KEY, metadataAsJson);
    metaData.forEach(metadataAsJson::put);
    return callCamel(item, historyId, payload, originalEventId);
}
Also used : Counter(io.micrometer.core.instrument.Counter) Endpoint(com.redhat.cloud.notifications.models.Endpoint) HashMap(java.util.HashMap) MapConverter(com.redhat.cloud.notifications.db.converters.MapConverter) CamelProperties(com.redhat.cloud.notifications.models.CamelProperties) BasicAuthentication(com.redhat.cloud.notifications.models.BasicAuthentication) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID)

Aggregations

CamelProperties (com.redhat.cloud.notifications.models.CamelProperties)11 Endpoint (com.redhat.cloud.notifications.models.Endpoint)10 JsonObject (io.vertx.core.json.JsonObject)5 HashMap (java.util.HashMap)5 BasicAuthentication (com.redhat.cloud.notifications.models.BasicAuthentication)4 QuarkusTest (io.quarkus.test.junit.QuarkusTest)4 Header (io.restassured.http.Header)4 Test (org.junit.jupiter.api.Test)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 DbIsolatedTest (com.redhat.cloud.notifications.db.DbIsolatedTest)3 Transactional (javax.transaction.Transactional)3 RhIdPrincipal (com.redhat.cloud.notifications.auth.principal.rhid.RhIdPrincipal)2 MapConverter (com.redhat.cloud.notifications.db.converters.MapConverter)2 NotificationHistory (com.redhat.cloud.notifications.models.NotificationHistory)2 WebhookProperties (com.redhat.cloud.notifications.models.WebhookProperties)2 UUID (java.util.UUID)2 RolesAllowed (javax.annotation.security.RolesAllowed)2 BadRequestException (javax.ws.rs.BadRequestException)2 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)2 NotFoundException (javax.ws.rs.NotFoundException)2