mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-28 03:57:33 +01:00
Fixed plugin group filters
This commit is contained in:
parent
3f118a5ea8
commit
9aa9970d26
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* 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.providers;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class ProviderIdentifier {
|
||||||
|
private final UUID serverUUID;
|
||||||
|
private final String pluginName;
|
||||||
|
private final String providerName;
|
||||||
|
private String serverName;
|
||||||
|
|
||||||
|
public ProviderIdentifier(UUID serverUUID, String pluginName, String providerName) {
|
||||||
|
this.serverUUID = serverUUID;
|
||||||
|
this.pluginName = pluginName;
|
||||||
|
this.providerName = providerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<String> getServerName() {
|
||||||
|
return Optional.of(serverName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setServerName(String serverName) {
|
||||||
|
this.serverName = serverName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getServerUUID() {
|
||||||
|
return serverUUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPluginName() {
|
||||||
|
return pluginName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProviderName() {
|
||||||
|
return providerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
ProviderIdentifier that = (ProviderIdentifier) o;
|
||||||
|
return serverUUID.equals(that.serverUUID) && pluginName.equals(that.pluginName) && providerName.equals(that.providerName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(serverUUID, pluginName, providerName);
|
||||||
|
}
|
||||||
|
}
|
@ -32,19 +32,21 @@ public class ExtensionUUIDsInGroupQuery extends QueryStatement<Set<UUID>> {
|
|||||||
|
|
||||||
private final String pluginName;
|
private final String pluginName;
|
||||||
private final String groupProvider;
|
private final String groupProvider;
|
||||||
|
private final UUID serverUUID;
|
||||||
private final List<String> inGroups;
|
private final List<String> inGroups;
|
||||||
|
|
||||||
public ExtensionUUIDsInGroupQuery(String pluginName, String groupProvider, List<String> inGroups) {
|
public ExtensionUUIDsInGroupQuery(String pluginName, String groupProvider, UUID serverUUID, List<String> inGroups) {
|
||||||
super(buildSQL(inGroups), 100);
|
super(buildSQL(inGroups), 100);
|
||||||
this.pluginName = pluginName;
|
this.pluginName = pluginName;
|
||||||
this.groupProvider = groupProvider;
|
this.groupProvider = groupProvider;
|
||||||
|
this.serverUUID = serverUUID;
|
||||||
this.inGroups = inGroups;
|
this.inGroups = inGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String buildSQL(Collection<String> inGroups) {
|
private static String buildSQL(Collection<String> inGroups) {
|
||||||
TextStringBuilder dynamicInClauseAllocation = new TextStringBuilder();
|
TextStringBuilder dynamicInClauseAllocation = new TextStringBuilder();
|
||||||
dynamicInClauseAllocation.appendWithSeparators(inGroups.stream().map(group -> "?").toArray(), ",");
|
dynamicInClauseAllocation.appendWithSeparators(inGroups.stream().map(group -> "?").toArray(), ",");
|
||||||
return SELECT + ExtensionGroupsTable.USER_UUID +
|
return SELECT + DISTINCT + ExtensionGroupsTable.USER_UUID +
|
||||||
FROM + ExtensionGroupsTable.TABLE_NAME +
|
FROM + ExtensionGroupsTable.TABLE_NAME +
|
||||||
WHERE + ExtensionGroupsTable.PROVIDER_ID + "=" + ExtensionProviderTable.STATEMENT_SELECT_PROVIDER_ID +
|
WHERE + ExtensionGroupsTable.PROVIDER_ID + "=" + ExtensionProviderTable.STATEMENT_SELECT_PROVIDER_ID +
|
||||||
AND + ExtensionGroupsTable.GROUP_NAME + " IN (" + dynamicInClauseAllocation.build() + ")";
|
AND + ExtensionGroupsTable.GROUP_NAME + " IN (" + dynamicInClauseAllocation.build() + ")";
|
||||||
@ -52,10 +54,11 @@ public class ExtensionUUIDsInGroupQuery extends QueryStatement<Set<UUID>> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void prepare(PreparedStatement statement) throws SQLException {
|
public void prepare(PreparedStatement statement) throws SQLException {
|
||||||
statement.setString(1, groupProvider);
|
ExtensionProviderTable.set3PluginValuesToStatement(statement, 1, groupProvider, pluginName, serverUUID);
|
||||||
statement.setString(2, pluginName);
|
int index = 4;
|
||||||
for (int i = 1; i <= inGroups.size(); i++) {
|
for (String group : inGroups) {
|
||||||
statement.setString(i + 2, inGroups.get(i));
|
statement.setString(index, group);
|
||||||
|
index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ public class QueryFilters {
|
|||||||
private final Map<String, Filter> filters;
|
private final Map<String, Filter> filters;
|
||||||
private final AllPlayersFilter allPlayersFilter;
|
private final AllPlayersFilter allPlayersFilter;
|
||||||
private final DBSystem dbSystem;
|
private final DBSystem dbSystem;
|
||||||
|
private final PluginGroupsFilter.PluginGroupsFilterQuery filterQuery;
|
||||||
|
|
||||||
private final AtomicBoolean fetchedPluginFilters = new AtomicBoolean(false);
|
private final AtomicBoolean fetchedPluginFilters = new AtomicBoolean(false);
|
||||||
|
|
||||||
@ -45,10 +46,12 @@ public class QueryFilters {
|
|||||||
public QueryFilters(
|
public QueryFilters(
|
||||||
Set<Filter> filters,
|
Set<Filter> filters,
|
||||||
AllPlayersFilter allPlayersFilter,
|
AllPlayersFilter allPlayersFilter,
|
||||||
DBSystem dbSystem
|
DBSystem dbSystem,
|
||||||
|
PluginGroupsFilter.PluginGroupsFilterQuery filterQuery
|
||||||
) {
|
) {
|
||||||
this.allPlayersFilter = allPlayersFilter;
|
this.allPlayersFilter = allPlayersFilter;
|
||||||
this.dbSystem = dbSystem;
|
this.dbSystem = dbSystem;
|
||||||
|
this.filterQuery = filterQuery;
|
||||||
this.filters = new HashMap<>();
|
this.filters = new HashMap<>();
|
||||||
put(filters);
|
put(filters);
|
||||||
}
|
}
|
||||||
@ -61,7 +64,7 @@ public class QueryFilters {
|
|||||||
|
|
||||||
private void prepareFilters() {
|
private void prepareFilters() {
|
||||||
if (!fetchedPluginFilters.get()) {
|
if (!fetchedPluginFilters.get()) {
|
||||||
put(dbSystem.getDatabase().query(new PluginGroupsFilter.PluginGroupsFilterQuery(dbSystem)));
|
put(dbSystem.getDatabase().query(filterQuery));
|
||||||
fetchedPluginFilters.set(true);
|
fetchedPluginFilters.set(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,15 +16,20 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.storage.database.queries.filter.filters;
|
package com.djrapitops.plan.storage.database.queries.filter.filters;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.extension.implementation.providers.ProviderIdentifier;
|
||||||
import com.djrapitops.plan.extension.implementation.storage.queries.ExtensionUUIDsInGroupQuery;
|
import com.djrapitops.plan.extension.implementation.storage.queries.ExtensionUUIDsInGroupQuery;
|
||||||
|
import com.djrapitops.plan.identification.Server;
|
||||||
|
import com.djrapitops.plan.identification.ServerInfo;
|
||||||
import com.djrapitops.plan.storage.database.DBSystem;
|
import com.djrapitops.plan.storage.database.DBSystem;
|
||||||
import com.djrapitops.plan.storage.database.queries.QueryAllStatement;
|
import com.djrapitops.plan.storage.database.queries.QueryAllStatement;
|
||||||
import com.djrapitops.plan.storage.database.queries.filter.SpecifiedFilterInformation;
|
import com.djrapitops.plan.storage.database.queries.filter.SpecifiedFilterInformation;
|
||||||
import com.djrapitops.plan.storage.database.sql.tables.ExtensionGroupsTable;
|
import com.djrapitops.plan.storage.database.sql.tables.ExtensionGroupsTable;
|
||||||
import com.djrapitops.plan.storage.database.sql.tables.ExtensionPluginTable;
|
import com.djrapitops.plan.storage.database.sql.tables.ExtensionPluginTable;
|
||||||
import com.djrapitops.plan.storage.database.sql.tables.ExtensionProviderTable;
|
import com.djrapitops.plan.storage.database.sql.tables.ExtensionProviderTable;
|
||||||
|
import com.djrapitops.plan.storage.database.sql.tables.ServerTable;
|
||||||
import com.djrapitops.plan.utilities.java.Maps;
|
import com.djrapitops.plan.utilities.java.Maps;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@ -35,32 +40,27 @@ import static com.djrapitops.plan.storage.database.sql.building.Sql.*;
|
|||||||
public class PluginGroupsFilter extends MultiOptionFilter {
|
public class PluginGroupsFilter extends MultiOptionFilter {
|
||||||
|
|
||||||
private final DBSystem dbSystem;
|
private final DBSystem dbSystem;
|
||||||
private final String pluginName;
|
|
||||||
private final String groupProvider;
|
|
||||||
private final List<String> groups;
|
private final List<String> groups;
|
||||||
|
private final ProviderIdentifier identifier;
|
||||||
|
private final String serverName;
|
||||||
|
|
||||||
public PluginGroupsFilter(
|
public PluginGroupsFilter(DBSystem dbSystem, ProviderIdentifier identifier, List<String> groups) {
|
||||||
DBSystem dbSystem,
|
|
||||||
String pluginName,
|
|
||||||
String groupProvider,
|
|
||||||
List<String> groups
|
|
||||||
) {
|
|
||||||
this.dbSystem = dbSystem;
|
this.dbSystem = dbSystem;
|
||||||
this.pluginName = pluginName;
|
this.identifier = identifier;
|
||||||
this.groupProvider = groupProvider;
|
|
||||||
this.groups = groups;
|
this.groups = groups;
|
||||||
|
this.serverName = identifier.getServerName().orElse("?");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getKind() {
|
public String getKind() {
|
||||||
return "pluginGroups-" + pluginName + "-" + groupProvider;
|
return "pluginGroups-" + serverName + " " + identifier.getPluginName() + " " + identifier.getProviderName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> getOptions() {
|
public Map<String, Object> getOptions() {
|
||||||
return Maps.builder(String.class, Object.class)
|
return Maps.builder(String.class, Object.class)
|
||||||
.put("plugin", pluginName)
|
.put("plugin", identifier.getPluginName())
|
||||||
.put("group", groupProvider)
|
.put("group", identifier.getProviderName())
|
||||||
.put("options", groups)
|
.put("options", groups)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
@ -68,7 +68,7 @@ public class PluginGroupsFilter extends MultiOptionFilter {
|
|||||||
@Override
|
@Override
|
||||||
public Set<UUID> getMatchingUUIDs(SpecifiedFilterInformation query) {
|
public Set<UUID> getMatchingUUIDs(SpecifiedFilterInformation query) {
|
||||||
return dbSystem.getDatabase().query(
|
return dbSystem.getDatabase().query(
|
||||||
new ExtensionUUIDsInGroupQuery(pluginName, groupProvider, getSelected(query))
|
new ExtensionUUIDsInGroupQuery(identifier.getPluginName(), identifier.getProviderName(), identifier.getServerUUID(), getSelected(query))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,12 +77,18 @@ public class PluginGroupsFilter extends MultiOptionFilter {
|
|||||||
|
|
||||||
private final DBSystem dbSystem;
|
private final DBSystem dbSystem;
|
||||||
|
|
||||||
public PluginGroupsFilterQuery(DBSystem dbSystem) {
|
@Inject
|
||||||
super(SELECT + DISTINCT + "pl." + ExtensionPluginTable.PLUGIN_NAME + " as plugin_name," +
|
public PluginGroupsFilterQuery(DBSystem dbSystem, ServerInfo serverInfo) {
|
||||||
|
super(SELECT + DISTINCT +
|
||||||
|
"pl." + ExtensionPluginTable.PLUGIN_NAME + " as plugin_name," +
|
||||||
|
"s." + ServerTable.NAME + " as server_name," +
|
||||||
|
"s." + ServerTable.SERVER_ID + " as server_id," +
|
||||||
|
"pl." + ExtensionPluginTable.SERVER_UUID + " as server_uuid," +
|
||||||
"pr." + ExtensionProviderTable.PROVIDER_NAME + " as provider_name," +
|
"pr." + ExtensionProviderTable.PROVIDER_NAME + " as provider_name," +
|
||||||
"gr." + ExtensionGroupsTable.GROUP_NAME + " as group_name" +
|
"gr." + ExtensionGroupsTable.GROUP_NAME + " as group_name" +
|
||||||
FROM + ExtensionPluginTable.TABLE_NAME + " pl" +
|
FROM + ExtensionPluginTable.TABLE_NAME + " pl" +
|
||||||
INNER_JOIN + ExtensionProviderTable.TABLE_NAME + " pr on pl." + ExtensionPluginTable.ID + "=pr." + ExtensionProviderTable.PLUGIN_ID +
|
INNER_JOIN + ServerTable.TABLE_NAME + " s on s." + ServerTable.SERVER_UUID + "=pl." + ExtensionPluginTable.SERVER_UUID +
|
||||||
|
INNER_JOIN + ExtensionProviderTable.TABLE_NAME + " pr on pl." + ExtensionPluginTable.ID + "=pr." + ExtensionProviderTable.PLUGIN_ID +
|
||||||
INNER_JOIN + ExtensionGroupsTable.TABLE_NAME + " gr on pr." + ExtensionProviderTable.ID + "=gr." + ExtensionGroupsTable.PROVIDER_ID);
|
INNER_JOIN + ExtensionGroupsTable.TABLE_NAME + " gr on pr." + ExtensionProviderTable.ID + "=gr." + ExtensionGroupsTable.PROVIDER_ID);
|
||||||
|
|
||||||
this.dbSystem = dbSystem;
|
this.dbSystem = dbSystem;
|
||||||
@ -90,29 +96,31 @@ public class PluginGroupsFilter extends MultiOptionFilter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<PluginGroupsFilter> processResults(ResultSet set) throws SQLException {
|
public Collection<PluginGroupsFilter> processResults(ResultSet set) throws SQLException {
|
||||||
Map<String, Map<String, List<String>>> byPlugin = new HashMap<>();
|
Map<ProviderIdentifier, List<String>> byProvider = new HashMap<>();
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
String plugin = set.getString("plugin_name");
|
String plugin = set.getString("plugin_name");
|
||||||
String provider = set.getString("provider_name");
|
String provider = set.getString("provider_name");
|
||||||
|
UUID serverUUID = UUID.fromString(set.getString("server_uuid"));
|
||||||
|
ProviderIdentifier identifier = new ProviderIdentifier(serverUUID, plugin, provider);
|
||||||
|
identifier.setServerName(Server.getIdentifiableName(
|
||||||
|
set.getString("server_name"),
|
||||||
|
set.getInt("server_id")
|
||||||
|
));
|
||||||
|
|
||||||
String group = set.getString("group_name");
|
String group = set.getString("group_name");
|
||||||
|
|
||||||
Map<String, List<String>> byProvider = byPlugin.getOrDefault(plugin, new HashMap<>());
|
List<String> groups = byProvider.getOrDefault(identifier, new ArrayList<>());
|
||||||
List<String> groups = byProvider.getOrDefault(provider, new ArrayList<>());
|
|
||||||
groups.add(group);
|
groups.add(group);
|
||||||
byProvider.put(provider, groups);
|
byProvider.put(identifier, groups);
|
||||||
byPlugin.put(plugin, byProvider);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<PluginGroupsFilter> filters = new ArrayList<>();
|
List<PluginGroupsFilter> filters = new ArrayList<>();
|
||||||
for (Map.Entry<String, Map<String, List<String>>> providersOfPlugin : byPlugin.entrySet()) {
|
for (Map.Entry<ProviderIdentifier, List<String>> groupsOfProvider : byProvider.entrySet()) {
|
||||||
for (Map.Entry<String, List<String>> groupsOfProvider : providersOfPlugin.getValue().entrySet()) {
|
filters.add(new PluginGroupsFilter(
|
||||||
filters.add(new PluginGroupsFilter(
|
dbSystem,
|
||||||
dbSystem,
|
groupsOfProvider.getKey(),
|
||||||
providersOfPlugin.getKey(),
|
groupsOfProvider.getValue()
|
||||||
groupsOfProvider.getKey(),
|
));
|
||||||
groupsOfProvider.getValue()
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return filters;
|
return filters;
|
||||||
}
|
}
|
||||||
|
@ -80,9 +80,9 @@ class OperatorsFilter extends MultipleChoiceFilter {
|
|||||||
|
|
||||||
class PluginGroupsFilter extends MultipleChoiceFilter {
|
class PluginGroupsFilter extends MultipleChoiceFilter {
|
||||||
constructor(
|
constructor(
|
||||||
id, plugin, group, options
|
id, kind, options
|
||||||
) {
|
) {
|
||||||
super(id, `pluginGroups: ${plugin} ${group}`, `are in ${plugin}'s ${group} Groups`, options);
|
super(id, kind, `are in ${options.plugin}'s ${options.group} Groups`, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,6 +177,9 @@ class RegisteredBetweenFilter extends BetweenDateFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createFilter(filter, id) {
|
function createFilter(filter, id) {
|
||||||
|
if (filter.kind.startsWith("pluginGroups-")) {
|
||||||
|
return new PluginGroupsFilter(id, filter.kind, filter.options);
|
||||||
|
}
|
||||||
switch (filter.kind) {
|
switch (filter.kind) {
|
||||||
case "activityIndexNow":
|
case "activityIndexNow":
|
||||||
return new ActivityIndexFilter(id, filter.options);
|
return new ActivityIndexFilter(id, filter.options);
|
||||||
@ -184,8 +187,6 @@ function createFilter(filter, id) {
|
|||||||
return new BannedFilter(id, filter.options);
|
return new BannedFilter(id, filter.options);
|
||||||
case "operators":
|
case "operators":
|
||||||
return new OperatorsFilter(id, filter.options);
|
return new OperatorsFilter(id, filter.options);
|
||||||
case "pluginGroups":
|
|
||||||
return new PluginGroupsFilter(id, filter.plugin, filter.group, filter.options);
|
|
||||||
case "playedBetween":
|
case "playedBetween":
|
||||||
return new PlayedBetweenFilter(id, filter.options);
|
return new PlayedBetweenFilter(id, filter.options);
|
||||||
case "registeredBetween":
|
case "registeredBetween":
|
||||||
|
Loading…
Reference in New Issue
Block a user