> For the complete documentation index, see [llms.txt](https://avbravo-2.gitbook.io/trucosjakartaee/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://avbravo-2.gitbook.io/trucosjakartaee/web-socket/websocket/websocket-con-notificaciones-en-bases-de-datos/enviar-notificaciones-todos-los-usuarios.md).

# Enviar notificaciones  todos los usuarios

Imaginemos que deseamos enviar notificaciones a un usuario especifico o  a un grupos o todos los usuarios.

Por ejemplo cuando creamos un nuevo rol deseamos notificar a todos los usuarios.

![](https://2578941663-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lc1Wg6ze2c8GK7mFBZX%2F-LhHK2YBvjVe5UtIYLNg%2F-LhHKV-LD_2HxMHpmOJK%2Fssss.png?alt=media\&token=2ac8a699-982c-42e4-b34c-d2277135da83)

Debemos Inyectar

```java
  @Inject
    AutoincrementableServices autoincrementableServices;
     //Notification
    @Inject
    UsuarioServices usuarioServices;
    @Inject
    JmoordbNotificationsRepository jmoordbNotificationsRepository;
    @Inject
    @Push(channel = "notification")
    private PushContext push;
```

### Creamos el método afterSave()

Recorremos la lista de usuarios y pasamos el username junto con los detalles y lo guardamos en jmoordbNotificationsRepository

y luego hacemos el push.send()

```java
public Boolean afterSave(Boolean saved) {
        try {

            for (Usuario u : usuarioServices.getUsuarioList()) {
                //Guardarlo en la base de datos
                JmoordbNotifications jmoordbNotifications = new JmoordbNotifications();
//                Usuario jmoordb_user = (Usuario) JmoordbContext.get("jmoordb_user");
                jmoordbNotifications.setIdjmoordbnotifications(autoincrementableServices.getContador("jmoordbnNotifications"));
                jmoordbNotifications.setUsername(u.getUsername());
                jmoordbNotifications.setMessage("se creo un nuevo rol");
                jmoordbNotifications.setViewed("no");
                jmoordbNotifications.setDate(DateUtil.fechaActual());
                jmoordbNotifications.setType("rolnuevo");
                jmoordbNotificationsRepository.save(jmoordbNotifications);
            }
            push.send("Se creo un nuevo rol");
        } catch (Exception e) {
        }
        return false;
    }
```
