Search in sources :

Example 6 with RestfulCollection

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());
}
Also used : Group(com.liferay.portal.model.Group) User(com.liferay.portal.model.User) MediaItem(org.apache.shindig.social.opensocial.model.MediaItem) ArrayList(java.util.ArrayList) RestfulCollection(org.apache.shindig.protocol.RestfulCollection) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry) Type(org.apache.shindig.social.opensocial.model.MediaItem.Type)

Example 7 with RestfulCollection

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());
}
Also used : Group(com.liferay.portal.model.Group) User(com.liferay.portal.model.User) ArrayList(java.util.ArrayList) RestfulCollection(org.apache.shindig.protocol.RestfulCollection) GroupId(org.apache.shindig.social.opensocial.spi.GroupId) Type(org.apache.shindig.social.opensocial.model.MediaItem.Type) MediaItem(org.apache.shindig.social.opensocial.model.MediaItem) UserId(org.apache.shindig.social.opensocial.spi.UserId) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry)

Aggregations

RestfulCollection (org.apache.shindig.protocol.RestfulCollection)7 ArrayList (java.util.ArrayList)6 User (com.liferay.portal.model.User)4 UserId (org.apache.shindig.social.opensocial.spi.UserId)4 Group (com.liferay.portal.model.Group)3 GroupId (org.apache.shindig.social.opensocial.spi.GroupId)3 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)2 Folder (com.liferay.portal.kernel.repository.model.Folder)2 ThemeDisplay (com.liferay.portal.theme.ThemeDisplay)2 DLFileEntry (com.liferay.portlet.documentlibrary.model.DLFileEntry)2 DLFolder (com.liferay.portlet.documentlibrary.model.DLFolder)2 SocialActivity (com.liferay.portlet.social.model.SocialActivity)2 Activity (org.apache.shindig.social.opensocial.model.Activity)2 Album (org.apache.shindig.social.opensocial.model.Album)2 MediaItem (org.apache.shindig.social.opensocial.model.MediaItem)2 Type (org.apache.shindig.social.opensocial.model.MediaItem.Type)2 Person (org.apache.shindig.social.opensocial.model.Person)1