Example usage for com.liferay.portal.kernel.util PrefsPropsUtil getInteger

List of usage examples for com.liferay.portal.kernel.util PrefsPropsUtil getInteger

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util PrefsPropsUtil getInteger.

Prototype

public static int getInteger(PortletPreferences preferences, String name, int defaultValue) 

Source Link

Usage

From source file:com.liferay.sync.internal.servlet.filter.SyncJSONFilter.java

License:Open Source License

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
        throws IOException, ServletException {

    SyncDevice syncDevice = null;//from   w ww.j a  v  a 2 s .  c  o  m

    HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;

    String uuid = httpServletRequest.getHeader("Sync-UUID");

    if (uuid != null) {
        syncDevice = SyncDeviceLocalServiceUtil.fetchSyncDeviceByUuidAndCompanyId(uuid,
                _portal.getCompanyId(httpServletRequest));
    }

    if (syncDevice == null) {
        syncDevice = SyncDeviceLocalServiceUtil.createSyncDevice(0);
    }

    syncDevice.setHostname(servletRequest.getRemoteHost());

    SyncDeviceThreadLocal.setSyncDevice(syncDevice);

    if (uuid != null) {
        filterChain.doFilter(servletRequest, servletResponse);

        return;
    }

    String uri = (String) servletRequest.getAttribute(WebKeys.INVOKER_FILTER_URI);

    if (uri.equals("/api/jsonws/invoke")) {
        String contentType = httpServletRequest.getHeader(HttpHeaders.CONTENT_TYPE);

        if ((contentType == null) || !contentType.startsWith(ContentTypes.MULTIPART_FORM_DATA)) {

            filterChain.doFilter(servletRequest, servletResponse);

            return;
        }

        if (!(httpServletRequest instanceof UploadServletRequest)) {
            servletRequest = _portal.getUploadServletRequest(httpServletRequest);
        }

        if (!isSyncJSONRequest(servletRequest)) {
            filterChain.doFilter(servletRequest, servletResponse);

            return;
        }
    } else if (!uri.startsWith("/api/jsonws/sync")) {
        filterChain.doFilter(servletRequest, servletResponse);

        return;
    }

    if (ParamUtil.get(httpServletRequest, "debug", false)) {
        filterChain.doFilter(servletRequest, servletResponse);

        return;
    }

    Throwable throwable = null;

    if (PrefsPropsUtil.getBoolean(_portal.getCompanyId(httpServletRequest),
            SyncServiceConfigurationKeys.SYNC_SERVICES_ENABLED,
            SyncServiceConfigurationValues.SYNC_SERVICES_ENABLED)) {

        int absoluteSyncClientMinBuild = 0;
        int syncClientMinBuild = 0;

        String syncDeviceType = httpServletRequest.getHeader("Sync-Device");

        if (syncDeviceType == null) {
            throwable = new SyncDeviceHeaderException();
        } else if (syncDeviceType.startsWith("desktop")) {
            absoluteSyncClientMinBuild = _ABSOLUTE_SYNC_CLIENT_MIN_BUILD_DESKTOP;

            syncClientMinBuild = PrefsPropsUtil.getInteger(_portal.getCompanyId(httpServletRequest),
                    SyncServiceConfigurationKeys.SYNC_CLIENT_MIN_BUILD_DESKTOP,
                    SyncServiceConfigurationValues.SYNC_CLIENT_MIN_BUILD_DESKTOP);
        } else if (syncDeviceType.equals("mobile-android")) {
            absoluteSyncClientMinBuild = _ABSOLUTE_SYNC_CLIENT_MIN_BUILD_ANDROID;

            syncClientMinBuild = PrefsPropsUtil.getInteger(_portal.getCompanyId(httpServletRequest),
                    SyncServiceConfigurationKeys.SYNC_CLIENT_MIN_BUILD_ANDROID,
                    SyncServiceConfigurationValues.SYNC_CLIENT_MIN_BUILD_ANDROID);
        } else if (syncDeviceType.equals("mobile-ios")) {
            absoluteSyncClientMinBuild = _ABSOLUTE_SYNC_CLIENT_MIN_BUILD_IOS;

            syncClientMinBuild = PrefsPropsUtil.getInteger(_portal.getCompanyId(httpServletRequest),
                    SyncServiceConfigurationKeys.SYNC_CLIENT_MIN_BUILD_IOS,
                    SyncServiceConfigurationValues.SYNC_CLIENT_MIN_BUILD_IOS);
        } else {
            throwable = new SyncDeviceHeaderException();
        }

        if (throwable == null) {
            if (syncClientMinBuild < absoluteSyncClientMinBuild) {
                syncClientMinBuild = absoluteSyncClientMinBuild;
            }

            int syncBuild = httpServletRequest.getIntHeader("Sync-Build");

            if (syncBuild >= syncClientMinBuild) {
                filterChain.doFilter(servletRequest, servletResponse);

                return;
            } else {
                throwable = new SyncClientMinBuildException(
                        "Sync client does not meet minimum build " + syncClientMinBuild);
            }
        }
    } else {
        throwable = new SyncServicesUnavailableException();
    }

    servletResponse.setCharacterEncoding(StringPool.UTF8);
    servletResponse.setContentType(ContentTypes.APPLICATION_JSON);

    OutputStream outputStream = servletResponse.getOutputStream();

    String json = _syncUtil.buildExceptionMessage(throwable);

    json = "{\"exception\": \"" + json + "\"}";

    outputStream.write(json.getBytes(StringPool.UTF8));

    outputStream.close();
}

From source file:com.liferay.sync.model.impl.SyncDeviceImpl.java

License:Open Source License

@Override
public boolean isSupported() {
    int minBuildNumber = 0;

    String type = getType();//from w  ww .j  a va  2  s. c  om

    if (type.startsWith("desktop")) {
        minBuildNumber = PrefsPropsUtil.getInteger(getCompanyId(),
                PortletPropsKeys.SYNC_CLIENT_MIN_BUILD_DESKTOP,
                PortletPropsValues.SYNC_CLIENT_MIN_BUILD_DESKTOP);
    } else if (type.equals("mobile-android")) {
        minBuildNumber = PrefsPropsUtil.getInteger(getCompanyId(),
                PortletPropsKeys.SYNC_CLIENT_MIN_BUILD_ANDROID,
                PortletPropsValues.SYNC_CLIENT_MIN_BUILD_ANDROID);
    } else if (type.equals("mobile-ios")) {
        minBuildNumber = PrefsPropsUtil.getInteger(getCompanyId(), PortletPropsKeys.SYNC_CLIENT_MIN_BUILD_IOS,
                PortletPropsValues.SYNC_CLIENT_MIN_BUILD_IOS);
    }

    if (getBuildNumber() >= minBuildNumber) {
        return true;
    }

    return false;
}

From source file:com.liferay.sync.service.impl.SyncDLObjectServiceImpl.java

License:Open Source License

protected Map<String, String> getPortletPreferencesMap() throws PortalException {

    Map<String, String> portletPreferencesMap = new HashMap<String, String>();

    User user = getUser();/*www .  j  a v a  2 s .  co  m*/

    int maxConnections = PrefsPropsUtil.getInteger(user.getCompanyId(),
            PortletPropsKeys.SYNC_CLIENT_MAX_CONNECTIONS, PortletPropsValues.SYNC_CLIENT_MAX_CONNECTIONS);

    portletPreferencesMap.put(PortletPropsKeys.SYNC_CLIENT_MAX_CONNECTIONS, String.valueOf(maxConnections));

    int pollInterval = PrefsPropsUtil.getInteger(user.getCompanyId(),
            PortletPropsKeys.SYNC_CLIENT_POLL_INTERVAL, PortletPropsValues.SYNC_CLIENT_POLL_INTERVAL);

    portletPreferencesMap.put(PortletPropsKeys.SYNC_CLIENT_POLL_INTERVAL, String.valueOf(pollInterval));

    return portletPreferencesMap;
}

From source file:com.liferay.trash.internal.TrashHelperImpl.java

License:Open Source License

@Override
public int getMaxAge(Group group) {
    int trashEntriesMaxAge = PrefsPropsUtil.getInteger(group.getCompanyId(), PropsKeys.TRASH_ENTRIES_MAX_AGE,
            PropsValues.TRASH_ENTRIES_MAX_AGE);

    UnicodeProperties typeSettingsProperties = group.getParentLiveGroupTypeSettingsProperties();

    return GetterUtil.getInteger(typeSettingsProperties.getProperty("trashEntriesMaxAge"), trashEntriesMaxAge);
}