Search in sources :

Example 96 with Song

use of org.liferay.jukebox.model.Song in project liferay-ide by liferay.

the class AlbumLocalServiceImpl method restoreDependentsFromTrash.

protected void restoreDependentsFromTrash(List<Song> songs, long trashEntryId) throws PortalException, SystemException {
    for (Song song : songs) {
        // Song
        TrashEntry trashEntry = trashEntryLocalService.fetchEntry(Song.class.getName(), song.getSongId());
        if (trashEntry != null) {
            continue;
        }
        TrashVersion trashVersion = trashVersionLocalService.fetchVersion(trashEntryId, Song.class.getName(), song.getSongId());
        int oldStatus = WorkflowConstants.STATUS_APPROVED;
        if (trashVersion != null) {
            oldStatus = trashVersion.getStatus();
        }
        song.setStatus(oldStatus);
        songPersistence.update(song);
        if (trashVersion != null) {
            trashVersionLocalService.deleteTrashVersion(trashVersion);
        }
        if (oldStatus == WorkflowConstants.STATUS_APPROVED) {
            assetEntryLocalService.updateVisible(Song.class.getName(), song.getSongId(), true);
        }
        // Indexer
        Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(Song.class);
        indexer.reindex(song);
    }
}
Also used : Song(org.liferay.jukebox.model.Song) TrashEntry(com.liferay.portlet.trash.model.TrashEntry) Indexer(com.liferay.portal.kernel.search.Indexer) TrashVersion(com.liferay.portlet.trash.model.TrashVersion)

Example 97 with Song

use of org.liferay.jukebox.model.Song in project liferay-ide by liferay.

the class AlbumLocalServiceImpl method deleteAlbum.

@Indexable(type = IndexableType.DELETE)
public Album deleteAlbum(long albumId) throws PortalException, SystemException {
    Album album = albumPersistence.findByPrimaryKey(albumId);
    List<Song> songs = songLocalService.getSongsByAlbumId(albumId);
    for (Song song : songs) {
        songLocalService.deleteSong(song.getSongId());
    }
    try {
        PortletFileRepositoryUtil.deletePortletFileEntry(album.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, String.valueOf(albumId));
    } catch (Exception e) {
    }
    return albumPersistence.remove(albumId);
}
Also used : Song(org.liferay.jukebox.model.Song) Album(org.liferay.jukebox.model.Album) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException) AlbumNameException(org.liferay.jukebox.AlbumNameException) Indexable(com.liferay.portal.kernel.search.Indexable)

Example 98 with Song

use of org.liferay.jukebox.model.Song 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 99 with Song

use of org.liferay.jukebox.model.Song in project liferay-ide by liferay.

the class SongLocalServiceImpl method moveSongToTrash.

@Indexable(type = IndexableType.REINDEX)
public Song moveSongToTrash(long userId, Song song) throws PortalException, SystemException {
    ServiceContext serviceContext = new ServiceContext();
    // Entry
    User user = userPersistence.findByPrimaryKey(userId);
    Date now = new Date();
    int oldStatus = song.getStatus();
    song.setModifiedDate(serviceContext.getModifiedDate(now));
    song.setStatus(WorkflowConstants.STATUS_IN_TRASH);
    song.setStatusByUserId(user.getUserId());
    song.setStatusByUserName(user.getFullName());
    song.setStatusDate(serviceContext.getModifiedDate(now));
    // Asset
    assetEntryLocalService.updateVisible(Song.class.getName(), song.getSongId(), false);
    // Trash
    UnicodeProperties typeSettingsProperties = new UnicodeProperties();
    typeSettingsProperties.put("title", song.getName());
    TrashEntry trashEntry = trashEntryLocalService.addTrashEntry(userId, song.getGroupId(), Song.class.getName(), song.getSongId(), song.getUuid(), null, oldStatus, null, typeSettingsProperties);
    song.setName(TrashUtil.getTrashTitle(trashEntry.getEntryId()));
    songPersistence.update(song);
    return song;
}
Also used : Song(org.liferay.jukebox.model.Song) User(com.liferay.portal.model.User) TrashEntry(com.liferay.portlet.trash.model.TrashEntry) UnicodeProperties(com.liferay.portal.kernel.util.UnicodeProperties) ServiceContext(com.liferay.portal.service.ServiceContext) Date(java.util.Date) Indexable(com.liferay.portal.kernel.search.Indexable)

Example 100 with Song

use of org.liferay.jukebox.model.Song 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

Song (org.liferay.jukebox.model.Song)110 NoSuchSongException (org.liferay.jukebox.NoSuchSongException)61 StringBundler (com.liferay.portal.kernel.util.StringBundler)59 SystemException (com.liferay.portal.kernel.exception.SystemException)39 Session (com.liferay.portal.kernel.dao.orm.Session)37 SQLQuery (com.liferay.portal.kernel.dao.orm.SQLQuery)35 QueryPos (com.liferay.portal.kernel.dao.orm.QueryPos)34 Query (com.liferay.portal.kernel.dao.orm.Query)25 ArrayList (java.util.ArrayList)22 UnmodifiableList (com.liferay.portal.kernel.util.UnmodifiableList)19 List (java.util.List)19 SongImpl (org.liferay.jukebox.model.impl.SongImpl)19 FinderPath (com.liferay.portal.kernel.dao.orm.FinderPath)12 Indexable (com.liferay.portal.kernel.search.Indexable)9 User (com.liferay.portal.model.User)7 ServiceContext (com.liferay.portal.service.ServiceContext)6 TrashEntry (com.liferay.portlet.trash.model.TrashEntry)6 Date (java.util.Date)6 Album (org.liferay.jukebox.model.Album)6 Folder (com.liferay.portal.kernel.repository.model.Folder)3