Search in sources :

Example 1 with TrashVersion

use of com.liferay.portlet.trash.model.TrashVersion in project liferay-ide by liferay.

the class SongLocalServiceImpl method moveSongFromTrash.

@Override
public Song moveSongFromTrash(long userId, long songId, long albumId) throws PortalException, SystemException {
    Song song = getSong(songId);
    TrashEntry trashEntry = song.getTrashEntry();
    if (trashEntry.isTrashEntry(Song.class, songId)) {
        restoreSongFromTrash(userId, songId);
    } else {
        // Entry
        TrashVersion trashVersion = trashVersionLocalService.fetchVersion(trashEntry.getEntryId(), Song.class.getName(), songId);
        int status = WorkflowConstants.STATUS_APPROVED;
        if (trashVersion != null) {
            status = trashVersion.getStatus();
        }
        ServiceContext serviceContext = new ServiceContext();
        // Entry
        User user = userPersistence.findByPrimaryKey(userId);
        Date now = new Date();
        song.setModifiedDate(serviceContext.getModifiedDate(now));
        song.setStatus(status);
        song.setStatusByUserId(user.getUserId());
        song.setStatusByUserName(user.getFullName());
        song.setStatusDate(serviceContext.getModifiedDate(now));
        songPersistence.update(song);
        // Asset
        assetEntryLocalService.updateVisible(Song.class.getName(), song.getSongId(), false);
        // Indexer
        Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(Song.class);
        indexer.reindex(song);
        if (trashVersion != null) {
            trashVersionLocalService.deleteTrashVersion(trashVersion);
        }
    }
    return songLocalService.moveSong(songId, albumId);
}
Also used : Song(org.liferay.jukebox.model.Song) TrashEntry(com.liferay.portlet.trash.model.TrashEntry) User(com.liferay.portal.model.User) Indexer(com.liferay.portal.kernel.search.Indexer) ServiceContext(com.liferay.portal.service.ServiceContext) TrashVersion(com.liferay.portlet.trash.model.TrashVersion) Date(java.util.Date)

Example 2 with TrashVersion

use of com.liferay.portlet.trash.model.TrashVersion 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)

Aggregations

Indexer (com.liferay.portal.kernel.search.Indexer)2 TrashEntry (com.liferay.portlet.trash.model.TrashEntry)2 TrashVersion (com.liferay.portlet.trash.model.TrashVersion)2 Song (org.liferay.jukebox.model.Song)2 User (com.liferay.portal.model.User)1 ServiceContext (com.liferay.portal.service.ServiceContext)1 Date (java.util.Date)1