use of com.liferay.portal.kernel.repository.model.FileEntry in project liferay-ide by liferay.
the class EditorPortlet method serveGetFolderChildren.
protected void serveGetFolderChildren(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception {
ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);
long repositoryId = ParamUtil.getLong(resourceRequest, "repositoryId");
long folderId = ParamUtil.getLong(resourceRequest, "folderId");
List<Folder> folders = DLAppServiceUtil.getFolders(repositoryId, folderId);
folders = ListUtil.sort(folders, new RepositoryModelNameComparator(true));
JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
for (Folder folder : folders) {
JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
jsonObject.put("entryId", folder.getFolderId());
jsonObject.put("label", folder.getName());
jsonObject.put("leaf", false);
jsonObject.put("type", "editor");
jsonArray.put(jsonObject);
}
boolean getFileEntries = ParamUtil.getBoolean(resourceRequest, "getFileEntries");
if (getFileEntries) {
PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();
List<FileEntry> fileEntries = DLAppServiceUtil.getFileEntries(repositoryId, folderId);
fileEntries = ListUtil.sort(fileEntries, new RepositoryModelNameComparator(true));
for (FileEntry fileEntry : fileEntries) {
JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
jsonObject.put("entryId", fileEntry.getFileEntryId());
String portalURL = PortalUtil.getPortalURL(themeDisplay);
String fileEntryURL = ShindigUtil.getFileEntryURL(portalURL, fileEntry.getFileEntryId());
jsonObject.put("fileEntryURL", fileEntryURL);
long gadgetId = 0;
try {
Gadget gadget = GadgetLocalServiceUtil.getGadget(themeDisplay.getCompanyId(), fileEntryURL);
gadgetId = gadget.getGadgetId();
} catch (Exception e) {
}
jsonObject.put("gadgetId", gadgetId);
jsonObject.put("label", fileEntry.getTitle());
jsonObject.put("leaf", true);
JSONObject jsonPermissions = JSONFactoryUtil.createJSONObject();
if (gadgetId > 0) {
boolean unpublishPermission = GadgetPermission.contains(permissionChecker, themeDisplay.getScopeGroupId(), gadgetId, ActionKeys.DELETE);
jsonPermissions.put("unpublishPermission", unpublishPermission);
}
jsonObject.put("permissions", jsonPermissions);
jsonObject.put("type", "editor");
jsonArray.put(jsonObject);
}
}
writeJSON(resourceRequest, resourceResponse, jsonArray);
}
use of com.liferay.portal.kernel.repository.model.FileEntry 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 com.liferay.portal.kernel.repository.model.FileEntry 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 com.liferay.portal.kernel.repository.model.FileEntry in project liferay-ide by liferay.
the class SongImpl method getFileEntry.
protected FileEntry getFileEntry(ThemeDisplay themeDisplay, String folderName) throws SystemException {
Repository repository = PortletFileRepositoryUtil.fetchPortletRepository(getGroupId(), Constants.JUKEBOX_PORTLET_REPOSITORY);
if (repository == null) {
return null;
}
try {
Folder folder = PortletFileRepositoryUtil.getPortletFolder(0, repository.getRepositoryId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, String.valueOf(getSongId()), null);
Folder songFolder = PortletFileRepositoryUtil.getPortletFolder(0, repository.getRepositoryId(), folder.getFolderId(), folderName, null);
List<FileEntry> fileEntries = PortletFileRepositoryUtil.getPortletFileEntries(themeDisplay.getScopeGroupId(), songFolder.getFolderId());
if (fileEntries.isEmpty()) {
return null;
}
return fileEntries.get(0);
} catch (Exception e) {
return null;
}
}
use of com.liferay.portal.kernel.repository.model.FileEntry in project liferay-ide by liferay.
the class AlbumStagedModelDataHandler method doExportStagedModel.
@Override
protected void doExportStagedModel(PortletDataContext portletDataContext, Album album) throws Exception {
Artist artist = ArtistLocalServiceUtil.getArtist(album.getArtistId());
Element albumElement = portletDataContext.getExportDataElement(album);
if (portletDataContext.getBooleanParameter(JukeboxPortletDataHandler.NAMESPACE, "artists")) {
// Artists are selected to export, making sure this album's artist
// is going to be exported as well
StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, album, artist, PortletDataContext.REFERENCE_TYPE_DEPENDENCY);
} else {
// Artists are not exported - adding missing reference element to
// validate
portletDataContext.addReferenceElement(album, albumElement, artist, PortletDataContext.REFERENCE_TYPE_DEPENDENCY, true);
}
if (album.hasCustomImage()) {
FileEntry fileEntry = album.getCustomImage();
StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, album, Album.class, fileEntry, FileEntry.class, PortletDataContext.REFERENCE_TYPE_WEAK);
}
portletDataContext.addClassedModel(albumElement, ExportImportPathUtil.getModelPath(album), album);
}
Aggregations