001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.notifications;
016    
017    import com.liferay.portal.kernel.util.ResourceBundleUtil;
018    
019    import java.util.HashMap;
020    import java.util.Locale;
021    import java.util.Map;
022    import java.util.ResourceBundle;
023    
024    /**
025     * @author Jonathan Lee
026     */
027    public class UserNotificationDefinition {
028    
029            public static final int NOTIFICATION_TYPE_ADD_ENTRY = 0;
030    
031            public static final int NOTIFICATION_TYPE_UPDATE_ENTRY = 1;
032    
033            public UserNotificationDefinition(
034                    String portletId, long classNameId, int notificationType,
035                    String description) {
036    
037                    _portletId = portletId;
038                    _classNameId = classNameId;
039                    _notificationType = notificationType;
040                    _description = description;
041            }
042    
043            public void addUserNotificationDeliveryType(
044                    UserNotificationDeliveryType userNotificationDeliveryType) {
045    
046                    _userNotificationDeliveryTypes.put(
047                            userNotificationDeliveryType.getType(),
048                            userNotificationDeliveryType);
049            }
050    
051            public long getClassNameId() {
052                    return _classNameId;
053            }
054    
055            public String getDescription(Locale locale) {
056                    ResourceBundle resourceBundle = ResourceBundleUtil.getBundle(
057                            "content.Language", locale, getClass());
058    
059                    String description = ResourceBundleUtil.getString(
060                            resourceBundle, _description);
061    
062                    if (description != null) {
063                            return description;
064                    }
065    
066                    return _description;
067            }
068    
069            public int getNotificationType() {
070                    return _notificationType;
071            }
072    
073            public String getPortletId() {
074                    return _portletId;
075            }
076    
077            public UserNotificationDeliveryType getUserNotificationDeliveryType(
078                    int deliveryType) {
079    
080                    return _userNotificationDeliveryTypes.get(deliveryType);
081            }
082    
083            public Map<Integer, UserNotificationDeliveryType>
084                    getUserNotificationDeliveryTypes() {
085    
086                    return _userNotificationDeliveryTypes;
087            }
088    
089            private final long _classNameId;
090            private final String _description;
091            private final int _notificationType;
092            private final String _portletId;
093            private final Map<Integer, UserNotificationDeliveryType>
094                    _userNotificationDeliveryTypes = new HashMap<>();
095    
096    }