use of net.robinfriedli.aiode.entities.Playlist 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);
}
}
}
}
}
use of net.robinfriedli.aiode.entities.Playlist in project aiode by robinfriedli.
the class SearchEngine method searchLocalList.
@Nullable
public static Playlist searchLocalList(Session session, String searchTerm) {
String searchName = Util.normalizeWhiteSpace(searchTerm).toLowerCase();
QueryBuilderFactory queryBuilderFactory = Aiode.get().getQueryBuilderFactory();
return queryBuilderFactory.find(Playlist.class).where((cb, root, query) -> cb.equal(cb.lower(root.get("name")), searchName)).build(session).uniqueResultOptional().orElse(null);
}
use of net.robinfriedli.aiode.entities.Playlist in project aiode by robinfriedli.
the class SearchEngine method searchLocalList.
@Nullable
public static Playlist searchLocalList(Session session, String searchTerm, boolean isPartitioned, String guildId) {
String searchName = Util.normalizeWhiteSpace(searchTerm).toLowerCase();
QueryBuilderFactory queryBuilderFactory = Aiode.get().getQueryBuilderFactory();
EntityQueryBuilder<Playlist> queryBuilder = queryBuilderFactory.find(Playlist.class).where((cb, root, query) -> cb.equal(cb.lower(root.get("name")), searchName));
if (isPartitioned) {
queryBuilder.where((cb, root, query) -> cb.equal(root.get("guildId"), guildId));
}
return queryBuilder.skipInterceptors(PartitionedQueryInterceptor.class).build(session).uniqueResultOptional().orElse(null);
}
use of net.robinfriedli.aiode.entities.Playlist 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);
}
}
}
Aggregations