обработчик уведомлений пользователя: пользовательский обработчик уведомлений не работает в liferay 7.1 - PullRequest
0 голосов
/ 08 июля 2019

мы создали собственный обработчик уведомлений, используя @component(service=UserNotificationHandler.class), но он не работает.

код обработчика уведомлений пользователя

package com.alert.service.notification;

import com.liferay.petra.string.StringBundler;
import com.liferay.petra.string.StringUtil;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.model.UserNotificationEvent;
import com.liferay.portal.kernel.notifications.BaseUserNotificationHandler;
import com.liferay.portal.kernel.notifications.UserNotificationHandler;
import com.liferay.portal.kernel.service.ServiceContext;

import org.osgi.service.component.annotations.Component;

@Component(immediate=true, service= UserNotificationHandler.class)
public class NotificationHandler extends BaseUserNotificationHandler {

    public NotificationHandler() {
        setPortletId("travelportalertportlet_WAR_travelportalertportlet");
    }

    @Override
    protected String getBody(UserNotificationEvent userNotificationEvent, ServiceContext serviceContext)
            throws Exception {
        // TODO Auto-generated method stub
        JSONObject json=JSONFactoryUtil.createJSONObject(userNotificationEvent.getPayload());
        return com.liferay.portal.kernel.util.StringUtil.replace(getBodyTemplate(), new String[] {"[$TITLE$]","[$SENDERNAME$]","[$BODY_TEXT$]"}, new String[] {json.getString("title"),json.getString("senderName"),json.getString("notificationText")});
    }

    @Override
    protected String getBodyTemplate() throws Exception {
        // TODO Auto-generated method stub
        StringBundler s=new StringBundler(5);
        s.append("<div> [$TITLE$] <div>");
        s.append("<div> [$SENDERNAME$] <div>");
        return s.toString();
    }
}

уведомление пользователя о вызове

final NotificationEvent notificationEvent = NotificationEventFactoryUtil.createNotificationEvent(
                            System.currentTimeMillis(), portletKey, notificationEventJSONObject);

                    UserNotificationEventLocalServiceUtil.addUserNotificationEvent(userId, notificationEvent);

-> получить вывод для вышеуказанной строки, но уведомление не сохраняется в таблице usernotificationregistry, а также пользователь не получает это уведомление.

вывод: - {mvccVersion = 0, uuid = 4735d3f5-3403-d354-b575-ceed6e50b5cc, userNotificationEventId = 1985806, companyId = 20155, userId = 58202, тип = travelportalertportlet_WAR_travelportalertportlet, отметка времени = 1562321525263, deliveryType = 0, deliveryBy = 0, доставлено = true, payload = {"classPK": "6001", "creationDate": "Чт, 04 июля, 14:17:34 GMT 2019 ", "ifiedDate": "Пт Июл 05 10:03:02 GMT 2019 "," entryDescription ":" оповещение работает " "entryURL":" http://localhost:8080/group/agency/service-alerts?p_p_id=travelportalertportlet_WAR_travelportalertportlet&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&_travelportalertportlet_WAR_travelportalertportlet_id=6001&_travelportalertportlet_WAR_travelportalertportlet_render=alert-view","className":"com.travelport.alert.model.Alert","tagText":"_AND_0","notificationType":1,"entryTitle":"alert работает "," emailSubject ":" Предупреждение службы обновлено - предупреждение working '"," userId ":" 58202 "," status ":" ONGOING "}, actionRequired = false, архивируются = ложь}

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...