Example usage for com.liferay.portal.kernel.service OrganizationLocalServiceUtil getUserOrganizations

List of usage examples for com.liferay.portal.kernel.service OrganizationLocalServiceUtil getUserOrganizations

Introduction

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

Prototype

public static java.util.List<com.liferay.portal.kernel.model.Organization> getUserOrganizations(long userId) 

Source Link

Usage

From source file:com.gleo.groupphoto.web.portlet.action.ViewUserDetailsActionMVCRenderCommand.java

License:Open Source License

@Override
public String render(RenderRequest renderRequest, RenderResponse renderResponse) {

    long userId = ParamUtil.getLong(renderRequest, "userId");
    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);

    String organizationsHTML = StringPool.BLANK;
    Contact contact = null;/*from  w  ww  .ja v a2 s.c om*/
    List<Organization> organizations = null;
    User user = null;
    Company company = null;
    Locale locale = themeDisplay.getLocale();

    String birthday = null;
    String jobTitle = null;
    String gender = null;
    String comments = null;

    // Get User
    if (userId > 0) {

        try {
            user = UserLocalServiceUtil.getUser(userId);
            company = CompanyLocalServiceUtil.getCompany(user.getCompanyId());

        } catch (PortalException e) {
            LOGGER.error(e);
        }

        if (user != null) {
            // Get Contact
            try {
                contact = user.getContact();

            } catch (PortalException e) {
                LOGGER.error(e);
            }

            // Get Organizations
            organizations = OrganizationLocalServiceUtil.getUserOrganizations(user.getUserId());
            StringBundler organizationsHTMLBundler = new StringBundler(organizations.size() * 2);

            if (!organizations.isEmpty()) {
                organizationsHTMLBundler.append(organizations.get(0).getName());
            }

            for (int i = 1; i < organizations.size(); i++) {
                organizationsHTMLBundler.append(", ");
                organizationsHTMLBundler.append(organizations.get(i).getName());
            }
            organizationsHTML = organizationsHTMLBundler.toString();

            // Fields
            setFields(renderRequest, contact, user, company, locale, birthday, gender, jobTitle);

            // Contact
            String className = Contact.class.getName();
            long classPK = contact.getContactId();

            List<Address> personalAddresses = Collections.emptyList();
            List<Address> organizationAddresses = new ArrayList<Address>();
            List<EmailAddress> emailAddresses = Collections.emptyList();
            List<Website> websites = Collections.emptyList();
            List<Phone> personalPhones = Collections.emptyList();
            List<Phone> organizationPhones = new ArrayList<Phone>();

            if (classPK > 0) {
                try {
                    personalAddresses = AddressServiceUtil.getAddresses(className, classPK);
                } catch (PortalException pe) {
                    LOGGER.error(pe);
                }

                try {
                    emailAddresses = EmailAddressServiceUtil.getEmailAddresses(className, classPK);
                } catch (PortalException pe) {
                    LOGGER.error(pe);
                }

                try {
                    websites = WebsiteServiceUtil.getWebsites(className, classPK);
                } catch (PortalException pe) {
                    LOGGER.error(pe);
                }
                try {
                    personalPhones = PhoneServiceUtil.getPhones(className, classPK);
                } catch (PortalException pe) {
                    LOGGER.error(pe);
                }

            }

            for (int i = 0; i < organizations.size(); i++) {
                try {
                    organizationAddresses.addAll(AddressServiceUtil.getAddresses(Organization.class.getName(),
                            organizations.get(i).getOrganizationId()));
                } catch (Exception e) {
                }
            }

            for (int i = 0; i < organizations.size(); i++) {
                try {
                    organizationPhones.addAll(PhoneServiceUtil.getPhones(Organization.class.getName(),
                            organizations.get(i).getOrganizationId()));
                } catch (Exception e) {
                }
            }

            // Comments
            comments = user.getComments();

            LOGGER.info("comments" + comments);
            if (comments != null && !comments.trim().equals(StringPool.BLANK)) {
                comments = StringUtil.replace(BBCodeTranslatorUtil.getHTML(user.getComments()),
                        ThemeConstants.TOKEN_THEME_IMAGES_PATH + EMOTICONS,
                        themeDisplay.getPathThemeImages() + EMOTICONS);
            }

            renderRequest.setAttribute("organizationAddresses", organizationAddresses);
            renderRequest.setAttribute("personalAddresses", personalAddresses);
            renderRequest.setAttribute("emailAddresses", emailAddresses);
            renderRequest.setAttribute("organizationAddresses", organizationAddresses);
            renderRequest.setAttribute("websites", websites);
            renderRequest.setAttribute("personalPhones", personalPhones);
            renderRequest.setAttribute("organizationPhones", organizationPhones);

        }
    }

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("userId =" + userId);
        LOGGER.debug("birthday =" + birthday);
        LOGGER.debug("gender =" + gender);
        LOGGER.debug("jobTitle =" + jobTitle);
        LOGGER.debug("comments =" + comments);
    }

    renderRequest.setAttribute("organizations", organizations);
    renderRequest.setAttribute("organizationsHTML", organizationsHTML);
    renderRequest.setAttribute("user2", user);
    renderRequest.setAttribute("contact", contact);
    renderRequest.setAttribute("languageUtil", LanguageUtil.getLanguage());
    renderRequest.setAttribute("locale", locale);
    renderRequest.setAttribute("comments", comments);
    renderRequest.setAttribute("htmlUtil", HtmlUtil.getHtml());

    return "/userdetails/jsp/user_details.jsp";
}

From source file:com.liferaystack.activator.LiferaystackActivatorLoginPreAction.java

License:Apache License

@Override
public void processLifecycleEvent(LifecycleEvent lifecycleEvent) throws ActionException {
    HttpServletRequest request = lifecycleEvent.getRequest();
    System.out.println("http request is " + request);
    try {/*from ww  w. j  av a2  s .  c o  m*/
        long userId = PortalUtil.getUser(request).getUserId();
        System.out.println("userId is >>>>>>>>>>>>>>>>>>>" + userId);
        List<Organization> organizations = OrganizationLocalServiceUtil.getUserOrganizations(userId);

        for (Organization organization : organizations) {
            System.out.println("users organisation is " + organization);
            Group organizationGroup = GroupLocalServiceUtil.getOrganizationGroup(organization.getCompanyId(),
                    organization.getOrganizationId());
            List<Layout> privateLayouts = LayoutLocalServiceUtil.getLayouts(organizationGroup.getGroupId(),
                    true);
            List<Layout> publicLayouts = LayoutLocalServiceUtil.getLayouts(organizationGroup.getGroupId(),
                    false);
            String rightURL = null;
            for (Layout layout : publicLayouts) {
                //if(layout.getP){
                rightURL = PortalUtil.getLayoutActualURL(layout);
                System.out.println("rightURL : " + rightURL);

                //}

            }
        }

    } catch (PortalException e) {
        e.printStackTrace();
    }
    System.out.println("login.event.post=" + lifecycleEvent + ", session s: ");
}

From source file:eu.gerhards.liferay.services.angular.service.impl.AngularOrganizationServiceImpl.java

License:Open Source License

public long[] checkOrganizations(long userId, long[] organizationIds) throws PortalException {

    long[] oldOrganizationIds = null;

    PermissionChecker permissionChecker = getPermissionChecker();

    if (userId != CompanyConstants.SYSTEM) {

        // Add back any mandatory organizations or organizations that the
        // administrator does not have the rights to remove and check that
        // he has the permission to add a new organization

        List<Organization> oldOrganizations = OrganizationLocalServiceUtil.getUserOrganizations(userId);

        oldOrganizationIds = new long[oldOrganizations.size()];

        for (int i = 0; i < oldOrganizations.size(); i++) {
            Organization organization = oldOrganizations.get(i);

            if (!ArrayUtil.contains(organizationIds, organization.getOrganizationId())
                    && (!OrganizationPermissionUtil.contains(permissionChecker, organization,
                            ActionKeys.ASSIGN_MEMBERS)
                            || OrganizationMembershipPolicyUtil.isMembershipProtected(permissionChecker, userId,
                                    organization.getOrganizationId())
                            || OrganizationMembershipPolicyUtil.isMembershipRequired(userId,
                                    organization.getOrganizationId()))) {

                organizationIds = ArrayUtil.append(organizationIds, organization.getOrganizationId());
            }/*from ww  w. j  av  a 2  s  .  c  o  m*/

            oldOrganizationIds[i] = organization.getOrganizationId();
        }
    }

    // Check that the administrator has the permission to add a new
    // organization and that the organization membership is allowed

    for (long organizationId : organizationIds) {
        if ((oldOrganizationIds != null) && ArrayUtil.contains(oldOrganizationIds, organizationId)) {

            continue;
        }

        Organization organization = OrganizationLocalServiceUtil.getOrganization(organizationId);

        OrganizationPermissionUtil.check(permissionChecker, organization, ActionKeys.ASSIGN_MEMBERS);
    }

    return organizationIds;
}

From source file:eu.gerhards.liferay.services.angular.service.impl.AngularUserServiceImpl.java

License:Open Source License

@Override
public User getUser(long userId) throws PortalException {

    _log.info("getting user with id: " + String.valueOf(userId));

    _log.debug("    ... security check ...");

    PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.VIEW);

    _log.debug("    ... getting information");

    User user = UserLocalServiceUtil.getUser(userId);
    Contact userContact = ContactLocalServiceUtil.getContact(user.getContactId());

    List<Role> userRoles = RoleLocalServiceUtil.getUserRoles(user.getUserId());
    List<Group> userGroups = GroupLocalServiceUtil.getUserGroups(user.getUserId());
    List<Organization> userOrganizations = OrganizationLocalServiceUtil.getUserOrganizations(user.getUserId());
    List<UserGroup> userUserGroups = UserGroupLocalServiceUtil.getUserUserGroups(user.getUserId());

    return user;//from   w w w . ja v a  2s . c  o m
}