List of usage examples for com.liferay.portal.kernel.servlet SessionErrors add
public static void add(PortletRequest portletRequest, String key)
From source file:com.beorn.onlinepayment.portlet.AdminPortlet.java
License:Open Source License
public void editRule(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException { try {// w ww . ja v a2 s . c o m ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); long ruleId = ParamUtil.getLong(actionRequest, "ruleId"); long paymentPluginConfigId = ParamUtil.getLong(actionRequest, "paymentPluginConfigId"); String content = ParamUtil.getString(actionRequest, "content"); PaymentPluginConfigPermission.check(permissionChecker, paymentPluginConfigId, ActionKeys.UPDATE); ServiceContext serviceContext = ServiceContextFactory.getInstance(Rule.class.getName(), actionRequest); Rule rule; if (ruleId == 0) { rule = RuleLocalServiceUtil.addRule(themeDisplay.getUserId(), paymentPluginConfigId, content, 0, serviceContext); } else { // Check that the user can update the previous config rule = RuleLocalServiceUtil.getRule(ruleId); PaymentPluginConfigPermission.check(permissionChecker, rule.getPaymentPluginConfigId(), ActionKeys.UPDATE); rule = RuleLocalServiceUtil.updateRule(ruleId, paymentPluginConfigId, content, rule.getPriority(), serviceContext); } String redirect = ParamUtil.getString(actionRequest, "successURL"); redirect = HttpUtil.setParameter(redirect, "_1_WAR_onlinepaymentportlet_ruleId", rule.getRuleId()); actionResponse.sendRedirect(redirect); SessionMessages.add(actionRequest, "edit-rule.success"); } catch (Exception e) { _log.error(e); actionResponse.setRenderParameters(actionRequest.getParameterMap()); SessionErrors.add(actionRequest, e.getClass().getName()); } }
From source file:com.beorn.onlinepayment.portlet.AdminPortlet.java
License:Open Source License
public void deleteRule(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException { try {/*from w w w .j a v a 2s . c o m*/ ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); long ruleId = ParamUtil.getLong(actionRequest, "ruleId"); Rule rule = RuleLocalServiceUtil.getRule(ruleId); PaymentPluginConfigPermission.check(permissionChecker, rule.getPaymentPluginConfigId(), ActionKeys.UPDATE); RuleLocalServiceUtil.deleteRule(rule); String redirect = ParamUtil.getString(actionRequest, "successURL"); actionResponse.sendRedirect(redirect); SessionMessages.add(actionRequest, "delete-rule.success"); } catch (Exception e) { _log.error(e); actionResponse.setRenderParameters(actionRequest.getParameterMap()); SessionErrors.add(actionRequest, e.getClass().getName()); } }
From source file:com.beorn.onlinepayment.portlet.AdminPortlet.java
License:Open Source License
public void editPlugin(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException { try {//from ww w . ja v a 2s .c o m ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); HttpServletRequest httpServletRequest = PortalUtil.getHttpServletRequest(actionRequest); ServletContext servletContext = httpServletRequest.getSession().getServletContext(); long paymentPluginId = ParamUtil.getLong(actionRequest, "pluginId"); PaymentPluginPermission.check(permissionChecker, paymentPluginId, ActionKeys.UPDATE); Map<Locale, String> nameMap = LocalizationUtil.getLocalizationMap(actionRequest, "name"); PaymentPlugin paymentPlugin = PaymentPluginLocalServiceUtil.getPaymentPlugin(paymentPluginId); String pluginConfig = ConfigUtil .getConfig(actionRequest, ConfigDescriptionUtil.parseConfigDescription(paymentPlugin.getPluginConfigParameters())) .toString(); if (Validator.isNull(nameMap) && nameMap.isEmpty()) SessionErrors.add(actionRequest, "name-required"); if (Validator.isNotNull(paymentPlugin.getPluginConfigParameters()) && !isConfigValid(servletContext, paymentPlugin, pluginConfig, false)) SessionErrors.add(actionRequest, "invalid-config"); if (!SessionErrors.isEmpty(actionRequest)) { actionResponse.setRenderParameters(actionRequest.getParameterMap()); return; } ServiceContext serviceContext = ServiceContextFactory.getInstance(PaymentPlugin.class.getName(), actionRequest); paymentPlugin = PaymentPluginLocalServiceUtil.updatePaymentPlugin(paymentPluginId, paymentPlugin.getApplicationId(), nameMap, null, null, pluginConfig, true, serviceContext); String redirect = ParamUtil.getString(actionRequest, "successURL"); actionResponse.sendRedirect(redirect); SessionMessages.add(actionRequest, "edit-plugin.success"); } catch (Exception e) { _log.error(e); actionResponse.setRenderParameters(actionRequest.getParameterMap()); SessionErrors.add(actionRequest, e.getClass().getName()); } }
From source file:com.beorn.onlinepayment.portlet.AdminPortlet.java
License:Open Source License
public void editSellerPlugin(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException { try {// w ww . j a v a 2 s .c o m ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); HttpServletRequest httpServletRequest = PortalUtil.getHttpServletRequest(actionRequest); ServletContext servletContext = httpServletRequest.getSession().getServletContext(); long pluginConfigId = ParamUtil.getLong(actionRequest, "pluginConfigId"); PaymentPluginConfigPermission.check(permissionChecker, pluginConfigId, ActionKeys.UPDATE); PaymentPluginConfig pluginConfig = PaymentPluginConfigLocalServiceUtil .getPaymentPluginConfig(pluginConfigId); PaymentPlugin paymentPlugin = PaymentPluginLocalServiceUtil .getPaymentPlugin(pluginConfig.getPaymentPluginId()); String config = ConfigUtil .getConfig(actionRequest, ConfigDescriptionUtil.parseConfigDescription(paymentPlugin.getSellerConfigParameters())) .toString(); if (Validator.isNotNull(paymentPlugin.getSellerConfigParameters())) { if (!isConfigValid(servletContext, paymentPlugin, config, true)) SessionErrors.add(actionRequest, "invalid-config"); } else { config = StringPool.BLANK; } if (!SessionErrors.isEmpty(actionRequest)) { actionResponse.setRenderParameters(actionRequest.getParameterMap()); return; } ServiceContext serviceContext = ServiceContextFactory.getInstance(PaymentPluginConfig.class.getName(), actionRequest); pluginConfig = PaymentPluginConfigLocalServiceUtil.updatePaymentPluginConfig(pluginConfigId, pluginConfig.getSellerId(), pluginConfig.getPaymentPluginId(), config, true, serviceContext); String redirect = ParamUtil.getString(actionRequest, "successURL"); actionResponse.sendRedirect(redirect); SessionMessages.add(actionRequest, "edit-seller-plugin.success"); } catch (Exception e) { _log.error(e); actionResponse.setRenderParameters(actionRequest.getParameterMap()); SessionErrors.add(actionRequest, e.getClass().getName()); } }
From source file:com.beorn.onlinepayment.portlet.AdminPortlet.java
License:Open Source License
public void editMethod(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException { try {/*from w w w.j a v a 2s .c om*/ ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); long paymentMethodId = ParamUtil.getLong(actionRequest, "methodId"); PaymentMethodPermission.check(permissionChecker, paymentMethodId, ActionKeys.UPDATE); Map<Locale, String> nameMap = LocalizationUtil.getLocalizationMap(actionRequest, "name"); if (Validator.isNull(nameMap) && nameMap.isEmpty()) SessionErrors.add(actionRequest, "name-required"); if (!SessionErrors.isEmpty(actionRequest)) { actionResponse.setRenderParameters(actionRequest.getParameterMap()); return; } ServiceContext serviceContext = ServiceContextFactory.getInstance(Seller.class.getName(), actionRequest); PaymentMethod paymentMethod = PaymentMethodLocalServiceUtil.getPaymentMethod(paymentMethodId); paymentMethod = PaymentMethodLocalServiceUtil.updatePaymentMethod(paymentMethodId, paymentMethod.getKey(), nameMap, serviceContext); String redirect = ParamUtil.getString(actionRequest, "successURL"); actionResponse.sendRedirect(redirect); SessionMessages.add(actionRequest, "edit-method.success"); } catch (Exception e) { _log.error(e); actionResponse.setRenderParameters(actionRequest.getParameterMap()); SessionErrors.add(actionRequest, e.getClass().getName()); } }
From source file:com.beorn.onlinepayment.portlet.AdminPortlet.java
License:Open Source License
public void associatePluginSellers(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException { try {/*from w ww.ja v a2s . c om*/ ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); long pluginId = ParamUtil.getLong(actionRequest, "pluginId"); PaymentAppPermission.check(permissionChecker, themeDisplay.getScopeGroupId(), ActionKeys.ADD_PAYMENT_PLUGIN_CONFIG); ServiceContext serviceContext = ServiceContextFactory.getInstance(PaymentPluginConfig.class.getName(), actionRequest); List<Seller> sellers = SellerServiceUtil.search(themeDisplay.getCompanyId(), null, true, QueryUtil.ALL_POS, QueryUtil.ALL_POS, new SellerCreateDateComparator()); for (Seller seller : sellers) { String paramName = "seller_" + seller.getSellerId(); boolean sellerEnabled = ParamUtil.getBoolean(actionRequest, paramName); boolean sellerWasEnabled = PaymentPluginConfigLocalServiceUtil .hasPaymentPluginConfigBySellerIdAndPaymentPluginId(seller.getSellerId(), pluginId); if (!sellerWasEnabled && sellerEnabled) { PaymentPluginConfigLocalServiceUtil.addPaymentPluginConfig(seller.getUserId(), seller.getSellerId(), pluginId, serviceContext); } else if (sellerWasEnabled && !sellerEnabled) { PaymentPluginConfig paymentPluginConfig = PaymentPluginConfigLocalServiceUtil .getPaymentPluginConfigBySellerIdAndPaymentPluginId(seller.getSellerId(), pluginId); PaymentPluginConfigLocalServiceUtil.deletePaymentPluginConfig(paymentPluginConfig); } } String redirect = ParamUtil.getString(actionRequest, "successURL"); actionResponse.sendRedirect(redirect); SessionMessages.add(actionRequest, "associate-plugin-sellers.success"); } catch (Exception e) { _log.error(e); actionResponse.setRenderParameters(actionRequest.getParameterMap()); SessionErrors.add(actionRequest, e.getClass().getName()); } }
From source file:com.beorn.onlinepayment.portlet.AdminPortlet.java
License:Open Source License
public void associateSellerPlugins(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException { try {/*from w w w. j av a 2s . c o m*/ ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); long sellerId = ParamUtil.getLong(actionRequest, "sellerId"); PaymentAppPermission.check(permissionChecker, themeDisplay.getScopeGroupId(), ActionKeys.ADD_PAYMENT_PLUGIN_CONFIG); Seller seller = SellerLocalServiceUtil.getSeller(sellerId); ServiceContext serviceContext = ServiceContextFactory.getInstance(PaymentPluginConfig.class.getName(), actionRequest); List<PaymentPlugin> paymentPlugins = PaymentPluginServiceUtil.search(themeDisplay.getCompanyId(), null, null, null, QueryUtil.ALL_POS, QueryUtil.ALL_POS, new PaymentPluginCreateDateComparator()); for (PaymentPlugin paymentPlugin : paymentPlugins) { String paramName = "paymentPlugin_" + paymentPlugin.getPaymentPluginId(); boolean paymentPluginEnabled = ParamUtil.getBoolean(actionRequest, paramName); boolean paymentPluginWasEnabled = PaymentPluginConfigLocalServiceUtil .hasPaymentPluginConfigBySellerIdAndPaymentPluginId(sellerId, paymentPlugin.getPaymentPluginId()); if (!paymentPluginWasEnabled && paymentPluginEnabled) { PaymentPluginConfigLocalServiceUtil.addPaymentPluginConfig(seller.getUserId(), sellerId, paymentPlugin.getPaymentPluginId(), serviceContext); } else if (paymentPluginWasEnabled && !paymentPluginEnabled) { PaymentPluginConfig paymentPluginConfig = PaymentPluginConfigLocalServiceUtil .getPaymentPluginConfigBySellerIdAndPaymentPluginId(sellerId, paymentPlugin.getPaymentPluginId()); PaymentPluginConfigLocalServiceUtil.deletePaymentPluginConfig(paymentPluginConfig); } } String redirect = ParamUtil.getString(actionRequest, "successURL"); actionResponse.sendRedirect(redirect); SessionMessages.add(actionRequest, "associate-seller-plugins.success"); } catch (Exception e) { _log.error(e); actionResponse.setRenderParameters(actionRequest.getParameterMap()); SessionErrors.add(actionRequest, e.getClass().getName()); } }
From source file:com.beorn.onlinepayment.portlet.AdminPortlet.java
License:Open Source License
public void editRulesPriority(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException { try {/*from www .j a v a 2s. c om*/ ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); long sellerId = ParamUtil.getLong(actionRequest, "sellerId"); SellerPermission.check(permissionChecker, sellerId, ActionKeys.UPDATE); ServiceContext serviceContext = ServiceContextFactory.getInstance(Rule.class.getName(), actionRequest); for (Rule rule : RuleLocalServiceUtil.getSellerRules(sellerId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) { int priority = ParamUtil.getInteger(actionRequest, "rulePriority_" + rule.getRuleId()); RuleLocalServiceUtil.updateRule(rule.getRuleId(), rule.getPaymentPluginConfigId(), rule.getContent(), priority, serviceContext); } SessionMessages.add(actionRequest, "edit-rules-priority.success"); } catch (Exception e) { _log.error(e); actionResponse.setRenderParameters(actionRequest.getParameterMap()); SessionErrors.add(actionRequest, e.getClass().getName()); } }
From source file:com.beorn.onlinepayment.portlet.AdminPortlet.java
License:Open Source License
public void editDefaultPluginConfig(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException { try {/*from w w w . j av a2 s . c o m*/ ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); long sellerId = ParamUtil.getLong(actionRequest, "sellerId"); long defaultPaymentPluginConfigId = ParamUtil.getLong(actionRequest, "defaultPaymentPluginConfigId"); SellerPermission.check(permissionChecker, sellerId, ActionKeys.UPDATE); PaymentPluginConfigLocalServiceUtil.updateDefaultPluginConfig(sellerId, defaultPaymentPluginConfigId); SessionMessages.add(actionRequest, "edit-default-plugin-config.success"); } catch (Exception e) { _log.error(e); actionResponse.setRenderParameters(actionRequest.getParameterMap()); SessionErrors.add(actionRequest, e.getClass().getName()); } }
From source file:com.commsen.liferay.portlet.customglobalmarkup.CustomGlobalMarkupConfigurationPortlet.java
License:Open Source License
@ProcessAction(name = "save") public void saveMarkups(ActionRequest request, ActionResponse response) throws SystemException, PortalException { List<String> paramNames = Collections.list(request.getParameterNames()); long max_markup_length = 2000; Map<String, String> markup_hints = ModelHintsUtil.getHints(Markup.class.getName(), "markup"); if (markup_hints.containsKey("max-length")) { try {/*from ww w . j a v a2s . c o m*/ max_markup_length = Long.parseLong(markup_hints.get("max-length")); } catch (NumberFormatException e) { _log.warn("Failed to parse max-length!", e); } } for (String key : paramNames) { if (key.startsWith("markup_")) { long id = Long.parseLong(key.substring(7)); Markup markup = MarkupLocalServiceUtil.getMarkup(id); if (markup != null) { if (ParamUtil.getBoolean(request, "delete_" + id)) { MarkupLocalServiceUtil.deleteMarkup(markup); } else { boolean changed = false; boolean error = false; // process text String markupText = ParamUtil.getString(request, key, ""); if (markupText.length() > max_markup_length) { error = true; SessionErrors.add(request, "custom-global-markup-error-too-long-" + id); } if (!markup.getMarkup().equals(markupText)) { changed = true; markup.setMarkup(markupText); } // process status boolean markupStatus = ParamUtil.getBoolean(request, "active_" + id); if (markup.getActive() != markupStatus) { changed = true; markup.setActive(markupStatus); } // process location short location = ParamUtil.getShort(request, "location_" + id, (short) -1); if (CustomGlobalMarkupLocation.isValid(location) && markup.getLocation() != location) { changed = true; markup.setLocation(location); } // finally if there are any changes update database if (error) { rememberMarkupInSession(request, markup); } else if (changed) { SessionMessages.add(request, "custom-global-markup-save-ok-" + id); MarkupLocalServiceUtil.updateMarkup(markup); } } } else { _log.warn("Markup with id " + id + " not found!"); } } } redirect(request, response); }