Example usage for com.liferay.portal.kernel.notifications NotificationEvent NotificationEvent

List of usage examples for com.liferay.portal.kernel.notifications NotificationEvent NotificationEvent

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.notifications NotificationEvent NotificationEvent.

Prototype

public NotificationEvent(long timestamp, String type, JSONObject payloadJSONObject) 

Source Link

Usage

From source file:com.near.notificaciones.service.impl.RNotificationServiceImpl.java

License:Open Source License

public String[] addNewNotification(String codigoRemitente, List<String> codigoDestinatarioList,
        Date fechaPrevista, String titulo, String contenido, Integer motivo) {
    Long companyId = Long.parseLong(PropsUtil.get("reynasa.fidelizacion.companyId"));
    String[] resultArray = null;/* w ww.j  a v a2 s  .  c om*/
    User remitente = null;
    try {
        remitente = UserLocalServiceUtil.getUserByScreenName(companyId, codigoRemitente);
        if (titulo != null && !titulo.trim().isEmpty()) {
            if (contenido != null && !contenido.trim().isEmpty()) {
                if (motivo != null && motivo != 0) {
                    String[] arrayRedireccionMotivo = RedireccionesRetriever.getRedireccionURL(motivo);
                    if (RedireccionesRetriever.getRedireccionURL(motivo) != null) {
                        User destinatario;
                        if (codigoDestinatarioList != null && !codigoDestinatarioList.isEmpty()) {
                            String horaPrevista, diaPrevisto;
                            SimpleDateFormat diaFormat = new SimpleDateFormat("dd/MM/yyyy");
                            SimpleDateFormat horaFormat = new SimpleDateFormat("HH:mm");
                            resultArray = new String[codigoDestinatarioList.size()];
                            String codigoDestinatario;
                            if (fechaPrevista != null) {
                                horaPrevista = horaFormat.format(fechaPrevista);
                                diaPrevisto = diaFormat.format(fechaPrevista);
                            } else {
                                Date fechaActual = new Date();
                                horaPrevista = horaFormat.format(fechaActual);
                                diaPrevisto = diaFormat.format(fechaActual);
                            }
                            JSONObject payloadJSON = JSONFactoryUtil.createJSONObject();
                            String redireccionMotivo = "<br><br><a href='" + arrayRedireccionMotivo[0]
                                    + "'><i class='icon-globe'></i> Ir a " + arrayRedireccionMotivo[1] + "</a>";
                            payloadJSON.put("userId", remitente.getUserId());
                            payloadJSON.put("remitenteNombre", remitente.getFullName());
                            payloadJSON.put("titulo", titulo);
                            payloadJSON.put("contenido", contenido + redireccionMotivo);
                            payloadJSON.put("fechaPrevista", diaPrevisto);
                            payloadJSON.put("horaPrevista", horaPrevista);
                            NotificationEvent notificationEvent;
                            for (int i = 0; i < codigoDestinatarioList.size(); i++) {
                                codigoDestinatario = codigoDestinatarioList.get(i);
                                if (codigoDestinatario != null && !codigoDestinatario.trim().isEmpty()) {
                                    try {
                                        destinatario = UserLocalServiceUtil.getUserByScreenName(companyId,
                                                codigoDestinatario);
                                        notificationEvent = new NotificationEvent(new Date().getTime(),
                                                ReynasaNotificationHandler.PORTLET_ID, payloadJSON);
                                        UserNotificationEventLocalServiceUtil.addUserNotificationEvent(
                                                destinatario.getUserId(), notificationEvent);
                                        resultArray[i] = "'" + codigoDestinatario
                                                + "': Notificacin enviada correctamente";
                                        logger.info(resultArray[i]);
                                    } catch (NoSuchUserException e) {
                                        resultArray[i] = "'" + codigoDestinatario
                                                + "': No se ha encontrado el destinatario";
                                        logger.error(resultArray[i]);
                                    } catch (Exception e) {
                                        resultArray[i] = "'" + codigoDestinatario
                                                + "': Ha habido un error durante el envo de la notificacin";
                                        logger.error(resultArray[i]);
                                    }
                                }
                            }
                        } else {
                            resultArray = new String[1];
                            resultArray[0] = "Error: Debe seleccionar un destinatario como mnimo";
                            logger.error(resultArray[0]);
                        }
                    } else {
                        resultArray = new String[1];
                        resultArray[0] = "Error: El motivo introducido para la notificacin no es vlido";
                        logger.error(resultArray[0]);
                    }
                } else {
                    resultArray = new String[1];
                    resultArray[0] = "Error: Debe introducir un motivo para la notificacin";
                    logger.error(resultArray[0]);
                }
            } else {
                resultArray = new String[1];
                resultArray[0] = "Error: Debe introducir un contenido para la notificacin";
                logger.error(resultArray[0]);
            }
        } else {
            resultArray = new String[1];
            resultArray[0] = "Error: Debe introducir un ttulo para la notificacin";
            logger.error(resultArray[0]);
        }
    } catch (NoSuchUserException e) {
        resultArray = new String[1];
        resultArray[0] = "Error: No se ha encontrado el usuario remitente";
        logger.error(resultArray[0]);
    } catch (Exception e) {
        resultArray = new String[1];
        resultArray[0] = "Error: Ha habido un error durante la operacin";
        logger.error(resultArray[0]);
    }
    return resultArray;
}

From source file:com.rivetlogic.geo.util.GeoMessageListener.java

License:Open Source License

public void doReceiveResponse(Message message) throws IOException {
    Long userId = message.getLong(GeoServicesPortletConstants.USER_ID);
    String type = GeoServicesPortletConstants.PORTLET_ID;
    Calendar cal = Calendar.getInstance();

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
    jsonObject.put(GeoServicesPortletConstants.NOTIFICATION_MESSAGE,
            message.getString(GeoServicesPortletConstants.RESPONSE_MESSAGE));

    NotificationEvent notificationEvent = new NotificationEvent(cal.getTimeInMillis(), type, jsonObject);
    try {/*from   w  ww.java  2  s .  c o m*/
        UserNotificationEventLocalServiceUtil.addUserNotificationEvent(userId, notificationEvent);
    } catch (PortalException e) {
        LOG.error(e);
    } catch (SystemException e) {
        LOG.error(e);
    }
}

From source file:com.rivetlogic.geoip.util.GeoipMessageListener.java

License:Open Source License

public void doReceiveResponse(Message message) throws IOException {
    Long userId = message.getLong(IPGeoServicesPortletConstants.USER_ID);
    String type = IPGeoServicesPortletConstants.PORTLET_ID;
    Calendar cal = Calendar.getInstance();

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
    jsonObject.put(IPGeoServicesPortletConstants.NOTIFICATION_MESSAGE,
            message.getString(IPGeoServicesPortletConstants.RESPONSE_MESSAGE));

    NotificationEvent notificationEvent = new NotificationEvent(cal.getTimeInMillis(), type, jsonObject);
    try {/* w w w.  j a v  a2  s  .c  o  m*/
        UserNotificationEventLocalServiceUtil.addUserNotificationEvent(userId, notificationEvent);
    } catch (PortalException e) {
        LOG.error(e);
    } catch (SystemException e) {
        LOG.error(e);
    }
}