Example usage for com.liferay.portal.kernel.util GetterUtil getLongValues

List of usage examples for com.liferay.portal.kernel.util GetterUtil getLongValues

Introduction

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

Prototype

public static long[] getLongValues(String[] values) 

Source Link

Document

Returns the String array values as a long array.

Usage

From source file:com.liferay.analytics.messaging.AnalyticsMessageListener.java

License:Open Source License

protected void doReceive(Message message) throws Exception {
    long companyId = message.getLong("companyId");
    long userId = message.getLong("userId");
    long anonymousUserId = message.getLong("anonymousUserId");
    String elementId = message.getString("elementId");
    String eventType = message.getString("event");
    String className = message.getString("className");
    long classPK = message.getLong("classPK");
    String referrerClassName = message.getString("referrerClassName");

    String[] values = StringUtil.split(message.getString("referrerClassPK"));

    long[] referrerClassPKs = GetterUtil.getLongValues(values);

    if (Validator.isNull(referrerClassName) || Validator.isNull(referrerClassPKs)) {

        referrerClassName = Layout.class.getName();
        referrerClassPKs = new long[] { message.getLong("plid") };
    }/*w w  w  .java  2s  .  c  o m*/

    String clientIP = message.getString("clientIP");
    String userAgent = message.getString("userAgent");
    String languageId = message.getString("languageId");
    String URL = message.getString("layoutURL");
    String additionalInfo = message.getString("additionalInfo");

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setCompanyId(companyId);

    AnalyticsEventLocalServiceUtil.addAnalyticsEvent(userId, anonymousUserId, className, classPK,
            referrerClassName, referrerClassPKs, elementId, eventType, clientIP, userAgent, languageId, URL,
            additionalInfo, serviceContext);
}

From source file:com.liferay.announcements.web.internal.display.context.DefaultAnnouncementsDisplayContext.java

License:Open Source License

@Override
public LinkedHashMap<Long, long[]> getAnnouncementScopes() throws PortalException {

    LinkedHashMap<Long, long[]> scopes = new LinkedHashMap<>();

    if (isCustomizeAnnouncementsDisplayed()) {
        long[] selectedScopeGroupIdsArray = GetterUtil
                .getLongValues(StringUtil.split(getSelectedScopeGroupIds()));
        long[] selectedScopeOrganizationIdsArray = GetterUtil
                .getLongValues(StringUtil.split(getSelectedScopeOrganizationIds()));
        long[] selectedScopeRoleIdsArray = GetterUtil
                .getLongValues(StringUtil.split(getSelectedScopeRoleIds()));
        long[] selectedScopeUserGroupIdsArray = GetterUtil
                .getLongValues(StringUtil.split(getSelectedScopeUserGroupIds()));

        if (selectedScopeGroupIdsArray.length != 0) {
            scopes.put(PortalUtil.getClassNameId(Group.class.getName()), selectedScopeGroupIdsArray);
        }//from  www . java2s. co m

        if (selectedScopeOrganizationIdsArray.length != 0) {
            scopes.put(PortalUtil.getClassNameId(Organization.class.getName()),
                    selectedScopeOrganizationIdsArray);
        }

        if (selectedScopeRoleIdsArray.length != 0) {
            scopes.put(PortalUtil.getClassNameId(Role.class.getName()), selectedScopeRoleIdsArray);
        }

        if (selectedScopeUserGroupIdsArray.length != 0) {
            scopes.put(PortalUtil.getClassNameId(UserGroup.class.getName()), selectedScopeUserGroupIdsArray);
        }
    } else {
        scopes = AnnouncementsUtil.getAnnouncementScopes(_announcementsRequestHelper.getUser());
    }

    scopes.put(Long.valueOf(0), new long[] { 0 });

    return scopes;
}

From source file:com.liferay.asset.publisher.internal.util.AssetPublisherHelperImpl.java

License:Open Source License

@Override
public long[] getAssetCategoryIds(PortletPreferences portletPreferences) {
    long[] assetCategoryIds = new long[0];

    for (int i = 0; true; i++) {
        String[] queryValues = portletPreferences.getValues("queryValues" + i, null);

        if (ArrayUtil.isEmpty(queryValues)) {
            break;
        }/*from  w  w w  .  j a  va  2s. com*/

        boolean queryContains = GetterUtil
                .getBoolean(portletPreferences.getValue("queryContains" + i, StringPool.BLANK));
        boolean queryAndOperator = GetterUtil
                .getBoolean(portletPreferences.getValue("queryAndOperator" + i, StringPool.BLANK));
        String queryName = portletPreferences.getValue("queryName" + i, StringPool.BLANK);

        if (Objects.equals(queryName, "assetCategories") && queryContains
                && (queryAndOperator || (queryValues.length == 1))) {

            assetCategoryIds = ArrayUtil.append(assetCategoryIds, GetterUtil.getLongValues(queryValues));
        }
    }

    return assetCategoryIds;
}

From source file:com.liferay.asset.publisher.internal.util.AssetPublisherHelperImpl.java

License:Open Source License

@Override
public AssetEntryQuery getAssetEntryQuery(PortletPreferences portletPreferences, long groupId, Layout layout,
        long[] overrideAllAssetCategoryIds, String[] overrideAllAssetTagNames) throws PortalException {

    long[] groupIds = getGroupIds(portletPreferences, groupId, layout);

    AssetEntryQuery assetEntryQuery = new AssetEntryQuery();

    _setCategoriesAndTags(assetEntryQuery, portletPreferences, groupIds, overrideAllAssetCategoryIds,
            overrideAllAssetTagNames);// ww w.  java2s. c o m

    assetEntryQuery.setGroupIds(groupIds);

    boolean anyAssetType = GetterUtil.getBoolean(portletPreferences.getValue("anyAssetType", null), true);

    if (!anyAssetType) {
        long[] availableClassNameIds = AssetRendererFactoryRegistryUtil.getClassNameIds(layout.getCompanyId());

        long[] classNameIds = getClassNameIds(portletPreferences, availableClassNameIds);

        assetEntryQuery.setClassNameIds(classNameIds);
    }

    long[] classTypeIds = GetterUtil.getLongValues(portletPreferences.getValues("classTypeIds", null));

    assetEntryQuery.setClassTypeIds(classTypeIds);

    boolean enablePermissions = GetterUtil.getBoolean(portletPreferences.getValue("enablePermissions", null));

    assetEntryQuery.setEnablePermissions(enablePermissions);

    boolean excludeZeroViewCount = GetterUtil
            .getBoolean(portletPreferences.getValue("excludeZeroViewCount", null));

    assetEntryQuery.setExcludeZeroViewCount(excludeZeroViewCount);

    boolean showOnlyLayoutAssets = GetterUtil
            .getBoolean(portletPreferences.getValue("showOnlyLayoutAssets", null));

    if (showOnlyLayoutAssets) {
        assetEntryQuery.setLayout(layout);
    }

    String orderByColumn1 = GetterUtil.getString(portletPreferences.getValue("orderByColumn1", "modifiedDate"));

    assetEntryQuery.setOrderByCol1(orderByColumn1);

    String orderByColumn2 = GetterUtil.getString(portletPreferences.getValue("orderByColumn2", "title"));

    assetEntryQuery.setOrderByCol2(orderByColumn2);

    String orderByType1 = GetterUtil.getString(portletPreferences.getValue("orderByType1", "DESC"));

    assetEntryQuery.setOrderByType1(orderByType1);

    String orderByType2 = GetterUtil.getString(portletPreferences.getValue("orderByType2", "ASC"));

    assetEntryQuery.setOrderByType2(orderByType2);

    return assetEntryQuery;
}

From source file:com.liferay.asset.publisher.internal.util.AssetPublisherHelperImpl.java

License:Open Source License

@Override
public long[] getClassNameIds(PortletPreferences portletPreferences, long[] availableClassNameIds) {

    boolean anyAssetType = GetterUtil
            .getBoolean(portletPreferences.getValue("anyAssetType", Boolean.TRUE.toString()));
    String selectionStyle = portletPreferences.getValue("selectionStyle", "dynamic");

    if (anyAssetType || selectionStyle.equals("manual")) {
        return availableClassNameIds;
    }//from  www.  java 2s. c o  m

    long defaultClassNameId = GetterUtil.getLong(portletPreferences.getValue("anyAssetType", null));

    if (defaultClassNameId > 0) {
        return new long[] { defaultClassNameId };
    }

    long[] classNameIds = GetterUtil.getLongValues(portletPreferences.getValues("classNameIds", null));

    if (ArrayUtil.isNotEmpty(classNameIds)) {
        return classNameIds;
    } else {
        return availableClassNameIds;
    }
}

From source file:com.liferay.asset.publisher.internal.util.AssetPublisherHelperImpl.java

License:Open Source License

private void _setCategoriesAndTags(AssetEntryQuery assetEntryQuery, PortletPreferences portletPreferences,
        long[] scopeGroupIds, long[] overrideAllAssetCategoryIds, String[] overrideAllAssetTagNames) {

    long[] allAssetCategoryIds = new long[0];
    long[] anyAssetCategoryIds = new long[0];
    long[] notAllAssetCategoryIds = new long[0];
    long[] notAnyAssetCategoryIds = new long[0];

    String[] allAssetTagNames = new String[0];
    String[] anyAssetTagNames = new String[0];
    String[] notAllAssetTagNames = new String[0];
    String[] notAnyAssetTagNames = new String[0];

    for (int i = 0; true; i++) {
        String[] queryValues = portletPreferences.getValues("queryValues" + i, null);

        if (ArrayUtil.isEmpty(queryValues)) {
            break;
        }/*  ww  w .  java2  s . c  o  m*/

        boolean queryContains = GetterUtil
                .getBoolean(portletPreferences.getValue("queryContains" + i, StringPool.BLANK));
        boolean queryAndOperator = GetterUtil
                .getBoolean(portletPreferences.getValue("queryAndOperator" + i, StringPool.BLANK));
        String queryName = portletPreferences.getValue("queryName" + i, StringPool.BLANK);

        if (Objects.equals(queryName, "assetCategories")) {
            long[] assetCategoryIds = GetterUtil.getLongValues(queryValues);

            if (queryContains && queryAndOperator) {
                allAssetCategoryIds = assetCategoryIds;
            } else if (queryContains && !queryAndOperator) {
                anyAssetCategoryIds = assetCategoryIds;
            } else if (!queryContains && queryAndOperator) {
                notAllAssetCategoryIds = assetCategoryIds;
            } else {
                notAnyAssetCategoryIds = assetCategoryIds;
            }
        } else {
            if (queryContains && queryAndOperator) {
                allAssetTagNames = queryValues;
            } else if (queryContains && !queryAndOperator) {
                anyAssetTagNames = queryValues;
            } else if (!queryContains && queryAndOperator) {
                notAllAssetTagNames = queryValues;
            } else {
                notAnyAssetTagNames = queryValues;
            }
        }
    }

    if (overrideAllAssetCategoryIds != null) {
        allAssetCategoryIds = overrideAllAssetCategoryIds;
    }

    allAssetCategoryIds = _filterAssetCategoryIds(allAssetCategoryIds);

    assetEntryQuery.setAllCategoryIds(allAssetCategoryIds);

    if (overrideAllAssetTagNames != null) {
        allAssetTagNames = overrideAllAssetTagNames;
    }

    long[] siteGroupIds = _getSiteGroupIds(scopeGroupIds);

    for (String assetTagName : allAssetTagNames) {
        long[] allAssetTagIds = _assetTagLocalService.getTagIds(siteGroupIds, assetTagName);

        assetEntryQuery.addAllTagIdsArray(allAssetTagIds);
    }

    assetEntryQuery.setAnyCategoryIds(anyAssetCategoryIds);

    long[] anyAssetTagIds = _assetTagLocalService.getTagIds(siteGroupIds, anyAssetTagNames);

    assetEntryQuery.setAnyTagIds(anyAssetTagIds);

    assetEntryQuery.setNotAllCategoryIds(notAllAssetCategoryIds);

    for (String assetTagName : notAllAssetTagNames) {
        long[] notAllAssetTagIds = _assetTagLocalService.getTagIds(siteGroupIds, assetTagName);

        assetEntryQuery.addNotAllTagIdsArray(notAllAssetTagIds);
    }

    assetEntryQuery.setNotAnyCategoryIds(notAnyAssetCategoryIds);

    long[] notAnyAssetTagIds = _assetTagLocalService.getTagIds(siteGroupIds, notAnyAssetTagNames);

    assetEntryQuery.setNotAnyTagIds(notAnyAssetTagIds);
}

From source file:com.liferay.asset.publisher.web.display.context.AssetPublisherDisplayContext.java

License:Open Source License

public JSONArray getAutoFieldRulesJSONArray() {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    String queryLogicIndexesParam = ParamUtil.getString(_request, "queryLogicIndexes");

    int[] queryLogicIndexes = null;

    if (Validator.isNotNull(queryLogicIndexesParam)) {
        queryLogicIndexes = StringUtil.split(queryLogicIndexesParam, 0);
    } else {//from  w  w w.  ja v a  2  s .c  o  m
        queryLogicIndexes = new int[0];

        for (int i = 0; true; i++) {
            String queryValues = PrefsParamUtil.getString(_portletPreferences, _request, "queryValues" + i);

            if (Validator.isNull(queryValues)) {
                break;
            }

            queryLogicIndexes = ArrayUtil.append(queryLogicIndexes, i);
        }

        if (queryLogicIndexes.length == 0) {
            queryLogicIndexes = ArrayUtil.append(queryLogicIndexes, -1);
        }
    }

    JSONArray rulesJSONArray = JSONFactoryUtil.createJSONArray();

    for (int queryLogicIndex : queryLogicIndexes) {
        JSONObject ruleJSONObject = JSONFactoryUtil.createJSONObject();

        boolean queryAndOperator = PrefsParamUtil.getBoolean(_portletPreferences, _request,
                "queryAndOperator" + queryLogicIndex);

        ruleJSONObject.put("queryAndOperator", queryAndOperator);

        boolean queryContains = PrefsParamUtil.getBoolean(_portletPreferences, _request,
                "queryContains" + queryLogicIndex, true);

        ruleJSONObject.put("queryContains", queryContains);

        String queryValues = StringUtil
                .merge(_portletPreferences.getValues("queryValues" + queryLogicIndex, new String[0]));

        String queryName = PrefsParamUtil.getString(_portletPreferences, _request,
                "queryName" + queryLogicIndex, "assetTags");

        if (Objects.equals(queryName, "assetTags")) {
            queryValues = ParamUtil.getString(_request, "queryTagNames" + queryLogicIndex, queryValues);

            queryValues = _assetPublisherWebUtil.filterAssetTagNames(themeDisplay.getScopeGroupId(),
                    queryValues);
        } else {
            queryValues = ParamUtil.getString(_request, "queryCategoryIds" + queryLogicIndex, queryValues);

            JSONArray categoryIdsTitles = JSONFactoryUtil.createJSONArray();

            long[] categoryIds = GetterUtil.getLongValues(queryValues.split(","));

            for (long categoryId : categoryIds) {
                AssetCategory category = AssetCategoryLocalServiceUtil.fetchAssetCategory(categoryId);

                categoryIdsTitles.put(category.getTitle(themeDisplay.getLocale()));
            }

            ruleJSONObject.put("categoryIdsTitles", categoryIdsTitles);
        }

        ruleJSONObject.put("queryValues", queryValues);
        ruleJSONObject.put("type", queryName);

        rulesJSONArray.put(ruleJSONObject);
    }

    return rulesJSONArray;
}

From source file:com.liferay.asset.publisher.web.display.context.AssetPublisherDisplayContext.java

License:Open Source License

public long[] getClassTypeIds() {
    if (_classTypeIds != null) {
        return _classTypeIds;
    }//from w  w  w  .j a  va 2s.c  o  m

    _classTypeIds = GetterUtil.getLongValues(_portletPreferences.getValues("classTypeIds", null));

    return _classTypeIds;
}

From source file:com.liferay.asset.publisher.web.internal.messaging.AssetEntriesCheckerUtil.java

License:Open Source License

private void _checkAssetEntries(com.liferay.portal.kernel.model.PortletPreferences portletPreferencesModel)
        throws PortalException {

    Layout layout = _layoutLocalService.fetchLayout(portletPreferencesModel.getPlid());

    if (layout == null) {
        return;/* w w w. j  av  a  2s.  c o m*/
    }

    PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.fromXML(layout.getCompanyId(),
            portletPreferencesModel.getOwnerId(), portletPreferencesModel.getOwnerType(),
            portletPreferencesModel.getPlid(), portletPreferencesModel.getPortletId(),
            portletPreferencesModel.getPreferences());

    if (!_assetPublisherWebUtil.getEmailAssetEntryAddedEnabled(portletPreferences)) {

        return;
    }

    List<AssetEntry> assetEntries = _getAssetEntries(portletPreferences, layout);

    if (assetEntries.isEmpty()) {
        return;
    }

    long[] notifiedAssetEntryIds = GetterUtil
            .getLongValues(portletPreferences.getValues("notifiedAssetEntryIds", null));

    ArrayList<AssetEntry> newAssetEntries = new ArrayList<>();

    for (AssetEntry assetEntry : assetEntries) {
        if (!ArrayUtil.contains(notifiedAssetEntryIds, assetEntry.getEntryId())) {

            newAssetEntries.add(assetEntry);
        }
    }

    List<Subscription> subscriptions = _subscriptionLocalService.getSubscriptions(
            portletPreferencesModel.getCompanyId(),
            com.liferay.portal.kernel.model.PortletPreferences.class.getName(),
            _assetPublisherWebUtil.getSubscriptionClassPK(portletPreferencesModel.getPlid(),
                    portletPreferencesModel.getPortletId()));

    _notifySubscribers(subscriptions, portletPreferences, newAssetEntries);

    try {
        portletPreferences.setValues("notifiedAssetEntryIds",
                StringUtil.split(ListUtil.toString(assetEntries, AssetEntry.ENTRY_ID_ACCESSOR)));

        portletPreferences.store();
    } catch (IOException | PortletException e) {
        throw new PortalException(e);
    }
}

From source file:com.liferay.asset.publisher.web.util.AssetPublisherUtil.java

License:Open Source License

public static long[] getAssetCategoryIds(PortletPreferences portletPreferences) {

    long[] assetCategoryIds = new long[0];

    for (int i = 0; true; i++) {
        String[] queryValues = portletPreferences.getValues("queryValues" + i, null);

        if (ArrayUtil.isEmpty(queryValues)) {
            break;
        }/*  ww  w  . java  2  s.co m*/

        boolean queryContains = GetterUtil
                .getBoolean(portletPreferences.getValue("queryContains" + i, StringPool.BLANK));
        boolean queryAndOperator = GetterUtil
                .getBoolean(portletPreferences.getValue("queryAndOperator" + i, StringPool.BLANK));
        String queryName = portletPreferences.getValue("queryName" + i, StringPool.BLANK);

        if (Objects.equals(queryName, "assetCategories") && queryContains
                && (queryAndOperator || (queryValues.length == 1))) {

            assetCategoryIds = ArrayUtil.append(assetCategoryIds, GetterUtil.getLongValues(queryValues));
        }
    }

    return assetCategoryIds;
}