Search in sources :

Example 6 with Repository

use of com.liferay.portal.model.Repository 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)

Example 7 with Repository

use of com.liferay.portal.model.Repository in project liferay-ide by liferay.

the class SongLocalServiceImpl method deleteSong.

@Indexable(type = IndexableType.DELETE)
public Song deleteSong(long songId) throws PortalException, SystemException {
    Song song = songPersistence.findByPrimaryKey(songId);
    Repository repository = PortletFileRepositoryUtil.fetchPortletRepository(song.getGroupId(), Constants.JUKEBOX_PORTLET_REPOSITORY);
    if (repository != null) {
        try {
            Folder folder = PortletFileRepositoryUtil.getPortletFolder(0, repository.getRepositoryId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, String.valueOf(songId), null);
            PortletFileRepositoryUtil.deleteFolder(folder.getFolderId());
        } catch (Exception e) {
        }
    }
    return songPersistence.remove(songId);
}
Also used : Song(org.liferay.jukebox.model.Song) Repository(com.liferay.portal.model.Repository) Folder(com.liferay.portal.kernel.repository.model.Folder) SongNameException(org.liferay.jukebox.SongNameException) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException) DuplicatedSongException(org.liferay.jukebox.DuplicatedSongException) Indexable(com.liferay.portal.kernel.search.Indexable)

Aggregations

Repository (com.liferay.portal.model.Repository)7 Folder (com.liferay.portal.kernel.repository.model.Folder)5 Indexable (com.liferay.portal.kernel.search.Indexable)5 PortalException (com.liferay.portal.kernel.exception.PortalException)4 SystemException (com.liferay.portal.kernel.exception.SystemException)4 User (com.liferay.portal.model.User)4 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)3 Album (org.liferay.jukebox.model.Album)3 Song (org.liferay.jukebox.model.Song)3 ServiceContext (com.liferay.portal.service.ServiceContext)1 Date (java.util.Date)1 AlbumNameException (org.liferay.jukebox.AlbumNameException)1 ArtistNameException (org.liferay.jukebox.ArtistNameException)1 DuplicatedSongException (org.liferay.jukebox.DuplicatedSongException)1 SongNameException (org.liferay.jukebox.SongNameException)1 Artist (org.liferay.jukebox.model.Artist)1