Search in sources :

Example 16 with PlaylistItem

use of net.robinfriedli.aiode.entities.PlaylistItem in project aiode by robinfriedli.

the class AlertPlaylistModificationInterceptor method afterCommit.

@Override
public void afterCommit() {
    List<Playlist> createdPlaylists = getCreatedEntities(Playlist.class);
    List<Playlist> deletedPlaylists = getDeletedEntities(Playlist.class);
    List<PlaylistItem> addedItems = getCreatedEntities(PlaylistItem.class);
    List<PlaylistItem> removedItems = getDeletedEntities(PlaylistItem.class);
    if (!createdPlaylists.isEmpty()) {
        String s = createdPlaylists.size() > 1 ? "Created playlists: " : "Created playlist: ";
        messageService.sendSuccess(s + StringList.create(createdPlaylists, Playlist::getName).toSeparatedString(", "), channel);
    }
    if (!deletedPlaylists.isEmpty()) {
        String s = deletedPlaylists.size() > 1 ? "Deleted playlists: " : "Deleted playlist: ";
        messageService.sendSuccess(s + StringList.create(deletedPlaylists, Playlist::getName).toSeparatedString(", "), channel);
    }
    if (!addedItems.isEmpty()) {
        if (addedItems.size() == 1) {
            PlaylistItem item = addedItems.get(0);
            if (!createdPlaylists.contains(item.getPlaylist())) {
                messageService.sendSuccess("Added " + item.display() + " to " + item.getPlaylist().getName(), channel);
            }
        } else {
            Multimap<Playlist, PlaylistItem> playlistWithItems = HashMultimap.create();
            for (PlaylistItem playlistItem : addedItems) {
                playlistWithItems.put(playlistItem.getPlaylist(), playlistItem);
            }
            for (Playlist playlist : playlistWithItems.keySet()) {
                if (!createdPlaylists.contains(playlist)) {
                    messageService.sendSuccess("Added " + playlistWithItems.get(playlist).size() + " items to playlist " + playlist.getName(), channel);
                }
            }
        }
    }
    if (!removedItems.isEmpty()) {
        if (removedItems.size() == 1) {
            PlaylistItem item = removedItems.get(0);
            if (!deletedPlaylists.contains(item.getPlaylist())) {
                messageService.sendSuccess("Removed " + item.display() + " from " + item.getPlaylist().getName(), channel);
            }
        } else {
            Multimap<Playlist, PlaylistItem> playlistWithItems = HashMultimap.create();
            for (PlaylistItem playlistItem : removedItems) {
                playlistWithItems.put(playlistItem.getPlaylist(), playlistItem);
            }
            for (Playlist playlist : playlistWithItems.keySet()) {
                if (!deletedPlaylists.contains(playlist)) {
                    messageService.sendSuccess("Removed " + playlistWithItems.get(playlist).size() + " items from playlist " + playlist.getName(), channel);
                }
            }
        }
    }
}
Also used : Playlist(net.robinfriedli.aiode.entities.Playlist) PlaylistItem(net.robinfriedli.aiode.entities.PlaylistItem)

Example 17 with PlaylistItem

use of net.robinfriedli.aiode.entities.PlaylistItem in project aiode by robinfriedli.

the class PlaylistItemTimestampInterceptor method onSaveChained.

@Override
public void onSaveChained(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
    if (entity instanceof PlaylistItem) {
        Date createdTimestamp = new Date();
        ((PlaylistItem) entity).setCreatedTimestamp(createdTimestamp);
        for (int i = 0; i < propertyNames.length; i++) {
            if ("createdTimestamp".equals(propertyNames[i])) {
                state[i] = createdTimestamp;
            }
        }
    }
}
Also used : PlaylistItem(net.robinfriedli.aiode.entities.PlaylistItem) Date(java.util.Date)

Example 18 with PlaylistItem

use of net.robinfriedli.aiode.entities.PlaylistItem in project aiode by robinfriedli.

the class VerifyPlaylistInterceptor method onDeleteChained.

@Override
public void onDeleteChained(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
    if (entity instanceof PlaylistItem) {
        PlaylistItem playlistItem = (PlaylistItem) entity;
        Playlist playlist = playlistItem.getPlaylist();
        if (playlistItem instanceof Song) {
            playlist.getSongs().remove(playlistItem);
        } else if (playlistItem instanceof Video) {
            playlist.getVideos().remove(playlistItem);
        } else if (playlistItem instanceof UrlTrack) {
            playlist.getUrlTracks().remove(playlistItem);
        }
    }
}
Also used : Playlist(net.robinfriedli.aiode.entities.Playlist) Song(net.robinfriedli.aiode.entities.Song) Video(net.robinfriedli.aiode.entities.Video) UrlTrack(net.robinfriedli.aiode.entities.UrlTrack) PlaylistItem(net.robinfriedli.aiode.entities.PlaylistItem)

Aggregations

PlaylistItem (net.robinfriedli.aiode.entities.PlaylistItem)18 Playlist (net.robinfriedli.aiode.entities.Playlist)10 InvalidCommandException (net.robinfriedli.aiode.exceptions.InvalidCommandException)6 Session (org.hibernate.Session)6 NoResultsFoundException (net.robinfriedli.aiode.exceptions.NoResultsFoundException)4 List (java.util.List)3 HollowYouTubeVideo (net.robinfriedli.aiode.audio.youtube.HollowYouTubeVideo)3 Song (net.robinfriedli.aiode.entities.Song)3 UrlTrack (net.robinfriedli.aiode.entities.UrlTrack)3 Video (net.robinfriedli.aiode.entities.Video)3 User (net.dv8tion.jda.api.entities.User)2 ShardManager (net.dv8tion.jda.api.sharding.ShardManager)2 AudioQueue (net.robinfriedli.aiode.audio.AudioQueue)2 Playable (net.robinfriedli.aiode.audio.Playable)2 SpringPropertiesConfig (net.robinfriedli.aiode.boot.SpringPropertiesConfig)2 CommandContext (net.robinfriedli.aiode.command.CommandContext)2 CommandManager (net.robinfriedli.aiode.command.CommandManager)2 CommandContribution (net.robinfriedli.aiode.entities.xml.CommandContribution)2 SearchEngine (net.robinfriedli.aiode.util.SearchEngine)2 Lists (com.google.common.collect.Lists)1