Skip to content

Commit

Permalink
[RHCLOUD-29373] Add bundle name on drawer notifications payloads (Red…
Browse files Browse the repository at this point in the history
  • Loading branch information
g-duval authored Dec 6, 2023
1 parent 04504c3 commit 642b10a
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public List<DrawerEntryPayload> getNotifications(String orgId, String username,
query.setDefaultSortBy("created:DESC");
Optional<Query.Sort> sort = query.getSort();
String hql = "SELECT dn.id, dn.read, " +
"dn.event.bundleDisplayName, dn.event.applicationDisplayName, dn.event.eventTypeDisplayName, dn.created, dn.event.renderedDrawerNotification "
+ "FROM DrawerNotification dn where dn.orgId = :orgId and dn.userId = :userid";
"dn.event.bundleDisplayName, dn.event.applicationDisplayName, dn.event.eventTypeDisplayName, dn.created, dn.event.renderedDrawerNotification, bundle.name "
+ "FROM DrawerNotification dn join Bundle bundle on dn.event.bundleId = bundle.id where dn.orgId = :orgId and dn.userId = :userid";

hql = addHqlConditions(hql, bundleIds, appIds, eventTypeIds, startDate, endDate, readStatus);
if (sort.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class DrawerEntryPayload {

private String source;

private String bundle;

public DrawerEntryPayload() {
}

Expand All @@ -39,6 +41,7 @@ public DrawerEntryPayload(Object[] rawDrawerEntry) {
title = (String) rawDrawerEntry[4];
created = (LocalDateTime) rawDrawerEntry[5];
description = (String) rawDrawerEntry[6];
bundle = (String) rawDrawerEntry[7];
}

public UUID getId() {
Expand Down Expand Up @@ -88,4 +91,12 @@ public String getSource() {
public void setSource(String source) {
this.source = source;
}

public String getBundle() {
return bundle;
}

public void setBundle(String bundle) {
this.bundle = bundle;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class DrawerEntryPayload {

private String source;

private String bundle;

public DrawerEntryPayload() {
}

Expand Down Expand Up @@ -76,4 +78,12 @@ public String getSource() {
public void setSource(String source) {
this.source = source;
}

public String getBundle() {
return bundle;
}

public void setBundle(String bundle) {
this.bundle = bundle;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ private static DrawerNotificationToConnector buildTestDrawerNotificationToConnec
drawerEntryPayload.setId(UUID.fromString("3ccfb747-610d-42e9-97de-05d43d07319d"));
drawerEntryPayload.setSource("My app");
drawerEntryPayload.setTitle("the title");
drawerEntryPayload.setBundle("My Bundle");

RecipientSettings recipientSettings = new RecipientSettings();
return new DrawerNotificationToConnector(orgId, drawerEntryPayload, Set.of(recipientSettings), List.of("user-1", "user-2"));
Expand Down Expand Up @@ -245,6 +246,7 @@ protected static void assertKafkaSinkDrawerIsSatisfied(MockEndpoint kafkaSinkMoc
assertNotNull(secondPayloadLevel.getString("id"));
assertNotEquals(payload.getString("id"), secondPayloadLevel.getString("id"));
assertEquals(false, secondPayloadLevel.getBoolean("read"));
assertEquals("My Bundle", secondPayloadLevel.getString("bundle"));

assertEquals(notification.drawerEntryPayload().getDescription(), secondPayloadLevel.getString("description"));
assertEquals(notification.drawerEntryPayload().getSource(), secondPayloadLevel.getString("source"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.redhat.cloud.notifications.db.repositories;

import com.redhat.cloud.notifications.models.Bundle;
import io.quarkus.cache.CacheResult;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.persistence.EntityManager;
import java.util.UUID;

@ApplicationScoped
public class BundleRepository {

@Inject
EntityManager entityManager;

@CacheResult(cacheName = "bundle-by-id")
public Bundle getBundle(UUID id) {
return entityManager.find(Bundle.class, id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.redhat.cloud.notifications.DelayedThrower;
import com.redhat.cloud.notifications.config.FeatureFlipper;
import com.redhat.cloud.notifications.db.repositories.BundleRepository;
import com.redhat.cloud.notifications.db.repositories.DrawerNotificationRepository;
import com.redhat.cloud.notifications.db.repositories.EndpointRepository;
import com.redhat.cloud.notifications.db.repositories.EventRepository;
Expand Down Expand Up @@ -95,6 +96,9 @@ public class DrawerProcessor extends SystemEndpointTypeProcessor {
@Inject
NotificationHistoryRepository notificationHistoryRepository;

@Inject
BundleRepository bundleRepository;

@PostConstruct
void postConstruct() {
Log.info("DrawerProcessor instance created");
Expand Down Expand Up @@ -184,6 +188,7 @@ private DrawerEntryPayload buildJsonPayloadFromEvent(Event event) {
drawerEntryPayload.setTitle(event.getEventTypeDisplayName());
drawerEntryPayload.setCreated(event.getCreated());
drawerEntryPayload.setSource(String.format("%s - %s", event.getApplicationDisplayName(), event.getBundleDisplayName()));
drawerEntryPayload.setBundle(bundleRepository.getBundle(event.getBundleId()).getName());
return drawerEntryPayload;
}

Expand Down
1 change: 1 addition & 0 deletions engine/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,4 @@ quarkus.cache.caffeine.is-email-aggregation-supported.expire-after-write=PT5M
quarkus.cache.caffeine.rbac-recipient-users-provider-get-users.expire-after-write=PT10M
quarkus.cache.caffeine.rbac-recipient-users-provider-get-group-users.expire-after-write=PT10M
quarkus.cache.caffeine.recipients-resolver-results.expire-after-write=PT1M
quarkus.cache.caffeine.bundle.by.id.expire-after-write=PT15M

0 comments on commit 642b10a

Please sign in to comment.