Search in sources :

Example 1 with ListField

use of org.apache.shindig.social.opensocial.model.ListField in project liferay-ide by liferay.

the class LiferayPersonService method getGroupPerson.

protected Person getGroupPerson(String groupId) throws Exception {
    Person person = null;
    long groupIdLong = GetterUtil.getLong(groupId);
    Group group = GroupLocalServiceUtil.getGroup(groupIdLong);
    if (group.isOrganization()) {
        Organization organization = OrganizationLocalServiceUtil.getOrganization(group.getClassPK());
        Name name = new NameImpl(organization.getName() + " (Organization)");
        person = new PersonImpl(groupId, name.getFormatted(), name);
        List<ListField> phoneNumbers = getPhoneNumbers(Organization.class.getName(), organization.getOrganizationId());
        person.setPhoneNumbers(phoneNumbers);
    } else if (group.isRegularSite()) {
        Name name = new NameImpl(group.getName() + " (Site)");
        person = new PersonImpl(groupId, name.getFormatted(), name);
    }
    person.setGender(Gender.male);
    return person;
}
Also used : Group(com.liferay.portal.model.Group) NameImpl(org.apache.shindig.social.core.model.NameImpl) Organization(com.liferay.portal.model.Organization) PersonImpl(org.apache.shindig.social.core.model.PersonImpl) ListField(org.apache.shindig.social.opensocial.model.ListField) Person(org.apache.shindig.social.opensocial.model.Person) Name(org.apache.shindig.social.opensocial.model.Name)

Example 2 with ListField

use of org.apache.shindig.social.opensocial.model.ListField in project liferay-ide by liferay.

the class LiferayPersonService method getPhoneNumbers.

protected List<ListField> getPhoneNumbers(String className, long classPK) throws Exception {
    List<ListField> phoneNumbers = new ArrayList<ListField>();
    List<com.liferay.portal.model.Phone> liferayPhones = PhoneServiceUtil.getPhones(className, classPK);
    for (com.liferay.portal.model.Phone liferayPhone : liferayPhones) {
        ListField phoneNumber = new ListFieldImpl(liferayPhone.getType().getName(), liferayPhone.getNumber());
        phoneNumbers.add(phoneNumber);
    }
    return phoneNumbers;
}
Also used : ListFieldImpl(org.apache.shindig.social.core.model.ListFieldImpl) ArrayList(java.util.ArrayList) ListField(org.apache.shindig.social.opensocial.model.ListField)

Example 3 with ListField

use of org.apache.shindig.social.opensocial.model.ListField in project liferay-ide by liferay.

the class LiferayPersonService method getEmails.

protected List<ListField> getEmails(User user) throws Exception {
    List<ListField> emails = new ArrayList<ListField>();
    ListField email = new ListFieldImpl(Field.PRIMARY.toString(), user.getEmailAddress());
    emails.add(email);
    List<EmailAddress> emailAddresses = EmailAddressLocalServiceUtil.getEmailAddresses(user.getCompanyId(), User.class.getName(), user.getUserId());
    for (EmailAddress emailAddress : emailAddresses) {
        email = new ListFieldImpl(emailAddress.getType().getName(), emailAddress.getAddress());
        emails.add(email);
    }
    return emails;
}
Also used : ListFieldImpl(org.apache.shindig.social.core.model.ListFieldImpl) User(com.liferay.portal.model.User) ArrayList(java.util.ArrayList) ListField(org.apache.shindig.social.opensocial.model.ListField) EmailAddress(com.liferay.portal.model.EmailAddress)

Example 4 with ListField

use of org.apache.shindig.social.opensocial.model.ListField in project liferay-ide by liferay.

the class LiferayPersonService method getUserPerson.

protected Person getUserPerson(User user, Set<String> fields, SecurityToken securityToken) throws Exception {
    Name name = new NameImpl(user.getFullName());
    Person person = new PersonImpl(String.valueOf(user.getUserId()), user.getScreenName(), name);
    StringBundler sb = new StringBundler(4);
    sb.append(securityToken.getDomain());
    sb.append(PortalUtil.getPathFriendlyURLPublic());
    sb.append(StringPool.SLASH);
    sb.append(user.getScreenName());
    person.setProfileUrl(sb.toString());
    sb.setIndex(0);
    sb.append(securityToken.getDomain());
    sb.append(PortalUtil.getPathImage());
    sb.append("/user_");
    sb.append(user.isFemale() ? "female" : "male");
    sb.append("_portrait?img_id=");
    sb.append(user.getPortraitId());
    sb.append("&t=");
    sb.append(WebServerServletTokenUtil.getToken(user.getPortraitId()));
    person.setThumbnailUrl(sb.toString());
    if (fields.contains(Person.Field.ABOUT_ME.toString())) {
        person.setAboutMe(user.getComments());
    }
    if (fields.contains(Person.Field.AGE.toString())) {
        Calendar birthday = new GregorianCalendar();
        birthday.setTime(user.getBirthday());
        Calendar today = Calendar.getInstance();
        int age = today.get(Calendar.YEAR) - birthday.get(Calendar.YEAR);
        birthday.add(Calendar.YEAR, age);
        if (today.before(birthday)) {
            age--;
        }
        person.setAge(age);
    }
    if (fields.contains(Person.Field.BIRTHDAY.toString())) {
        person.setBirthday(user.getBirthday());
    }
    if (fields.contains(Person.Field.EMAILS)) {
        person.setEmails(getEmails(user));
    }
    if (fields.contains(Person.Field.GENDER.toString())) {
        if (user.isFemale()) {
            person.setGender(Gender.female);
        } else {
            person.setGender(Gender.male);
        }
    }
    if (fields.contains(Person.Field.NICKNAME.toString())) {
        person.setNickname(user.getScreenName());
    }
    if (fields.contains(Person.Field.PHONE_NUMBERS.toString())) {
        List<ListField> phoneNumbers = getPhoneNumbers(Contact.class.getName(), user.getContactId());
        person.setPhoneNumbers(phoneNumbers);
    }
    if (fields.contains(Person.Field.UTC_OFFSET.toString())) {
        person.setUtcOffset(new Long(user.getTimeZone().getRawOffset()));
    }
    if (securityToken.getOwnerId().equals(person.getId())) {
        person.setIsOwner(true);
    }
    if (securityToken.getViewerId().equals(person.getId())) {
        person.setIsViewer(true);
    }
    return person;
}
Also used : NameImpl(org.apache.shindig.social.core.model.NameImpl) PersonImpl(org.apache.shindig.social.core.model.PersonImpl) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) ListField(org.apache.shindig.social.opensocial.model.ListField) Person(org.apache.shindig.social.opensocial.model.Person) StringBundler(com.liferay.portal.kernel.util.StringBundler) Name(org.apache.shindig.social.opensocial.model.Name) Contact(com.liferay.portal.model.Contact)

Aggregations

ListField (org.apache.shindig.social.opensocial.model.ListField)4 ArrayList (java.util.ArrayList)2 ListFieldImpl (org.apache.shindig.social.core.model.ListFieldImpl)2 NameImpl (org.apache.shindig.social.core.model.NameImpl)2 PersonImpl (org.apache.shindig.social.core.model.PersonImpl)2 Name (org.apache.shindig.social.opensocial.model.Name)2 Person (org.apache.shindig.social.opensocial.model.Person)2 StringBundler (com.liferay.portal.kernel.util.StringBundler)1 Contact (com.liferay.portal.model.Contact)1 EmailAddress (com.liferay.portal.model.EmailAddress)1 Group (com.liferay.portal.model.Group)1 Organization (com.liferay.portal.model.Organization)1 User (com.liferay.portal.model.User)1 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1