Search in sources :

Example 1 with MediaItem

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

the class LiferayActivityService method getMediaItems.

protected JSONArray getMediaItems(List<MediaItem> mediaItems) {
    if (mediaItems == null) {
        return null;
    }
    JSONArray mediaItemsJSONArray = JSONFactoryUtil.createJSONArray();
    for (MediaItem mediaItem : mediaItems) {
        JSONObject mediaItemsJsonObject = JSONFactoryUtil.createJSONObject();
        mediaItemsJsonObject.put("mimeType", mediaItem.getMimeType());
        mediaItemsJsonObject.put("type", String.valueOf(mediaItem.getType()));
        mediaItemsJsonObject.put("url", mediaItem.getUrl());
        mediaItemsJSONArray.put(mediaItemsJsonObject);
    }
    return mediaItemsJSONArray;
}
Also used : JSONObject(com.liferay.portal.kernel.json.JSONObject) MediaItem(org.apache.shindig.social.opensocial.model.MediaItem) JSONArray(com.liferay.portal.kernel.json.JSONArray)

Example 2 with MediaItem

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

the class LiferayMediaItemService method toMediaItem.

protected MediaItem toMediaItem(FileEntry fileEntry, Set<String> fields, SecurityToken securityToken) throws Exception {
    MediaItem mediaItem = new MediaItemImpl();
    mediaItem.setAlbumId(String.valueOf(fileEntry.getFolderId()));
    mediaItem.setCreated(String.valueOf(fileEntry.getCreateDate()));
    mediaItem.setDescription(fileEntry.getDescription());
    mediaItem.setId(String.valueOf(fileEntry.getFileEntryId()));
    mediaItem.setLastUpdated(String.valueOf(fileEntry.getModifiedDate()));
    mediaItem.setMimeType(MimeTypesUtil.getContentType(StringPool.PERIOD.concat(fileEntry.getExtension())));
    mediaItem.setNumViews(String.valueOf(fileEntry.getReadCount()));
    mediaItem.setTitle(fileEntry.getTitle());
    mediaItem.setType(toMediaItemType(StringPool.PERIOD.concat(fileEntry.getExtension())));
    String fileEntryURL = ShindigUtil.getFileEntryURL(securityToken.getDomain(), fileEntry.getFileEntryId());
    mediaItem.setUrl(fileEntryURL);
    FileVersion fileVersion = fileEntry.getLatestFileVersion();
    SerializerUtil.copyProperties(fileVersion.getAttributes(), mediaItem, _MEDIA_ITEM_FIELDS);
    return mediaItem;
}
Also used : MediaItemImpl(org.apache.shindig.social.core.model.MediaItemImpl) MediaItem(org.apache.shindig.social.opensocial.model.MediaItem) FileVersion(com.liferay.portal.kernel.repository.model.FileVersion)

Example 3 with MediaItem

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

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

Example 5 with MediaItem

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

the class LiferayActivityService method getMediaItems.

protected List<MediaItem> getMediaItems(JSONArray mediaItemsJSONArray) {
    if (mediaItemsJSONArray == null) {
        return null;
    }
    List<MediaItem> mediaItems = new ArrayList<MediaItem>();
    for (int i = 0; i < mediaItemsJSONArray.length(); i++) {
        JSONObject mediaItemsJsonObject = mediaItemsJSONArray.getJSONObject(i);
        MediaItem mediaItem = new MediaItemImpl(mediaItemsJsonObject.getString("mimeType"), Type.valueOf(mediaItemsJsonObject.getString("type")), mediaItemsJsonObject.getString("url"));
        mediaItems.add(mediaItem);
    }
    return mediaItems;
}
Also used : MediaItemImpl(org.apache.shindig.social.core.model.MediaItemImpl) JSONObject(com.liferay.portal.kernel.json.JSONObject) MediaItem(org.apache.shindig.social.opensocial.model.MediaItem) ArrayList(java.util.ArrayList)

Aggregations

MediaItem (org.apache.shindig.social.opensocial.model.MediaItem)5 ArrayList (java.util.ArrayList)3 JSONObject (com.liferay.portal.kernel.json.JSONObject)2 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)2 Group (com.liferay.portal.model.Group)2 User (com.liferay.portal.model.User)2 DLFileEntry (com.liferay.portlet.documentlibrary.model.DLFileEntry)2 RestfulCollection (org.apache.shindig.protocol.RestfulCollection)2 MediaItemImpl (org.apache.shindig.social.core.model.MediaItemImpl)2 Type (org.apache.shindig.social.opensocial.model.MediaItem.Type)2 JSONArray (com.liferay.portal.kernel.json.JSONArray)1 FileVersion (com.liferay.portal.kernel.repository.model.FileVersion)1 GroupId (org.apache.shindig.social.opensocial.spi.GroupId)1 UserId (org.apache.shindig.social.opensocial.spi.UserId)1