001/* 002 * Copyright 2016 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.runtime.plugins.admin.notificator; 017 018import java.util.LinkedHashMap; 019import java.util.Map; 020 021import org.ametys.runtime.i18n.I18nizableText; 022 023/** 024 * Represents a client-side notification. 025 */ 026public class Notification 027{ 028 /** The possible type of notification */ 029 public static enum NotificationType 030 { 031 /** INFO */ 032 INFO, 033 /** WARN */ 034 WARN, 035 /** ERROR */ 036 ERROR 037 } 038 039 /** The type of notification */ 040 protected NotificationType _type; 041 /** The title of the notification */ 042 protected I18nizableText _title; 043 /** The detailed message of the notification */ 044 protected I18nizableText _message; 045 /** The icon of the notification */ 046 protected String _iconGlyph; 047 /** The associated JS action */ 048 protected String _action; 049 050 /** 051 * Constructs a new notification. 052 * @param type The type of notification 053 * @param title The title of the notification 054 * @param message The detailed message (description) of the notification (can contain HTML) 055 * @param iconGlyph The icon of the notification 056 * @param action The JS action to execute when clicking on '<a>' elements of description 057 */ 058 public Notification(NotificationType type, I18nizableText title, I18nizableText message, String iconGlyph, String action) 059 { 060 _type = type; 061 _title = title; 062 _message = message; 063 _iconGlyph = iconGlyph; 064 _action = action; 065 } 066 067 /** 068 * Gets the representation of a notification as a map 069 * @return The notification as a map 070 */ 071 public Map<String, Object> toMap() 072 { 073 Map<String, Object> map = new LinkedHashMap<>(); 074 map.put("type", _type.toString().toLowerCase()); 075 map.put("title", _title); 076 map.put("message", _message); 077 map.put("iconGlyph", _iconGlyph); 078 map.put("action", _action); 079 return map; 080 } 081}