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

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

Introduction

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

Prototype

public Group getGroup();

Source Link

Document

Returns the current layout's group.

Usage

From source file:com.liferay.asset.publisher.web.internal.util.AssetPublisherWebUtil.java

License:Open Source License

public boolean isScopeIdSelectable(PermissionChecker permissionChecker, String scopeId, long companyGroupId,
        Layout layout, boolean checkPermission) throws PortalException {

    long groupId = _assetPublisherUtil.getGroupIdFromScopeId(scopeId, layout.getGroupId(),
            layout.isPrivateLayout());/*ww  w.  j av a2s  .c o m*/

    if (scopeId.startsWith(AssetPublisherUtil.SCOPE_ID_CHILD_GROUP_PREFIX)) {

        Group group = _groupLocalService.getGroup(groupId);

        if (!group.hasAncestor(layout.getGroupId())) {
            return false;
        }
    } else if (scopeId.startsWith(AssetPublisherUtil.SCOPE_ID_PARENT_GROUP_PREFIX)) {

        Group siteGroup = layout.getGroup();

        if (!siteGroup.hasAncestor(groupId)) {
            return false;
        }

        Group group = _groupLocalService.getGroup(groupId);

        if (SitesUtil.isContentSharingWithChildrenEnabled(group)) {
            return true;
        }

        if (!PrefsPropsUtil.getBoolean(layout.getCompanyId(),
                PropsKeys.SITES_CONTENT_SHARING_THROUGH_ADMINISTRATORS_ENABLED)) {

            return false;
        }

        if (checkPermission) {
            return GroupPermissionUtil.contains(permissionChecker, group, ActionKeys.UPDATE);
        }
    } else if ((groupId != companyGroupId) && checkPermission) {
        return GroupPermissionUtil.contains(permissionChecker, groupId, ActionKeys.UPDATE);
    }

    return true;
}

From source file:com.liferay.asset.publisher.web.util.AssetPublisherUtil.java

License:Open Source License

public static boolean isScopeIdSelectable(PermissionChecker permissionChecker, String scopeId,
        long companyGroupId, Layout layout, boolean checkPermission) throws PortalException {

    long groupId = getGroupIdFromScopeId(scopeId, layout.getGroupId(), layout.isPrivateLayout());

    if (scopeId.startsWith(SCOPE_ID_CHILD_GROUP_PREFIX)) {
        Group group = _groupLocalService.getGroup(groupId);

        if (!group.hasAncestor(layout.getGroupId())) {
            return false;
        }//from ww  w.j  ava  2  s  .c  o m
    } else if (scopeId.startsWith(SCOPE_ID_PARENT_GROUP_PREFIX)) {
        Group siteGroup = layout.getGroup();

        if (!siteGroup.hasAncestor(groupId)) {
            return false;
        }

        Group group = _groupLocalService.getGroup(groupId);

        if (SitesUtil.isContentSharingWithChildrenEnabled(group)) {
            return true;
        }

        if (!PrefsPropsUtil.getBoolean(layout.getCompanyId(),
                PropsKeys.SITES_CONTENT_SHARING_THROUGH_ADMINISTRATORS_ENABLED)) {

            return false;
        }

        if (checkPermission) {
            return GroupPermissionUtil.contains(permissionChecker, group, ActionKeys.UPDATE);
        }
    } else if ((groupId != companyGroupId) && checkPermission) {
        return GroupPermissionUtil.contains(permissionChecker, groupId, ActionKeys.UPDATE);
    }

    return true;
}

From source file:com.liferay.exportimport.controller.PortletExportController.java

License:Open Source License

public void exportPortlet(PortletDataContext portletDataContext, long plid, Element parentElement,
        boolean exportPermissions, boolean exportPortletArchivedSetups, boolean exportPortletData,
        boolean exportPortletSetup, boolean exportPortletUserPreferences) throws Exception {

    long layoutId = LayoutConstants.DEFAULT_PARENT_LAYOUT_ID;

    Layout layout = _layoutLocalService.fetchLayout(plid);

    if (layout != null) {
        layoutId = layout.getLayoutId();
    }//from ww w  .ja  v a 2s  .c o  m

    Portlet portlet = _portletLocalService.getPortletById(portletDataContext.getCompanyId(),
            portletDataContext.getPortletId());

    if ((portlet == null) || portlet.isUndeployedPortlet()) {
        if (_log.isDebugEnabled()) {
            _log.debug("Do not export portlet " + portletDataContext.getPortletId()
                    + " because the portlet is not deployed");
        }

        return;
    }

    if (!portlet.isInstanceable() && !portlet.isPreferencesUniquePerLayout()
            && portletDataContext.hasNotUniquePerLayout(portletDataContext.getPortletId())) {

        return;
    }

    if (BackgroundTaskThreadLocal.hasBackgroundTask()) {
        PortletDataContext clonedPortletDataContext = _portletDataContextFactory
                .clonePortletDataContext(portletDataContext);

        ManifestSummary manifestSummary = clonedPortletDataContext.getManifestSummary();

        manifestSummary.resetCounters();

        PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance();

        portletDataHandler.prepareManifestSummary(clonedPortletDataContext);

        _portletDataHandlerStatusMessageSender.sendStatusMessage("portlet", portletDataContext.getPortletId(),
                manifestSummary);
    }

    Document document = SAXReaderUtil.createDocument();

    Element portletElement = document.addElement("portlet");

    portletElement.addAttribute("portlet-id", portletDataContext.getPortletId());
    portletElement.addAttribute("root-portlet-id", portletDataContext.getRootPortletId());
    portletElement.addAttribute("old-plid", String.valueOf(plid));
    portletElement.addAttribute("scope-group-id", String.valueOf(portletDataContext.getScopeGroupId()));
    portletElement.addAttribute("scope-layout-type", portletDataContext.getScopeType());
    portletElement.addAttribute("scope-layout-uuid", portletDataContext.getScopeLayoutUuid());
    portletElement.addAttribute("private-layout", String.valueOf(portletDataContext.isPrivateLayout()));

    // Data

    if (exportPortletData) {
        javax.portlet.PortletPreferences jxPortletPreferences = null;

        if (ExportImportThreadLocal.isInitialLayoutStagingInProcess()) {
            if (layout != null) {
                Group liveGroup = layout.getGroup();

                Group stagingGroup = liveGroup.getStagingGroup();

                layout.setGroupId(stagingGroup.getGroupId());

                jxPortletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup(layout,
                        portletDataContext.getPortletId());

                layout.setGroupId(liveGroup.getGroupId());
            } else {
                Group liveGroup = _groupLocalService.getGroup(portletDataContext.getGroupId());

                Group stagingGroup = liveGroup.getStagingGroup();

                jxPortletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup(
                        portletDataContext.getCompanyId(), stagingGroup.getGroupId(),
                        portletDataContext.getPortletId());
            }
        } else {
            if (layout != null) {
                jxPortletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup(layout,
                        portletDataContext.getPortletId());
            } else {
                jxPortletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup(
                        portletDataContext.getCompanyId(), portletDataContext.getGroupId(),
                        portletDataContext.getPortletId());
            }
        }

        if (!portlet.isPreferencesUniquePerLayout()) {
            StringBundler sb = new StringBundler(5);

            sb.append(portletDataContext.getPortletId());
            sb.append(StringPool.AT);
            sb.append(portletDataContext.getScopeType());
            sb.append(StringPool.AT);
            sb.append(portletDataContext.getScopeLayoutUuid());

            String dataKey = sb.toString();

            if (!portletDataContext.hasNotUniquePerLayout(dataKey)) {
                portletDataContext.putNotUniquePerLayout(dataKey);

                exportPortletData(portletDataContext, portlet, layout, jxPortletPreferences, portletElement);
            }
        } else {
            exportPortletData(portletDataContext, portlet, layout, jxPortletPreferences, portletElement);
        }
    }

    // Portlet preferences

    if (exportPortletSetup) {

        // Company

        exportPortletPreferences(portletDataContext, portletDataContext.getCompanyId(),
                PortletKeys.PREFS_OWNER_TYPE_COMPANY, false, layout, plid, portlet.getRootPortletId(),
                portletElement);

        // Group

        exportPortletPreferences(portletDataContext, portletDataContext.getScopeGroupId(),
                PortletKeys.PREFS_OWNER_TYPE_GROUP, false, layout, PortletKeys.PREFS_PLID_SHARED,
                portlet.getRootPortletId(), portletElement);

        // Group embedded portlets

        exportPortletPreferences(portletDataContext, portletDataContext.getScopeGroupId(),
                PortletKeys.PREFS_OWNER_TYPE_LAYOUT, false, layout, PortletKeys.PREFS_PLID_SHARED,
                portlet.getPortletId(), portletElement);

        // Layout

        exportPortletPreferences(portletDataContext, PortletKeys.PREFS_OWNER_ID_DEFAULT,
                PortletKeys.PREFS_OWNER_TYPE_LAYOUT, false, layout, plid, portletDataContext.getPortletId(),
                portletElement);
    }

    // Portlet user preferences

    if (exportPortletUserPreferences) {
        List<PortletPreferences> portletPreferencesList = _portletPreferencesLocalService.getPortletPreferences(
                PortletKeys.PREFS_OWNER_TYPE_USER, plid, portletDataContext.getPortletId());

        for (PortletPreferences portletPreferences : portletPreferencesList) {

            boolean defaultUser = false;

            if (portletPreferences.getOwnerId() == PortletKeys.PREFS_OWNER_ID_DEFAULT) {

                defaultUser = true;
            }

            exportPortletPreferences(portletDataContext, portletPreferences.getOwnerId(),
                    PortletKeys.PREFS_OWNER_TYPE_USER, defaultUser, layout, plid,
                    portletDataContext.getPortletId(), portletElement);
        }

        try {
            PortletPreferences groupPortletPreferences = _portletPreferencesLocalService.getPortletPreferences(
                    portletDataContext.getScopeGroupId(), PortletKeys.PREFS_OWNER_TYPE_GROUP,
                    PortletKeys.PREFS_PLID_SHARED, portlet.getRootPortletId());

            exportPortletPreference(portletDataContext, portletDataContext.getScopeGroupId(),
                    PortletKeys.PREFS_OWNER_TYPE_GROUP, false, groupPortletPreferences,
                    portlet.getRootPortletId(), PortletKeys.PREFS_PLID_SHARED, portletElement);
        } catch (NoSuchPortletPreferencesException nsppe) {

            // LPS-52675

            if (_log.isDebugEnabled()) {
                _log.debug(nsppe, nsppe);
            }
        }
    }

    // Archived setups

    if (exportPortletArchivedSetups) {
        List<PortletItem> portletItems = _portletItemLocalService.getPortletItems(
                portletDataContext.getGroupId(), portletDataContext.getRootPortletId(),
                PortletPreferences.class.getName());

        for (PortletItem portletItem : portletItems) {
            exportPortletPreferences(portletDataContext, portletItem.getPortletItemId(),
                    PortletKeys.PREFS_OWNER_TYPE_ARCHIVED, false, null, plid, portletItem.getPortletId(),
                    portletElement);
        }
    }

    // Permissions

    if (exportPermissions) {
        _permissionExporter.exportPortletPermissions(portletDataContext, portletDataContext.getPortletId(),
                layout, portletElement);
    }

    // Zip

    StringBundler pathSB = new StringBundler(4);

    pathSB.append(ExportImportPathUtil.getPortletPath(portletDataContext));
    pathSB.append(StringPool.SLASH);
    pathSB.append(plid);
    pathSB.append("/portlet.xml");

    String path = pathSB.toString();

    Element element = parentElement.addElement("portlet");

    element.addAttribute("portlet-id", portletDataContext.getPortletId());
    element.addAttribute("layout-id", String.valueOf(layoutId));
    element.addAttribute("path", path);
    element.addAttribute("portlet-data", String.valueOf(exportPortletData));

    PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance();

    element.addAttribute("schema-version", portletDataHandler.getSchemaVersion());

    StringBundler configurationOptionsSB = new StringBundler(6);

    if (exportPortletSetup) {
        configurationOptionsSB.append("setup");
        configurationOptionsSB.append(StringPool.COMMA);
    }

    if (exportPortletArchivedSetups) {
        configurationOptionsSB.append("archived-setups");
        configurationOptionsSB.append(StringPool.COMMA);
    }

    if (exportPortletUserPreferences) {
        configurationOptionsSB.append("user-preferences");
        configurationOptionsSB.append(StringPool.COMMA);
    }

    if (configurationOptionsSB.index() > 0) {
        configurationOptionsSB.setIndex(configurationOptionsSB.index() - 1);
    }

    element.addAttribute("portlet-configuration", configurationOptionsSB.toString());

    try {
        portletDataContext.addZipEntry(path, document.formattedString());
    } catch (IOException ioe) {
        if (_log.isWarnEnabled()) {
            _log.warn(ioe.getMessage());
        }
    }
}

From source file:com.liferay.exportimport.controller.PortletExportController.java

License:Open Source License

public void exportPortletData(PortletDataContext portletDataContext, Portlet portlet, Layout layout,
        javax.portlet.PortletPreferences jxPortletPreferences, Element parentElement) throws Exception {

    if (portlet == null) {
        return;//  w  ww.ja  v  a2s  .  c om
    }

    PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance();

    if ((portletDataHandler == null) || portletDataHandler.isDataPortletInstanceLevel()) {

        return;
    }

    Group group = _groupLocalService.getGroup(portletDataContext.getGroupId());

    long plid = LayoutConstants.DEFAULT_PLID;

    if (layout != null) {
        group = layout.getGroup();
        plid = layout.getPlid();
    }

    if (group.isStagingGroup()) {
        group = group.getLiveGroup();
    }

    String portletId = portlet.getPortletId();

    if (ExportImportThreadLocal.isStagingInProcess() && !group.isStagedPortlet(portletId)) {

        if (_log.isDebugEnabled()) {
            _log.debug("Not exporting data for " + portletId + " because it is configured not to be staged");
        }

        return;
    }

    if (_log.isDebugEnabled()) {
        _log.debug("Exporting data for " + portletId);
    }

    String path = ExportImportPathUtil.getPortletDataPath(portletDataContext);

    if (portletDataContext.hasPrimaryKey(String.class, path)) {
        return;
    }

    Date originalStartDate = portletDataContext.getStartDate();

    Date portletLastPublishDate = ExportImportDateUtil.getLastPublishDate(portletDataContext,
            jxPortletPreferences);

    portletDataContext.setStartDate(portletLastPublishDate);

    long groupId = portletDataContext.getGroupId();

    portletDataContext.setGroupId(portletDataContext.getScopeGroupId());

    portletDataContext.clearScopedPrimaryKeys();

    String data = null;

    try {
        data = portletDataHandler.exportData(portletDataContext, portletId, jxPortletPreferences);
    } finally {
        portletDataContext.setGroupId(groupId);
        portletDataContext.setStartDate(originalStartDate);
    }

    if (Validator.isNull(data)) {
        if (_log.isDebugEnabled()) {
            _log.debug("Not exporting data for " + portletId + " because null data was returned");
        }

        return;
    }

    Element portletDataElement = parentElement.addElement("portlet-data");

    portletDataElement.addAttribute("path", path);

    portletDataContext.addZipEntry(path, data);

    boolean updateLastPublishDate = MapUtil.getBoolean(portletDataContext.getParameterMap(),
            PortletDataHandlerKeys.UPDATE_LAST_PUBLISH_DATE);

    if (ExportImportThreadLocal.isStagingInProcess() && updateLastPublishDate) {

        DateRange adjustedDateRange = new DateRange(portletLastPublishDate, portletDataContext.getEndDate());

        _exportImportProcessCallbackRegistry.registerCallback(portletDataContext.getExportImportProcessId(),
                new UpdatePortletLastPublishDateCallable(adjustedDateRange, portletDataContext.getEndDate(),
                        portletDataContext.getGroupId(), plid, portletId));
    }
}

From source file:com.liferay.exportimport.lar.ExportImportHelperImpl.java

License:Open Source License

@Override
public void setPortletScope(PortletDataContext portletDataContext, Element portletElement) {

    // Portlet data scope

    String scopeLayoutUuid = GetterUtil.getString(portletElement.attributeValue("scope-layout-uuid"));
    String scopeLayoutType = GetterUtil.getString(portletElement.attributeValue("scope-layout-type"));

    portletDataContext.setScopeLayoutUuid(scopeLayoutUuid);
    portletDataContext.setScopeType(scopeLayoutType);

    // Layout scope

    try {//from  w ww .j  a  va 2s .co  m
        Group scopeGroup = null;

        if (scopeLayoutType.equals("company")) {
            scopeGroup = _groupLocalService.getCompanyGroup(portletDataContext.getCompanyId());
        } else if (Validator.isNotNull(scopeLayoutUuid)) {
            Layout scopeLayout = _layoutLocalService.getLayoutByUuidAndGroupId(scopeLayoutUuid,
                    portletDataContext.getGroupId(), portletDataContext.isPrivateLayout());

            scopeGroup = _groupLocalService.checkScopeGroup(scopeLayout, portletDataContext.getUserId(null));

            Group group = scopeLayout.getGroup();

            if (group.isStaged() && !group.isStagedRemotely()) {
                try {
                    boolean privateLayout = GetterUtil
                            .getBoolean(portletElement.attributeValue("private-layout"));

                    Layout oldLayout = _layoutLocalService.getLayoutByUuidAndGroupId(scopeLayoutUuid,
                            portletDataContext.getSourceGroupId(), privateLayout);

                    Group oldScopeGroup = oldLayout.getScopeGroup();

                    if (group.isStagingGroup()) {
                        scopeGroup.setLiveGroupId(oldScopeGroup.getGroupId());

                        _groupLocalService.updateGroup(scopeGroup);
                    } else {
                        oldScopeGroup.setLiveGroupId(scopeGroup.getGroupId());

                        _groupLocalService.updateGroup(oldScopeGroup);
                    }
                } catch (NoSuchLayoutException nsle) {
                    if (_log.isWarnEnabled()) {
                        _log.warn(nsle);
                    }
                }
            }

            if (!ExportImportThreadLocal.isStagingInProcess() && group.isStagingGroup()
                    && !group.isStagedPortlet(portletDataContext.getPortletId())) {

                scopeGroup = group.getLiveGroup();

                Layout scopeLiveLayout = _layoutLocalService.fetchLayoutByUuidAndGroupId(scopeLayoutUuid,
                        group.getLiveGroupId(), portletDataContext.isPrivateLayout());

                if (scopeLiveLayout != null) {
                    scopeGroup = _groupLocalService.checkScopeGroup(scopeLiveLayout,
                            portletDataContext.getUserId(null));
                }
            }
        } else {
            Group group = _groupLocalService.getGroup(portletDataContext.getGroupId());

            if (!ExportImportThreadLocal.isStagingInProcess() && group.isStagingGroup()
                    && !group.isStagedPortlet(portletDataContext.getPortletId())) {

                scopeGroup = group.getLiveGroup();
            }
        }

        if (scopeGroup != null) {
            portletDataContext.setScopeGroupId(scopeGroup.getGroupId());

            Map<Long, Long> groupIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Group.class);

            long oldScopeGroupId = GetterUtil.getLong(portletElement.attributeValue("scope-group-id"));

            groupIds.put(oldScopeGroupId, scopeGroup.getGroupId());
        }
    } catch (PortalException pe) {

        // LPS-52675

        if (_log.isDebugEnabled()) {
            _log.debug(pe, pe);
        }
    } catch (Exception e) {
        _log.error(e, e);
    }
}

From source file:com.liferay.exportimport.staging.LayoutStagingImpl.java

License:Open Source License

@Override
public boolean isBranchingLayout(Layout layout) {
    try {//from   w  w  w.  j  a v  a2 s.c  o  m
        return isBranchingLayoutSet(layout.getGroup(), layout.isPrivateLayout());
    } catch (Exception e) {
        throw new IllegalStateException(
                "Unable to determine if layout " + layout.getPlid() + " is enabled for versioning", e);
    }
}

From source file:com.liferay.exportimport.staging.StagingImpl.java

License:Open Source License

protected long publishPortlet(long userId, long scopeGroupId, long plid, String portletId,
        Map<String, String[]> parameterMap, boolean copyFromLive) throws PortalException {

    Layout sourceLayout = _layoutLocalService.getLayout(plid);

    Group scopeGroup = sourceLayout.getScopeGroup();

    Group stagingGroup = null;//from ww w .  j a  va  2  s  .  c o  m
    Group liveGroup = null;

    Layout targetLayout = null;

    if (sourceLayout.isTypeControlPanel()) {
        stagingGroup = _groupLocalService.fetchGroup(scopeGroupId);

        liveGroup = stagingGroup.getLiveGroup();

        targetLayout = sourceLayout;
    } else if (sourceLayout.hasScopeGroup() && (scopeGroup.getGroupId() == scopeGroupId)) {

        stagingGroup = scopeGroup;

        liveGroup = stagingGroup.getLiveGroup();

        targetLayout = _layoutLocalService.getLayout(liveGroup.getClassPK());
    } else {
        stagingGroup = sourceLayout.getGroup();

        liveGroup = stagingGroup.getLiveGroup();

        targetLayout = _layoutLocalService.fetchLayoutByUuidAndGroupId(sourceLayout.getUuid(),
                liveGroup.getGroupId(), sourceLayout.isPrivateLayout());
    }

    if (copyFromLive) {
        return publishPortlet(userId, liveGroup.getGroupId(), stagingGroup.getGroupId(), targetLayout.getPlid(),
                sourceLayout.getPlid(), portletId, parameterMap);
    }

    return publishPortlet(userId, stagingGroup.getGroupId(), liveGroup.getGroupId(), sourceLayout.getPlid(),
            targetLayout.getPlid(), portletId, parameterMap);
}

From source file:com.liferay.flags.internal.messaging.FlagsRequestMessageListener.java

License:Open Source License

@Override
protected void doReceive(Message message) throws Exception {
    FlagsRequest flagsRequest = (FlagsRequest) message.getPayload();

    // Service context

    ServiceContext serviceContext = flagsRequest.getServiceContext();

    // Company/* w  w  w .  jav a  2s.c o  m*/

    long companyId = serviceContext.getCompanyId();

    Company company = _companyLocalService.getCompany(serviceContext.getCompanyId());

    // Group

    Layout layout = _layoutLocalService.getLayout(serviceContext.getPlid());

    Group group = layout.getGroup();

    // Reporter user

    String reporterUserName = null;
    String reporterEmailAddress = null;

    User reporterUser = _userLocalService.getUserById(serviceContext.getUserId());

    Locale locale = LocaleUtil.getDefault();

    if (reporterUser.isDefaultUser()) {
        reporterUserName = LanguageUtil.get(locale, "anonymous");
    } else {
        reporterUserName = reporterUser.getFullName();
        reporterEmailAddress = reporterUser.getEmailAddress();
    }

    // Reported user

    String reportedUserName = StringPool.BLANK;
    String reportedEmailAddress = StringPool.BLANK;
    String reportedURL = StringPool.BLANK;

    User reportedUser = _userLocalService.getUserById(flagsRequest.getReportedUserId());

    if (reportedUser.isDefaultUser()) {
        reportedUserName = group.getDescriptiveName();
    } else {
        reportedUserName = reportedUser.getFullName();
        reportedEmailAddress = reportedUser.getEmailAddress();
        reportedURL = reportedUser.getDisplayURL(serviceContext.getThemeDisplay());
    }

    // Content

    String contentType = ResourceActionsUtil.getModelResource(locale, flagsRequest.getClassName());

    // Reason

    String reason = LanguageUtil.get(locale, flagsRequest.getReason());

    // Email

    FlagsGroupServiceConfiguration flagsGroupServiceConfiguration = ConfigurationProviderUtil
            .getCompanyConfiguration(FlagsGroupServiceConfiguration.class, companyId);

    String fromName = flagsGroupServiceConfiguration.emailFromName();
    String fromAddress = flagsGroupServiceConfiguration.emailFromAddress();

    String subject = ContentUtil.get(FlagsRequestMessageListener.class.getClassLoader(),
            flagsGroupServiceConfiguration.emailSubject());
    String body = ContentUtil.get(FlagsRequestMessageListener.class.getClassLoader(),
            flagsGroupServiceConfiguration.emailBody());

    // Recipients

    Set<User> recipients = getRecipients(companyId, serviceContext.getScopeGroupId());

    for (User recipient : recipients) {
        try {
            notify(reporterUser.getUserId(), company, group, reporterEmailAddress, reporterUserName,
                    reportedEmailAddress, reportedUserName, reportedURL, flagsRequest.getClassPK(),
                    flagsRequest.getContentTitle(), contentType, flagsRequest.getContentURL(), reason, fromName,
                    fromAddress, recipient.getFullName(), recipient.getEmailAddress(), subject, body,
                    serviceContext);
        } catch (IOException ioe) {
            if (_log.isWarnEnabled()) {
                _log.warn(ioe);
            }
        }
    }
}

From source file:com.liferay.grow.service.wrapper.LayoutCustomServiceWrapper.java

License:Open Source License

@Override
public Layout addLayout(long userId, long groupId, boolean privateLayout, long parentLayoutId, String name,
        String title, String description, String type, boolean hidden, String friendlyURL,
        ServiceContext serviceContext) throws PortalException {

    Layout layout = super.addLayout(userId, groupId, privateLayout, parentLayoutId, name, title, description,
            type, hidden, friendlyURL, serviceContext);

    try {//ww w .j ava2 s.co  m
        Group group = layout.getGroup();

        String layoutFriendlyURL = layout.getFriendlyURL();

        String defaultUserPublicLayoutFriendlyURL = getFriendlyURL(
                PropsValues.DEFAULT_USER_PUBLIC_LAYOUT_FRIENDLY_URL);

        // Remove the Guest role's View permission for default user Profile
        // Page

        if (group.isUser() && layout.isPublicLayout()
                && layoutFriendlyURL.equals(defaultUserPublicLayoutFriendlyURL)) {

            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 withdraw View permission for Layout with plid " + layout.getPlid(), e);
    }

    return layout;
}

From source file:com.liferay.iframe.web.internal.util.IFrameUtil.java

License:Open Source License

public static boolean isPasswordTokenEnabled(PortletRequest portletRequest) throws PortalException {

    if (!PropsValues.SESSION_STORE_PASSWORD) {
        return false;
    }//from  w ww  .ja v  a  2 s.c om

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

    Layout layout = themeDisplay.getLayout();

    String roleName = PropsValues.IFRAME_PASSWORD_PASSWORD_TOKEN_ROLE;

    if (layout.isPrivateLayout() && layout.getGroup().isUser()
            && (themeDisplay.getRealUserId() == layout.getGroup().getClassPK())) {

        return true;
    }

    if (Validator.isNull(roleName)) {
        return false;
    }

    try {
        Role role = RoleLocalServiceUtil.getRole(themeDisplay.getCompanyId(), roleName);

        if (UserLocalServiceUtil.hasRoleUser(role.getRoleId(), themeDisplay.getUserId())) {

            return true;
        }
    } catch (Exception e) {
        if (_log.isWarnEnabled()) {
            _log.warn("Error getting role " + roleName + ". The password token " + "will be disabled.");
        }
    }

    return false;
}