Add 'Data_gathering.Preserve_join_address_case' setting (default false)

- Allows preserving case information of gathered join addresses
- Only affects future data
This commit is contained in:
Aurora Lahtela 2022-09-03 12:15:54 +03:00
parent cc56cf0985
commit 813abd040a
11 changed files with 39 additions and 13 deletions

View File

@ -17,11 +17,14 @@
package com.djrapitops.plan.delivery.domain.datatransfer;
import com.djrapitops.plan.identification.Server;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
/**
* Represents outgoing server information json.
*/
public class ServerDto {
public class ServerDto implements Comparable<ServerDto> {
private final String serverUUID;
private final String serverName;
@ -49,6 +52,24 @@ public class ServerDto {
return proxy;
}
@Override
public int compareTo(@NotNull ServerDto other) {
return String.CASE_INSENSITIVE_ORDER.compare(this.serverName, other.serverName);
}
@Override
public boolean equals(Object other) {
if (this == other) return true;
if (other == null || getClass() != other.getClass()) return false;
ServerDto serverDto = (ServerDto) other;
return isProxy() == serverDto.isProxy() && Objects.equals(getServerUUID(), serverDto.getServerUUID()) && Objects.equals(getServerName(), serverDto.getServerName());
}
@Override
public int hashCode() {
return Objects.hash(getServerUUID(), getServerName(), isProxy());
}
@Override
public String toString() {
return "ServerDto{" +

View File

@ -38,6 +38,7 @@ import com.djrapitops.plan.storage.database.DBSystem;
import com.djrapitops.plan.storage.database.sql.tables.JoinAddressTable;
import com.djrapitops.plan.storage.database.transactions.Transaction;
import com.djrapitops.plan.storage.database.transactions.events.*;
import org.apache.commons.lang3.StringUtils;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -109,6 +110,7 @@ public class PlayerJoinEventConsumer {
private void storeJoinAddress(PlayerJoin join) {
join.getPlayer().getJoinAddress()
.map(joinAddress -> config.isTrue(DataGatheringSettings.PRESERVE_JOIN_ADDRESS_CASE) ? joinAddress : StringUtils.lowerCase(joinAddress))
.map(StoreJoinAddressTransaction::new)
.ifPresent(dbSystem.getDatabase()::executeTransaction);
}
@ -165,7 +167,7 @@ public class PlayerJoinEventConsumer {
join.getPlayer().getCurrentGameMode().orElse(null));
session.getExtraData().put(PlayerName.class, new PlayerName(join.getPlayer().getName()));
session.getExtraData().put(ServerName.class, new ServerName(join.getServer().isProxy() ? join.getServer().getName() : "Proxy Server"));
session.getExtraData().put(JoinAddress.class, new JoinAddress(join.getJoinAddress()));
session.getExtraData().put(JoinAddress.class, new JoinAddress(config.isTrue(DataGatheringSettings.PRESERVE_JOIN_ADDRESS_CASE) ? join.getJoinAddress() : StringUtils.lowerCase(join.getJoinAddress())));
return session;
}

View File

@ -32,6 +32,7 @@ public class DataGatheringSettings {
public static final Setting<Boolean> DISK_SPACE = new BooleanSetting("Data_gathering.Disk_space");
public static final Setting<Boolean> LOG_UNKNOWN_COMMANDS = new BooleanSetting("Data_gathering.Commands.Log_unknown");
public static final Setting<Boolean> COMBINE_COMMAND_ALIASES = new BooleanSetting("Data_gathering.Commands.Log_aliases_as_main_command");
public static final Setting<Boolean> PRESERVE_JOIN_ADDRESS_CASE = new BooleanSetting("Data_gathering.Preserve_join_address_case");
private DataGatheringSettings() {
/* static variable class */

View File

@ -318,7 +318,7 @@ public class LargeStoreQueries {
.filter(Optional::isPresent)
.map(Optional::get)
.map(JoinAddress::getAddress)
.map(String::toLowerCase)
// .map(String::toLowerCase)
.filter(address -> !existingJoinAddresses.contains(address))
.distinct()
.forEach(address -> {

View File

@ -108,8 +108,6 @@ public class JoinAddressQueries {
new TextStringBuilder().appendWithSeparators(joinAddresses.stream().map(item -> '?').iterator(), ",") +
')'; // Don't append addresses directly, SQL injection hazard
return db -> db.querySet(sql, RowExtractors.getInt(SessionsTable.USER_ID), joinAddresses
.stream().map(String::toLowerCase)
.toArray());
return db -> db.querySet(sql, RowExtractors.getInt(SessionsTable.USER_ID), joinAddresses.toArray());
}
}

View File

@ -29,9 +29,9 @@ public class JoinAddressTable {
public static final String JOIN_ADDRESS = "join_address";
public static final int JOIN_ADDRESS_MAX_LENGTH = 191;
public static final String SELECT_ID = '(' + SELECT + ID + FROM + TABLE_NAME + WHERE + JOIN_ADDRESS + "=LOWER(?))";
public static final String SELECT_ID = '(' + SELECT + ID + FROM + TABLE_NAME + WHERE + JOIN_ADDRESS + "=?)";
public static final String INSERT_STATEMENT = "INSERT INTO " + TABLE_NAME +
" (" + JOIN_ADDRESS + ") VALUES (LOWER(?))";
" (" + JOIN_ADDRESS + ") VALUES (?)";
public static final String DEFAULT_VALUE_FOR_LOOKUP = "unknown";
private JoinAddressTable() {}

View File

@ -61,7 +61,7 @@ public class StoreJoinAddressTransaction extends Transaction {
}
private String getAddress() {
return StringUtils.truncate(joinAddress.get().toLowerCase(), JoinAddressTable.JOIN_ADDRESS_MAX_LENGTH);
return StringUtils.truncate(joinAddress.get(), JoinAddressTable.JOIN_ADDRESS_MAX_LENGTH);
}
@Override

View File

@ -44,7 +44,7 @@ import static com.djrapitops.plan.storage.database.sql.building.Sql.*;
public class SessionJoinAddressPatch extends Patch {
public static Query<List<String>> uniqueJoinAddressesOld() {
String sql = SELECT + DISTINCT + "LOWER(COALESCE(" + UserInfoTable.JOIN_ADDRESS + ", ?)) as address" +
String sql = SELECT + DISTINCT + "COALESCE(" + UserInfoTable.JOIN_ADDRESS + ", ?) as address" +
FROM + UserInfoTable.TABLE_NAME +
ORDER_BY + "address ASC";
return new QueryStatement<>(sql, 100) {
@ -79,7 +79,7 @@ public class SessionJoinAddressPatch extends Patch {
private Integer getDefaultAddressId() {
return query(new QueryStatement<>(SELECT + ID +
FROM + JoinAddressTable.TABLE_NAME +
WHERE + JoinAddressTable.JOIN_ADDRESS + "=LOWER(?)") {
WHERE + JoinAddressTable.JOIN_ADDRESS + "=?") {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, JoinAddressTable.DEFAULT_VALUE_FOR_LOOKUP);
@ -99,7 +99,7 @@ public class SessionJoinAddressPatch extends Patch {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
for (String joinAddress : joinAddresses) {
statement.setString(1, StringUtils.truncate(joinAddress.toLowerCase(), JoinAddressTable.JOIN_ADDRESS_MAX_LENGTH));
statement.setString(1, StringUtils.truncate(joinAddress, JoinAddressTable.JOIN_ADDRESS_MAX_LENGTH));
statement.addBatch();
}
}

View File

@ -96,6 +96,8 @@ Data_gathering:
Accept_GeoLite2_EULA: false
Ping: true
Disk_space: true
# Does not affect already gathered data
Preserve_join_address_case: false
# -----------------------------------------------------
# Supported time units: MILLISECONDS, SECONDS, MINUTES, HOURS, DAYS
# -----------------------------------------------------

View File

@ -101,6 +101,8 @@ Data_gathering:
Commands:
Log_unknown: false
Log_aliases_as_main_command: true
# Does not affect already gathered data
Preserve_join_address_case: false
# -----------------------------------------------------
# Supported time units: MILLISECONDS, SECONDS, MINUTES, HOURS, DAYS
# -----------------------------------------------------

View File

@ -3,7 +3,7 @@
"name": "dashboard",
"version": "0.1.0",
"private": true,
"proxy": "https://localhost:8804",
"proxy": "http://localhost:8800",
"dependencies": {
"@fortawesome/fontawesome-free": "^6.2.0",
"@fortawesome/fontawesome-svg-core": "^6.2.0",