Skip to content

Refactor: split long service files and centralize exception handling#35

Merged
milljoniaer merged 6 commits intomainfrom
copilot/cleanup-long-unreadable-files
Mar 20, 2026
Merged

Refactor: split long service files and centralize exception handling#35
milljoniaer merged 6 commits intomainfrom
copilot/cleanup-long-unreadable-files

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 20, 2026

Codebase cleanup — several files grew past 500-600 lines. Split them into focused modules and eliminated repetitive try-catch boilerplate across controllers.

Server

  • GlobalExceptionHandler (@ControllerAdvice) — centralizes exception→HTTP mapping (ResourceNotFoundException→404, IllegalArgumentException→400, IOException/RuntimeException→500). Removes ~160 lines of try-catch from ActivityController (591→434 lines).
// Before: every endpoint had this
try {
    ActivityResponse activity = activityService.getActivityById(id);
    return ResponseEntity.ok(activity);
} catch (Exception e) {
    logger.error("...", e.getMessage());
    return ResponseEntity.status(404).body(ErrorResponse.of(e.getMessage()));
}

// After: just the happy path
ActivityResponse activity = activityService.getActivityById(id);
return ResponseEntity.ok(activity);
  • Split MarkdownToDocxService (632→270 lines) — extracted DocxHeaderFooterHelper (header/footer creation, logo, styled runs, field runs) and DocxTableHelper (Artikulationsschema table layout, column widths)

  • Split ActivityService (673→491 lines) — extracted ActivityExtractionService for PDF upload, LLM metadata extraction, data normalization, and defaults

Client

  • Split apiService.ts (521→106 lines) — extracted domain modules activityApiService.ts, historyApiService.ts, userApiService.ts. ApiService class remains as a re-exporting facade so all existing call sites are unaffected.

Test impact

All 62 server tests and 114 client tests pass unchanged (test setup updated for new constructors/injections).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • jfrog-prod-use1-shared-virginia-main.s3.amazonaws.com
    • Triggering command: /usr/lib/jvm/temurin-21-jdk-amd64/bin/java /usr/lib/jvm/temurin-21-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /home/REDACTED/.m2/wrapper/dists/apache-maven-3.9.11/a2d47e15/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/home/REDACTED/.m2/wrapper/dists/apache-maven-3.9.11/a2d47e15/bin/m2.conf -Dmaven.home=/home/REDACTED/.m2/wrapper/dists/apache-maven-3.9.11/a2d47e15 -Dlibrary.jansi.path=/home/REDACTED/.m2/wrapper/dists/apache-maven-3.9.11/a2d47e15/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/LEARN-Hub/LEARN-Hub/server org.codehaus.plexus.classworlds.launcher.Launcher clean compile -q (dns block)
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java -Dfile.encoding=UTF-8 -Xms256M -Xss8M -Djdk.util.zip.disableZip64ExtraFieldValidation=true -Dsun.misc.unsafe.memory.access=allow --add-opens java.base/sun.reflect.annotation=ALL-UNNAMED -Xmx14576m -classpath /opt/hostedtoolcache/CodeQL/2.24.3/x64/codeql/java/tools/semmle-extractor-java.jar:/opt/hostedtoolcache/CodeQL/2.24.3/x64/codeql/java/tools/lombok-javac-extend.jar com.semmle.extractor.java.JavaExtractor --jdk-version 17 --javac-args @@@/tmp/codeql-scratch-21fe057196e5a270/dbs/java/log/ext/javac.args (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.

Copilot AI and others added 4 commits March 20, 2026 11:06
…boilerplate

- Create ResourceNotFoundException for 404 responses
- Create GlobalExceptionHandler (@ControllerAdvice) handling ResourceNotFoundException,
  IllegalArgumentException, IOException, and RuntimeException
- Remove try-catch blocks from all ActivityController endpoints (591→434 lines)
- Extract reusable parseRequiredDocumentId() and buildFileDownloadResponse() helpers
- Remove unused buildCombinedMarkdown() method
- Update ActivityService to throw ResourceNotFoundException

Co-authored-by: milljoniaer <78978542+milljoniaer@users.noreply.github.com>
- Extract DocxHeaderFooterHelper (300 lines) - header/footer creation, logo, styled runs, field runs
- Extract DocxTableHelper (146 lines) - Artikulationsschema table layout, column widths, cell sizing
- MarkdownToDocxService reduced from 632→270 lines (57% reduction)
- Update tests to use new constructor with injected helpers

Co-authored-by: milljoniaer <78978542+milljoniaer@users.noreply.github.com>
- Move PDF metadata extraction, normalization, and defaults logic to
  ActivityExtractionService (239 lines)
- ActivityService reduced from 673→491 lines (27% reduction)
- ActivityService retains CRUD, filtering, recommendation criteria
- Update ActivityServiceTest to inject extraction service with mocks

Co-authored-by: milljoniaer <78978542+milljoniaer@users.noreply.github.com>
- Extract ActivityApi (309 lines) - activity CRUD, PDF/DOCX downloads, recommendations
- Extract HistoryApi (105 lines) - search history and favourites
- Extract UserApi (77 lines) - user management and profiles
- apiService.ts reduced from 521→106 lines (80% reduction)
- ApiService class remains as backward-compatible facade
- Export ApiRequestMixin for shared request handling

Co-authored-by: milljoniaer <78978542+milljoniaer@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor code for better readability and reuse Refactor: split long service files and centralize exception handling Mar 20, 2026
Copilot AI requested a review from milljoniaer March 20, 2026 11:23
@milljoniaer milljoniaer marked this pull request as ready for review March 20, 2026 12:22
@milljoniaer milljoniaer merged commit bc1650c into main Mar 20, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants