Skip to content

feat(creacc): translate CREACC to Java#13

Merged
a2chang merged 3 commits intomainfrom
migrate/CREACC
May 1, 2026
Merged

feat(creacc): translate CREACC to Java#13
a2chang merged 3 commits intomainfrom
migrate/CREACC

Conversation

@a2chang
Copy link
Copy Markdown
Contributor

@a2chang a2chang commented May 1, 2026

Source program: https://github.com/augment-solutions/cics-banking-sample-application-cbsa/blob/main/src/base/cobol_src/CREACC.cbl

Mapped REST endpoints

  • POST /api/v1/creacc/insert

Notable decisions

  • Reused InqcustService and InqacccuService to mirror the COBOL EXEC CICS LINK validation flow before persisting the account.
  • Replaced the COBOL named-counter ENQ/DEQ with a CockroachDB control row SELECT FOR UPDATE, wrapped in CrdbRetry, so account allocation is transactional and retry-safe.
  • Persisted the account, control, and proctran updates in one transaction so failed writes do not leave partially-created account state behind.
  • Preserved the z/OS Connect nested CreAcc JSON contract in request/response DTOs while continuing the project-wide RFC-7807 ProblemDetail error handling for failure paths.

Test coverage

  • Unit: CreaccServiceUnitTest
  • SpringBootTest: CreaccServiceIntegrationTest
  • MockMvc: CreaccControllerTest
  • Web slice: CreaccControllerWebMvcTest

@a2chang
Copy link
Copy Markdown
Contributor Author

a2chang commented May 1, 2026

augment review

@augmentcode
Copy link
Copy Markdown
Contributor

augmentcode Bot commented May 1, 2026

Test Coverage Guardian 🧪

Test coverage looks good. The new/changed behavior in this PR has adequate test coverage. No additional tests needed.

This PR includes comprehensive testing across multiple layers:

  • Unit tests: CreaccServiceUnitTest validates business logic with mocked dependencies
  • Integration tests: CreaccServiceIntegrationTest tests the full service layer against CockroachDB
  • Controller tests: CreaccControllerTest validates HTTP endpoints with SpringBootTest
  • Web slice tests: CreaccControllerWebMvcTest tests controller behavior in isolation

The tests cover happy paths, validation failures, edge cases (max accounts per customer), and error handling scenarios.

Copy link
Copy Markdown

@augment-app-staging augment-app-staging Bot left a comment

Choose a reason for hiding this comment

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

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

}

private boolean isSupportedAccountType(String accountType) {
return accountType.startsWith("ISA")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Using startsWith here will accept values like ISAFOO (still <= 8 chars) as “supported”, which looks like it bypasses the intended account-type validation.

Severity: medium

🤖 Was this useful? React with 👍 or 👎

@Test
void createsAccountAuditTrailAndControlRow() {
insertCustomer(10L);
LocalDate today = LocalDate.now(Clock.systemUTC());
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Capturing today before calling creaccService.create(...) can make this test flaky if execution crosses midnight UTC between the two calls (the service derives its own today from Instant.now(clock)).

Severity: low

Other Locations
  • src/test/java/com/augment/cbsa/web/creacc/CreaccControllerTest.java:51

🤖 Was this useful? React with 👍 or 👎

@a2chang
Copy link
Copy Markdown
Contributor Author

a2chang commented May 1, 2026

augment review

Copy link
Copy Markdown

@augment-app-staging augment-app-staging Bot left a comment

Choose a reason for hiding this comment

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

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

private static final Set<String> VALIDATION_FAIL_CODES = Set.of("A");
private static final Set<String> NOT_FOUND_FAIL_CODES = Set.of("1");
private static final Set<String> CAPACITY_FAIL_CODES = Set.of("8");
private static final Set<String> TRANSIENT_FAIL_CODES = Set.of("3", "5");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

After replacing the COBOL ENQ/DEQ with transactional row locking, it looks like CREACC never produces failCode 3/5 anymore, so isTransientFailure() (and the controller’s 503 mapping) may be unreachable.
If counter/lock acquisition can still fail transiently, consider whether it should be surfaced as a CREACC failure code rather than bubbling up as an abend/500.

Severity: medium

Other Locations
  • src/main/java/com/augment/cbsa/web/creacc/CreaccController.java:67
  • src/main/java/com/augment/cbsa/repository/CreaccRepository.java:39

🤖 Was this useful? React with 👍 or 👎

@Test
void createsAccountAuditTrailAndControlRow() {
insertCustomer(10L);
LocalDate today = LocalDate.now(Clock.systemUTC());
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These assertions derive today from Clock.systemUTC() separately from the application’s injected Clock, which can make the test flaky if execution crosses midnight between the two reads.
Using the same fixed/overridden Clock for both the service and expectations would avoid intermittent failures.

Severity: low

Other Locations
  • src/test/java/com/augment/cbsa/web/creacc/CreaccControllerTest.java:51

🤖 Was this useful? React with 👍 or 👎

Copy link
Copy Markdown

@augment-app-staging augment-app-staging Bot left a comment

Choose a reason for hiding this comment

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

Review completed. 1 suggestion posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

.set(ACCOUNT.ACTUAL_BALANCE, account.actualBalance())
.execute();
} catch (DataAccessException exception) {
throw rollbackFailure("7", "Unable to create the account record.");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

By catching DataAccessException here and converting it into a rollback failure, Cockroach serialization failures (SQLSTATE 40001) will also be treated as a business failure rather than being retried by CrdbRetry. This can make account creation intermittently fail under contention even though the operation is retryable.

Severity: medium

Other Locations
  • src/main/java/com/augment/cbsa/repository/CreaccRepository.java:58
  • src/main/java/com/augment/cbsa/repository/CreaccRepository.java:93
  • src/main/java/com/augment/cbsa/repository/CreaccRepository.java:126

🤖 Was this useful? React with 👍 or 👎

@a2chang
Copy link
Copy Markdown
Contributor Author

a2chang commented May 1, 2026

augment review

Copy link
Copy Markdown

@augment-app-staging augment-app-staging Bot left a comment

Choose a reason for hiding this comment

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

Review completed. 3 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

) {

public CreaccCommareaRequestDto {
Objects.requireNonNull(commCustno, "commCustno must not be null");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These Objects.requireNonNull(...) checks in the request DTO constructor can throw during JSON deserialization, which will bypass the validation handlers and fall into CbsaExceptionHandler#handleUnexpected (500) instead of returning a 400 validation error. That can make missing/invalid fields surface as server errors.

Severity: medium

Other Locations
  • src/main/java/com/augment/cbsa/web/creacc/dto/CreaccRequestDto.java:16
  • src/main/java/com/augment/cbsa/web/creacc/dto/CreaccKeyDto.java:24

🤖 Was this useful? React with 👍 or 👎

private static final String COUNTER_ABEND_CODE = "HNCS";
private static final String PROCTRAN_ABEND_CODE = "HWPT";
private static final long MAX_ACCOUNT_NUMBER = 99_999_999L;
private static final DateTimeFormatter COBOL_DATE_FORMATTER = DateTimeFormatter.ofPattern("ddMMyyyy");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

DateTimeFormatter.ofPattern("ddMMyyyy") without an explicit locale can emit non-ASCII digits under some default locales, which can corrupt persisted PROCTRAN.DESCRIPTION (it’s meant to be COBOL-style numeric text). Consider ensuring the formatter is locale-stable for these numeric fields.

Severity: low

Other Locations
  • src/main/java/com/augment/cbsa/web/creacc/CreaccController.java:30

🤖 Was this useful? React with 👍 or 👎

return new CreaccResponseDto(new CreaccCommareaResponseDto(
EYE_CATCHER,
account.customerNumber(),
new CreaccKeyDto(Integer.parseInt(account.sortcode()), account.accountNumber()),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Integer.parseInt(account.sortcode()) will throw if cbsa.sortcode ever contains non-digit characters or surrounding whitespace, turning a configuration issue into a 500 at runtime. It might be worth validating/normalizing sortcode before using it to build responses.

Severity: medium

🤖 Was this useful? React with 👍 or 👎

@a2chang
Copy link
Copy Markdown
Contributor Author

a2chang commented May 1, 2026

Round 3 of 3 (auto-review cap reached). Round-3 surfaced 4 distinct items; the 5th comment re-flagged the DataAccessException catch issue that was already addressed in this round on commit 5b7e924.

Captured as follow-up issues so this can merge:

Merging per the 3-round review cap.

@a2chang a2chang merged commit 5628a12 into main May 1, 2026
1 check passed
@a2chang a2chang deleted the migrate/CREACC branch May 1, 2026 08:46
@a2chang a2chang mentioned this pull request May 1, 2026
22 tasks
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