Fixed many Extension Provider store errors

This commit is contained in:
Rsl1122 2019-03-20 17:17:23 +02:00
parent f31dbe8a9a
commit 134a7b1e18
10 changed files with 184 additions and 45 deletions

View File

@ -13,6 +13,8 @@ dependencies {
compile "org.slf4j:slf4j-api:$slf4jVersion"
compile "com.maxmind.geoip2:geoip2:$geoIpVersion"
compileOnly "com.google.guava:guava:$guavaVersion"
testCompile project(path: ":api", configuration: 'shadow')
}
shadowJar {

View File

@ -73,7 +73,7 @@ public class ExtensionProviderTable {
.column(IS_PLAYER_NAME, BOOL).notNull().defaultValue(false)
.column(PLUGIN_ID, INT).notNull()
.column(ICON_ID, INT).notNull()
.column(TAB_ID, INT).notNull()
.column(TAB_ID, INT)
.foreignKey(PLUGIN_ID, ExtensionPluginTable.TABLE_NAME, ExtensionPluginTable.ID)
.foreignKey(ICON_ID, ExtensionIconTable.TABLE_NAME, ExtensionIconTable.ID)
.foreignKey(TAB_ID, ExtensionTabTable.TABLE_NAME, ExtensionTabTable.ID)

View File

@ -92,12 +92,13 @@ public class ExtensionServiceImplementation implements ExtensionService {
gatherer.storeExtensionInformation();
extensionGatherers.put(pluginName, gatherer);
logger.getDebugLogger().logOn(DebugChannels.DATA_EXTENSIONS, pluginName + " extension disabled in the config.");
logger.getDebugLogger().logOn(DebugChannels.DATA_EXTENSIONS, pluginName + " extension registered.");
}
private boolean shouldNotAllowRegistration(String pluginName) {
PluginsConfigSection pluginsConfig = config.getPluginsConfigSection();
if (pluginsConfig.hasSection(pluginName)) {
if (!pluginsConfig.hasSection(pluginName)) {
try {
pluginsConfig.createSection(pluginName);
} catch (IOException e) {

View File

@ -27,6 +27,7 @@ import com.djrapitops.plan.extension.implementation.providers.DataProvider;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
import java.util.UUID;
import static com.djrapitops.plan.db.sql.parsing.Sql.AND;
@ -81,14 +82,26 @@ public class StoreBooleanProviderTransaction extends Transaction {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, providerInformation.getText());
statement.setString(2, providerInformation.getDescription().orElse(null));
if (providerInformation.getDescription().isPresent()) {
statement.setString(2, providerInformation.getDescription().get());
} else {
statement.setNull(2, Types.VARCHAR);
}
statement.setInt(3, providerInformation.getPriority());
statement.setString(4, providerInformation.getCondition().orElse(null));
statement.setString(5, providedCondition);
ExtensionTabTable.set3TabValuesToStatement(statement, 6, providerInformation.getTab().orElse(null), providerInformation.getPluginName(), serverUUID);
if (providerInformation.getCondition().isPresent()) {
statement.setString(4, providerInformation.getCondition().orElse(null));
} else {
statement.setNull(4, Types.VARCHAR);
}
if (providedCondition != null) {
statement.setString(5, providedCondition);
} else {
statement.setNull(5, Types.VARCHAR);
}
ExtensionTabTable.set3TabValuesToStatement(statement, 6, providerInformation.getTab().orElse("No Tab"), providerInformation.getPluginName(), serverUUID);
ExtensionIconTable.set3IconValuesToStatement(statement, 9, providerInformation.getIcon());
ExtensionPluginTable.set2PluginValuesToStatement(statement, 11, providerInformation.getPluginName(), serverUUID);
statement.setString(13, providerInformation.getName());
ExtensionPluginTable.set2PluginValuesToStatement(statement, 12, providerInformation.getPluginName(), serverUUID);
statement.setString(14, providerInformation.getName());
}
};
}
@ -113,13 +126,25 @@ public class StoreBooleanProviderTransaction extends Transaction {
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, providerInformation.getName());
statement.setString(2, providerInformation.getText());
statement.setString(3, providerInformation.getDescription().orElse(null));
if (providerInformation.getDescription().isPresent()) {
statement.setString(3, providerInformation.getDescription().get());
} else {
statement.setNull(3, Types.VARCHAR);
}
statement.setInt(4, providerInformation.getPriority());
statement.setString(5, providerInformation.getCondition().orElse(null));
statement.setString(6, providedCondition);
ExtensionTabTable.set3TabValuesToStatement(statement, 7, providerInformation.getTab().orElse(null), providerInformation.getPluginName(), serverUUID);
if (providerInformation.getCondition().isPresent()) {
statement.setString(5, providerInformation.getCondition().orElse(null));
} else {
statement.setNull(5, Types.VARCHAR);
}
if (providedCondition != null) {
statement.setString(6, providedCondition);
} else {
statement.setNull(6, Types.VARCHAR);
}
ExtensionTabTable.set3TabValuesToStatement(statement, 7, providerInformation.getTab().orElse("No Tab"), providerInformation.getPluginName(), serverUUID);
ExtensionIconTable.set3IconValuesToStatement(statement, 10, providerInformation.getIcon());
ExtensionPluginTable.set2PluginValuesToStatement(statement, 12, providerInformation.getPluginName(), serverUUID);
ExtensionPluginTable.set2PluginValuesToStatement(statement, 13, providerInformation.getPluginName(), serverUUID);
}
};
}

View File

@ -27,6 +27,7 @@ import com.djrapitops.plan.extension.implementation.providers.DataProvider;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
import java.util.UUID;
import static com.djrapitops.plan.db.sql.parsing.Sql.AND;
@ -82,12 +83,20 @@ public class StoreDoubleProviderTransaction extends Transaction {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, providerInformation.getText());
statement.setString(2, providerInformation.getDescription().orElse(null));
if (providerInformation.getDescription().isPresent()) {
statement.setString(2, providerInformation.getDescription().get());
} else {
statement.setNull(2, Types.VARCHAR);
}
statement.setInt(3, providerInformation.getPriority());
statement.setString(4, providerInformation.getCondition().orElse(null));
ExtensionTabTable.set3TabValuesToStatement(statement, 5, providerInformation.getTab().orElse(null), providerInformation.getPluginName(), serverUUID);
if (providerInformation.getCondition().isPresent()) {
statement.setString(4, providerInformation.getCondition().orElse(null));
} else {
statement.setNull(4, Types.VARCHAR);
}
ExtensionTabTable.set3TabValuesToStatement(statement, 5, providerInformation.getTab().orElse("No Tab"), providerInformation.getPluginName(), serverUUID);
ExtensionIconTable.set3IconValuesToStatement(statement, 8, providerInformation.getIcon());
ExtensionPluginTable.set2PluginValuesToStatement(statement, 10, providerInformation.getPluginName(), serverUUID);
ExtensionPluginTable.set2PluginValuesToStatement(statement, 11, providerInformation.getPluginName(), serverUUID);
statement.setString(13, providerInformation.getName());
}
};
@ -103,7 +112,7 @@ public class StoreDoubleProviderTransaction extends Transaction {
TAB_ID + "," +
ICON_ID + "," +
PLUGIN_ID +
") VALUES (?,?,?,?,?,?," +
") VALUES (?,?,?,?,?," +
ExtensionTabTable.STATEMENT_SELECT_TAB_ID + "," +
ExtensionIconTable.STATEMENT_SELECT_ICON_ID + "," +
ExtensionPluginTable.STATEMENT_SELECT_PLUGIN_ID + ")";
@ -112,12 +121,20 @@ public class StoreDoubleProviderTransaction extends Transaction {
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, providerInformation.getName());
statement.setString(2, providerInformation.getText());
statement.setString(3, providerInformation.getDescription().orElse(null));
if (providerInformation.getDescription().isPresent()) {
statement.setString(3, providerInformation.getDescription().get());
} else {
statement.setNull(3, Types.VARCHAR);
}
statement.setInt(4, providerInformation.getPriority());
statement.setString(5, providerInformation.getCondition().orElse(null));
ExtensionTabTable.set3TabValuesToStatement(statement, 6, providerInformation.getTab().orElse(null), providerInformation.getPluginName(), serverUUID);
if (providerInformation.getCondition().isPresent()) {
statement.setString(5, providerInformation.getCondition().get());
} else {
statement.setNull(5, Types.VARCHAR);
}
ExtensionTabTable.set3TabValuesToStatement(statement, 6, providerInformation.getTab().orElse("No Tab"), providerInformation.getPluginName(), serverUUID);
ExtensionIconTable.set3IconValuesToStatement(statement, 9, providerInformation.getIcon());
ExtensionPluginTable.set2PluginValuesToStatement(statement, 11, providerInformation.getPluginName(), serverUUID);
ExtensionPluginTable.set2PluginValuesToStatement(statement, 12, providerInformation.getPluginName(), serverUUID);
}
};
}

View File

@ -28,6 +28,7 @@ import com.djrapitops.plan.extension.implementation.providers.DataProvider;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
import java.util.UUID;
import static com.djrapitops.plan.db.sql.parsing.Sql.AND;
@ -39,6 +40,7 @@ import static com.djrapitops.plan.db.sql.tables.ExtensionProviderTable.*;
*
* @author Rsl1122
*/
@SuppressWarnings("Duplicates")
public class StoreNumberProviderTransaction extends Transaction {
private final FormatType formatType;
@ -66,8 +68,7 @@ public class StoreNumberProviderTransaction extends Transaction {
}
private Executable updateProvider() {
String sql = "UPDATE " + TABLE_NAME +
" SET " +
String sql = "UPDATE " + TABLE_NAME + " SET " +
TEXT + "=?," +
DESCRIPTION + "=?," +
PRIORITY + "=?," +
@ -82,14 +83,22 @@ public class StoreNumberProviderTransaction extends Transaction {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, providerInformation.getText());
statement.setString(2, providerInformation.getDescription().orElse(null));
if (providerInformation.getDescription().isPresent()) {
statement.setString(2, providerInformation.getDescription().get());
} else {
statement.setNull(2, Types.VARCHAR);
}
statement.setInt(3, providerInformation.getPriority());
statement.setString(4, providerInformation.getCondition().orElse(null));
if (providerInformation.getCondition().isPresent()) {
statement.setString(4, providerInformation.getCondition().orElse(null));
} else {
statement.setNull(4, Types.VARCHAR);
}
statement.setString(5, formatType.name());
ExtensionTabTable.set3TabValuesToStatement(statement, 6, providerInformation.getTab().orElse(null), providerInformation.getPluginName(), serverUUID);
ExtensionTabTable.set3TabValuesToStatement(statement, 6, providerInformation.getTab().orElse("No Tab"), providerInformation.getPluginName(), serverUUID);
ExtensionIconTable.set3IconValuesToStatement(statement, 9, providerInformation.getIcon());
ExtensionPluginTable.set2PluginValuesToStatement(statement, 11, providerInformation.getPluginName(), serverUUID);
statement.setString(13, providerInformation.getName());
ExtensionPluginTable.set2PluginValuesToStatement(statement, 12, providerInformation.getPluginName(), serverUUID);
statement.setString(14, providerInformation.getName());
}
};
}
@ -114,13 +123,21 @@ public class StoreNumberProviderTransaction extends Transaction {
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, providerInformation.getName());
statement.setString(2, providerInformation.getText());
statement.setString(3, providerInformation.getDescription().orElse(null));
if (providerInformation.getDescription().isPresent()) {
statement.setString(3, providerInformation.getDescription().get());
} else {
statement.setNull(3, Types.VARCHAR);
}
statement.setInt(4, providerInformation.getPriority());
statement.setString(5, providerInformation.getCondition().orElse(null));
if (providerInformation.getCondition().isPresent()) {
statement.setString(5, providerInformation.getCondition().orElse(null));
} else {
statement.setNull(5, Types.VARCHAR);
}
statement.setString(6, formatType.name());
ExtensionTabTable.set3TabValuesToStatement(statement, 7, providerInformation.getTab().orElse(null), providerInformation.getPluginName(), serverUUID);
ExtensionTabTable.set3TabValuesToStatement(statement, 7, providerInformation.getTab().orElse("No Tab"), providerInformation.getPluginName(), serverUUID);
ExtensionIconTable.set3IconValuesToStatement(statement, 10, providerInformation.getIcon());
ExtensionPluginTable.set2PluginValuesToStatement(statement, 12, providerInformation.getPluginName(), serverUUID);
ExtensionPluginTable.set2PluginValuesToStatement(statement, 13, providerInformation.getPluginName(), serverUUID);
}
};
}

View File

@ -27,6 +27,7 @@ import com.djrapitops.plan.extension.implementation.providers.DataProvider;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
import java.util.UUID;
import static com.djrapitops.plan.db.sql.parsing.Sql.AND;
@ -81,14 +82,22 @@ public class StoreStringProviderTransaction extends Transaction {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, providerInformation.getText());
statement.setString(2, providerInformation.getDescription().orElse(null));
if (providerInformation.getDescription().isPresent()) {
statement.setString(2, providerInformation.getDescription().get());
} else {
statement.setNull(2, Types.VARCHAR);
}
statement.setInt(3, providerInformation.getPriority());
statement.setString(4, providerInformation.getCondition().orElse(null));
if (providerInformation.getCondition().isPresent()) {
statement.setString(4, providerInformation.getCondition().orElse(null));
} else {
statement.setNull(4, Types.VARCHAR);
}
statement.setBoolean(5, playerName);
ExtensionTabTable.set3TabValuesToStatement(statement, 6, providerInformation.getTab().orElse(null), providerInformation.getPluginName(), serverUUID);
ExtensionTabTable.set3TabValuesToStatement(statement, 6, providerInformation.getTab().orElse("No Tab"), providerInformation.getPluginName(), serverUUID);
ExtensionIconTable.set3IconValuesToStatement(statement, 9, providerInformation.getIcon());
ExtensionPluginTable.set2PluginValuesToStatement(statement, 11, providerInformation.getPluginName(), serverUUID);
statement.setString(13, providerInformation.getName());
ExtensionPluginTable.set2PluginValuesToStatement(statement, 12, providerInformation.getPluginName(), serverUUID);
statement.setString(14, providerInformation.getName());
}
};
}
@ -113,13 +122,21 @@ public class StoreStringProviderTransaction extends Transaction {
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, providerInformation.getName());
statement.setString(2, providerInformation.getText());
statement.setString(3, providerInformation.getDescription().orElse(null));
if (providerInformation.getDescription().isPresent()) {
statement.setString(3, providerInformation.getDescription().get());
} else {
statement.setNull(3, Types.VARCHAR);
}
statement.setInt(4, providerInformation.getPriority());
statement.setString(5, providerInformation.getCondition().orElse(null));
if (providerInformation.getCondition().isPresent()) {
statement.setString(5, providerInformation.getCondition().orElse(null));
} else {
statement.setNull(5, Types.VARCHAR);
}
statement.setBoolean(6, playerName);
ExtensionTabTable.set3TabValuesToStatement(statement, 7, providerInformation.getTab().orElse(null), providerInformation.getPluginName(), serverUUID);
ExtensionTabTable.set3TabValuesToStatement(statement, 7, providerInformation.getTab().orElse("No Tab"), providerInformation.getPluginName(), serverUUID);
ExtensionIconTable.set3IconValuesToStatement(statement, 10, providerInformation.getIcon());
ExtensionPluginTable.set2PluginValuesToStatement(statement, 12, providerInformation.getPluginName(), serverUUID);
ExtensionPluginTable.set2PluginValuesToStatement(statement, 13, providerInformation.getPluginName(), serverUUID);
}
};
}

View File

@ -19,6 +19,7 @@ package com.djrapitops.plan.system;
import com.djrapitops.plan.api.PlanAPI;
import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.data.plugin.HookHandler;
import com.djrapitops.plan.extension.ExtensionService;
import com.djrapitops.plan.extension.ExtensionServiceImplementation;
import com.djrapitops.plan.system.cache.CacheSystem;
import com.djrapitops.plan.system.database.DBSystem;
@ -253,4 +254,8 @@ public class PlanSystem implements SubSystem {
public boolean isEnabled() {
return enabled;
}
public ExtensionService getExtensionService() {
return extensionService;
}
}

View File

@ -30,6 +30,7 @@ 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;
@ -44,12 +45,17 @@ 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.system.PlanSystem;
import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.settings.config.Config;
import com.djrapitops.plan.system.settings.config.PlanConfig;
import com.djrapitops.plan.system.settings.paths.DatabaseSettings;
import com.djrapitops.plan.system.settings.paths.WebserverSettings;
import com.djrapitops.plan.utilities.SHA256Hash;
import com.djrapitops.plan.utilities.comparators.DateHolderRecentComparator;
@ -69,6 +75,8 @@ 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;
@ -104,7 +112,9 @@ public abstract class CommonDBTest {
static void handleSetup(String dbName) throws Exception {
system = component.getPlanSystem();
system.getConfigSystem().getConfig().set(WebserverSettings.PORT, TEST_PORT_NUMBER);
PlanConfig config = system.getConfigSystem().getConfig();
config.set(WebserverSettings.PORT, TEST_PORT_NUMBER);
config.set(DatabaseSettings.TYPE, dbName);
system.enable();
dbSystem = system.getDatabaseSystem();
@ -1015,4 +1025,48 @@ public abstract class CommonDBTest {
Map<UUID, Integer> result = db.query(ServerAggregateQueries.serverUserCounts());
assertEquals(expected, result);
}
@Test
public void extensionValuesAreStored() {
ExtensionServiceImplementation extensionService = (ExtensionServiceImplementation) system.getExtensionService();
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());
}
}));
}
@PluginInfo(name = "TestExtension")
public class TestExtension implements DataExtension {
@NumberProvider(text = "a number")
public long value(UUID playerUUD) {
return 5L;
}
@BooleanProvider(text = "a boolean")
public boolean boolVal(UUID playerUUID) {
return false;
}
@DoubleProvider(text = "a double")
public double doubleVal(UUID playerUUID) {
return 0.5;
}
@PercentageProvider(text = "a percentage")
public double percentageVal(UUID playerUUID) {
return 0.5;
}
@StringProvider(text = "a string")
public String stringVal(UUID playerUUID) {
return "";
}
}
}

View File

@ -23,6 +23,7 @@ import com.djrapitops.plan.db.access.transactions.events.SessionEndTransaction;
import com.djrapitops.plan.db.access.transactions.events.WorldNameStoreTransaction;
import com.djrapitops.plan.system.PlanSystem;
import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.locale.lang.ErrorPageLang;
import com.djrapitops.plan.system.settings.config.PlanConfig;
import com.djrapitops.plan.system.settings.paths.WebserverSettings;
import com.djrapitops.plan.system.webserver.cache.PageId;
@ -113,7 +114,7 @@ public class JSErrorRegressionTest {
System.out.println("Testing Player Page via UUID");
WebDriver driver = seleniumDriver.getDriver();
driver.get("http://localhost:" + TEST_PORT_NUMBER + "/player/" + TestConstants.PLAYER_ONE_UUID);
assertFalse(driver.getPageSource(), driver.getPageSource().contains("404 "));
assertFalse(driver.getPageSource(), driver.getPageSource().contains(ErrorPageLang.NOT_PLAYED_404.getDefault()));
}
@Test