Search in sources :

Example 1 with Repository

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

the class ArtistLocalServiceImpl method updateArtist.

@Indexable(type = IndexableType.REINDEX)
public Artist updateArtist(long userId, long artistId, String name, String bio, InputStream inputStream, ServiceContext serviceContext) throws PortalException, SystemException {
    // Event
    User user = userPersistence.findByPrimaryKey(userId);
    validate(name);
    Artist artist = artistPersistence.findByPrimaryKey(artistId);
    artist.setModifiedDate(serviceContext.getModifiedDate(null));
    artist.setName(name);
    artist.setBio(bio);
    artist.setExpandoBridgeAttributes(serviceContext);
    artistPersistence.update(artist);
    if (inputStream != null) {
        Repository repository = PortletFileRepositoryUtil.fetchPortletRepository(serviceContext.getScopeGroupId(), Constants.JUKEBOX_PORTLET_REPOSITORY);
        if (repository != null) {
            try {
                PortletFileRepositoryUtil.deletePortletFileEntry(repository.getRepositoryId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, String.valueOf(artist.getArtistId()));
            } catch (Exception e) {
                if (_log.isDebugEnabled()) {
                    _log.debug("Cannot delete artist image");
                }
            }
        }
        PortletFileRepositoryUtil.addPortletFileEntry(serviceContext.getScopeGroupId(), userId, Artist.class.getName(), artist.getArtistId(), Constants.JUKEBOX_PORTLET_REPOSITORY, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, inputStream, String.valueOf(artist.getArtistId()), StringPool.BLANK, true);
    }
    // Asset
    updateAsset(userId, artist, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds());
    return artist;
}
Also used : Artist(org.liferay.jukebox.model.Artist) Repository(com.liferay.portal.model.Repository) User(com.liferay.portal.model.User) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException) ArtistNameException(org.liferay.jukebox.ArtistNameException) Indexable(com.liferay.portal.kernel.search.Indexable)

Example 2 with Repository

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

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

the class KBArticleAttachmentsUtil method getFolderId.

public static long getFolderId(long groupId, long userId, long resourcePrimKey) throws PortalException, SystemException {
    ServiceContext serviceContext = new ServiceContext();
    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);
    Repository repository = PortletFileRepositoryUtil.addPortletRepository(groupId, PortletKeys.KNOWLEDGE_BASE_ARTICLE, serviceContext);
    Folder folder = PortletFileRepositoryUtil.addPortletFolder(userId, repository.getRepositoryId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, String.valueOf(resourcePrimKey), serviceContext);
    return folder.getFolderId();
}
Also used : Repository(com.liferay.portal.model.Repository) ServiceContext(com.liferay.portal.service.ServiceContext) Folder(com.liferay.portal.kernel.repository.model.Folder)

Example 4 with Repository

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

the class AlbumLocalServiceImpl method updateAlbum.

@Indexable(type = IndexableType.REINDEX)
public Album updateAlbum(long userId, long albumId, long artistId, String name, int year, InputStream inputStream, ServiceContext serviceContext) throws PortalException, SystemException {
    // Event
    User user = userPersistence.findByPrimaryKey(userId);
    validate(name);
    Album album = albumPersistence.findByPrimaryKey(albumId);
    album.setModifiedDate(serviceContext.getModifiedDate(null));
    album.setArtistId(artistId);
    album.setName(name);
    album.setYear(year);
    album.setExpandoBridgeAttributes(serviceContext);
    albumPersistence.update(album);
    if (inputStream != null) {
        Repository repository = PortletFileRepositoryUtil.fetchPortletRepository(serviceContext.getScopeGroupId(), Constants.JUKEBOX_PORTLET_REPOSITORY);
        if (repository != null) {
            try {
                PortletFileRepositoryUtil.deletePortletFileEntry(repository.getRepositoryId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, String.valueOf(album.getAlbumId()));
            } catch (Exception e) {
                if (_log.isDebugEnabled()) {
                    _log.debug("Cannot delete album cover");
                }
            }
        }
        PortletFileRepositoryUtil.addPortletFileEntry(serviceContext.getScopeGroupId(), userId, Album.class.getName(), album.getAlbumId(), Constants.JUKEBOX_PORTLET_REPOSITORY, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, inputStream, String.valueOf(album.getAlbumId()), StringPool.BLANK, true);
    }
    // Asset
    updateAsset(userId, album, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds());
    return album;
}
Also used : Repository(com.liferay.portal.model.Repository) User(com.liferay.portal.model.User) 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 5 with Repository

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

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