All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.xlcloud.console.menu.BaseMenuItemsProducer Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2012 AMG.lab, a Bull Group Company
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.xlcloud.console.menu;

import java.util.HashSet;
import java.util.Set;

import javax.enterprise.event.Observes;
import javax.inject.Inject;

import org.xlcloud.console.context.IdentityContext;
import org.xlcloud.console.context.IdentityContextCreationEvent;

/**
 * Produces menu items available for the user identified by current identity context.
 * @author Tomek Adamczewski, AMG.net
 */
public abstract class BaseMenuItemsProducer {

    @Inject
    private MenuCollectorBean menuCollector;

    /**
     * It observes for the {@link IdentityContextCreationEvent},
     *  then collect all menu items available for the user identified by the given identity context,
     *  and push these menu items to {@link MenuCollectorBean}.
     * @param event identity context creation event
     */
    public void consumeMessageEvent(@Observes IdentityContextCreationEvent event) {
        Set menuItems = getMenuItems(event.getIdentityContext());
        if (menuItems != null) {
            for (MenuItem menuItem : menuItems) {
                menuCollector.addMenuItem(menuItem);
            }
        }
    }

    /**
     * Returns set of menu items for current module.
     * @param identityContext current user identity context
     * @return set of menu items
     */
    protected abstract Set getMenuItems(IdentityContext identityContext);

    protected Set asSet(MenuItem menuItem) {
        Set result = new HashSet();
        result.add(menuItem);
        return result;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy