use of com.redhat.cloud.notifications.models.EmailSubscription in project notifications-backend by RedHatInsights.
the class UserConfigResource method getPreferences.
@GET
@Path("/notification-preference/{bundleName}/{applicationName}")
@Produces(APPLICATION_JSON)
@Operation(hidden = true)
public UserConfigPreferences getPreferences(@Context SecurityContext sec, @PathParam("bundleName") String bundleName, @PathParam("applicationName") String applicationName) {
final RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
final String account = principal.getAccount();
final String name = principal.getName();
final UserConfigPreferences preferences = new UserConfigPreferences();
// TODO Get the DAILY and INSTANT subscriptions with a single SQL query and return UserConfigPreferences directly from Hibernate.
EmailSubscription daily = emailSubscriptionRepository.getEmailSubscription(account, name, bundleName, applicationName, EmailSubscriptionType.DAILY);
preferences.setDailyEmail(daily != null);
EmailSubscription instant = emailSubscriptionRepository.getEmailSubscription(account, name, bundleName, applicationName, EmailSubscriptionType.INSTANT);
preferences.setInstantEmail(instant != null);
return preferences;
}
use of com.redhat.cloud.notifications.models.EmailSubscription 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.EmailSubscription 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