Search in sources :

Example 1 with Bundle

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

the class BehaviorGroupRepository method create.

@Transactional
BehaviorGroup create(String accountId, BehaviorGroup behaviorGroup, boolean isDefaultBehaviorGroup) {
    behaviorGroup.setAccountId(accountId);
    if (isDefaultBehaviorGroup != behaviorGroup.isDefaultBehavior()) {
        throw new BadRequestException(String.format("Unexpected default behavior group status: Expected [%s] found: [%s]", isDefaultBehaviorGroup, behaviorGroup.isDefaultBehavior()));
    }
    Bundle bundle = entityManager.find(Bundle.class, behaviorGroup.getBundleId());
    if (bundle == null) {
        throw new NotFoundException("bundle_id not found");
    } else {
        behaviorGroup.setBundle(bundle);
        entityManager.persist(behaviorGroup);
        behaviorGroup.filterOutBundle();
        return behaviorGroup;
    }
}
Also used : Bundle(com.redhat.cloud.notifications.models.Bundle) BadRequestException(javax.ws.rs.BadRequestException) NotFoundException(javax.ws.rs.NotFoundException) Transactional(javax.transaction.Transactional)

Example 2 with Bundle

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

the class CrudTestHelpers method buildBundle.

public static Bundle buildBundle(String name, String displayName) {
    Bundle bundle = new Bundle();
    bundle.setName(name);
    bundle.setDisplayName(displayName);
    return bundle;
}
Also used : Bundle(com.redhat.cloud.notifications.models.Bundle)

Example 3 with Bundle

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

the class ResourceHelpers method createTestAppAndEventTypes.

public UUID createTestAppAndEventTypes() {
    Bundle bundle = createBundle(TEST_BUNDLE_NAME, "...");
    Application app1 = createApplication(bundle.getId(), TEST_APP_NAME, "...");
    for (int i = 0; i < 100; i++) {
        String name = String.format(TEST_EVENT_TYPE_FORMAT, i);
        String displayName = "... -> " + i;
        String description = "Desc .. --> " + i;
        createEventType(app1.getId(), name, displayName, description);
    }
    Application app2 = createApplication(bundle.getId(), TEST_APP_NAME_2, "...");
    for (int i = 0; i < 100; i++) {
        String name = String.format(TEST_EVENT_TYPE_FORMAT, i);
        String displayName = "... -> " + i;
        createEventType(app2.getId(), name, displayName, null);
    }
    return bundle.getId();
}
Also used : Bundle(com.redhat.cloud.notifications.models.Bundle) Application(com.redhat.cloud.notifications.models.Application) Endpoint(com.redhat.cloud.notifications.models.Endpoint)

Example 4 with Bundle

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

the class EphemeralDataInitializer method persist.

@Transactional
void persist(EphemeralData data) {
    if (data.bundles != null) {
        for (com.redhat.cloud.notifications.ephemeral.Bundle b : data.bundles) {
            String selectBundleQuery = "FROM Bundle WHERE name = :bundleName";
            Bundle bundle;
            try {
                bundle = entityManager.createQuery(selectBundleQuery, Bundle.class).setParameter("bundleName", b.name).getSingleResult();
                LOGGER.infof("Bundle with name '%s' already exists, it won't be created from the ephemeral data", b.name);
            } catch (NoResultException e) {
                bundle = new Bundle();
                bundle.setName(b.name);
                bundle.setDisplayName(b.displayName);
                entityManager.persist(bundle);
            }
            if (b.applications != null) {
                for (com.redhat.cloud.notifications.ephemeral.Application a : b.applications) {
                    String selectAppQuery = "FROM Application WHERE bundle.name = :bundleName AND name = :appName";
                    Application app;
                    try {
                        app = entityManager.createQuery(selectAppQuery, Application.class).setParameter("bundleName", b.name).setParameter("appName", a.name).getSingleResult();
                        LOGGER.infof("Application with name '%s' already exists, it won't be created from the ephemeral data", a.name);
                    } catch (NoResultException e) {
                        app = new Application();
                        app.setName(a.name);
                        app.setDisplayName(a.displayName);
                        app.setBundle(bundle);
                        app.setBundleId(bundle.getId());
                        entityManager.persist(app);
                    }
                    if (a.eventTypes != null) {
                        for (com.redhat.cloud.notifications.ephemeral.EventType et : a.eventTypes) {
                            String selectEventTypeQuery = "FROM EventType WHERE application.bundle.name = :bundleName AND application.name = :appName AND name = :eventTypeName";
                            EventType eventType;
                            try {
                                entityManager.createQuery(selectEventTypeQuery, EventType.class).setParameter("bundleName", b.name).setParameter("appName", a.name).setParameter("eventTypeName", et.name).getSingleResult();
                                LOGGER.infof("Event type with name '%s' already exists, it won't be created from the ephemeral data", et.name);
                            } catch (NoResultException e) {
                                eventType = new EventType();
                                eventType.setName(et.name);
                                eventType.setDisplayName(et.displayName);
                                eventType.setDescription(et.description);
                                eventType.setApplication(app);
                                eventType.setApplicationId(app.getId());
                                entityManager.persist(eventType);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : EventType(com.redhat.cloud.notifications.models.EventType) Bundle(com.redhat.cloud.notifications.models.Bundle) NoResultException(javax.persistence.NoResultException) Application(com.redhat.cloud.notifications.models.Application) Transactional(javax.transaction.Transactional)

Example 5 with Bundle

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

the class EventConsumerTest method mockGetEventTypeAndCreateEvent.

private EventType mockGetEventTypeAndCreateEvent() {
    Bundle bundle = new Bundle();
    bundle.setDisplayName("Bundle");
    Application app = new Application();
    app.setDisplayName("Application");
    app.setBundle(bundle);
    EventType eventType = new EventType();
    eventType.setDisplayName("Event type");
    eventType.setApplication(app);
    when(eventTypeRepository.getEventType(eq(BUNDLE), eq(APP), eq(EVENT_TYPE))).thenReturn(eventType);
    when(eventRepository.create(any(Event.class))).thenAnswer(invocation -> invocation.getArgument(0));
    return eventType;
}
Also used : EventType(com.redhat.cloud.notifications.models.EventType) Bundle(com.redhat.cloud.notifications.models.Bundle) Event(com.redhat.cloud.notifications.models.Event) Application(com.redhat.cloud.notifications.models.Application)

Aggregations

Bundle (com.redhat.cloud.notifications.models.Bundle)28 Application (com.redhat.cloud.notifications.models.Application)13 QuarkusTest (io.quarkus.test.junit.QuarkusTest)13 Test (org.junit.jupiter.api.Test)13 BehaviorGroup (com.redhat.cloud.notifications.models.BehaviorGroup)12 DbIsolatedTest (com.redhat.cloud.notifications.db.DbIsolatedTest)11 EventType (com.redhat.cloud.notifications.models.EventType)11 Endpoint (com.redhat.cloud.notifications.models.Endpoint)6 Transactional (javax.transaction.Transactional)5 NotFoundException (javax.ws.rs.NotFoundException)4 BadRequestException (javax.ws.rs.BadRequestException)3 Event (com.redhat.cloud.notifications.models.Event)2 EmailSubscription (com.redhat.cloud.notifications.models.EmailSubscription)1 EmailSubscriptionType (com.redhat.cloud.notifications.models.EmailSubscriptionType)1 NotificationHistory (com.redhat.cloud.notifications.models.NotificationHistory)1 EventLogEntry (com.redhat.cloud.notifications.routers.models.EventLogEntry)1 SettingsValues (com.redhat.cloud.notifications.routers.models.SettingsValues)1 ApplicationSettingsValue (com.redhat.cloud.notifications.routers.models.SettingsValues.ApplicationSettingsValue)1 BundleSettingsValue (com.redhat.cloud.notifications.routers.models.SettingsValues.BundleSettingsValue)1 Header (io.restassured.http.Header)1