-
Notifications
You must be signed in to change notification settings - Fork 8
[MODORDSTOR-501] Consolidate Batch Item Events for Audit Logging #1243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7175d14
[MODORDSTOR-501] Consolidate Batch Item Events for Audit Logging
Saba-Zedginidze-EPAM 57cdedc
[MODORDSTOR-501] Improve implementation
Saba-Zedginidze-EPAM 3e4064d
[MODORDSTOR-501] Fix failing tests
Saba-Zedginidze-EPAM 1fcf9b4
[MODORDSTOR-501] Add batch tracking service test
Saba-Zedginidze-EPAM bc6e423
[MODORDSTOR-501] Include new test in suite
Saba-Zedginidze-EPAM d15c7b2
[MODORDSTOR-501] Add interface
Saba-Zedginidze-EPAM 6508e68
[MODORDSTOR-501] Update acq models
Saba-Zedginidze-EPAM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule acq-models
updated
2 files
| +7 −0 | mod-orders-storage/examples/batch_tracking.sample | |
| +42 −0 | mod-orders-storage/schemas/batch_tracking.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/org/folio/service/batch/BatchTrackingService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package org.folio.service.batch; | ||
|
|
||
| import io.vertx.core.Future; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.extern.log4j.Log4j2; | ||
| import org.folio.rest.acq.model.BatchTracking; | ||
| import org.folio.rest.core.RestClient; | ||
| import org.folio.rest.core.models.RequestContext; | ||
| import org.folio.rest.core.models.RequestEntry; | ||
|
|
||
| import static org.folio.orders.utils.ResourcePathResolver.BATCH_TRACKING; | ||
| import static org.folio.orders.utils.ResourcePathResolver.resourcesPath; | ||
|
|
||
| @Log4j2 | ||
| @AllArgsConstructor | ||
| public class BatchTrackingService { | ||
|
|
||
| private static final String BATCH_TRACKING_HEADER = "X-Batch-Tracking-Id"; | ||
| private static final String BATCH_TRACKING_ENDPOINT = resourcesPath(BATCH_TRACKING); | ||
|
|
||
| protected final RestClient restClient; | ||
|
|
||
| public Future<Void> createBatchTrackingRecord(String id, int totalRecords, RequestContext requestContext) { | ||
| var batchTracking = new BatchTracking().withId(id).withTotalRecords(totalRecords); | ||
| var requestEntry = new RequestEntry(BATCH_TRACKING_ENDPOINT); | ||
| return restClient.post(requestEntry, batchTracking, BatchTracking.class, requestContext) | ||
| .map(tracking -> requestContext.getHeaders().put(BATCH_TRACKING_HEADER, tracking.getId())) // Add the batch tracking ID to the request headers for downstream services to use. | ||
| .onFailure(t -> log.error("Failed to create batch tracking record for batchId: {}", batchTracking.getId(), t)) | ||
| .recover(t -> Future.succeededFuture()) // In case of failure, we return a succeeded future to avoid failing the entire batch process. | ||
Saba-Zedginidze-EPAM marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .mapEmpty(); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/test/java/org/folio/service/batch/BatchTrackingServiceTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| package org.folio.service.batch; | ||
|
|
||
| import static io.vertx.core.Future.failedFuture; | ||
| import static io.vertx.core.Future.succeededFuture; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.ArgumentMatchers.eq; | ||
| import static org.mockito.Mockito.doReturn; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.UUID; | ||
|
|
||
| import io.vertx.core.Future; | ||
| import io.vertx.junit5.VertxExtension; | ||
| import io.vertx.junit5.VertxTestContext; | ||
| import org.folio.CopilotGenerated; | ||
| import org.folio.rest.acq.model.BatchTracking; | ||
| import org.folio.rest.core.RestClient; | ||
| import org.folio.rest.core.models.RequestContext; | ||
| import org.folio.rest.core.models.RequestEntry; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.mockito.InjectMocks; | ||
| import org.mockito.Mock; | ||
| import org.mockito.MockitoAnnotations; | ||
| import org.mockito.junit.jupiter.MockitoExtension; | ||
|
|
||
| @CopilotGenerated(model = "Claude Opus 4.5") | ||
| @ExtendWith({ VertxExtension.class, MockitoExtension.class }) | ||
| public class BatchTrackingServiceTest { | ||
|
|
||
| private static final String BATCH_TRACKING_HEADER = "X-Batch-Tracking-Id"; | ||
|
|
||
| @InjectMocks | ||
| private BatchTrackingService batchTrackingService; | ||
| @Mock | ||
| private RestClient restClient; | ||
| @Mock | ||
| private RequestContext requestContext; | ||
|
|
||
| @Test | ||
| void shouldCreateBatchTrackingRecordAndPopulateHeader(VertxTestContext vertxTestContext) { | ||
| // Given | ||
| String batchId = UUID.randomUUID().toString(); | ||
| int totalRecords = 10; | ||
| Map<String, String> headers = new HashMap<>(); | ||
| BatchTracking createdBatchTracking = new BatchTracking().withId(batchId).withTotalRecords(totalRecords); | ||
|
|
||
| when(requestContext.getHeaders()).thenReturn(headers); | ||
| doReturn(succeededFuture(createdBatchTracking)) | ||
| .when(restClient).post(any(RequestEntry.class), any(BatchTracking.class), eq(BatchTracking.class), eq(requestContext)); | ||
|
|
||
| // When | ||
| Future<Void> future = batchTrackingService.createBatchTrackingRecord(batchId, totalRecords, requestContext); | ||
|
|
||
| // Then | ||
| vertxTestContext.assertComplete(future) | ||
| .onComplete(result -> { | ||
| assertTrue(result.succeeded()); | ||
| assertEquals(batchId, headers.get(BATCH_TRACKING_HEADER)); | ||
| vertxTestContext.completeNow(); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldReturnSucceededFutureWhenRestClientFails(VertxTestContext vertxTestContext) { | ||
| // Given | ||
| String batchId = UUID.randomUUID().toString(); | ||
| int totalRecords = 5; | ||
|
|
||
| doReturn(failedFuture(new RuntimeException("Connection error"))) | ||
| .when(restClient).post(any(RequestEntry.class), any(BatchTracking.class), eq(BatchTracking.class), eq(requestContext)); | ||
|
|
||
| // When | ||
| Future<Void> future = batchTrackingService.createBatchTrackingRecord(batchId, totalRecords, requestContext); | ||
|
|
||
| // Then | ||
| vertxTestContext.assertComplete(future) | ||
| .onComplete(result -> { | ||
| assertTrue(result.succeeded()); | ||
| vertxTestContext.completeNow(); | ||
| }); | ||
| } | ||
|
|
||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.