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;
}
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());
}
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;
}
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;
}
Aggregations