use of org.apache.shindig.protocol.RestfulCollection in project liferay-ide by liferay.
the class LiferayMediaItemService method doGetMediaItems.
protected RestfulCollection<MediaItem> doGetMediaItems(UserId userId, String appId, String albumId, Set<String> fields, CollectionOptions collectionOptions, SecurityToken securityToken) throws Exception {
long userIdLong = GetterUtil.getLong(userId.getUserId(securityToken));
User user = UserLocalServiceUtil.getUserById(userIdLong);
List<MediaItem> mediaItems = new ArrayList<MediaItem>();
if (!ShindigUtil.isValidUser(user)) {
return new RestfulCollection<MediaItem>(mediaItems, collectionOptions.getFirst(), mediaItems.size(), collectionOptions.getMax());
}
Group group = user.getGroup();
long groupIdLong = group.getGroupId();
long albumIdLong = GetterUtil.getLong(albumId);
List<FileEntry> fileEntries = DLAppServiceUtil.getFileEntries(groupIdLong, albumIdLong);
for (FileEntry fileEntry : fileEntries) {
MediaItem.Type mediaItemType = toMediaItemType(StringPool.PERIOD.concat(fileEntry.getExtension()));
if (mediaItemType == null) {
continue;
}
MediaItem mediaItem = toMediaItem(fileEntry, fields, securityToken);
mediaItems.add(mediaItem);
}
return new RestfulCollection<MediaItem>(mediaItems, collectionOptions.getFirst(), mediaItems.size(), collectionOptions.getMax());
}
use of org.apache.shindig.protocol.RestfulCollection in project liferay-ide by liferay.
the class LiferayMediaItemService method doGetMediaItems.
protected RestfulCollection<MediaItem> doGetMediaItems(Set<UserId> userIds, GroupId groupId, String appId, Set<String> fields, CollectionOptions collectionOptions, SecurityToken securityToken) throws Exception {
List<MediaItem> mediaItems = new ArrayList<MediaItem>();
for (UserId userId : userIds) {
long userIdLong = GetterUtil.getLong(userId.getUserId(securityToken));
User user = UserLocalServiceUtil.getUserById(userIdLong);
if (!ShindigUtil.isValidUser(user)) {
continue;
}
List<FileEntry> fileEntries = new ArrayList<FileEntry>();
GroupId.Type groupIdType = groupId.getType();
if (groupIdType.equals(GroupId.Type.all) || groupIdType.equals(GroupId.Type.friends) || groupIdType.equals(GroupId.Type.groupId)) {
List<User> socialUsers = UserLocalServiceUtil.getSocialUsers(user.getUserId(), SocialRelationConstants.TYPE_BI_FRIEND, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
for (User socialUser : socialUsers) {
Group group = socialUser.getGroup();
List<FileEntry> friendFileEntries = DLAppServiceUtil.getGroupFileEntries(group.getGroupId(), socialUser.getUserId(), collectionOptions.getFirst(), collectionOptions.getMax());
fileEntries.addAll(friendFileEntries);
}
} else if (groupIdType.equals(GroupId.Type.self)) {
Group group = user.getGroup();
fileEntries = DLAppServiceUtil.getGroupFileEntries(group.getGroupId(), user.getUserId(), collectionOptions.getFirst(), collectionOptions.getMax());
}
for (FileEntry fileEntry : fileEntries) {
MediaItem.Type mediaItemType = toMediaItemType(StringPool.PERIOD.concat(fileEntry.getExtension()));
if (mediaItemType == null) {
continue;
}
MediaItem mediaItem = toMediaItem(fileEntry, fields, securityToken);
mediaItems.add(mediaItem);
}
}
return new RestfulCollection<MediaItem>(mediaItems, collectionOptions.getFirst(), mediaItems.size(), collectionOptions.getMax());
}
Aggregations