Search in sources :

Example 6 with FileEntry

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);
}
Also used : Gadget(com.liferay.opensocial.model.Gadget) JSONArray(com.liferay.portal.kernel.json.JSONArray) Folder(com.liferay.portal.kernel.repository.model.Folder) IOException(java.io.IOException) PortletException(javax.portlet.PortletException) RepositoryModelNameComparator(com.liferay.portlet.documentlibrary.util.comparator.RepositoryModelNameComparator) JSONObject(com.liferay.portal.kernel.json.JSONObject) PermissionChecker(com.liferay.portal.security.permission.PermissionChecker) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay)

Example 7 with FileEntry

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());
}
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 8 with FileEntry

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());
}
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 9 with FileEntry

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;
    }
}
Also used : Repository(com.liferay.portal.model.Repository) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) Folder(com.liferay.portal.kernel.repository.model.Folder) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException)

Example 10 with FileEntry

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);
}
Also used : Artist(org.liferay.jukebox.model.Artist) Element(com.liferay.portal.kernel.xml.Element) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry)

Aggregations

FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)34 DLFileEntry (com.liferay.portlet.documentlibrary.model.DLFileEntry)15 PortalException (com.liferay.portal.kernel.exception.PortalException)8 Folder (com.liferay.portal.kernel.repository.model.Folder)7 ServiceContext (com.liferay.portal.service.ServiceContext)6 IOException (java.io.IOException)6 SystemException (com.liferay.portal.kernel.exception.SystemException)5 JSONObject (com.liferay.portal.kernel.json.JSONObject)5 Element (com.liferay.portal.kernel.xml.Element)5 User (com.liferay.portal.model.User)5 NoSuchFileEntryException (com.liferay.portlet.documentlibrary.NoSuchFileEntryException)5 InputStream (java.io.InputStream)5 StringBundler (com.liferay.portal.kernel.util.StringBundler)4 ArrayList (java.util.ArrayList)4 NoSuchGroupException (com.liferay.portal.NoSuchGroupException)3 RepositoryException (com.liferay.portal.kernel.repository.RepositoryException)3 FileVersion (com.liferay.portal.kernel.repository.model.FileVersion)3 Group (com.liferay.portal.model.Group)3 Repository (com.liferay.portal.model.Repository)3 PrincipalException (com.liferay.portal.security.auth.PrincipalException)3