use of com.djrapitops.plan.identification.Server in project Plan by plan-player-analytics.
the class ServerQueries method fetchProxyServerInformation.
public static Query<Optional<Server>> fetchProxyServerInformation() {
String sql = SELECT + '*' + FROM + ServerTable.TABLE_NAME + WHERE + ServerTable.INSTALLED + "=?" + AND + ServerTable.PROXY + "=?" + LIMIT + '1';
return new QueryStatement<Optional<Server>>(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setBoolean(1, true);
statement.setBoolean(2, true);
}
@Override
public Optional<Server> processResults(ResultSet set) throws SQLException {
if (set.next()) {
return Optional.of(new Server(set.getInt(ServerTable.ID), ServerUUID.fromString(set.getString(ServerTable.SERVER_UUID)), set.getString(ServerTable.NAME), set.getString(ServerTable.WEB_ADDRESS), set.getBoolean(ServerTable.PROXY), set.getString(ServerTable.PLAN_VERSION)));
}
return Optional.empty();
}
};
}
use of com.djrapitops.plan.identification.Server in project Plan by plan-player-analytics.
the class ServerQueries method fetchPlanServerInformation.
/**
* Query database for all Plan server information.
*
* @return Map: Server UUID - Plan Server Information
*/
public static Query<Map<ServerUUID, Server>> fetchPlanServerInformation() {
String sql = SELECT + '*' + FROM + ServerTable.TABLE_NAME + WHERE + ServerTable.INSTALLED + "=?";
return new QueryStatement<Map<ServerUUID, Server>>(sql, 100) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setBoolean(1, true);
}
@Override
public Map<ServerUUID, Server> processResults(ResultSet set) throws SQLException {
Map<ServerUUID, Server> servers = new HashMap<>();
while (set.next()) {
ServerUUID serverUUID = ServerUUID.fromString(set.getString(ServerTable.SERVER_UUID));
servers.put(serverUUID, new Server(set.getInt(ServerTable.ID), serverUUID, set.getString(ServerTable.NAME), set.getString(ServerTable.WEB_ADDRESS), set.getBoolean(ServerTable.PROXY), set.getString(ServerTable.PLAN_VERSION)));
}
return servers;
}
};
}
use of com.djrapitops.plan.identification.Server in project Plan by plan-player-analytics.
the class ServerQueries method findMatchingServers.
public static Query<List<Server>> findMatchingServers(String identifier) {
if (identifier.isEmpty())
return db -> Collections.emptyList();
String sql = SELECT + '*' + FROM + ServerTable.TABLE_NAME + WHERE + "(LOWER(" + ServerTable.SERVER_UUID + ") LIKE LOWER(?)" + OR + "LOWER(" + ServerTable.NAME + ") LIKE LOWER(?)" + OR + ServerTable.ID + "=?" + OR + ServerTable.ID + "=?)" + AND + ServerTable.INSTALLED + "=?" + LIMIT + '1';
return new QueryStatement<List<Server>>(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, '%' + identifier + '%');
statement.setString(2, '%' + identifier + '%');
statement.setInt(3, NumberUtils.isParsable(identifier) ? Integer.parseInt(identifier) : -1);
String id = identifier.startsWith("Server ") ? identifier.substring(7) : identifier;
statement.setInt(4, NumberUtils.isParsable(id) ? Integer.parseInt(id) : -1);
statement.setBoolean(5, true);
}
@Override
public List<Server> processResults(ResultSet set) throws SQLException {
List<Server> matches = new ArrayList<>();
while (set.next()) {
matches.add(new Server(set.getInt(ServerTable.ID), ServerUUID.fromString(set.getString(ServerTable.SERVER_UUID)), set.getString(ServerTable.NAME), set.getString(ServerTable.WEB_ADDRESS), set.getBoolean(ServerTable.PROXY), set.getString(ServerTable.PLAN_VERSION)));
}
return matches;
}
};
}
use of com.djrapitops.plan.identification.Server in project Plan by plan-player-analytics.
the class AccessControlTest method setUpClass.
@BeforeAll
static void setUpClass(@TempDir Path tempDir) throws Exception {
File file = tempDir.resolve("TestCert.p12").toFile();
File testCert = TestResources.getTestResourceFile("TestCert.p12", ConfigUpdater.class);
Files.copy(testCert.toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING);
String absolutePath = file.getAbsolutePath();
PluginMockComponent component = new PluginMockComponent(tempDir);
system = component.getPlanSystem();
PlanConfig config = system.getConfigSystem().getConfig();
config.set(WebserverSettings.CERTIFICATE_PATH, absolutePath);
config.set(WebserverSettings.CERTIFICATE_KEYPASS, "test");
config.set(WebserverSettings.CERTIFICATE_STOREPASS, "test");
config.set(WebserverSettings.CERTIFICATE_ALIAS, "test");
config.set(WebserverSettings.PORT, TEST_PORT_NUMBER);
system.enable();
User userLevel0 = new User("test0", "console", null, PassEncryptUtil.createHash("testPass"), 0, Collections.emptyList());
User userLevel1 = new User("test1", "console", null, PassEncryptUtil.createHash("testPass"), 1, Collections.emptyList());
User userLevel2 = new User("test2", TestConstants.PLAYER_ONE_NAME, TestConstants.PLAYER_ONE_UUID, PassEncryptUtil.createHash("testPass"), 2, Collections.emptyList());
User userLevel100 = new User("test100", "console", null, PassEncryptUtil.createHash("testPass"), 100, Collections.emptyList());
system.getDatabaseSystem().getDatabase().executeTransaction(new RegisterWebUserTransaction(userLevel0));
system.getDatabaseSystem().getDatabase().executeTransaction(new RegisterWebUserTransaction(userLevel1));
system.getDatabaseSystem().getDatabase().executeTransaction(new RegisterWebUserTransaction(userLevel2));
system.getDatabaseSystem().getDatabase().executeTransaction(new RegisterWebUserTransaction(userLevel100));
system.getDatabaseSystem().getDatabase().executeTransaction(new PlayerRegisterTransaction(TestConstants.PLAYER_ONE_UUID, () -> 0L, TestConstants.PLAYER_ONE_NAME));
system.getDatabaseSystem().getDatabase().executeTransaction(new StoreServerInformationTransaction(new Server(TestConstants.SERVER_UUID, TestConstants.SERVER_NAME, address, TestConstants.VERSION)));
Caller caller = system.getExtensionService().register(new ExtensionsDatabaseTest.PlayerExtension()).orElseThrow(AssertionError::new);
caller.updatePlayerData(TestConstants.PLAYER_ONE_UUID, TestConstants.PLAYER_ONE_NAME);
address = "https://localhost:" + TEST_PORT_NUMBER;
cookieLevel0 = login(address, userLevel0.getUsername());
cookieLevel1 = login(address, userLevel1.getUsername());
cookieLevel2 = login(address, userLevel2.getUsername());
cookieLevel100 = login(address, userLevel100.getUsername());
}
use of com.djrapitops.plan.identification.Server in project Plan by plan-player-analytics.
the class LargeStoreQueries method storeAllPlanServerInformation.
/**
* Execute a big batch of server information insert statements.
*
* @param servers Collection of Plan Servers.
* @return Executable, use inside a {@link com.djrapitops.plan.storage.database.transactions.Transaction}
*/
public static Executable storeAllPlanServerInformation(Collection<Server> servers) {
if (servers == null || servers.isEmpty())
return Executable.empty();
return new ExecBatchStatement(ServerTable.INSERT_STATEMENT) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
for (Server server : servers) {
ServerUUID serverUUID = server.getUuid();
if (serverUUID == null) {
continue;
}
statement.setString(1, serverUUID.toString());
statement.setString(2, server.getName());
statement.setString(3, server.getWebAddress());
statement.setBoolean(4, true);
statement.setBoolean(5, server.isProxy());
statement.setString(6, server.getPlanVersion());
statement.addBatch();
}
}
};
}
Aggregations