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

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

Introduction

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

Prototype

public long getCompanyId() 

Source Link

Document

Returns the portal instance ID.

Usage

From source file:com.liferay.login.web.internal.portlet.action.CreateAnonymousAccountMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

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

    PortletConfig portletConfig = (PortletConfig) actionRequest
            .getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);

    String portletName = portletConfig.getPortletName();

    if (!portletName.equals(LoginPortletKeys.FAST_LOGIN)) {
        throw new PrincipalException("Unable to create anonymous account");
    }//  w  w w .jav a  2  s  .  c o m

    if (actionRequest.getRemoteUser() != null) {
        actionResponse.sendRedirect(themeDisplay.getPathMain());

        return;
    }

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

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

    PortletURL portletURL = PortletURLFactoryUtil.create(actionRequest, LoginPortletKeys.FAST_LOGIN,
            PortletRequest.RENDER_PHASE);

    portletURL.setParameter("mvcRenderCommandName", "/login/login_redirect");
    portletURL.setParameter("emailAddress", emailAddress);
    portletURL.setParameter("anonymousUser", Boolean.TRUE.toString());
    portletURL.setWindowState(LiferayWindowState.POP_UP);

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    try {
        if (cmd.equals(Constants.ADD)) {
            addAnonymousUser(actionRequest, actionResponse);

            sendRedirect(actionRequest, actionResponse, portletURL.toString());
        } else if (cmd.equals(Constants.UPDATE)) {
            Company company = themeDisplay.getCompany();

            if (!company.isStrangers()) {
                throw new PrincipalException.MustBeEnabled(company.getCompanyId(),
                        PropsKeys.COMPANY_SECURITY_STRANGERS);
            }

            jsonObject = updateIncompleteUser(actionRequest, actionResponse);

            JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
        }
    } catch (Exception e) {
        if (cmd.equals(Constants.UPDATE)) {
            jsonObject.putException(e);

            JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
        } else if (e instanceof UserEmailAddressException.MustNotBeDuplicate) {

            User user = _userLocalService.getUserByEmailAddress(themeDisplay.getCompanyId(), emailAddress);

            if (user.getStatus() != WorkflowConstants.STATUS_INCOMPLETE) {
                SessionErrors.add(actionRequest, e.getClass());
            } else {
                sendRedirect(actionRequest, actionResponse, portletURL.toString());
            }
        } else if (e instanceof CaptchaConfigurationException || e instanceof CaptchaTextException
                || e instanceof CompanyMaxUsersException || e instanceof ContactNameException
                || e instanceof EmailAddressException || e instanceof GroupFriendlyURLException
                || e instanceof UserEmailAddressException) {

            SessionErrors.add(actionRequest, e.getClass(), e);
        } else {
            _log.error("Unable to create anonymous account", e);

            _portal.sendError(e, actionRequest, actionResponse);
        }
    }
}

From source file:com.liferay.login.web.internal.portlet.action.CreateAnonymousAccountMVCActionCommand.java

License:Open Source License

protected JSONObject updateIncompleteUser(ActionRequest actionRequest, ActionResponse actionResponse)
        throws Exception {

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

    ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(), actionRequest);

    boolean autoPassword = true;
    String password1 = null;/*w w w . j a  va 2  s .  com*/
    String password2 = null;
    boolean autoScreenName = false;
    String screenName = null;
    String emailAddress = ParamUtil.getString(actionRequest, "emailAddress");
    long facebookId = 0;
    String openId = null;
    String firstName = null;
    String middleName = null;
    String lastName = null;
    long prefixId = 0;
    long suffixId = 0;
    boolean male = true;
    int birthdayMonth = 0;
    int birthdayDay = 1;
    int birthdayYear = 1970;
    String jobTitle = null;
    boolean updateUserInformation = false;
    boolean sendEmail = true;

    User user = _userService.updateIncompleteUser(themeDisplay.getCompanyId(), autoPassword, password1,
            password2, autoScreenName, screenName, emailAddress, facebookId, openId, themeDisplay.getLocale(),
            firstName, middleName, lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear,
            jobTitle, updateUserInformation, sendEmail, serviceContext);

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    if (user.getStatus() == WorkflowConstants.STATUS_APPROVED) {
        jsonObject.put("userStatus", "user_added");
    } else {
        jsonObject.put("userStatus", "user_pending");
    }

    return jsonObject;
}

From source file:com.liferay.login.web.internal.portlet.action.ForgotPasswordMVCActionCommand.java

License:Open Source License

protected User getUser(ActionRequest actionRequest) throws Exception {
    PortletSession portletSession = actionRequest.getPortletSession();

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

    String sessionEmailAddress = (String) portletSession
            .getAttribute(WebKeys.FORGOT_PASSWORD_REMINDER_USER_EMAIL_ADDRESS);

    User user = null;/*from  www.  ja va 2s  .  com*/

    if (Validator.isNotNull(sessionEmailAddress)) {
        user = _userLocalService.getUserByEmailAddress(themeDisplay.getCompanyId(), sessionEmailAddress);
    } else {
        long userId = ParamUtil.getLong(actionRequest, "userId");
        String screenName = ParamUtil.getString(actionRequest, "screenName");
        String emailAddress = ParamUtil.getString(actionRequest, "emailAddress");

        if (Validator.isNotNull(emailAddress)) {
            user = _userLocalService.getUserByEmailAddress(themeDisplay.getCompanyId(), emailAddress);
        } else if (Validator.isNotNull(screenName)) {
            user = _userLocalService.getUserByScreenName(themeDisplay.getCompanyId(), screenName);
        } else if (userId > 0) {
            user = _userLocalService.getUserById(userId);
        } else {
            throw new NoSuchUserException("User does not exist");
        }
    }

    if (!user.isActive()) {
        throw new UserActiveException("Inactive user " + user.getUuid());
    }

    _userLocalService.checkLockout(user);

    return user;
}

From source file:com.liferay.map.google.maps.internal.display.context.GoogleMapsDisplayContext.java

License:Open Source License

public String getCompanyGoogleMapsAPIKey() {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    PortletPreferences companyPortletPreferences = PrefsPropsUtil.getPreferences(themeDisplay.getCompanyId());

    return companyPortletPreferences.getValue("googleMapsAPIKey", null);
}

From source file:com.liferay.map.taglib.servlet.taglib.MapDisplayTag.java

License:Open Source License

private String _getMapProviderKey() {
    String mapProdiverKey = _mapProviderKey;

    if (Validator.isNull(mapProdiverKey)) {
        ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

        MapProviderHelper mapProviderHelper = ServletContextUtil.getMapProviderHelper();

        mapProdiverKey = mapProviderHelper.getMapProviderKey(themeDisplay.getCompanyId(),
                themeDisplay.getSiteGroupId());
    }//from   w  w w . j  a va  2  s.c  om

    return mapProdiverKey;
}

From source file:com.liferay.marketplace.app.manager.web.internal.portlet.MarketplaceAppManagerPortlet.java

License:Open Source License

public void updatePluginSetting(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

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

    String pluginId = ParamUtil.getString(actionRequest, "pluginId");
    String pluginType = ParamUtil.getString(actionRequest, "pluginType");

    String[] roles = StringUtil.split(ParamUtil.getString(actionRequest, "roles"), CharPool.NEW_LINE);

    Arrays.sort(roles);/*from  ww  w  . j  a  va2  s.  co m*/

    boolean active = ParamUtil.getBoolean(actionRequest, "active");

    if (pluginType.equals(Plugin.TYPE_PORTLET)) {
        _portletService.updatePortlet(themeDisplay.getCompanyId(), pluginId, StringPool.BLANK, active);
    } else {
        if (roles.length == 0) {
            PluginSetting pluginSetting = _pluginSettingLocalService
                    .getPluginSetting(themeDisplay.getCompanyId(), pluginId, pluginType);

            roles = StringUtil.split(pluginSetting.getRoles());
        }

        _pluginSettingService.updatePluginSetting(themeDisplay.getCompanyId(), pluginId, pluginType,
                StringUtil.merge(roles), active);
    }
}

From source file:com.liferay.marketplace.app.manager.web.internal.portlet.MarketplaceAppManagerPortlet.java

License:Open Source License

public void updatePluginSettings(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

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

    String[] contextNames = StringUtil.split(ParamUtil.getString(actionRequest, "contextNames"));

    boolean active = ParamUtil.getBoolean(actionRequest, "active");

    for (String contextName : contextNames) {
        ServletContext servletContext = ServletContextPool.get(contextName);

        List<LayoutTemplate> layoutTemplates = (List<LayoutTemplate>) servletContext
                .getAttribute(WebKeys.PLUGIN_LAYOUT_TEMPLATES);

        if (layoutTemplates != null) {
            for (LayoutTemplate layoutTemplate : layoutTemplates) {
                PluginSetting pluginSetting = _pluginSettingLocalService.getPluginSetting(
                        themeDisplay.getCompanyId(), layoutTemplate.getLayoutTemplateId(),
                        Plugin.TYPE_LAYOUT_TEMPLATE);

                _pluginSettingService.updatePluginSetting(themeDisplay.getCompanyId(),
                        layoutTemplate.getLayoutTemplateId(), Plugin.TYPE_LAYOUT_TEMPLATE,
                        pluginSetting.getRoles(), active);
            }//w  ww. j  ava  2 s .c o m
        }

        List<Portlet> portlets = (List<Portlet>) servletContext.getAttribute(WebKeys.PLUGIN_PORTLETS);

        if (portlets != null) {
            for (Portlet portlet : portlets) {
                _portletService.updatePortlet(themeDisplay.getCompanyId(), portlet.getPortletId(),
                        StringPool.BLANK, active);
            }
        }

        List<Theme> themes = (List<Theme>) servletContext.getAttribute(WebKeys.PLUGIN_THEMES);

        if (themes != null) {
            for (Theme theme : themes) {
                PluginSetting pluginSetting = _pluginSettingLocalService
                        .getPluginSetting(themeDisplay.getCompanyId(), theme.getThemeId(), Plugin.TYPE_THEME);

                _pluginSettingService.updatePluginSetting(themeDisplay.getCompanyId(), theme.getThemeId(),
                        Plugin.TYPE_THEME, pluginSetting.getRoles(), active);
            }
        }
    }
}

From source file:com.liferay.mentions.web.internal.portlet.MentionsPortlet.java

License:Open Source License

protected JSONArray getJSONArray(HttpServletRequest request) throws PortalException {

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

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

    SocialInteractionsConfiguration socialInteractionsConfiguration = SocialInteractionsConfigurationUtil
            .getSocialInteractionsConfiguration(themeDisplay.getCompanyId(), MentionsPortletKeys.MENTIONS);

    String query = ParamUtil.getString(request, "query");

    List<User> users = _mentionsUserFinder.getUsers(themeDisplay.getCompanyId(), themeDisplay.getUserId(),
            query, socialInteractionsConfiguration);

    for (User user : users) {
        if (user.isDefaultUser() || (themeDisplay.getUserId() == user.getUserId())) {

            continue;
        }//from  ww  w  . j  a  va2s  .com

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

        jsonObject.put("fullName", user.getFullName());

        String mention = "@" + user.getScreenName();

        String profileURL = user.getDisplayURL(themeDisplay);

        if (Validator.isNotNull(profileURL)) {
            mention = StringBundler.concat("<a href=\"", profileURL, "\">@", user.getScreenName(), "</a>");
        }

        jsonObject.put("mention", mention);

        jsonObject.put("portraitURL", user.getPortraitURL(themeDisplay));
        jsonObject.put("screenName", user.getScreenName());

        jsonArray.put(jsonObject);
    }

    return jsonArray;
}

From source file:com.liferay.mentions.web.internal.servlet.taglib.ui.MentionsCompanySettingsFormNavigatorEntry.java

License:Open Source License

@Override
public void include(HttpServletRequest request, HttpServletResponse response) throws IOException {

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

    PortletPreferences companyPortletPreferences = PrefsPropsUtil.getPreferences(themeDisplay.getCompanyId(),
            true);//  w  w w. j av  a  2 s  .  c o m

    boolean companyMentionsEnabled = PrefsParamUtil.getBoolean(companyPortletPreferences, request,
            "mentionsEnabled", true);

    request.setAttribute(MentionsWebKeys.COMPANY_MENTIONS_ENABLED, companyMentionsEnabled);

    super.include(request, response);
}

From source file:com.liferay.mentions.web.internal.servlet.taglib.ui.MentionsSitesFormNavigatorEntry.java

License:Open Source License

@Override
public boolean isVisible(User user, Object formModelBean) {
    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();

    ThemeDisplay themeDisplay = serviceContext.getThemeDisplay();

    HttpServletRequest request = themeDisplay.getRequest();

    PortletPreferences companyPortletPreferences = PrefsPropsUtil.getPreferences(themeDisplay.getCompanyId(),
            true);//w  w  w . j  a v a  2 s . c  o  m

    return PrefsParamUtil.getBoolean(companyPortletPreferences, request, "mentionsEnabled", true);
}