Example usage for com.liferay.portal.kernel.search Sort INT_TYPE

List of usage examples for com.liferay.portal.kernel.search Sort INT_TYPE

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.search Sort INT_TYPE.

Prototype

int INT_TYPE

To view the source code for com.liferay.portal.kernel.search Sort INT_TYPE.

Click Source Link

Usage

From source file:com.liferay.asset.categories.admin.web.internal.display.context.AssetCategoriesDisplayContext.java

License:Open Source License

public SearchContainer getCategoriesSearchContainer() throws PortalException {

    if (_categoriesSearchContainer != null) {
        return _categoriesSearchContainer;
    }//  w  w  w . ja  v a 2s. c o  m

    SearchContainer categoriesSearchContainer = new SearchContainer(_renderRequest, getIteratorURL(), null,
            "there-are-no-categories");

    if (Validator.isNull(getKeywords())) {
        if (isShowCategoriesAddButton()) {
            categoriesSearchContainer
                    .setEmptyResultsMessageCssClass("there-are-no-categories.-you-can-add-a-category-by-"
                            + "clicking-the-plus-button-on-the-bottom-right-corner");
            categoriesSearchContainer
                    .setEmptyResultsMessageCssClass("taglib-empty-result-message-header-has-plus-btn");
        }
    } else {
        categoriesSearchContainer.setSearch(true);
    }

    categoriesSearchContainer.setOrderByCol(getOrderByCol());

    boolean orderByAsc = false;

    String orderByType = getOrderByType();

    if (orderByType.equals("asc")) {
        orderByAsc = true;
    }

    OrderByComparator<AssetCategory> orderByComparator = new AssetCategoryCreateDateComparator(orderByAsc);

    categoriesSearchContainer.setOrderByComparator(orderByComparator);

    categoriesSearchContainer.setOrderByType(orderByType);

    EmptyOnClickRowChecker emptyOnClickRowChecker = new EmptyOnClickRowChecker(_renderResponse);

    StringBundler sb = new StringBundler(7);

    sb.append("^(?!.*");
    sb.append(_renderResponse.getNamespace());
    sb.append("redirect).*(/vocabulary/");
    sb.append(getVocabularyId());
    sb.append("/category/");
    sb.append(getCategoryId());
    sb.append(")");

    emptyOnClickRowChecker.setRememberCheckBoxStateURLRegex(sb.toString());

    categoriesSearchContainer.setRowChecker(emptyOnClickRowChecker);

    List<AssetCategory> categories = null;
    int categoriesCount = 0;

    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    long scopeGroupId = themeDisplay.getScopeGroupId();

    if (Validator.isNotNull(getKeywords())) {
        AssetCategoryDisplay assetCategoryDisplay = null;

        Sort sort = null;

        if (isFlattenedNavigationAllowed()) {
            sort = new Sort("leftCategoryId", Sort.INT_TYPE, orderByAsc);
        } else {
            sort = new Sort("createDate", Sort.LONG_TYPE, orderByAsc);
        }

        assetCategoryDisplay = AssetCategoryServiceUtil.searchCategoriesDisplay(new long[] { scopeGroupId },
                getKeywords(), new long[] { getVocabularyId() }, new long[0],
                categoriesSearchContainer.getStart(), categoriesSearchContainer.getEnd(), sort);

        categoriesCount = assetCategoryDisplay.getTotal();

        categoriesSearchContainer.setTotal(categoriesCount);

        categories = assetCategoryDisplay.getCategories();
    } else if (isFlattenedNavigationAllowed()) {
        AssetCategory category = getCategory();

        if (Validator.isNull(category)) {
            categoriesCount = AssetCategoryServiceUtil
                    .getVocabularyCategoriesCount(themeDisplay.getScopeGroupId(), getVocabularyId());

            categories = AssetCategoryServiceUtil.getVocabularyCategories(getVocabularyId(),
                    categoriesSearchContainer.getStart(), categoriesSearchContainer.getEnd(),
                    new AssetCategoryLeftCategoryIdComparator(orderByAsc));
        } else {
            categoriesCount = AssetCategoryServiceUtil.getVocabularyCategoriesCount(
                    themeDisplay.getScopeGroupId(), category.getCategoryId(), getVocabularyId());

            categories = AssetCategoryServiceUtil.getVocabularyCategories(category.getCategoryId(),
                    getVocabularyId(), categoriesSearchContainer.getStart(), categoriesSearchContainer.getEnd(),
                    new AssetCategoryLeftCategoryIdComparator(orderByAsc));
        }

        categoriesSearchContainer.setTotal(categoriesCount);
    } else {
        categoriesCount = AssetCategoryServiceUtil.getVocabularyCategoriesCount(scopeGroupId, getCategoryId(),
                getVocabularyId());

        categoriesSearchContainer.setTotal(categoriesCount);

        categories = AssetCategoryServiceUtil.getVocabularyCategories(scopeGroupId, getCategoryId(),
                getVocabularyId(), categoriesSearchContainer.getStart(), categoriesSearchContainer.getEnd(),
                categoriesSearchContainer.getOrderByComparator());
    }

    categoriesSearchContainer.setResults(categories);

    _categoriesSearchContainer = categoriesSearchContainer;

    return _categoriesSearchContainer;
}

From source file:com.liferay.asset.internal.util.AssetHelperImpl.java

License:Open Source License

private String _getOrderByCol(String sortField, String fieldType, int sortType, Locale locale) {

    if (sortField.startsWith(DDMStructureManager.STRUCTURE_INDEXER_FIELD_PREFIX)) {

        StringBundler sb = new StringBundler(5);

        sb.append(sortField);//  www .  j av  a  2  s . co m
        sb.append(StringPool.UNDERLINE);
        sb.append(LocaleUtil.toLanguageId(locale));
        sb.append(StringPool.UNDERLINE);

        String suffix = "String";

        if (!fieldType.equals("ddm-date") && ((sortType == Sort.DOUBLE_TYPE) || (sortType == Sort.FLOAT_TYPE)
                || (sortType == Sort.INT_TYPE) || (sortType == Sort.LONG_TYPE))) {

            suffix = "Number";
        }

        sb.append(suffix);

        sortField = Field.getSortableFieldName(sb.toString());
    } else if (sortField.equals("modifiedDate")) {
        sortField = Field.MODIFIED_DATE;
    } else if (sortField.equals("title")) {
        sortField = Field.getSortableFieldName("localized_title_".concat(LocaleUtil.toLanguageId(locale)));
    }

    return sortField;
}

From source file:com.liferay.asset.internal.util.AssetHelperImpl.java

License:Open Source License

private int _getSortType(String fieldType) {
    int sortType = Sort.STRING_TYPE;

    if (fieldType.equals(Field.CREATE_DATE) || fieldType.equals(Field.EXPIRATION_DATE)
            || fieldType.equals(Field.PUBLISH_DATE) || fieldType.equals("ddm-date")
            || fieldType.equals("modifiedDate")) {

        sortType = Sort.LONG_TYPE;/*from   w w  w  .  j  a  v  a2 s.c  om*/
    } else if (fieldType.equals(Field.PRIORITY) || fieldType.equals("ddm-decimal")
            || fieldType.equals("ddm-number")) {

        sortType = Sort.DOUBLE_TYPE;
    } else if (fieldType.equals("ddm-integer")) {
        sortType = Sort.INT_TYPE;
    }

    return sortType;
}

From source file:com.liferay.asset.tags.admin.web.internal.display.context.AssetTagsDisplayContext.java

License:Open Source License

public SearchContainer getTagsSearchContainer() throws PortalException {
    if (_tagsSearchContainer != null) {
        return _tagsSearchContainer;
    }//from   w ww . j  a v  a2s  . c  o m

    SearchContainer tagsSearchContainer = new SearchContainer(_renderRequest, _renderResponse.createRenderURL(),
            null, "there-are-no-tags");

    String keywords = getKeywords();

    if (Validator.isNull(keywords)) {
        if (isShowAddButton()) {
            tagsSearchContainer.setEmptyResultsMessage("there-are-no-tags.-you-can-add-a-tag-by-clicking-the-"
                    + "plus-button-on-the-bottom-right-corner");
            tagsSearchContainer
                    .setEmptyResultsMessageCssClass("taglib-empty-result-message-header-has-plus-btn");
        }
    } else {
        tagsSearchContainer.setSearch(true);
    }

    tagsSearchContainer.setRowChecker(new EmptyOnClickRowChecker(_renderResponse));

    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    if (Validator.isNotNull(keywords)) {
        Sort sort = null;

        String orderByCol = getOrderByCol();

        if (orderByCol.equals("name")) {
            sort = SortFactoryUtil.getSort(AssetTag.class, Sort.STRING_TYPE, Field.NAME, getOrderByType());
        } else if (orderByCol.equals("usages")) {
            sort = SortFactoryUtil.getSort(AssetTag.class, Sort.INT_TYPE, "assetCount_Number",
                    getOrderByType());
        }

        BaseModelSearchResult<AssetTag> baseModelSearchResult = AssetTagLocalServiceUtil.searchTags(
                new long[] { themeDisplay.getScopeGroupId() }, keywords, tagsSearchContainer.getStart(),
                tagsSearchContainer.getEnd(), sort);

        tagsSearchContainer.setResults(baseModelSearchResult.getBaseModels());
        tagsSearchContainer.setTotal(baseModelSearchResult.getLength());
    } else {
        String orderByCol = getOrderByCol();

        tagsSearchContainer.setOrderByCol(orderByCol);

        OrderByComparator<AssetTag> orderByComparator = null;

        boolean orderByAsc = false;

        String orderByType = getOrderByType();

        if (orderByType.equals("asc")) {
            orderByAsc = true;
        }

        if (orderByCol.equals("name")) {
            orderByComparator = new AssetTagNameComparator(orderByAsc);
        } else if (orderByCol.equals("usages")) {
            orderByComparator = new AssetTagAssetCountComparator(orderByAsc);
        }

        tagsSearchContainer.setOrderByComparator(orderByComparator);

        tagsSearchContainer.setOrderByType(orderByType);

        long scopeGroupId = themeDisplay.getScopeGroupId();

        int tagsCount = AssetTagServiceUtil.getTagsCount(scopeGroupId, keywords);

        tagsSearchContainer.setTotal(tagsCount);

        List<AssetTag> tags = AssetTagServiceUtil.getTags(scopeGroupId, StringPool.BLANK,
                tagsSearchContainer.getStart(), tagsSearchContainer.getEnd(),
                tagsSearchContainer.getOrderByComparator());

        tagsSearchContainer.setResults(tags);
    }

    _tagsSearchContainer = tagsSearchContainer;

    return _tagsSearchContainer;
}