Skip to content

Commit

Permalink
Merge pull request #464 from Backbase/feature/PRSUM-10218-stream-serv…
Browse files Browse the repository at this point in the history
…ices-update-new-developer

Feature/prsum 10218 stream services update new developer
  • Loading branch information
daniel-chiuratto-seabra authored Oct 1, 2024
2 parents e956e82 + 2d867ae commit a45ea59
Show file tree
Hide file tree
Showing 33 changed files with 924 additions and 1,019 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file.

## [5.14.0](https://github.com/Backbase/stream-services/compare/5.13.0...5.14.0)
### Changed
- Updated arrangement-manager service-api from v2 to v3

## [5.13.0](https://github.com/Backbase/stream-services/compare/5.12.0...5.13.0)
### Changed
- Bumping Backbase BOM to 2024.09-LTS
Expand All @@ -9,7 +14,6 @@ All notable changes to this project will be documented in this file.
### Added
- Adding additional pmts mappings


## [5.11.1](https://github.com/Backbase/stream-services/compare/5.11.0...5.11.1)
### Changed
- Updated plan-manager service api from 0.5.0 to 0.9.0
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<parent>
<groupId>com.backbase.buildingblocks</groupId>
<artifactId>backbase-parent</artifactId>
<version>17.0.0</version>
<version>17.1.0</version>
<relativePath/>
</parent>

<groupId>com.backbase.stream</groupId>
<artifactId>stream-services</artifactId>
<version>5.13.0</version>
<version>5.14.0</version>

<packaging>pom</packaging>
<name>Stream :: Services</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.backbase.stream.service;

import com.backbase.dbs.arrangement.api.service.v2.model.AccountArrangementItem;
import com.backbase.dbs.arrangement.api.service.v3.model.ArrangementItem;
import com.backbase.stream.exceptions.UserNotFoundException;
import com.backbase.stream.legalentity.model.AssignedPermission;
import com.backbase.stream.legalentity.model.BaseProductGroup.ProductGroupTypeEnum;
import com.backbase.stream.legalentity.model.LegalEntity;
import com.backbase.stream.legalentity.model.ProductGroup;
import com.backbase.stream.legalentity.model.ServiceAgreement;
import com.backbase.stream.legalentity.model.User;
import com.backbase.stream.product.service.ArrangementService;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Flux;
Expand Down Expand Up @@ -71,42 +70,10 @@ private Flux<AssignedPermission> getAssignedPermissionForServiceAgreement(
.map(products -> setAssignedPermissionForArrangements(permission, products)));
}

/**
* Get All Products a legal entity has access to.
*
* @param legalEntityId Internal Legal Entity Id
* @return List of Products
*/
public Flux<AccountArrangementItem> getProductsForInternalLegalEntityId(String legalEntityId) {
return legalEntityService.getMasterServiceAgreementForInternalLegalEntityId(legalEntityId)
.flatMapMany(sa -> accessGroupService.getDataGroupItemIdsByServiceAgreementId(sa.getInternalId())
.flatMap(arrangementService::getArrangement)
);
}

/**
* Get All Products a legal entity has access to.
*
* @param legalEntityId External Legal Entity Id
* @return List of Products
*/
public Flux<AccountArrangementItem> getProductsForExternalLegalEntityId(String legalEntityId) {
return legalEntityService.getLegalEntityByExternalId(legalEntityId).flux()
.flatMap(legalEntity -> getProductsForInternalLegalEntityId(legalEntity.getInternalId()));
}

private AssignedPermission setAssignedPermissionForJourneys(AssignedPermission permission, List<String> externalIds,
ProductGroup.ProductGroupTypeEnum productGroupTypeEnum) {
permission.setPermittedObjectExternalIds(externalIds);
return permission;
}

private AssignedPermission setAssignedPermissionForArrangements(AssignedPermission permission,
List<AccountArrangementItem> products) {
List<String> externalIds = products.stream().map(AccountArrangementItem::getExternalArrangementId)
.collect(Collectors.toList());
permission.setPermittedObjects(
Collections.singletonMap(ProductGroup.ProductGroupTypeEnum.ARRANGEMENTS.name(), products));
List<ArrangementItem> products) {
List<String> externalIds = products.stream().map(ArrangementItem::getExternalArrangementId).toList();
permission.setPermittedObjects(Collections.singletonMap(ProductGroupTypeEnum.ARRANGEMENTS.name(), products));
permission.setPermittedObjectExternalIds(externalIds);
return permission;
}
Expand All @@ -115,9 +82,7 @@ public Mono<Tuple2<User, LegalEntity>> getLegalEntityForUserName(String username
return userService.getUserByExternalId(username)
.doOnNext(user -> log.info("Found user: {} for username: {}", user.getInternalId(), username))
.switchIfEmpty(Mono.error(new UserNotFoundException("User not found for username: " + username)))
.flatMap(user -> {
return Mono.just(user).zipWith(legalEntityService.getLegalEntityByInternalId(user.getLegalEntityId()));
});
.flatMap(user -> Mono.just(user).zipWith(legalEntityService.getLegalEntityByInternalId(user.getLegalEntityId())));
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
package com.backbase.stream.compositions.product.core.mapper;

import com.backbase.dbs.arrangement.api.service.v3.model.ArrangementPutItem;
import org.mapstruct.AfterMapping;
import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.springframework.stereotype.Component;

@Component
@Mapper(componentModel = "spring", injectionStrategy = InjectionStrategy.CONSTRUCTOR)
public interface ArrangementMapper {
com.backbase.stream.compositions.product.api.model.AccountArrangementItemPut mapStreamToComposition(
com.backbase.dbs.arrangement.api.service.v2.model.AccountArrangementItemPut arrangement);

com.backbase.dbs.arrangement.api.service.v2.model.AccountArrangementItemPut mapIntegrationToStream(
com.backbase.stream.compositions.product.integration.client.model.AccountArrangementItemPut arrangementItem);
com.backbase.stream.compositions.product.api.model.AccountArrangementItemPut mapStreamToComposition(ArrangementPutItem arrangement);

ArrangementPutItem mapIntegrationToStream(com.backbase.stream.compositions.product.integration.client.model.AccountArrangementItemPut arrangementItem);

ArrangementPutItem mapCompositionToStream(com.backbase.stream.compositions.product.api.model.AccountArrangementItemPut arrangementItem);

/**
* The following after mapping has been set because the models are initializing both internalLegalEntities
* and externalLegalEntities fields, which are Sets, and they need to have at least 1 element. For this scenario
* if we do not set them as null, the validation rejects them.
*
* @param arrangementPutItem {@link ArrangementPutItem} instance to be used for data ingestion
*/
@AfterMapping
default void setNullLegalEntities(@MappingTarget ArrangementPutItem arrangementPutItem) {
arrangementPutItem.setInternalLegalEntities(null);
arrangementPutItem.setExternalLegalEntities(null);
}

com.backbase.dbs.arrangement.api.service.v2.model.AccountArrangementItemPut mapCompositionToStream(
com.backbase.stream.compositions.product.api.model.AccountArrangementItemPut arrangementItem);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.backbase.stream.compositions.product.core.model;

import com.backbase.dbs.arrangement.api.service.v2.model.AccountArrangementItemPut;
import com.backbase.dbs.arrangement.api.service.v3.model.ArrangementPutItem;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -11,7 +11,7 @@
@Builder(toBuilder = true)
@AllArgsConstructor
public class ArrangementIngestPushRequest {
private AccountArrangementItemPut arrangement;
private ArrangementPutItem arrangement;
private String arrangementInternalId;
private String source;
private RequestConfig config;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.backbase.stream.compositions.product.core.model;

import com.backbase.dbs.arrangement.api.service.v2.model.AccountArrangementItemPut;
import com.backbase.dbs.arrangement.api.service.v3.model.ArrangementPutItem;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -11,7 +11,7 @@
@Builder(toBuilder = true)
@AllArgsConstructor
public class ArrangementIngestResponse {
private AccountArrangementItemPut arrangement;
private ArrangementPutItem arrangement;
private String arrangementInternalId;
private String source;
private RequestConfig config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.backbase.buildingblocks.presentation.errors.BadRequestException;
import com.backbase.buildingblocks.presentation.errors.Error;
import com.backbase.dbs.arrangement.api.service.v2.model.AccountArrangementItemPut;
import com.backbase.dbs.arrangement.api.service.v3.model.ArrangementPutItem;
import com.backbase.stream.compositions.product.core.model.ArrangementIngestPullRequest;
import com.backbase.stream.compositions.product.core.model.ArrangementIngestPushRequest;
import com.backbase.stream.compositions.product.core.model.ArrangementIngestResponse;
Expand Down Expand Up @@ -68,7 +68,7 @@ public Mono<ArrangementIngestResponse> pushArrangement(ArrangementIngestPushRequ
}

private Mono<ArrangementIngestResponse> validate(ArrangementIngestResponse res) {
Set<ConstraintViolation<AccountArrangementItemPut>> violations = validator.validate(res.getArrangement());
Set<ConstraintViolation<ArrangementPutItem>> violations = validator.validate(res.getArrangement());

if (!CollectionUtils.isEmpty(violations)) {
List<Error> errors = violations.stream().map(c -> new Error()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
package com.backbase.stream.compositions.product.core.mapper;

import com.backbase.stream.compositions.product.api.model.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

import com.backbase.stream.compositions.product.api.model.AccountArrangementItemPut;
import com.backbase.stream.compositions.product.api.model.ArrangementIngestionConfig;
import com.backbase.stream.compositions.product.api.model.ArrangementIngestionResponse;
import com.backbase.stream.compositions.product.api.model.ArrangementPullIngestionRequest;
import com.backbase.stream.compositions.product.api.model.ArrangementPushIngestionRequest;
import com.backbase.stream.compositions.product.core.model.ArrangementIngestPullRequest;
import com.backbase.stream.compositions.product.core.model.ArrangementIngestPushRequest;
import com.backbase.stream.compositions.product.core.model.ArrangementIngestResponse;
Expand All @@ -12,11 +21,6 @@
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.http.ResponseEntity;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class ArrangementRestMapperTest {
private static final String ARRANGEMENT_ID = "arrangementId";
Expand All @@ -37,7 +41,7 @@ void mapPushRequest() {
AccountArrangementItemPut arrangementItemPut = new AccountArrangementItemPut();

when(arrangementMapper.mapCompositionToStream(arrangementItemPut))
.thenReturn(new com.backbase.dbs.arrangement.api.service.v2.model.AccountArrangementItemPut());
.thenReturn(new com.backbase.dbs.arrangement.api.service.v3.model.ArrangementPutItem());

when(chainsMapper.map(any()))
.thenReturn(RequestConfig.builder().build());
Expand Down Expand Up @@ -79,8 +83,8 @@ void mapPullRequest() {

@Test
void mapResponse() {
com.backbase.dbs.arrangement.api.service.v2.model.AccountArrangementItemPut streamArrangement =
new com.backbase.dbs.arrangement.api.service.v2.model.AccountArrangementItemPut();
com.backbase.dbs.arrangement.api.service.v3.model.ArrangementPutItem streamArrangement =
new com.backbase.dbs.arrangement.api.service.v3.model.ArrangementPutItem();

AccountArrangementItemPut compositionArrangement = new AccountArrangementItemPut();

Expand All @@ -89,7 +93,7 @@ void mapResponse() {

ArrangementIngestResponse response = ArrangementIngestResponse
.builder()
.arrangement(new com.backbase.dbs.arrangement.api.service.v2.model.AccountArrangementItemPut())
.arrangement(new com.backbase.dbs.arrangement.api.service.v3.model.ArrangementPutItem())
.build();

ResponseEntity<ArrangementIngestionResponse> responseEntity = arrangementRestMapper.mapResponse(response);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.backbase.stream.compositions.product.core.service.impl;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

import com.backbase.stream.compositions.product.core.mapper.ArrangementMapper;
import com.backbase.stream.compositions.product.core.model.ArrangementIngestPullRequest;
import com.backbase.stream.compositions.product.core.model.ArrangementIngestResponse;
import com.backbase.stream.compositions.product.integration.client.ArrangementIntegrationApi;
import com.backbase.stream.compositions.product.integration.client.model.AccountArrangementItemPut;
import com.backbase.stream.compositions.product.integration.client.model.PullArrangementResponse;
import java.util.Objects;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
Expand All @@ -14,9 +18,6 @@
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class ArrangementIntegrationServiceImplTest {
@InjectMocks
Expand Down Expand Up @@ -44,14 +45,12 @@ void pullArrangement_Success() {
.name("name")
)));
when(arrangementMapper.mapIntegrationToStream(any()))
.thenReturn(new com.backbase.dbs.arrangement.api.service.v2.model.AccountArrangementItemPut());
.thenReturn(new com.backbase.dbs.arrangement.api.service.v3.model.ArrangementPutItem());

Mono<ArrangementIngestResponse> responseMono = arrangementIntegrationService.pullArrangement(request);

StepVerifier.create(responseMono)
.expectNextMatches(item -> {
return item != null;
})
.expectNextMatches(Objects::nonNull)
.verifyComplete();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package com.backbase.stream.compositions.product.http;

import com.backbase.dbs.arrangement.api.service.v2.model.AccountArrangementItemPut;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static org.mockserver.integration.ClientAndServer.startClientAndServer;
import static org.mockserver.model.HttpRequest.request;
import static org.mockserver.model.HttpResponse.response;

import com.backbase.dbs.arrangement.api.service.v3.model.ArrangementPutItem;
import com.backbase.stream.compositions.paymentorder.client.model.PaymentOrderIngestionResponse;
import com.backbase.stream.compositions.paymentorder.client.model.PaymentOrderPostResponse;
import com.backbase.stream.compositions.product.api.model.ArrangementPullIngestionRequest;
Expand All @@ -20,12 +26,16 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.net.URI;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import org.apache.activemq.broker.BrokerService;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockserver.client.MockServerClient;
Expand All @@ -41,18 +51,6 @@
import org.springframework.test.web.reactive.server.WebTestClient;
import reactor.core.publisher.Mono;

import java.io.IOException;
import java.net.URI;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static org.mockserver.integration.ClientAndServer.startClientAndServer;
import static org.mockserver.model.HttpRequest.request;
import static org.mockserver.model.HttpResponse.response;

@DirtiesContext
@SpringBootTest
@AutoConfigureWebTestClient
Expand Down Expand Up @@ -220,7 +218,7 @@ void pushIngestProduct_Success() throws Exception {
@Test
void pullIngestArrangement_Success() throws Exception {
when(arrangementService.updateArrangement(any()))
.thenReturn(Mono.just(new AccountArrangementItemPut()));
.thenReturn(Mono.just(new ArrangementPutItem()));

ArrangementPullIngestionRequest pullIngestionRequest =
new ArrangementPullIngestionRequest()
Expand Down Expand Up @@ -266,7 +264,7 @@ void pushIngestArrangement_Success() throws IOException {
mapper.treeToValue(node, com.backbase.stream.compositions.product.api.model.AccountArrangementItemPut.class);

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

ArrangementPushIngestionRequest pushIngestionRequest =
new ArrangementPushIngestionRequest()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.backbase.stream.cursor.events;

import com.backbase.dbs.arrangement.api.service.v2.model.AccountArrangementItem;
import com.backbase.dbs.arrangement.api.service.v3.model.ArrangementItem;
import com.backbase.stream.TransactionService;
import com.backbase.stream.cursor.configuration.CursorServiceConfigurationProperties;
import com.backbase.stream.cursor.model.IngestionCursor;
Expand Down Expand Up @@ -85,13 +85,11 @@ private Flux<IngestionCursor> createIngestionCursor(User user, LegalEntity legal
List<IngestionCursor> ingestionCursors = new ArrayList<>();
ProductGroup.ProductGroupTypeEnum arrangements1 = ProductGroup.ProductGroupTypeEnum.ARRANGEMENTS;
Object arrangements = assignedPermission.getPermittedObjects().get(arrangements1.name());
if (arrangements instanceof List && (((List) arrangements).get(0) instanceof AccountArrangementItem)) {
List<AccountArrangementItem> products = (List<AccountArrangementItem>) arrangements;

for (AccountArrangementItem product : products) {
if (arrangements instanceof List && (((List<?>) arrangements).getFirst() instanceof ArrangementItem)) {
@SuppressWarnings("unchecked") List<ArrangementItem> products = (List<ArrangementItem>) arrangements;

for (ArrangementItem product : products) {
IngestionCursor ingestionCursor = createLoginIngestionCursor(loginEvent, user, legalEntity);

ingestionCursor.setArrangementId(product.getId());
ingestionCursor.setExternalArrangementId(product.getExternalArrangementId());
// Make this configurable?
Expand Down
Loading

0 comments on commit a45ea59

Please sign in to comment.