Search in sources :

Example 11 with Folder

use of com.liferay.portal.kernel.repository.model.Folder in project com-liferay-apio-architect by liferay.

the class MediaObjectNestedCollectionResource method _addFileEntry.

private FileEntry _addFileEntry(Long folderId, MediaObjectCreatorForm mediaObjectCreatorForm) throws PortalException {
    Folder folder = _dlAppService.getFolder(folderId);
    BinaryFile binaryFile = mediaObjectCreatorForm.getBinaryFile();
    return _dlAppService.addFileEntry(folder.getGroupId(), folderId, mediaObjectCreatorForm.getName(), binaryFile.getMimeType(), mediaObjectCreatorForm.getTitle(), mediaObjectCreatorForm.getDescription(), null, binaryFile.getInputStream(), binaryFile.getSize(), new ServiceContext());
}
Also used : ServiceContext(com.liferay.portal.kernel.service.ServiceContext) Folder(com.liferay.portal.kernel.repository.model.Folder) BinaryFile(com.liferay.apio.architect.file.BinaryFile)

Example 12 with Folder

use of com.liferay.portal.kernel.repository.model.Folder in project com-liferay-apio-architect by liferay.

the class MediaObjectNestedCollectionResource method _getPageItems.

private PageItems<FileEntry> _getPageItems(Pagination pagination, Long folderId) throws PortalException {
    Folder folder = _dlAppService.getFolder(folderId);
    List<FileEntry> dlFileEntries = _dlAppService.getFileEntries(folder.getGroupId(), folder.getFolderId(), pagination.getStartPosition(), pagination.getEndPosition());
    int count = _dlAppService.getFileEntriesCount(folder.getGroupId(), folder.getFolderId());
    return new PageItems<>(dlFileEntries, count);
}
Also used : FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) PageItems(com.liferay.apio.architect.pagination.PageItems) Folder(com.liferay.portal.kernel.repository.model.Folder)

Example 13 with Folder

use of com.liferay.portal.kernel.repository.model.Folder in project com-liferay-apio-architect by liferay.

the class FolderNestedCollectionResource method _addFolder.

private Folder _addFolder(Long groupId, FolderForm folderForm) throws PortalException {
    long parentFolderId = 0;
    Try<Folder> folderTry = Try.fromFallible(() -> _dlAppService.getFolder(groupId, parentFolderId, folderForm.getName()));
    if (folderTry.isSuccess()) {
        throw new BadRequestException("A folder with that name already exists");
    }
    return _dlAppService.addFolder(groupId, parentFolderId, folderForm.getName(), folderForm.getDescription(), new ServiceContext());
}
Also used : ServiceContext(com.liferay.portal.kernel.service.ServiceContext) BadRequestException(javax.ws.rs.BadRequestException) Folder(com.liferay.portal.kernel.repository.model.Folder)

Example 14 with Folder

use of com.liferay.portal.kernel.repository.model.Folder in project liferay-ide by liferay.

the class SongLocalServiceImpl method addSong.

@Indexable(type = IndexableType.REINDEX)
public Song addSong(long userId, long albumId, String name, String songFileName, InputStream songInputStream, String lyricsFileName, InputStream lyricsInputStream, ServiceContext serviceContext) throws PortalException, SystemException {
    long groupId = serviceContext.getScopeGroupId();
    User user = userPersistence.findByPrimaryKey(userId);
    Date now = new Date();
    long songId = counterLocalService.increment();
    Album album = albumPersistence.findByPrimaryKey(albumId);
    validate(songId, groupId, album.getArtistId(), albumId, name);
    Song song = songPersistence.create(songId);
    song.setUuid(serviceContext.getUuid());
    song.setGroupId(groupId);
    song.setCompanyId(user.getCompanyId());
    song.setUserId(user.getUserId());
    song.setUserName(user.getFullName());
    song.setCreateDate(serviceContext.getCreateDate(now));
    song.setModifiedDate(serviceContext.getModifiedDate(now));
    song.setArtistId(album.getArtistId());
    song.setAlbumId(albumId);
    song.setName(name);
    song.setExpandoBridgeAttributes(serviceContext);
    songPersistence.update(song);
    if ((songInputStream != null) || (lyricsInputStream != null)) {
        Repository repository = PortletFileRepositoryUtil.addPortletRepository(groupId, Constants.JUKEBOX_PORTLET_REPOSITORY, serviceContext);
        Folder folder = PortletFileRepositoryUtil.addPortletFolder(userId, repository.getRepositoryId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, String.valueOf(song.getSongId()), serviceContext);
        if (songInputStream != null) {
            Folder songFolder = PortletFileRepositoryUtil.addPortletFolder(userId, repository.getRepositoryId(), folder.getFolderId(), Constants.SONGS_FOLDER_NAME, serviceContext);
            FileEntry fileEntry = PortletFileRepositoryUtil.addPortletFileEntry(groupId, userId, Song.class.getName(), song.getSongId(), Constants.JUKEBOX_PORTLET_REPOSITORY, songFolder.getFolderId(), songInputStream, songFileName, StringPool.BLANK, true);
            DLProcessorRegistryUtil.trigger(fileEntry, null, true);
        }
        if (lyricsInputStream != null) {
            Folder lyricsFolder = PortletFileRepositoryUtil.addPortletFolder(userId, repository.getRepositoryId(), folder.getFolderId(), Constants.LYRICS_FOLDER_NAME, serviceContext);
            FileEntry fileEntry = PortletFileRepositoryUtil.addPortletFileEntry(groupId, userId, Song.class.getName(), song.getSongId(), Constants.JUKEBOX_PORTLET_REPOSITORY, lyricsFolder.getFolderId(), lyricsInputStream, lyricsFileName, StringPool.BLANK, true);
            DLProcessorRegistryUtil.trigger(fileEntry, null, true);
        }
    }
    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {
        addEntryResources(song, serviceContext.isAddGroupPermissions(), serviceContext.isAddGuestPermissions());
    } else {
        addEntryResources(song, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions());
    }
    // Message boards
    mbMessageLocalService.addDiscussionMessage(userId, album.getUserName(), groupId, Song.class.getName(), songId, WorkflowConstants.ACTION_PUBLISH);
    // Asset
    updateAsset(userId, song, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds());
    return song;
}
Also used : Song(org.liferay.jukebox.model.Song) Repository(com.liferay.portal.model.Repository) User(com.liferay.portal.model.User) Album(org.liferay.jukebox.model.Album) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) Folder(com.liferay.portal.kernel.repository.model.Folder) Date(java.util.Date) Indexable(com.liferay.portal.kernel.search.Indexable)

Example 15 with Folder

use of com.liferay.portal.kernel.repository.model.Folder in project liferay-ide by liferay.

the class SongLocalServiceImpl method updateSong.

@Indexable(type = IndexableType.REINDEX)
public Song updateSong(long userId, long songId, long albumId, String name, String songFileName, InputStream songInputStream, String lyricsFileName, InputStream lyricsInputStream, ServiceContext serviceContext) throws PortalException, SystemException {
    // Event
    User user = userPersistence.findByPrimaryKey(userId);
    Song song = songPersistence.findByPrimaryKey(songId);
    Album album = albumPersistence.findByPrimaryKey(albumId);
    validate(songId, song.getGroupId(), album.getArtistId(), albumId, name);
    song.setModifiedDate(serviceContext.getModifiedDate(null));
    song.setArtistId(album.getArtistId());
    song.setAlbumId(albumId);
    song.setName(name);
    song.setExpandoBridgeAttributes(serviceContext);
    songPersistence.update(song);
    if ((songInputStream != null) || (lyricsInputStream != null)) {
        Repository repository = PortletFileRepositoryUtil.addPortletRepository(serviceContext.getScopeGroupId(), Constants.JUKEBOX_PORTLET_REPOSITORY, serviceContext);
        Folder folder = PortletFileRepositoryUtil.addPortletFolder(userId, repository.getRepositoryId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, String.valueOf(song.getSongId()), serviceContext);
        if (songInputStream != null) {
            Folder songFolder = PortletFileRepositoryUtil.addPortletFolder(userId, repository.getRepositoryId(), folder.getFolderId(), Constants.SONGS_FOLDER_NAME, serviceContext);
            List<FileEntry> fileEntries = PortletFileRepositoryUtil.getPortletFileEntries(serviceContext.getScopeGroupId(), songFolder.getFolderId());
            for (FileEntry fileEntry : fileEntries) {
                PortletFileRepositoryUtil.deletePortletFileEntry(fileEntry.getFileEntryId());
                DLProcessorRegistryUtil.cleanUp(fileEntry);
            }
            FileEntry fileEntry = PortletFileRepositoryUtil.addPortletFileEntry(serviceContext.getScopeGroupId(), userId, Song.class.getName(), song.getSongId(), Constants.JUKEBOX_PORTLET_REPOSITORY, songFolder.getFolderId(), songInputStream, songFileName, StringPool.BLANK, true);
            triggerDLProcessors(fileEntry);
        }
        if (lyricsInputStream != null) {
            Folder lyricsFolder = PortletFileRepositoryUtil.addPortletFolder(userId, repository.getRepositoryId(), folder.getFolderId(), Constants.LYRICS_FOLDER_NAME, serviceContext);
            List<FileEntry> fileEntries = PortletFileRepositoryUtil.getPortletFileEntries(serviceContext.getScopeGroupId(), lyricsFolder.getFolderId());
            for (FileEntry fileEntry : fileEntries) {
                PortletFileRepositoryUtil.deletePortletFileEntry(fileEntry.getFileEntryId());
                DLProcessorRegistryUtil.cleanUp(fileEntry);
            }
            FileEntry fileEntry = PortletFileRepositoryUtil.addPortletFileEntry(serviceContext.getScopeGroupId(), userId, Song.class.getName(), song.getSongId(), Constants.JUKEBOX_PORTLET_REPOSITORY, lyricsFolder.getFolderId(), lyricsInputStream, lyricsFileName, StringPool.BLANK, true);
            triggerDLProcessors(fileEntry);
        }
    }
    // Asset
    updateAsset(userId, song, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds());
    return song;
}
Also used : Song(org.liferay.jukebox.model.Song) Repository(com.liferay.portal.model.Repository) User(com.liferay.portal.model.User) Album(org.liferay.jukebox.model.Album) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) Folder(com.liferay.portal.kernel.repository.model.Folder) Indexable(com.liferay.portal.kernel.search.Indexable)

Aggregations

Folder (com.liferay.portal.kernel.repository.model.Folder)19 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)7 ServiceContext (com.liferay.portal.service.ServiceContext)6 PortalException (com.liferay.portal.kernel.exception.PortalException)5 SystemException (com.liferay.portal.kernel.exception.SystemException)5 Repository (com.liferay.portal.model.Repository)5 User (com.liferay.portal.model.User)5 JSONObject (com.liferay.portal.kernel.json.JSONObject)4 DLFolder (com.liferay.portlet.documentlibrary.model.DLFolder)4 Indexable (com.liferay.portal.kernel.search.Indexable)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Song (org.liferay.jukebox.model.Song)3 NoSuchGroupException (com.liferay.portal.NoSuchGroupException)2 RepositoryException (com.liferay.portal.kernel.repository.RepositoryException)2 ServiceContext (com.liferay.portal.kernel.service.ServiceContext)2 Group (com.liferay.portal.model.Group)2 PrincipalException (com.liferay.portal.security.auth.PrincipalException)2 ThemeDisplay (com.liferay.portal.theme.ThemeDisplay)2 NoSuchFileEntryException (com.liferay.portlet.documentlibrary.NoSuchFileEntryException)2