Search in sources :

Example 1 with BehaviorGroup

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

the class BehaviorGroupRepository method findEventTypesByBehaviorGroupId.

public List<EventType> findEventTypesByBehaviorGroupId(String accountId, UUID behaviorGroupId) {
    BehaviorGroup behaviorGroup = entityManager.find(BehaviorGroup.class, behaviorGroupId);
    if (behaviorGroup == null) {
        throw new NotFoundException("Behavior group not found");
    }
    String query = "SELECT e FROM EventType e LEFT JOIN FETCH e.application JOIN e.behaviors b " + "WHERE (b.behaviorGroup.accountId = :accountId OR b.behaviorGroup.accountId IS NULL) AND b.behaviorGroup.id = :behaviorGroupId";
    return entityManager.createQuery(query, EventType.class).setParameter("accountId", accountId).setParameter("behaviorGroupId", behaviorGroupId).getResultList();
}
Also used : EventType(com.redhat.cloud.notifications.models.EventType) BehaviorGroup(com.redhat.cloud.notifications.models.BehaviorGroup) NotFoundException(javax.ws.rs.NotFoundException)

Example 2 with BehaviorGroup

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

the class BehaviorGroupRepository method findBehaviorGroupsByEndpointId.

public List<BehaviorGroup> findBehaviorGroupsByEndpointId(String accountId, UUID endpointId) {
    Endpoint endpoint = entityManager.find(Endpoint.class, endpointId);
    if (endpoint == null) {
        throw new NotFoundException("Endpoint not found");
    }
    String query = "SELECT bg FROM BehaviorGroup bg LEFT JOIN FETCH bg.bundle JOIN bg.actions a WHERE bg.accountId = :accountId AND a.endpoint.id = :endpointId";
    List<BehaviorGroup> behaviorGroups = entityManager.createQuery(query, BehaviorGroup.class).setParameter("accountId", accountId).setParameter("endpointId", endpointId).getResultList();
    for (BehaviorGroup behaviorGroup : behaviorGroups) {
        behaviorGroup.filterOutActions();
    }
    return behaviorGroups;
}
Also used : Endpoint(com.redhat.cloud.notifications.models.Endpoint) BehaviorGroup(com.redhat.cloud.notifications.models.BehaviorGroup) NotFoundException(javax.ws.rs.NotFoundException)

Example 3 with BehaviorGroup

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

the class CrudTestHelpers method updateDefaultBehaviorGroup.

public static void updateDefaultBehaviorGroup(Header identity, String behaviorGroupId, String displayName, String bundleId, boolean expectedResult, int expectedStatus) {
    BehaviorGroup behaviorGroup = buildDefaultBehaviorGroup(displayName, bundleId);
    ValidatableResponse respoonse = given().header(identity).basePath(API_INTERNAL).contentType(JSON).body(Json.encode(behaviorGroup)).pathParam("id", behaviorGroupId).put("/behaviorGroups/default/{id}").then().statusCode(expectedStatus);
    if (familyOf(expectedStatus) == SUCCESSFUL) {
        Boolean result = respoonse.extract().as(Boolean.class);
        assertEquals(expectedResult, result);
    }
}
Also used : ValidatableResponse(io.restassured.response.ValidatableResponse) BehaviorGroup(com.redhat.cloud.notifications.models.BehaviorGroup)

Example 4 with BehaviorGroup

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

the class ResourceHelpers method createBehaviorGroup.

public BehaviorGroup createBehaviorGroup(String accountId, String displayName, UUID bundleId) {
    BehaviorGroup behaviorGroup = new BehaviorGroup();
    behaviorGroup.setDisplayName(displayName);
    behaviorGroup.setBundleId(bundleId);
    return behaviorGroupRepository.create(accountId, behaviorGroup);
}
Also used : BehaviorGroup(com.redhat.cloud.notifications.models.BehaviorGroup)

Example 5 with BehaviorGroup

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

the class ResourceHelpers method createDefaultBehaviorGroup.

public BehaviorGroup createDefaultBehaviorGroup(String displayName, UUID bundleId) {
    BehaviorGroup behaviorGroup = new BehaviorGroup();
    behaviorGroup.setDisplayName(displayName);
    behaviorGroup.setBundleId(bundleId);
    return behaviorGroupRepository.createDefault(behaviorGroup);
}
Also used : BehaviorGroup(com.redhat.cloud.notifications.models.BehaviorGroup)

Aggregations

BehaviorGroup (com.redhat.cloud.notifications.models.BehaviorGroup)28 Bundle (com.redhat.cloud.notifications.models.Bundle)12 QuarkusTest (io.quarkus.test.junit.QuarkusTest)12 Test (org.junit.jupiter.api.Test)12 DbIsolatedTest (com.redhat.cloud.notifications.db.DbIsolatedTest)11 EventType (com.redhat.cloud.notifications.models.EventType)8 Endpoint (com.redhat.cloud.notifications.models.Endpoint)6 Application (com.redhat.cloud.notifications.models.Application)5 NotFoundException (javax.ws.rs.NotFoundException)4 Transactional (javax.transaction.Transactional)3 ValidatableResponse (io.restassured.response.ValidatableResponse)2 BehaviorGroupAction (com.redhat.cloud.notifications.models.BehaviorGroupAction)1 BehaviorGroupActionId (com.redhat.cloud.notifications.models.BehaviorGroupActionId)1 EventTypeBehavior (com.redhat.cloud.notifications.models.EventTypeBehavior)1 EventTypeBehaviorId (com.redhat.cloud.notifications.models.EventTypeBehaviorId)1 Header (io.restassured.http.Header)1 JsonObject (io.vertx.core.json.JsonObject)1 BadRequestException (javax.ws.rs.BadRequestException)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1