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

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

Introduction

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

Prototype

public static int[] getIntegerValues(String[] values, int[] defaultValue) 

Source Link

Document

Returns the String array values as an integer array.

Usage

From source file:com.liferay.content.targeting.portlet.util.CampaignQueryRuleUtil.java

License:Open Source License

public static List<QueryRule> getCampaignQueryRules(PortletPreferences portletPreferences, Locale locale,
        boolean includeEmptyQueryRule) throws PortalException, SystemException {

    List<QueryRule> campaignQueryRules = new ArrayList<QueryRule>();

    int[] queryRulesIndexes = GetterUtil
            .getIntegerValues(portletPreferences.getValues("queryLogicIndexes", null), new int[0]);

    for (int queryRulesIndex : queryRulesIndexes) {
        QueryRule campaignQueryRule = getQueryRule(portletPreferences, queryRulesIndex, locale);

        if (campaignQueryRule.isValid()) {
            campaignQueryRules.add(campaignQueryRule);
        }/*from  www .  j av  a2s  .c  o m*/
    }

    if (campaignQueryRules.isEmpty() && includeEmptyQueryRule) {
        campaignQueryRules.add(new CampaignQueryRule());
    }

    Collections.sort(campaignQueryRules);

    campaignQueryRules.add(getDefaultQueryRule(portletPreferences, locale));

    return campaignQueryRules;
}

From source file:com.liferay.content.targeting.portlet.util.UserSegmentQueryRuleUtil.java

License:Open Source License

public static List<QueryRule> getUserSegmentQueryRules(PortletPreferences portletPreferences, Locale locale,
        boolean includeEmptyQueryRule) throws PortalException, SystemException {

    List<QueryRule> userSegmentQueryRules = new ArrayList<QueryRule>();

    int[] queryRulesIndexes = GetterUtil
            .getIntegerValues(portletPreferences.getValues("queryLogicIndexes", null), new int[0]);

    for (int queryRulesIndex : queryRulesIndexes) {
        QueryRule userSegmentQueryRule = getQueryRule(portletPreferences, queryRulesIndex, locale);

        if (userSegmentQueryRule.isValid()) {
            userSegmentQueryRules.add(userSegmentQueryRule);
        }//w w w. j a v a 2 s .c o  m
    }

    if (userSegmentQueryRules.isEmpty() && includeEmptyQueryRule) {
        userSegmentQueryRules.add(new UserSegmentQueryRule());
    }

    userSegmentQueryRules.add(getDefaultQueryRule(portletPreferences, locale));

    return userSegmentQueryRules;
}

From source file:com.liferay.contenttargeting.portlet.CampaignContentDisplayPortlet.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 assetEntryIdDefault = GetterUtil.getLong(portletPreferences.getValue("assetEntryIdDefault", null));
    boolean contentDefaultValue = GetterUtil
            .getBoolean(portletPreferences.getValue("contentDefaultValue", null));

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

        CampaignQueryRule queryRule = null;

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

        if (userSegmentIds != null) {
            long[] groupIds = ContentTargetingUtil
                    .getAncestorsAndCurrentGroupIds(themeDisplay.getSiteGroupId());

            Campaign campaign = _campaignLocalService.fetchCurrentMaxPriorityCampaign(groupIds, userSegmentIds);

            if (campaign != null) {
                queryRule = CampaignQueryRuleUtil.match(campaign.getCampaignId(), portletPreferences,
                        themeDisplay.getLocale());

                template.put("campaignClassName", Campaign.class.getName());
                template.put("campaignClassPK", campaign.getCampaignId());
                template.put("groupId", campaign.getGroupId());
            }//from  w  ww .  j a  v  a2 s  . co m
        }

        boolean isMatchingRule = false;

        if ((queryRule != null) || (contentDefaultValue && (assetEntryIdDefault > 0))) {

            isMatchingRule = true;

            long assetEntryId = assetEntryIdDefault;

            if (queryRule != null) {
                assetEntryId = queryRule.getAssetEntryId();
            }

            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));

            template.put("assetEntryClassName", assetEntry.getClassName());
            template.put("assetEntryClassPK", assetEntry.getClassPK());
        } else {
            portletRequest.setAttribute(WebKeys.PORTLET_CONFIGURATOR_VISIBILITY, Boolean.TRUE);
        }

        template.put("isMatchingRule", isMatchingRule);
        template.put("liferayWindowStatePopUp", LiferayWindowState.POP_UP);
    } else if (path.equals(CampaignContentDisplayPath.EDIT_QUERY_RULE)
            || path.equals(CampaignContentDisplayPath.CONFIGURATION)) {

        template.put("assetRendererFactories",
                getSelectableAssetRendererFactories(themeDisplay.getCompanyId()));

        String assetImageDefault = StringPool.BLANK;
        String assetTitleDefault = StringPool.BLANK;
        String assetTypeDefault = StringPool.BLANK;

        if (assetEntryIdDefault > 0) {
            AssetEntry assetEntry = AssetEntryLocalServiceUtil.fetchAssetEntry(assetEntryIdDefault);

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

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

            assetImageDefault = assetRenderer.getThumbnailPath(portletRequest);
            assetTitleDefault = assetRenderer.getTitle(themeDisplay.getLocale());
            assetTypeDefault = assetRendererFactory.getTypeName(themeDisplay.getLocale(), true);
        }

        List<Campaign> campaigns = _campaignService.getCampaigns(themeDisplay.getScopeGroupId());

        template.put("campaigns", campaigns);

        template.put("assetEntryIdDefault", assetEntryIdDefault);
        template.put("assetImageDefault", assetImageDefault);
        template.put("assetTitleDefault", assetTitleDefault);
        template.put("assetTypeDefault", assetTypeDefault);
        template.put("contentDefaultValue", contentDefaultValue);
        template.put("liferayWindowStateExclusive", LiferayWindowState.EXCLUSIVE);
        template.put("portletPreferences", portletPreferences);

        int[] queryRulesIndexes = GetterUtil
                .getIntegerValues(portletPreferences.getValues("queryLogicIndexes", null), new int[] { 0 });

        template.put("queryLogicIndexes", queryRulesIndexes);
        template.put("campaignQueryRuleUtilClass",
                staticModels.get("com.liferay.contenttargeting.portlet.util." + "CampaignQueryRuleUtil"));
        template.put("userSegmentContentDisplayUtilClass", staticModels
                .get("com.liferay.contenttargeting.portlet.util." + "UserSegmentContentDisplayUtil"));
    }
}

From source file:com.liferay.contenttargeting.portlet.UserSegmentContentDisplayPortlet.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 assetEntryIdDefault = GetterUtil.getLong(portletPreferences.getValue("assetEntryIdDefault", null));
    boolean contentDefaultValue = GetterUtil
            .getBoolean(portletPreferences.getValue("contentDefaultValue", null));

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

        UserSegmentQueryRule queryRule = null;

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

        if (userSegmentIds != null) {
            long[] userSegmentAssetCategoryIds = ContentTargetingUtil.getAssetCategoryIds(userSegmentIds);

            queryRule = UserSegmentQueryRuleUtil.match(userSegmentAssetCategoryIds, portletPreferences,
                    themeDisplay.getLocale());
        }/*  ww  w.  ja  v a2  s  .  com*/

        boolean isMatchingRule = false;

        if ((queryRule != null) || (contentDefaultValue && (assetEntryIdDefault > 0))) {

            isMatchingRule = true;

            long assetEntryId = assetEntryIdDefault;

            if (queryRule != null) {
                assetEntryId = queryRule.getAssetEntryId();
            }

            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 {
            portletRequest.setAttribute(WebKeys.PORTLET_CONFIGURATOR_VISIBILITY, Boolean.TRUE);
        }

        template.put("isMatchingRule", isMatchingRule);
        template.put("liferayWindowStatePopUp", LiferayWindowState.POP_UP);
    } else if (path.equals(UserSegmentContentDisplayPath.EDIT_QUERY_RULE)
            || path.equals(UserSegmentContentDisplayPath.CONFIGURATION)) {

        template.put("assetRendererFactories",
                getSelectableAssetRendererFactories(themeDisplay.getCompanyId()));

        String assetImageDefault = StringPool.BLANK;
        String assetTitleDefault = StringPool.BLANK;
        String assetTypeDefault = StringPool.BLANK;

        if (assetEntryIdDefault > 0) {
            AssetEntry assetEntry = AssetEntryLocalServiceUtil.fetchAssetEntry(assetEntryIdDefault);

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

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

            assetImageDefault = assetRenderer.getThumbnailPath(portletRequest);
            assetTitleDefault = assetRenderer.getTitle(themeDisplay.getLocale());
            assetTypeDefault = assetRendererFactory.getTypeName(themeDisplay.getLocale(), true);
        }

        template.put("assetEntryIdDefault", assetEntryIdDefault);
        template.put("assetImageDefault", assetImageDefault);
        template.put("assetTitleDefault", assetTitleDefault);
        template.put("assetTypeDefault", assetTypeDefault);
        template.put("contentDefaultValue", contentDefaultValue);
        template.put("liferayWindowStateExclusive", LiferayWindowState.EXCLUSIVE);
        template.put("portletPreferences", portletPreferences);

        int[] queryRulesIndexes = GetterUtil
                .getIntegerValues(portletPreferences.getValues("queryLogicIndexes", null), new int[] { 0 });

        template.put("queryLogicIndexes", queryRulesIndexes);
        template.put("userSegmentQueryRuleUtilClass",
                staticModels.get("com.liferay.contenttargeting.portlet.util." + "UserSegmentQueryRuleUtil"));
        template.put("userSegmentContentDisplayUtilClass", staticModels
                .get("com.liferay.contenttargeting.portlet.util." + "UserSegmentContentDisplayUtil"));

        ServiceContext serviceContext = new ServiceContext();

        serviceContext.setScopeGroupId(themeDisplay.getScopeGroupId());

        long[] vocabularyGroupIds = new long[1];
        long[] vocabularyIds = new long[1];

        if (themeDisplay.getScopeGroupId() == themeDisplay.getCompanyGroupId()) {

            vocabularyGroupIds[0] = themeDisplay.getCompanyGroupId();

            vocabularyIds[0] = UserSegmentUtil.getAssetVocabularyId(themeDisplay.getUserId(), serviceContext);
        } else {
            vocabularyGroupIds = ContentTargetingUtil
                    .getAncestorsAndCurrentGroupIds(themeDisplay.getSiteGroupId());
            vocabularyIds = UserSegmentUtil.getAssetVocabularyIds(vocabularyGroupIds);
        }

        template.put("vocabularyGroupIds", StringUtil.merge(vocabularyGroupIds));
        template.put("vocabularyIds", StringUtil.merge(vocabularyIds));
    }
}