This is an automated email from the ASF dual-hosted git repository.

riemer pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/streampipes.git


The following commit(s) were added to refs/heads/dev by this push:
     new 329f56c8d Delete pipeline-related notifications upon pipeline deletion 
(#1533) (#1785)
329f56c8d is described below

commit 329f56c8de8b919c901a3f095f07d18941998b41
Author: Dominik Riemer <[email protected]>
AuthorDate: Sun Jul 23 11:36:54 2023 +0200

    Delete pipeline-related notifications upon pipeline deletion (#1533) (#1785)
---
 .../manager/pipeline/PipelineManager.java          |  7 +-
 .../management/NotificationsResourceManager.java   | 75 ++++++++++++++++++++++
 .../storage/api/INotificationStorage.java          |  2 +
 .../couchdb/impl/NotificationStorageImpl.java      | 28 ++++++--
 .../app/notifications/notifications.component.html | 11 +++-
 .../notifications/service/notifications.service.ts |  6 ++
 6 files changed, 119 insertions(+), 10 deletions(-)

diff --git 
a/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/pipeline/PipelineManager.java
 
b/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/pipeline/PipelineManager.java
index fdc303c2e..c8cc072b1 100644
--- 
a/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/pipeline/PipelineManager.java
+++ 
b/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/pipeline/PipelineManager.java
@@ -25,6 +25,7 @@ import 
org.apache.streampipes.model.base.NamedStreamPipesEntity;
 import org.apache.streampipes.model.client.user.Permission;
 import org.apache.streampipes.model.pipeline.Pipeline;
 import org.apache.streampipes.model.pipeline.PipelineOperationStatus;
+import org.apache.streampipes.resource.management.NotificationsResourceManager;
 import org.apache.streampipes.storage.api.IPermissionStorage;
 import org.apache.streampipes.storage.api.IPipelineStorage;
 import org.apache.streampipes.storage.management.StorageDispatcher;
@@ -111,7 +112,11 @@ public class PipelineManager {
    * @param pipelineId of pipeline to be deleted
    */
   public static void deletePipeline(String pipelineId) {
-    getPipelineStorage().deletePipeline(pipelineId);
+    var pipeline = getPipeline(pipelineId);
+    if (Objects.nonNull(pipeline)) {
+      getPipelineStorage().deletePipeline(pipelineId);
+      new 
NotificationsResourceManager().deleteNotificationsForPipeline(pipeline);
+    }
   }
 
 
diff --git 
a/streampipes-resource-management/src/main/java/org/apache/streampipes/resource/management/NotificationsResourceManager.java
 
b/streampipes-resource-management/src/main/java/org/apache/streampipes/resource/management/NotificationsResourceManager.java
new file mode 100644
index 000000000..632f2c113
--- /dev/null
+++ 
b/streampipes-resource-management/src/main/java/org/apache/streampipes/resource/management/NotificationsResourceManager.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.resource.management;
+
+import org.apache.streampipes.model.pipeline.Pipeline;
+import org.apache.streampipes.model.staticproperty.FreeTextStaticProperty;
+import org.apache.streampipes.model.staticproperty.StaticProperty;
+import org.apache.streampipes.storage.api.INotificationStorage;
+import org.apache.streampipes.storage.management.StorageDispatcher;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+public class NotificationsResourceManager extends 
AbstractResourceManager<INotificationStorage> {
+
+  private static final String InternalNotificationsAppId = 
"org.apache.streampipes.sinks.internal.jvm.notification";
+  private static final String InternalNotificationsTitleKey = "title";
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(NotificationsResourceManager.class);
+
+  public NotificationsResourceManager() {
+    
super(StorageDispatcher.INSTANCE.getNoSqlStore().getNotificationStorageApi());
+  }
+
+  public void deleteNotificationsForPipeline(Pipeline pipeline) {
+    try {
+      List<String> notificationTypes = 
getAllNotificationTypesForPipeline(pipeline);
+      notificationTypes.forEach(notificationType -> {
+        var notifications = db.getAllNotifications(notificationType);
+        notifications.forEach(notification -> 
db.deleteNotification(notification.getId()));
+      });
+    } catch (IllegalArgumentException e) {
+      LOG.error("Could not find a notification type which is part of the 
pipeline.");
+    }
+  }
+
+  private List<String> getAllNotificationTypesForPipeline(Pipeline pipeline) {
+    return pipeline
+        .getActions()
+        .stream()
+        .filter(sink -> sink.getAppId().equals(InternalNotificationsAppId))
+        .map(sink -> sink.getCorrespondingPipeline() + "-" + 
extractNotificationTitle(sink.getStaticProperties()))
+        .toList();
+  }
+
+  private String extractNotificationTitle(List<StaticProperty> 
staticProperties) {
+    return staticProperties
+        .stream()
+        .filter(sp -> sp instanceof FreeTextStaticProperty)
+        .filter(sp -> 
sp.getInternalName().equals(InternalNotificationsTitleKey))
+        .map(sp -> ((FreeTextStaticProperty) sp).getValue())
+        .findFirst()
+        .orElseThrow(IllegalArgumentException::new);
+  }
+
+
+}
diff --git 
a/streampipes-storage-api/src/main/java/org/apache/streampipes/storage/api/INotificationStorage.java
 
b/streampipes-storage-api/src/main/java/org/apache/streampipes/storage/api/INotificationStorage.java
index e05203733..cd1e83f1e 100644
--- 
a/streampipes-storage-api/src/main/java/org/apache/streampipes/storage/api/INotificationStorage.java
+++ 
b/streampipes-storage-api/src/main/java/org/apache/streampipes/storage/api/INotificationStorage.java
@@ -29,6 +29,8 @@ public interface INotificationStorage {
 
   List<Notification> getAllNotifications(String notificationTypeId, Integer 
offset, Integer count);
 
+  List<Notification> getAllNotifications(String notificationTypeId);
+
   List<Notification> getAllNotificationsFromTimestamp(long startTime);
 
   List<Notification> getUnreadNotifications();
diff --git 
a/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/impl/NotificationStorageImpl.java
 
b/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/impl/NotificationStorageImpl.java
index 49a1c46d6..8cd2d8b62 100644
--- 
a/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/impl/NotificationStorageImpl.java
+++ 
b/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/impl/NotificationStorageImpl.java
@@ -26,6 +26,7 @@ import org.apache.streampipes.storage.couchdb.utils.Utils;
 
 import com.google.gson.Gson;
 import com.google.gson.JsonObject;
+import org.lightcouch.View;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -52,12 +53,7 @@ public class NotificationStorageImpl extends 
AbstractDao<Notification> implement
                                                 Integer offset,
                                                 Integer count) {
     List<JsonObject> notifications =
-        couchDbClientSupplier
-            .get()
-            .view("notificationtypes/notificationtypes")
-            .startKey(Arrays.asList(notificationTypeId, "\ufff0"))
-            .endKey(Arrays.asList(notificationTypeId, 0))
-            .descending(true)
+        getQuery(notificationTypeId)
             .includeDocs(true)
             .skip(offset)
             .limit(count)
@@ -66,6 +62,26 @@ public class NotificationStorageImpl extends 
AbstractDao<Notification> implement
     return map(notifications);
   }
 
+  @Override
+  public List<Notification> getAllNotifications(String notificationTypeId) {
+    List<JsonObject> notifications =
+        getQuery(notificationTypeId)
+            .includeDocs(true)
+            .query(JsonObject.class);
+
+    return map(notifications);
+  }
+
+  private View getQuery(String notificationTypeId) {
+    return couchDbClientSupplier
+        .get()
+        .view("notificationtypes/notificationtypes")
+        .startKey(Arrays.asList(notificationTypeId, "\ufff0"))
+        .endKey(Arrays.asList(notificationTypeId, 0))
+        .descending(true)
+        .includeDocs(true);
+  }
+
   @Override
   public List<Notification> getAllNotificationsFromTimestamp(long startTime) {
 
diff --git a/ui/src/app/notifications/notifications.component.html 
b/ui/src/app/notifications/notifications.component.html
index cafa23a3e..94f578587 100644
--- a/ui/src/app/notifications/notifications.component.html
+++ b/ui/src/app/notifications/notifications.component.html
@@ -70,8 +70,9 @@
                     }"
                 >
                     <div
-                        mat-list-avatar
+                        matListItemAvatar
                         class="notification-avatar sp-accent-bg"
+                        style="background: var(--color-accent)"
                     >
                         {{
                             elementIconText.getElementIconText(
@@ -79,8 +80,12 @@
                             )
                         }}
                     </div>
-                    <h4 mat-line>{{ existingNotification.pipelineName }}</h4>
-                    <p mat-line>{{ existingNotification.notificationTitle 
}}</p>
+                    <h4 matListItemTitle>
+                        {{ existingNotification.pipelineName }}
+                    </h4>
+                    <p matListItemLine>
+                        {{ existingNotification.notificationTitle }}
+                    </p>
                     <div class="new-notification-info-panel">
                         <div
                             class="new-notification-info"
diff --git a/ui/src/app/notifications/service/notifications.service.ts 
b/ui/src/app/notifications/service/notifications.service.ts
index 8485a540f..cf3b481c0 100644
--- a/ui/src/app/notifications/service/notifications.service.ts
+++ b/ui/src/app/notifications/service/notifications.service.ts
@@ -40,6 +40,12 @@ export class NotificationsService {
         return this.http
             .get(
                 this.notificationUrl + '/time' + '?' + 'startTime=' + 
startTime,
+                {
+                    context: new HttpContext().set(
+                        NGX_LOADING_BAR_IGNORED,
+                        true,
+                    ),
+                },
             )
             .pipe(
                 map(data => {

Reply via email to