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

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

Introduction

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

Prototype

public UserNotificationDefinition(String portletId, long classNameId, int notificationType,
            String description) 

Source Link

Usage

From source file:com.liferay.notifications.hook.events.StartupAction.java

License:Open Source License

protected void addUserNotificationDefinitions(String xml, String portletId) throws Exception {

    Class<?> clazz = getClass();

    xml = JavaFieldsParser.parse(clazz.getClassLoader(), xml);

    Document document = SAXReaderUtil.read(xml);

    Element rootElement = document.getRootElement();

    for (Element definitionElement : rootElement.elements("definition")) {
        String modelName = definitionElement.elementText("model-name");

        long classNameId = 0;

        if (Validator.isNotNull(modelName)) {
            classNameId = PortalUtil.getClassNameId(modelName);
        }/* w  w  w  .  jav a2 s  .co  m*/

        int notificationType = GetterUtil.getInteger(definitionElement.elementText("notification-type"));

        String description = GetterUtil.getString(definitionElement.elementText("description"));

        UserNotificationDefinition userNotificationDefinition = new UserNotificationDefinition(portletId,
                classNameId, notificationType, description);

        for (Element deliveryTypeElement : definitionElement.elements("delivery-type")) {

            String name = deliveryTypeElement.elementText("name");
            int type = GetterUtil.getInteger(deliveryTypeElement.elementText("type"));
            boolean defaultValue = GetterUtil.getBoolean(deliveryTypeElement.elementText("default"));
            boolean modifiable = GetterUtil.getBoolean(deliveryTypeElement.elementText("modifiable"));

            userNotificationDefinition.addUserNotificationDeliveryType(
                    new UserNotificationDeliveryType(name, type, defaultValue, modifiable));
        }

        UserNotificationManagerUtil.addUserNotificationDefinition(portletId, userNotificationDefinition);
    }
}