Skip to content

feature/expand-activity-log#14

Merged
VonAdamo merged 1 commit into
mainfrom
feature/expand-activity-log
Apr 27, 2026
Merged

feature/expand-activity-log#14
VonAdamo merged 1 commit into
mainfrom
feature/expand-activity-log

Conversation

@VonAdamo

@VonAdamo VonAdamo commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes

    • Replaced direct error output with structured logging across services, improving diagnostics and error traceability.
    • Enhanced service resilience to gracefully handle activity logging failures without disrupting core document management or ticket operations.
  • Tests

    • Added comprehensive tests verifying document and support ticket services continue functioning when activity logging encounters errors.

@coderabbitai

coderabbitai Bot commented Apr 27, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The pull request modifies transaction propagation for ActivityLogService.createActivityLog to use REQUIRES_NEW, enabling it to run in its own transaction scope. Callers in CommentService, DocumentServiceImpl, and SupportTicketServiceImpl are updated to replace stderr printing with structured SLF4J logging. New unit tests verify services continue functioning when activity log creation fails.

Changes

Cohort / File(s) Summary
Transaction Configuration
src/main/java/org/group1/projectbackend/service/ActivityLogService.java
Added @Transactional(propagation = Propagation.REQUIRES_NEW) annotation and Propagation import to create an independent transaction scope for createActivityLog().
Error Logging Migration
src/main/java/org/group1/projectbackend/service/CommentService.java, src/main/java/org/group1/projectbackend/service/impl/DocumentServiceImpl.java, src/main/java/org/group1/projectbackend/service/impl/SupportTicketServiceImpl.java
Replaced System.err stderr prints with SLF4J logger.error() calls in activity-log failure handlers. Added class-level Logger instances and structured logging context fields (ticketId, userId, activityType).
Failure Tolerance Tests
src/test/java/org/group1/projectbackend/service/DocumentServiceTest.java, src/test/java/org/group1/projectbackend/service/SupportTicketServiceTest.java
Added unit tests verifying uploadDocument, deleteDocument, ticket creation, and ticket updates complete successfully despite activityLogService.createActivityLog() throwing RuntimeException. Tests confirm repository operations execute while activity-log failures are gracefully handled.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Poem

🐰 A rabbit hops through transactions clean,
REQUIRES_NEW, a scope pristine,
Logs now flow through SLF4J streams,
Failures logged, not lost in stderr dreams,
Tests confirm: services bounce, not break! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'feature/expand-activity-log' is vague and generic. While it references activity logs, it does not clearly convey the actual changes made (adding transaction scope management, replacing stderr with SLF4J logging, and adding resilience tests). The title uses a feature branch naming convention rather than describing specific functionality improvements. Revise the title to be more descriptive of the core changes, such as 'Add REQUIRES_NEW transaction scope and SLF4J logging for activity log operations' or similar to clearly communicate the main improvements.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/expand-activity-log

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/java/org/group1/projectbackend/service/ActivityLogService.java (1)

38-53: ⚠️ Potential issue | 🔴 Critical

REQUIRES_NEW will silently break activity logging for newly created tickets.

createActivityLog runs in a brand-new transaction (separate JDBC connection) that immediately calls supportTicketRepository.findById(dto.getSupportTicketId()) (line 45). In the SupportTicketServiceImpl.createTicket flow, the ticket has just been persisted in the outer transaction and is not yet committed when logActivitySafely is invoked. Under the default READ_COMMITTED isolation level, the new transaction cannot see that row, so findById returns empty and throws ResourceNotFoundException — which is then silently caught and logged by the catch (RuntimeException) block in logActivitySafely.

Net effect: the TICKET_CREATED activity log entry is lost for every newly created ticket.

The updateStatus, CommentService.createComment, and DocumentServiceImpl.upload/deleteDocument callers are not affected because they reference user/ticket rows that were committed before the request.

Options:

  • Drop REQUIRES_NEW and keep activity-log creation in the caller's transaction (simplest; lets the new ticket be visible).
  • Keep REQUIRES_NEW but defer the call until after the parent commit (e.g., TransactionSynchronizationManager.registerSynchronization(...).afterCommit() or ApplicationEventPublisher + @TransactionalEventListener(AFTER_COMMIT)).
  • Pass the already-loaded User/SupportTicket entities to avoid refetching via FK, eliminating the visibility dependency.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/org/group1/projectbackend/service/ActivityLogService.java`
around lines 38 - 53, The method ActivityLogService.createActivityLog is
annotated with `@Transactional`(propagation = Propagation.REQUIRES_NEW), which
prevents the newly created SupportTicket in
SupportTicketServiceImpl.createTicket from being visible and causes
findById(dto.getSupportTicketId()) to throw; change createActivityLog to run in
the caller's transaction by removing Propagation.REQUIRES_NEW (use the default
`@Transactional` or no annotation) so the uncommitted ticket is visible to
supportTicketRepository.findById, or alternatively if you must keep
REQUIRES_NEW, defer the logging until after commit via
TransactionSynchronizationManager.registerSynchronization(...).afterCommit() or
switch callers to pass the already-loaded User/SupportTicket entities into
createActivityLog to avoid refetching.
🧹 Nitpick comments (1)
src/test/java/org/group1/projectbackend/service/SupportTicketServiceTest.java (1)

95-113: Good failure-tolerance coverage; consider an integration test for the REQUIRES_NEW interaction.

The two new tests correctly assert the "swallow-and-continue" contract of logActivitySafely. However, since activityLogService is mocked here, they will not catch the real interaction issue between REQUIRES_NEW and the outer (uncommitted) saveTicket transaction (see the comment on ActivityLogService.createActivityLog). An integration test with a real ActivityLogService and database would surface that — and would also act as a regression guard once that issue is addressed.

Also applies to: 155-169

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/test/java/org/group1/projectbackend/service/SupportTicketServiceTest.java`
around lines 95 - 113, Add an integration test that uses the real
ActivityLogService and the DB (not the mocked activityLogService) to exercise
the REQUIRES_NEW interaction and catch the transaction ordering issue: in the
SupportTicketServiceTest class create a new test (or convert the existing
shouldCreateTicketEvenWhenActivityLogFails variant) that boots the Spring
context (e.g., `@SpringBootTest` or `@DataJpaTest` with service beans), injects the
real ActivityLogService and repositories, calls
supportTicketService.createTicket("alice", request) and asserts the
SupportTicket is persisted even if ActivityLogService.createActivityLog throws
or rolls back; this ensures the
logActivitySafely/ActivityLogService.createActivityLog REQUIRES_NEW behavior is
validated against the actual DB transaction boundaries and will act as a
regression guard.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/main/java/org/group1/projectbackend/service/ActivityLogService.java`:
- Around line 38-53: The method ActivityLogService.createActivityLog is
annotated with `@Transactional`(propagation = Propagation.REQUIRES_NEW), which
prevents the newly created SupportTicket in
SupportTicketServiceImpl.createTicket from being visible and causes
findById(dto.getSupportTicketId()) to throw; change createActivityLog to run in
the caller's transaction by removing Propagation.REQUIRES_NEW (use the default
`@Transactional` or no annotation) so the uncommitted ticket is visible to
supportTicketRepository.findById, or alternatively if you must keep
REQUIRES_NEW, defer the logging until after commit via
TransactionSynchronizationManager.registerSynchronization(...).afterCommit() or
switch callers to pass the already-loaded User/SupportTicket entities into
createActivityLog to avoid refetching.

---

Nitpick comments:
In
`@src/test/java/org/group1/projectbackend/service/SupportTicketServiceTest.java`:
- Around line 95-113: Add an integration test that uses the real
ActivityLogService and the DB (not the mocked activityLogService) to exercise
the REQUIRES_NEW interaction and catch the transaction ordering issue: in the
SupportTicketServiceTest class create a new test (or convert the existing
shouldCreateTicketEvenWhenActivityLogFails variant) that boots the Spring
context (e.g., `@SpringBootTest` or `@DataJpaTest` with service beans), injects the
real ActivityLogService and repositories, calls
supportTicketService.createTicket("alice", request) and asserts the
SupportTicket is persisted even if ActivityLogService.createActivityLog throws
or rolls back; this ensures the
logActivitySafely/ActivityLogService.createActivityLog REQUIRES_NEW behavior is
validated against the actual DB transaction boundaries and will act as a
regression guard.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0358dfb0-0e1d-4cdc-af11-710d51f740a0

📥 Commits

Reviewing files that changed from the base of the PR and between 1e3ae2c and ea25b50.

📒 Files selected for processing (6)
  • src/main/java/org/group1/projectbackend/service/ActivityLogService.java
  • src/main/java/org/group1/projectbackend/service/CommentService.java
  • src/main/java/org/group1/projectbackend/service/impl/DocumentServiceImpl.java
  • src/main/java/org/group1/projectbackend/service/impl/SupportTicketServiceImpl.java
  • src/test/java/org/group1/projectbackend/service/DocumentServiceTest.java
  • src/test/java/org/group1/projectbackend/service/SupportTicketServiceTest.java

@VonAdamo
VonAdamo merged commit e94381e into main Apr 27, 2026
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.

1 participant