用户通知处理程序:自定义通知处理程序在liferay 7.1中不起作用

时间:2019-07-08 05:56:18

标签: liferay-7

我们已经使用@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,   type = travelportalertportlet_WAR_travelportalertportlet,   timestamp = 1562321525263,deliveryType = 0,deliverBy = 0,delivered = true,   有效载荷= {“ classPK”:“ 6001”,“ createdDate”:“”格林尼治标准时间07年4月4日14:17:34   2019“,” modifiedDate“:” Fri Jul 05 10:03:02 GMT   2019“,” entryDescription“:”警报为   working“,” 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“:”警报   正在工作”,“ emailSubject”:“服务警报已更新-警报为   working'“,” userId“:” 58202“,” status“:” ONGOING“},actionRequired = false,   archived = false}

0 个答案:

没有答案
相关问题