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

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

Introduction

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

Prototype

public Group getScopeGroup() 

Source Link

Document

Returns the scoped or sub-scoped active group (e.g.

Usage

From source file:com.liferay.announcements.web.internal.display.context.util.AnnouncementsRequestHelper.java

License:Open Source License

public Group getScopeGroup() {
    if (_scopeGroup != null) {
        return _scopeGroup;
    }/*from www . ja  va2s.c o  m*/

    ThemeDisplay themeDisplay = getThemeDisplay();

    _scopeGroup = themeDisplay.getScopeGroup();

    return _scopeGroup;
}

From source file:com.liferay.application.list.BasePanelApp.java

License:Open Source License

protected Group getGroup(HttpServletRequest request) {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    Group group = themeDisplay.getScopeGroup();

    if (!group.isControlPanel()) {
        return null;
    }/*from www. j  a v  a2s  .  co  m*/

    Portlet portlet = getPortlet();

    String controlPanelEntryCategory = portlet.getControlPanelEntryCategory();

    if (Validator.isNull(controlPanelEntryCategory)
            || !controlPanelEntryCategory.startsWith(PortletCategoryKeys.SITE_ADMINISTRATION)) {

        return null;
    }

    if (groupProvider == null) {
        return null;
    }

    return groupProvider.getGroup(request);
}

From source file:com.liferay.application.list.taglib.servlet.taglib.BasePanelTag.java

License:Open Source License

public Group getGroup() {
    GroupProvider groupProvider = (GroupProvider) request.getAttribute(ApplicationListWebKeys.GROUP_PROVIDER);

    if (groupProvider != null) {
        Group group = groupProvider.getGroup(request);

        if (group != null) {
            return group;
        }/*w  w w .  j a  va  2  s . c o  m*/
    }

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

    return themeDisplay.getScopeGroup();
}

From source file:com.liferay.asset.publisher.web.internal.portlet.toolbar.contributor.AssetPublisherPortletToolbarContributor.java

License:Open Source License

private boolean _isVisible(AssetPublisherDisplayContext assetPublisherDisplayContext,
        PortletRequest portletRequest) {

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

    if (!assetPublisherDisplayContext.isShowAddContentButton()) {
        return false;
    }/*from  w w  w  .  ja v  a 2s.c o  m*/

    Group scopeGroup = themeDisplay.getScopeGroup();

    if (scopeGroup.hasStagingGroup() && !scopeGroup.isStagingGroup()
            && PropsValues.STAGING_LIVE_GROUP_LOCKING_ENABLED) {

        return false;
    }

    Layout layout = themeDisplay.getLayout();

    if (layout.isLayoutPrototypeLinkActive() && assetPublisherDisplayContext.isSelectionStyleManual()) {

        return false;
    }

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    String portletName = portletDisplay.getPortletName();

    if (portletName.equals(AssetPublisherPortletKeys.HIGHEST_RATED_ASSETS)) {

        return false;
    }

    if (portletName.equals(AssetPublisherPortletKeys.MOST_VIEWED_ASSETS)) {
        return false;
    }

    if (portletName.equals(AssetPublisherPortletKeys.RELATED_ASSETS)) {
        return false;
    }

    return true;
}

From source file:com.liferay.asset.taglib.servlet.taglib.AssetTagsSelectorTag.java

License:Open Source License

protected long[] getGroupIds() {
    if (_groupIds != null) {
        return _groupIds;
    }// ww w  .  j  a va 2  s . c om

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

    long[] groupIds = null;

    Group group = themeDisplay.getScopeGroup();

    if (group.isLayout()) {
        groupIds = new long[] { group.getParentGroupId() };
    } else {
        groupIds = new long[] { group.getGroupId() };
    }

    if (group.getParentGroupId() != themeDisplay.getCompanyGroupId()) {
        groupIds = ArrayUtil.append(groupIds, themeDisplay.getCompanyGroupId());
    }

    return groupIds;
}

From source file:com.liferay.blogs.web.internal.upload.ImageBlogsUploadFileEntryHandler.java

License:Open Source License

@Override
public FileEntry upload(UploadPortletRequest uploadPortletRequest) throws IOException, PortalException {

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

    portletResourcePermission.check(themeDisplay.getPermissionChecker(), themeDisplay.getScopeGroup(),
            ActionKeys.ADD_ENTRY);/*from ww  w. jav a  2  s  . co  m*/

    String fileName = uploadPortletRequest.getFileName(_PARAMETER_NAME);
    long size = uploadPortletRequest.getSize(_PARAMETER_NAME);

    _validateFile(fileName, size);

    String contentType = uploadPortletRequest.getContentType(_PARAMETER_NAME);

    try (InputStream inputStream = uploadPortletRequest.getFileAsStream(_PARAMETER_NAME)) {

        return addFileEntry(fileName, contentType, inputStream, themeDisplay);
    }
}

From source file:com.liferay.calendar.web.internal.portlet.CalendarPortlet.java

License:Open Source License

protected Hits search(ThemeDisplay themeDisplay, String keywords) throws Exception {

    SearchContext searchContext = new SearchContext();

    keywords = StringUtil.toLowerCase(keywords);

    searchContext.setAttribute(Field.NAME, keywords);
    searchContext.setAttribute("resourceName", keywords);

    searchContext.setCompanyId(themeDisplay.getCompanyId());
    searchContext.setEnd(SearchContainer.DEFAULT_DELTA);
    searchContext.setGroupIds(new long[0]);

    Group group = themeDisplay.getScopeGroup();

    searchContext.setIncludeStagingGroups(group.isStagingGroup());

    searchContext.setStart(0);/*from w  w  w  .j  a  va  2s  .c o  m*/
    searchContext.setUserId(themeDisplay.getUserId());

    Indexer<?> indexer = CalendarSearcher.getInstance();

    return indexer.search(searchContext);
}

From source file:com.liferay.contacts.web.internal.portlet.ContactsCenterPortlet.java

License:Open Source License

protected JSONObject getContactsJSONObject(PortletRequest portletRequest, PortletResponse portletResponse)
        throws Exception {

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

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

    String filterBy = ParamUtil.getString(portletRequest, "filterBy");
    String keywords = ParamUtil.getString(portletRequest, "keywords");
    int start = ParamUtil.getInteger(portletRequest, "start");
    int end = ParamUtil.getInteger(portletRequest, "end");

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    JSONObject optionsJSONObject = JSONFactoryUtil.createJSONObject();

    optionsJSONObject.put("end", end);
    optionsJSONObject.put("filterBy", filterBy);
    optionsJSONObject.put("keywords", keywords);
    optionsJSONObject.put("start", start);

    jsonObject.put("options", optionsJSONObject);

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    String portletId = portletDisplay.getId();

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    if (filterBy.equals(ContactsConstants.FILTER_BY_DEFAULT)
            && !portletId.equals(ContactsPortletKeys.MEMBERS)) {

        List<BaseModel<?>> contacts = entryLocalService.searchUsersAndContacts(themeDisplay.getCompanyId(),
                themeDisplay.getUserId(), keywords, start, end);

        int contactsCount = entryLocalService.searchUsersAndContactsCount(themeDisplay.getCompanyId(),
                themeDisplay.getUserId(), keywords);

        jsonObject.put("count", contactsCount);

        for (BaseModel<?> contact : contacts) {
            JSONObject contactJSONObject = null;

            if (contact instanceof User) {
                contactJSONObject = getUserJSONObject(portletResponse, themeDisplay, (User) contact);
            } else {
                contactJSONObject = getEntryJSONObject(portletResponse, themeDisplay, (Entry) contact,
                        redirect);//from w  w  w .  j  a  va  2s  .  c o  m
            }

            jsonArray.put(contactJSONObject);
        }
    } else if (filterBy.equals(ContactsConstants.FILTER_BY_FOLLOWERS)
            && !portletId.equals(ContactsPortletKeys.MEMBERS)) {

        List<SocialRelation> socialRelations = socialRelationLocalService.getInverseRelations(
                themeDisplay.getUserId(), SocialRelationConstants.TYPE_UNI_FOLLOWER, start, end);

        for (SocialRelation socialRelation : socialRelations) {
            jsonArray.put(getUserJSONObject(portletResponse, themeDisplay, socialRelation.getUserId1()));
        }
    } else if (filterBy.equals(ContactsConstants.FILTER_BY_TYPE_MY_CONTACTS)
            && !portletId.equals(ContactsPortletKeys.MEMBERS)) {

        List<Entry> entries = entryLocalService.search(themeDisplay.getUserId(), keywords, start, end);

        int entriesCount = entryLocalService.searchCount(themeDisplay.getUserId(), keywords);

        jsonObject.put("count", entriesCount);

        for (Entry entry : entries) {
            JSONObject contactJSONObject = getEntryJSONObject(portletResponse, themeDisplay, entry, redirect);

            jsonArray.put(contactJSONObject);
        }
    } else {
        LinkedHashMap<String, Object> params = new LinkedHashMap<>();

        params.put("inherit", Boolean.TRUE);

        Group group = themeDisplay.getScopeGroup();
        Layout layout = themeDisplay.getLayout();

        if (group.isUser() && layout.isPublicLayout()) {
            params.put("socialRelationType",
                    new Long[] { group.getClassPK(), (long) SocialRelationConstants.TYPE_BI_CONNECTION });
        } else if (filterBy.startsWith(ContactsConstants.FILTER_BY_TYPE)) {
            params.put("socialRelationType",
                    new Long[] { themeDisplay.getUserId(), ContactsUtil.getSocialRelationType(filterBy) });
        }

        if (portletId.equals(ContactsPortletKeys.MEMBERS)) {
            params.put("usersGroups", group.getGroupId());
        } else if (filterBy.startsWith(ContactsConstants.FILTER_BY_GROUP)) {
            params.put("usersGroups", ContactsUtil.getGroupId(filterBy));
        }

        List<User> usersList = null;

        if (filterBy.equals(ContactsConstants.FILTER_BY_ADMINS)) {
            Role siteAdministratorRole = roleLocalService.getRole(group.getCompanyId(),
                    RoleConstants.SITE_ADMINISTRATOR);

            params.put("userGroupRole", new Long[] { group.getGroupId(), siteAdministratorRole.getRoleId() });

            Set<User> users = new HashSet<>();

            users.addAll(userLocalService.search(themeDisplay.getCompanyId(), keywords,
                    WorkflowConstants.STATUS_APPROVED, params, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
                    (OrderByComparator) null));

            Role siteOwnerRole = roleLocalService.getRole(group.getCompanyId(), RoleConstants.SITE_OWNER);

            params.put("userGroupRole", new Long[] { group.getGroupId(), siteOwnerRole.getRoleId() });

            users.addAll(userLocalService.search(themeDisplay.getCompanyId(), keywords,
                    WorkflowConstants.STATUS_APPROVED, params, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
                    (OrderByComparator) null));

            usersList = new ArrayList<>(users);

            ListUtil.sort(usersList, new UserLastNameComparator(true));
        } else {
            int usersCount = userLocalService.searchCount(themeDisplay.getCompanyId(), keywords,
                    WorkflowConstants.STATUS_APPROVED, params);

            jsonObject.put("count", usersCount);

            usersList = userLocalService.search(themeDisplay.getCompanyId(), keywords,
                    WorkflowConstants.STATUS_APPROVED, params, start, end, new UserLastNameComparator(true));
        }

        for (User user : usersList) {
            JSONObject userJSONObject = getUserJSONObject(portletResponse, themeDisplay, user);

            jsonArray.put(userJSONObject);
        }
    }

    jsonObject.put("users", jsonArray);

    return jsonObject;
}

From source file:com.liferay.dynamic.data.mapping.model.impl.DDMStructureImpl.java

License:Open Source License

/**
 * Returns the WebDAV URL to access the structure.
 *
 * @param  themeDisplay the theme display needed to build the URL. It can
 *         set HTTPS access, the server name, the server port, the path
 *         context, and the scope group.
 * @param  webDAVToken the WebDAV token for the URL
 * @return the WebDAV URL/*from  w ww.  jav  a 2s. c o  m*/
 */
@Override
public String getWebDavURL(ThemeDisplay themeDisplay, String webDAVToken) {
    StringBundler sb = new StringBundler(11);

    boolean secure = false;

    if (themeDisplay.isSecure() || PropsValues.WEBDAV_SERVLET_HTTPS_REQUIRED) {

        secure = true;
    }

    String portalURL = PortalUtil.getPortalURL(themeDisplay.getServerName(), themeDisplay.getServerPort(),
            secure);

    sb.append(portalURL);

    sb.append(themeDisplay.getPathContext());
    sb.append(StringPool.SLASH);
    sb.append("webdav");

    Group group = themeDisplay.getScopeGroup();

    sb.append(group.getFriendlyURL());

    sb.append(StringPool.SLASH);
    sb.append(webDAVToken);
    sb.append(StringPool.SLASH);
    sb.append("Structures");
    sb.append(StringPool.SLASH);
    sb.append(getStructureId());

    return sb.toString();
}

From source file:com.liferay.dynamic.data.mapping.model.impl.DDMTemplateImpl.java

License:Open Source License

/**
 * Returns the WebDAV URL to access the template.
 *
 * @param  themeDisplay the theme display needed to build the URL. It can
 *         set HTTPS access, the server name, the server port, the path
 *         context, and the scope group.
 * @param  webDAVToken the WebDAV token for the URL
 * @return the WebDAV URL/*from   ww w.jav  a 2  s . c om*/
 */
@Override
public String getWebDavURL(ThemeDisplay themeDisplay, String webDAVToken) {
    StringBundler sb = new StringBundler(11);

    boolean secure = false;

    if (themeDisplay.isSecure() || PropsValues.WEBDAV_SERVLET_HTTPS_REQUIRED) {

        secure = true;
    }

    String portalURL = PortalUtil.getPortalURL(themeDisplay.getServerName(), themeDisplay.getServerPort(),
            secure);

    sb.append(portalURL);

    sb.append(themeDisplay.getPathContext());
    sb.append(StringPool.SLASH);
    sb.append("webdav");

    Group group = themeDisplay.getScopeGroup();

    sb.append(group.getFriendlyURL());

    sb.append(StringPool.SLASH);
    sb.append(webDAVToken);
    sb.append(StringPool.SLASH);
    sb.append("Templates");
    sb.append(StringPool.SLASH);
    sb.append(getTemplateId());

    return sb.toString();
}