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

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

Introduction

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

Prototype

public long getCompanyId() 

Source Link

Document

Returns the portal instance ID.

Usage

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

License:Open Source License

@Override
protected void setAttributes(HttpServletRequest request) {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    request.setAttribute("liferay-asset:asset-add-button:addDisplayPageParameter", _addDisplayPageParameter);
    request.setAttribute("liferay-asset:asset-add-button:allAssetCategoryIds", _allAssetCategoryIds);
    request.setAttribute("liferay-asset:asset-add-button:allAssetTagNames", _allAssetTagNames);

    long[] classNameIds = _classNameIds;

    if (classNameIds == null) {
        classNameIds = AssetRendererFactoryRegistryUtil.getClassNameIds(themeDisplay.getCompanyId());
    }/*from   w ww  . j  ava  2  s.c o  m*/

    request.setAttribute("liferay-asset:asset-add-button:classNameIds", classNameIds);

    request.setAttribute("liferay-asset:asset-add-button:classTypeIds", _classTypeIds);

    long[] groupIds = _groupIds;

    if (groupIds == null) {
        groupIds = new long[] { themeDisplay.getScopeGroupId() };
    }

    request.setAttribute("liferay-asset:asset-add-button:groupIds", groupIds);

    request.setAttribute("liferay-asset:asset-add-button:redirect", _redirect);
    request.setAttribute("liferay-asset:asset-add-button:useDialog", _useDialog);
}

From source file:com.liferay.blogs.web.internal.trackback.Trackback.java

License:Open Source License

public void addTrackback(BlogsEntry entry, ThemeDisplay themeDisplay, String excerpt, String url,
        String blogName, String title, Function<String, ServiceContext> serviceContextFunction)
        throws PortalException {

    long userId = _userLocalService.getDefaultUserId(themeDisplay.getCompanyId());
    long groupId = entry.getGroupId();
    String className = BlogsEntry.class.getName();
    long classPK = entry.getEntryId();

    String body = buildBody(themeDisplay, excerpt, url);

    long commentId = _commentManager.addComment(userId, groupId, className, classPK, blogName, title, body,
            serviceContextFunction);/* w  w w. ja va2  s.  co  m*/

    String entryURL = buildEntryURL(entry, themeDisplay);

    _linkbackConsumer.addNewTrackback(commentId, url, entryURL);
}

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  ww  .  j a  va 2  s.c o  m
    searchContext.setUserId(themeDisplay.getUserId());

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

    return indexer.search(searchContext);
}

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

License:Open Source License

protected void serveCalendarBookings(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws IOException, PortalException {

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

    long[] calendarIds = ParamUtil.getLongValues(resourceRequest, "calendarIds");
    java.util.Calendar endTimeJCalendar = getJCalendar(resourceRequest, "endTime");
    java.util.Calendar startTimeJCalendar = getJCalendar(resourceRequest, "startTime");
    int[] statuses = ParamUtil.getIntegerValues(resourceRequest, "statuses");

    List<CalendarBooking> calendarBookings = Collections.<CalendarBooking>emptyList();

    if (!ArrayUtil.isEmpty(calendarIds)) {
        calendarBookings = _calendarBookingService.search(themeDisplay.getCompanyId(), new long[0], calendarIds,
                new long[0], -1, null, startTimeJCalendar.getTimeInMillis(), endTimeJCalendar.getTimeInMillis(),
                true, statuses, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
                new CalendarBookingStartTimeComparator(true));

        int eventsPerPage = ParamUtil.getInteger(resourceRequest, "eventsPerPage");

        if ((eventsPerPage > 0) && (eventsPerPage < calendarBookings.size())) {

            calendarBookings = calendarBookings.subList(0, eventsPerPage);
        }//from   ww  w.j  ava 2 s .c om
    }

    JSONArray jsonArray = CalendarUtil.toCalendarBookingsJSONArray(themeDisplay, calendarBookings,
            getTimeZone(resourceRequest));

    writeJSON(resourceRequest, resourceResponse, jsonArray);
}

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

License:Open Source License

protected void serveCalendarResources(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws Exception {

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

    String keywords = ParamUtil.getString(resourceRequest, "keywords");

    Set<Calendar> calendarsSet = new LinkedHashSet<>();

    Hits hits = search(themeDisplay, keywords);

    for (Document document : hits.getDocs()) {
        long calendarId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

        Calendar calendar = _calendarService.getCalendar(calendarId);

        CalendarResource calendarResource = calendar.getCalendarResource();

        if (calendarResource.isActive()) {
            Group group = _groupLocalService.getGroup(calendar.getGroupId());

            if (group.hasStagingGroup()) {
                Group stagingGroup = group.getStagingGroup();

                long stagingGroupId = stagingGroup.getGroupId();

                if (stagingGroupId == themeDisplay.getScopeGroupId()) {
                    calendar = _calendarLocalService.fetchCalendarByUuidAndGroupId(calendar.getUuid(),
                            stagingGroupId);
                }// ww  w.  jav  a 2 s.c o  m
            }

            calendarsSet.add(calendar);
        }
    }

    String name = StringUtil.merge(CustomSQLUtil.keywords(keywords), StringPool.BLANK);

    LinkedHashMap<String, Object> params = new LinkedHashMap<>();

    params.put("usersGroups", themeDisplay.getUserId());

    List<Group> groups = _groupLocalService.search(themeDisplay.getCompanyId(), name, null, params, true, 0,
            SearchContainer.DEFAULT_DELTA);

    for (Group group : groups) {
        long groupClassNameId = _portal.getClassNameId(Group.class);

        addCalendar(resourceRequest, calendarsSet, groupClassNameId, group.getGroupId());
    }

    long userClassNameId = _portal.getClassNameId(User.class);

    List<User> users = _userLocalService.search(themeDisplay.getCompanyId(), keywords, 0, null, 0,
            SearchContainer.DEFAULT_DELTA, new UserFirstNameComparator());

    for (User user : users) {
        addCalendar(resourceRequest, calendarsSet, userClassNameId, user.getUserId());
    }

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    for (Calendar calendar : calendarsSet) {
        JSONObject jsonObject = CalendarUtil.toCalendarJSONObject(themeDisplay, calendar);

        jsonArray.put(jsonObject);
    }

    writeJSON(resourceRequest, resourceResponse, jsonArray);
}

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

License:Open Source License

protected void serveResourceCalendars(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws Exception {

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

    long calendarResourceId = ParamUtil.getLong(resourceRequest, "calendarResourceId");

    List<Calendar> calendars = _calendarService.search(themeDisplay.getCompanyId(), null,
            new long[] { calendarResourceId }, null, true, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);

    JSONArray jsonArray = CalendarUtil.toCalendarsJSONArray(themeDisplay, calendars);

    writeJSON(resourceRequest, resourceResponse, jsonArray);
}

From source file:com.liferay.comment.taglib.internal.struts.EditDiscussionStrutsAction.java

License:Open Source License

protected long updateComment(HttpServletRequest request) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    long commentId = ParamUtil.getLong(request, "commentId");

    String className = ParamUtil.getString(request, "className");
    long classPK = ParamUtil.getLong(request, "classPK");
    long parentCommentId = ParamUtil.getLong(request, "parentCommentId");
    String subject = ParamUtil.getString(request, "subject");
    String body = ParamUtil.getString(request, "body");

    Function<String, ServiceContext> serviceContextFunction = new ServiceContextFunction(request);

    DiscussionPermission discussionPermission = _getDiscussionPermission(themeDisplay);

    if (commentId <= 0) {

        // Add message

        User user = null;//from   w w w .j  a va  2  s .c  o m

        if (themeDisplay.isSignedIn()) {
            user = themeDisplay.getUser();
        } else {
            String emailAddress = ParamUtil.getString(request, "emailAddress");

            user = _userLocalService.fetchUserByEmailAddress(themeDisplay.getCompanyId(), emailAddress);

            if ((user == null) || (user.getStatus() != WorkflowConstants.STATUS_INCOMPLETE)) {

                return 0;
            }
        }

        String name = PrincipalThreadLocal.getName();

        PrincipalThreadLocal.setName(user.getUserId());

        try {
            discussionPermission.checkAddPermission(themeDisplay.getCompanyId(), themeDisplay.getScopeGroupId(),
                    className, classPK);

            commentId = _commentManager.addComment(user.getUserId(), className, classPK, user.getFullName(),
                    parentCommentId, subject, body, serviceContextFunction);
        } finally {
            PrincipalThreadLocal.setName(name);
        }
    } else {

        // Update message

        if (Validator.isNull(className) || (classPK == 0)) {
            Comment comment = _commentManager.fetchComment(commentId);

            if (comment != null) {
                className = comment.getClassName();
                classPK = comment.getClassPK();
            }
        }

        discussionPermission.checkUpdatePermission(commentId);

        commentId = _commentManager.updateComment(themeDisplay.getUserId(), className, classPK, commentId,
                subject, body, serviceContextFunction);
    }

    // Subscription

    boolean subscribe = ParamUtil.getBoolean(request, "subscribe");

    if (subscribe) {
        _commentManager.subscribeDiscussion(themeDisplay.getUserId(), themeDisplay.getScopeGroupId(), className,
                classPK);
    }

    return commentId;
}

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 www. j  a  v  a  2  s. 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.lists.form.web.internal.display.context.DDLFormDisplayContext.java

License:Open Source License

protected boolean hasWorkflowEnabled(DDLRecordSet recordSet, ThemeDisplay themeDisplay) {

    return _workflowDefinitionLinkLocalService.hasWorkflowDefinitionLink(themeDisplay.getCompanyId(),
            recordSet.getGroupId(), DDLRecordSet.class.getName(), recordSet.getRecordSetId());
}

From source file:com.liferay.dynamic.data.lists.form.web.internal.portlet.action.SaveRecordSetMVCCommandHelper.java

License:Open Source License

protected void updateWorkflowDefinitionLink(PortletRequest portletRequest, DDLRecordSet recordSet,
        DDMFormValues ddmFormValues) throws PortalException {

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

    long groupId = ParamUtil.getLong(portletRequest, "groupId");

    String workflowDefinition = getWorkflowDefinition(ddmFormValues);

    if (workflowDefinition.equals("no-workflow")) {
        workflowDefinition = "";
    }/*from w  w  w . j a  v a 2 s .c  o m*/

    workflowDefinitionLinkLocalService.updateWorkflowDefinitionLink(themeDisplay.getUserId(),
            themeDisplay.getCompanyId(), groupId, DDLRecordSet.class.getName(), recordSet.getRecordSetId(), 0,
            workflowDefinition);
}