Class FcmAppNotificationHandlerImpl
- java.lang.Object
-
- org.cyclos.impl.AbstractServerComponent
-
- org.cyclos.impl.AbstractNetworkedServerComponent
-
- org.cyclos.impl.BaseNetworkedHandlerImpl
-
- org.cyclos.impl.utils.appnotifications.FcmAppNotificationHandlerImpl
-
- All Implemented Interfaces:
AppNotificationHandler
@Component public class FcmAppNotificationHandlerImpl extends BaseNetworkedHandlerImpl implements AppNotificationHandler
Firebase Cloud Messaging (FCM) app notification handler implementation.
There are two types of messages that can be sent to clients:- Notification messages: handled automatically by the platform (FCM shows the notification message on the device)
- Data messages: handled directly by the app
This is the link to the API doc: API Reference
This implementation send notification messages with a data payload of custom key-value pairs. The data payload is stored inAppNotificationMessage.getVariables()
-
-
Field Summary
-
Fields inherited from class org.cyclos.impl.AbstractNetworkedServerComponent
authHandler, conversionHandler, customFieldValueHandler, entityManagerHandler, groupsHandler, productsHandler, restBeanPropertyMapping, userLocatorHandler
-
Fields inherited from class org.cyclos.impl.AbstractServerComponent
accountHandler, configurationHandler, dataTranslationHandler, notificationHandler, profileFieldHandler, transactionHandler, translationHandler
-
-
Constructor Summary
Constructors Constructor Description FcmAppNotificationHandlerImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanReceiveNotifications(BasicUser user)Returns whether the app notifications are configured for the user and if it also has the required mediums to receive it (e.g an FCM registration token).
If false no notifications will be sent to this specific user.voiddestroy()voidinitialize()com.google.firebase.FirebaseAppinstantiateApp(String credentials)Initializes the Firebase SDKs with the given credentials and store it in the local storage with an one-day of expiration.booleannotify(AppNotificationMessage notification)Sends (synchronously) a new app notification.voidvalidate(BasicUser user, Object medium)Validates the given medium used to send the app notification to the user.-
Methods inherited from class org.cyclos.impl.AbstractNetworkedServerComponent
canManage, checkManagesUser, checkPermission, checkRelatesToUser, checkValue, clearAlreadyValidated, getBaseEntityManagerHandler, getConfiguration, getLoggedBasicUser, getLoggedUser, getProducts, getTranslatedName, getTranslatedValue, hasPermission, hasValue, inSameNetwork, inSameNetworkOrGlobal, isAdmin, isAlreadyValidated, isBroker, isGlobalAdmin, isGlobalAdminInNetwork, isGuest, isLoggedIn, isMember, isMemberOnly, isNetworkAdmin, isOperator, isRelatedToUser, isSystem, isUserManager, isUserManagerOf, message, message, permission, permission, permissionOptionalValue, permissionOptionalValue, setAlreadyValidated, toDate, toDateTime, validate
-
Methods inherited from class org.cyclos.impl.AbstractServerComponent
dataTranslationProxy, dataTranslationProxy, delete, detach, doDataTranslationProxy, find, flush, from, getApplicationContext, getFormatter, getFormatter, getFormatter, getLogger, getRemoteAddress, getSessionData, mailContentBuilder, message, message, persist, processBatch, processBatch, refresh, remove, selectFrom, subQuery, update
-
-
-
-
Method Detail
-
canReceiveNotifications
public boolean canReceiveNotifications(BasicUser user)
Description copied from interface:AppNotificationHandlerReturns whether the app notifications are configured for the user and if it also has the required mediums to receive it (e.g an FCM registration token).
If false no notifications will be sent to this specific user.- Specified by:
canReceiveNotificationsin interfaceAppNotificationHandler
-
destroy
public void destroy()
-
initialize
@PostConstruct public void initialize()
-
instantiateApp
public com.google.firebase.FirebaseApp instantiateApp(String credentials) throws AppNotificationException
Initializes the Firebase SDKs with the given credentials and store it in the local storage with an one-day of expiration.- Parameters:
credentials- the JSON private key- Returns:
- the initialized instance
- Throws:
AppNotificationException- if any error has occurred during initialization
-
notify
public boolean notify(AppNotificationMessage notification)
Description copied from interface:AppNotificationHandlerSends (synchronously) a new app notification.- Specified by:
notifyin interfaceAppNotificationHandler- Returns:
- whether the notification was sent or not.
-
validate
public void validate(BasicUser user, Object medium)
Description copied from interface:AppNotificationHandlerValidates the given medium used to send the app notification to the user. The medium depends on the underlying implementation, e.g in case of FCM it would be a token of type String.- Specified by:
validatein interfaceAppNotificationHandler
-
-