Skip to content

Commit

Permalink
Merge pull request #365 from Backbase/feature/ingest-arrangement-id-f…
Browse files Browse the repository at this point in the history
…or-pmts

Feature/ingest arrangement id for pmts
  • Loading branch information
Jan-Nel authored Aug 15, 2023
2 parents a346062 + 15fe501 commit b4c9f25
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ jobs:

- name: Upload to Repo
if: "contains(github.ref, 'master') || contains(github.ref, 'support/') || contains(github.ref, 'develop')" # In case of develop branch it will upload the snapshot version
run: mvn -B deploy -Pdocker-image,no-latest-tag -Dmaven.test.skip=true -Ddocker.default.tag=${{ env.DOCKER_TAG_VERSION }} -Ddocker.repo.url=repo.backbase.com -Ddocker.repo.project=backbase-stream-images -Djib.to.auth.username=${{ secrets.REPO_USERNAME }} -Djib.to.auth.password=${{ secrets.REPO_PASSWORD }} -DaltDeploymentRepository=backbase::default::https://repo.backbase.com/backbase-stream-releases/
run: mvn -B deploy -Pdocker-image,no-latest-tag,no-scs -Dmaven.test.skip=true -Ddocker.default.tag=${{ env.DOCKER_TAG_VERSION }} -Ddocker.repo.url=repo.backbase.com -Ddocker.repo.project=backbase-stream-images -Djib.to.auth.username=${{ secrets.REPO_USERNAME }} -Djib.to.auth.password=${{ secrets.REPO_PASSWORD }} -DaltDeploymentRepository=backbase::default::https://repo.backbase.com/backbase-stream-releases/
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog
All notable changes to this project will be documented in this file.

## [3.60.0](https://github.com/Backbase/stream-services/compare/3.59.0...3.60.0)
### Added
- Adding the ability to retrieve the arrangement a payment belongs to.
### Changed
- updated application-local configurations to be aligned with the new Backbase Local env.

## [3.59.0](https://github.com/Backbase/stream-services/compare/3.58.2...3.59.0)
### Added
- Add update identity user attributes in case it's previously created.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@ spring:
eureka:
client:
enabled: true
serviceUrl.defaultZone: http://localhost:8080/registry/eureka
serviceUrl.defaultZone: http://localhost:8761/eureka/

backbase:
communication:
services:
usermanager:
direct-uri: http://localhost:8086/user-manager
direct-uri: http://localhost:8060
access-control:
direct-uri: http://localhost:8086/access-control
direct-uri: http://localhost:8040
arrangement:
manager:
direct-uri: http://localhost:8082/arrangement-manager
direct-uri: http://localhost:8050
user:
profile:
direct-uri: http://localhost:8086/user-profile-manager
direct-uri: http://localhost:8061
identity:
integration:
direct-uri: http://localhost:8181/identity-integration-service
direct-uri: http://localhost:8070
http:
client-secret: bb-secret
client-id: bb-client
access-token-uri: "http://localhost:8181/oidc-token-converter-service/oauth/token"
access-token-uri: "http://localhost:7779/oauth/token"
stream:
legalentity:
sink:
Expand All @@ -43,7 +43,7 @@ backbase:
integration-base-url: http://localhost:7001
chains:
product-composition:
enabled: true
enabled: false
base-url: http://localhost:9003
async: false
events:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ backbase:
communication:
services:
usermanager:
direct-uri: http://localhost:8086/user-manager
direct-uri: http://localhost:8060
access-control:
direct-uri: http://localhost:8086/access-control
direct-uri: http://localhost:8040
arrangement:
manager:
direct-uri: http://localhost:8082/arrangement-manager
direct-uri: http://localhost:8050
payment:
order:
direct-uri: http://localhost:8090/payment-order-service
direct-uri: http://localhost:8051
transaction:
manager:
direct-uri: http://localhost:8083/transaction-manager
direct-uri: http://localhost:8083
http:
client-secret: bb-secret
client-id: bb-client
access-token-uri: http://localhost:8181/oidc-token-converter-service/oauth/token
access-token-uri: "http://localhost:7779/oauth/token"
activemq:
enabled: true
stream:
Expand All @@ -50,7 +50,7 @@ eureka:
role: live
client:
serviceUrl:
defaultZone: http://localhost:8080/registry/eureka/
defaultZone: http://localhost:8761/eureka/

logging:
level:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ backbase:
communication:
services:
usermanager:
direct-uri: http://localhost:8086/user-manager
direct-uri: http://localhost:8060
access-control:
direct-uri: http://localhost:8086/access-control
direct-uri: http://localhost:8040
arrangement:
manager:
direct-uri: http://localhost:8082/arrangement-manager
direct-uri: http://localhost:8050
http:
client-secret: bb-secret
client-id: bb-client
access-token-uri: http://localhost:8181/oidc-token-converter-service/oauth/token
access-token-uri: "http://localhost:7779/oauth/token"
stream:
compositions:
product-catalog:
Expand All @@ -37,7 +37,7 @@ eureka:
role: live
client:
serviceUrl:
defaultZone: http://localhost:8080/registry/eureka/
defaultZone: http://localhost:8761/eureka/

bootstrap:
enabled: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,29 @@ sso:
eureka:
client:
enabled: true
serviceUrl.defaultZone: http://localhost:8080/registry/eureka
serviceUrl.defaultZone: http://localhost:8761/eureka/

backbase:
communication:
services:
usermanager:
direct-uri: http://localhost:8086/user-manager
direct-uri: http://localhost:8060
access-control:
direct-uri: http://localhost:8086/access-control
direct-uri: http://localhost:8040
arrangement:
manager:
direct-uri: http://localhost:8082/arrangement-manager
direct-uri: http://localhost:8050
http:
client-secret: bb-secret
client-id: bb-client
access-token-uri: http://localhost:8181/oidc-token-converter-service/oauth/token
access-token-uri: "http://localhost:7779/oauth/token"
stream:
compositions:
product:
integration-base-url: http://localhost:7003
chains:
transaction-composition:
enabled: true
enabled: false
base-url: http://localhost:9004
async: false
excludeProductTypeExternalIds:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ backbase:
communication:
services:
usermanager:
direct-uri: http://localhost:8086/user-manager
direct-uri: http://localhost:8060
access-control:
direct-uri: http://localhost:8086/access-control
direct-uri: http://localhost:8040
arrangement:
manager:
direct-uri: http://localhost:8082/arrangement-manager
direct-uri: http://localhost:8050
transaction:
manager:
direct-uri: http://localhost:8083/transaction-manager
direct-uri: http://localhost:8083
http:
client-secret: bb-secret
client-id: bb-client
access-token-uri: http://localhost:8181/oidc-token-converter-service/oauth/token
access-token-uri: "http://localhost:7779/oauth/token"
activemq:
enabled: true
stream:
Expand All @@ -58,7 +58,7 @@ eureka:
role: live
client:
serviceUrl:
defaultZone: http://localhost:8080/registry/eureka/
defaultZone: http://localhost:8761/eureka/

logging:
level:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.backbase.stream.config;

import com.backbase.dbs.arrangement.api.service.v2.ArrangementsApi;
import com.backbase.dbs.paymentorder.api.service.v2.PaymentOrdersApi;
import com.backbase.stream.PaymentOrderService;
import com.backbase.stream.PaymentOrderServiceImpl;
Expand Down Expand Up @@ -34,10 +35,11 @@ public PaymentOrderUnitOfWorkExecutor paymentOrderUnitOfWorkExecutor(
PaymentOrderTaskExecutor paymentOrderTaskExecutor,
PaymentOrderUnitOfWorkRepository paymentOrderUnitOfWorkRepository,
PaymentOrderWorkerConfigurationProperties paymentOrderWorkerConfigurationProperties,
PaymentOrdersApi paymentOrdersApi) {
PaymentOrdersApi paymentOrdersApi,
ArrangementsApi arrangementsApi) {

return new PaymentOrderUnitOfWorkExecutor(paymentOrderUnitOfWorkRepository, paymentOrderTaskExecutor,
paymentOrderWorkerConfigurationProperties, paymentOrdersApi, paymentOrderTypeMapper);
paymentOrderWorkerConfigurationProperties, paymentOrdersApi, arrangementsApi, paymentOrderTypeMapper);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.backbase.stream.model;

import com.backbase.dbs.arrangement.api.service.v2.model.AccountArrangementItems;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -16,5 +17,5 @@ public class PaymentOrderIngestContext {
private String internalUserId;
private List<PaymentOrderPostRequest> corePaymentOrder = new ArrayList<>();
private List<GetPaymentOrderResponse> existingPaymentOrder = new ArrayList<>();

private List<AccountArrangementItems> arrangementIds = new ArrayList<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
import static com.backbase.dbs.paymentorder.api.service.v2.model.Status.READY;
import static com.backbase.dbs.paymentorder.api.service.v2.model.Status.REJECTED;

import com.backbase.dbs.arrangement.api.service.v2.ArrangementsApi;
import com.backbase.dbs.arrangement.api.service.v2.model.AccountArrangementItem;
import com.backbase.dbs.arrangement.api.service.v2.model.AccountArrangementItems;
import com.backbase.dbs.arrangement.api.service.v2.model.AccountArrangementsFilter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;

Expand Down Expand Up @@ -40,15 +45,18 @@
public class PaymentOrderUnitOfWorkExecutor extends UnitOfWorkExecutor<PaymentOrderTask> {

private final PaymentOrdersApi paymentOrdersApi;
private final ArrangementsApi arrangementsApi;
private final PaymentOrderTypeMapper paymentOrderTypeMapper;

public PaymentOrderUnitOfWorkExecutor(UnitOfWorkRepository<PaymentOrderTask, String> repository,
StreamTaskExecutor<PaymentOrderTask> streamTaskExecutor,
StreamWorkerConfiguration streamWorkerConfiguration,
PaymentOrdersApi paymentOrdersApi,
PaymentOrderTypeMapper paymentOrderTypeMapper) {
StreamTaskExecutor<PaymentOrderTask> streamTaskExecutor,
StreamWorkerConfiguration streamWorkerConfiguration,
PaymentOrdersApi paymentOrdersApi,
ArrangementsApi arrangementsApi,
PaymentOrderTypeMapper paymentOrderTypeMapper) {
super(repository, streamTaskExecutor, streamWorkerConfiguration);
this.paymentOrdersApi = paymentOrdersApi;
this.arrangementsApi = arrangementsApi;
this.paymentOrderTypeMapper = paymentOrderTypeMapper;
}

Expand All @@ -63,11 +71,12 @@ public Flux<UnitOfWork<PaymentOrderTask>> prepareUnitOfWork(List<PaymentOrderIng

public Flux<UnitOfWork<PaymentOrderTask>> prepareUnitOfWork(Flux<PaymentOrderPostRequest> items) {
return items.collectList()
.map(paymentOrderPostRequests -> this.createPaymentOrderIngestContext(paymentOrderPostRequests))
.flatMap(this::getPersistedScheduledTransfers)
.flatMapMany(this::getPaymentOrderIngestRequest)
.bufferTimeout(streamWorkerConfiguration.getBufferSize(), streamWorkerConfiguration.getBufferMaxTime())
.flatMap(this::prepareUnitOfWork);
.map(paymentOrderPostRequests -> this.createPaymentOrderIngestContext(paymentOrderPostRequests))
.flatMap(this::addArrangementIdMap)
.flatMap(this::getPersistedScheduledTransfers)
.flatMapMany(this::getPaymentOrderIngestRequest)
.bufferTimeout(streamWorkerConfiguration.getBufferSize(), streamWorkerConfiguration.getBufferMaxTime())
.flatMap(this::prepareUnitOfWork);
}

private PaymentOrderIngestContext createPaymentOrderIngestContext(List<PaymentOrderPostRequest> paymentOrderPostRequests) {
Expand All @@ -90,28 +99,44 @@ private PaymentOrderIngestContext createPaymentOrderIngestContext(List<PaymentOr

return getPayments(paymentOrderIngestContext2.internalUserId())
.map(response -> {
listOfPayments.addAll(response.getPaymentOrders());
listOfPayments.addAll(response.getPaymentOrders());
return listOfPayments;
})
.map(getPaymentOrderResponses -> paymentOrderIngestContext2.existingPaymentOrder(getPaymentOrderResponses))
.doOnSuccess(result ->
log.debug("Successfully fetched dbs scheduled payment orders"));
}

private @NotNull @Valid Mono<PaymentOrderIngestContext> addArrangementIdMap(PaymentOrderIngestContext paymentOrderIngestContext) {

return Flux.fromIterable(paymentOrderIngestContext.corePaymentOrder())
.flatMap(this::getArrangement)
.distinct()
.collectList()
.map(accountInternalIdGetResponseBody -> paymentOrderIngestContext.arrangementIds(accountInternalIdGetResponseBody));
}

private Mono<AccountArrangementItems> getArrangement(PaymentOrderPostRequest paymentOrderPostRequest) {
AccountArrangementsFilter accountArrangementsFilter = new AccountArrangementsFilter()
.externalArrangementIds(Collections.singletonList(paymentOrderPostRequest.getOriginatorAccount().getExternalArrangementId()));
return arrangementsApi.postFilter(accountArrangementsFilter);
}

/**
* Calls the payment order service to retrieve existing payments.
*
* @param internalUserId The user's internal id that came with the Payments.
* @return A Mono with the response from the service api.
*/
private Mono<PaymentOrderPostFilterResponse> getPayments(String internalUserId) {

var paymentOrderPostFilterRequest = new PaymentOrderPostFilterRequest();
paymentOrderPostFilterRequest.setStatuses(
List.of(READY, ACCEPTED, PROCESSED, CANCELLED, REJECTED, CANCELLATION_PENDING));

return paymentOrdersApi.postFilterPaymentOrders(
null, null, null, null, null, null, null, null, null, null, null,
internalUserId, null, null, null, null,
internalUserId, null, null, null, Integer.MAX_VALUE,
null, null, paymentOrderPostFilterRequest);
}

Expand All @@ -134,6 +159,11 @@ private Flux<PaymentOrderIngestRequest> getPaymentOrderIngestRequest(PaymentOrde
// build new payment list (Bank ref is in core, but not in DBS)
paymentOrderIngestContext.corePaymentOrder().forEach(corePaymentOrder -> {
if(!existingBankRefIds.contains(corePaymentOrder.getBankReferenceId())) {
AccountArrangementItem accountArrangementItem = getInternalArrangementId(paymentOrderIngestContext.arrangementIds(),
corePaymentOrder.getOriginatorAccount().getExternalArrangementId());
if (accountArrangementItem != null) {
corePaymentOrder.getOriginatorAccount().setArrangementId(accountArrangementItem.getId());
}
paymentOrderIngestRequests.add(new NewPaymentOrderIngestRequest(corePaymentOrder));
}
});
Expand All @@ -157,4 +187,13 @@ private Flux<PaymentOrderIngestRequest> getPaymentOrderIngestRequest(PaymentOrde

return Flux.fromIterable(paymentOrderIngestRequests);
}

private AccountArrangementItem getInternalArrangementId(List<AccountArrangementItems> accountArrangementItemsList, String externalArrangementId) {

return accountArrangementItemsList.stream()
.flatMap(a -> a.getArrangementElements().stream())
.filter(b -> b.getExternalArrangementId().equalsIgnoreCase(externalArrangementId))
.findFirst()
.orElse(null);
}
}
Loading

0 comments on commit b4c9f25

Please sign in to comment.