Files
sumoc-backend/src/main/java/SuMoC/backend/notification

Notification System Overview

This document provides an overview of the notification system for client developers integrating with the backend. It explains notification types, expected payloads, and device token registration.

Notification Types

Notifications sent to clients are categorized by NotificationType:

  • TREND: Informs users about changes in their mobility trends (e.g., reduced car usage). See TrendNotificationService.
  • ADHOC_ALTERNATIVE: Suggests a more sustainable alternative after a recent trip upload. See AdHocSuggestionService.
  • REGULAR_TRIP_ALTERNATIVE: Suggests an alternative for a detected regular trip (e.g., weekly commute). See RegularTripSuggestionService.
  • FRIENDSHIP_REQUEST_RECEIVED: Notifies about a new pending friendship request.

See NotificationType.java for the full enum.

Notification Payloads

Each notification type includes a data payload. The main DTOs in the notification body are:

  • TREND: Contains a list of TrendDetectionDTO objects, each describing a detected trend for the user. The structure includes fields such as userId, timespan, type, attribute, deltaType, changeValue, and trendConnotation. See TrendDetectionDTO.java for details.
  • ADHOC_ALTERNATIVE: Contains a list of RouteDTO objects representing the best alternative(s) for a recent trip ( see AdHocSuggestionService).
  • REGULAR_TRIP_ALTERNATIVE: Contains a list of 1 or 2 RouteDTO objects for the best alternative(s) to a detected regular trip, depending on user preferences (e.g., if preferPhysicalActivity is set, two alternatives may be included). See RegularTripSuggestionService and RegularTripDetectionService for details.
  • FRIENDSHIP_REQUEST_RECEIVED: Contains a friendshipDTO where friend is the user who sent the request. See FriendshipDTO.java.

Device Token Registration

To receive push notifications, clients must register their device token. Token registration is handled in the NotificationController. The backend stores or updates the token for the authenticated user.

Unregistering Device Token

When a user logs out, the client should call the device token unregistration endpoint to remove the device token from the backend. This ensures the user will no longer receive push notifications on that device after logout.

  • Endpoint: PUT /notifications/unregister-device-token

For Backend Developers

To queue notifications for users, use the NotificationSchedulerService as the main entry point. This service provides methods to schedule notifications with the appropriate type and payload. See NotificationSchedulerService.java for usage details.


For further details, refer to the respective service and DTO classes in the codebase.