Example usage for com.liferay.portal.kernel.util PrefsParamUtil getString

List of usage examples for com.liferay.portal.kernel.util PrefsParamUtil getString

Introduction

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

Prototype

public static String getString(PortletPreferences preferences, PortletRequest portletRequest, String param) 

Source Link

Usage

From source file:com.beorn.onlinepayment.shopping.action.BtopCheckoutAction.java

License:Open Source License

@Override
public void processAction(StrutsPortletAction originalStrutsPortletAction, PortletConfig portletConfig,
        ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

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

    long companyId = themeDisplay.getCompanyId();
    long ownerId = themeDisplay.getScopeGroupId();
    int ownerType = PortletKeys.PREFS_OWNER_TYPE_GROUP;
    long plid = PortletKeys.PREFS_PLID_SHARED;
    String portletId = PortletKeys.SHOPPING;

    PortletPreferences preferences = PortletPreferencesLocalServiceUtil.getPreferences(companyId, ownerId,
            ownerType, plid, portletId);

    String paymentType = PrefsParamUtil.getString(preferences, actionRequest, "paymentType");

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
    if (cmd.equals(Constants.SAVE) && paymentType.equals("Betop")) {
        processSaveCheckoutActionWithoutForwarding(originalStrutsPortletAction, actionRequest, actionResponse);

        PaymentAppSender paymentAppSender = PaymentAppUtil.getPaymentAppSender();

        ShoppingCart cart = ShoppingUtil.getCart(actionRequest);

        ShoppingOrder order = (ShoppingOrder) actionRequest.getAttribute("SHOPPING_ORDER");

        long sellerId = GetterUtil.getLong(preferences.getValue("sellerId", "0"));
        double amount = ShoppingUtil.calculateTotal(cart.getItems(), order.getBillingState(), cart.getCoupon(),
                cart.getAltShipping(), cart.isInsure());
        String currencyCode = preferences.getValue("currencyId", "USD");

        Long transactionId = paymentAppSender.addTransaction(sellerId, amount, currencyCode);

        OrderTransactionLocalServiceUtil.addOrderTransaction(order.getOrderId(), transactionId);

        HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);

        String remoteIp = request.getRemoteAddr();
        String forwardedForIp = StringUtil.extractFirst(request.getHeader("X-Forwarded-For"),
                StringPool.COMMA_AND_SPACE);
        if (forwardedForIp != null)
            remoteIp = forwardedForIp;// w w  w .ja  v a 2s .c om

        List<ApiPaymentMethod> paymentMethods = paymentAppSender.getPaymentMethods(transactionId,
                paymentAppSender.geolocalizeIp(remoteIp));

        Long[] paymentMethodIds = new Long[paymentMethods.size()];
        String[] paymentMethodNames = new String[paymentMethods.size()];

        for (int i = 0; i < paymentMethods.size(); ++i) {
            paymentMethodIds[i] = paymentMethods.get(i).getPaymentMethodId();
            paymentMethodNames[i] = paymentMethods.get(i).getName(themeDisplay.getLocale());
        }

        actionRequest.setAttribute("orderId", order.getOrderId());
        actionRequest.setAttribute("paymentMethodIds", paymentMethodIds);
        actionRequest.setAttribute("paymentMethodNames", paymentMethodNames);

    } else {
        originalStrutsPortletAction.processAction(originalStrutsPortletAction, portletConfig, actionRequest,
                actionResponse);
    }
}

From source file:com.beorn.onlinepayment.shopping.action.BtopCheckoutAction.java

License:Open Source License

@Override
public String render(StrutsPortletAction originalStrutsPortletAction, PortletConfig portletConfig,
        RenderRequest renderRequest, RenderResponse renderResponse) throws Exception {

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

    long companyId = themeDisplay.getCompanyId();
    long ownerId = themeDisplay.getScopeGroupId();
    int ownerType = PortletKeys.PREFS_OWNER_TYPE_GROUP;
    long plid = PortletKeys.PREFS_PLID_SHARED;
    String portletId = PortletKeys.SHOPPING;

    PortletPreferences preferences = PortletPreferencesLocalServiceUtil.getPreferences(companyId, ownerId,
            ownerType, plid, portletId);

    String paymentType = PrefsParamUtil.getString(preferences, renderRequest, "paymentType");

    String cmd = ParamUtil.getString(renderRequest, Constants.CMD);
    if (cmd.equals(Constants.SAVE) && paymentType.equals("Betop"))
        return "/portlet/shopping/btop_choose_payment_method.jsp";

    return originalStrutsPortletAction.render(originalStrutsPortletAction, portletConfig, renderRequest,
            renderResponse);//  w  ww . j  a va  2  s .  c om
}

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 . j ava2 s  . co 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.journal.content.web.internal.portlet.JournalContentPortlet.java

License:Open Source License

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

    PortletPreferences portletPreferences = renderRequest.getPreferences();

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

    long articleGroupId = PrefsParamUtil.getLong(portletPreferences, renderRequest, "groupId",
            themeDisplay.getScopeGroupId());

    String articleId = PrefsParamUtil.getString(portletPreferences, renderRequest, "articleId");
    String ddmTemplateKey = PrefsParamUtil.getString(portletPreferences, renderRequest, "ddmTemplateKey");

    JournalArticle article = null;//  www.  j a  v  a 2s.c  o m
    JournalArticleDisplay articleDisplay = null;

    if ((articleGroupId > 0) && Validator.isNotNull(articleId)) {
        String viewMode = ParamUtil.getString(renderRequest, "viewMode");
        String languageId = LanguageUtil.getLanguageId(renderRequest);
        int page = ParamUtil.getInteger(renderRequest, "page", 1);

        article = _journalArticleLocalService.fetchLatestArticle(articleGroupId, articleId,
                WorkflowConstants.STATUS_APPROVED);

        try {
            if (article == null) {
                article = _journalArticleLocalService.getLatestArticle(articleGroupId, articleId,
                        WorkflowConstants.STATUS_ANY);
            }

            if (Validator.isNull(ddmTemplateKey)) {
                ddmTemplateKey = article.getDDMTemplateKey();
            }

            articleDisplay = _journalContent.getDisplay(article, ddmTemplateKey, viewMode, languageId, page,
                    new PortletRequestModel(renderRequest, renderResponse), themeDisplay);
        } catch (Exception e) {
            renderRequest.removeAttribute(WebKeys.JOURNAL_ARTICLE);
        }
    }

    if (article != null) {
        renderRequest.setAttribute(WebKeys.JOURNAL_ARTICLE, article);
    }

    if (articleDisplay != null) {
        renderRequest.setAttribute(WebKeys.JOURNAL_ARTICLE_DISPLAY, articleDisplay);
    } else {
        renderRequest.removeAttribute(WebKeys.JOURNAL_ARTICLE_DISPLAY);
    }

    super.doView(renderRequest, renderResponse);
}

From source file:m.omarh.liferay.resources.importer.generator.SitemapGeneratorPortlet.java

License:Open Source License

public void saveResourceImporter(ActionRequest actionRequest, ActionResponse actionResponse) {

    PortletPreferences portletPreferences = actionRequest.getPreferences();

    String resourceImporterURL = PrefsParamUtil.getString(portletPreferences, actionRequest,
            "resourceImporterURL");
    String pluginSourceURL = PrefsParamUtil.getString(portletPreferences, actionRequest, "pluginSourceURL");

    try {//from   ww w.ja  va  2s  . co  m
        portletPreferences.setValue("resourceImporterURL", resourceImporterURL);
        portletPreferences.setValue("pluginSourceURL", pluginSourceURL);

        portletPreferences.store();

    } catch (ReadOnlyException | ValidatorException | IOException e) {
        _log.error(e.getMessage());
    }

    String fullPathResourceImporterURL = AutoDeployUtil.getAutoDeployDestDir() + StringPool.SLASH
            + resourceImporterURL + "/resources-importer/";
    String fullPathPluginSourceURL = pluginSourceURL + "/docroot/WEB-INF/src/resources-importer/";

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

    //writting tree with flag writeFlag set to true
    TreeUtil.buildJSONTree(themeDisplay, true, fullPathResourceImporterURL, fullPathPluginSourceURL);
}