use of com.redhat.cloud.notifications.models.BehaviorGroup in project notifications-backend by RedHatInsights.
the class CrudTestHelpers method createDefaultBehaviorGroup.
public static Optional<String> createDefaultBehaviorGroup(Header identity, String displayName, String bundleId, int expected) {
BehaviorGroup behaviorGroup = buildDefaultBehaviorGroup(displayName, bundleId);
ValidatableResponse response = given().header(identity).basePath(API_INTERNAL).contentType(JSON).body(Json.encode(behaviorGroup)).post("/behaviorGroups/default").then().statusCode(expected);
if (familyOf(expected) == SUCCESSFUL) {
return Optional.of(response.extract().body().jsonPath().getString("id"));
}
return Optional.empty();
}
use of com.redhat.cloud.notifications.models.BehaviorGroup in project notifications-backend by RedHatInsights.
the class BehaviorGroupRepositoryTest method testAddAndDeleteEventTypeBehavior.
@Test
void testAddAndDeleteEventTypeBehavior() {
Bundle bundle = resourceHelpers.createBundle();
Application app = resourceHelpers.createApplication(bundle.getId());
EventType eventType = createEventType(app);
BehaviorGroup behaviorGroup1 = resourceHelpers.createBehaviorGroup(DEFAULT_ACCOUNT_ID, "Behavior group 1", bundle.getId());
BehaviorGroup behaviorGroup2 = resourceHelpers.createBehaviorGroup(DEFAULT_ACCOUNT_ID, "Behavior group 2", bundle.getId());
BehaviorGroup behaviorGroup3 = resourceHelpers.createBehaviorGroup(DEFAULT_ACCOUNT_ID, "Behavior group 3", bundle.getId());
updateAndCheckEventTypeBehaviors(DEFAULT_ACCOUNT_ID, eventType.getId(), true, behaviorGroup1.getId());
updateAndCheckEventTypeBehaviors(DEFAULT_ACCOUNT_ID, eventType.getId(), true, behaviorGroup1.getId());
updateAndCheckEventTypeBehaviors(DEFAULT_ACCOUNT_ID, eventType.getId(), true, behaviorGroup1.getId(), behaviorGroup2.getId());
updateAndCheckEventTypeBehaviors(DEFAULT_ACCOUNT_ID, eventType.getId(), true, behaviorGroup2.getId());
updateAndCheckEventTypeBehaviors(DEFAULT_ACCOUNT_ID, eventType.getId(), true, behaviorGroup1.getId(), behaviorGroup2.getId(), behaviorGroup3.getId());
updateAndCheckEventTypeBehaviors(DEFAULT_ACCOUNT_ID, eventType.getId(), true);
}
use of com.redhat.cloud.notifications.models.BehaviorGroup in project notifications-backend by RedHatInsights.
the class BehaviorGroupRepository method findDefaults.
public List<BehaviorGroup> findDefaults() {
final String query = "SELECT DISTINCT b FROM BehaviorGroup b LEFT JOIN FETCH b.actions a " + "WHERE b.accountId IS NULL " + "ORDER BY b.created DESC, a.position ASC";
List<BehaviorGroup> behaviorGroups = entityManager.createQuery(query, BehaviorGroup.class).getResultList();
for (BehaviorGroup behaviorGroup : behaviorGroups) {
behaviorGroup.filterOutBundle();
}
return behaviorGroups;
}
use of com.redhat.cloud.notifications.models.BehaviorGroup in project notifications-backend by RedHatInsights.
the class BehaviorGroupRepository method findByBundleId.
public List<BehaviorGroup> findByBundleId(String accountId, UUID bundleId) {
Bundle bundle = entityManager.find(Bundle.class, bundleId);
if (bundle == null) {
throw new NotFoundException("Bundle not found");
}
List<BehaviorGroup> behaviorGroups = entityManager.createNamedQuery("findByBundleId", BehaviorGroup.class).setParameter("accountId", accountId).setParameter("bundleId", bundleId).getResultList();
for (BehaviorGroup behaviorGroup : behaviorGroups) {
behaviorGroup.filterOutBundle();
}
return behaviorGroups;
}
use of com.redhat.cloud.notifications.models.BehaviorGroup in project notifications-backend by RedHatInsights.
the class BehaviorGroupRepository method findBehaviorGroupsByEventTypeId.
public List<BehaviorGroup> findBehaviorGroupsByEventTypeId(String accountId, UUID eventTypeId, Query limiter) {
EventType eventType = entityManager.find(EventType.class, eventTypeId);
if (eventType == null) {
throw new NotFoundException("Event type not found");
}
String query = "SELECT bg FROM BehaviorGroup bg JOIN bg.behaviors b WHERE (bg.accountId = :accountId OR bg.accountId IS NULL) AND b.eventType.id = :eventTypeId";
if (limiter != null) {
query = limiter.getModifiedQuery(query);
}
TypedQuery<BehaviorGroup> typedQuery = entityManager.createQuery(query, BehaviorGroup.class).setParameter("accountId", accountId).setParameter("eventTypeId", eventTypeId);
if (limiter != null && limiter.getLimit() != null && limiter.getLimit().getLimit() > 0) {
typedQuery = typedQuery.setMaxResults(limiter.getLimit().getLimit()).setFirstResult(limiter.getLimit().getOffset());
}
List<BehaviorGroup> behaviorGroups = typedQuery.getResultList();
for (BehaviorGroup behaviorGroup : behaviorGroups) {
behaviorGroup.filterOutBundle().filterOutActions();
}
return behaviorGroups;
}
Aggregations