Example usage for com.liferay.portal.kernel.util ListUtil sort

List of usage examples for com.liferay.portal.kernel.util ListUtil sort

Introduction

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

Prototype

public static <E> List<E> sort(List<E> list, Comparator<? super E> comparator) 

Source Link

Usage

From source file:com.inikah.slayer.model.impl.ProfileImpl.java

License:Open Source License

public List<KeyValuePair> getLanguagesSpokenAsList() {
    List<KeyValuePair> items = new ArrayList<KeyValuePair>();

    Map<Long, String> languages = getLanguagesSpoken();
    Iterator<Long> itr = languages.keySet().iterator();

    while (itr.hasNext()) {
        long key = itr.next();
        String value = languages.get(key);

        items.add(new KeyValuePair(String.valueOf(key), value));
    }/*from  ww  w  .  j  a  v a  2 s .  c om*/

    return ListUtil.sort(items, new KeyValuePairComparator(false, true));
}

From source file:com.inikah.slayer.model.impl.ProfileImpl.java

License:Open Source License

public List<KeyValuePair> getLanguagesSpokenForFilter() {

    List<KeyValuePair> results = new ArrayList<KeyValuePair>();

    List<KeyValuePair> original = getLanguagesSpokenAsList();
    List<KeyValuePair> actuals = FilterUtil.getLanguagesSpoken(isBride());

    for (KeyValuePair kvPair1 : actuals) {
        String key1 = kvPair1.getKey();
        for (KeyValuePair kvPair2 : original) {
            String key2 = kvPair2.getKey();
            if (key2.equalsIgnoreCase(key1)) {
                StringBuilder sb = new StringBuilder();
                sb.append(kvPair2.getValue());
                sb.append(StringPool.SPACE);
                sb.append(StringPool.OPEN_PARENTHESIS);
                sb.append(kvPair1.getValue());
                sb.append(StringPool.CLOSE_PARENTHESIS);
                results.add(new KeyValuePair(key1, sb.toString()));
                break;
            }/*from www  .  jav  a  2s  .  co m*/
        }
    }

    return ListUtil.sort(results, new KeyValuePairComparator(false, true));
}

From source file:com.inikah.slayer.service.impl.MyKeyValueLocalServiceImpl.java

License:Open Source License

public List<KeyValuePair> getItemsForFilter(boolean bride, String column, long parentId, String parentColumn) {
    List<MyKeyValue> items = myKeyValueFinder.findResults(bride, column, parentId, parentColumn);

    List<KeyValuePair> kvPairs = new ArrayList<KeyValuePair>();
    for (MyKeyValue myKeyValue : items) {

        long key = myKeyValue.getMyKey();

        String name = LanguageUtil.get(Locale.ENGLISH, myKeyValue.getMyName());
        if (column.contains("ountry")) {
            name = TextFormatter.formatName(name);
        }//  w  w  w.j  a v  a 2  s.  co m

        StringBuilder sb = new StringBuilder(name);
        sb.append(StringPool.SPACE);
        sb.append(StringPool.OPEN_PARENTHESIS);
        sb.append(myKeyValue.getMyValue());
        sb.append(StringPool.CLOSE_PARENTHESIS);
        kvPairs.add(new KeyValuePair(String.valueOf(key), sb.toString()));
    }

    return ListUtil.sort(kvPairs, new KeyValuePairComparator(false, true));
}

From source file:com.knowarth.portlets.themepersonalizer.ThemePersonalizerAdminPortlet.java

License:Open Source License

@Override
protected void doView(RenderRequest renderRequest, RenderResponse renderResponse)
        throws PortletException, IOException {

    try {/*w ww .  j  av a2  s . c o  m*/
        ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);

        List selectedThemeIdList = new ArrayList();

        List<AvailablePersonalizedTheme> selectedPersonalizedThemes = AvailablePersonalizedThemeLocalServiceUtil
                .findAllByCompanyId(themeDisplay.getCompanyId());
        List<String> selectedThemeIds = new ArrayList<String>();
        for (AvailablePersonalizedTheme selectedPersonalizedTheme : selectedPersonalizedThemes) {
            Theme themeObject = ThemeLocalServiceUtil.fetchTheme(themeDisplay.getCompanyId(),
                    selectedPersonalizedTheme.getThemeId());
            if (Validator.isNotNull(themeObject)) {
                selectedThemeIdList.add(new KeyValuePair(themeObject.getThemeId(), themeObject.getName()));
                selectedThemeIds.add(themeObject.getThemeId());
            }
        }
        List availableThemeIdsList = new ArrayList();

        List<Theme> themes = ThemeLocalServiceUtil.getThemes(themeDisplay.getCompanyId());

        for (Theme themeObject : themes) {
            if (!selectedThemeIds.contains(themeObject.getThemeId()) && !themeObject.isWapTheme()) {
                availableThemeIdsList.add(new KeyValuePair(themeObject.getThemeId(), themeObject.getName()));
            }
        }

        availableThemeIdsList = ListUtil.sort(availableThemeIdsList, new KeyValuePairComparator(false, true));
        renderRequest.setAttribute("selectedThemeIdList", selectedThemeIdList);
        renderRequest.setAttribute("availableThemeIdsList", availableThemeIdsList);
    } catch (SystemException e) {
        SessionErrors.add(renderRequest, "system-error-please-contact-adminstrator");
        _log.error("Error retriving available theme information", e);
    }
    include(viewJSP, renderRequest, renderResponse);

}

From source file:com.liferay.asset.categories.navigation.web.internal.display.context.AssetCategoriesNavigationDisplayContext.java

License:Open Source License

public List<KeyValuePair> getAvailableVocabularyNames() {
    List<KeyValuePair> availableVocabularNames = new ArrayList<>();

    long[] assetVocabularyIds = getAssetVocabularyIds();

    Arrays.sort(assetVocabularyIds);

    Set<Long> availableAssetVocabularyIdsSet = SetUtil.fromArray(getAvailableAssetVocabularyIds());

    for (long assetVocabularyId : availableAssetVocabularyIdsSet) {
        if (Arrays.binarySearch(assetVocabularyIds, assetVocabularyId) < 0) {

            AssetVocabulary assetVocabulary = AssetVocabularyLocalServiceUtil
                    .fetchAssetVocabulary(assetVocabularyId);

            availableVocabularNames/*from w  w  w.j a  va  2 s. com*/
                    .add(new KeyValuePair(String.valueOf(assetVocabularyId), getTitle(assetVocabulary)));
        }
    }

    return ListUtil.sort(availableVocabularNames, new KeyValuePairComparator(false, true));
}

From source file:com.liferay.asset.taglib.internal.display.context.InputAssetLinksDisplayContext.java

License:Open Source License

public List<AssetRendererFactory<?>> getAssetRendererFactories() {
    List<AssetRendererFactory<?>> assetRendererFactories = AssetRendererFactoryRegistryUtil
            .getAssetRendererFactories(_themeDisplay.getCompanyId());

    assetRendererFactories = ListUtil.filter(assetRendererFactories,
            new PredicateFilter<AssetRendererFactory<?>>() {

                @Override//  w  w  w .j  a v  a2s.  c  o  m
                public boolean filter(AssetRendererFactory<?> assetRendererFactory) {

                    if (assetRendererFactory.isLinkable() && assetRendererFactory.isSelectable()) {

                        return true;
                    }

                    return false;
                }

            });

    return ListUtil.sort(assetRendererFactories,
            new AssetRendererFactoryTypeNameComparator(_themeDisplay.getLocale()));
}

From source file:com.liferay.contacts.contactscenter.portlet.ContactsCenterPortlet.java

License:Open Source License

protected JSONObject getContactsJSONObject(PortletRequest portletRequest, PortletResponse portletResponse)
        throws Exception {

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

    String redirect = ParamUtil.getString(portletRequest, "redirect");

    String filterBy = ParamUtil.getString(portletRequest, "filterBy");
    String keywords = ParamUtil.getString(portletRequest, "keywords");
    int start = ParamUtil.getInteger(portletRequest, "start");
    int end = ParamUtil.getInteger(portletRequest, "end");

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    JSONObject optionsJSONObject = JSONFactoryUtil.createJSONObject();

    optionsJSONObject.put("end", end);
    optionsJSONObject.put("filterBy", filterBy);
    optionsJSONObject.put("keywords", keywords);
    optionsJSONObject.put("start", start);

    jsonObject.put("options", optionsJSONObject);

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    String portletId = portletDisplay.getId();

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    if (filterBy.equals(ContactsConstants.FILTER_BY_DEFAULT) && !portletId.equals(PortletKeys.MEMBERS)) {

        List<BaseModel<?>> contacts = EntryLocalServiceUtil.searchUsersAndContacts(themeDisplay.getCompanyId(),
                themeDisplay.getUserId(), keywords, start, end);

        int contactsCount = EntryLocalServiceUtil.searchUsersAndContactsCount(themeDisplay.getCompanyId(),
                themeDisplay.getUserId(), keywords);

        jsonObject.put("count", contactsCount);

        for (BaseModel<?> contact : contacts) {
            JSONObject contactJSONObject = null;

            if (contact instanceof User) {
                contactJSONObject = getUserJSONObject(portletResponse, themeDisplay, (User) contact);
            } else {
                contactJSONObject = getEntryJSONObject(portletResponse, themeDisplay, (Entry) contact,
                        redirect);//from w ww.j  a  v  a 2  s .c  o m
            }

            jsonArray.put(contactJSONObject);
        }
    } else if (filterBy.equals(ContactsConstants.FILTER_BY_FOLLOWERS)
            && !portletId.equals(PortletKeys.MEMBERS)) {

        List<SocialRelation> socialRelations = SocialRelationLocalServiceUtil.getInverseRelations(
                themeDisplay.getUserId(), SocialRelationConstants.TYPE_UNI_FOLLOWER, start, end);

        for (SocialRelation socialRelation : socialRelations) {
            jsonArray.put(getUserJSONObject(portletResponse, themeDisplay, socialRelation.getUserId1()));
        }
    } else if (filterBy.equals(ContactsConstants.FILTER_BY_TYPE_MY_CONTACTS)
            && !portletId.equals(PortletKeys.MEMBERS)) {

        List<Entry> entries = EntryLocalServiceUtil.search(themeDisplay.getUserId(), keywords, start, end);

        int entriesCount = EntryLocalServiceUtil.searchCount(themeDisplay.getUserId(), keywords);

        jsonObject.put("count", entriesCount);

        for (Entry entry : entries) {
            JSONObject contactJSONObject = getEntryJSONObject(portletResponse, themeDisplay, entry, redirect);

            jsonArray.put(contactJSONObject);
        }
    } else {
        LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>();

        params.put("inherit", Boolean.TRUE);

        Group group = themeDisplay.getScopeGroup();
        Layout layout = themeDisplay.getLayout();

        if (group.isUser() && layout.isPublicLayout()) {
            params.put("socialRelationType",
                    new Long[] { group.getClassPK(), (long) SocialRelationConstants.TYPE_BI_CONNECTION });
        } else if (filterBy.startsWith(ContactsConstants.FILTER_BY_TYPE)) {
            params.put("socialRelationType",
                    new Long[] { themeDisplay.getUserId(), ContactsUtil.getSocialRelationType(filterBy) });
        }

        if (portletId.equals(PortletKeys.MEMBERS)) {
            params.put("usersGroups", group.getGroupId());
        } else if (filterBy.startsWith(ContactsConstants.FILTER_BY_GROUP)) {
            params.put("usersGroups", ContactsUtil.getGroupId(filterBy));
        }

        List<User> usersList = null;

        if (filterBy.equals(ContactsConstants.FILTER_BY_ADMINS)) {
            Role siteAdministratorRole = RoleLocalServiceUtil.getRole(group.getCompanyId(),
                    RoleConstants.SITE_ADMINISTRATOR);

            params.put("userGroupRole",
                    new Long[] { new Long(group.getGroupId()), new Long(siteAdministratorRole.getRoleId()) });

            Set<User> users = new HashSet<User>();

            users.addAll(UserLocalServiceUtil.search(themeDisplay.getCompanyId(), keywords,
                    WorkflowConstants.STATUS_APPROVED, params, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
                    (OrderByComparator) null));

            Role siteOwnerRole = RoleLocalServiceUtil.getRole(group.getCompanyId(), RoleConstants.SITE_OWNER);

            params.put("userGroupRole",
                    new Long[] { new Long(group.getGroupId()), new Long(siteOwnerRole.getRoleId()) });

            users.addAll(UserLocalServiceUtil.search(themeDisplay.getCompanyId(), keywords,
                    WorkflowConstants.STATUS_APPROVED, params, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
                    (OrderByComparator) null));

            usersList = new ArrayList<User>(users);

            ListUtil.sort(usersList, new UserLastNameComparator(true));
        } else {
            int usersCount = UserLocalServiceUtil.searchCount(themeDisplay.getCompanyId(), keywords,
                    WorkflowConstants.STATUS_APPROVED, params);

            jsonObject.put("count", usersCount);

            usersList = UserLocalServiceUtil.search(themeDisplay.getCompanyId(), keywords,
                    WorkflowConstants.STATUS_APPROVED, params, start, end, new UserLastNameComparator(true));
        }

        for (User user : usersList) {
            JSONObject userJSONObject = getUserJSONObject(portletResponse, themeDisplay, user);

            jsonArray.put(userJSONObject);
        }
    }

    jsonObject.put("users", jsonArray);

    return jsonObject;
}

From source file:com.liferay.contacts.web.internal.portlet.ContactsCenterPortlet.java

License:Open Source License

protected JSONObject getContactsJSONObject(PortletRequest portletRequest, PortletResponse portletResponse)
        throws Exception {

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

    String redirect = ParamUtil.getString(portletRequest, "redirect");

    String filterBy = ParamUtil.getString(portletRequest, "filterBy");
    String keywords = ParamUtil.getString(portletRequest, "keywords");
    int start = ParamUtil.getInteger(portletRequest, "start");
    int end = ParamUtil.getInteger(portletRequest, "end");

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    JSONObject optionsJSONObject = JSONFactoryUtil.createJSONObject();

    optionsJSONObject.put("end", end);
    optionsJSONObject.put("filterBy", filterBy);
    optionsJSONObject.put("keywords", keywords);
    optionsJSONObject.put("start", start);

    jsonObject.put("options", optionsJSONObject);

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    String portletId = portletDisplay.getId();

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    if (filterBy.equals(ContactsConstants.FILTER_BY_DEFAULT)
            && !portletId.equals(ContactsPortletKeys.MEMBERS)) {

        List<BaseModel<?>> contacts = entryLocalService.searchUsersAndContacts(themeDisplay.getCompanyId(),
                themeDisplay.getUserId(), keywords, start, end);

        int contactsCount = entryLocalService.searchUsersAndContactsCount(themeDisplay.getCompanyId(),
                themeDisplay.getUserId(), keywords);

        jsonObject.put("count", contactsCount);

        for (BaseModel<?> contact : contacts) {
            JSONObject contactJSONObject = null;

            if (contact instanceof User) {
                contactJSONObject = getUserJSONObject(portletResponse, themeDisplay, (User) contact);
            } else {
                contactJSONObject = getEntryJSONObject(portletResponse, themeDisplay, (Entry) contact,
                        redirect);/*  w w w .  j a v a2  s .  c o m*/
            }

            jsonArray.put(contactJSONObject);
        }
    } else if (filterBy.equals(ContactsConstants.FILTER_BY_FOLLOWERS)
            && !portletId.equals(ContactsPortletKeys.MEMBERS)) {

        List<SocialRelation> socialRelations = socialRelationLocalService.getInverseRelations(
                themeDisplay.getUserId(), SocialRelationConstants.TYPE_UNI_FOLLOWER, start, end);

        for (SocialRelation socialRelation : socialRelations) {
            jsonArray.put(getUserJSONObject(portletResponse, themeDisplay, socialRelation.getUserId1()));
        }
    } else if (filterBy.equals(ContactsConstants.FILTER_BY_TYPE_MY_CONTACTS)
            && !portletId.equals(ContactsPortletKeys.MEMBERS)) {

        List<Entry> entries = entryLocalService.search(themeDisplay.getUserId(), keywords, start, end);

        int entriesCount = entryLocalService.searchCount(themeDisplay.getUserId(), keywords);

        jsonObject.put("count", entriesCount);

        for (Entry entry : entries) {
            JSONObject contactJSONObject = getEntryJSONObject(portletResponse, themeDisplay, entry, redirect);

            jsonArray.put(contactJSONObject);
        }
    } else {
        LinkedHashMap<String, Object> params = new LinkedHashMap<>();

        params.put("inherit", Boolean.TRUE);

        Group group = themeDisplay.getScopeGroup();
        Layout layout = themeDisplay.getLayout();

        if (group.isUser() && layout.isPublicLayout()) {
            params.put("socialRelationType",
                    new Long[] { group.getClassPK(), (long) SocialRelationConstants.TYPE_BI_CONNECTION });
        } else if (filterBy.startsWith(ContactsConstants.FILTER_BY_TYPE)) {
            params.put("socialRelationType",
                    new Long[] { themeDisplay.getUserId(), ContactsUtil.getSocialRelationType(filterBy) });
        }

        if (portletId.equals(ContactsPortletKeys.MEMBERS)) {
            params.put("usersGroups", group.getGroupId());
        } else if (filterBy.startsWith(ContactsConstants.FILTER_BY_GROUP)) {
            params.put("usersGroups", ContactsUtil.getGroupId(filterBy));
        }

        List<User> usersList = null;

        if (filterBy.equals(ContactsConstants.FILTER_BY_ADMINS)) {
            Role siteAdministratorRole = roleLocalService.getRole(group.getCompanyId(),
                    RoleConstants.SITE_ADMINISTRATOR);

            params.put("userGroupRole", new Long[] { group.getGroupId(), siteAdministratorRole.getRoleId() });

            Set<User> users = new HashSet<>();

            users.addAll(userLocalService.search(themeDisplay.getCompanyId(), keywords,
                    WorkflowConstants.STATUS_APPROVED, params, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
                    (OrderByComparator) null));

            Role siteOwnerRole = roleLocalService.getRole(group.getCompanyId(), RoleConstants.SITE_OWNER);

            params.put("userGroupRole", new Long[] { group.getGroupId(), siteOwnerRole.getRoleId() });

            users.addAll(userLocalService.search(themeDisplay.getCompanyId(), keywords,
                    WorkflowConstants.STATUS_APPROVED, params, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
                    (OrderByComparator) null));

            usersList = new ArrayList<>(users);

            ListUtil.sort(usersList, new UserLastNameComparator(true));
        } else {
            int usersCount = userLocalService.searchCount(themeDisplay.getCompanyId(), keywords,
                    WorkflowConstants.STATUS_APPROVED, params);

            jsonObject.put("count", usersCount);

            usersList = userLocalService.search(themeDisplay.getCompanyId(), keywords,
                    WorkflowConstants.STATUS_APPROVED, params, start, end, new UserLastNameComparator(true));
        }

        for (User user : usersList) {
            JSONObject userJSONObject = getUserJSONObject(portletResponse, themeDisplay, user);

            jsonArray.put(userJSONObject);
        }
    }

    jsonObject.put("users", jsonArray);

    return jsonObject;
}

From source file:com.liferay.content.targeting.portlet.UserSegmentContentListPortlet.java

License:Open Source License

protected void populateViewContext(String path, PortletRequest portletRequest, PortletResponse portletResponse,
        Template template, TemplateHashModel staticModels) throws Exception {

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

    PortletPreferences portletPreferences = portletRequest.getPreferences();

    long[] availableClassNameIds = getAvailableClassNameIds(themeDisplay.getCompanyId());

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

    populatePortletDisplayTemplateContext(template, portletPreferences, themeDisplay.getScopeGroupId(),
            "abstracts");

    if (Validator.isNull(path) || path.equals(UserSegmentContentListPath.VIEW)) {

        template.put("liferayWindowStatePopUp", LiferayWindowState.POP_UP);

        long[] userSegmentIds = (long[]) portletRequest.getAttribute(WebKeys.USER_SEGMENT_IDS);

        List<AssetEntry> assetEntries = new ArrayList<AssetEntry>();

        if (ArrayUtil.isNotEmpty(userSegmentIds)) {
            AssetEntryQuery entryQuery = new AssetEntryQuery();

            entryQuery.setAnyCategoryIds(
                    ContentTargetingUtil.getAssetCategoryIds(themeDisplay.getScopeGroupId(), userSegmentIds));
            entryQuery.setClassNameIds(classNameIds);

            assetEntries = AssetEntryServiceUtil.getEntries(entryQuery);

            portletRequest.setAttribute("view.jsp-results", new ArrayList());
            portletRequest.setAttribute("view.jsp-assetEntryIndex", new Integer(0));
            portletRequest.setAttribute("view.jsp-show", new Boolean(true));
            portletRequest.setAttribute("view.jsp-print", new Boolean(false));
        }/*from  w  w  w  . j a  v a2s . com*/

        template.put("assetEntries", assetEntries);
        template.put("assetRendererFactoryRegistryUtilClass",
                staticModels.get(AssetRendererFactoryRegistryUtil.class.getName()));

        if (assetEntries.isEmpty()) {
            portletRequest.setAttribute(WebKeys.PORTLET_CONFIGURATOR_VISIBILITY, Boolean.TRUE);
        }

        populatePortletDisplayTemplateViewContext(template, portletRequest, themeDisplay, assetEntries, null);
    } else if (path.equals(UserSegmentContentListPath.VIEW_CONTENT)) {
        long assetEntryId = ParamUtil.getLong(portletRequest, "assetEntryId");

        AssetEntry assetEntry = AssetEntryLocalServiceUtil.fetchAssetEntry(assetEntryId);

        AssetRendererFactory assetRendererFactory = AssetRendererFactoryRegistryUtil
                .getAssetRendererFactoryByClassName(assetEntry.getClassName());

        AssetRenderer assetRenderer = assetRendererFactory.getAssetRenderer(assetEntry.getClassPK());

        portletRequest.setAttribute("view.jsp-results", new ArrayList());
        portletRequest.setAttribute("view.jsp-assetEntryIndex", new Integer(0));
        portletRequest.setAttribute("view.jsp-assetEntry", assetEntry);
        portletRequest.setAttribute("view.jsp-assetRendererFactory", assetRendererFactory);
        portletRequest.setAttribute("view.jsp-assetRenderer", assetRenderer);
        portletRequest.setAttribute("view.jsp-title", assetEntry.getTitle(themeDisplay.getLocale()));
        portletRequest.setAttribute("view.jsp-show", new Boolean(false));
        portletRequest.setAttribute("view.jsp-print", new Boolean(false));
    } else if (path.equals(UserSegmentContentListPath.CONFIGURATION)) {
        List<KeyValuePair> typesLeftList = new ArrayList<KeyValuePair>();

        for (long classNameId : classNameIds) {
            String className = PortalUtil.getClassName(classNameId);

            typesLeftList.add(new KeyValuePair(String.valueOf(classNameId),
                    ResourceActionsUtil.getModelResource(themeDisplay.getLocale(), className)));
        }

        List<KeyValuePair> typesRightList = new ArrayList<KeyValuePair>();

        Arrays.sort(classNameIds);

        List<String> modelResources = new ArrayList<String>();

        for (long classNameId : availableClassNameIds) {
            ClassName className = ClassNameLocalServiceUtil.getClassName(classNameId);

            if (Arrays.binarySearch(classNameIds, classNameId) < 0) {
                typesRightList.add(new KeyValuePair(String.valueOf(classNameId),
                        ResourceActionsUtil.getModelResource(themeDisplay.getLocale(), className.getValue())));
            }

            modelResources
                    .add(ResourceActionsUtil.getModelResource(themeDisplay.getLocale(), className.getValue()));
        }

        typesRightList = ListUtil.sort(typesRightList, new KeyValuePairComparator(false, true));

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

        template.put("anyAssetType", anyAssetType);
        template.put("availableClassNameIds", availableClassNameIds);
        template.put("classNameIds", classNameIds);
        template.put("modelResources", modelResources);
        template.put("typesLeftList", typesLeftList);
        template.put("typesRightList", typesRightList);
    }
}

From source file:com.liferay.contenttargeting.portlet.UserSegmentContentListPortlet.java

License:Open Source License

protected void populateViewContext(String path, PortletRequest portletRequest, PortletResponse portletResponse,
        Template template, TemplateHashModel staticModels) throws Exception {

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

    PortletPreferences portletPreferences = portletRequest.getPreferences();

    long[] availableClassNameIds = getAvailableClassNameIds(themeDisplay.getCompanyId());

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

    if (Validator.isNull(path) || path.equals(UserSegmentContentListPath.VIEW)) {

        template.put("liferayWindowStatePopUp", LiferayWindowState.POP_UP);

        long[] userSegmentIds = (long[]) portletRequest.getAttribute(WebKeys.USER_SEGMENT_IDS);

        List<AssetEntry> assetEntries = new ArrayList<AssetEntry>();

        if (ArrayUtil.isNotEmpty(userSegmentIds)) {
            AssetEntryQuery entryQuery = new AssetEntryQuery();

            entryQuery.setAnyCategoryIds(ContentTargetingUtil.getAssetCategoryIds(userSegmentIds));
            entryQuery.setClassNameIds(classNameIds);

            assetEntries = AssetEntryServiceUtil.getEntries(entryQuery);

            portletRequest.setAttribute("view.jsp-results", new ArrayList());
            portletRequest.setAttribute("view.jsp-assetEntryIndex", new Integer(0));
            portletRequest.setAttribute("view.jsp-show", new Boolean(true));
            portletRequest.setAttribute("view.jsp-print", new Boolean(false));
        }// www .j av a  2 s . com

        template.put("assetEntries", assetEntries);
        template.put("assetRendererFactoryRegistryUtilClass",
                staticModels.get("com.liferay.portlet.asset." + "AssetRendererFactoryRegistryUtil"));

        if (assetEntries.isEmpty()) {
            portletRequest.setAttribute(WebKeys.PORTLET_CONFIGURATOR_VISIBILITY, Boolean.TRUE);
        }
    } else if (path.equals(UserSegmentContentListPath.VIEW_CONTENT)) {
        long assetEntryId = ParamUtil.getLong(portletRequest, "assetEntryId");

        AssetEntry assetEntry = AssetEntryLocalServiceUtil.fetchAssetEntry(assetEntryId);

        AssetRendererFactory assetRendererFactory = AssetRendererFactoryRegistryUtil
                .getAssetRendererFactoryByClassName(assetEntry.getClassName());

        AssetRenderer assetRenderer = assetRendererFactory.getAssetRenderer(assetEntry.getClassPK());

        portletRequest.setAttribute("view.jsp-results", new ArrayList());
        portletRequest.setAttribute("view.jsp-assetEntryIndex", new Integer(0));
        portletRequest.setAttribute("view.jsp-assetEntry", assetEntry);
        portletRequest.setAttribute("view.jsp-assetRendererFactory", assetRendererFactory);
        portletRequest.setAttribute("view.jsp-assetRenderer", assetRenderer);
        portletRequest.setAttribute("view.jsp-title", assetEntry.getTitle(themeDisplay.getLocale()));
        portletRequest.setAttribute("view.jsp-show", new Boolean(false));
        portletRequest.setAttribute("view.jsp-print", new Boolean(false));
    } else if (path.equals(UserSegmentContentListPath.CONFIGURATION)) {
        List<KeyValuePair> typesLeftList = new ArrayList<KeyValuePair>();

        for (long classNameId : classNameIds) {
            String className = PortalUtil.getClassName(classNameId);

            typesLeftList.add(new KeyValuePair(String.valueOf(classNameId),
                    ResourceActionsUtil.getModelResource(themeDisplay.getLocale(), className)));
        }

        List<KeyValuePair> typesRightList = new ArrayList<KeyValuePair>();

        Arrays.sort(classNameIds);

        List<String> modelResources = new ArrayList<String>();

        for (long classNameId : availableClassNameIds) {
            ClassName className = ClassNameLocalServiceUtil.getClassName(classNameId);

            if (Arrays.binarySearch(classNameIds, classNameId) < 0) {
                typesRightList.add(new KeyValuePair(String.valueOf(classNameId),
                        ResourceActionsUtil.getModelResource(themeDisplay.getLocale(), className.getValue())));
            }

            modelResources
                    .add(ResourceActionsUtil.getModelResource(themeDisplay.getLocale(), className.getValue()));
        }

        typesRightList = ListUtil.sort(typesRightList, new KeyValuePairComparator(false, true));

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

        template.put("anyAssetType", anyAssetType);
        template.put("availableClassNameIds", availableClassNameIds);
        template.put("classNameIds", classNameIds);
        template.put("modelResources", modelResources);
        template.put("typesLeftList", typesLeftList);
        template.put("typesRightList", typesRightList);
    }
}