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);
}
}
}
}
}
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;
}
}
}
}
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);
}
}
}
Aggregations