Example usage for com.liferay.portal.kernel.service EmailAddressServiceUtil getEmailAddresses

List of usage examples for com.liferay.portal.kernel.service EmailAddressServiceUtil getEmailAddresses

Introduction

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

Prototype

public static java.util.List<com.liferay.portal.kernel.model.EmailAddress> getEmailAddresses(String className,
            long classPK) throws com.liferay.portal.kernel.exception.PortalException 

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  .j  ava 2  s.com
    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";
}