Example usage for com.liferay.portal.kernel.model LayoutTypePortlet removePortletId

List of usage examples for com.liferay.portal.kernel.model LayoutTypePortlet removePortletId

Introduction

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

Prototype

public void removePortletId(long userId, String portletId);

Source Link

Usage

From source file:com.liferay.grow.layout.helper.service.impl.LayoutHelperServiceImpl.java

License:Open Source License

@Override
public void updateProfilePages() {
    if (_log.isInfoEnabled()) {
        _log.info("Updating Profile Pages...");
    }// w w w .  ja v a 2s.c o m

    List<User> users = _userLocalService.getUsers(QueryUtil.ALL_POS, QueryUtil.ALL_POS);

    for (User user : users) {
        try {
            if (user.isDefaultUser()) {
                continue;
            }

            List<Layout> layouts = _layoutLocalService.getLayouts(user.getGroupId(), false);

            if (layouts.size() != 1) {
                if (_log.isInfoEnabled()) {
                    _log.info("User: " + user.getScreenName() + " has " + layouts.size() + " public layout");
                }
            }

            if (layouts.isEmpty()) {
                continue;
            }

            Layout layout = layouts.get(0);

            LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

            // Update Theme

            layout.setThemeId("frontenduserprofilegrow_WAR_growthemeuserprofile");
            layout.setColorSchemeId("01");

            UnicodeProperties properties = layoutTypePortlet.getTypeSettingsProperties();

            properties.put("layoutUpdateable", Boolean.TRUE.toString());
            properties.put("sitemap-changefreq", "daily");
            properties.put("sitemap-include", "1");

            // Remove OWXPSubscribePortlet

            String owxpSubscribePortletId = "com_liferay_owxp_subscribe_portlet_OWXPSubscribePortlet";

            List<String> portletIds = layoutTypePortlet.getPortletIds();

            for (String portletId : portletIds) {
                if (portletId.startsWith(owxpSubscribePortletId)) {
                    layoutTypePortlet.removePortletId(user.getUserId(), portletId);

                    break;
                }
            }

            _layoutLocalService.updateLayout(layout);

            // Remove the Guest role's View permission from the Profile
            // Pages

            Role guestRole = _roleLocalService.getRole(layout.getCompanyId(), RoleConstants.GUEST);

            _resourcePermissionLocalService.setResourcePermissions(layout.getCompanyId(),
                    Layout.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL,
                    String.valueOf(layout.getPlid()), guestRole.getRoleId(), new String[0]);
        } catch (Exception e) {
            _log.error("Cannot remove View permission for " + user.getScreenName(), e);
        }
    }

    if (_log.isInfoEnabled()) {
        _log.info("Profile Pages have been updated");
    }

}