mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-03-09 13:19:07 +01:00
Query for DataExtension data of a single player
This commit is contained in:
parent
a514e29e78
commit
28d5cf106a
@ -29,6 +29,7 @@ public class Sql {
|
||||
public static final String GROUP_BY = " GROUP BY ";
|
||||
public static final String ORDER_BY = " ORDER BY ";
|
||||
public static final String INNER_JOIN = " INNER JOIN ";
|
||||
public static final String LEFT_JOIN = " LEFT JOIN ";
|
||||
public static final String AND = " AND ";
|
||||
|
||||
private Sql() {
|
||||
|
@ -50,8 +50,12 @@ public class TabInformation {
|
||||
return StringUtils.truncate(tabName, 50);
|
||||
}
|
||||
|
||||
public static Icon defaultIcon() {
|
||||
return new Icon(Family.SOLID, "circle", Color.NONE);
|
||||
}
|
||||
|
||||
public Icon getTabIcon() {
|
||||
return icon != null ? icon : new Icon(Family.SOLID, "circle", Color.NONE);
|
||||
return icon != null ? icon : defaultIcon();
|
||||
}
|
||||
|
||||
public int getTabPriority() {
|
||||
|
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.extension.implementation.results.player;
|
||||
|
||||
/**
|
||||
|
@ -64,6 +64,6 @@ public class ExtensionDescriptive implements Comparable<ExtensionDescriptive> {
|
||||
|
||||
@Override
|
||||
public int compareTo(ExtensionDescriptive other) {
|
||||
Integer.compare(other.priority, this.priority); // Higher is first
|
||||
return Integer.compare(other.priority, this.priority); // Higher is first
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.extension.implementation.results.player;
|
||||
|
||||
import com.djrapitops.plan.extension.icon.Icon;
|
||||
|
||||
/**
|
||||
* Information about a DataExtension stored in the database.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class ExtensionInformation {
|
||||
|
||||
private final int id;
|
||||
private final String pluginName;
|
||||
private final Icon icon;
|
||||
|
||||
public ExtensionInformation(int id, String pluginName, Icon icon) {
|
||||
this.id = id;
|
||||
this.pluginName = pluginName;
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getPluginName() {
|
||||
return pluginName;
|
||||
}
|
||||
|
||||
public Icon getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return '{' + "id=" + id + ", pluginName='" + pluginName + '\'' + '}';
|
||||
}
|
||||
}
|
@ -16,8 +16,6 @@
|
||||
*/
|
||||
package com.djrapitops.plan.extension.implementation.results.player;
|
||||
|
||||
import com.djrapitops.plan.extension.icon.Icon;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -29,28 +27,44 @@ import java.util.List;
|
||||
*/
|
||||
public class ExtensionPlayerData {
|
||||
|
||||
private String pluginName;
|
||||
private Icon pluginIcon;
|
||||
private final int pluginID;
|
||||
|
||||
private ExtensionInformation extensionInformation;
|
||||
|
||||
private List<ExtensionTabData> tabs;
|
||||
|
||||
public ExtensionPlayerData(String pluginName, Icon pluginIcon) {
|
||||
this.pluginName = pluginName;
|
||||
this.pluginIcon = pluginIcon;
|
||||
private ExtensionPlayerData(int pluginID) {
|
||||
this.pluginID = pluginID;
|
||||
|
||||
tabs = new ArrayList<>();
|
||||
}
|
||||
|
||||
public int getPluginID() {
|
||||
return pluginID;
|
||||
}
|
||||
|
||||
public ExtensionInformation getExtensionInformation() {
|
||||
return extensionInformation;
|
||||
}
|
||||
|
||||
public List<ExtensionTabData> getTabs() {
|
||||
return tabs;
|
||||
}
|
||||
|
||||
public class Factory {
|
||||
public static class Factory {
|
||||
|
||||
private final ExtensionPlayerData data;
|
||||
|
||||
public Factory() {
|
||||
data = new ExtensionPlayerData(pluginName, pluginIcon);
|
||||
public Factory(int pluginId) {
|
||||
data = new ExtensionPlayerData(pluginId);
|
||||
}
|
||||
|
||||
public Factory setInformation(ExtensionInformation information) {
|
||||
if (information.getId() != data.pluginID) {
|
||||
throw new IllegalArgumentException("ID mismatch, wanted id: " + data.pluginID + " but got " + information);
|
||||
}
|
||||
data.extensionInformation = information;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Factory addTab(ExtensionTabData tab) {
|
||||
|
@ -93,11 +93,11 @@ public class ExtensionTabData implements Comparable<ExtensionTabData> {
|
||||
return Integer.compare(this.tabInformation.getTabPriority(), other.tabInformation.getTabPriority()); // Lower is first
|
||||
}
|
||||
|
||||
public class Factory {
|
||||
public static class Factory {
|
||||
|
||||
private final ExtensionTabData data;
|
||||
|
||||
Factory(TabInformation tabInformation) {
|
||||
public Factory(TabInformation tabInformation) {
|
||||
data = new ExtensionTabData(tabInformation);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.extension.implementation.storage.queries;
|
||||
|
||||
import com.djrapitops.plan.db.access.Query;
|
||||
import com.djrapitops.plan.db.access.QueryAllStatement;
|
||||
import com.djrapitops.plan.db.access.QueryStatement;
|
||||
import com.djrapitops.plan.db.sql.tables.ExtensionIconTable;
|
||||
import com.djrapitops.plan.db.sql.tables.ExtensionPluginTable;
|
||||
import com.djrapitops.plan.extension.icon.Color;
|
||||
import com.djrapitops.plan.extension.icon.Family;
|
||||
import com.djrapitops.plan.extension.icon.Icon;
|
||||
import com.djrapitops.plan.extension.implementation.results.player.ExtensionInformation;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.*;
|
||||
|
||||
/**
|
||||
* Queries for information about DataExtensions stored in the database.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class ExtensionInformationQueries {
|
||||
|
||||
private ExtensionInformationQueries() {
|
||||
/* Static method class */
|
||||
}
|
||||
|
||||
public static Query<List<ExtensionInformation>> extensionsOfServer(UUID serverUUID) {
|
||||
String sql = SELECT +
|
||||
ExtensionPluginTable.TABLE_NAME + '.' + ExtensionPluginTable.ID + " as id," +
|
||||
ExtensionPluginTable.TABLE_NAME + '.' + ExtensionPluginTable.PLUGIN_NAME + " as plugin_name," +
|
||||
ExtensionIconTable.TABLE_NAME + '.' + ExtensionIconTable.ICON_NAME + " as icon_name," +
|
||||
ExtensionIconTable.COLOR + ',' +
|
||||
ExtensionIconTable.FAMILY +
|
||||
FROM + ExtensionPluginTable.TABLE_NAME +
|
||||
INNER_JOIN + ExtensionIconTable.TABLE_NAME + " on " +
|
||||
ExtensionPluginTable.ICON_ID + "=" + ExtensionIconTable.TABLE_NAME + '.' + ExtensionIconTable.ID +
|
||||
WHERE + ExtensionPluginTable.SERVER_UUID + "=?";
|
||||
|
||||
return new QueryStatement<List<ExtensionInformation>>(sql, 100) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, serverUUID.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ExtensionInformation> processResults(ResultSet set) throws SQLException {
|
||||
List<ExtensionInformation> information = new ArrayList<>();
|
||||
while (set.next()) {
|
||||
information.add(extractExtensionInformationFromQuery(set));
|
||||
}
|
||||
return information;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static ExtensionInformation extractExtensionInformationFromQuery(ResultSet set) throws SQLException {
|
||||
int id = set.getInt("id");
|
||||
String pluginName = set.getString("plugin_name");
|
||||
|
||||
String iconName = set.getString("icon_name");
|
||||
Family iconFamily = Family.getByName(set.getString(ExtensionIconTable.FAMILY)).orElse(Family.SOLID);
|
||||
Color color = Color.getByName(set.getString(ExtensionIconTable.COLOR)).orElse(Color.NONE);
|
||||
Icon icon = new Icon(iconFamily, iconName, color);
|
||||
|
||||
return new ExtensionInformation(id, pluginName, icon);
|
||||
}
|
||||
|
||||
public static Query<Map<UUID, List<ExtensionInformation>>> allExtensions() {
|
||||
String sql = SELECT +
|
||||
ExtensionPluginTable.TABLE_NAME + '.' + ExtensionPluginTable.ID + " as id," +
|
||||
ExtensionPluginTable.TABLE_NAME + '.' + ExtensionPluginTable.PLUGIN_NAME + " as plugin_name," +
|
||||
ExtensionPluginTable.SERVER_UUID + ',' +
|
||||
ExtensionIconTable.TABLE_NAME + '.' + ExtensionIconTable.ICON_NAME + " as icon_name," +
|
||||
ExtensionIconTable.COLOR + ',' +
|
||||
ExtensionIconTable.FAMILY +
|
||||
FROM + ExtensionPluginTable.TABLE_NAME +
|
||||
INNER_JOIN + ExtensionIconTable.TABLE_NAME + " on " +
|
||||
ExtensionPluginTable.ICON_ID + "=" + ExtensionIconTable.TABLE_NAME + '.' + ExtensionIconTable.ID;
|
||||
|
||||
return new QueryAllStatement<Map<UUID, List<ExtensionInformation>>>(sql, 100) {
|
||||
@Override
|
||||
public Map<UUID, List<ExtensionInformation>> processResults(ResultSet set) throws SQLException {
|
||||
Map<UUID, List<ExtensionInformation>> byServerUUID = new HashMap<>();
|
||||
while (set.next()) {
|
||||
UUID serverUUID = UUID.fromString(set.getString(ExtensionPluginTable.SERVER_UUID));
|
||||
List<ExtensionInformation> information = byServerUUID.getOrDefault(serverUUID, new ArrayList<>());
|
||||
information.add(extractExtensionInformationFromQuery(set));
|
||||
byServerUUID.put(serverUUID, information);
|
||||
}
|
||||
return byServerUUID;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,242 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.extension.implementation.storage.queries;
|
||||
|
||||
import com.djrapitops.plan.db.SQLDB;
|
||||
import com.djrapitops.plan.db.access.Query;
|
||||
import com.djrapitops.plan.db.access.QueryStatement;
|
||||
import com.djrapitops.plan.db.sql.tables.ExtensionIconTable;
|
||||
import com.djrapitops.plan.db.sql.tables.ExtensionPlayerValueTable;
|
||||
import com.djrapitops.plan.db.sql.tables.ExtensionProviderTable;
|
||||
import com.djrapitops.plan.db.sql.tables.ExtensionTabTable;
|
||||
import com.djrapitops.plan.extension.ElementOrder;
|
||||
import com.djrapitops.plan.extension.FormatType;
|
||||
import com.djrapitops.plan.extension.icon.Color;
|
||||
import com.djrapitops.plan.extension.icon.Family;
|
||||
import com.djrapitops.plan.extension.icon.Icon;
|
||||
import com.djrapitops.plan.extension.implementation.TabInformation;
|
||||
import com.djrapitops.plan.extension.implementation.results.player.*;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
import static com.djrapitops.plan.db.sql.parsing.Sql.*;
|
||||
|
||||
/**
|
||||
* Query all ExtensionPlayerData by Server UUIDs.
|
||||
* <p>
|
||||
* Returns Map: Server UUID - List of ExtensionPlayerData.
|
||||
* <p>
|
||||
* How it is done:
|
||||
* - Two queries are run, one that fetches all extensions and one that fetches all data of the player.
|
||||
* - Data query is sorted into a multi-map: PluginID - Tab Name - Tab Data
|
||||
* - (Tab Name can be empty.)
|
||||
* - Multi-map is sorted into ExtensionPlayerData objects by PluginID, one per ID
|
||||
* - This map is sorted into final Map: Server UUID - List of ExtensionPlayerData at the highest level.
|
||||
* <p>
|
||||
* There are multiple data extraction methods to make extracting the value query easier.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class ExtensionPlayerDataQuery implements Query<Map<UUID, List<ExtensionPlayerData>>> {
|
||||
|
||||
private final UUID playerUUID;
|
||||
|
||||
public ExtensionPlayerDataQuery(UUID playerUUID) {
|
||||
this.playerUUID = playerUUID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<UUID, List<ExtensionPlayerData>> executeQuery(SQLDB db) {
|
||||
Map<UUID, List<ExtensionInformation>> extensionsByServerUUID = db.query(ExtensionInformationQueries.allExtensions());
|
||||
Map<Integer, ExtensionPlayerData.Factory> extensionDataByPluginID = db.query(fetchIncompletePlayerDataByPluginID());
|
||||
|
||||
return flatMapByServerUUID(extensionsByServerUUID, extensionDataByPluginID);
|
||||
}
|
||||
|
||||
private Map<UUID, List<ExtensionPlayerData>> flatMapByServerUUID(Map<UUID, List<ExtensionInformation>> extensionsByServerUUID, Map<Integer, ExtensionPlayerData.Factory> extensionDataByPluginID) {
|
||||
Map<UUID, List<ExtensionPlayerData>> extensionDataByServerUUID = new HashMap<>();
|
||||
|
||||
for (Map.Entry<UUID, List<ExtensionInformation>> entry : extensionsByServerUUID.entrySet()) {
|
||||
UUID serverUUID = entry.getKey();
|
||||
for (ExtensionInformation extensionInformation : entry.getValue()) {
|
||||
ExtensionPlayerData.Factory data = extensionDataByPluginID.get(extensionInformation.getId());
|
||||
if (data == null) {
|
||||
continue;
|
||||
}
|
||||
List<ExtensionPlayerData> list = extensionDataByServerUUID.getOrDefault(serverUUID, new ArrayList<>());
|
||||
list.add(data.setInformation(extensionInformation).build());
|
||||
extensionDataByServerUUID.put(serverUUID, list);
|
||||
}
|
||||
}
|
||||
return extensionDataByServerUUID;
|
||||
}
|
||||
|
||||
private Query<Map<Integer, ExtensionPlayerData.Factory>> fetchIncompletePlayerDataByPluginID() {
|
||||
String sql = SELECT +
|
||||
"v1." + ExtensionPlayerValueTable.BOOLEAN_VALUE + " as boolean_value," +
|
||||
"v1." + ExtensionPlayerValueTable.DOUBLE_VALUE + " as double_value," +
|
||||
"v1." + ExtensionPlayerValueTable.PERCENTAGE_VALUE + " as percentage_value," +
|
||||
"v1." + ExtensionPlayerValueTable.LONG_VALUE + " as long_value," +
|
||||
"v1." + ExtensionPlayerValueTable.STRING_VALUE + " as string_value," +
|
||||
"p1." + ExtensionProviderTable.PLUGIN_ID + " as plugin_id," +
|
||||
"p1." + ExtensionProviderTable.PROVIDER_NAME + " as provider_name," +
|
||||
"p1." + ExtensionProviderTable.TEXT + " as text," +
|
||||
"p1." + ExtensionProviderTable.DESCRIPTION + " as description," +
|
||||
"p1." + ExtensionProviderTable.PRIORITY + " as provider_priority," +
|
||||
"p1." + ExtensionProviderTable.FORMAT_TYPE + " as format_type," +
|
||||
"p1." + ExtensionProviderTable.IS_PLAYER_NAME + " as is_player_name," +
|
||||
"t1." + ExtensionTabTable.TAB_NAME + " as tab_name," +
|
||||
"t1." + ExtensionTabTable.TAB_PRIORITY + " as tab_priority," +
|
||||
"t1." + ExtensionTabTable.ELEMENT_ORDER + " as element_order," +
|
||||
"i1." + ExtensionIconTable.ICON_NAME + " as plugin_icon_name," +
|
||||
"i1." + ExtensionIconTable.FAMILY + " as plugin_icon_family," +
|
||||
"i1." + ExtensionIconTable.COLOR + " as plugin_icon_color," +
|
||||
"i2." + ExtensionIconTable.ICON_NAME + " as tab_icon_name," +
|
||||
"i2." + ExtensionIconTable.FAMILY + " as tab_icon_family," +
|
||||
"i2." + ExtensionIconTable.COLOR + " as tab_icon_color" +
|
||||
FROM + ExtensionPlayerValueTable.TABLE_NAME + " v1" +
|
||||
INNER_JOIN + ExtensionProviderTable.TABLE_NAME + " p1 on p1." + ExtensionProviderTable.ID + "=v1." + ExtensionPlayerValueTable.PROVIDER_ID +
|
||||
LEFT_JOIN + ExtensionTabTable.TABLE_NAME + " t1 on t1." + ExtensionTabTable.ID + "=p1." + ExtensionProviderTable.TAB_ID +
|
||||
LEFT_JOIN + ExtensionIconTable.TABLE_NAME + " i1 on i1." + ExtensionIconTable.ID + "=p1." + ExtensionProviderTable.ICON_ID +
|
||||
LEFT_JOIN + ExtensionIconTable.TABLE_NAME + " i2 on i2." + ExtensionIconTable.ID + "=p1." + ExtensionTabTable.ICON_ID +
|
||||
WHERE + ExtensionPlayerValueTable.USER_UUID + "=?";
|
||||
|
||||
return new QueryStatement<Map<Integer, ExtensionPlayerData.Factory>>(sql, 1000) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, playerUUID.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, ExtensionPlayerData.Factory> processResults(ResultSet set) throws SQLException {
|
||||
Map<Integer, Map<String, ExtensionTabData.Factory>> tabDataByPluginID = extractTabDataByPluginID(set);
|
||||
return flatMapToPlayerData(tabDataByPluginID);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private Map<Integer, ExtensionPlayerData.Factory> flatMapToPlayerData(Map<Integer, Map<String, ExtensionTabData.Factory>> tabDataByPluginID) {
|
||||
Map<Integer, ExtensionPlayerData.Factory> dataByPluginID = new HashMap<>();
|
||||
for (Map.Entry<Integer, Map<String, ExtensionTabData.Factory>> entry : tabDataByPluginID.entrySet()) {
|
||||
Integer pluginID = entry.getKey();
|
||||
ExtensionPlayerData.Factory data = dataByPluginID.getOrDefault(pluginID, new ExtensionPlayerData.Factory(pluginID));
|
||||
for (ExtensionTabData.Factory tabData : entry.getValue().values()) {
|
||||
data.addTab(tabData.build());
|
||||
}
|
||||
dataByPluginID.put(pluginID, data);
|
||||
}
|
||||
return dataByPluginID;
|
||||
}
|
||||
|
||||
private Map<Integer, Map<String, ExtensionTabData.Factory>> extractTabDataByPluginID(ResultSet set) throws SQLException {
|
||||
Map<Integer, Map<String, ExtensionTabData.Factory>> tabDataByPluginID = new HashMap<>();
|
||||
|
||||
while (set.next()) {
|
||||
int pluginID = set.getInt("plugin_id");
|
||||
Map<String, ExtensionTabData.Factory> tabData = tabDataByPluginID.getOrDefault(pluginID, new HashMap<>());
|
||||
|
||||
String tabName = Optional.ofNullable(set.getString("tab_name")).orElse("");
|
||||
ExtensionTabData.Factory inMap = tabData.get(tabName);
|
||||
ExtensionTabData.Factory extensionTab = inMap != null ? inMap : extractTab(tabName, set, tabData);
|
||||
|
||||
ExtensionDescriptive extensionDescriptive = extractDescriptive(set);
|
||||
extractAndPutDataTo(extensionTab, extensionDescriptive, set);
|
||||
|
||||
tabData.put(tabName, extensionTab);
|
||||
tabDataByPluginID.put(pluginID, tabData);
|
||||
}
|
||||
return tabDataByPluginID;
|
||||
}
|
||||
|
||||
private void extractAndPutDataTo(ExtensionTabData.Factory extensionTab, ExtensionDescriptive descriptive, ResultSet set) throws SQLException {
|
||||
boolean booleanValue = set.getBoolean(ExtensionPlayerValueTable.BOOLEAN_VALUE);
|
||||
if (!set.wasNull()) {
|
||||
extensionTab.putBooleanData(new ExtensionBooleanData(descriptive, booleanValue));
|
||||
return;
|
||||
}
|
||||
|
||||
double doubleValue = set.getDouble(ExtensionPlayerValueTable.DOUBLE_VALUE);
|
||||
if (!set.wasNull()) {
|
||||
extensionTab.putDoubleData(new ExtensionDoubleData(descriptive, doubleValue));
|
||||
return;
|
||||
}
|
||||
|
||||
double percentageValue = set.getDouble(ExtensionPlayerValueTable.PERCENTAGE_VALUE);
|
||||
if (!set.wasNull()) {
|
||||
extensionTab.putPercentageData(new ExtensionDoubleData(descriptive, percentageValue));
|
||||
return;
|
||||
}
|
||||
|
||||
long numberValue = set.getLong(ExtensionPlayerValueTable.LONG_VALUE);
|
||||
if (!set.wasNull()) {
|
||||
FormatType formatType = FormatType.getByName(set.getString(ExtensionProviderTable.FORMAT_TYPE)).orElse(FormatType.NONE);
|
||||
extensionTab.putNumberData(new ExtensionNumberData(descriptive, formatType, numberValue));
|
||||
return;
|
||||
}
|
||||
|
||||
String stringValue = set.getString(ExtensionPlayerValueTable.STRING_VALUE);
|
||||
if (stringValue != null) {
|
||||
boolean isPlayerName = set.getBoolean("is_player_name");
|
||||
extensionTab.putStringData(new ExtensionStringData(descriptive, isPlayerName, stringValue));
|
||||
}
|
||||
}
|
||||
|
||||
private ExtensionDescriptive extractDescriptive(ResultSet set) throws SQLException {
|
||||
String name = set.getString("provider_name");
|
||||
String text = set.getString(ExtensionProviderTable.TEXT);
|
||||
String description = set.getString(ExtensionProviderTable.DESCRIPTION);
|
||||
int priority = set.getInt("provider_priority");
|
||||
|
||||
String iconName = set.getString("plugin_icon_name");
|
||||
Family family = Family.getByName("plugin_icon_family").orElse(Family.SOLID);
|
||||
Color color = Color.getByName("plugin_icon_color").orElse(Color.NONE);
|
||||
Icon icon = new Icon(family, iconName, color);
|
||||
|
||||
return new ExtensionDescriptive(name, text, description, icon, priority);
|
||||
}
|
||||
|
||||
private ExtensionTabData.Factory extractTab(String tabName, ResultSet set, Map<String, ExtensionTabData.Factory> tabData) throws SQLException {
|
||||
Optional<Integer> tabPriority = Optional.of(set.getInt("tab_priority"));
|
||||
if (set.wasNull()) {
|
||||
tabPriority = Optional.empty();
|
||||
}
|
||||
Optional<ElementOrder[]> elementOrder = Optional.ofNullable(set.getString(ExtensionTabTable.ELEMENT_ORDER)).map(ElementOrder::deserialize);
|
||||
|
||||
Icon tabIcon = extractTabIcon(set);
|
||||
|
||||
return tabData.getOrDefault(tabName, new ExtensionTabData.Factory(new TabInformation(
|
||||
tabName,
|
||||
tabIcon,
|
||||
elementOrder.orElse(ElementOrder.values()),
|
||||
tabPriority.orElse(100)
|
||||
)));
|
||||
}
|
||||
|
||||
private Icon extractTabIcon(ResultSet set) throws SQLException {
|
||||
Optional<String> iconName = Optional.ofNullable(set.getString("tab_icon_name"));
|
||||
if (iconName.isPresent()) {
|
||||
Family iconFamily = Family.getByName(set.getString("tab_icon_family")).orElse(Family.SOLID);
|
||||
Color iconColor = Color.getByName(set.getString("tab_icon_color")).orElse(Color.NONE);
|
||||
return new Icon(iconFamily, iconName.get(), iconColor);
|
||||
} else {
|
||||
return TabInformation.defaultIcon();
|
||||
}
|
||||
}
|
||||
}
|
@ -30,7 +30,6 @@ import com.djrapitops.plan.data.store.objects.Nickname;
|
||||
import com.djrapitops.plan.data.time.GMTimes;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
import com.djrapitops.plan.db.access.Executable;
|
||||
import com.djrapitops.plan.db.access.HasMoreThanZeroQueryStatement;
|
||||
import com.djrapitops.plan.db.access.Query;
|
||||
import com.djrapitops.plan.db.access.queries.*;
|
||||
import com.djrapitops.plan.db.access.queries.containers.ContainerFetchQueries;
|
||||
@ -45,10 +44,14 @@ import com.djrapitops.plan.db.access.transactions.init.CleanTransaction;
|
||||
import com.djrapitops.plan.db.access.transactions.init.CreateIndexTransaction;
|
||||
import com.djrapitops.plan.db.access.transactions.init.CreateTablesTransaction;
|
||||
import com.djrapitops.plan.db.patches.Patch;
|
||||
import com.djrapitops.plan.db.sql.tables.ExtensionPlayerValueTable;
|
||||
import com.djrapitops.plan.extension.DataExtension;
|
||||
import com.djrapitops.plan.extension.ExtensionServiceImplementation;
|
||||
import com.djrapitops.plan.extension.annotation.*;
|
||||
import com.djrapitops.plan.extension.implementation.results.player.ExtensionBooleanData;
|
||||
import com.djrapitops.plan.extension.implementation.results.player.ExtensionPlayerData;
|
||||
import com.djrapitops.plan.extension.implementation.results.player.ExtensionStringData;
|
||||
import com.djrapitops.plan.extension.implementation.results.player.ExtensionTabData;
|
||||
import com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery;
|
||||
import com.djrapitops.plan.system.PlanSystem;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
@ -75,8 +78,6 @@ import java.io.File;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.OperatingSystemMXBean;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
@ -1033,13 +1034,21 @@ public abstract class CommonDBTest {
|
||||
extensionService.register(new TestExtension());
|
||||
extensionService.updatePlayerValues(playerUUID, TestConstants.PLAYER_ONE_NAME);
|
||||
|
||||
assertTrue(db.query(new HasMoreThanZeroQueryStatement("SELECT COUNT(1) as c FROM " + ExtensionPlayerValueTable.TABLE_NAME +
|
||||
" WHERE " + ExtensionPlayerValueTable.USER_UUID + "=?") {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, playerUUID.toString());
|
||||
}
|
||||
}));
|
||||
Map<UUID, List<ExtensionPlayerData>> playerDataByServerUUID = db.query(new ExtensionPlayerDataQuery(playerUUID));
|
||||
List<ExtensionPlayerData> ofServer = playerDataByServerUUID.get(serverUUID);
|
||||
assertNotNull(ofServer);
|
||||
assertFalse(ofServer.isEmpty());
|
||||
|
||||
ExtensionPlayerData extensionPlayerData = ofServer.get(0);
|
||||
List<ExtensionTabData> tabs = extensionPlayerData.getTabs();
|
||||
assertEquals(1, tabs.size()); // No tab defined, should contain 1 tab
|
||||
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));
|
||||
}
|
||||
|
||||
@PluginInfo(name = "TestExtension")
|
||||
@ -1066,7 +1075,7 @@ public abstract class CommonDBTest {
|
||||
|
||||
@StringProvider(text = "a string")
|
||||
public String stringVal(UUID playerUUID) {
|
||||
return "";
|
||||
return "Something";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,8 +29,8 @@ import static org.junit.Assert.assertTrue;
|
||||
public class OptionalAssert {
|
||||
|
||||
public static <T> void equals(T expected, Optional<T> result) {
|
||||
assertTrue(result.isPresent());
|
||||
assertEquals(expected, result.get());
|
||||
assertTrue("No result present, expected: " + expected, result.isPresent());
|
||||
assertEquals("Wrong result, expected: " + expected + ", got: " + result.get(), expected, result.get());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user