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

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

Introduction

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

Prototype

public static String toString(List<?> list, String param) 

Source Link

Usage

From source file:com.inkwell.internet.slogan.search.SloganIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(Object obj) throws Exception {

    Slogan slogan = (Slogan) obj;//ww  w .  j  a va  2 s  . c  o m
    long companyId = slogan.getCompanyId();
    long groupId = getParentGroupId(slogan.getGroupId());
    long scopeGroupId = slogan.getGroupId();
    long userId = slogan.getUserId();
    long resourcePrimKey = slogan.getPrimaryKey();
    String title = slogan.getSloganText();
    String content = slogan.getSloganText();
    String description = slogan.getSloganText();
    Date modifiedDate = slogan.getSloganDate();

    long[] assetCategoryIds = AssetCategoryLocalServiceUtil.getCategoryIds(Slogan.class.getName(),
            resourcePrimKey);

    List<AssetCategory> categories = AssetCategoryLocalServiceUtil.getCategories(Slogan.class.getName(),
            resourcePrimKey);

    String[] assetCategoryNames = StringUtil.split(ListUtil.toString(categories, "name"));

    // EE lets you do this quicker: 

    // String[] assetCategoryNames =
    //     AssetCategoryLocalServiceUtil.getCategoryNames(
    //         Slogan.class.getName(), resourcePrimKey);

    String[] assetTagNames = AssetTagLocalServiceUtil.getTagNames(Slogan.class.getName(), resourcePrimKey);

    Document document = new DocumentImpl();

    document.addUID(PORTLET_ID, resourcePrimKey);

    document.addModifiedDate(modifiedDate);

    document.addKeyword(Field.COMPANY_ID, companyId);
    document.addKeyword(Field.PORTLET_ID, PORTLET_ID);
    document.addKeyword(Field.GROUP_ID, groupId);
    document.addKeyword(Field.SCOPE_GROUP_ID, scopeGroupId);
    document.addKeyword(Field.USER_ID, userId);
    document.addText(Field.TITLE, title);
    document.addText(Field.CONTENT, content);
    document.addText(Field.DESCRIPTION, description);
    document.addKeyword(Field.ASSET_CATEGORY_IDS, assetCategoryIds);
    document.addKeyword("assetCategoryNames", assetCategoryNames);
    //document.addKeyword(Field.ASSET_CATEGORY_NAMES, assetCategoryNames);
    document.addKeyword(Field.ASSET_TAG_NAMES, assetTagNames);

    document.addKeyword(Field.ENTRY_CLASS_NAME, Slogan.class.getName());
    document.addKeyword(Field.ENTRY_CLASS_PK, resourcePrimKey);

    return document;
}

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

License:Open Source License

public String getSelectCategoryURL() throws Exception {
    if (_selectCategoryURL != null) {
        return _selectCategoryURL;
    }//from  w  w  w. j  a v  a 2 s . c  o m

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

    List<AssetVocabulary> vocabularies = AssetVocabularyServiceUtil
            .getGroupVocabularies(themeDisplay.getScopeGroupId());

    PortletURL selectCategoryURL = PortletProviderUtil.getPortletURL(_request, AssetCategory.class.getName(),
            PortletProvider.Action.BROWSE);

    selectCategoryURL.setParameter("allowedSelectVocabularies", Boolean.TRUE.toString());
    selectCategoryURL.setParameter("eventName", _renderResponse.getNamespace() + "selectCategory");
    selectCategoryURL.setParameter("singleSelect", Boolean.TRUE.toString());
    selectCategoryURL.setParameter("vocabularyIds",
            ListUtil.toString(vocabularies, AssetVocabulary.VOCABULARY_ID_ACCESSOR));
    selectCategoryURL.setWindowState(LiferayWindowState.POP_UP);

    _selectCategoryURL = selectCategoryURL.toString();

    return _selectCategoryURL;
}

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

License:Open Source License

public String getVocabularyIds() throws Exception {
    List<AssetVocabulary> vocabularies = AssetVocabularyServiceUtil.getGroupsVocabularies(getGroupIds());

    return ListUtil.toString(vocabularies, AssetVocabulary.VOCABULARY_ID_ACCESSOR);
}

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;/*  www  . j a  va  2  s .co  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.portlet.DisplayPageFriendlyURLResolver.java

License:Open Source License

@Override
public String getActualURL(long companyId, long groupId, boolean privateLayout, String mainPath,
        String friendlyURL, Map<String, String[]> params, Map<String, Object> requestContext)
        throws PortalException {

    String urlTitle = friendlyURL.substring(JournalArticleConstants.CANONICAL_URL_SEPARATOR.length());

    JournalArticle journalArticle = _journalArticleLocalService.getArticleByUrlTitle(groupId, urlTitle);

    Layout layout = getJournalArticleLayout(groupId, privateLayout, friendlyURL);

    String layoutActualURL = _portal.getLayoutActualURL(layout, mainPath);

    InheritableMap<String, String[]> actualParams = new InheritableMap<>();

    if (params != null) {
        actualParams.setParentMap(params);
    }/*  w  w  w  . j  a  v a2s  . com*/

    UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties();

    String defaultAssetPublisherPortletId = typeSettingsProperties
            .get(LayoutTypePortletConstants.DEFAULT_ASSET_PUBLISHER_PORTLET_ID);

    String currentDefaultAssetPublisherPortletId = defaultAssetPublisherPortletId;

    if (Validator.isNull(defaultAssetPublisherPortletId)) {
        defaultAssetPublisherPortletId = PortletIdCodec.encode(AssetPublisherPortletKeys.ASSET_PUBLISHER);
    }

    HttpServletRequest request = (HttpServletRequest) requestContext.get("request");

    if (Validator.isNull(currentDefaultAssetPublisherPortletId)) {
        String actualPortletAuthenticationToken = AuthTokenUtil.getToken(request, layout.getPlid(),
                defaultAssetPublisherPortletId);

        actualParams.put("p_p_auth", new String[] { actualPortletAuthenticationToken });
    }

    actualParams.put("p_p_id", new String[] { defaultAssetPublisherPortletId });
    actualParams.put("p_p_lifecycle", new String[] { "0" });

    if (Validator.isNull(currentDefaultAssetPublisherPortletId)) {
        actualParams.put("p_p_state", new String[] { WindowState.MAXIMIZED.toString() });
    }

    actualParams.put("p_p_mode", new String[] { "view" });
    actualParams.put("p_j_a_id", new String[] { String.valueOf(journalArticle.getId()) });

    String namespace = _portal.getPortletNamespace(defaultAssetPublisherPortletId);

    actualParams.put(namespace + "mvcPath", new String[] { "/view_content.jsp" });

    AssetRendererFactory<?> assetRendererFactory = AssetRendererFactoryRegistryUtil
            .getAssetRendererFactoryByClassName(JournalArticle.class.getName());

    actualParams.put(namespace + "type", new String[] { assetRendererFactory.getType() });

    actualParams.put(namespace + "urlTitle", new String[] { journalArticle.getUrlTitle() });

    String queryString = _http.parameterMapToString(actualParams, false);

    if (layoutActualURL.contains(StringPool.QUESTION)) {
        layoutActualURL = layoutActualURL + StringPool.AMPERSAND + queryString;
    } else {
        layoutActualURL = layoutActualURL + StringPool.QUESTION + queryString;
    }

    Locale locale = _portal.getLocale(request);

    _portal.addPageSubtitle(journalArticle.getTitle(locale), request);
    _portal.addPageDescription(journalArticle.getDescription(locale), request);

    List<AssetTag> assetTags = _assetTagLocalService.getTags(JournalArticle.class.getName(),
            journalArticle.getPrimaryKey());

    if (!assetTags.isEmpty()) {
        _portal.addPageKeywords(ListUtil.toString(assetTags, AssetTag.NAME_ACCESSOR), request);
    }

    return layoutActualURL;
}

From source file:com.liferay.asset.taglib.servlet.taglib.AssetCategoriesSelectorTag.java

License:Open Source License

protected List<String[]> getCategoryIdsTitles() {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    List<String[]> categoryIdsTitles = new ArrayList<>();

    String categoryIds = StringPool.BLANK;

    if (Validator.isNotNull(_categoryIds)) {
        categoryIds = _categoryIds;//from w ww . j  av  a 2s.co m
    }

    if (Validator.isNull(_className)) {
        if (!_ignoreRequestValue) {
            String categoryIdsParam = request.getParameter(_hiddenInput);

            if (categoryIdsParam != null) {
                categoryIds = categoryIdsParam;
            }
        }

        String[] categoryIdsTitle = AssetCategoryUtil.getCategoryIdsTitles(categoryIds, StringPool.BLANK, 0,
                themeDisplay);

        categoryIdsTitles.add(categoryIdsTitle);

        return categoryIdsTitles;
    }

    try {
        for (AssetVocabulary vocabulary : getVocabularies()) {
            String categoryNames = StringPool.BLANK;

            if (Validator.isNotNull(_className) && (_classPK > 0)) {
                List<AssetCategory> categories = AssetCategoryServiceUtil.getCategories(_className, _classPK);

                categoryIds = ListUtil.toString(categories, AssetCategory.CATEGORY_ID_ACCESSOR);
                categoryNames = ListUtil.toString(categories, AssetCategory.NAME_ACCESSOR);
            }

            if (!_ignoreRequestValue) {
                String categoryIdsParam = request
                        .getParameter(_hiddenInput + StringPool.UNDERLINE + vocabulary.getVocabularyId());

                if (Validator.isNotNull(categoryIdsParam)) {
                    categoryIds = categoryIdsParam;
                }
            }

            String[] categoryIdsTitle = AssetCategoryUtil.getCategoryIdsTitles(categoryIds, categoryNames,
                    vocabulary.getVocabularyId(), themeDisplay);

            categoryIdsTitles.add(categoryIdsTitle);
        }
    } catch (Exception e) {
    }

    return categoryIdsTitles;
}

From source file:com.liferay.asset.taglib.servlet.taglib.AssetTagsSelectorTag.java

License:Open Source License

protected String getTagNames() {
    String tagNames = _tagNames;/*  w  w  w. j  a v a  2s .co m*/

    if (Validator.isNotNull(_className) && (_classPK > 0)) {
        List<AssetTag> tags = AssetTagServiceUtil.getTags(_className, _classPK);

        tagNames = ListUtil.toString(tags, AssetTag.NAME_ACCESSOR);
    }

    if (!_ignoreRequestValue) {
        String curTagsParam = request.getParameter(_hiddenInput);

        if (Validator.isNotNull(curTagsParam)) {
            tagNames = curTagsParam;
        }
    }

    return tagNames;
}

From source file:com.liferay.content.targeting.analytics.service.impl.AnalyticsEventLocalServiceImpl.java

License:Open Source License

protected long[] getAnalyticsEventsIds(List<AnalyticsEvent> analyticsEvents) {

    return StringUtil.split(ListUtil.toString(analyticsEvents, AnalyticsEvent.ANALYTICS_EVENT_ID_ACCESSOR), 0L);
}

From source file:com.liferay.contenttargeting.portlet.ContentTargetingPortlet.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);

    if (Validator.isNull(path) || path.equals(ContentTargetingPath.VIEW)
            || path.equals(ContentTargetingPath.VIEW_CAMPAIGNS_RESOURCES)
            || path.equals(ContentTargetingPath.VIEW_USER_SEGMENTS_RESOURCES)) {

        template.put("actionKeys", staticModels.get("com.liferay.contenttargeting.util.ActionKeys"));

        template.put("campaignPermission",
                staticModels.get("com.liferay.contenttargeting.service.permission." + "CampaignPermission"));
        template.put("contentTargetingPermission", staticModels
                .get("com.liferay.contenttargeting.service.permission." + "ContentTargetingPermission"));
        template.put("userSegmentPermission",
                staticModels.get("com.liferay.contenttargeting.service.permission." + "UserSegmentPermission"));

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

        template.put("campaignSearchContainerIterator",
                new CampaignSearchContainerIterator(themeDisplay.getScopeGroupId(), keywords));
        template.put("userSegmentSearchContainerIterator",
                new UserSegmentSearchContainerIterator(themeDisplay.getScopeGroupId(), keywords));
        template.put("usedUserSegmentExceptionClass", UsedUserSegmentException.class);
    } else if (path.equals(ContentTargetingPath.EDIT_CAMPAIGN)
            || path.equals(ContentTargetingPath.VIEW_CAMPAIGN_REPORTS)) {

        long campaignId = ParamUtil.getLong(portletRequest, "campaignId");

        template.put("campaignId", campaignId);

        int priority = 1;
        long userSegmentId = -1;

        if (campaignId > 0) {
            Campaign campaign = _campaignLocalService.getCampaign(campaignId);

            template.put("campaign", campaign);

            List<UserSegment> campaignUserSegments = _userSegmentLocalService
                    .getCampaignUserSegments(campaignId);

            priority = campaign.getPriority();

            // Initially, only one user segment per campaign is supported

            if ((campaignUserSegments != null) && !campaignUserSegments.isEmpty()) {

                UserSegment campaignUserSegment = campaignUserSegments.get(0);

                userSegmentId = campaignUserSegment.getUserSegmentId();
            }//  w  w w.  j  a v  a  2  s  . co  m
        }

        template.put("priority", priority);
        template.put("userSegmentId", userSegmentId);

        long[] groupIds = ContentTargetingUtil.getAncestorsAndCurrentGroupIds(themeDisplay.getScopeGroupId());

        List<UserSegment> userSegments = _userSegmentService.getUserSegments(groupIds);

        template.put("userSegments", userSegments);

        template.put("trackingActionsRegistry", _trackingActionsRegistry);

        Map<String, TrackingAction> trackingActions = _trackingActionsRegistry.getTrackingActions();

        boolean isolated = themeDisplay.isIsolated();

        try {
            themeDisplay.setIsolated(true);

            template.put("trackingActions", trackingActions.values());

            if (campaignId > 0) {
                List<TrackingActionInstance> instances = _trackingActionInstanceService
                        .getTrackingActionInstances(campaignId);

                template.put("trackingActionInstances", instances);

                List<TrackingActionTemplate> addedTrackingActionTemplates = new ArrayList<TrackingActionTemplate>();

                for (TrackingActionInstance instance : instances) {
                    TrackingAction trackingAction = _trackingActionsRegistry
                            .getTrackingAction(instance.getTrackingActionKey());

                    TrackingActionTemplate trackingActionTemplate = new TrackingActionTemplate();

                    String html = trackingAction.getFormHTML(instance, _cloneTemplateContext(template));

                    trackingActionTemplate.setInstanceId(instance.getTrackingActionInstanceId());
                    trackingActionTemplate.setTrackingAction(trackingAction);
                    trackingActionTemplate.setTemplate(HtmlUtil.escapeAttribute(html));

                    addedTrackingActionTemplates.add(trackingActionTemplate);
                }

                template.put("addedTrackingActionTemplates", addedTrackingActionTemplates);
            }

            List<TrackingActionTemplate> trackingActionTemplates = new ArrayList<TrackingActionTemplate>();

            for (TrackingAction trackingAction : trackingActions.values()) {
                TrackingActionTemplate trackingActionTemplate = new TrackingActionTemplate();

                String html = trackingAction.getFormHTML(null, _cloneTemplateContext(template));

                trackingActionTemplate.setTrackingAction(trackingAction);
                trackingActionTemplate.setTemplate(HtmlUtil.escapeAttribute(html));

                trackingActionTemplates.add(trackingActionTemplate);
            }

            template.put("trackingActionTemplates", trackingActionTemplates);

            if (path.equals(ContentTargetingPath.VIEW_CAMPAIGN_REPORTS)) {
                template.put("tabs2", ParamUtil.getString(portletRequest, "tabs2"));

                Map<String, Report> campaignReports = _reportsRegistry.getReports(Campaign.class.getName());

                List<ReportTemplate> campaignReportsTemplates = new ArrayList<ReportTemplate>();

                for (Report report : campaignReports.values()) {
                    ReportTemplate reportTemplate = new ReportTemplate();

                    String html = report.getHTML(_cloneTemplateContext(template));

                    reportTemplate.setReport(report);
                    reportTemplate.setTemplate(html);

                    campaignReportsTemplates.add(reportTemplate);
                }

                template.put("campaignReportsTabNames", ListUtil.toString(campaignReportsTemplates, "name"));
                template.put("campaignReportsTemplates", campaignReportsTemplates);
            }
        } finally {
            themeDisplay.setIsolated(isolated);
        }
    } else if (path.equals(ContentTargetingPath.EDIT_USER_SEGMENT)
            || path.equals(ContentTargetingPath.VIEW_USER_SEGMENT_REPORTS)) {

        long userSegmentId = ParamUtil.getLong(portletRequest, "userSegmentId");

        template.put("userSegmentId", userSegmentId);

        template.put("rulesRegistry", _rulesRegistry);

        Map<String, Rule> rules = _rulesRegistry.getRules();

        boolean isolated = themeDisplay.isIsolated();

        try {
            themeDisplay.setIsolated(true);

            template.put("rules", rules.values());

            if (userSegmentId > 0) {
                List<RuleInstance> ruleInstances = _ruleInstanceService.getRuleInstances(userSegmentId);

                template.put("ruleInstances", ruleInstances);

                List<RuleTemplate> addedRuleTemplates = new ArrayList<RuleTemplate>();

                for (RuleInstance ruleInstance : ruleInstances) {
                    Rule rule = _rulesRegistry.getRule(ruleInstance.getRuleKey());

                    RuleTemplate ruleTemplate = new RuleTemplate();

                    String html = rule.getFormHTML(ruleInstance, _cloneTemplateContext(template));

                    ruleTemplate.setInstanceId(ruleInstance.getRuleInstanceId());
                    ruleTemplate.setRule(rule);
                    ruleTemplate.setTemplate(HtmlUtil.escapeAttribute(html));

                    addedRuleTemplates.add(ruleTemplate);
                }

                template.put("addedRuleTemplates", addedRuleTemplates);

                UserSegment userSegment = _userSegmentLocalService.getUserSegment(userSegmentId);

                template.put("userSegment", userSegment);
            }

            List<RuleTemplate> ruleTemplates = new ArrayList<RuleTemplate>();

            for (Rule rule : rules.values()) {
                RuleTemplate ruleTemplate = new RuleTemplate();

                String html = rule.getFormHTML(null, _cloneTemplateContext(template));

                ruleTemplate.setRule(rule);
                ruleTemplate.setTemplate(HtmlUtil.escapeAttribute(html));

                ruleTemplates.add(ruleTemplate);
            }

            template.put("ruleTemplates", ruleTemplates);

            if (path.equals(ContentTargetingPath.VIEW_USER_SEGMENT_REPORTS)) {

                template.put("tabs2", ParamUtil.getString(portletRequest, "tabs2"));

                Map<String, Report> userSegmentReports = _reportsRegistry
                        .getReports(UserSegment.class.getName());

                List<ReportTemplate> userSegmentReportsTemplates = new ArrayList<ReportTemplate>();

                for (Report report : userSegmentReports.values()) {
                    ReportTemplate reportTemplate = new ReportTemplate();

                    String html = report.getHTML(_cloneTemplateContext(template));

                    reportTemplate.setReport(report);
                    reportTemplate.setTemplate(html);

                    userSegmentReportsTemplates.add(reportTemplate);
                }

                template.put("userSegmentReportsTabNames",
                        ListUtil.toString(userSegmentReportsTemplates, "name"));
                template.put("userSegmentReportsTemplates", userSegmentReportsTemplates);
            }
        } finally {
            themeDisplay.setIsolated(isolated);
        }
    }
}

From source file:com.liferay.knowledgebase.admin.lar.AdminPortletDataHandlerImpl.java

License:Open Source License

protected List<KBArticle> getKBArticles(PortletDataContext portletDataContext) throws Exception {

    // Order kbArticles by depth and sort siblings by priority to retain the
    // priority value on import. See KBArticleLocalServiceImpl#getPriority.

    List<KBArticle> kbArticles = new ArrayList<KBArticle>();

    List<KBArticle> siblingKBArticles = new ArrayList<KBArticle>();

    Long[][] params = new Long[][] { new Long[] { KBArticleConstants.DEFAULT_PARENT_RESOURCE_PRIM_KEY } };

    while ((params = KnowledgeBaseUtil.getParams(params[0])) != null) {
        List<KBArticle> curKBArticles = KBArticleUtil.findByG_P_M(portletDataContext.getScopeGroupId(),
                ArrayUtil.toArray(params[1]), true, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
                new KBArticlePriorityComparator(true));

        siblingKBArticles.addAll(curKBArticles);

        if (params[0].length > 0) {
            continue;
        }//from  w w w.  j a  v  a2 s .  c  o  m

        long[] siblingKBArticlesResourcePrimKeys = StringUtil
                .split(ListUtil.toString(siblingKBArticles, "resourcePrimKey"), 0L);

        params[0] = ArrayUtil.toArray(siblingKBArticlesResourcePrimKeys);

        kbArticles.addAll(siblingKBArticles);
        siblingKBArticles.clear();
    }

    return kbArticles;
}