Skip to content

Commit

Permalink
Fix - Modified invocation of the putArrangementById API to provide th…
Browse files Browse the repository at this point in the history
…e internal ID of the arrangement instead of the external ID
  • Loading branch information
joshua-backbase committed Nov 19, 2024
1 parent e63edf9 commit 20638f8
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 21 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog
All notable changes to this project will be documented in this file.

## [6.4.2](https://github.com/Backbase/stream-services/compare/6.4.1...6.4.2)
### Fixed
- Fixed invocation of [putArrangementById](https://backbase.io/developers/apis/specs/arrangement-manager/arrangement-service-api/3.0.5/operations/Arrangements/putArrangementById/) in `ArrangementService` to pass in the arrangement's internalId.
The arrangement's externalId was erroneously being provided to this method.

## [6.4.0](https://github.com/Backbase/stream-services/compare/6.3.0...6.4.0)
### Fixed
- Fixed setting internal id for creatorLE before creating SA
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private Mono<ArrangementIngestResponse> validate(ArrangementIngestResponse res)
}

private Mono<ArrangementIngestResponse> sendToDbs(ArrangementIngestResponse res) {
return arrangementService.updateArrangement(res.getArrangement())
return arrangementService.updateArrangement(res.getArrangementInternalId(), res.getArrangement())
.map(item -> ArrangementIngestResponse.builder()
.arrangement(res.getArrangement())
.arrangementInternalId(res.getArrangementInternalId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ void pushIngestProduct_Success() throws Exception {

@Test
void pullIngestArrangement_Success() throws Exception {
when(arrangementService.updateArrangement(any()))
when(arrangementService.updateArrangement(any(), any()))
.thenReturn(Mono.just(new ArrangementPutItem()));

ArrangementPullIngestionRequest pullIngestionRequest =
Expand All @@ -237,7 +237,7 @@ void pullIngestArrangement_Success() throws Exception {

@Test
void pullIngestArrangement_Fail() throws Exception {
when(arrangementService.updateArrangement(any()))
when(arrangementService.updateArrangement(any(), any()))
.thenThrow(new RuntimeException());

ArrangementPullIngestionRequest pullIngestionRequest =
Expand All @@ -263,7 +263,7 @@ void pushIngestArrangement_Success() throws IOException {
com.backbase.stream.compositions.product.api.model.AccountArrangementItemPut arrangementItemPut =
mapper.treeToValue(node, com.backbase.stream.compositions.product.api.model.AccountArrangementItemPut.class);

when(arrangementService.updateArrangement(any()))
when(arrangementService.updateArrangement(any(), any()))
.thenReturn(Mono.just(new ArrangementPutItem()));

ArrangementPushIngestionRequest pushIngestionRequest =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ public Mono<ArrangementItem> createArrangement(PostArrangement postArrangement)

}

public Mono<ArrangementPutItem> updateArrangement(ArrangementPutItem arrangementPutItem) {
public Mono<ArrangementPutItem> updateArrangement(String arrangementId, ArrangementPutItem arrangementPutItem) {
log.info("Updating Arrangement: {}", arrangementPutItem.getExternalArrangementId());
if(arrangementPutItem.getDebitCards() == null) {
arrangementPutItem.setDebitCards(emptyList());
}
return arrangementsApi.putArrangementById(arrangementPutItem.getExternalArrangementId(), arrangementPutItem)
return arrangementsApi.putArrangementById(arrangementId, arrangementPutItem)
.doOnEach(aVoid -> log.info("Updated Arrangement: {}", arrangementPutItem.getExternalArrangementId()))
.thenReturn(fromCallable(() -> arrangementPutItem))
.thenReturn(arrangementPutItem)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -122,35 +123,37 @@ void createArrangement_Failure() {

@Test
void updateArrangement() {
String arrangementId = UUID.randomUUID().toString();
ArrangementPutItem request = buildArrangementPutItem();

when(arrangementsApi.putArrangementById(request.getExternalArrangementId(), request)).thenReturn(Mono.empty());
when(arrangementsApi.putArrangementById(arrangementId, request)).thenReturn(Mono.empty());

StepVerifier.create(arrangementService.updateArrangement(request))
StepVerifier.create(arrangementService.updateArrangement(arrangementId, request))
.assertNext(response -> {
Assertions.assertNotNull(response);
Assertions.assertEquals(request.getExternalArrangementId(), response.getExternalArrangementId());
Assertions.assertEquals(request.getProductId(), response.getProductId());
}).verifyComplete();

verify(arrangementsApi).putArrangementById(request.getExternalArrangementId(), request);
verify(arrangementsApi).putArrangementById(arrangementId, request);
}

@Test
void updateArrangement_Failure() {
String arrangementId = UUID.randomUUID().toString();
ArrangementPutItem request = buildArrangementPutItem();

WebClientResponseException webClientResponseException = buildWebClientResponseException(HttpStatus.BAD_REQUEST, "Bad Request for update arrangement");
when(arrangementsApi.putArrangementById(request.getExternalArrangementId(), request)).thenReturn(Mono.error(webClientResponseException));
when(arrangementsApi.putArrangementById(arrangementId, request)).thenReturn(Mono.error(webClientResponseException));

StepVerifier.create(arrangementService.updateArrangement(request))
StepVerifier.create(arrangementService.updateArrangement(arrangementId, request))
.consumeErrorWith(e -> {
Assertions.assertInstanceOf(ArrangementUpdateException.class, e);
Assertions.assertEquals("Failed to update Arrangement: %s".formatted(request.getExternalArrangementId()), e.getMessage());
Assertions.assertEquals(webClientResponseException.getMessage(), e.getCause().getMessage());
}).verify();

verify(arrangementsApi).putArrangementById(request.getExternalArrangementId(), request);
verify(arrangementsApi).putArrangementById(arrangementId, request);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,22 +293,21 @@ public Mono<ArrangementItem> upsertArrangement(ProductGroupTask streamTask, Post
streamTask.info(ARRANGEMENT, UPSERT_ARRANGEMENT, "", postArrangement.getId(), null, "Inserting or updating arrangement: %s", postArrangement.getId());
log.info("Upsert Arrangement: {} in Product Group: {}", postArrangement.getId(), streamTask.getData().getName());
Mono<ArrangementItem> updateArrangement = arrangementService.getArrangementInternalId(postArrangement.getId())
.flatMap(internalIdList -> {
String internalIds = String.join(",", internalIdList);
log.info("Arrangement already exists: {}", internalIdList);
streamTask.info(ARRANGEMENT, UPSERT_ARRANGEMENT, EXISTS, postArrangement.getId(), internalIds, "Arrangement %s already exists", postArrangement.getId());
ArrangementPutItem arrangemenItemBase = productMapper.toArrangementItemPut(postArrangement);
return arrangementService.updateArrangement(arrangemenItemBase)
.flatMap(arrangementInternalId -> {
log.info("Arrangement already exists: {}", arrangementInternalId);
streamTask.info(ARRANGEMENT, UPSERT_ARRANGEMENT, EXISTS, postArrangement.getId(), arrangementInternalId, "Arrangement %s already exists", postArrangement.getId());
ArrangementPutItem arrangementItemBase = productMapper.toArrangementItemPut(postArrangement);
return arrangementService.updateArrangement(arrangementInternalId, arrangementItemBase)
.onErrorResume(ArrangementUpdateException.class, e -> {
streamTask.error(ARRANGEMENT, UPDATE_ARRANGEMENT, FAILED, postArrangement.getId(), internalIds, e, e.getHttpResponse(), "Failed to update arrangement: %s", postArrangement.getId());
streamTask.error(ARRANGEMENT, UPDATE_ARRANGEMENT, FAILED, postArrangement.getId(), arrangementInternalId, e, e.getHttpResponse(), "Failed to update arrangement: %s", postArrangement.getId());
return Mono.error(new StreamTaskException(streamTask, e.getCause(),
e.getMessage() + " " + e.getCause().getMessage()));
})
.map(actual -> {
log.info("Updated arrangement: {}", actual.getExternalArrangementId());
streamTask.info(ARRANGEMENT, UPSERT_ARRANGEMENT, UPDATED, postArrangement.getId(), internalIdList, "Updated Arrangement");
streamTask.info(ARRANGEMENT, UPSERT_ARRANGEMENT, UPDATED, postArrangement.getId(), arrangementInternalId, "Updated Arrangement");
ArrangementItem arrangementItem = productMapper.toArrangementItem(actual);
arrangementItem.setId(internalIdList);
arrangementItem.setId(arrangementInternalId);
return arrangementItem;
});
});
Expand Down

0 comments on commit 20638f8

Please sign in to comment.