use of com.redhat.cloud.notifications.models.EventType 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());
}
use of com.redhat.cloud.notifications.models.EventType in project notifications-backend by RedHatInsights.
the class EventLogCleanerTest method testPostgresStoredProcedure.
@Test
@Transactional
void testPostgresStoredProcedure() {
deleteAllEvents();
EventType eventType = createEventType();
createEvent(eventType, now().minus(Duration.ofHours(1L)));
createEvent(eventType, now().minus(Duration.ofDays(62L)));
assertEquals(2L, count());
entityManager.createNativeQuery("CALL cleanEventLog()").executeUpdate();
assertEquals(1L, count());
}
use of com.redhat.cloud.notifications.models.EventType in project notifications-backend by RedHatInsights.
the class ResourceHelpers method createEventType.
@Transactional
public EventType createEventType(UUID appId, String eventTypeName) {
EventType eventType = new EventType();
eventType.setApplication(entityManager.find(Application.class, appId));
eventType.setApplicationId(appId);
eventType.setName(eventTypeName);
eventType.setDisplayName("Policies will take care of the rules");
eventType.setDescription("Policies is super cool, you should use it");
entityManager.persist(eventType);
return eventType;
}
use of com.redhat.cloud.notifications.models.EventType in project notifications-backend by RedHatInsights.
the class EmailTemplateMigrationService method createInstantEmailTemplate.
/*
* Creates an instant email template and the underlying templates only if:
* - the event type exists in the DB
* - the instant email template does not already exist in the DB
* Existing instant email templates are never updated by this migration service.
*/
private void createInstantEmailTemplate(List<String> warnings, String bundleName, String appName, List<String> eventTypeNames, String subjectTemplateName, String subjectTemplateExtension, String subjectTemplateDescription, String bodyTemplateName, String bodyTemplateExtension, String bodyTemplateDescription) {
for (String eventTypeName : eventTypeNames) {
Optional<EventType> eventType = findEventType(warnings, bundleName, appName, eventTypeName);
if (eventType.isPresent()) {
if (instantEmailTemplateExists(eventType.get())) {
warnings.add(String.format("Instant email template found in DB for event type: %s/%s/%s", bundleName, appName, eventTypeName));
} else {
Template subjectTemplate = getOrCreateTemplate(warnings, subjectTemplateName, subjectTemplateExtension, subjectTemplateDescription);
Template bodyTemplate = getOrCreateTemplate(warnings, bodyTemplateName, bodyTemplateExtension, bodyTemplateDescription);
LOGGER.infof("Creating instant email template for event type: %s/%s/%s", bundleName, appName, eventTypeName);
InstantEmailTemplate emailTemplate = new InstantEmailTemplate();
emailTemplate.setEventType(eventType.get());
emailTemplate.setSubjectTemplate(subjectTemplate);
emailTemplate.setSubjectTemplateId(subjectTemplate.getId());
emailTemplate.setBodyTemplate(bodyTemplate);
emailTemplate.setBodyTemplateId(bodyTemplate.getId());
entityManager.persist(emailTemplate);
}
}
}
}
use of com.redhat.cloud.notifications.models.EventType in project notifications-backend by RedHatInsights.
the class NotificationResourceTest method testGetEventTypesAffectedByEndpoint.
@Test
void testGetEventTypesAffectedByEndpoint() {
String tenant = "testGetEventTypesAffectedByEndpoint";
String orgId = "testGetEventTypesAffectedByEndpointOrgId";
Header identityHeader = initRbacMock(tenant, orgId, "user", FULL_ACCESS);
UUID bundleId = helpers.createTestAppAndEventTypes();
UUID behaviorGroupId1 = helpers.createBehaviorGroup(tenant, "behavior-group-1", bundleId).getId();
UUID behaviorGroupId2 = helpers.createBehaviorGroup(tenant, "behavior-group-2", bundleId).getId();
UUID appId = applicationRepository.getApplications(TEST_BUNDLE_NAME).stream().filter(a -> a.getName().equals(TEST_APP_NAME_2)).findFirst().get().getId();
UUID endpointId1 = helpers.createWebhookEndpoint(tenant);
UUID endpointId2 = helpers.createWebhookEndpoint(tenant);
List<EventType> eventTypes = applicationRepository.getEventTypes(appId);
// ep1 assigned to ev0; ep2 not assigned.
behaviorGroupRepository.updateEventTypeBehaviors(tenant, eventTypes.get(0).getId(), Set.of(behaviorGroupId1));
behaviorGroupRepository.updateBehaviorGroupActions(tenant, behaviorGroupId1, List.of(endpointId1));
String responseBody = given().header(identityHeader).pathParam("endpointId", endpointId1.toString()).when().get("/notifications/behaviorGroups/affectedByRemovalOfEndpoint/{endpointId}").then().statusCode(200).contentType(JSON).extract().asString();
JsonArray behaviorGroups = new JsonArray(responseBody);
assertEquals(1, behaviorGroups.size());
behaviorGroups.getJsonObject(0).mapTo(BehaviorGroup.class);
assertEquals(behaviorGroupId1.toString(), behaviorGroups.getJsonObject(0).getString("id"));
responseBody = given().header(identityHeader).pathParam("endpointId", endpointId2.toString()).when().get("/notifications/behaviorGroups/affectedByRemovalOfEndpoint/{endpointId}").then().statusCode(200).contentType(JSON).extract().asString();
behaviorGroups = new JsonArray(responseBody);
assertEquals(0, behaviorGroups.size());
// ep1 assigned to event ev0; ep2 assigned to event ev1
behaviorGroupRepository.updateEventTypeBehaviors(tenant, eventTypes.get(0).getId(), Set.of(behaviorGroupId2));
behaviorGroupRepository.updateBehaviorGroupActions(tenant, behaviorGroupId2, List.of(endpointId2));
responseBody = given().header(identityHeader).pathParam("endpointId", endpointId1.toString()).when().get("/notifications/behaviorGroups/affectedByRemovalOfEndpoint/{endpointId}").then().statusCode(200).contentType(JSON).extract().asString();
behaviorGroups = new JsonArray(responseBody);
assertEquals(1, behaviorGroups.size());
behaviorGroups.getJsonObject(0).mapTo(BehaviorGroup.class);
assertEquals(behaviorGroupId1.toString(), behaviorGroups.getJsonObject(0).getString("id"));
responseBody = given().header(identityHeader).pathParam("endpointId", endpointId2.toString()).when().get("/notifications/behaviorGroups/affectedByRemovalOfEndpoint/{endpointId}").then().statusCode(200).contentType(JSON).extract().asString();
behaviorGroups = new JsonArray(responseBody);
assertEquals(1, behaviorGroups.size());
behaviorGroups.getJsonObject(0).mapTo(BehaviorGroup.class);
assertEquals(behaviorGroupId2.toString(), behaviorGroups.getJsonObject(0).getString("id"));
}
Aggregations