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.ArrayList;
019import java.util.List;
020import java.util.Map;
021import java.util.stream.Collectors;
022
023import org.ametys.core.ui.Callable;
024import org.ametys.runtime.plugin.ExtensionPoint;
025import org.ametys.runtime.plugin.component.AbstractThreadSafeComponentExtensionPoint;
026
027/**
028 * {@link ExtensionPoint} in charge of collecting all the administrator notifications to send.
029 */
030public class AdministratorNotificatorExtensionPoint extends AbstractThreadSafeComponentExtensionPoint<AdministratorNotificator>
031{
032    /** Avalon Role */
033    public static final String ROLE = AdministratorNotificatorExtensionPoint.class.getName();
034    
035    /**
036     * Gets the notifications to send to the admin.
037     * @return The list of all notifications to send.
038     */
039    @Callable
040    public List<Map<String, Object>> getNotifications()
041    {
042        List<Map<String, Object>> notifications = new ArrayList<>();
043        
044        for (String id : getExtensionsIds())
045        {
046            AdministratorNotificator notificator = getExtension(id);
047            notifications.addAll(notificator.getNotifications().stream().map(Notification::toMap).collect(Collectors.toList()));
048        }
049        
050        return notifications;
051    }
052}