From f550a7b518794c67b3c3c1c9c5bbf69c9222df53 Mon Sep 17 00:00:00 2001 From: Sikandar Ejaz <34721766+SikandarEjaz@users.noreply.github.com> Date: Mon, 8 Jun 2026 19:02:16 -0400 Subject: [PATCH] addressed issue #236 --- Middleware/README.md | 2 +- .../core/controllers/DatasetController.java | 20 ++--- .../{ => src/main/resources}/DATA_SOURCES.md | 0 .../src/main/resources/static/home.html | 84 ++++++++++--------- 4 files changed, 49 insertions(+), 57 deletions(-) rename Middleware/{ => src/main/resources}/DATA_SOURCES.md (100%) diff --git a/Middleware/README.md b/Middleware/README.md index 8c8b3c4a..ff154842 100644 --- a/Middleware/README.md +++ b/Middleware/README.md @@ -191,7 +191,7 @@ Include your username and password in the request body as JSON, for example: ## Available Data Sources -- [Dataset Catalog](DATA_SOURCES.md) - Complete list of all available datasets +- [Dataset Catalog](src/main/resources/DATA_SOURCES.md) - Complete list of all available datasets ## Demo & Presentations diff --git a/Middleware/src/main/java/ca/concordia/encs/citydata/core/controllers/DatasetController.java b/Middleware/src/main/java/ca/concordia/encs/citydata/core/controllers/DatasetController.java index c32e73bc..b6b65caa 100644 --- a/Middleware/src/main/java/ca/concordia/encs/citydata/core/controllers/DatasetController.java +++ b/Middleware/src/main/java/ca/concordia/encs/citydata/core/controllers/DatasetController.java @@ -2,11 +2,9 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Map; +import org.springframework.core.io.ClassPathResource; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -40,20 +38,12 @@ public DatasetController(DatasetAccessService datasetAccessService) { @GetMapping("/list") public ResponseEntity listDatasets() { try { - Path filePath = Paths.get("DATA_SOURCES.md"); - String content = Files.readString(filePath, StandardCharsets.UTF_8); + var resource = new ClassPathResource("DATA_SOURCES.md"); + String content = new String(resource.getInputStream().readAllBytes(), StandardCharsets.UTF_8); return ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN).body(content); } catch (IOException e) { - // Fallback: try relative to project root - try { - Path filePath = Paths.get("Middleware/DATA_SOURCES.md"); - String content = Files.readString(filePath, StandardCharsets.UTF_8); - return ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN).body(content); - } catch (IOException e2) { - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) - .body("Could not load dataset list. Tried ./DATA_SOURCES.md and Middleware/DATA_SOURCES.md. " - + "Working directory: " + Paths.get("").toAbsolutePath()); - } + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) + .body("Could not load DATA_SOURCES.md from classpath."); } } diff --git a/Middleware/DATA_SOURCES.md b/Middleware/src/main/resources/DATA_SOURCES.md similarity index 100% rename from Middleware/DATA_SOURCES.md rename to Middleware/src/main/resources/DATA_SOURCES.md diff --git a/Middleware/src/main/resources/static/home.html b/Middleware/src/main/resources/static/home.html index aba3d239..0e68d765 100644 --- a/Middleware/src/main/resources/static/home.html +++ b/Middleware/src/main/resources/static/home.html @@ -295,7 +295,7 @@
- CITYdata +

@@ -411,46 +411,48 @@

API Response