use of com.redhat.cloud.notifications.models.Application in project notifications-backend by RedHatInsights.
the class EndpointResource method unsubscribeEmail.
@DELETE
@Path("/email/subscription/{bundleName}/{applicationName}/{type}")
@Produces(APPLICATION_JSON)
@RolesAllowed(ConsoleIdentityProvider.RBAC_WRITE_INTEGRATIONS_ENDPOINTS)
@Transactional
public boolean unsubscribeEmail(@Context SecurityContext sec, @PathParam("bundleName") String bundleName, @PathParam("applicationName") String applicationName, @PathParam("type") EmailSubscriptionType type) {
RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
Application app = applicationRepository.getApplication(bundleName, applicationName);
if (app == null) {
throw new NotFoundException();
} else {
return emailSubscriptionRepository.unsubscribe(principal.getAccount(), principal.getName(), bundleName, applicationName, type);
}
}
use of com.redhat.cloud.notifications.models.Application 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.Application in project notifications-backend by RedHatInsights.
the class ResourceHelpers method createApplication.
public Application createApplication(UUID bundleId, String name, String displayName) {
Application app = new Application();
app.setBundleId(bundleId);
app.setName(name);
app.setDisplayName(displayName);
return applicationRepository.createApp(app);
}
use of com.redhat.cloud.notifications.models.Application 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.Application in project notifications-backend by RedHatInsights.
the class UserConfigResource method saveSettings.
@POST
@Path("/notification-preference")
@Consumes(APPLICATION_JSON)
@Produces(TEXT_PLAIN)
@Operation(hidden = true)
@Transactional
public Response saveSettings(@Context SecurityContext sec, @Valid SettingsValues values) {
final RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
final String account = principal.getAccount();
final String name = principal.getName();
final List<Boolean> subscriptionRequests = new ArrayList<>();
values.bundles.forEach((bundleName, bundleSettingsValue) -> bundleSettingsValue.applications.forEach((applicationName, applicationSettingsValue) -> {
Application app = applicationRepository.getApplication(bundleName, applicationName);
applicationSettingsValue.notifications.forEach((emailSubscriptionType, subscribed) -> {
if (subscribed) {
if (app != null) {
subscriptionRequests.add(emailSubscriptionRepository.subscribe(account, name, bundleName, applicationName, emailSubscriptionType));
}
} else {
subscriptionRequests.add(emailSubscriptionRepository.unsubscribe(account, name, bundleName, applicationName, emailSubscriptionType));
}
});
}));
boolean allisSuccess = subscriptionRequests.stream().allMatch(Boolean.TRUE::equals);
Response.ResponseBuilder builder;
if (allisSuccess) {
builder = Response.ok();
} else {
// Prevent from saving
builder = Response.serverError().entity("Storing of settings Failed.");
builder.type("text/plain");
}
return builder.build();
}
Aggregations