use of com.redhat.cloud.notifications.models.Bundle in project notifications-backend by RedHatInsights.
the class CrudTestHelpers method updateBundle.
public static void updateBundle(Header identity, String bundleId, String name, String displayName, int expectedStatusCode) {
Bundle bundle = buildBundle(name, displayName);
updateBundle(identity, bundleId, bundle, expectedStatusCode);
}
use of com.redhat.cloud.notifications.models.Bundle in project notifications-backend by RedHatInsights.
the class DbCleaner method clean.
/**
* Deletes all records from all database tables (except for flyway_schema_history) and restores the default records.
* This method should be called from a method annotated with <b>both</b> {@link BeforeEach} and {@link AfterEach} in
* all test classes that involve SQL queries to guarantee the tests isolation in terms of stored data.
*/
@Transactional
public void clean() {
for (Class<?> entity : ENTITIES) {
entityManager.createQuery("DELETE FROM " + entity.getSimpleName()).executeUpdate();
}
Bundle bundle = new Bundle(DEFAULT_BUNDLE_NAME, DEFAULT_BUNDLE_DISPLAY_NAME);
bundleRepository.createBundle(bundle);
Application app = new Application();
app.setBundleId(bundle.getId());
app.setName(DEFAULT_APP_NAME);
app.setDisplayName(DEFAULT_APP_DISPLAY_NAME);
applicationRepository.createApp(app);
EventType eventType = new EventType();
eventType.setApplicationId(app.getId());
eventType.setName(DEFAULT_EVENT_TYPE_NAME);
eventType.setDisplayName(DEFAULT_EVENT_TYPE_DISPLAY_NAME);
eventType.setDescription(DEFAULT_EVENT_TYPE_DESCRIPTION);
applicationRepository.createEventType(eventType);
entityManager.createQuery("UPDATE CurrentStatus SET status = :status").setParameter("status", Status.UP).executeUpdate();
}
use of com.redhat.cloud.notifications.models.Bundle 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.Bundle in project notifications-backend by RedHatInsights.
the class BehaviorGroupRepositoryTest method createBehaviorGroupWithIllegalDisplayName.
private void createBehaviorGroupWithIllegalDisplayName(String displayName) {
Bundle bundle = resourceHelpers.createBundle();
ConstraintViolationException e = assertThrows(ConstraintViolationException.class, () -> {
resourceHelpers.createBehaviorGroup(DEFAULT_ACCOUNT_ID, displayName, bundle.getId());
});
assertTrue(Pattern.compile("property path: [a-zA-Z0-9.]+displayName").matcher(e.getMessage()).find());
}
use of com.redhat.cloud.notifications.models.Bundle in project notifications-backend by RedHatInsights.
the class UserConfigResource method getSettingsValueForUser.
/**
* Pulls the user settings values of an user across all the know applications of a bundle
*/
private SettingsValues getSettingsValueForUser(String account, String username, String bundleName) {
if (bundleName == null || bundleName.equals("")) {
throw new BadRequestException("bundleName must have a value");
}
SettingsValues settingsValues = new SettingsValues();
Bundle bundle = bundleRepository.getBundle(bundleName);
if (bundle == null) {
throw new BadRequestException("Unknown bundleName: " + bundleName);
} else {
BundleSettingsValue bundleSettingsValue = new BundleSettingsValue();
bundleSettingsValue.displayName = bundle.getDisplayName();
settingsValues.bundles.put(bundle.getName(), bundleSettingsValue);
for (Application application : applicationRepository.getApplications(bundle.getName())) {
ApplicationSettingsValue applicationSettingsValue = new ApplicationSettingsValue();
applicationSettingsValue.displayName = application.getDisplayName();
settingsValues.bundles.get(bundle.getName()).applications.put(application.getName(), applicationSettingsValue);
for (EmailSubscriptionType emailSubscriptionType : EmailSubscriptionType.values()) {
// TODO NOTIF-450 How do we deal with a failure here? What kind of response should be sent to the UI when the engine is down?
boolean supported = templateEngineClient.isSubscriptionTypeSupported(bundle.getName(), application.getName(), emailSubscriptionType);
if (supported) {
settingsValues.bundles.get(bundle.getName()).applications.get(application.getName()).notifications.put(emailSubscriptionType, false);
}
}
}
List<EmailSubscription> emailSubscriptions = emailSubscriptionRepository.getEmailSubscriptionsForUser(account, username);
for (EmailSubscription emailSubscription : emailSubscriptions) {
if (settingsValues.bundles.containsKey(emailSubscription.getApplication().getBundle().getName())) {
BundleSettingsValue bundleSettings = settingsValues.bundles.get(emailSubscription.getApplication().getBundle().getName());
if (bundleSettings.applications.containsKey(emailSubscription.getApplication().getName())) {
ApplicationSettingsValue applicationSettingsValue = bundleSettings.applications.get(emailSubscription.getApplication().getName());
if (applicationSettingsValue.notifications.containsKey(emailSubscription.getType())) {
bundleSettings.applications.get(emailSubscription.getApplication().getName()).notifications.put(emailSubscription.getType(), true);
}
}
}
}
return settingsValues;
}
}
Aggregations