Add /dumps/rankUsers?rank=<rank> to get all Users with a certain rank

This commit is contained in:
Colin McDonald 2016-10-16 19:38:28 -04:00
parent 0ca0dea102
commit d90981bdec
2 changed files with 48 additions and 0 deletions

View File

@ -153,6 +153,23 @@ public final class User {
usersCollection.find(new Document("lastUsernameLower", lastUsernameLower.toLowerCase())).first(SyncUtils.vertxWrap(callback)); usersCollection.find(new Document("lastUsernameLower", lastUsernameLower.toLowerCase())).first(SyncUtils.vertxWrap(callback));
} }
public static void findByIdGrouped(Set<UUID> search, SingleResultCallback<Map<UUID, User>> callback) {
usersCollection.find(new Document("_id", new Document("$in", search))).into(new LinkedList<>(), SyncUtils.vertxWrap((users, error) -> {
if (error != null) {
callback.onResult(null, error);
return;
}
Map<UUID, User> result = new HashMap<>();
for (User user : users) {
result.put(user.getId(), user);
}
callback.onResult(result, null);
}));
}
public static void findOrCreateByIdGrouped(Map<UUID, String> search, SingleResultCallback<Map<UUID, User>> callback) { public static void findOrCreateByIdGrouped(Map<UUID, String> search, SingleResultCallback<Map<UUID, User>> callback) {
usersCollection.find(new Document("_id", new Document("$in", search.keySet()))).into(new LinkedList<>(), SyncUtils.vertxWrap((users, error) -> { usersCollection.find(new Document("_id", new Document("$in", search.keySet()))).into(new LinkedList<>(), SyncUtils.vertxWrap((users, error) -> {
if (error != null) { if (error != null) {

View File

@ -179,6 +179,37 @@ public final class GETDumpsType implements Handler<RoutingContext> {
APIv3.respondJson(ctx, 200, grantCache.get(serverGroup.toLowerCase())); APIv3.respondJson(ctx, 200, grantCache.get(serverGroup.toLowerCase()));
return; return;
case "rankusers":
Rank rank = Rank.findById(ctx.request().getParam("rank"));
if (rank == null) {
ErrorUtils.respondNotFound(ctx, "Rank", ctx.request().getParam("rank"));
return;
}
Grant.findByRank(ImmutableSet.of(rank), (grants, grantError) -> {
if (grantError != null) {
ErrorUtils.respondInternalError(ctx, grantError);
return;
}
Set<UUID> uuids = new HashSet<>();
for (Grant grant : grants) {
if (grant.isActive()) {
uuids.add(grant.getUser());
}
}
User.findByIdGrouped(uuids, (users, userError) -> {
if (userError != null) {
ErrorUtils.respondInternalError(ctx, userError);
} else {
APIv3.respondJson(ctx, 200, users.values());
}
});
});
return;
case "ipintel": case "ipintel":
APIv3.respondJson(ctx, 200, ipIntelCache.values()); APIv3.respondJson(ctx, 200, ipIntelCache.values());
return; return;