use of com.redhat.cloud.notifications.models.Application 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);
}
}
}
}
}
}
}
}
use of com.redhat.cloud.notifications.models.Application in project notifications-backend by RedHatInsights.
the class ApplicationRepository method createEventType.
@Transactional
public EventType createEventType(EventType eventType) {
Application app = entityManager.find(Application.class, eventType.getApplicationId());
if (app == null) {
throw new NotFoundException();
} else {
eventType.setApplication(app);
entityManager.persist(eventType);
eventType.filterOutApplication();
return eventType;
}
}
use of com.redhat.cloud.notifications.models.Application 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;
}
use of com.redhat.cloud.notifications.models.Application in project notifications-backend by RedHatInsights.
the class LifecycleITest method subscribeUserPreferences.
@Transactional
void subscribeUserPreferences(String accountId, String userId, UUID appId) {
Application application = entityManager.find(Application.class, appId);
EmailSubscription subscription = new EmailSubscription();
subscription.setId(new EmailSubscriptionId());
subscription.setAccountId(accountId);
subscription.setUserId(userId);
subscription.setApplication(application);
subscription.setType(INSTANT);
entityManager.persist(subscription);
}
use of com.redhat.cloud.notifications.models.Application in project notifications-backend by RedHatInsights.
the class BehaviorGroupRepositoryTest method testFindBehaviorGroupsByEventTypeId.
@Test
void testFindBehaviorGroupsByEventTypeId() {
Bundle bundle = resourceHelpers.createBundle();
Application app = resourceHelpers.createApplication(bundle.getId());
EventType eventType = createEventType(app);
BehaviorGroup behaviorGroup = resourceHelpers.createBehaviorGroup(DEFAULT_ACCOUNT_ID, "displayName", bundle.getId());
updateAndCheckEventTypeBehaviors(DEFAULT_ACCOUNT_ID, eventType.getId(), true, behaviorGroup.getId());
List<BehaviorGroup> behaviorGroups = resourceHelpers.findBehaviorGroupsByEventTypeId(eventType.getId());
assertEquals(1, behaviorGroups.size());
assertEquals(behaviorGroup.getId(), behaviorGroups.get(0).getId());
}
Aggregations