From a8e5db8aadd050f5b6e249a290f9f4c628e835a2 Mon Sep 17 00:00:00 2001
From: Daniel Gerhardt <code@dgerhardt.net>
Date: Mon, 14 Jan 2019 13:55:46 +0100
Subject: [PATCH] Add bulk delete method to EntityService

---
 .../arsnova/service/DefaultEntityServiceImpl.java   | 13 +++++++++++++
 .../java/de/thm/arsnova/service/EntityService.java  |  3 +++
 2 files changed, 16 insertions(+)

diff --git a/src/main/java/de/thm/arsnova/service/DefaultEntityServiceImpl.java b/src/main/java/de/thm/arsnova/service/DefaultEntityServiceImpl.java
index 003bb2d0d..abe3c0d65 100644
--- a/src/main/java/de/thm/arsnova/service/DefaultEntityServiceImpl.java
+++ b/src/main/java/de/thm/arsnova/service/DefaultEntityServiceImpl.java
@@ -239,6 +239,19 @@ public class DefaultEntityServiceImpl<T extends Entity> implements EntityService
 		eventPublisher.publishEvent(new AfterDeletionEvent<>(this, entity));
 	}
 
+	@Override
+	@PreFilter(value = "hasPermission(filterObject, 'delete')", filterTarget = "entities")
+	public void delete(final Iterable<T> entities) {
+		for (T entity : entities) {
+			prepareDelete(entity);
+			eventPublisher.publishEvent(new BeforeDeletionEvent<>(this, entity));
+		}
+		repository.deleteAll(entities);
+		for (T entity : entities) {
+			eventPublisher.publishEvent(new AfterDeletionEvent<>(this, entity));
+		}
+	}
+
 	/**
 	 * This method can be overridden by subclasses to do additional entity related actions before deletion.
 	 *
diff --git a/src/main/java/de/thm/arsnova/service/EntityService.java b/src/main/java/de/thm/arsnova/service/EntityService.java
index 9158e4f5b..708612479 100644
--- a/src/main/java/de/thm/arsnova/service/EntityService.java
+++ b/src/main/java/de/thm/arsnova/service/EntityService.java
@@ -62,4 +62,7 @@ public interface EntityService<T extends Entity> {
 
 	@PreAuthorize("hasPermission(#entity, 'delete')")
 	void delete(T entity);
+
+	@PreFilter(value = "hasPermission(filterObject, 'delete')", filterTarget = "entities")
+	void delete(Iterable<T> entities);
 }
-- 
GitLab