com.liferay.users.admin.web.internal.portlet.action.EditProfileAndPrivateAreaMVCActionCommand.java Source code

Java tutorial

Introduction

Here is the source code for com.liferay.users.admin.web.internal.portlet.action.EditProfileAndPrivateAreaMVCActionCommand.java

Source

/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.liferay.users.admin.web.internal.portlet.action;

import com.liferay.portal.kernel.model.Group;
import com.liferay.portal.kernel.model.LayoutSet;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.portlet.bridges.mvc.BaseMVCActionCommand;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCActionCommand;
import com.liferay.portal.kernel.security.permission.ActionKeys;
import com.liferay.portal.kernel.security.permission.PermissionChecker;
import com.liferay.portal.kernel.service.permission.GroupPermissionUtil;
import com.liferay.portal.kernel.service.permission.PortalPermissionUtil;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.Portal;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.sites.kernel.util.Sites;
import com.liferay.users.admin.constants.UsersAdminPortletKeys;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

/**
 * @author Drew Brokke
 */
@Component(immediate = true, property = { "javax.portlet.name=" + UsersAdminPortletKeys.MY_ORGANIZATIONS,
        "javax.portlet.name=" + UsersAdminPortletKeys.USERS_ADMIN,
        "mvc.command.name=/users_admin/edit_profile_and_private_area" }, service = MVCActionCommand.class)
public class EditProfileAndPrivateAreaMVCActionCommand extends BaseMVCActionCommand {

    @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);
            }
        }
    }

    @Reference
    private Portal _portal;

    @Reference
    private Sites _sites;

}