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