-
Notifications
You must be signed in to change notification settings - Fork 0
migrate(CRDTAGY): translate credit agency batch (1..5) #30
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
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package com.augment.cbsa.domain; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| public enum CreditAgency { | ||
|
|
||
| CRDTAGY1(1, "CRDTAGY1", "CIPA", 1, 3), | ||
| CRDTAGY2(2, "CRDTAGY2", "CIPB", 1, 3), | ||
| CRDTAGY3(3, "CRDTAGY3", "CIPC", 1, 3), | ||
| CRDTAGY4(4, "CRDTAGY4", "CIPD", 1, 3), | ||
| CRDTAGY5(5, "CRDTAGY5", "CIPE", 1, 3); | ||
|
|
||
| private final int agencyNumber; | ||
| private final String programName; | ||
| private final String containerName; | ||
| private final int minimumDelaySeconds; | ||
| private final int maximumDelaySecondsExclusive; | ||
|
|
||
| CreditAgency( | ||
| int agencyNumber, | ||
| String programName, | ||
| String containerName, | ||
| int minimumDelaySeconds, | ||
| int maximumDelaySecondsExclusive | ||
| ) { | ||
| this.agencyNumber = agencyNumber; | ||
| this.programName = programName; | ||
| this.containerName = containerName; | ||
| this.minimumDelaySeconds = minimumDelaySeconds; | ||
| this.maximumDelaySecondsExclusive = maximumDelaySecondsExclusive; | ||
| } | ||
|
|
||
| public int agencyNumber() { | ||
| return agencyNumber; | ||
| } | ||
|
|
||
| public String programName() { | ||
| return programName; | ||
| } | ||
|
|
||
| public String containerName() { | ||
| return containerName; | ||
| } | ||
|
|
||
| public int minimumDelaySeconds() { | ||
| return minimumDelaySeconds; | ||
| } | ||
|
|
||
| public int maximumDelaySecondsExclusive() { | ||
| return maximumDelaySecondsExclusive; | ||
| } | ||
|
|
||
| public static CreditAgency fromAgencyNumber(int agencyNumber) { | ||
| return Arrays.stream(values()) | ||
| .filter(agency -> agency.agencyNumber == agencyNumber) | ||
| .findFirst() | ||
| .orElseThrow(() -> new IllegalArgumentException("Unsupported credit agency number: " + agencyNumber)); | ||
| } | ||
| } |
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
9 changes: 9 additions & 0 deletions
9
src/main/java/com/augment/cbsa/service/CreditAgencyDelayExecutor.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,9 @@ | ||
| package com.augment.cbsa.service; | ||
|
|
||
| import java.time.Duration; | ||
|
|
||
| @FunctionalInterface | ||
| public interface CreditAgencyDelayExecutor { | ||
|
|
||
| void delay(Duration duration) throws InterruptedException; | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/augment/cbsa/service/CreditAgencyDelayGenerator.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,10 @@ | ||
| package com.augment.cbsa.service; | ||
|
|
||
| import com.augment.cbsa.domain.CreditAgency; | ||
| import java.time.Duration; | ||
|
|
||
| @FunctionalInterface | ||
| public interface CreditAgencyDelayGenerator { | ||
|
|
||
| Duration nextDelay(CreditAgency agency); | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/augment/cbsa/service/CreditAgencyScoreGenerator.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,10 @@ | ||
| package com.augment.cbsa.service; | ||
|
|
||
| import com.augment.cbsa.domain.CreditAgency; | ||
| import com.augment.cbsa.domain.CrecustRequest; | ||
|
|
||
| @FunctionalInterface | ||
| public interface CreditAgencyScoreGenerator { | ||
|
|
||
| int nextCreditScore(CreditAgency agency, CrecustRequest request); | ||
| } |
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/main/java/com/augment/cbsa/web/crdtagy/CrdtagyController.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 com.augment.cbsa.web.crdtagy; | ||
|
|
||
| import com.augment.cbsa.domain.CrecustRequest; | ||
| import com.augment.cbsa.error.CbsaAbendException; | ||
| import com.augment.cbsa.service.CreditAgencyService; | ||
| import com.augment.cbsa.web.crecust.dto.CrecustCommareaResponseDto; | ||
| import com.augment.cbsa.web.crecust.dto.CrecustRequestDto; | ||
| import com.augment.cbsa.web.crecust.dto.CrecustResponseDto; | ||
| import jakarta.validation.Valid; | ||
| import jakarta.validation.constraints.Max; | ||
| import jakarta.validation.constraints.Min; | ||
| import java.util.Objects; | ||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.concurrent.CompletionException; | ||
| import java.util.concurrent.ExecutionException; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.concurrent.TimeoutException; | ||
| import org.springframework.validation.annotation.Validated; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @Validated | ||
| @RequestMapping("/api/v1/crdtagy") | ||
| public class CrdtagyController { | ||
|
|
||
| private static final long CREDIT_AGENCY_TIMEOUT_SECONDS = 5; | ||
|
|
||
| private final CreditAgencyService creditAgencyService; | ||
|
|
||
| public CrdtagyController(CreditAgencyService creditAgencyService) { | ||
| this.creditAgencyService = Objects.requireNonNull(creditAgencyService, "creditAgencyService must not be null"); | ||
| } | ||
|
|
||
| @PostMapping("/{agencyNumber}") | ||
| public CrecustResponseDto process( | ||
| @PathVariable @Min(1) @Max(5) int agencyNumber, | ||
| @Valid @RequestBody CrecustRequestDto requestDto | ||
| ) { | ||
| var commarea = requestDto.creCust(); | ||
| int creditScore = awaitCreditScore(new CrecustRequest( | ||
| commarea.commName(), | ||
| commarea.commAddress(), | ||
| commarea.commDateOfBirth() | ||
| ), agencyNumber); | ||
|
|
||
| return new CrecustResponseDto(new CrecustCommareaResponseDto( | ||
| defaultString(commarea.commEyecatcher()), | ||
| commarea.commKey(), | ||
| commarea.commName(), | ||
| commarea.commAddress(), | ||
| commarea.commDateOfBirth(), | ||
| creditScore, | ||
| defaultInt(commarea.commCsReviewDate()), | ||
| defaultString(commarea.commSuccess()), | ||
| defaultString(commarea.commFailCode()) | ||
| )); | ||
| } | ||
|
|
||
| private int awaitCreditScore(CrecustRequest request, int agencyNumber) { | ||
| CompletableFuture<java.util.Optional<Integer>> future = | ||
| creditAgencyService.requestCreditScore(request, agencyNumber); | ||
| try { | ||
| return future.get(CREDIT_AGENCY_TIMEOUT_SECONDS, TimeUnit.SECONDS).orElse(0); | ||
| } catch (TimeoutException exception) { | ||
| future.cancel(true); | ||
| throw new CbsaAbendException("PLOP", "Credit agency processing timed out.", exception); | ||
| } catch (ExecutionException | CompletionException exception) { | ||
| Throwable cause = exception.getCause(); | ||
| if (cause instanceof RuntimeException runtimeException) { | ||
| throw runtimeException; | ||
| } | ||
| throw new IllegalStateException("Credit agency processing failed.", cause); | ||
| } catch (InterruptedException exception) { | ||
| Thread.currentThread().interrupt(); | ||
| future.cancel(true); | ||
| throw new CbsaAbendException("PLOP", "Credit agency processing was interrupted.", exception); | ||
| } | ||
| } | ||
|
|
||
| private String defaultString(String value) { | ||
| return value == null ? "" : value; | ||
| } | ||
|
|
||
| private int defaultInt(Integer value) { | ||
| return value == null ? 0 : value; | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On successful processing,
CommSuccess/CommFailCodeare currently echoed from the request (and defaulted), so callers can receive a credit score but still see a blank/incorrect success indicator. Consider populating these fields from the actual outcome (similar to other controllers) so the response consistently signals success/failure.Severity: medium
🤖 Was this useful? React with 👍 or 👎