Search in sources :

Example 1 with TrashEntry

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

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

the class ArtistClp method getTrashEntry.

@Override
public TrashEntry getTrashEntry() throws PortalException, SystemException {
    if (!isInTrash()) {
        return null;
    }
    TrashEntry trashEntry = TrashEntryLocalServiceUtil.fetchEntry(getModelClassName(), getTrashEntryClassPK());
    if (trashEntry != null) {
        return trashEntry;
    }
    TrashHandler trashHandler = getTrashHandler();
    if (!Validator.isNull(trashHandler.getContainerModelClassName())) {
        ContainerModel containerModel = trashHandler.getParentContainerModel(this);
        while (containerModel != null) {
            if (containerModel instanceof TrashedModel) {
                TrashedModel trashedModel = (TrashedModel) containerModel;
                return trashedModel.getTrashEntry();
            }
            trashHandler = TrashHandlerRegistryUtil.getTrashHandler(trashHandler.getContainerModelClassName());
            if (trashHandler == null) {
                return null;
            }
            containerModel = trashHandler.getContainerModel(containerModel.getParentContainerModelId());
        }
    }
    return null;
}
Also used : TrashEntry(com.liferay.portlet.trash.model.TrashEntry) TrashHandler(com.liferay.portal.kernel.trash.TrashHandler) TrashedModel(com.liferay.portal.model.TrashedModel) ContainerModel(com.liferay.portal.model.ContainerModel)

Example 3 with TrashEntry

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

the class AlbumLocalServiceImpl method moveAlbumToTrash.

@Indexable(type = IndexableType.REINDEX)
@Override
public Album moveAlbumToTrash(long userId, long albumId) throws PortalException, SystemException {
    ServiceContext serviceContext = new ServiceContext();
    // Folder
    User user = userPersistence.findByPrimaryKey(userId);
    Date now = new Date();
    Album album = albumPersistence.findByPrimaryKey(albumId);
    int oldStatus = album.getStatus();
    album.setModifiedDate(serviceContext.getModifiedDate(now));
    album.setStatus(WorkflowConstants.STATUS_IN_TRASH);
    album.setStatusByUserId(user.getUserId());
    album.setStatusByUserName(user.getFullName());
    album.setStatusDate(serviceContext.getModifiedDate(now));
    albumPersistence.update(album);
    // Asset
    assetEntryLocalService.updateVisible(Album.class.getName(), album.getAlbumId(), false);
    // Trash
    TrashEntry trashEntry = trashEntryLocalService.addTrashEntry(userId, album.getGroupId(), Album.class.getName(), album.getAlbumId(), album.getUuid(), null, oldStatus, null, null);
    // Folders and entries
    List<Song> songs = songLocalService.getSongsByAlbumId(album.getAlbumId());
    moveDependentsToTrash(songs, trashEntry.getEntryId());
    return album;
}
Also used : Song(org.liferay.jukebox.model.Song) User(com.liferay.portal.model.User) TrashEntry(com.liferay.portlet.trash.model.TrashEntry) ServiceContext(com.liferay.portal.service.ServiceContext) Album(org.liferay.jukebox.model.Album) Date(java.util.Date) Indexable(com.liferay.portal.kernel.search.Indexable)

Example 4 with TrashEntry

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

the class AlbumLocalServiceImpl method restoreAlbumFromTrash.

@Indexable(type = IndexableType.REINDEX)
@Override
public Album restoreAlbumFromTrash(long userId, long albumId) throws PortalException, SystemException {
    ServiceContext serviceContext = new ServiceContext();
    // Folder
    User user = userPersistence.findByPrimaryKey(userId);
    Date now = new Date();
    Album album = albumPersistence.findByPrimaryKey(albumId);
    TrashEntry trashEntry = trashEntryLocalService.getEntry(Album.class.getName(), albumId);
    album.setModifiedDate(serviceContext.getModifiedDate(now));
    album.setStatus(trashEntry.getStatus());
    album.setStatusByUserId(user.getUserId());
    album.setStatusByUserName(user.getFullName());
    album.setStatusDate(serviceContext.getModifiedDate(now));
    albumPersistence.update(album);
    assetEntryLocalService.updateVisible(Album.class.getName(), album.getAlbumId(), true);
    // Songs
    List<Song> songs = songLocalService.getSongsByAlbumId(album.getGroupId(), album.getAlbumId(), WorkflowConstants.STATUS_IN_TRASH);
    restoreDependentsFromTrash(songs, trashEntry.getEntryId());
    // Trash
    trashEntryLocalService.deleteEntry(trashEntry.getEntryId());
    return album;
}
Also used : Song(org.liferay.jukebox.model.Song) User(com.liferay.portal.model.User) TrashEntry(com.liferay.portlet.trash.model.TrashEntry) ServiceContext(com.liferay.portal.service.ServiceContext) Album(org.liferay.jukebox.model.Album) Date(java.util.Date) Indexable(com.liferay.portal.kernel.search.Indexable)

Example 5 with TrashEntry

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

the class SongModelImpl method getTrashEntry.

@Override
public TrashEntry getTrashEntry() throws PortalException, SystemException {
    if (!isInTrash()) {
        return null;
    }
    TrashEntry trashEntry = TrashEntryLocalServiceUtil.fetchEntry(getModelClassName(), getTrashEntryClassPK());
    if (trashEntry != null) {
        return trashEntry;
    }
    TrashHandler trashHandler = getTrashHandler();
    if (!Validator.isNull(trashHandler.getContainerModelClassName())) {
        ContainerModel containerModel = trashHandler.getParentContainerModel(this);
        while (containerModel != null) {
            if (containerModel instanceof TrashedModel) {
                TrashedModel trashedModel = (TrashedModel) containerModel;
                return trashedModel.getTrashEntry();
            }
            trashHandler = TrashHandlerRegistryUtil.getTrashHandler(trashHandler.getContainerModelClassName());
            if (trashHandler == null) {
                return null;
            }
            containerModel = trashHandler.getContainerModel(containerModel.getParentContainerModelId());
        }
    }
    return null;
}
Also used : TrashEntry(com.liferay.portlet.trash.model.TrashEntry) TrashHandler(com.liferay.portal.kernel.trash.TrashHandler) TrashedModel(com.liferay.portal.model.TrashedModel) ContainerModel(com.liferay.portal.model.ContainerModel)

Aggregations

TrashEntry (com.liferay.portlet.trash.model.TrashEntry)12 TrashHandler (com.liferay.portal.kernel.trash.TrashHandler)6 ContainerModel (com.liferay.portal.model.ContainerModel)6 TrashedModel (com.liferay.portal.model.TrashedModel)6 Song (org.liferay.jukebox.model.Song)6 User (com.liferay.portal.model.User)5 ServiceContext (com.liferay.portal.service.ServiceContext)5 Date (java.util.Date)5 Indexable (com.liferay.portal.kernel.search.Indexable)4 Indexer (com.liferay.portal.kernel.search.Indexer)2 TrashVersion (com.liferay.portlet.trash.model.TrashVersion)2 Album (org.liferay.jukebox.model.Album)2 UnicodeProperties (com.liferay.portal.kernel.util.UnicodeProperties)1