Example usage for com.liferay.portal.kernel.service GroupLocalServiceUtil getGroup

List of usage examples for com.liferay.portal.kernel.service GroupLocalServiceUtil getGroup

Introduction

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

Prototype

public static com.liferay.portal.kernel.model.Group getGroup(long companyId, String groupKey)
        throws com.liferay.portal.kernel.exception.PortalException 

Source Link

Document

Returns the group with the matching group key.

Usage

From source file:com.liferay.calendar.notification.impl.NotificationTemplateContextFactory.java

License:Open Source License

public static NotificationTemplateContext getInstance(NotificationType notificationType,
        NotificationTemplateType notificationTemplateType, CalendarBooking calendarBooking, User user)
        throws Exception {

    CalendarBooking parentCalendarBooking = calendarBooking.getParentCalendarBooking();

    Calendar calendar = parentCalendarBooking.getCalendar();

    NotificationTemplateContext notificationTemplateContext = new NotificationTemplateContext();

    CalendarNotificationTemplate calendarNotificationTemplate = CalendarNotificationTemplateLocalServiceUtil
            .fetchCalendarNotificationTemplate(calendar.getCalendarId(), notificationType,
                    notificationTemplateType);

    notificationTemplateContext.setCalendarNotificationTemplate(calendarNotificationTemplate);

    notificationTemplateContext.setCompanyId(calendarBooking.getCompanyId());
    notificationTemplateContext.setGroupId(calendarBooking.getGroupId());
    notificationTemplateContext.setCalendarId(calendar.getCalendarId());
    notificationTemplateContext.setNotificationTemplateType(notificationTemplateType);
    notificationTemplateContext.setNotificationType(notificationType);

    // Attributes

    Map<String, Serializable> attributes = new HashMap<>();

    TimeZone userTimezone = user.getTimeZone();

    Format dateFormatDateTime = FastDateFormatFactoryUtil.getDateTime(user.getLocale(),
            CalendarUtil.getCalendarBookingDisplayTimeZone(calendarBooking, userTimezone));

    String userTimezoneDisplayName = userTimezone.getDisplayName(false, TimeZone.SHORT, user.getLocale());

    String endTime = dateFormatDateTime.format(calendarBooking.getEndTime()) + StringPool.SPACE
            + userTimezoneDisplayName;//from ww  w. ja va2 s. c o  m

    attributes.put("endTime", endTime);

    attributes.put("location", calendarBooking.getLocation());

    Group group = GroupLocalServiceUtil.getGroup(user.getCompanyId(), GroupConstants.GUEST);

    String portalURL = _getPortalURL(group.getCompanyId(), group.getGroupId());

    attributes.put("portalURL", portalURL);

    PortletConfig portletConfig = getPortletConfig();

    ResourceBundle resourceBundle = portletConfig.getResourceBundle(user.getLocale());

    attributes.put("portletName",
            LanguageUtil.get(resourceBundle, "javax.portlet.title.".concat(CalendarPortletKeys.CALENDAR)));

    String startTime = dateFormatDateTime.format(calendarBooking.getStartTime()) + StringPool.SPACE
            + userTimezoneDisplayName;

    attributes.put("startTime", startTime);

    attributes.put("title", calendarBooking.getTitle(user.getLocale()));

    String calendarBookingURL = _getCalendarBookingURL(user, calendarBooking.getCalendarBookingId());

    attributes.put("url", calendarBookingURL);

    notificationTemplateContext.setAttributes(attributes);

    return notificationTemplateContext;
}

From source file:com.liferay.calendar.notification.impl.NotificationTemplateContextFactory.java

License:Open Source License

private static String _getCalendarBookingURL(User user, long calendarBookingId) throws PortalException {

    Group group = GroupLocalServiceUtil.getGroup(user.getCompanyId(), GroupConstants.GUEST);

    Layout layout = LayoutLocalServiceUtil.fetchLayout(group.getDefaultPublicPlid());

    String portalURL = _getPortalURL(group.getCompanyId(), group.getGroupId());

    String layoutActualURL = PortalUtil.getLayoutActualURL(layout);

    String url = portalURL + layoutActualURL;

    String namespace = PortalUtil.getPortletNamespace(CalendarPortletKeys.CALENDAR);

    url = HttpUtil.addParameter(url, namespace + "mvcPath", "/view_calendar_booking.jsp");

    url = HttpUtil.addParameter(url, "p_p_id", CalendarPortletKeys.CALENDAR);
    url = HttpUtil.addParameter(url, "p_p_lifecycle", "0");
    url = HttpUtil.addParameter(url, "p_p_state", WindowState.MAXIMIZED.toString());
    url = HttpUtil.addParameter(url, namespace + "calendarBookingId", calendarBookingId);

    return url;//  w  w w .  j ava2s .  co m
}

From source file:com.liferay.exportimport.resources.importer.internal.util.BaseImporter.java

License:Open Source License

@Override
public void afterPropertiesSet() throws Exception {
    User user = UserLocalServiceUtil.getDefaultUser(companyId);

    userId = user.getUserId();/*from  w w  w  .  java  2s  .c o  m*/

    if (isCompanyGroup()) {
        return;
    }

    Group group = null;

    if (targetClassName.equals(LayoutSetPrototype.class.getName())) {
        LayoutSetPrototype layoutSetPrototype = getLayoutSetPrototype(companyId, targetValue);

        if (layoutSetPrototype != null) {
            existing = true;
        } else {
            layoutSetPrototype = LayoutSetPrototypeLocalServiceUtil.addLayoutSetPrototype(userId, companyId,
                    getTargetValueMap(), new HashMap<Locale, String>(), true, true, new ServiceContext());
        }

        group = layoutSetPrototype.getGroup();

        targetClassPK = layoutSetPrototype.getLayoutSetPrototypeId();
    } else if (targetClassName.equals(Group.class.getName())) {
        if (targetValue.equals(GroupConstants.GLOBAL)) {
            group = GroupLocalServiceUtil.getCompanyGroup(companyId);
        } else if (targetValue.equals(GroupConstants.GUEST)) {
            group = GroupLocalServiceUtil.getGroup(companyId, GroupConstants.GUEST);

            List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(group.getGroupId(), false,
                    LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, false, 0, 1);

            if (!layouts.isEmpty()) {
                Layout layout = layouts.get(0);

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

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

                if (portletIds.size() != 2) {
                    existing = true;
                }

                for (String portletId : portletIds) {
                    if (!portletId.equals("47") && !portletId.equals("58")) {

                        existing = true;
                    }
                }
            }
        } else {
            group = GroupLocalServiceUtil.fetchGroup(companyId, targetValue);

            if (group != null) {
                int privateLayoutPageCount = group.getPrivateLayoutsPageCount();

                int publicLayoutPageCount = group.getPublicLayoutsPageCount();

                if ((privateLayoutPageCount != 0) || (publicLayoutPageCount != 0)) {

                    existing = true;
                }
            } else {
                group = GroupLocalServiceUtil.addGroup(userId, GroupConstants.DEFAULT_PARENT_GROUP_ID,
                        StringPool.BLANK, GroupConstants.DEFAULT_PARENT_GROUP_ID,
                        GroupConstants.DEFAULT_LIVE_GROUP_ID, getMap(targetValue), null,
                        GroupConstants.TYPE_SITE_OPEN, true, GroupConstants.DEFAULT_MEMBERSHIP_RESTRICTION,
                        null, true, true, new ServiceContext());
            }
        }

        targetClassPK = group.getGroupId();
    }

    if (group != null) {
        groupId = group.getGroupId();
    }
}

From source file:com.liferay.site.browser.web.internal.display.context.SiteBrowserDisplayContext.java

License:Open Source License

public GroupSearch getGroupSearch() throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    Company company = themeDisplay.getCompany();

    GroupSearch groupSearch = new GroupSearch(_liferayPortletRequest, getPortletURL());

    GroupSearchTerms groupSearchTerms = (GroupSearchTerms) groupSearch.getSearchTerms();

    List<Group> results = new ArrayList<>();

    int additionalSites = 0;
    int total = 0;

    boolean includeCompany = ParamUtil.getBoolean(_request, "includeCompany");
    boolean includeUserPersonalSite = ParamUtil.getBoolean(_request, "includeUserPersonalSite");

    long[] classNameIds = _CLASS_NAME_IDS;

    if (includeCompany) {
        classNameIds = ArrayUtil.append(classNameIds, PortalUtil.getClassNameId(Company.class));
    }//from w  w  w  .  j  av a2 s .co m

    if (includeUserPersonalSite) {
        if (groupSearch.getStart() == 0) {
            Group userPersonalSite = GroupLocalServiceUtil.getGroup(company.getCompanyId(),
                    GroupConstants.USER_PERSONAL_SITE);

            results.add(userPersonalSite);
        }

        additionalSites++;
    }

    String type = getType();

    if (type.equals("layoutScopes")) {
        total = GroupLocalServiceUtil.getGroupsCount(themeDisplay.getCompanyId(), Layout.class.getName(),
                getGroupId());
    } else if (type.equals("parent-sites")) {
    } else {
        total = GroupLocalServiceUtil.searchCount(themeDisplay.getCompanyId(), classNameIds,
                groupSearchTerms.getKeywords(), getGroupParams());
    }

    total += additionalSites;

    groupSearch.setTotal(total);

    int start = groupSearch.getStart();

    if (groupSearch.getStart() > additionalSites) {
        start = groupSearch.getStart() - additionalSites;
    }

    List<Group> groups = null;

    if (type.equals("layoutScopes")) {
        groups = GroupLocalServiceUtil.getGroups(company.getCompanyId(), Layout.class.getName(), getGroupId(),
                start, groupSearch.getResultEnd() - additionalSites);

        groups = _filterLayoutGroups(groups, isPrivateLayout());
    } else if (type.equals("parent-sites")) {
        Group group = GroupLocalServiceUtil.getGroup(getGroupId());

        groups = group.getAncestors();

        String filter = getFilter();

        if (Validator.isNotNull(filter)) {
            groups = _filterGroups(groups, filter);
        }

        total = groups.size();

        total += additionalSites;

        groupSearch.setTotal(total);
    } else {
        groups = GroupLocalServiceUtil.search(company.getCompanyId(), classNameIds,
                groupSearchTerms.getKeywords(), getGroupParams(), QueryUtil.ALL_POS, QueryUtil.ALL_POS,
                groupSearch.getOrderByComparator());

        groups = _filterGroups(groups, themeDisplay.getPermissionChecker());

        total = groups.size();

        total += additionalSites;

        groupSearch.setTotal(total);

        groups = groups.subList(start, groupSearch.getResultEnd() - additionalSites);
    }

    results.addAll(groups);

    groupSearch.setResults(results);

    return groupSearch;
}

From source file:it.sysdata.base.service.impl.UserHelperLocalServiceImpl.java

License:Open Source License

public User addUserEmail(String emailAddress, String password, String firstName, String lastName,
        ServiceContext serviceContext) throws PortalException, SystemException {

    HttpServletRequest httpServletRequest = serviceContext.getRequest();
    Locale locale = PortalUtil.getLocale(httpServletRequest);

    String userAgent = httpServletRequest.getHeader("User-Agent");

    _validateUser(emailAddress, password, serviceContext);

    long companyId = serviceContext.getCompanyId();

    long[] groupIds = new long[1];
    long[] roleIds = null;
    long[] userGroupIds = null;
    long[] organizationIds = null;

    if (Validator.isNotNull(PortletPropsValues.API_NEWUSER_USERGROUP_MEMBER)) {

        UserGroup userGroup = UserGroupLocalServiceUtil.getUserGroup(companyId,
                PortletPropsValues.API_NEWUSER_USERGROUP_MEMBER);

        userGroupIds = new long[] { userGroup.getUserGroupId() };
    }/*from ww w . j  ava 2 s .c om*/

    if (Validator.isNotNull(PortletPropsValues.API_NEWUSER_GROUPNAME_MEMBER)) {

        Group group = GroupLocalServiceUtil.getGroup(companyId,
                PortletPropsValues.API_NEWUSER_GROUPNAME_MEMBER);

        if (group.getGroupId() > 0) {
            groupIds[0] = group.getGroupId();
        } else {
            groupIds = null;
        }
    }

    //      Role role = RoleLocalServiceUtil.getRole(companyId, "roleName");

    //      if (role.getRoleId() > 0) {
    //         roleIds[0] = role.getRoleId();
    //      }
    //      else {
    //         roleIds = null;
    //      }

    User user = UserLocalServiceUtil.addUser(0, companyId, false, password, password, true, null, emailAddress,
            0, null, locale, firstName, null, lastName, 0, 0, true, 1, 1, 1970, null, groupIds, organizationIds,
            roleIds, userGroupIds, PortletPropsValues.API_NEWUSER_SENDEMAIL, serviceContext);

    _log.info(
            String.format("addUserEmail %s, %s, %s > %s", emailAddress, password, userAgent, user.getUserId()));

    return user;
}