Remove old data importer code

This commit is contained in:
Colin McDonald 2016-08-17 21:23:23 -04:00
parent 1689c3da67
commit e100009f4a
6 changed files with 0 additions and 330 deletions

View File

@ -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() {

View File

@ -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<Void> callback) {
Map<ObjectId, UUID> oidToUniqueId = new HashMap<>();
importFrom.getCollection("user").find().forEach(new UserConverter(oidToUniqueId), (ignored, error) -> {
if (error != null) {
callback.onResult(null, error);
return;
}
Future<Void> punishmentsFuture = Future.future();
Future<Void> grantsFuture = Future.future();
Future<Void> 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());
}
});
});
}
}

View File

@ -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<Document> {
private final Map<ObjectId, UUID> oidToUniqueId;
public GrantConverter(Map<ObjectId, UUID> oidToUniqueId) {
this.oidToUniqueId = oidToUniqueId;
}
@SuppressWarnings("unchecked")
@Override
public void apply(Document grant) {
UUID target = oidToUniqueId.get(((Map<String, Object>) 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<String>) grant.get("scope")) : ImmutableSet.of(),
rank,
grant.containsKey("expires") ? grant.getDate("expires").toInstant() : null,
grant.containsKey("addedBy") ? oidToUniqueId.get(((Map<String, Object>) grant.get("addedBy")).get("$id")) : null,
grant.containsKey("created") ? grant.getDate("created").toInstant() : Instant.now(),
null,
null,
null,
-1,
-1
);
SyncUtils.<Void>runBlocking(v -> created.insert(v));
log.info("Created grant " + created.getId() + " (" + created.getRank() + ")");
}
}

View File

@ -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<Document> {
private final Map<ObjectId, UUID> oidToUniqueId;
public IpLogConverter(Map<ObjectId, UUID> oidToUniqueId) {
this.oidToUniqueId = oidToUniqueId;
}
@SuppressWarnings("unchecked")
@Override
public void apply(Document ipLogEntry) {
UUID user = oidToUniqueId.get(((Map<String, Object>) 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.<Void>runBlocking(v -> created.insert(v));
log.info("Created ip log entry " + created.getId() + " (" + created.getUser() + " - " + created.getUserIp() + ")");
}
}

View File

@ -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<Document> {
private final Map<ObjectId, UUID> oidToUniqueId;
public PunishmentConverter(Map<ObjectId, UUID> oidToUniqueId) {
this.oidToUniqueId = oidToUniqueId;
}
@SuppressWarnings("unchecked")
@Override
public void apply(Document punishment) {
UUID target = oidToUniqueId.get(((Map<String, Object>) 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<String, Object>) punishment.get("addedBy")).get("$id")) : null,
punishment.getDate("created").toInstant(),
punishment.containsKey("createdOn") ? String.valueOf(((Map<String, Object>) punishment.get("createdOn")).get("$id")) : "Old Website",
punishment.containsKey("createdOn") ? ActorType.SERVER : ActorType.WEBSITE,
punishment.containsKey("removedBy") ? (((Map<String, Object>) punishment.get("removedBy")).get("$ref").equals("user") ? oidToUniqueId.get(((Map<String, Object>) 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.<Void>runBlocking(v -> created.insert(v));
log.info("Created punishment " + created.getId() + " (" + created.getType() + ")");
}
}

View File

@ -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<Document> {
private final Map<ObjectId, UUID> oidToUniqueId;
public UserConverter(Map<ObjectId, UUID> 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.<Void>runBlocking(v -> created.insert(v));
log.info("Created user " + created.getLastUsername() + " (" + created.getId() + ")");
}
}