Example usage for com.liferay.portal.kernel.settings SettingsFactoryUtil getSettings

List of usage examples for com.liferay.portal.kernel.settings SettingsFactoryUtil getSettings

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.settings SettingsFactoryUtil getSettings.

Prototype

public static Settings getSettings(SettingsLocator settingsLocator) throws SettingsException 

Source Link

Usage

From source file:blade.document.action.displaycontext.BladeActionDisplayContext.java

License:Apache License

/**
 * Read settings from page Documents And Media portlet "Show Actions" portlet configuration.<br/>
 * But for Documents And Media admin portlet, it will always be true.
 *//*www .j  a va2  s  . co m*/
private boolean _showAction() throws SettingsException {
    PortletDisplay portletDisplay = _themeDisplay.getPortletDisplay();

    String portletName = portletDisplay.getPortletName();

    if (portletName.equals(PortletKeys.DOCUMENT_LIBRARY_ADMIN)) {
        return true;
    }

    Settings settings = SettingsFactoryUtil
            .getSettings(new PortletInstanceSettingsLocator(_themeDisplay.getLayout(), portletDisplay.getId()));

    TypedSettings typedSettings = new TypedSettings(settings);

    return typedSettings.getBooleanValue("showActions");
}

From source file:com.liferay.adaptive.media.image.internal.configuration.AdaptiveMediaImageConfigurationHelperImpl.java

License:Open Source License

private Stream<AdaptiveMediaImageConfigurationEntry> _getConfigurationEntries(long companyId) {

    try {//from   w w w  .j a v a2  s.  c  om
        Settings settings = SettingsFactoryUtil.getSettings(new CompanyServiceSettingsLocator(companyId,
                AdaptiveMediaImageCompanyConfiguration.class.getName()));

        Optional<String[]> nullableImageVariants = _getNullableImageVariants(settings);

        String[] imageVariants = nullableImageVariants
                .orElseGet(() -> settings.getValues("imageVariants", new String[0]));

        return Stream.of(imageVariants).map(_configurationEntryParser::parse);
    } catch (SettingsException se) {
        throw new AdaptiveMediaRuntimeException.InvalidConfiguration(se);
    }
}

From source file:com.liferay.adaptive.media.image.internal.configuration.AdaptiveMediaImageConfigurationHelperImpl.java

License:Open Source License

private void _updateConfiguration(long companyId,
        List<AdaptiveMediaImageConfigurationEntry> configurationEntries) throws IOException {

    try {//  w  w w .  j  a v  a 2s . com
        Settings settings = SettingsFactoryUtil.getSettings(new CompanyServiceSettingsLocator(companyId,
                AdaptiveMediaImageCompanyConfiguration.class.getName()));

        ModifiableSettings modifiableSettings = settings.getModifiableSettings();

        Stream<AdaptiveMediaImageConfigurationEntry> configurationEntryStream = configurationEntries.stream();

        List<String> imageVariants = configurationEntryStream
                .map(_configurationEntryParser::getConfigurationString).collect(Collectors.toList());

        modifiableSettings.setValues("imageVariants", imageVariants.toArray(new String[imageVariants.size()]));

        modifiableSettings.store();
    } catch (SettingsException | ValidatorException e) {
        throw new AdaptiveMediaRuntimeException.InvalidConfiguration(e);
    }
}

From source file:com.liferay.adaptive.media.image.internal.configuration.AMImageConfigurationHelperImpl.java

License:Open Source License

private Stream<AMImageConfigurationEntry> _getAMImageConfigurationEntries(long companyId) {

    if (_configurationEntries.containsKey(companyId)) {
        Collection<AMImageConfigurationEntry> amImageConfigurationEntries = _configurationEntries
                .get(companyId);//from   w w w  .  j ava 2 s  .c o m

        return amImageConfigurationEntries.stream();
    }

    try {
        Settings settings = SettingsFactoryUtil.getSettings(
                new CompanyServiceSettingsLocator(companyId, AMImageCompanyConfiguration.class.getName()));

        Optional<String[]> nullableImageVariants = _getNullableImageVariants(settings);

        String[] imageVariants = nullableImageVariants
                .orElseGet(() -> settings.getValues("imageVariants", new String[0]));

        Stream<String> imageVariantsStream = Stream.of(imageVariants);

        List<AMImageConfigurationEntry> amImageConfigurationEntries = imageVariantsStream
                .map(_amImageConfigurationEntryParser::parse).collect(Collectors.toList());

        _configurationEntries.put(companyId, amImageConfigurationEntries);

        return amImageConfigurationEntries.stream();
    } catch (SettingsException se) {
        throw new AMRuntimeException.InvalidConfiguration(se);
    }
}

From source file:com.liferay.adaptive.media.image.internal.configuration.AMImageConfigurationHelperImpl.java

License:Open Source License

private void _updateConfiguration(long companyId, List<AMImageConfigurationEntry> amImageConfigurationEntries)
        throws IOException {

    try {/*from  www.jav  a  2s  .c  o m*/
        Settings settings = SettingsFactoryUtil.getSettings(
                new CompanyServiceSettingsLocator(companyId, AMImageCompanyConfiguration.class.getName()));

        ModifiableSettings modifiableSettings = settings.getModifiableSettings();

        Stream<AMImageConfigurationEntry> amImageConfigurationEntryStream = amImageConfigurationEntries
                .stream();

        List<String> imageVariants = amImageConfigurationEntryStream
                .map(_amImageConfigurationEntryParser::getConfigurationString).collect(Collectors.toList());

        modifiableSettings.setValues("imageVariants", imageVariants.toArray(new String[imageVariants.size()]));

        modifiableSettings.store();

        amImageConfigurationEntryStream = amImageConfigurationEntries.stream();

        _configurationEntries.put(companyId, amImageConfigurationEntryStream.collect(Collectors.toList()));
    } catch (SettingsException | ValidatorException e) {
        throw new AMRuntimeException.InvalidConfiguration(e);
    }
}

From source file:com.liferay.blogs.settings.BlogsGroupServiceSettings.java

License:Open Source License

public static BlogsGroupServiceSettings getInstance(long groupId) throws PortalException {

    Settings settings = SettingsFactoryUtil
            .getSettings(new GroupServiceSettingsLocator(groupId, BlogsConstants.SERVICE_NAME));

    return new BlogsGroupServiceSettings(settings);
}

From source file:com.liferay.blogs.settings.BlogsGroupServiceSettings.java

License:Open Source License

public static BlogsGroupServiceSettings getInstance(long groupId, Map<String, String[]> parameterMap)
        throws PortalException {

    Settings settings = SettingsFactoryUtil
            .getSettings(new GroupServiceSettingsLocator(groupId, BlogsConstants.SERVICE_NAME));

    return new BlogsGroupServiceSettings(new ParameterMapSettings(parameterMap, settings));
}

From source file:com.liferay.document.library.web.internal.settings.DLPortletInstanceSettings.java

License:Open Source License

public static DLPortletInstanceSettings getInstance(Layout layout, String portletId) throws PortalException {

    Settings settings = SettingsFactoryUtil.getSettings(new PortletInstanceSettingsLocator(layout, portletId));

    return new DLPortletInstanceSettings(settings);
}

From source file:com.liferay.document.library.web.internal.settings.DLPortletInstanceSettings.java

License:Open Source License

public static DLPortletInstanceSettings getInstance(Layout layout, String portletId,
        Map<String, String[]> parameterMap) throws PortalException {

    Settings settings = SettingsFactoryUtil.getSettings(new PortletInstanceSettingsLocator(layout, portletId));

    Settings parameterMapSettings = new ParameterMapSettings(parameterMap, settings);

    return new DLPortletInstanceSettings(parameterMapSettings);
}

From source file:com.liferay.layout.admin.web.internal.exportimport.data.handler.LayoutStagedModelDataHandler.java

License:Open Source License

protected Map<String, Object[]> getPortletids(PortletDataContext portletDataContext, Layout layout)
        throws Exception {

    if (!LayoutStagingUtil.prepareLayoutStagingHandler(portletDataContext, layout)
            || !layout.isSupportsEmbeddedPortlets()) {

        // Only portlet type layouts support page scoping

        return Collections.emptyMap();
    }/*ww  w  . j a va 2  s  .c o m*/

    Map<String, Object[]> portletIds = new HashMap<>();

    LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

    // The getAllPortlets method returns all effective nonsystem portlets
    // for any layout type, including embedded portlets, or in the case of
    // panel type layout, selected portlets

    for (Portlet portlet : layoutTypePortlet.getAllPortlets(false)) {
        String portletId = portlet.getPortletId();

        Settings portletInstanceSettings = SettingsFactoryUtil
                .getSettings(new PortletInstanceSettingsLocator(layout, portletId));

        String scopeType = portletInstanceSettings.getValue("lfrScopeType", null);
        String scopeLayoutUuid = portletInstanceSettings.getValue("lfrScopeLayoutUuid", null);

        long scopeGroupId = portletDataContext.getScopeGroupId();

        if (Validator.isNotNull(scopeType)) {
            Group scopeGroup = null;

            if (scopeType.equals("company")) {
                scopeGroup = _groupLocalService.getCompanyGroup(layout.getCompanyId());
            } else if (scopeType.equals("layout")) {
                Layout scopeLayout = null;

                scopeLayout = _layoutLocalService.fetchLayoutByUuidAndGroupId(scopeLayoutUuid,
                        portletDataContext.getGroupId(), portletDataContext.isPrivateLayout());

                if (scopeLayout == null) {
                    continue;
                }

                scopeGroup = scopeLayout.getScopeGroup();
            } else {
                throw new IllegalArgumentException("Scope type " + scopeType + " is invalid");
            }

            if (scopeGroup != null) {
                scopeGroupId = scopeGroup.getGroupId();
            }
        }

        String key = PortletPermissionUtil.getPrimaryKey(layout.getPlid(), portletId);

        portletIds.put(key, new Object[] { portletId, scopeGroupId, scopeType, scopeLayoutUuid });
    }

    return portletIds;
}