Search in sources :

Example 1 with ExtensionServerDataQuery

use of com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery in project Plan by plan-player-analytics.

the class ExtensionsDatabaseTest method extensionServerAggregateQueriesWork.

@Test
default void extensionServerAggregateQueriesWork() {
    ExtensionSvc extensionService = extensionService();
    extensionService.register(new PlayerExtension());
    extensionService.updatePlayerValues(playerUUID, TestConstants.PLAYER_ONE_NAME, CallEvents.MANUAL);
    List<ExtensionData> ofServer = db().query(new ExtensionServerDataQuery(serverUUID()));
    assertFalse(ofServer.isEmpty());
    ExtensionData extensionData = ofServer.get(0);
    List<ExtensionTabData> tabs = extensionData.getTabs();
    // No tab defined, should contain 1 tab
    assertEquals(1, tabs.size());
    ExtensionTabData tabData = tabs.get(0);
    System.out.println(tabData.getValueOrder());
    OptionalAssert.equals("0.0", tabData.getPercentage("boolVal_aggregate").map(data -> data.getFormattedValue(Objects::toString)));
    OptionalAssert.equals("0.5", tabData.getPercentage("percentageVal_avg").map(data -> data.getFormattedValue(Objects::toString)));
    OptionalAssert.equals("0.5", tabData.getDouble("doubleVal_avg").map(data -> data.getFormattedValue(Objects::toString)));
    OptionalAssert.equals("0.5", tabData.getDouble("doubleVal_total").map(data -> data.getFormattedValue(Objects::toString)));
    OptionalAssert.equals("5", tabData.getNumber("value_avg").map(data -> data.getFormattedValue(Objects::toString)));
    OptionalAssert.equals("5", tabData.getNumber("value_total").map(data -> data.getFormattedValue(Objects::toString)));
    List<ExtensionTableData> tableData = tabData.getTableData();
    assertEquals(1, tableData.size());
    HtmlTable table = tableData.get(0).getHtmlTable();
    String result = table.toHtml();
    assertTrue(result.contains("<tbody><tr><td>Group</td><td>1</td></tr></tbody>"), result);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) com.djrapitops.plan.extension.annotation(com.djrapitops.plan.extension.annotation) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) ServerUUID(com.djrapitops.plan.identification.ServerUUID) ExtensionSvc(com.djrapitops.plan.extension.ExtensionSvc) Map(java.util.Map) RemoveUnsatisfiedConditionalServerResultsTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalServerResultsTransaction) DatabaseTestPreparer(com.djrapitops.plan.storage.database.DatabaseTestPreparer) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) ExtensionServerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery) TestConstants(utilities.TestConstants) NotReadyException(com.djrapitops.plan.extension.NotReadyException) ExtensionPlayerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery) Table(com.djrapitops.plan.extension.table.Table) ExtensionDataBuilder(com.djrapitops.plan.extension.builder.ExtensionDataBuilder) TestErrorLogger(utilities.TestErrorLogger) HtmlTable(com.djrapitops.plan.delivery.rendering.html.structure.HtmlTable) DataExtension(com.djrapitops.plan.extension.DataExtension) OptionalAssert(utilities.OptionalAssert) Color(com.djrapitops.plan.extension.icon.Color) ExtensionServerTableDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerTableDataQuery) Icon(com.djrapitops.plan.extension.icon.Icon) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) List(java.util.List) Assertions(org.junit.jupiter.api.Assertions) CallEvents(com.djrapitops.plan.extension.CallEvents) RandomData(utilities.RandomData) com.djrapitops.plan.extension.implementation.results(com.djrapitops.plan.extension.implementation.results) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) RemoveUnsatisfiedConditionalPlayerResultsTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalPlayerResultsTransaction) HtmlTable(com.djrapitops.plan.delivery.rendering.html.structure.HtmlTable) ExtensionSvc(com.djrapitops.plan.extension.ExtensionSvc) ExtensionServerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test)

Example 2 with ExtensionServerDataQuery

use of com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery in project Plan by plan-player-analytics.

the class ExtensionsDatabaseTest method extensionServerValuesAreStored.

@Test
default void extensionServerValuesAreStored() {
    ExtensionSvc extensionService = extensionService();
    extensionService.register(new ServerExtension());
    extensionService.updateServerValues(CallEvents.SERVER_EXTENSION_REGISTER);
    List<ExtensionData> ofServer = db().query(new ExtensionServerDataQuery(serverUUID()));
    assertFalse(ofServer.isEmpty());
    ExtensionData extensionData = ofServer.get(0);
    List<ExtensionTabData> tabs = extensionData.getTabs();
    // No tab defined, should contain 1 tab
    assertEquals(1, tabs.size());
    ExtensionTabData tabData = tabs.get(0);
    OptionalAssert.equals("5", tabData.getNumber("value").map(data -> data.getFormattedValue(Object::toString)));
    OptionalAssert.equals("No", tabData.getBoolean("boolVal").map(ExtensionBooleanData::getFormattedValue));
    OptionalAssert.equals("0.5", tabData.getDouble("doubleVal").map(data -> data.getFormattedValue(Object::toString)));
    OptionalAssert.equals("0.5", tabData.getPercentage("percentageVal").map(data -> data.getFormattedValue(Object::toString)));
    OptionalAssert.equals("Something", tabData.getString("stringVal").map(ExtensionStringData::getFormattedValue));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) com.djrapitops.plan.extension.annotation(com.djrapitops.plan.extension.annotation) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) ServerUUID(com.djrapitops.plan.identification.ServerUUID) ExtensionSvc(com.djrapitops.plan.extension.ExtensionSvc) Map(java.util.Map) RemoveUnsatisfiedConditionalServerResultsTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalServerResultsTransaction) DatabaseTestPreparer(com.djrapitops.plan.storage.database.DatabaseTestPreparer) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) ExtensionServerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery) TestConstants(utilities.TestConstants) NotReadyException(com.djrapitops.plan.extension.NotReadyException) ExtensionPlayerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery) Table(com.djrapitops.plan.extension.table.Table) ExtensionDataBuilder(com.djrapitops.plan.extension.builder.ExtensionDataBuilder) TestErrorLogger(utilities.TestErrorLogger) HtmlTable(com.djrapitops.plan.delivery.rendering.html.structure.HtmlTable) DataExtension(com.djrapitops.plan.extension.DataExtension) OptionalAssert(utilities.OptionalAssert) Color(com.djrapitops.plan.extension.icon.Color) ExtensionServerTableDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerTableDataQuery) Icon(com.djrapitops.plan.extension.icon.Icon) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) List(java.util.List) Assertions(org.junit.jupiter.api.Assertions) CallEvents(com.djrapitops.plan.extension.CallEvents) RandomData(utilities.RandomData) com.djrapitops.plan.extension.implementation.results(com.djrapitops.plan.extension.implementation.results) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) RemoveUnsatisfiedConditionalPlayerResultsTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalPlayerResultsTransaction) ExtensionServerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery) ExtensionSvc(com.djrapitops.plan.extension.ExtensionSvc) Test(org.junit.jupiter.api.Test)

Example 3 with ExtensionServerDataQuery

use of com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery in project Plan by plan-player-analytics.

the class ServerPage method toHtml.

@Override
public String toHtml() {
    PlaceholderReplacer placeholders = new PlaceholderReplacer();
    ServerUUID serverUUID = server.getUuid();
    placeholders.put("serverUUID", serverUUID.toString());
    placeholders.put("serverName", server.getIdentifiableName());
    placeholders.put("serverDisplayName", server.getName());
    placeholders.put("refreshBarrier", config.get(WebserverSettings.REDUCED_REFRESH_BARRIER));
    placeholders.put("timeZone", config.getTimeZoneOffsetHours());
    placeholders.put("gmPieColors", theme.getValue(ThemeVal.GRAPH_GM_PIE));
    placeholders.put("contributors", Contributors.generateContributorHtml());
    placeholders.put("versionButton", versionChecker.getUpdateButton().orElse(versionChecker.getCurrentVersionButton()));
    placeholders.put("version", versionChecker.getCurrentVersion());
    placeholders.put("updateModal", versionChecker.getUpdateModal());
    CachingSupplier<ServerPluginTabs> pluginTabs = new CachingSupplier<>(() -> {
        List<ExtensionData> extensionData = dbSystem.getDatabase().query(new ExtensionServerDataQuery(serverUUID));
        return new ServerPluginTabs(extensionData, formatters);
    });
    long after = System.currentTimeMillis() - config.get(WebserverSettings.REDUCED_REFRESH_BARRIER);
    String navIdentifier = DataID.EXTENSION_NAV.of(serverUUID);
    String tabIdentifier = DataID.EXTENSION_TABS.of(serverUUID);
    String nav = jsonStorage.fetchJsonMadeAfter(navIdentifier, after).orElseGet(() -> {
        jsonStorage.invalidateOlder(navIdentifier, after);
        return jsonStorage.storeJson(navIdentifier, pluginTabs.get().getNav());
    }).json;
    String tabs = jsonStorage.fetchJsonMadeAfter(tabIdentifier, after).orElseGet(() -> {
        jsonStorage.invalidateOlder(tabIdentifier, after);
        return jsonStorage.storeJson(tabIdentifier, pluginTabs.get().getTabs());
    }).json;
    PlaceholderReplacer pluginPlaceholders = new PlaceholderReplacer();
    pluginPlaceholders.put("serverUUID", serverUUID.toString());
    pluginPlaceholders.put("serverName", server.getIdentifiableName());
    pluginPlaceholders.put("serverDisplayName", server.getName());
    pluginPlaceholders.put("backButton", serverInfo.getServer().isProxy() ? Html.BACK_BUTTON_NETWORK.create() : "");
    pluginPlaceholders.put("navPluginsTabs", nav);
    pluginPlaceholders.put("tabsPlugins", tabs);
    return UnaryChain.of(templateHtml).chain(theme::replaceThemeColors).chain(placeholders::apply).chain(pluginPlaceholders::apply).chain(locale::replaceLanguageInHtml).apply();
}
Also used : ExtensionServerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery) ServerUUID(com.djrapitops.plan.identification.ServerUUID) PlaceholderReplacer(com.djrapitops.plan.delivery.formatting.PlaceholderReplacer) CachingSupplier(com.djrapitops.plan.delivery.domain.container.CachingSupplier) ExtensionData(com.djrapitops.plan.extension.implementation.results.ExtensionData)

Example 4 with ExtensionServerDataQuery

use of com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery in project Plan by plan-player-analytics.

the class NetworkPage method toHtml.

@Override
public String toHtml() {
    PlaceholderReplacer placeholders = new PlaceholderReplacer();
    ServerUUID serverUUID = serverInfo.getServerUUID();
    placeholders.put("networkDisplayName", config.get(ProxySettings.NETWORK_NAME));
    placeholders.put("serverName", config.get(ProxySettings.NETWORK_NAME));
    placeholders.put("serverUUID", serverUUID.toString());
    placeholders.put("refreshBarrier", config.get(WebserverSettings.REDUCED_REFRESH_BARRIER));
    placeholders.put("gmPieColors", theme.getValue(ThemeVal.GRAPH_GM_PIE));
    placeholders.put("playersGraphColor", theme.getValue(ThemeVal.GRAPH_PLAYERS_ONLINE));
    placeholders.put("worldMapColLow", theme.getValue(ThemeVal.WORLD_MAP_LOW));
    placeholders.put("worldMapColHigh", theme.getValue(ThemeVal.WORLD_MAP_HIGH));
    placeholders.put("maxPingColor", theme.getValue(ThemeVal.GRAPH_MAX_PING));
    placeholders.put("minPingColor", theme.getValue(ThemeVal.GRAPH_MIN_PING));
    placeholders.put("avgPingColor", theme.getValue(ThemeVal.GRAPH_AVG_PING));
    placeholders.put("timeZone", config.getTimeZoneOffsetHours());
    placeholders.put("versionButton", versionChecker.getUpdateButton().orElse(versionChecker.getCurrentVersionButton()));
    placeholders.put("version", versionChecker.getCurrentVersion());
    placeholders.put("updateModal", versionChecker.getUpdateModal());
    placeholders.put("contributors", Contributors.generateContributorHtml());
    CachingSupplier<ServerPluginTabs> pluginTabs = new CachingSupplier<>(() -> {
        List<ExtensionData> extensionData = dbSystem.getDatabase().query(new ExtensionServerDataQuery(serverUUID));
        return new ServerPluginTabs(extensionData, formatters);
    });
    long after = System.currentTimeMillis() - config.get(WebserverSettings.REDUCED_REFRESH_BARRIER);
    String navIdentifier = DataID.EXTENSION_NAV.of(serverUUID);
    String tabIdentifier = DataID.EXTENSION_TABS.of(serverUUID);
    String nav = jsonStorage.fetchJsonMadeAfter(navIdentifier, after).orElseGet(() -> {
        jsonStorage.invalidateOlder(navIdentifier, after);
        return jsonStorage.storeJson(navIdentifier, pluginTabs.get().getNav());
    }).json;
    String tabs = jsonStorage.fetchJsonMadeAfter(tabIdentifier, after).orElseGet(() -> {
        jsonStorage.invalidateOlder(tabIdentifier, after);
        return jsonStorage.storeJson(tabIdentifier, pluginTabs.get().getTabs());
    }).json;
    PlaceholderReplacer pluginPlaceholders = new PlaceholderReplacer();
    pluginPlaceholders.put("networkDisplayName", config.get(ProxySettings.NETWORK_NAME));
    pluginPlaceholders.put("serverName", config.get(ProxySettings.NETWORK_NAME));
    pluginPlaceholders.put("serverUUID", serverUUID.toString());
    pluginPlaceholders.put("navPluginsTabs", nav);
    pluginPlaceholders.put("tabsPlugins", StringUtils.remove(tabs, "${backButton}"));
    return UnaryChain.of(templateHtml).chain(theme::replaceThemeColors).chain(placeholders::apply).chain(pluginPlaceholders::apply).chain(locale::replaceLanguageInHtml).apply();
}
Also used : ExtensionServerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery) ServerUUID(com.djrapitops.plan.identification.ServerUUID) PlaceholderReplacer(com.djrapitops.plan.delivery.formatting.PlaceholderReplacer) CachingSupplier(com.djrapitops.plan.delivery.domain.container.CachingSupplier) ExtensionData(com.djrapitops.plan.extension.implementation.results.ExtensionData)

Example 5 with ExtensionServerDataQuery

use of com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery in project Plan by plan-player-analytics.

the class ExtensionsDatabaseTest method removeEverythingRemovesServerExtensionData.

@Test
default void removeEverythingRemovesServerExtensionData() {
    extensionServerValuesAreStored();
    db().executeTransaction(new RemoveEverythingTransaction());
    assertTrue(db().query(new ExtensionServerDataQuery(serverUUID())).isEmpty());
}
Also used : ExtensionServerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) Test(org.junit.jupiter.api.Test)

Aggregations

ExtensionServerDataQuery (com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery)7 ServerUUID (com.djrapitops.plan.identification.ServerUUID)4 Test (org.junit.jupiter.api.Test)4 HtmlTable (com.djrapitops.plan.delivery.rendering.html.structure.HtmlTable)3 ExtensionSvc (com.djrapitops.plan.extension.ExtensionSvc)3 RemoveEverythingTransaction (com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction)3 CachingSupplier (com.djrapitops.plan.delivery.domain.container.CachingSupplier)2 PlaceholderReplacer (com.djrapitops.plan.delivery.formatting.PlaceholderReplacer)2 CallEvents (com.djrapitops.plan.extension.CallEvents)2 DataExtension (com.djrapitops.plan.extension.DataExtension)2 NotReadyException (com.djrapitops.plan.extension.NotReadyException)2 com.djrapitops.plan.extension.annotation (com.djrapitops.plan.extension.annotation)2 ExtensionDataBuilder (com.djrapitops.plan.extension.builder.ExtensionDataBuilder)2 Color (com.djrapitops.plan.extension.icon.Color)2 Icon (com.djrapitops.plan.extension.icon.Icon)2 com.djrapitops.plan.extension.implementation.results (com.djrapitops.plan.extension.implementation.results)2 ExtensionData (com.djrapitops.plan.extension.implementation.results.ExtensionData)2 ExtensionPlayerDataQuery (com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery)2 ExtensionServerTableDataQuery (com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerTableDataQuery)2 RemoveUnsatisfiedConditionalPlayerResultsTransaction (com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalPlayerResultsTransaction)2