Example usage for com.liferay.portal.kernel.servlet SessionErrors add

List of usage examples for com.liferay.portal.kernel.servlet SessionErrors add

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.servlet SessionErrors add.

Prototype

public static void add(PortletRequest portletRequest, String key) 

Source Link

Usage

From source file:com.inkwell.internet.productregistration.registration.portlet.ProductAdminPortlet.java

License:Open Source License

/**
 * This Action updates an existing product with values that were entered
 * into the edit_product.jsp./*from   w  w w .  j a va2 s  . com*/
 *
 * @param request
 * @param response
 * @throws java.lang.Exception
 */

public void updateProduct(ActionRequest request, ActionResponse response) throws Exception {

    long productKey = ParamUtil.getLong(request, "resourcePrimKey");
    ArrayList<String> errors = new ArrayList();
    if (Validator.isNotNull(productKey)) {
        PRProduct product = PRProductLocalServiceUtil.getPRProduct(productKey);
        PRProduct requestProduct = ActionUtil.productFromRequest(request);

        if (ProdRegValidator.validateProduct(requestProduct, errors)) {
            product.setProductName(requestProduct.getProductName());
            product.setSerialNumber(requestProduct.getSerialNumber());
            PRProductLocalServiceUtil.updatePRProduct(product);
            SessionMessages.add(request, "productUpdated");

        } else {
            for (String error : errors) {
                SessionErrors.add(request, error);

            }

        }

    } else {
        SessionErrors.add(request, "error-updating");
    }

}

From source file:com.inkwell.internet.productregistration.registration.portlet.ProductAdminPortlet.java

License:Open Source License

/**
 * This Action deletes a product from the database.
 *
 * @param request/*from   w  w  w  . j a va 2s. com*/
 * @param response
 * @throws java.lang.Exception
 */
public void deleteProduct(ActionRequest request, ActionResponse response) throws Exception {

    long productKey = ParamUtil.getLong(request, "resourcePrimKey");

    if (Validator.isNotNull(productKey)) {
        PRProductLocalServiceUtil.deleteProduct(productKey);
        SessionMessages.add(request, "productDeleted");
    } else {
        SessionErrors.add(request, "error-deleting");
    }
}

From source file:com.inkwell.internet.productregistration.registration.portlet.ProductRegistrationPortlet.java

License:Open Source License

/**
 * Takes a submitted registration and adds it to the database if it passes
 * validation.//from ww  w . j a v  a 2  s .c  om
 *
 * @param request
 * @param response
 */
public void registerProduct(ActionRequest request, ActionResponse response) throws Exception {

    PRUser regUser = ActionUtil.prUserFromRequest(request);
    PRRegistration registration = ActionUtil.prRegistrationFromRequest(request);
    ArrayList<String> errors = new ArrayList<String>();
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    long userId = themeDisplay.getUserId();

    User liferayUser = UserLocalServiceUtil.getUser(userId);

    boolean userValid = ProdRegValidator.validateUser(regUser, errors);
    boolean regValid = ProdRegValidator.validateRegistration(registration, errors);

    if (userValid && regValid) {
        // TODO: Logic needs to change here for multiple registrations and
        // to check for logged-in users
        PRUser user = null;

        // check to see if user is a guest
        if (liferayUser.isDefaultUser()) {
            userId = 0;
            user = PRUserLocalServiceUtil.addPRUser(regUser, userId);
        } else {
            // Check to see if we have a PR User from the Liferay user ID
            user = PRUserLocalServiceUtil.getPRUser(themeDisplay.getScopeGroupId(), userId);

            if (user == null) {
                // Create a new mapping
                regUser.setUserId(userId);
                user = PRUserLocalServiceUtil.addPRUser(regUser, userId);
            }
        }

        registration.setPrUserId(user.getPrUserId());
        PRRegistrationLocalServiceUtil.addRegistration(registration);
        SessionMessages.add(request, "registration-saved-successfully");
        response.setRenderParameter("jspPage", viewThankYouJSP);
    } else {
        for (String error : errors) {
            SessionErrors.add(request, error);
        }
        SessionErrors.add(request, "error-saving-registration");
        response.setRenderParameter("jspPage", viewAddRegistrationJSP);
        request.setAttribute("regUser", regUser);
        request.setAttribute("registration", registration);
    }
}

From source file:com.inkwell.internet.slogan.actions.DeleteSloganActionCommand.java

License:Open Source License

public boolean processCommand(PortletRequest request, PortletResponse response) throws PortletException {

    long sloganKey = ParamUtil.getLong(request, "resourcePrimKey");

    if (Validator.isNotNull(sloganKey)) {
        try {/* w ww  .  j  a  va2  s.  co m*/
            SloganLocalServiceUtil.deleteSlogan(sloganKey);
        } catch (PortalException e) {
            SessionErrors.add(request, "error-deleting");
            return false;
        } catch (SystemException e) {
            SessionErrors.add(request, "error-deleting");
            return false;
        }
        SessionMessages.add(request, "slogan-deleted");
        return true;
    } else {
        SessionErrors.add(request, "error-deleting");
        return false;
    }
}

From source file:com.inkwell.internet.slogan.portlet.SloganContest.java

License:Open Source License

/**
 * Called when a user is either adding or updating a statement. If the
 * primary key is greater than 0, an update is performed, because there's an
 * existing key. Otherwise, an add is performed.
 *
 * @param request//from w ww.ja v  a 2s. c  o m
 * @param response
 * @throws SystemException
 * @throws PortalException
 */
public void updateSlogan(ActionRequest request, ActionResponse response)
        throws PortalException, SystemException {

    Slogan slogan = ActionUtil.sloganFromRequest(request);

    ArrayList<String> errors = new ArrayList<String>();
    ServiceContext serviceContext = ServiceContextFactory.getInstance(Slogan.class.getName(), request);

    if (SloganValidator.validateSlogan(slogan, errors)) {
        if (slogan.getSloganId() > 0) {
            // Updating

            try {
                Slogan fromDB = SloganLocalServiceUtil.getSlogan(slogan.getSloganId());

                if (fromDB != null && (slogan.getSloganId() == fromDB.getSloganId())) {

                    fromDB = SloganLocalServiceUtil.updateSlogan(slogan, false);

                    SessionMessages.add(request, "slogan-added");
                }
            } catch (PortalException e) {
                errors.add("failed-to-update");
            } catch (SystemException e) {
                errors.add("failed-to-update");
            }
        } else {
            // Adding

            try {
                SloganLocalServiceUtil.addSlogan(slogan, slogan.getUserId(), serviceContext);

            } catch (SystemException e) {
                errors.add("failed-to-add");
            } catch (PortalException e) {
                errors.add("failed-to-add");
            }
        }

        // response.setRenderParameter("jspPage", "/html/view.jsp");
    } else {
        for (String error : errors) {
            SessionErrors.add(request, error);
        }

        request.setAttribute(WebKeys.SLOGAN_ENTRY, slogan);
        response.setRenderParameter("jspPage", "/html/edit_slogan.jsp");
    }
}

From source file:com.inkwell.internet.slogan.portlet.SloganContest.java

License:Open Source License

/**
 * Deletes the slogan from the database.
 *
 * @param request/* w w w  . j a v  a 2  s. c  o  m*/
 * @param response
 */
public void deleteSlogan(ActionRequest request, ActionResponse response) throws Exception {

    long sloganKey = ParamUtil.getLong(request, "resourcePrimKey");

    if (Validator.isNotNull(sloganKey)) {
        SloganLocalServiceUtil.deleteSlogan(sloganKey);
        SessionMessages.add(request, "slogan-deleted");
    } else {
        SessionErrors.add(request, "error-deleting");

    }
}

From source file:com.inkwell.internet.slogan.portlet.SloganContest.java

License:Open Source License

public void render(RenderRequest renderRequest, RenderResponse renderResponse)
        throws PortletException, IOException {
    try {/*from w  w w  . java2 s  .  c o  m*/
        Slogan slogan = null;

        long resourcePrimKey = ParamUtil.getLong(renderRequest, "resourcePrimKey");

        if (resourcePrimKey > 0) {
            slogan = SloganLocalServiceUtil.getSlogan(resourcePrimKey);
        } else {
            slogan = new SloganImpl();
        }

        renderRequest.setAttribute(WebKeys.SLOGAN_ENTRY, slogan);
    } catch (Exception e) {
        if (e instanceof NoSuchSloganException) {
            SessionErrors.add(renderRequest, e.getClass().getName());
        } else {
            throw new PortletException(e);
        }
    }

    super.render(renderRequest, renderResponse);
}

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 {//  ww  w .ja v  a  2  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.knowarth.portlets.themepersonalizer.ThemePersonalizerAdminPortlet.java

License:Open Source License

@ProcessAction(name = "saveAvailableThemes")
public void saveAction(ActionRequest request, ActionResponse response) {
    try {/*from  w w  w.j a v  a  2s  .c o  m*/
        ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

        String themesIdsString = ParamUtil.getString(request, "selectedThemeIds");

        AvailablePersonalizedThemeLocalServiceUtil.removeAllByCompanyId(themeDisplay.getCompanyId());

        if (Validator.isNotNull(themesIdsString)) {
            String[] themeIds = themesIdsString.split(",");
            for (String themeId : themeIds) {
                AvailablePersonalizedThemeLocalServiceUtil
                        .addAvailablePersonalizedTheme(themeDisplay.getCompanyId(), themeId);
            }
        }
        SessionMessages.add(request, "available-theme-changes-saved-successfully");
    } catch (SystemException e) {
        SessionErrors.add(request, "system-error-please-contact-adminstrator");
        _log.error("Error persisting available theme information", e);
    }
}

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

License:Open Source License

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

    try {/* ww  w.j  a  v a 2s  .com*/
        ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);

        if (!themeDisplay.isSignedIn()) {
            renderRequest.setAttribute(WebKeys.PORTLET_CONFIGURATOR_VISIBILITY, Boolean.FALSE);
        } else {
            Map<String, String> availableThemesMap = retrieveAvailableThemesMap(themeDisplay.getCompanyId());
            Layout layout = themeDisplay.getLayout();
            UserPersonalizedTheme userPersonalTheme = UserPersonalizedThemeLocalServiceUtil
                    .findByUserIDAndLayoutId(themeDisplay.getCompanyId(), themeDisplay.getUserId(),
                            layout.getLayoutId());
            if (Validator.isNotNull(userPersonalTheme)) {
                setPersonalizedThemeParams(renderRequest, themeDisplay.getCompanyId(), availableThemesMap,
                        userPersonalTheme);
            } else {
                setDefaults(renderRequest, themeDisplay.getCompanyId(), availableThemesMap);
            }

        }

    } catch (SystemException e) {
        SessionErrors.add(renderRequest, "system-error-please-contact-adminstrator");
        _log.error("Error retrieving personalized theme information", e);
    }
    include(viewJSP, renderRequest, renderResponse);

}