Skip to content

Commit

Permalink
Create get for tpp by entityId
Browse files Browse the repository at this point in the history
  • Loading branch information
BaldiVi committed Jan 23, 2025
1 parent 2b2580e commit 27cb15f
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/main/java/it/gov/pagopa/tpp/controller/TppController.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,7 @@ public interface TppController {
@GetMapping("/{tppId}/token")
Mono<ResponseEntity<TokenSectionDTO>> getTokenSection(@Valid @PathVariable String tppId);

@GetMapping("/entityId/{entityId}")
Mono<ResponseEntity<TppDTOWithoutTokenSection>> getTppByEntityId(@Valid @PathVariable String entityId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,9 @@ public Mono<ResponseEntity<TokenSectionDTO>> getTokenSection(String tppId) {
.map(ResponseEntity::ok);
}

public Mono<ResponseEntity<TppDTOWithoutTokenSection>> getTppByEntityId(String entityId) {
return tppService.getTppByEntityId(entityId)
.map(ResponseEntity::ok);
}

}
2 changes: 2 additions & 0 deletions src/main/java/it/gov/pagopa/tpp/service/TppService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ public interface TppService {

Mono<TokenSectionDTO> getTokenSection(String tppId);

Mono<TppDTOWithoutTokenSection> getTppByEntityId(String entityId);

}
17 changes: 15 additions & 2 deletions src/main/java/it/gov/pagopa/tpp/service/TppServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class TppServiceImpl implements TppService {
private final TokenSectionDTOToObjectMapper tokenSectionMapperToObject;
private final ExceptionMap exceptionMap;
private final AzureEncryptService azureEncryptService;
private static final String TPP_NOT_FOUND = "Tpp not found during get process";

public TppServiceImpl(TppRepository tppRepository, TppObjectToDTOMapper mapperToDTO, TppWithoutTokenSectionObjectToDTOMapper tppWithoutTokenSectionMapperToDTO, TokenSectionObjectToDTOMapper tokenSectionMapperToDTO,
TppDTOToObjectMapper mapperToObject, TokenSectionDTOToObjectMapper tokenSectionMapperToObject, ExceptionMap exceptionMap, AzureEncryptService azureEncryptService) {
Expand Down Expand Up @@ -185,19 +186,31 @@ public Mono<TppDTOWithoutTokenSection> getTppDetails(String tppId) {

return tppRepository.findByTppId(tppId)
.switchIfEmpty(Mono.error(exceptionMap.throwException(ExceptionName.TPP_NOT_ONBOARDED,
"Tpp not found during get process")))
TPP_NOT_FOUND)))
.map(tppWithoutTokenSectionMapperToDTO::map)
.doOnSuccess(tppDTO -> log.info("[TPP-SERVICE][GET] Found TPP with tppId: {}", tppId))
.doOnError(error -> log.error("[TPP-SERVICE][GET] Error retrieving TPP for tppId {}: {}", tppId, error.getMessage()));
}

@Override
public Mono<TppDTOWithoutTokenSection> getTppByEntityId(String entityId) {
log.info("[TPP-SERVICE][GET] Received request to get TPP for entityId: {}", inputSanify(entityId));

return tppRepository.findByEntityId(entityId)
.switchIfEmpty(Mono.error(exceptionMap.throwException(ExceptionName.TPP_NOT_ONBOARDED,
TPP_NOT_FOUND)))
.map(tppWithoutTokenSectionMapperToDTO::map)
.doOnSuccess(tppDTO -> log.info("[TPP-SERVICE][GET] Found TPP with entityId: {}", entityId))
.doOnError(error -> log.error("[TPP-SERVICE][GET] Error retrieving TPP for entityId {}: {}", entityId, error.getMessage()));
}

@Override
public Mono<TokenSectionDTO> getTokenSection(String tppId) {
log.info("[TPP-SERVICE][GET] Received request to get TokenSection for tppId: {}", inputSanify(tppId));

return tppRepository.findByTppId(tppId)
.switchIfEmpty(Mono.error(exceptionMap.throwException(ExceptionName.TPP_NOT_ONBOARDED,
"Tpp not found during get process")))
TPP_NOT_FOUND)))
.flatMap(tpp -> {
TokenSection tokenSection = tpp.getTokenSection();
keyDecrypt(tokenSection, tppId);
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/it/gov/pagopa/tpp/controller/TppControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,23 @@ void getTppDetails_Ok() {
});
}

@Test
void getTppByEntityId_Ok() {
Mockito.when(tppService.getTppByEntityId(MOCK_TPP_DTO_WITHOUT_TOKEN_SECTION.getEntityId()))
.thenReturn(Mono.just(MOCK_TPP_DTO_WITHOUT_TOKEN_SECTION));

webClient.get()
.uri("/emd/tpp/entityId/{entityId}",MOCK_TPP_DTO_WITHOUT_TOKEN_SECTION.getEntityId())
.exchange()
.expectStatus().isOk()
.expectBody(TppDTOWithoutTokenSection.class)
.consumeWith(response -> {
TppDTOWithoutTokenSection resultResponse = response.getResponseBody();
Assertions.assertNotNull(resultResponse);
Assertions.assertEquals(MOCK_TPP_DTO_WITHOUT_TOKEN_SECTION,resultResponse);
});
}

@Test
void getTokenSection_Ok() {
Mockito.when(tppService.getTokenSection("tppId"))
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/it/gov/pagopa/tpp/service/TppServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,28 @@ void getTppDetails_TppNotOnboarded() {
.verify();
}

@Test
void getTppByEntityId_Ok() {
Mockito.when(tppRepository.findByEntityId(MOCK_TPP_DTO_WITHOUT_TOKEN_SECTION.getEntityId()))
.thenReturn(Mono.just(MOCK_TPP));

StepVerifier.create(tppService.getTppByEntityId(MOCK_TPP_DTO_WITHOUT_TOKEN_SECTION.getEntityId()))
.expectNextMatches(result -> result.equals(MOCK_TPP_DTO_WITHOUT_TOKEN_SECTION))
.verifyComplete();
}

@Test
void getTppByEntityId_TppNotOnboarded() {
Mockito.when(tppRepository.findByEntityId(MOCK_TPP_DTO_WITHOUT_TOKEN_SECTION.getEntityId()))
.thenReturn(Mono.empty());

StepVerifier.create(tppService.getTppByEntityId(MOCK_TPP_DTO_WITHOUT_TOKEN_SECTION.getEntityId()))
.expectErrorMatches(throwable ->
throwable instanceof ClientExceptionWithBody &&
((ClientExceptionWithBody) throwable).getCode().equals("TPP_NOT_ONBOARDED"))
.verify();
}

@Test
void getTokenSection_Ok() {
Mockito.when(tppRepository.findByTppId(MOCK_TPP_DTO.getTppId()))
Expand Down

0 comments on commit 27cb15f

Please sign in to comment.