Skip to content

Commit

Permalink
Merge pull request #371 from Backbase/feature/service-agreement-update
Browse files Browse the repository at this point in the history
Secondary Service Agreement update functionality
  • Loading branch information
shafiquech authored Sep 1, 2023
2 parents 273d731 + ce2ade3 commit 16a9356
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog
All notable changes to this project will be documented in this file.

## [3.62.0](https://github.com/Backbase/stream-services/compare/3.61.0...3.62.0)
### Added
- Secondary Service Agreement update
## [3.60.3](https://github.com/Backbase/stream-services/compare/3.60.1...3.60.2)
### Changed
- Enhance Legal Entity level Limit Object to set Limit based on Privilege, Business Function and Legal Entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.backbase.dbs.accesscontrol.api.service.v3.model.ServiceAgreementParticipantsGetResponseBody;
import com.backbase.dbs.accesscontrol.api.service.v3.model.ServiceAgreementUsersQuery;
import com.backbase.dbs.accesscontrol.api.service.v3.model.ServicesAgreementIngest;
import com.backbase.dbs.accesscontrol.api.service.v3.model.ServiceAgreementPut;
import com.backbase.dbs.user.api.service.v2.UserManagementApi;
import com.backbase.dbs.user.api.service.v2.model.GetUser;
import com.backbase.stream.configuration.DeletionProperties;
Expand Down Expand Up @@ -93,6 +94,7 @@
import org.mapstruct.factory.Mappers;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.reactive.function.client.WebClientResponseException;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
Expand Down Expand Up @@ -172,6 +174,23 @@ public Mono<ServiceAgreement> getServiceAgreementByExternalId(String externalId)
.map(accessGroupMapper::toStream);
}

/**
*
* @param streamTask
* @param serviceAgreement
* @return Service Agreement
*/
public Mono<ServiceAgreement> updateServiceAgreementItem(StreamTask streamTask, ServiceAgreement serviceAgreement) {
log.info("Updating Service Agreement with external Id: {}", serviceAgreement.getExternalId());
ServiceAgreementPut serviceAgreementPut = accessGroupMapper.toPresentationPut(serviceAgreement);
return serviceAgreementsApi.putServiceAgreementItem(serviceAgreement.getInternalId(), serviceAgreementPut)
.onErrorResume(HttpClientErrorException.class, throwable -> {
log.error(SERVICE_AGREEMENT, "update", "failed", serviceAgreement.getExternalId(),
"", throwable, throwable.getResponseBodyAsString(), "Failed to update Service Agreement");
return Mono.error(new StreamTaskException(streamTask, throwable, "Failed to update Service Agreement"));
})
.thenReturn(serviceAgreement);
}
/**
* Update Service Agreement.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.springframework.http.HttpStatus.BAD_REQUEST;

import com.backbase.dbs.accesscontrol.api.service.v3.DataGroupsApi;
import com.backbase.dbs.accesscontrol.api.service.v3.FunctionGroupsApi;
Expand Down Expand Up @@ -74,6 +75,7 @@
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.http.HttpMethod;
import org.springframework.web.reactive.function.client.WebClientResponseException;
import org.springframework.web.client.HttpClientErrorException;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
Expand Down Expand Up @@ -667,7 +669,47 @@ void deleteFunctionGroupsForServiceAgreement_templateTypeConfigured_deletesOnlyT
List<PresentationIdentifier> value = captor.getValue();
assertEquals(templateFunctionGroup.getId(), value.get(0).getIdIdentifier());
}
@Test
void testUpdateServiceAgreementItem() {
StreamTask streamTask = Mockito.mock(StreamTask.class);

ServiceAgreement serviceAgreement = new ServiceAgreement();
serviceAgreement.setExternalId("external-id");
serviceAgreement.setInternalId("internal-id");
serviceAgreement.setName("name");

when(serviceAgreementsApi.putServiceAgreementItem(any(), any())).thenReturn(Mono.empty());

Mono<ServiceAgreement> resultMono = subject.updateServiceAgreementItem(streamTask, serviceAgreement);

StepVerifier.create(resultMono)
.expectNext(serviceAgreement)
.verifyComplete();

verify(serviceAgreementsApi, times(1))
.putServiceAgreementItem(eq("internal-id"), any());

}

@Test
void testUpdateServiceAgreementItemFailed() {
StreamTask streamTask = Mockito.mock(StreamTask.class);

ServiceAgreement serviceAgreement = new ServiceAgreement();
serviceAgreement.setExternalId("external-id");
serviceAgreement.setInternalId("internal-id");

when(serviceAgreementsApi.putServiceAgreementItem(any(), any()))
.thenReturn(Mono.error(new HttpClientErrorException(BAD_REQUEST, "Bad request", null, null, null)));

Mono<ServiceAgreement> resultMono = subject.updateServiceAgreementItem(streamTask, serviceAgreement);

StepVerifier.create(resultMono)
.verifyError(StreamTaskException.class);

verify(serviceAgreementsApi, times(1))
.putServiceAgreementItem(eq("internal-id"), any());
}
private void thenRegularUsersUpdateCall(String expectedSaExId, PresentationAction expectedAction,
String... expectedUserIds) {
PresentationServiceAgreementUsersBatchUpdate expectedRegularUserAddUpdate =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ backbase:
sink:
useIdentityIntegration: true
userProfileEnabled: true
serviceAgreementUpdateEnabled: false
compositions:
legal-entity:
integration-base-url: http://localhost:7001
Expand Down Expand Up @@ -444,4 +445,5 @@ bootstrap:

logging:
level:
com.backbase.stream: INFO
com.backbase.stream.compositions: DEBUG
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ backbase:
sink:
useIdentityIntegration: true
userProfileEnabled: true
serviceAgreementUpdateEnabled: false
compositions:
legal-entity:
integration-base-url: http://legal-entity-integration:8080
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -882,8 +882,14 @@ private Mono<LegalEntityTask> setupCustomServiceAgreement(LegalEntityTask stream
streamTask.info(SERVICE_AGREEMENT, SETUP_SERVICE_AGREEMENT, EXISTS, sa.getExternalId(), sa.getInternalId(),
"Existing Service Agreement: %s found for Legal Entity: %s", sa.getExternalId(),
legalEntity.getExternalId());
return accessGroupService.updateServiceAgreementAssociations(streamTask, newSa, userActions)
.thenReturn(streamTask);
if (legalEntitySagaConfigurationProperties.isServiceAgreementUpdateEnabled()) {
return accessGroupService.updateServiceAgreementItem(streamTask, newSa)
.then(accessGroupService.updateServiceAgreementAssociations(streamTask, newSa, userActions))
.thenReturn(streamTask);
} else {
return accessGroupService.updateServiceAgreementAssociations(streamTask, newSa, userActions)
.thenReturn(streamTask);
}
});
// As creatorLegalEntity doesnt accept external ID
// If creatorLegalEntity property is specified and equals to LE's parentExternalId then setup the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ public class LegalEntitySagaConfigurationProperties extends StreamWorkerConfigur
*/
private boolean userProfileEnabled = false;

/**
* Enable service agreement update
*/
private boolean serviceAgreementUpdateEnabled = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.lenient;

import com.backbase.dbs.accesscontrol.api.service.v3.model.ServiceAgreementParticipantsGetResponseBody;
import com.backbase.dbs.contact.api.service.v2.model.AccessContextScope;
Expand Down Expand Up @@ -441,6 +442,8 @@ void productGroupsProcessedSequentially() {
when(legalEntityService.putLegalEntity(any())).thenReturn(Mono.just(legalEntityTask.getLegalEntity()));
when(legalEntitySagaConfigurationProperties.isUseIdentityIntegration())
.thenReturn(true);
when(legalEntitySagaConfigurationProperties.isServiceAgreementUpdateEnabled())
.thenReturn(true);
when(userService.setupRealm(legalEntityTask.getLegalEntity()))
.thenReturn(Mono.empty());
when(userService.linkLegalEntityToRealm(legalEntityTask.getLegalEntity()))
Expand All @@ -453,6 +456,8 @@ void productGroupsProcessedSequentially() {
.thenReturn(Mono.empty());
when(accessGroupService.getServiceAgreementByExternalId("Service_Agreement_Id"))
.thenReturn(Mono.just(new ServiceAgreement().internalId("101").externalId("Service_Agreement_Id")));
lenient().when(accessGroupService.updateServiceAgreementItem(any(), any()))
.thenReturn(Mono.just(new ServiceAgreement().internalId("101").externalId("Service_Agreement_Id")));
when(accessGroupService.updateServiceAgreementAssociations(any(), any(), any()))
.thenReturn(Mono.just(new ServiceAgreement().internalId("101").externalId("Service_Agreement_Id")));
when(accessGroupService.createServiceAgreement(any(), any()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ private void setupWireMock() {
WireMock.put("/access-control/service-api/v3/accesscontrol/data-groups/batch/update/data-items")
.willReturn(WireMock.aResponse().withStatus(HttpStatus.ACCEPTED.value()))
);
stubFor(
WireMock.put("/access-control/service-api/v3/accesscontrol/service-agreements/500001")
.willReturn(WireMock.aResponse().withStatus(HttpStatus.OK.value()))
);
stubFor(
WireMock.post("/loan/service-api/v1/loans/batch")
.willReturn(WireMock.aResponse().withStatus(HttpStatus.MULTI_STATUS.value())
Expand Down

0 comments on commit 16a9356

Please sign in to comment.