Example usage for com.liferay.portal.kernel.theme ThemeDisplay isSignedIn

List of usage examples for com.liferay.portal.kernel.theme ThemeDisplay isSignedIn

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.theme ThemeDisplay isSignedIn.

Prototype

public boolean isSignedIn() 

Source Link

Usage

From source file:com.liferay.salesforce.portlet.SalesforceOpportunityPortlet.java

License:Apache License

public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws IOException, PortletException {
    HttpServletResponse response = PortalUtil.getHttpServletResponse(resourceResponse);
    ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);
    response.setContentType("text");
    String requestMethod = ParamUtil.getString(resourceRequest, "type");

    resourceResponse.setContentType("text/javascript");
    String username = getUsername(resourceRequest);
    try {//from   w  w w  .j ava  2 s.c o  m
        if (themeDisplay.isSignedIn() && (requestMethod != null) && requestMethod.equals("opps")
                && username != null) {
            MessageBatch messageBatch = SalesforceOpportunityLocalServiceUtil.getOpportunitiesByUserName(
                    PortalUtil.getDefaultCompanyId(), username, Arrays.asList(FIELD_NAMES),
                    PortalUtil.getUserId(resourceRequest));
            response.getWriter().print(MessageBatchConverter.getJSONString(messageBatch));

            response.flushBuffer();
        } else if (themeDisplay.isSignedIn() && (requestMethod != null)
                && requestMethod.equals("accountDetails") && username != null) {

            String accountName = resourceRequest.getParameter("accountNm");

            MessageBatch messageBatch = SalesforceAccountLocalServiceUtil.getAccountsByName(
                    PortalUtil.getDefaultCompanyId(), accountName, Arrays.asList(DETAIL_FIELD_NAMES),
                    PortalUtil.getUserId(resourceRequest));
            response.getWriter().print(MessageBatchConverter.getPivotedJSONString(messageBatch));
            response.flushBuffer();
        } else {
            response.getWriter().print("");
            response.flushBuffer();
        }
    } catch (SystemException e) {
        e.printStackTrace();
        throw new PortletException("Unable to process request", e);
    }
}

From source file:com.liferay.trash.web.internal.portlet.TrashViewPortletProvider.java

License:Open Source License

@Override
public PortletURL getPortletURL(HttpServletRequest request) throws PortalException {

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

    String portletId = PortletProviderUtil.getPortletId(TrashEntry.class.getName(),
            PortletProvider.Action.VIEW);

    if (!themeDisplay.isSignedIn() || !_trashHelper.isTrashEnabled(themeDisplay.getScopeGroupId())
            || !PortletPermissionUtil.hasControlPanelAccessPermission(themeDisplay.getPermissionChecker(),
                    themeDisplay.getScopeGroupId(), portletId)) {

        return null;
    }/*from   w w w . j  a  v a  2s .  co m*/

    PortletURL portletURL = _portal.getControlPanelPortletURL(request, portletId, PortletRequest.RENDER_PHASE);

    portletURL.setParameter("redirect", themeDisplay.getURLCurrent());

    return portletURL;
}

From source file:com.slemarchand.quick.sign.up.web.portlet.QuickSignUpPortlet.java

License:Open Source License

@Override
public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
        throws IOException, PortletException {

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

    String password = ParamUtil.getString(actionRequest, "password");

    User user = null;// ww w .j av a2  s .com

    try {
        user = addUser(actionRequest, actionResponse, password);
    } catch (UserEmailAddressException | UserScreenNameException | ContactNameException | EmailAddressException
            | GroupFriendlyURLException | RequiredFieldException | RequiredUserException | UserIdException
            | UserPasswordException e) {
        SessionErrors.add(actionRequest, e.getClass(), e);
    } catch (SystemException | PortalException e) {
        throw new PortletException(e);
    }

    if (user != null && !themeDisplay.isSignedIn()) {
        try {
            String redirect = getSuccessRedirect(actionRequest, actionResponse);

            login(themeDisplay, actionRequest, actionResponse, user, password, redirect);

        } catch (Exception e) {
            throw new PortletException(e);
        }
    }
}

From source file:se.vgregion.portal.innovationsslussen.createidea.controller.CreateIdeaViewController.java

License:Open Source License

/**
 * The default render method.//from ww  w .  j  a  v  a2  s  .co m
 *
 * @param request  the request
 * @param response the response
 * @param model    the model
 * @param idea     the idea
 * @param result   the binding results
 * @return the view
 */
@RenderMapping()
public String createIdea(RenderRequest request, RenderResponse response, final ModelMap model,
        @ModelAttribute Idea idea, BindingResult result) {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    long scopeGroupId = themeDisplay.getScopeGroupId();
    long userId = themeDisplay.getUserId();
    boolean isSignedIn = themeDisplay.isSignedIn();

    if (model.get("errors") == null) {

        // No idea exists
        idea = IdeaPortletUtil.getIdeaFromRequest(request);

        // Set dummy data for person
        if (idea.getIdeaPerson().getName().equals("")) {

            String screenName = "";
            String otherUserVgrId = (String) model.get("otherUserVgrId");
            if (otherUserVgrId != null) {
                if (!otherUserVgrId.equals("")) {
                    screenName = otherUserVgrId;

                }
            } else {
                screenName = themeDisplay.getUser().getScreenName();
            }

            IdeaPerson ideaPerson = idea.getIdeaPerson();
            AdPerson adCriteria = new AdPerson();
            adCriteria.setCn(screenName);
            List<AdPerson> findings = ldapService.find(adCriteria);
            if (findings.size() == 1) {
                AdPerson person = findings.get(0);
                ideaPerson.setEmail(person.getMail());
                ideaPerson.setJobPosition(person.getTitle());
                ideaPerson.setName(person.getDisplayName());
                ideaPerson.setAdministrativeUnit(person.getDivision());
                ideaPerson.setPhoneMobile(person.getMobile());
                ideaPerson.setPhone(person.getTelephoneNumber());
                ideaPerson.setVgrId(person.getCn());
                ideaPerson.setName(person.getDisplayName());
                model.addAttribute("otherUserVgrId", idea.getIdeaPerson().getVgrId());
            }

            populateValuesFromKiv(screenName, ideaPerson);
        }
    } else {
        // Copy binding error from save action
        result.addAllErrors((BindingResult) model.get("errors"));

        if (idea.getIdeaPerson() != null) {
            String vgrId = idea.getIdeaPerson().getVgrId();

            if (vgrId != null && !vgrId.isEmpty()) {
                model.addAttribute("otherUserVgrId", vgrId);
            }
        }
    }

    IdeaPermissionChecker ideaPermissionChecker = ideaPermissionCheckerService
            .getIdeaPermissionChecker(scopeGroupId, userId, idea);

    model.addAttribute("isSignedIn", isSignedIn);
    model.addAttribute("idea", idea);
    model.addAttribute("ideaClass", Idea.class);
    model.addAttribute("ideaPermissionChecker", ideaPermissionChecker);

    return "view";
}

From source file:se.vgregion.portal.innovationsslussen.idea.controller.IdeaViewController.java

License:Open Source License

/**
 * The default render method./*from  w w w.j  a v  a2  s  .  c om*/
 *
 * @param request  the request
 * @param response the response
 * @param model    the model
 * @return the view
 */
@RenderMapping()
public String showIdea(RenderRequest request, RenderResponse response, final ModelMap model)
        throws PortalException, SystemException {

    ThemeDisplay themeDisplay = getThemeDisplay(request);
    String ideaType = ParamUtil.getString(request, "type", "public");

    String returnView = "view_public";

    //If a user trying to accsess the private part of an idea when not sign in.
    if (ideaType.equals("private") && !themeDisplay.isSignedIn()) {
        returnView = "idea_not_sign_in";
    } else {

        long scopeGroupId = themeDisplay.getScopeGroupId();
        long companyId = themeDisplay.getCompanyId();
        long userId = themeDisplay.getUserId();
        boolean isSignedIn = themeDisplay.isSignedIn();
        String urlTitle = ParamUtil.getString(request, "urlTitle", "");

        Layout ideaLayout = getFriendlyURLLayout(scopeGroupId, themeDisplay.getLayout().isPrivateLayout());
        long ideaPlid = ideaLayout.getPlid();
        model.addAttribute("ideaPlid", ideaPlid);

        int maxCommentCountDisplay = ParamUtil.getInteger(request, "maxCommentCountDisplay",
                defaultCommentCount);
        boolean moreComments = ParamUtil.getString(request, "moreComments") != null;
        if (moreComments) {
            maxCommentCountDisplay += defaultCommentCount;
        }

        if (!urlTitle.equals("")) {
            Idea idea = ideaService.findIdeaByUrlTitle(urlTitle);
            if (idea != null) {

                boolean isIdeaUserLiked = ideaService.getIsIdeaUserLiked(companyId, scopeGroupId, userId,
                        urlTitle);
                boolean isIdeaUserFavorite = ideaService.getIsIdeaUserFavorite(companyId, scopeGroupId, userId,
                        urlTitle);

                List<CommentItemVO> commentsList = null;

                if (ideaType.equals("private")) {
                    commentsList = ideaService.getPrivateComments(idea);
                } else {
                    commentsList = ideaService.getPublicComments(idea);
                }

                if (idea.getIdeaContentPrivate() != null) {
                    String ideTansportor = idea.getIdeaContentPrivate().getIdeTansportor();
                    if (ideTansportor != null && !ideTansportor.isEmpty()) {
                        model.addAttribute("tansportor", ideTansportor);
                    }
                }

                IdeaPermissionChecker ideaPermissionChecker = ideaPermissionCheckerService
                        .getIdeaPermissionChecker(scopeGroupId, userId, idea);

                model.addAttribute("commentCount", commentsList.size());
                commentsList = commentsList.subList(0, Math.min(maxCommentCountDisplay, commentsList.size()));

                idea = IdeaPortletUtil.replaceBreaklines(idea);

                model.addAttribute("idea", idea);
                model.addAttribute("commentsList", commentsList);
                model.addAttribute("commentsDelta", 1);
                model.addAttribute("isIdeaUserFavorite", isIdeaUserFavorite);
                model.addAttribute("isIdeaUserLiked", isIdeaUserLiked);
                model.addAttribute("urlTitle", urlTitle);
                model.addAttribute("userId", userId);

                model.addAttribute("isSignedIn", isSignedIn);
                model.addAttribute("ideaPermissionChecker", ideaPermissionChecker);

                model.addAttribute("ideaType", ideaType);

                model.addAttribute("maxCommentCountDisplay", maxCommentCountDisplay);
                model.addAttribute("defaultCommentCount", defaultCommentCount);

                model.addAttribute("ideaPortletName", IdeaPortletsConstants.PORTLET_NAME_IDEA_PORTLET);

                model.addAttribute("bariumUrl", bariumUrl);

                if (ideaType.equals("private") && (ideaPermissionChecker.getHasPermissionViewIdeaPrivate()
                        || idea.getUserId() == userId)) {
                    returnView = "view_private";
                }

                // If a user trying to access the public or private part of an idea that still is private.
                // The user dose not have premmisions and is not the creator of the idea.
                // Showing 404 view.
                if (!idea.isPublic() && !(ideaPermissionChecker.getHasPermissionViewIdeaPrivate()
                        || idea.getUserId() == userId)) {
                    HttpServletResponse httpServletResponse = PortalUtil.getHttpServletResponse(response);
                    httpServletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
                    returnView = "idea_404";
                }
            } else {
                HttpServletResponse httpServletResponse = getHttpServletResponse(response);
                httpServletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
                returnView = "idea_404";
            }
        }
    }
    return returnView;
}

From source file:se.vgregion.portal.innovationsslussen.idea.controller.IdeaViewController.java

License:Open Source License

private boolean isAllowedToDoAction(PortletRequest request, Idea idea, Action action,
        IdeaContentType ideaContentType) {
    // Initialize variables
    ThemeDisplay themeDisplay = getThemeDisplay(request);
    long userId = themeDisplay.getUserId();
    long groupId = themeDisplay.getScopeGroupId();

    IdeaPermissionChecker ideaPermissionChecker = ideaPermissionCheckerService.getIdeaPermissionChecker(groupId,
            userId, idea);/*from  ww  w  . j  av a2 s.c  om*/

    // Then check for necessary permissions.
    boolean publicAndPublicPermission;
    boolean privateAndPrivatePermission;
    boolean isSignedIn;
    boolean publicPart;

    if (ideaContentType.equals(IdeaContentType.IDEA_CONTENT_TYPE_PUBLIC)) {
        publicPart = true;
    } else if (ideaContentType.equals(IdeaContentType.IDEA_CONTENT_TYPE_PRIVATE)) {
        publicPart = false;
    } else {
        throw new IllegalArgumentException("Unexpected IdeaContentType.");
    }

    switch (action) {
    case ADD_COMMENT:
        isSignedIn = themeDisplay.isSignedIn();
        if (!isSignedIn) {
            return false;
        }
        if (idea.getUserId() == userId) {
            return true;
        }
        publicAndPublicPermission = publicPart && ideaPermissionChecker.getHasPermissionAddCommentPublic();
        privateAndPrivatePermission = !publicPart && ideaPermissionChecker.getHasPermissionAddCommentPrivate();
        break;
    case UPLOAD_FILE:
        isSignedIn = themeDisplay.isSignedIn();
        if (!isSignedIn) {
            return false;
        }

        publicAndPublicPermission = publicPart && ideaPermissionChecker.getHasPermissionAddCommentPublic();
        privateAndPrivatePermission = !publicPart && ideaPermissionChecker.getHasPermissionAddCommentPrivate();
        break;
    case VIEW_IDEA:
        publicAndPublicPermission = publicPart && ideaPermissionChecker.getHasPermissionViewIdeaPublic();
        privateAndPrivatePermission = !publicPart && ideaPermissionChecker.getHasPermissionViewIdeaPrivate();
        break;
    default:
        throw new IllegalArgumentException("Unexpected action: " + action);
    }

    boolean necessaryPermissions = publicAndPublicPermission || privateAndPrivatePermission;

    return necessaryPermissions;
}

From source file:se.vgregion.portal.innovationsslussen.idea.controller.IdeaViewController.java

License:Open Source License

/**
 * Method handling Action request./* ww  w . ja  va 2  s  . c o  m*/
 *
 * @param request  the request
 * @param response the response
 * @param model    the model
 */
@ActionMapping(params = "action=addFavorite")
public final void addFavorite(ActionRequest request, ActionResponse response, final ModelMap model) {

    LOGGER.info("addFavorite");

    ThemeDisplay themeDisplay = getThemeDisplay(request);
    long companyId = themeDisplay.getCompanyId();
    long groupId = themeDisplay.getScopeGroupId();
    long userId = themeDisplay.getUserId();

    IdeaContentType ideaContentType = IdeaContentType.valueOf(ParamUtil.getString(request, "ideaContentType"));
    String urlTitle = ParamUtil.getString(request, "urlTitle", "");

    if (themeDisplay.isSignedIn()) {
        ideaService.addFavorite(companyId, groupId, userId, urlTitle);
    }

    if (ideaContentType == IdeaContentType.IDEA_CONTENT_TYPE_PRIVATE) {
        response.setRenderParameter("type", "private");
    }

    response.setRenderParameter("urlTitle", urlTitle);
}

From source file:se.vgregion.portal.innovationsslussen.idea.controller.IdeaViewController.java

License:Open Source License

/**
 * Method handling Action request.//ww  w .  j ava  2 s .  c  o  m
 *
 * @param request  the request
 * @param response the response
 * @param model    the model
 */
@ActionMapping(params = "action=addLike")
public final void addLike(ActionRequest request, ActionResponse response, final ModelMap model) {

    LOGGER.info("addLike");

    ThemeDisplay themeDisplay = getThemeDisplay(request);
    long companyId = themeDisplay.getCompanyId();
    long groupId = themeDisplay.getScopeGroupId();
    long userId = themeDisplay.getUserId();

    IdeaContentType ideaContentType = IdeaContentType.valueOf(ParamUtil.getString(request, "ideaContentType"));
    String urlTitle = ParamUtil.getString(request, "urlTitle", "");

    if (themeDisplay.isSignedIn()) {
        ideaService.addLike(companyId, groupId, userId, urlTitle);
    }

    if (ideaContentType == IdeaContentType.IDEA_CONTENT_TYPE_PRIVATE) {
        response.setRenderParameter("type", "private");
    }

    response.setRenderParameter("urlTitle", urlTitle);
}

From source file:se.vgregion.portal.innovationsslussen.idea.controller.IdeaViewController.java

License:Open Source License

/**
 * Method handling Action request./*from  w w  w.j av a 2 s. c o  m*/
 *
 * @param request  the request
 * @param response the response
 * @param model    the model
 */
@ActionMapping(params = "action=removeFavorite")
public final void removeFavorite(ActionRequest request, ActionResponse response, final ModelMap model) {

    LOGGER.info("removeFavorite");

    ThemeDisplay themeDisplay = getThemeDisplay(request);
    long companyId = themeDisplay.getCompanyId();
    long groupId = themeDisplay.getScopeGroupId();
    long userId = themeDisplay.getUserId();

    IdeaContentType ideaContentType = IdeaContentType.valueOf(ParamUtil.getString(request, "ideaContentType"));
    String urlTitle = ParamUtil.getString(request, "urlTitle", "");

    if (themeDisplay.isSignedIn()) {
        ideaService.removeFavorite(companyId, groupId, userId, urlTitle);
    }

    if (ideaContentType == IdeaContentType.IDEA_CONTENT_TYPE_PRIVATE) {
        response.setRenderParameter("type", "private");
    }

    response.setRenderParameter("urlTitle", urlTitle);

}

From source file:se.vgregion.portal.innovationsslussen.idea.controller.IdeaViewController.java

License:Open Source License

/**
 * Method handling Action request.// ww w. j a va 2 s  .  c  o  m
 *
 * @param request  the request
 * @param response the response
 * @param model    the model
 */
@ActionMapping(params = "action=removeLike")
public final void removeLike(ActionRequest request, ActionResponse response, final ModelMap model) {

    LOGGER.info("removeLike");

    ThemeDisplay themeDisplay = getThemeDisplay(request);
    long companyId = themeDisplay.getCompanyId();
    long groupId = themeDisplay.getScopeGroupId();
    long userId = themeDisplay.getUserId();

    IdeaContentType ideaContentType = IdeaContentType.valueOf(ParamUtil.getString(request, "ideaContentType"));
    String urlTitle = ParamUtil.getString(request, "urlTitle", "");

    if (themeDisplay.isSignedIn()) {
        ideaService.removeLike(companyId, groupId, userId, urlTitle);
    }

    if (ideaContentType == IdeaContentType.IDEA_CONTENT_TYPE_PRIVATE) {
        response.setRenderParameter("type", "private");
    }

    response.setRenderParameter("urlTitle", urlTitle);
}