Example usage for com.liferay.portal.kernel.model User getGroup

List of usage examples for com.liferay.portal.kernel.model User getGroup

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.model User getGroup.

Prototype

public Group getGroup();

Source Link

Usage

From source file:com.liferay.exportimport.internal.content.processor.test.DefaultExportImportContentProcessorTest.java

License:Open Source License

@Test
public void testExportLinksToUserLayouts() throws Exception {
    User user = TestPropsValues.getUser();

    Group group = user.getGroup();

    Layout privateLayout = LayoutTestUtil.addLayout(group, true);
    Layout publicLayout = LayoutTestUtil.addLayout(group, false);

    PortletDataContext portletDataContextExport = PortletDataContextFactoryUtil.createExportPortletDataContext(
            group.getCompanyId(), group.getGroupId(), new HashMap<>(),
            new Date(System.currentTimeMillis() - Time.HOUR), new Date(), new TestReaderWriter());

    Element rootElement = SAXReaderUtil.createElement("root");

    portletDataContextExport.setExportDataRootElement(rootElement);

    Element missingReferencesElement = rootElement.addElement("missing-references");

    portletDataContextExport.setMissingReferencesElement(missingReferencesElement);

    JournalArticle journalArticle = JournalTestUtil.addArticle(group.getGroupId(),
            RandomTestUtil.randomString(), RandomTestUtil.randomString());

    String content = replaceLinksToLayoutsParameters(getContent("layout_links_user_group.txt"), privateLayout,
            publicLayout);/*from w ww.j a  v a  2s.  co  m*/

    content = _exportImportContentProcessor.replaceExportContentReferences(portletDataContextExport,
            journalArticle, content, true, true);

    assertLinksToLayouts(content, privateLayout, 0);
    assertLinksToLayouts(content, privateLayout, privateLayout.getGroupId());
    assertLinksToLayouts(content, publicLayout, 0);
    assertLinksToLayouts(content, publicLayout, publicLayout.getGroupId());
}

From source file:com.liferay.pokedex.web.sampledata.AddDefaultPokemonsPortalInstanceLifecycleListener.java

License:Open Source License

@Override
public void portalInstanceRegistered(Company company) throws Exception {
    List<User> users = _userLocalService.getCompanyUsers(company.getCompanyId(), 0, 10);

    for (User user : users) {
        if (!user.isActive() || user.isDefaultUser()) {
            continue;
        }//from  w ww .  ja  v a  2 s  .  c o  m

        Group group = user.getGroup();

        if (group == null) {
            continue;
        }

        List<Pokemon> pokemons = _pokemonLocalService.getPokemons(user.getGroupId());

        if (!pokemons.isEmpty()) {
            continue;
        }

        addDefaultPokemons(user);
    }
}

From source file:com.liferay.users.admin.web.internal.portlet.action.EditProfileAndPrivateAreaMVCActionCommand.java

License:Open Source License

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

    User user = _portal.getSelectedUser(actionRequest);

    Group group = user.getGroup();

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

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    if (GroupPermissionUtil.contains(permissionChecker, group.getGroupId(), ActionKeys.UPDATE)
            && PortalPermissionUtil.contains(permissionChecker, ActionKeys.UNLINK_LAYOUT_SET_PROTOTYPE)) {

        long publicLayoutSetPrototypeId = ParamUtil.getLong(actionRequest, "publicLayoutSetPrototypeId");
        long privateLayoutSetPrototypeId = ParamUtil.getLong(actionRequest, "privateLayoutSetPrototypeId");
        boolean publicLayoutSetPrototypeLinkEnabled = ParamUtil.getBoolean(actionRequest,
                "publicLayoutSetPrototypeLinkEnabled");
        boolean privateLayoutSetPrototypeLinkEnabled = ParamUtil.getBoolean(actionRequest,
                "privateLayoutSetPrototypeLinkEnabled");

        LayoutSet publicLayoutSet = group.getPublicLayoutSet();
        LayoutSet privateLayoutSet = group.getPrivateLayoutSet();

        if ((publicLayoutSetPrototypeId > 0) || (privateLayoutSetPrototypeId > 0)
                || (publicLayoutSetPrototypeLinkEnabled != publicLayoutSet.isLayoutSetPrototypeLinkEnabled())
                || (privateLayoutSetPrototypeLinkEnabled != privateLayoutSet
                        .isLayoutSetPrototypeLinkEnabled())) {

            _sites.updateLayoutSetPrototypesLinks(group, publicLayoutSetPrototypeId,
                    privateLayoutSetPrototypeId, publicLayoutSetPrototypeLinkEnabled,
                    privateLayoutSetPrototypeLinkEnabled);
        }/*w  w  w.j av  a2  s  .co m*/
    }
}

From source file:com.liferay.users.admin.web.internal.portlet.action.EditUserMVCActionCommand.java

License:Open Source License

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

    actionRequest = _wrapActionRequest(actionRequest);

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

    try {/*from   w ww .  j a  v a2 s.c  om*/
        User user = null;
        String oldScreenName = StringPool.BLANK;
        boolean updateLanguageId = false;

        if (cmd.equals(Constants.ADD)) {
            user = addUser(actionRequest);
        } else if (cmd.equals(Constants.DEACTIVATE) || cmd.equals(Constants.DELETE)
                || cmd.equals(Constants.RESTORE)) {

            deleteUsers(actionRequest);
        } else if (cmd.equals("deleteRole")) {
            deleteRole(actionRequest);
        } else if (cmd.equals(Constants.UPDATE)) {
            Object[] returnValue = updateUser(actionRequest, actionResponse);

            user = (User) returnValue[0];
            oldScreenName = (String) returnValue[1];
            updateLanguageId = (Boolean) returnValue[2];
        } else if (cmd.equals("unlock")) {
            user = updateLockout(actionRequest);
        }

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

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

        if (user != null) {
            if (Validator.isNotNull(oldScreenName)) {

                // This will fix the redirect if the user is on his personal
                // my account page and changes his screen name. A redirect
                // that references the old screen name no longer points to a
                // valid screen name and therefore needs to be updated.

                Group group = user.getGroup();

                if (group.getGroupId() == themeDisplay.getScopeGroupId()) {
                    Layout layout = themeDisplay.getLayout();

                    String friendlyURLPath = group.getPathFriendlyURL(layout.isPrivateLayout(), themeDisplay);

                    String oldPath = friendlyURLPath + StringPool.SLASH + oldScreenName;
                    String newPath = friendlyURLPath + StringPool.SLASH + user.getScreenName();

                    redirect = StringUtil.replace(redirect, oldPath, newPath);

                    redirect = StringUtil.replace(redirect, URLCodec.encodeURL(oldPath),
                            URLCodec.encodeURL(newPath));
                }
            }

            if (updateLanguageId && themeDisplay.isI18n()) {
                String i18nLanguageId = user.getLanguageId();

                int pos = i18nLanguageId.indexOf(CharPool.UNDERLINE);

                if (pos != -1) {
                    i18nLanguageId = i18nLanguageId.substring(0, pos);
                }

                String i18nPath = StringPool.SLASH + i18nLanguageId;

                redirect = StringUtil.replace(redirect, themeDisplay.getI18nPath(), i18nPath);
            }

            redirect = http.setParameter(redirect, actionResponse.getNamespace() + "p_u_i_d", user.getUserId());
        }

        Group scopeGroup = themeDisplay.getScopeGroup();

        if (scopeGroup.isUser() && (userLocalService.fetchUserById(scopeGroup.getClassPK()) == null)) {

            redirect = http.setParameter(redirect, "doAsGroupId", 0);
            redirect = http.setParameter(redirect, "refererPlid", 0);
        }

        sendRedirect(actionRequest, actionResponse, redirect);
    } catch (Exception e) {
        String mvcPath = "/edit_user.jsp";

        if (e instanceof NoSuchUserException || e instanceof PrincipalException) {

            SessionErrors.add(actionRequest, e.getClass());

            mvcPath = "/error.jsp";
        } else if (e instanceof AssetCategoryException || e instanceof AssetTagException
                || e instanceof CompanyMaxUsersException || e instanceof ContactBirthdayException
                || e instanceof ContactNameException || e instanceof GroupFriendlyURLException
                || e instanceof MembershipPolicyException || e instanceof NoSuchListTypeException
                || e instanceof RequiredUserException || e instanceof UserEmailAddressException
                || e instanceof UserFieldException || e instanceof UserIdException
                || e instanceof UserReminderQueryException || e instanceof UserScreenNameException) {

            if (e instanceof NoSuchListTypeException) {
                NoSuchListTypeException nslte = (NoSuchListTypeException) e;

                Class<?> clazz = e.getClass();

                SessionErrors.add(actionRequest, clazz.getName() + nslte.getType());
            } else {
                SessionErrors.add(actionRequest, e.getClass(), e);
            }

            if (e instanceof CompanyMaxUsersException || e instanceof RequiredUserException) {

                String redirect = portal.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));

                if (Validator.isNotNull(redirect)) {
                    sendRedirect(actionRequest, actionResponse, redirect);

                    return;
                }
            }
        } else {
            throw e;
        }

        actionResponse.setRenderParameter("mvcPath", mvcPath);
    }
}