Package backend.logic

Klasse NotificationService

java.lang.Object
backend.logic.NotificationService

public class NotificationService extends Object
Service class for managing notifications within the system. Provides static methods to create, retrieve, and update notifications stored in a relational database.
  • Felddetails

  • Konstruktordetails

    • NotificationService

      public NotificationService()
  • Methodendetails

    • setConnectionProvider

      public static void setConnectionProvider(ConnectionProvider provider)
      secures database connection
    • createNotification

      public static void createNotification(int userId, String entityType, int entityId, String fieldChanged, String oldValue, String newValue, String message, File file, boolean asAdmin, LocalDate originalInvoiceDate, boolean selfmade)
      Creates a new notification entry in the database.
      Parameter:
      userId - The ID of the user the notification is associated with.
      entityType - The type of the entity the notification refers to.
      entityId - The ID of the entity the notification refers to.
      fieldChanged - The name of the field that was changed.
      oldValue - The old value before the change.
      newValue - The new value after the change.
      message - A descriptive message of the change.
      file - An optional file to store with the notification (nullable).
      asAdmin - Whether the change was made in an administrative context.
      originalInvoiceDate - The original invoice date associated with the entity (nullable).
      selfmade - Whether the change was made by the user themselves.
    • getNotificationsByUser

      public static List<Notification> getNotificationsByUser(User user)
      Retrieves all notifications for a given user that are not marked as admin-level.
      Parameter:
      user - The user whose notifications should be retrieved.
      Gibt zurück:
      A list of Notification objects for the user.
    • getAdminNotification

      public static List<Notification> getAdminNotification()
      Retrieves all notifications that were marked as administrative (not user-made).
      Gibt zurück:
      A list of admin-level Notification objects.
    • getNotification

      public static List<Notification> getNotification(boolean isSelfMadeChange, int userId)
      Retrieves notifications based on whether they were self-made or admin-created.
      Parameter:
      isSelfMadeChange - Indicates whether to retrieve user-made (true) or admin (false) notifications.
      userId - The user ID to filter by (ignored if set to -1).
      Gibt zurück:
      A list of matching Notification objects.
    • markNotificationAsRead

      public static void markNotificationAsRead(long id, boolean newVal)
      Marks a given notification as read or unread.
      Parameter:
      id - The ID of the notification.
      newVal - true to mark as read, false to mark as unread.
    • hasUnreadNotifications

      public static boolean hasUnreadNotifications(List<Notification> notifications, long userId)
      Checks whether the given list of notifications contains any unread notifications for a specific user.
      Parameter:
      notifications - The list of notifications to check.
      userId - The user ID to filter for.
      Gibt zurück:
      true if there are unread notifications for the user; false otherwise.
    • hasUnreadAdminNotifications

      public static boolean hasUnreadAdminNotifications(List<Notification> notifications, long userId)
      Checks whether the given list of admin notifications contains any unread entries.
      Parameter:
      notifications - The list of admin notifications to check.
      userId - The user ID (ignored).
      Gibt zurück:
      true if there are any unread admin notifications; false otherwise.