From 476dd402872dc7c0136c779d13eb0e49c59264ef Mon Sep 17 00:00:00 2001 From: Nathaniel Gerlek Date: Thu, 14 Nov 2024 10:05:59 -0700 Subject: [PATCH 01/10] refactor: rmv Server's dependency on Controllers --- src/main/java/edu/byu/cs/server/Server.java | 86 ++++----- .../endpointprovider/EndpointProvider.java | 55 ++++++ .../EndpointProviderImpl.java | 170 ++++++++++++++++++ 3 files changed, 268 insertions(+), 43 deletions(-) create mode 100644 src/main/java/edu/byu/cs/server/endpointprovider/EndpointProvider.java create mode 100644 src/main/java/edu/byu/cs/server/endpointprovider/EndpointProviderImpl.java diff --git a/src/main/java/edu/byu/cs/server/Server.java b/src/main/java/edu/byu/cs/server/Server.java index eee8d25a..beeae5b7 100644 --- a/src/main/java/edu/byu/cs/server/Server.java +++ b/src/main/java/edu/byu/cs/server/Server.java @@ -5,6 +5,8 @@ import edu.byu.cs.dataAccess.DaoService; import edu.byu.cs.dataAccess.DataAccessException; import edu.byu.cs.properties.ApplicationProperties; +import edu.byu.cs.server.endpointprovider.EndpointProvider; +import edu.byu.cs.server.endpointprovider.EndpointProviderImpl; import edu.byu.cs.service.SubmissionService; import edu.byu.cs.util.ResourceUtils; import org.apache.commons.cli.*; @@ -15,19 +17,18 @@ import java.io.IOException; import java.util.Properties; -import static edu.byu.cs.controller.AdminController.*; -import static edu.byu.cs.controller.AuthController.*; -import static edu.byu.cs.controller.CasController.*; -import static edu.byu.cs.controller.ConfigController.*; -import static edu.byu.cs.controller.SubmissionController.*; -import static edu.byu.cs.controller.UserController.*; import static spark.Spark.*; public class Server { private static final Logger LOGGER = LoggerFactory.getLogger(Server.class); + private final EndpointProvider provider; - public static int setupEndpoints(int port) { + public Server(EndpointProvider endpointProvider) { + this.provider = endpointProvider; + } + + public int setupEndpoints(int port) { port(port); webSocket("/ws", WebSocketController.class); @@ -43,79 +44,77 @@ public static int setupEndpoints(int port) { }); path("/auth", () -> { - get("/callback", callbackGet); - get("/login", loginGet); + get("/callback", provider.callbackGet()); + get("/login", provider.loginGet()); // all routes after this point require authentication - post("/logout", logoutPost); + post("/logout", provider.logoutPost()); }); path("/api", () -> { before("/*", (req, res) -> { - if (!req.requestMethod().equals("OPTIONS")) - verifyAuthenticatedMiddleware.handle(req, res); + if (!req.requestMethod().equals("OPTIONS")) provider.verifyAuthenticatedMiddleware().handle(req, res); }); - patch("/repo", repoPatch); + patch("/repo", provider.repoPatch()); - get("/submit", submitGet); - post("/submit", submitPost); + get("/submit", provider.submitGet()); + post("/submit", provider.submitPost()); - get("/latest", latestSubmissionForMeGet); + get("/latest", provider.latestSubmissionForMeGet()); - get("/submission", submissionXGet); - get("/submission/:phase", submissionXGet); + get("/submission", provider.submissionXGet()); + get("/submission/:phase", provider.submissionXGet()); - get("/me", meGet); + get("/me", provider.meGet()); - get("/config", getConfigStudent); + get("/config", provider.getConfigStudent()); path("/admin", () -> { before("/*", (req, res) -> { - if (!req.requestMethod().equals("OPTIONS")) - verifyAdminMiddleware.handle(req, res); + if (!req.requestMethod().equals("OPTIONS")) provider.verifyAdminMiddleware().handle(req, res); }); - patch("/repo/:netId", repoPatchAdmin); + patch("/repo/:netId", provider.repoPatchAdmin()); - get("/repo/history", repoHistoryAdminGet); + get("/repo/history", provider.repoHistoryAdminGet()); - get("/users", usersGet); + get("/users", provider.usersGet()); - post("/submit", adminRepoSubmitPost); + post("/submit", provider.adminRepoSubmitPost()); path("/submissions", () -> { - post("/approve", approveSubmissionPost); + post("/approve", provider.approveSubmissionPost()); - get("/latest", latestSubmissionsGet); + get("/latest", provider.latestSubmissionsGet()); - get("/latest/:count", latestSubmissionsGet); + get("/latest/:count", provider.latestSubmissionsGet()); - get("/active", submissionsActiveGet); + get("/active", provider.submissionsActiveGet()); - get("/student/:netId", studentSubmissionsGet); + get("/student/:netId", provider.studentSubmissionsGet()); - post("/rerun", submissionsReRunPost); + post("/rerun", provider.submissionsReRunPost()); }); - get("/test_mode", testModeGet); + get("/test_mode", provider.testModeGet()); - get("/analytics/commit", commitAnalyticsGet); + get("/analytics/commit", provider.commitAnalyticsGet()); - get("/analytics/commit/:option", commitAnalyticsGet); + get("/analytics/commit/:option", provider.commitAnalyticsGet()); - get("/honorChecker/zip/:section", honorCheckerZipGet); + get("/honorChecker/zip/:section", provider.honorCheckerZipGet()); - get("/sections", sectionsGet); + get("/sections", provider.sectionsGet()); path("/config", () -> { - get("", getConfigAdmin); + get("", provider.getConfigAdmin()); - post("/phases", updateLivePhases); - post("/banner", updateBannerMessage); + post("/phases", provider.updateLivePhases()); + post("/banner", provider.updateBannerMessage()); - post("/courseIds", updateCourseIdsPost); - get("/courseIds", updateCourseIdsUsingCanvasGet); + post("/courseIds", provider.updateCourseIdsPost()); + get("/courseIds", provider.updateCourseIdsUsingCanvasGet()); }); }); }); @@ -207,7 +206,8 @@ public static void main(String[] args) { throw new RuntimeException(e); } - int port = setupEndpoints(8080); + EndpointProvider endpointProvider = new EndpointProviderImpl(); + int port = new Server(endpointProvider).setupEndpoints(8080); LOGGER.info("Server started on port {}", port); diff --git a/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProvider.java b/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProvider.java new file mode 100644 index 00000000..8ab0345e --- /dev/null +++ b/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProvider.java @@ -0,0 +1,55 @@ +package edu.byu.cs.server.endpointprovider; + +import spark.Filter; +import spark.Route; + +public interface EndpointProvider { + + // AdminController + + Route usersGet(); + Route testModeGet(); + Route commitAnalyticsGet(); + Route honorCheckerZipGet(); + Route sectionsGet(); + + // AuthController + + Filter verifyAuthenticatedMiddleware(); + Filter verifyAdminMiddleware(); + Route meGet(); + + // CasController + + Route callbackGet(); + Route loginGet(); + Route logoutPost(); + + // ConfigController + + Route getConfigAdmin(); + Route getConfigStudent(); + Route updateLivePhases(); + Route updateBannerMessage(); + Route updateCourseIdsPost(); + Route updateCourseIdsUsingCanvasGet(); + + // SubmissionController + + Route submitPost(); + Route adminRepoSubmitPost(); + Route submitGet(); + Route latestSubmissionForMeGet(); + Route submissionXGet(); + Route latestSubmissionsGet(); + Route submissionsActiveGet(); + Route studentSubmissionsGet(); + Route approveSubmissionPost(); + Route submissionsReRunPost(); + + // UserController + + Route repoPatch(); + Route repoPatchAdmin(); + Route repoHistoryAdminGet(); +} diff --git a/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProviderImpl.java b/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProviderImpl.java new file mode 100644 index 00000000..af35839f --- /dev/null +++ b/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProviderImpl.java @@ -0,0 +1,170 @@ +package edu.byu.cs.server.endpointprovider; + +import edu.byu.cs.controller.*; +import spark.Filter; +import spark.Route; + +public class EndpointProviderImpl implements EndpointProvider { + + // AdminController + + @Override + public Route usersGet() { + return AdminController.usersGet; + } + + @Override + public Route testModeGet() { + return AdminController.testModeGet; + } + + @Override + public Route commitAnalyticsGet() { + return AdminController.commitAnalyticsGet; + } + + @Override + public Route honorCheckerZipGet() { + return AdminController.honorCheckerZipGet; + } + + @Override + public Route sectionsGet() { + return AdminController.sectionsGet; + } + + // AuthController + + @Override + public Filter verifyAuthenticatedMiddleware() { + return AuthController.verifyAuthenticatedMiddleware; + } + + @Override + public Filter verifyAdminMiddleware() { + return AuthController.verifyAdminMiddleware; + } + + @Override + public Route meGet() { + return AuthController.meGet; + } + + // CasController + + @Override + public Route callbackGet() { + return CasController.callbackGet; + } + + @Override + public Route loginGet() { + return CasController.loginGet; + } + + @Override + public Route logoutPost() { + return CasController.logoutPost; + } + + // ConfigController + + @Override + public Route getConfigAdmin() { + return ConfigController.getConfigAdmin; + } + + @Override + public Route getConfigStudent() { + return ConfigController.getConfigStudent; + } + + @Override + public Route updateLivePhases() { + return ConfigController.updateLivePhases; + } + + @Override + public Route updateBannerMessage() { + return ConfigController.updateBannerMessage; + } + + @Override + public Route updateCourseIdsPost() { + return ConfigController.updateCourseIdsPost; + } + + @Override + public Route updateCourseIdsUsingCanvasGet() { + return ConfigController.updateCourseIdsUsingCanvasGet; + } + + // SubmissionController + + @Override + public Route submitPost() { + return SubmissionController.submitPost; + } + + @Override + public Route adminRepoSubmitPost() { + return SubmissionController.adminRepoSubmitPost; + } + + @Override + public Route submitGet() { + return SubmissionController.submitGet; + } + + @Override + public Route latestSubmissionForMeGet() { + return SubmissionController.latestSubmissionForMeGet; + } + + @Override + public Route submissionXGet() { + return SubmissionController.submissionXGet; + } + + @Override + public Route latestSubmissionsGet() { + return SubmissionController.latestSubmissionsGet; + } + + @Override + public Route submissionsActiveGet() { + return SubmissionController.submissionsActiveGet; + } + + @Override + public Route studentSubmissionsGet() { + return SubmissionController.studentSubmissionsGet; + } + + @Override + public Route approveSubmissionPost() { + return SubmissionController.approveSubmissionPost; + } + + @Override + public Route submissionsReRunPost() { + return SubmissionController.submissionsReRunPost; + } + + // UserController + + @Override + public Route repoPatch() { + return UserController.repoPatch; + } + + @Override + public Route repoPatchAdmin() { + return UserController.repoPatchAdmin; + } + + @Override + public Route repoHistoryAdminGet() { + return UserController.repoHistoryAdminGet; + } +} From b8897f2813652abb095e457d5db390aaf15c2dac Mon Sep 17 00:00:00 2001 From: Nathaniel Gerlek Date: Thu, 14 Nov 2024 10:11:13 -0700 Subject: [PATCH 02/10] refactor: extract program-start logic from Server into a Main class --- src/main/java/Main.java | 103 ++++++++++++++++++++ src/main/java/edu/byu/cs/server/Server.java | 102 ++----------------- 2 files changed, 109 insertions(+), 96 deletions(-) create mode 100644 src/main/java/Main.java diff --git a/src/main/java/Main.java b/src/main/java/Main.java new file mode 100644 index 00000000..a533f101 --- /dev/null +++ b/src/main/java/Main.java @@ -0,0 +1,103 @@ +import edu.byu.cs.autograder.GradingException; +import edu.byu.cs.server.endpointprovider.EndpointProvider; +import edu.byu.cs.server.endpointprovider.EndpointProviderImpl; +import edu.byu.cs.dataAccess.DaoService; +import edu.byu.cs.dataAccess.DataAccessException; +import edu.byu.cs.properties.ApplicationProperties; +import edu.byu.cs.server.Server; +import edu.byu.cs.service.SubmissionService; +import edu.byu.cs.util.ResourceUtils; +import org.apache.commons.cli.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.util.Properties; + +public class Main { + private static Logger LOGGER = LoggerFactory.getLogger(Main.class); + + private static EndpointProvider endpointProvider = new EndpointProviderImpl(); + + public static void main(String[] args) { + ResourceUtils.copyResourceFiles("phases", new File("")); + setupProperties(args); + + try { + DaoService.initializeSqlDAOs(); + } catch (DataAccessException e) { + LOGGER.error("Error setting up database", e); + throw new RuntimeException(e); + } + + new Server(endpointProvider).start(8080); + + try { + SubmissionService.reRunSubmissionsInQueue(); + } catch (IOException | DataAccessException | GradingException e) { + LOGGER.error("Error rerunning submissions already in queue", e); + } + } + + private static void setupProperties(String[] args) { + Options options = getOptions(); + + Properties properties = new Properties(); + + CommandLineParser parser = new DefaultParser(); + try { + CommandLine cmd = parser.parse(options, args); + if (cmd.hasOption("db-host")) { + properties.setProperty("db-host", cmd.getOptionValue("db-host")); + } + if (cmd.hasOption("db-port")) { + properties.setProperty("db-port", cmd.getOptionValue("db-port")); + } + if (cmd.hasOption("db-name")) { + properties.setProperty("db-name", cmd.getOptionValue("db-name")); + } + if (cmd.hasOption("db-user")) { + properties.setProperty("db-user", cmd.getOptionValue("db-user")); + } + if (cmd.hasOption("db-pass")) { + properties.setProperty("db-pass", cmd.getOptionValue("db-pass")); + } + if (cmd.hasOption("frontend-url")) { + properties.setProperty("frontend-url", cmd.getOptionValue("frontend-url")); + } + if (cmd.hasOption("cas-callback-url")) { + properties.setProperty("cas-callback-url", cmd.getOptionValue("cas-callback-url")); + } + if (cmd.hasOption("canvas-token")) { + properties.setProperty("canvas-token", cmd.getOptionValue("canvas-token")); + } + if (cmd.hasOption("use-canvas")) { + properties.setProperty("use-canvas", cmd.getOptionValue("use-canvas")); + } + if (cmd.hasOption("disable-compilation")) { + properties.setProperty("run-compilation", "false"); + } + } catch (ParseException e) { + throw new RuntimeException("Error parsing command line arguments", e); + } + + ApplicationProperties.loadProperties(properties); + } + + private static Options getOptions() { + Options options = new Options(); + options.addOption(null, "db-host", true, "Database Host"); + options.addOption(null, "db-port", true, "Database Port"); + options.addOption(null, "db-name", true, "Database Name"); + options.addOption(null, "db-user", true, "Database User"); + options.addOption(null, "db-pass", true, "Database Password"); + options.addOption(null, "frontend-url", true, "Frontend URL"); + options.addOption(null, "cas-callback-url", true, "CAS Callback URL"); + options.addOption(null, "canvas-token", true, "Canvas Token"); + options.addOption(null, "use-canvas", true, "Using Canvas"); + options.addOption(null, "disable-compilation", false, "Turn off student code compilation"); + return options; + } + +} diff --git a/src/main/java/edu/byu/cs/server/Server.java b/src/main/java/edu/byu/cs/server/Server.java index beeae5b7..2cbe4406 100644 --- a/src/main/java/edu/byu/cs/server/Server.java +++ b/src/main/java/edu/byu/cs/server/Server.java @@ -1,22 +1,11 @@ package edu.byu.cs.server; -import edu.byu.cs.autograder.GradingException; import edu.byu.cs.controller.WebSocketController; -import edu.byu.cs.dataAccess.DaoService; -import edu.byu.cs.dataAccess.DataAccessException; import edu.byu.cs.properties.ApplicationProperties; import edu.byu.cs.server.endpointprovider.EndpointProvider; -import edu.byu.cs.server.endpointprovider.EndpointProviderImpl; -import edu.byu.cs.service.SubmissionService; -import edu.byu.cs.util.ResourceUtils; -import org.apache.commons.cli.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.IOException; -import java.util.Properties; - import static spark.Spark.*; public class Server { @@ -28,6 +17,12 @@ public Server(EndpointProvider endpointProvider) { this.provider = endpointProvider; } + public int start(int desiredPort) { + int chosenPort = setupEndpoints(desiredPort); + LOGGER.info("Server started on port {}", chosenPort); + return chosenPort; + } + public int setupEndpoints(int port) { port(port); @@ -133,89 +128,4 @@ public int setupEndpoints(int port) { return port(); } - - private static void setupProperties(String[] args) { - Options options = getOptions(); - - Properties properties = new Properties(); - - CommandLineParser parser = new DefaultParser(); - try { - CommandLine cmd = parser.parse(options, args); - if (cmd.hasOption("db-host")) { - properties.setProperty("db-host", cmd.getOptionValue("db-host")); - } - if (cmd.hasOption("db-port")) { - properties.setProperty("db-port", cmd.getOptionValue("db-port")); - } - if (cmd.hasOption("db-name")) { - properties.setProperty("db-name", cmd.getOptionValue("db-name")); - } - if (cmd.hasOption("db-user")) { - properties.setProperty("db-user", cmd.getOptionValue("db-user")); - } - if (cmd.hasOption("db-pass")) { - properties.setProperty("db-pass", cmd.getOptionValue("db-pass")); - } - if (cmd.hasOption("frontend-url")) { - properties.setProperty("frontend-url", cmd.getOptionValue("frontend-url")); - } - if (cmd.hasOption("cas-callback-url")) { - properties.setProperty("cas-callback-url", cmd.getOptionValue("cas-callback-url")); - } - if (cmd.hasOption("canvas-token")) { - properties.setProperty("canvas-token", cmd.getOptionValue("canvas-token")); - } - if (cmd.hasOption("use-canvas")) { - properties.setProperty("use-canvas", cmd.getOptionValue("use-canvas")); - } - if (cmd.hasOption("disable-compilation")) { - properties.setProperty("run-compilation", "false"); - } - } catch (ParseException e) { - throw new RuntimeException("Error parsing command line arguments", e); - } - - ApplicationProperties.loadProperties(properties); - } - - private static Options getOptions() { - Options options = new Options(); - options.addOption(null, "db-host", true, "Database Host"); - options.addOption(null, "db-port", true, "Database Port"); - options.addOption(null, "db-name", true, "Database Name"); - options.addOption(null, "db-user", true, "Database User"); - options.addOption(null, "db-pass", true, "Database Password"); - options.addOption(null, "frontend-url", true, "Frontend URL"); - options.addOption(null, "cas-callback-url", true, "CAS Callback URL"); - options.addOption(null, "canvas-token", true, "Canvas Token"); - options.addOption(null, "use-canvas", true, "Using Canvas"); - options.addOption(null, "disable-compilation", false, "Turn off student code compilation"); - return options; - } - - - public static void main(String[] args) { - ResourceUtils.copyResourceFiles("phases", new File("")); - setupProperties(args); - - try { - DaoService.initializeSqlDAOs(); - } catch (DataAccessException e) { - LOGGER.error("Error setting up database", e); - throw new RuntimeException(e); - } - - EndpointProvider endpointProvider = new EndpointProviderImpl(); - int port = new Server(endpointProvider).setupEndpoints(8080); - - LOGGER.info("Server started on port {}", port); - - try { - SubmissionService.reRunSubmissionsInQueue(); - } catch (IOException | DataAccessException | GradingException e) { - LOGGER.error("Error rerunning submissions already in queue", e); - } - } - } From 733bd7ed782733729cffab7488f31b09b7ae2946 Mon Sep 17 00:00:00 2001 From: Nathaniel Gerlek Date: Thu, 14 Nov 2024 17:21:37 -0700 Subject: [PATCH 03/10] make setupEndpoints private --- src/main/java/edu/byu/cs/server/Server.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/edu/byu/cs/server/Server.java b/src/main/java/edu/byu/cs/server/Server.java index 2cbe4406..3b1ceeaf 100644 --- a/src/main/java/edu/byu/cs/server/Server.java +++ b/src/main/java/edu/byu/cs/server/Server.java @@ -23,7 +23,7 @@ public int start(int desiredPort) { return chosenPort; } - public int setupEndpoints(int port) { + private int setupEndpoints(int port) { port(port); webSocket("/ws", WebSocketController.class); From 3a7241d0a105b999f3bca2bb119786f0a6753b5f Mon Sep 17 00:00:00 2001 From: Nathaniel Gerlek Date: Sat, 16 Nov 2024 16:29:46 -0700 Subject: [PATCH 04/10] refactor: move /* endpoint logic from Server to EndpointProvider --- src/main/java/edu/byu/cs/server/Server.java | 21 +++--------- .../endpointprovider/EndpointProvider.java | 7 ++++ .../EndpointProviderImpl.java | 33 +++++++++++++++++++ 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/src/main/java/edu/byu/cs/server/Server.java b/src/main/java/edu/byu/cs/server/Server.java index 3b1ceeaf..5e92321c 100644 --- a/src/main/java/edu/byu/cs/server/Server.java +++ b/src/main/java/edu/byu/cs/server/Server.java @@ -1,7 +1,6 @@ package edu.byu.cs.server; import edu.byu.cs.controller.WebSocketController; -import edu.byu.cs.properties.ApplicationProperties; import edu.byu.cs.server.endpointprovider.EndpointProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,12 +30,7 @@ private int setupEndpoints(int port) { staticFiles.location("/frontend/dist"); - before((request, response) -> { - response.header("Access-Control-Allow-Headers", "Authorization,Content-Type"); - response.header("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE,PATCH,OPTIONS"); - response.header("Access-Control-Allow-Credentials", "true"); - response.header("Access-Control-Allow-Origin", ApplicationProperties.frontendUrl()); - }); + before(provider.beforeAll()); path("/auth", () -> { get("/callback", provider.callbackGet()); @@ -115,15 +109,10 @@ private int setupEndpoints(int port) { }); // spark's notFound method does not work - get("/*", (req, res) -> { - if (req.pathInfo().equals("/ws")) - return null; - - String urlParams = req.queryString(); - urlParams = urlParams == null ? "" : "?" + urlParams; - res.redirect("/" + urlParams, 302); - return null; - }); + get("/*", provider.defaultGet()); + + after(provider.afterAll()); + init(); return port(); diff --git a/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProvider.java b/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProvider.java index 8ab0345e..a8af2cf5 100644 --- a/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProvider.java +++ b/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProvider.java @@ -5,6 +5,13 @@ public interface EndpointProvider { + // Wildcard endpoints + + Filter beforeAll(); + Filter afterAll(); + + Route defaultGet(); + // AdminController Route usersGet(); diff --git a/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProviderImpl.java b/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProviderImpl.java index af35839f..f897e3a3 100644 --- a/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProviderImpl.java +++ b/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProviderImpl.java @@ -1,11 +1,44 @@ package edu.byu.cs.server.endpointprovider; import edu.byu.cs.controller.*; +import edu.byu.cs.properties.ApplicationProperties; import spark.Filter; import spark.Route; +import java.util.Map; + public class EndpointProviderImpl implements EndpointProvider { + // Wildcard endpoints + + @Override + public Filter beforeAll() { + return (request, response) -> { + response.header("Access-Control-Allow-Headers", "Authorization,Content-Type"); + response.header("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE,PATCH,OPTIONS"); + response.header("Access-Control-Allow-Credentials", "true"); + response.header("Access-Control-Allow-Origin", ApplicationProperties.frontendUrl()); + }; + } + + @Override + public Filter afterAll() { + return (req, res) -> {}; + } + + @Override + public Route defaultGet() { + return (req, res) -> { + if (req.pathInfo().equals("/ws")) + return null; + + String urlParams = req.queryString(); + urlParams = urlParams == null ? "" : "?" + urlParams; + res.redirect("/" + urlParams, 302); + return null; + }; + } + // AdminController @Override From 31c3515d601e491e77ae37094f5f3f42e82330ed Mon Sep 17 00:00:00 2001 From: ThanGerlek Date: Tue, 19 Nov 2024 00:52:45 +0000 Subject: [PATCH 05/10] chore: add scheduleShutdown() to EndpointProvider --- .../edu/byu/cs/server/endpointprovider/EndpointProvider.java | 1 + .../byu/cs/server/endpointprovider/EndpointProviderImpl.java | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProvider.java b/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProvider.java index a8af2cf5..0ef17ef1 100644 --- a/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProvider.java +++ b/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProvider.java @@ -37,6 +37,7 @@ public interface EndpointProvider { Route getConfigAdmin(); Route getConfigStudent(); Route updateLivePhases(); + Route scheduleShutdown(); Route updateBannerMessage(); Route updateCourseIdsPost(); Route updateCourseIdsUsingCanvasGet(); diff --git a/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProviderImpl.java b/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProviderImpl.java index f897e3a3..162e4c1e 100644 --- a/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProviderImpl.java +++ b/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProviderImpl.java @@ -117,6 +117,11 @@ public Route updateLivePhases() { return ConfigController.updateLivePhases; } + @Override + public Route scheduleShutdown() { + return ConfigController.scheduleShutdown; + } + @Override public Route updateBannerMessage() { return ConfigController.updateBannerMessage; From 6230110c5427a03dcbd8d1c2efcdb59ec31fd549 Mon Sep 17 00:00:00 2001 From: ThanGerlek Date: Tue, 19 Nov 2024 00:59:17 +0000 Subject: [PATCH 06/10] chore: rmv unused imports --- src/main/java/edu/byu/cs/controller/ConfigController.java | 1 - src/main/java/edu/byu/cs/server/Server.java | 3 +-- .../byu/cs/server/endpointprovider/EndpointProviderImpl.java | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/edu/byu/cs/controller/ConfigController.java b/src/main/java/edu/byu/cs/controller/ConfigController.java index f3a48517..1126da7c 100644 --- a/src/main/java/edu/byu/cs/controller/ConfigController.java +++ b/src/main/java/edu/byu/cs/controller/ConfigController.java @@ -1,6 +1,5 @@ package edu.byu.cs.controller; -import com.google.gson.Gson; import com.google.gson.JsonObject; import edu.byu.cs.dataAccess.DataAccessException; import edu.byu.cs.model.*; diff --git a/src/main/java/edu/byu/cs/server/Server.java b/src/main/java/edu/byu/cs/server/Server.java index d01cabec..e61a6404 100644 --- a/src/main/java/edu/byu/cs/server/Server.java +++ b/src/main/java/edu/byu/cs/server/Server.java @@ -1,6 +1,5 @@ package edu.byu.cs.server; -import edu.byu.cs.controller.ConfigController; import edu.byu.cs.controller.WebSocketController; import edu.byu.cs.server.endpointprovider.EndpointProvider; import org.slf4j.Logger; @@ -101,7 +100,7 @@ private int setupEndpoints(int port) { get("", provider.getConfigAdmin()); post("/phases", provider.updateLivePhases()); - post("/phases/shutdown", ConfigController.scheduleShutdown); + post("/phases/shutdown", provider.scheduleShutdown()); post("/banner", provider.updateBannerMessage()); post("/courseIds", provider.updateCourseIdsPost()); diff --git a/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProviderImpl.java b/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProviderImpl.java index 162e4c1e..1e4584ee 100644 --- a/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProviderImpl.java +++ b/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProviderImpl.java @@ -5,8 +5,6 @@ import spark.Filter; import spark.Route; -import java.util.Map; - public class EndpointProviderImpl implements EndpointProvider { // Wildcard endpoints From 8cb281bb0c465db22ae53c3ce828a10308a778fb Mon Sep 17 00:00:00 2001 From: 19mdavenport Date: Sat, 23 Nov 2024 00:39:30 +0000 Subject: [PATCH 07/10] add test for missing functionality --- .../edu/byu/cs/autograder/score/ScorerTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/java/edu/byu/cs/autograder/score/ScorerTest.java b/src/test/java/edu/byu/cs/autograder/score/ScorerTest.java index 2cdaece6..46b54e78 100644 --- a/src/test/java/edu/byu/cs/autograder/score/ScorerTest.java +++ b/src/test/java/edu/byu/cs/autograder/score/ScorerTest.java @@ -274,6 +274,21 @@ void score_doesNotDecrease_when_distributedHigherPriorScore() throws CanvasExcep Assertions.assertEquals(UNIT_TESTS_POSSIBLE_POINTS, rubricItems.get(Rubric.RubricType.UNIT_TESTS).results().score()); } + @Test + void score_doesDecrease_when_higherPriorScoreOfFailedSubmission() throws CanvasException, DataAccessException { + Submission lastSubmission = previousSubmissionHelper( + new Phase3SubmissionValues(0, CODE_QUALITY_POSSIBLE_POINTS, UNIT_TESTS_POSSIBLE_POINTS, -1), + new Phase3SubmissionValues(PASSOFF_POSSIBLE_POINTS, CODE_QUALITY_POSSIBLE_POINTS, UNIT_TESTS_POSSIBLE_POINTS, 30) + ); + + Assertions.assertNotNull(lastSubmission); + EnumMap rubricItems = lastSubmission.rubric().items(); + + Assertions.assertEquals(PASSOFF_POSSIBLE_POINTS / 2f, rubricItems.get(Rubric.RubricType.PASSOFF_TESTS).results().score()); + Assertions.assertEquals(CODE_QUALITY_POSSIBLE_POINTS / 2f, rubricItems.get(Rubric.RubricType.QUALITY).results().score()); + Assertions.assertEquals(UNIT_TESTS_POSSIBLE_POINTS / 2f, rubricItems.get(Rubric.RubricType.UNIT_TESTS).results().score()); + } + // Helper Methods for constructing /** From e031d03e2aee22ff648f35c38f1d46da1538009f Mon Sep 17 00:00:00 2001 From: 19mdavenport Date: Sat, 23 Nov 2024 00:44:34 +0000 Subject: [PATCH 08/10] add missing functionality --- src/main/java/edu/byu/cs/autograder/score/Scorer.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/edu/byu/cs/autograder/score/Scorer.java b/src/main/java/edu/byu/cs/autograder/score/Scorer.java index c090ddcb..50921373 100644 --- a/src/main/java/edu/byu/cs/autograder/score/Scorer.java +++ b/src/main/java/edu/byu/cs/autograder/score/Scorer.java @@ -318,9 +318,11 @@ private Rubric.Results mergeResultsWithPrevious(Rubric.RubricType rubricType, Ru float score = startingScore; for (Submission previousSubmission : previousSubmissions) { - Rubric.RubricItem previousItem = previousSubmission.rubric().items().get(rubricType); - if (previousItem != null && previousItem.results().rawScore() <= results.rawScore()) { - score = Math.max(score, previousItem.results().score()); + if(previousSubmission.passed()) { + Rubric.RubricItem previousItem = previousSubmission.rubric().items().get(rubricType); + if (previousItem != null && previousItem.results().rawScore() <= results.rawScore()) { + score = Math.max(score, previousItem.results().score()); + } } } From e355b52a1ef565ed34acef43c6fee109e0da5baa Mon Sep 17 00:00:00 2001 From: Nathaniel Gerlek Date: Thu, 21 Nov 2024 12:15:36 -0700 Subject: [PATCH 09/10] fix: update mainClass in pom.xml --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index d05bcf09..294419cc 100644 --- a/pom.xml +++ b/pom.xml @@ -142,7 +142,7 @@ - edu.byu.cs.server.Server + Main @@ -169,7 +169,7 @@ true - edu.byu.cs.server.Server + Main From 33829fa0eb9f30d4e4594c6e32af645d1b00cc39 Mon Sep 17 00:00:00 2001 From: ThanGerlek Date: Mon, 25 Nov 2024 18:06:12 +0000 Subject: [PATCH 10/10] fix: add updatePenalties() to EndpointProvider --- src/main/java/edu/byu/cs/server/Server.java | 2 +- .../edu/byu/cs/server/endpointprovider/EndpointProvider.java | 1 + .../byu/cs/server/endpointprovider/EndpointProviderImpl.java | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/byu/cs/server/Server.java b/src/main/java/edu/byu/cs/server/Server.java index 714ab909..c2deb6be 100644 --- a/src/main/java/edu/byu/cs/server/Server.java +++ b/src/main/java/edu/byu/cs/server/Server.java @@ -106,7 +106,7 @@ private int setupEndpoints(int port) { post("/courseIds", provider.updateCourseIdsPost()); get("/courseIds", provider.updateCourseIdsUsingCanvasGet()); - post("/penalties", updatePenalties); + post("/penalties", provider.updatePenalties()); }); }); }); diff --git a/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProvider.java b/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProvider.java index 0ef17ef1..b89c1d6a 100644 --- a/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProvider.java +++ b/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProvider.java @@ -41,6 +41,7 @@ public interface EndpointProvider { Route updateBannerMessage(); Route updateCourseIdsPost(); Route updateCourseIdsUsingCanvasGet(); + Route updatePenalties(); // SubmissionController diff --git a/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProviderImpl.java b/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProviderImpl.java index 1e4584ee..1ba31d02 100644 --- a/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProviderImpl.java +++ b/src/main/java/edu/byu/cs/server/endpointprovider/EndpointProviderImpl.java @@ -135,6 +135,11 @@ public Route updateCourseIdsUsingCanvasGet() { return ConfigController.updateCourseIdsUsingCanvasGet; } + @Override + public Route updatePenalties() { + return ConfigController.updatePenalties; + } + // SubmissionController @Override