diff --git a/src/main/java/net/frozenorb/apiv3/APIv3.java b/src/main/java/net/frozenorb/apiv3/APIv3.java index bfe0cfd..0918744 100644 --- a/src/main/java/net/frozenorb/apiv3/APIv3.java +++ b/src/main/java/net/frozenorb/apiv3/APIv3.java @@ -154,16 +154,6 @@ public final class APIv3 extends AbstractVerticle { log.info(user.getLastUsername() + " - " + user.getLastSeenAt()); } });*/ - - /*V2Importer converter = new V2Importer("mongodb://158.69.126.126", "minehq"); - - converter.startImport((ignored, error) -> { - if (error != null) { - error.printStackTrace(); - } else { - log.info("Finished conversion!"); - } - });*/ } private void setupConfig() { diff --git a/src/main/java/net/frozenorb/apiv3/dataImport/V2Importer.java b/src/main/java/net/frozenorb/apiv3/dataImport/V2Importer.java deleted file mode 100644 index 76aaba6..0000000 --- a/src/main/java/net/frozenorb/apiv3/dataImport/V2Importer.java +++ /dev/null @@ -1,54 +0,0 @@ -package net.frozenorb.apiv3.dataImport; - -import com.mongodb.async.SingleResultCallback; -import com.mongodb.async.client.MongoClients; -import com.mongodb.async.client.MongoDatabase; -import io.vertx.core.CompositeFuture; -import io.vertx.core.Future; -import net.frozenorb.apiv3.dataImport.converters.GrantConverter; -import net.frozenorb.apiv3.dataImport.converters.PunishmentConverter; -import net.frozenorb.apiv3.dataImport.converters.UserConverter; -import net.frozenorb.apiv3.unsorted.MongoToVertxCallback; -import org.bson.types.ObjectId; - -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -public final class V2Importer { - - private final MongoDatabase importFrom; - - public V2Importer(String mongoIp, String database) { - importFrom = MongoClients.create(mongoIp).getDatabase(database); - } - - public void startImport(SingleResultCallback callback) { - Map oidToUniqueId = new HashMap<>(); - - importFrom.getCollection("user").find().forEach(new UserConverter(oidToUniqueId), (ignored, error) -> { - if (error != null) { - callback.onResult(null, error); - return; - } - - Future punishmentsFuture = Future.future(); - Future grantsFuture = Future.future(); - Future ipLogFuture = Future.future(); - - importFrom.getCollection("punishment").find().forEach(new PunishmentConverter(oidToUniqueId), new MongoToVertxCallback<>(punishmentsFuture)); - importFrom.getCollection("grant").find().forEach(new GrantConverter(oidToUniqueId), new MongoToVertxCallback<>(grantsFuture)); - //importFrom.getCollection("iplog").find().forEach(new IpLogConverter(oidToUniqueId), new MongoToVertxCallback<>(ipLogFuture)); - ipLogFuture.complete(); - - CompositeFuture.all(punishmentsFuture, grantsFuture, ipLogFuture).setHandler((result) -> { - if (result.succeeded()) { - callback.onResult(null, null); - } else { - callback.onResult(null, result.cause()); - } - }); - }); - } - -} \ No newline at end of file diff --git a/src/main/java/net/frozenorb/apiv3/dataImport/converters/GrantConverter.java b/src/main/java/net/frozenorb/apiv3/dataImport/converters/GrantConverter.java deleted file mode 100644 index b516beb..0000000 --- a/src/main/java/net/frozenorb/apiv3/dataImport/converters/GrantConverter.java +++ /dev/null @@ -1,68 +0,0 @@ -package net.frozenorb.apiv3.dataImport.converters; - -import com.google.common.collect.ImmutableSet; -import com.mongodb.Block; -import lombok.extern.slf4j.Slf4j; -import net.frozenorb.apiv3.model.Grant; -import net.frozenorb.apiv3.util.SyncUtils; -import org.bson.Document; -import org.bson.types.ObjectId; - -import java.time.Instant; -import java.util.Collection; -import java.util.Map; -import java.util.UUID; - -@Slf4j -public final class GrantConverter implements Block { - - private final Map oidToUniqueId; - - public GrantConverter(Map oidToUniqueId) { - this.oidToUniqueId = oidToUniqueId; - } - - @SuppressWarnings("unchecked") - @Override - public void apply(Document grant) { - UUID target = oidToUniqueId.get(((Map) grant.get("target")).get("$id")); - - if (target == null) { - return; - } - - String rank = grant.getString("role"); - - if (rank.equalsIgnoreCase("unban") || rank.equalsIgnoreCase("pass") || rank.equalsIgnoreCase("pink") || rank.equalsIgnoreCase("jrdev")) { - return; - } else if (rank.equalsIgnoreCase("high_roller")) { - rank = "highroller"; - } else if (rank.equalsIgnoreCase("dev")) { - rank = "developer"; - } else if (rank.equalsIgnoreCase("coowner")) { - rank = "owner"; - } else if (rank.equalsIgnoreCase("youtuber")) { - rank = "famous"; - } - - Grant created = new Grant( - new ObjectId().toString(), - target, - grant.containsKey("comment") ? grant.getString("comment") : "", - grant.containsKey("scope") ? ImmutableSet.copyOf((Collection) grant.get("scope")) : ImmutableSet.of(), - rank, - grant.containsKey("expires") ? grant.getDate("expires").toInstant() : null, - grant.containsKey("addedBy") ? oidToUniqueId.get(((Map) grant.get("addedBy")).get("$id")) : null, - grant.containsKey("created") ? grant.getDate("created").toInstant() : Instant.now(), - null, - null, - null, - -1, - -1 - ); - - SyncUtils.runBlocking(v -> created.insert(v)); - log.info("Created grant " + created.getId() + " (" + created.getRank() + ")"); - } - -} \ No newline at end of file diff --git a/src/main/java/net/frozenorb/apiv3/dataImport/converters/IpLogConverter.java b/src/main/java/net/frozenorb/apiv3/dataImport/converters/IpLogConverter.java deleted file mode 100644 index 092249e..0000000 --- a/src/main/java/net/frozenorb/apiv3/dataImport/converters/IpLogConverter.java +++ /dev/null @@ -1,58 +0,0 @@ -package net.frozenorb.apiv3.dataImport.converters; - -import com.mongodb.Block; -import lombok.extern.slf4j.Slf4j; -import net.frozenorb.apiv3.model.IpLogEntry; -import net.frozenorb.apiv3.util.IpUtils; -import net.frozenorb.apiv3.util.SyncUtils; -import org.bson.Document; -import org.bson.types.ObjectId; - -import java.util.Date; -import java.util.Map; -import java.util.UUID; - -@Slf4j -public final class IpLogConverter implements Block { - - private final Map oidToUniqueId; - - public IpLogConverter(Map oidToUniqueId) { - this.oidToUniqueId = oidToUniqueId; - } - - @SuppressWarnings("unchecked") - @Override - public void apply(Document ipLogEntry) { - UUID user = oidToUniqueId.get(((Map) ipLogEntry.get("user")).get("$id")); - - if (user == null || ipLogEntry.getString("ip") == null) { - return; - } - - String ip = ipLogEntry.getString("ip").replace("/", ""); - - if (!IpUtils.isValidIp(ip)) { - return; - } - - Date lastSeen = ipLogEntry.getDate("lastSeen"); - - if (lastSeen == null) { - lastSeen = new Date(); - } - - IpLogEntry created = new IpLogEntry( - new ObjectId().toString(), - user, - ip, - lastSeen.toInstant(), - lastSeen.toInstant(), - ((Number) ipLogEntry.get("uses")).intValue() - ); - - SyncUtils.runBlocking(v -> created.insert(v)); - log.info("Created ip log entry " + created.getId() + " (" + created.getUser() + " - " + created.getUserIp() + ")"); - } - -} \ No newline at end of file diff --git a/src/main/java/net/frozenorb/apiv3/dataImport/converters/PunishmentConverter.java b/src/main/java/net/frozenorb/apiv3/dataImport/converters/PunishmentConverter.java deleted file mode 100644 index e098378..0000000 --- a/src/main/java/net/frozenorb/apiv3/dataImport/converters/PunishmentConverter.java +++ /dev/null @@ -1,69 +0,0 @@ -package net.frozenorb.apiv3.dataImport.converters; - -import com.google.common.collect.ImmutableMap; -import com.mongodb.Block; -import lombok.extern.slf4j.Slf4j; -import net.frozenorb.apiv3.actor.ActorType; -import net.frozenorb.apiv3.model.Punishment; -import net.frozenorb.apiv3.util.SyncUtils; -import org.bson.Document; -import org.bson.types.ObjectId; - -import java.time.Instant; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.TimeUnit; - -@Slf4j -public final class PunishmentConverter implements Block { - - private final Map oidToUniqueId; - - public PunishmentConverter(Map oidToUniqueId) { - this.oidToUniqueId = oidToUniqueId; - } - - @SuppressWarnings("unchecked") - @Override - public void apply(Document punishment) { - UUID target = oidToUniqueId.get(((Map) punishment.get("user")).get("$id")); - - if (target == null) { - return; - } - - // Old punishments have this value set to false to indicate they're not active anymore. - if (punishment.containsKey("active") && !punishment.getBoolean("active")) { - return; - } - - Instant twoWeeks = Instant.now().minusSeconds(TimeUnit.DAYS.toSeconds(14)); - - if (punishment.getDate("created").toInstant().isBefore(twoWeeks)) { - return; - } - - Punishment created = new Punishment( - new ObjectId().toString(), - target, - "Hidden (legacy punishment)", - punishment.getString("reason").toString(), - Punishment.PunishmentType.valueOf(punishment.getString("type").toUpperCase()), - punishment.containsKey("expires") ? punishment.getDate("expires").toInstant() : null, - punishment.containsKey("meta") ? (punishment.get("meta") instanceof List ? ImmutableMap.of() : (Document) punishment.get("meta")) : ImmutableMap.of(), - null, - punishment.containsKey("addedBy") ? oidToUniqueId.get(((Map) punishment.get("addedBy")).get("$id")) : null, - punishment.getDate("created").toInstant(), - punishment.containsKey("createdOn") ? String.valueOf(((Map) punishment.get("createdOn")).get("$id")) : "Old Website", - punishment.containsKey("createdOn") ? ActorType.SERVER : ActorType.WEBSITE, - punishment.containsKey("removedBy") ? (((Map) punishment.get("removedBy")).get("$ref").equals("user") ? oidToUniqueId.get(((Map) punishment.get("removedBy")).get("$id")) : null) : null, - punishment.containsKey("removedBy") ? (punishment.containsKey("removedAt") ? punishment.getDate("removedAt") : punishment.getDate("created")).toInstant() : null, - punishment.containsKey("removedBy") ? punishment.getString("removalReason").toString() : null - ); - - SyncUtils.runBlocking(v -> created.insert(v)); - log.info("Created punishment " + created.getId() + " (" + created.getType() + ")"); - } - -} \ No newline at end of file diff --git a/src/main/java/net/frozenorb/apiv3/dataImport/converters/UserConverter.java b/src/main/java/net/frozenorb/apiv3/dataImport/converters/UserConverter.java deleted file mode 100644 index ed3ef9d..0000000 --- a/src/main/java/net/frozenorb/apiv3/dataImport/converters/UserConverter.java +++ /dev/null @@ -1,71 +0,0 @@ -package net.frozenorb.apiv3.dataImport.converters; - -import com.google.common.collect.ImmutableMap; -import com.mongodb.Block; -import lombok.extern.slf4j.Slf4j; -import net.frozenorb.apiv3.model.User; -import net.frozenorb.apiv3.util.SyncUtils; -import net.frozenorb.apiv3.util.UuidUtils; -import org.bson.Document; -import org.bson.types.ObjectId; - -import java.time.Instant; -import java.util.Map; -import java.util.UUID; - -@Slf4j -public final class UserConverter implements Block { - - private final Map oidToUniqueId; - - public UserConverter(Map oidToUniqueId) { - this.oidToUniqueId = oidToUniqueId; - } - - @Override - public void apply(Document user) { - String uuidString = String.valueOf(user.get("uuid")); - - if (uuidString == null || uuidString.length() != 32 || user.get("name") == null) { - return; - } - - UUID uuid = UuidUtils.parseUuid(uuidString); - - if (!UuidUtils.isAcceptableUuid(uuid)) { - return; - } - - oidToUniqueId.put(user.getObjectId("_id"), uuid); - - User created = new User( - uuid, - user.get("name").toString(), - ImmutableMap.of(user.get("name").toString(), user.getDate("joined").toInstant()), - null, - null, - null, - null, - user.getString("email"), - user.containsKey("email") ? Instant.EPOCH : null, - null, - null, - null, - user.getString("phone"), - user.containsKey("phone") ? Instant.EPOCH : null, - null, - null, - null, - null, - null, - "INVALID", - user.getDate("joined").toInstant(), - user.getDate("joined").toInstant(), - false - ); - - SyncUtils.runBlocking(v -> created.insert(v)); - log.info("Created user " + created.getLastUsername() + " (" + created.getId() + ")"); - } - -} \ No newline at end of file