-
Notifications
You must be signed in to change notification settings - Fork 0
AMP-272 & AMP-170 changes #35
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 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1485372
AMP-272 changes
srivanimuddineni 7f52e4b
changes
srivanimuddineni b018b63
AMP-170 changes
srivanimuddineni 7d40d52
feature: amp-272 material service retry
coling01 41156ba
feature: amp-272 material service retry
coling01 c886d9c
Merge pull request #36 from hmcts/dev/AMP-272-colin
srivanimuddineni 7739fb4
AMP-170-Resolved test case review comments
srivanimuddineni 225c31c
AMP-170:Added TODO
srivanimuddineni 2c3010b
AMP-170-Added resusable String
srivanimuddineni 8d13ffd
feature: amp-272 material service retry
coling01 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
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
41 changes: 0 additions & 41 deletions
41
src/main/java/uk/gov/hmcts/cp/subscription/config/RetryTemplateConfig.java
This file was deleted.
Oops, something went wrong.
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
50 changes: 36 additions & 14 deletions
50
src/main/java/uk/gov/hmcts/cp/subscription/services/NotificationService.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 |
|---|---|---|
| @@ -1,41 +1,63 @@ | ||
| package uk.gov.hmcts.cp.subscription.services; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import static java.time.Duration.ofSeconds; | ||
| import static org.awaitility.Awaitility.await; | ||
|
|
||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.beans.factory.annotation.Qualifier; | ||
| import org.springframework.retry.support.RetryTemplate; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import uk.gov.hmcts.cp.material.openapi.api.MaterialApi; | ||
| import uk.gov.hmcts.cp.material.openapi.model.MaterialMetadata; | ||
| import uk.gov.hmcts.cp.openapi.model.PcrEventPayload; | ||
| import uk.gov.hmcts.cp.subscription.model.EntityEventType; | ||
| import uk.gov.hmcts.cp.subscription.services.exceptions.MaterialMetadataNotReadyException; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.UUID; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Slf4j | ||
| public class NotificationService { | ||
|
|
||
| private final MaterialApi materialApi; | ||
| private final DocumentService documentService; | ||
| @Qualifier("retryTemplate") | ||
| private final RetryTemplate materialRetryTemplate; | ||
| private final Duration waitTimeout; | ||
| private final Duration pollInterval; | ||
|
|
||
| @Autowired | ||
| public NotificationService(final MaterialApi materialApi, | ||
| final DocumentService documentService) { | ||
| this(materialApi, documentService, ofSeconds(30), ofSeconds(5)); | ||
| } | ||
|
|
||
| public NotificationService(final MaterialApi materialApi, | ||
| final DocumentService documentService, | ||
| final Duration waitTimeout, | ||
| final Duration pollInterval) { | ||
| this.materialApi = materialApi; | ||
| this.documentService = documentService; | ||
| this.waitTimeout = waitTimeout; | ||
| this.pollInterval = pollInterval; | ||
| } | ||
|
|
||
| public void processInboundEvent(final PcrEventPayload pcrEventPayload) { | ||
| final MaterialMetadata materialMetadata = materialRetryTemplate.execute(context -> | ||
| waitForMaterialMetadata(pcrEventPayload.getMaterialId())); | ||
| final MaterialMetadata materialMetadata = waitForMaterialMetadata(pcrEventPayload.getMaterialId()); | ||
|
|
||
| final EntityEventType eventType = EntityEventType.valueOf(pcrEventPayload.getEventType().name()); | ||
| documentService.saveDocumentMapping(materialMetadata.getMaterialId(), eventType); | ||
| } | ||
|
|
||
| private MaterialMetadata waitForMaterialMetadata(final UUID materialId) { | ||
| final MaterialMetadata response = materialApi.getMaterialMetadataByMaterialId(materialId); | ||
| if (response == null) { | ||
| throw new MaterialMetadataNotReadyException("PCR - Material metadata not ready for materialId: " + materialId); | ||
| } | ||
| return response; | ||
| final AtomicReference<MaterialMetadata> materialResponse = new AtomicReference<>(); | ||
| await() | ||
| .atMost(waitTimeout) | ||
| .pollInterval(pollInterval) | ||
| .until(() -> { | ||
| final MaterialMetadata response = materialApi.getMaterialMetadataByMaterialId(materialId); | ||
| materialResponse.set(response); | ||
| return response != null; | ||
| }); | ||
| return materialResponse.get(); | ||
| } | ||
| } | ||
12 changes: 0 additions & 12 deletions
12
...a/uk/gov/hmcts/cp/subscription/services/exceptions/MaterialMetadataNotReadyException.java
This file was deleted.
Oops, something went wrong.
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
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.