Search in sources :

Example 1 with ConfigurationService

use of org.craftercms.studio.api.v2.service.config.ConfigurationService in project studio by craftercms.

the class UiServiceInternalImpl method getGlobalMenu.

@Override
@SuppressWarnings("unchecked")
public List<MenuItem> getGlobalMenu(Set<String> permissions) throws ServiceLayerException {
    if (CollectionUtils.isNotEmpty(permissions)) {
        HierarchicalConfiguration menuConfig = getGlobalMenuConfig();
        List<MenuItem> menuItems = new ArrayList<>();
        // TODO: Move this config to ConfigurationService
        List<HierarchicalConfiguration> itemsConfig = menuConfig.configurationsAt(MENU_ITEMS_CONFIG_KEY);
        if (CollectionUtils.isNotEmpty(itemsConfig)) {
            for (HierarchicalConfiguration itemConfig : itemsConfig) {
                String requiredPermission = getRequiredStringProperty(itemConfig, PERMISSION_CONFIG_KEY);
                if (requiredPermission.equals(ANY_PERMISSION_WILDCARD) || permissions.contains(requiredPermission)) {
                    MenuItem item = new MenuItem();
                    item.setId(getRequiredStringProperty(itemConfig, ID_CONFIG_KEY));
                    item.setLabel(getRequiredStringProperty(itemConfig, LABEL_CONFIG_KEY));
                    item.setIcon(getRequiredStringProperty(itemConfig, ICON_CONFIG_KEY));
                    menuItems.add(item);
                }
            }
        } else {
            throw new ConfigurationException("No menu items found in global menu config");
        }
        return menuItems;
    } else {
        return null;
    }
}
Also used : ConfigurationException(org.craftercms.studio.api.v2.exception.configuration.ConfigurationException) ArrayList(java.util.ArrayList) MenuItem(org.craftercms.studio.model.ui.MenuItem) HierarchicalConfiguration(org.apache.commons.configuration2.HierarchicalConfiguration)

Aggregations

ArrayList (java.util.ArrayList)1 HierarchicalConfiguration (org.apache.commons.configuration2.HierarchicalConfiguration)1 ConfigurationException (org.craftercms.studio.api.v2.exception.configuration.ConfigurationException)1 MenuItem (org.craftercms.studio.model.ui.MenuItem)1