Search in sources :

Example 1 with Person

use of org.apache.shindig.social.opensocial.model.Person 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 Person

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

the class LiferayPersonService method doGetPeople.

protected RestfulCollection<Person> doGetPeople(Set<UserId> userIds, GroupId groupId, CollectionOptions collectionOptions, Set<String> fields, SecurityToken securityToken) throws Exception {
    List<Person> people = new ArrayList<Person>();
    for (UserId userId : userIds) {
        Person person = null;
        String userIdString = userId.getUserId(securityToken);
        GroupId.Type groupIdType = groupId.getType();
        if (groupIdType.equals(GroupId.Type.all) || groupIdType.equals(GroupId.Type.friends) || groupIdType.equals(GroupId.Type.groupId)) {
            long userIdLong = GetterUtil.getLong(userIdString);
            User user = UserLocalServiceUtil.getUserById(userIdLong);
            List<User> friends = UserLocalServiceUtil.getSocialUsers(user.getUserId(), SocialRelationConstants.TYPE_BI_FRIEND, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
            for (User friend : friends) {
                person = getUserPerson(friend, fields, securityToken);
                people.add(person);
            }
        } else if (groupIdType.equals(GroupId.Type.self)) {
            person = doGetPerson(userId, fields, securityToken);
            people.add(person);
        }
    }
    return new RestfulCollection<Person>(people, collectionOptions.getFirst(), people.size(), collectionOptions.getMax());
}
Also used : User(com.liferay.portal.model.User) UserId(org.apache.shindig.social.opensocial.spi.UserId) ArrayList(java.util.ArrayList) RestfulCollection(org.apache.shindig.protocol.RestfulCollection) Person(org.apache.shindig.social.opensocial.model.Person) GroupId(org.apache.shindig.social.opensocial.spi.GroupId)

Example 3 with Person

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

the class LiferayPersonService method doGetPerson.

protected Person doGetPerson(UserId userId, Set<String> fields, SecurityToken securityToken) throws Exception {
    String userIdString = userId.getUserId(securityToken);
    Person person = null;
    if (userIdString.startsWith("G-")) {
        String groupId = userIdString.substring("G-".length());
        person = getGroupPerson(groupId);
    } else {
        long userIdLong = GetterUtil.getLong(userIdString);
        User user = UserLocalServiceUtil.getUserById(userIdLong);
        if (!ShindigUtil.isValidUser(user)) {
            return null;
        }
        person = getUserPerson(user, fields, securityToken);
    }
    return person;
}
Also used : User(com.liferay.portal.model.User) Person(org.apache.shindig.social.opensocial.model.Person)

Example 4 with Person

use of org.apache.shindig.social.opensocial.model.Person 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

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