use of net.robinfriedli.aiode.persist.tasks.HibernatePlaylistMigrator in project aiode by robinfriedli.
the class MigratePlaylistsTask method migrateFile.
private void migrateFile(Session session, Context context, Guild guild, SpotifyApi spotifyApi) throws Exception {
HibernatePlaylistMigrator hibernatePlaylistMigrator = new HibernatePlaylistMigrator(context, guild, spotifyApi, session);
Map<Playlist, List<PlaylistItem>> playlistMap = hibernatePlaylistMigrator.perform();
for (Playlist playlist : playlistMap.keySet()) {
playlistMap.get(playlist).forEach(item -> {
item.add();
session.persist(item);
});
session.persist(playlist);
}
File directory = new File("./resources/archive");
if (!directory.exists()) {
directory.mkdir();
}
File file = context.getFile();
Objects.requireNonNull(file);
Files.move(file, new File(directory.getPath() + "/" + file.getName()));
}
use of net.robinfriedli.aiode.persist.tasks.HibernatePlaylistMigrator in project aiode by robinfriedli.
the class GuildManager method handleNewGuild.
private void handleNewGuild(Guild guild, GuildContext guildContext) {
Aiode aiode = Aiode.get();
MessageService messageService = aiode.getMessageService();
try {
EmbedDocumentContribution embedDocumentContribution = embedDocumentContext.query(attribute("name").is("getting-started"), EmbedDocumentContribution.class).getOnlyResult();
if (embedDocumentContribution != null) {
EmbedBuilder embedBuilder = embedDocumentContribution.buildEmbed();
TextChannel defaultTextChannelForGuild = getDefaultTextChannelForGuild(guild, guildContext);
if (defaultTextChannelForGuild != null) {
messageService.sendWithLogo(embedBuilder, defaultTextChannelForGuild);
}
}
} catch (Exception e) {
logger.error("Error sending getting started message", e);
}
SessionFactory sessionFactory = hibernateComponent.getSessionFactory();
SpotifyApi.Builder spotifyApiBuilder = aiode.getSpotifyApiBuilder();
if (defaultPlaylistContext != null) {
try (Session session = sessionFactory.withOptions().interceptor(InterceptorChain.of(PlaylistItemTimestampInterceptor.class, VerifyPlaylistInterceptor.class)).openSession()) {
HibernatePlaylistMigrator hibernatePlaylistMigrator = new HibernatePlaylistMigrator(defaultPlaylistContext, guild, spotifyApiBuilder.build(), session);
Map<Playlist, List<PlaylistItem>> playlistMap = hibernatePlaylistMigrator.perform();
Mode mode = getMode();
HibernateInvoker.create(session).invokeConsumer(currentSession -> {
for (Playlist playlist : playlistMap.keySet()) {
Playlist existingList = SearchEngine.searchLocalList(currentSession, playlist.getName(), mode == GuildManager.Mode.PARTITIONED, guild.getId());
if (existingList == null) {
playlistMap.get(playlist).forEach(item -> {
item.add();
currentSession.persist(item);
});
currentSession.persist(playlist);
}
}
});
} catch (Exception e) {
logger.error("Exception while setting up default playlists", e);
}
}
}
Aggregations