From 7a10f1f70db209901b49e6683f69bb7028fefa50 Mon Sep 17 00:00:00 2001 From: Francisco Saldanha Date: Mon, 9 May 2016 16:36:14 -0300 Subject: [PATCH] Fix BugsnagSLF4JLogger and sort staff response by rank weight --- src/main/java/net/frozenorb/apiv3/APIv3.java | 4 ++-- .../frozenorb/apiv3/routes/users/GETStaff.java | 16 +++++++++++----- .../apiv3/unsorted/BugsnagSLF4JLogger.java | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/frozenorb/apiv3/APIv3.java b/src/main/java/net/frozenorb/apiv3/APIv3.java index d9e3ff6..32a0133 100644 --- a/src/main/java/net/frozenorb/apiv3/APIv3.java +++ b/src/main/java/net/frozenorb/apiv3/APIv3.java @@ -39,7 +39,7 @@ import net.frozenorb.apiv3.routes.users.*; import net.frozenorb.apiv3.serialization.DateTypeAdapter; import net.frozenorb.apiv3.serialization.FollowAnnotationExclusionStrategy; import net.frozenorb.apiv3.serialization.ObjectIdTypeAdapter; -import net.frozenorb.apiv3.unsorted.BugsnagSLF4jLogger; +import net.frozenorb.apiv3.unsorted.BugsnagSLF4JLogger; import net.frozenorb.apiv3.unsorted.LoggingExceptionHandler; import org.bson.types.ObjectId; import org.mongodb.morphia.Datastore; @@ -144,7 +144,7 @@ public final class APIv3 { Client bugsnag = new Client(config.getProperty("bugsnag.apiKey")); bugsnag.setReleaseStage(config.getProperty("general.releaseStage")); bugsnag.setProjectPackages("net.frozenorb.apiv3"); - bugsnag.setLogger(new BugsnagSLF4jLogger()); + bugsnag.setLogger(new BugsnagSLF4JLogger()); } private void setupHttp() { diff --git a/src/main/java/net/frozenorb/apiv3/routes/users/GETStaff.java b/src/main/java/net/frozenorb/apiv3/routes/users/GETStaff.java index 8e1e1a4..96da6e4 100644 --- a/src/main/java/net/frozenorb/apiv3/routes/users/GETStaff.java +++ b/src/main/java/net/frozenorb/apiv3/routes/users/GETStaff.java @@ -8,10 +8,7 @@ import spark.Request; import spark.Response; import spark.Route; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; +import java.util.*; public final class GETStaff implements Route { @@ -24,7 +21,16 @@ public final class GETStaff implements Route { } }); - Map> result = new HashMap<>(); + Map> result = new TreeMap<>((Comparator) (first, second) -> { + Rank firstRank = Rank.byId(first); + Rank secondRank = Rank.byId(second); + + if (firstRank.getWeight() > secondRank.getWeight()) { + return -1; + } + + return 1; + }); APIv3.getDatastore().createQuery(Grant.class).field("rank").in(staffRanks.keySet()).forEach(grant -> { if (grant.isActive()) { diff --git a/src/main/java/net/frozenorb/apiv3/unsorted/BugsnagSLF4JLogger.java b/src/main/java/net/frozenorb/apiv3/unsorted/BugsnagSLF4JLogger.java index 773da9c..f1574c6 100644 --- a/src/main/java/net/frozenorb/apiv3/unsorted/BugsnagSLF4JLogger.java +++ b/src/main/java/net/frozenorb/apiv3/unsorted/BugsnagSLF4JLogger.java @@ -4,7 +4,7 @@ import com.bugsnag.Logger; import lombok.extern.slf4j.Slf4j; @Slf4j -public class BugsnagSLF4jLogger extends Logger { +public class BugsnagSLF4JLogger extends Logger { public void debug(String message) { log.debug(message);