class AbstractPushNotificationRecipientServiceImpl implements AbstractPushNotificationRecipientService<T> {

    @Transactional
    @Nonnull
    @Override
    public T updatePushNotificationRecipientUserDevice(@Nonnull final Long recipientId, @Nonnull final Long userDeviceId) {
        assertPushNotificationRecipientIdNotNull(recipientId);
        Assert.notNull(userDeviceId, "User device id should not be null");
        LOGGER.debug("Updating user device for push notification recipient with id - {}, user device id - {}", recipientId, userDeviceId);
        T recipient = getRepository().findById(recipientId).orElseThrow(() -> new PushNotificationRecipientNotFoundForIdException(recipientId, getInstanceClass()));;
        // Load user device
        final UserDevice userDevice = userDeviceService.getUserDeviceById(userDeviceId);
        assertPushNotificationRecipientAndDeviceBelongToSameUser(recipient, userDevice);
        // Check if device is already associated with recipient
        PushNotificationRecipientDevice recipientDevice = pushNotificationRecipientDeviceRepository.findByRecipientAndDevice(recipient, userDevice);
        if (recipientDevice == null) {
            LOGGER.debug("Push notification recipient with id - {} is not yet associated with user device by id - {}, associating them.", recipient.getId(), userDevice.getId());
            recipientDevice = new PushNotificationRecipientDevice();
            recipientDevice.setRecipient(recipient);
            recipientDevice.setDevice(userDevice);
            // Persist recipient device
            recipientDevice = pushNotificationRecipientDeviceRepository.save(recipientDevice);
            // Add to the collection of recipient devices
            recipient.getDevices().add(recipientDevice);
            LOGGER.debug("Successfully associated push notification recipient with id - {} to user device with id - {}, created recipient device id - {}", recipient.getId(), userDevice.getId(), recipientDevice.getId());
        }
        // Update last used device for recipient
        recipient.setLastDevice(userDevice);
        recipient.setUpdated(LocalDateTime.now());
        // Persist recipient
        recipient = getRepository().save(recipient);
        LOGGER.debug("Successfully updated user device for push notification recipient with id - {}. User device id - {}", recipient.getId(), userDevice.getId());
        return recipient;
    }

    public  AbstractPushNotificationRecipientServiceImpl();

}