Example usage for com.liferay.portal.kernel.model User fetchContact

List of usage examples for com.liferay.portal.kernel.model User fetchContact

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.model User fetchContact.

Prototype

public Contact fetchContact();

Source Link

Usage

From source file:com.liferay.users.admin.web.internal.portlet.action.UpdateContactInformationMVCActionCommand.java

License:Open Source License

private void _updateContact(User user, String facebookSn, String jabberSn, String skypeSn, String smsSn,
        String twitterSn) throws Exception {

    facebookSn = StringUtil.toLowerCase(StringUtil.trim(facebookSn));
    jabberSn = StringUtil.toLowerCase(StringUtil.trim(jabberSn));
    skypeSn = StringUtil.toLowerCase(StringUtil.trim(skypeSn));
    twitterSn = StringUtil.toLowerCase(StringUtil.trim(twitterSn));

    if (Validator.isNotNull(smsSn) && !Validator.isEmailAddress(smsSn)) {
        throw new UserSmsException.MustBeEmailAddress(smsSn);
    }//from   w w  w.ja v a2  s .  co  m

    Contact contact = user.fetchContact();

    if (contact == null) {
        contact = _contactLocalService.createContact(user.getContactId());

        contact.setCompanyId(user.getCompanyId());
        contact.setUserName(StringPool.BLANK);
        contact.setClassName(User.class.getName());
        contact.setClassPK(user.getUserId());

        Company company = _companyLocalService.getCompany(user.getCompanyId());

        contact.setAccountId(company.getAccountId());

        contact.setParentContactId(ContactConstants.DEFAULT_PARENT_CONTACT_ID);
    }

    contact.setFacebookSn(facebookSn);
    contact.setJabberSn(jabberSn);
    contact.setSkypeSn(skypeSn);
    contact.setSmsSn(smsSn);
    contact.setTwitterSn(twitterSn);

    _contactLocalService.updateContact(contact);
}

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

License:Open Source License

@Override
public Contact getUserContact(long userId) throws PortalException {

    _log.info("Getting contact record for 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 contact = null;/*from   w  w  w  . j  a  v  a  2 s . com*/

    if (user != null) {
        contact = user.fetchContact();
    }

    return contact;
}