From 457334403ecda400b054d9699dc2a4c1d1b08a0b Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Tue, 23 Jan 2018 18:38:47 +0200 Subject: [PATCH] Transfer Operations for CacheInspectPluginsTab --- .../operation/TransferOperations.java | 2 +- .../sql/operation/SQLTransferOps.java | 23 +++++++++ .../databases/sql/tables/TransferTable.java | 48 +++++++++++++++++++ .../CacheInspectPluginsTabRequest.java | 3 +- 4 files changed, 73 insertions(+), 3 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/operation/TransferOperations.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/operation/TransferOperations.java index c385f693a..862b4c021 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/operation/TransferOperations.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/operation/TransferOperations.java @@ -26,7 +26,7 @@ public interface TransferOperations { void storeNetworkPageContent(UUID serverUUID, String encodedHtml) throws DBException; - void storePlayerPluginsTab(UUID player, UUID serverUUID, String encodedHtml) throws DBException; + void storePlayerPluginsTab(UUID player, String encodedHtml) throws DBException; // Get diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLTransferOps.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLTransferOps.java index e724aeb98..910ad05c9 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLTransferOps.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLTransferOps.java @@ -76,4 +76,27 @@ public class SQLTransferOps extends SQLOps implements TransferOperations { throw SQLErrorUtil.getExceptionFor(e); } } + + @Override + public void storePlayerPluginsTab(UUID player, String encodedHtml) throws DBException { + try { + transferTable.storePlayerPluginsTab(player, encodedHtml); + } catch (SQLException e) { + throw SQLErrorUtil.getExceptionFor(e); + } + } + + @Override + public UUID getServerPlayerIsOnline(UUID playerUUID) { + return null; // TODO + } + + @Override + public Map getEncodedPlayerPluginsTabs(UUID playerUUID) throws DBException { + try { + return transferTable.getPlayerPluginsTabs(playerUUID); + } catch (SQLException e) { + throw SQLErrorUtil.getExceptionFor(e); + } + } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/TransferTable.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/TransferTable.java index 21db2abe5..09851e791 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/TransferTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/TransferTable.java @@ -12,6 +12,7 @@ import com.djrapitops.plan.system.database.databases.sql.statements.Sql; import com.djrapitops.plan.system.database.databases.sql.statements.TableSqlParser; import com.djrapitops.plan.system.info.request.CacheAnalysisPageRequest; import com.djrapitops.plan.system.info.request.CacheInspectPageRequest; +import com.djrapitops.plan.system.info.request.CacheInspectPluginsTabRequest; import com.djrapitops.plan.system.info.request.CacheNetworkPageContentRequest; import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.utilities.MiscUtils; @@ -147,4 +148,51 @@ public class TransferTable extends Table { public Map getServerHtml() throws SQLException { return getHtmlPerUUIDForCacheRequest(CacheAnalysisPageRequest.class); } + + public void storePlayerPluginsTab(UUID player, String encodedHtml) throws SQLException { + execute(new ExecStatement(insertStatement) { + @Override + public void prepare(PreparedStatement statement) throws SQLException { + statement.setString(1, ServerInfo.getServerUUID().toString()); + statement.setLong(2, MiscUtils.getTime() + TimeAmount.MINUTE.ms()); + statement.setString(3, CacheInspectPluginsTabRequest.class.getSimpleName().toLowerCase()); + statement.setString(4, player.toString()); + statement.setString(5, encodedHtml); + } + }); + } + + public Map getPlayerPluginsTabs(UUID playerUUID) throws SQLException { + String serverIDColumn = serverTable + "." + serverTable.getColumnID(); + String serverUUIDColumn = serverTable + "." + serverTable.getColumnUUID() + " as s_uuid"; + String sql = "SELECT " + + columnContent + ", " + + serverUUIDColumn + + " FROM " + tableName + + " JOIN " + serverTable + " on " + serverIDColumn + "=" + columnSenderID + + " WHERE " + columnInfoType + "= ?" + + " AND " + columnExpiry + "> ?" + + " AND " + columnExtraVariables + "=?"; + + return query(new QueryStatement>(sql, 250) { + @Override + public void prepare(PreparedStatement statement) throws SQLException { + statement.setString(1, CacheInspectPluginsTabRequest.class.getSimpleName().toLowerCase()); + statement.setLong(2, MiscUtils.getTime()); + statement.setString(3, playerUUID.toString()); + } + + @Override + public Map processResults(ResultSet set) throws SQLException { + Map htmlPerUUID = new HashMap<>(); + while (set.next()) { + UUID serverUUID = UUID.fromString(set.getString("s_uuid")); + String html64 = set.getString(columnContent); + + htmlPerUUID.put(serverUUID, html64); + } + return htmlPerUUID; + } + }); + } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/request/CacheInspectPluginsTabRequest.java b/Plan/src/main/java/com/djrapitops/plan/system/info/request/CacheInspectPluginsTabRequest.java index 2f81dc2c6..42a27f37a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/request/CacheInspectPluginsTabRequest.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/request/CacheInspectPluginsTabRequest.java @@ -9,7 +9,6 @@ import com.djrapitops.plan.api.exceptions.connection.TransferDatabaseException; import com.djrapitops.plan.api.exceptions.connection.WebException; import com.djrapitops.plan.api.exceptions.database.DBException; import com.djrapitops.plan.system.database.databases.Database; -import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.webserver.pages.DefaultResponses; import com.djrapitops.plan.system.webserver.response.Response; import com.djrapitops.plan.system.webserver.response.cache.PageId; @@ -55,7 +54,7 @@ public class CacheInspectPluginsTabRequest extends InfoRequestWithVariables impl String encodedHtml = Base64Util.encode(navAndHtml); try { - Database.getActive().transfer().storePlayerPluginsTab(player, ServerInfo.getServerUUID(), encodedHtml); + Database.getActive().transfer().storePlayerPluginsTab(player, encodedHtml); } catch (DBException e) { throw new TransferDatabaseException(e); }