Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [P4PU-540] removed transcation receipt #145

Merged
merged 3 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions openapi/pagopa-arc-be.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -198,46 +198,6 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ErrorDTO'
/transactions/{transactionId}/receipt:
get:
tags:
- arc transactions
summary: "Retrieve transaction receipt from arc"
operationId: getTransactionReceipt
security:
- bearerAuth: [ ]
parameters:
- name: transactionId
in: path
description: "A unique id that identifies a transaction"
required: true
schema:
type: string
responses:
'200':
description: "Obtained PDF transaction receipt"
content:
application/pdf:
schema:
type: string
format: binary
'401':
description: "Wrong or missing function key"
'404':
description: "Transaction details not found"
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorDTO'
example:
error: "receipt_not_found_error"
error_description: "string"
'500':
description: "Internal Server Error"
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorDTO'
/notices:
get:
tags:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package it.gov.pagopa.arc.connector.bizevents;

import it.gov.pagopa.arc.connector.bizevents.dto.BizEventsTransactionsListDTO;
import org.springframework.core.io.Resource;

public interface BizEventsConnector {
BizEventsTransactionsListDTO getTransactionsList(String fiscalCode, int size);
Resource getTransactionReceipt(String fiscalCode, String transactionId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,5 @@ public BizEventsTransactionsListDTO getTransactionsList(String fiscalCode, int s
}
return bizEventsTransactionsListDTO;
}

@Override
public Resource getTransactionReceipt(String fiscalCode, String transactionId) {
Resource transactionReceipt;
try {
transactionReceipt = bizEventsRestClient.transactionReceipt(apikey, fiscalCode, transactionId);
}catch (FeignException e){
if (e.status() == HttpStatus.NOT_FOUND.value()){
throw new BizEventsReceiptNotFoundException("An error occurred handling request from biz-Events to retrieve transaction receipt with transaction id [%s] for the current user".formatted(transactionId));
}
throw new BizEventsInvocationException(ERROR_MESSAGE_INVOCATION_EXCEPTION);
}
return transactionReceipt;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import it.gov.pagopa.arc.connector.bizevents.dto.BizEventsTransactionsListDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

@FeignClient(
name = "biz-events",
Expand All @@ -22,16 +25,6 @@ BizEventsTransactionsListDTO transactionsList(
@RequestParam(value = "size", required = false, defaultValue = "10") int size
);

@GetMapping(
value = "/transactions/{event-id}/pdf")
@ResponseBody
@ResponseStatus(HttpStatus.OK)
Resource transactionReceipt(
@RequestHeader(value = "Ocp-Apim-Subscription-Key") String apikey,
@RequestHeader(value = "x-fiscal-code") String fiscalCode,
@PathVariable(value = "event-id") String transactionId
);

}


Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import it.gov.pagopa.arc.controller.generated.ArcTransactionsApi;
import it.gov.pagopa.arc.model.generated.TransactionsListDTO;
import it.gov.pagopa.arc.service.TransactionsService;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -23,10 +22,4 @@ public ResponseEntity<TransactionsListDTO> getTransactionsList(Integer page, Int
return new ResponseEntity<>(transactionsListDTO, HttpStatus.OK);
}

@Override
public ResponseEntity<Resource> getTransactionReceipt(String transactionId) {
Resource receipt = transactionsService.retrieveTransactionReceipt(transactionId);
return new ResponseEntity<>(receipt,HttpStatus.OK);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ public ResponseEntity<ErrorDTO> handleBizEventsInvocationException(RuntimeExcept
return handleArcErrorException(ex, request, HttpStatus.INTERNAL_SERVER_ERROR, ErrorDTO.ErrorEnum.GENERIC_ERROR);
}

@ExceptionHandler(BizEventsReceiptNotFoundException.class)
public ResponseEntity<ErrorDTO> handleBizEventsReceiptNotFoundException(RuntimeException ex, HttpServletRequest request){
return handleArcErrorException(ex, request, HttpStatus.NOT_FOUND, ErrorDTO.ErrorEnum.RECEIPT_NOT_FOUND_ERROR);
}
Giuseppe-LaManna marked this conversation as resolved.
Show resolved Hide resolved

@ExceptionHandler(BizEventsInvalidAmountException.class)
public ResponseEntity<ErrorDTO> handleBizEventsInvalidAmountException(RuntimeException ex, HttpServletRequest request){
return handleArcErrorException(ex, request, HttpStatus.BAD_REQUEST, ErrorDTO.ErrorEnum.INVALID_AMOUNT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@


import it.gov.pagopa.arc.model.generated.TransactionsListDTO;
import org.springframework.core.io.Resource;

public interface TransactionsService {
TransactionsListDTO retrieveTransactionsList(Integer page, Integer size, String filter);
Resource retrieveTransactionReceipt(String transactionId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,5 @@ public TransactionsListDTO retrieveTransactionsList(Integer page, Integer size,
return bizEventsService.retrieveTransactionsListFromBizEvents(page,size,filter);
}

@Override
public Resource retrieveTransactionReceipt(String transactionId) {
log.info("[GET_TRANSACTION_RECEIPT] The current user has requested to retrieve transaction receipt for transaction with ID {}", transactionId);
return bizEventsService.retrieveTransactionReceiptFromBizEvents(transactionId);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

public interface BizEventsService {
TransactionsListDTO retrieveTransactionsListFromBizEvents(Integer page, Integer size, String filter);
Resource retrieveTransactionReceiptFromBizEvents(String transactionId);
NoticesListResponseDTO retrievePaidListFromBizEvents(String userFiscalCode, NoticeRequestDTO noticeRequestDTO);
NoticeDetailsDTO retrievePaidNoticeDetailsFromBizEvents(String userId, String userFiscalCode, String eventId);
Resource retrievePaidNoticeReceiptFromBizEvents(String userId, String userFiscalCode, String eventId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,6 @@ public TransactionsListDTO retrieveTransactionsListFromBizEvents(Integer page, I
}
return transactionsListDTOMapper.apply(transactions, size);
}

@Override
public Resource retrieveTransactionReceiptFromBizEvents(String transactionId) {
String retrievedUserFiscalCode = SecurityUtils.getUserFiscalCode();
return bizEventsConnector.getTransactionReceipt(retrievedUserFiscalCode, transactionId);
}

@Override
public NoticesListResponseDTO retrievePaidListFromBizEvents(String userFiscalCode, NoticeRequestDTO noticeRequestDTO) {
return bizEventsPaidNoticeConnector.getPaidNoticeList(userFiscalCode, noticeRequestDTO);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
package it.gov.pagopa.arc.connector.bizevents;

import static it.gov.pagopa.arc.config.WireMockConfig.WIREMOCK_TEST_PROP2BASEPATH_MAP_PREFIX;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import ch.qos.logback.classic.LoggerContext;
import it.gov.pagopa.arc.config.FeignConfig;
import it.gov.pagopa.arc.config.WireMockConfig;
import it.gov.pagopa.arc.connector.bizevents.dto.BizEventsTransactionsListDTO;
import it.gov.pagopa.arc.exception.custom.BizEventsInvocationException;
import it.gov.pagopa.arc.exception.custom.BizEventsReceiptNotFoundException;
import it.gov.pagopa.arc.utils.MemoryAppender;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -25,7 +19,6 @@
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
import org.springframework.core.io.Resource;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;

Expand Down Expand Up @@ -99,36 +92,4 @@ void givenHeaderAndParameterWhenErrorThenThrowBizEventsInvocationException() {

}

@Test
void givenTransactionIdWhenCallBizEventsConnectorThenReturnTransactionReceipt() throws IOException {
//given
//when
Resource transactionReceipt = bizEventsConnector.getTransactionReceipt("DUMMY_FISCAL_CODE_RECEIPT", "TRANSACTION_ID_RECEIPT_OK_1");

//then
Assertions.assertNotNull(transactionReceipt);
Assertions.assertTrue(transactionReceipt.exists());
byte[] expectedContent = Files.readAllBytes(Paths.get("src/test/resources/stub/__files/testReceiptPdfFile.pdf"));
byte[] actualContent = transactionReceipt.getInputStream().readAllBytes();
assertArrayEquals(expectedContent, actualContent);
}

@Test
void givenTransactionIdWhenReceiptNotFoundThenReturnException() {
//given
//when
BizEventsReceiptNotFoundException bizEventsReceiptNotFoundException = assertThrows(BizEventsReceiptNotFoundException.class,
() -> bizEventsConnector.getTransactionReceipt("DUMMY_FISCAL_CODE_RECEIPT_NOT_FOUND", "TRANSACTION_ID_RECEIPT_NOT_FOUND_1"));
Assertions.assertEquals("An error occurred handling request from biz-Events to retrieve transaction receipt with transaction id [TRANSACTION_ID_RECEIPT_NOT_FOUND_1] for the current user", bizEventsReceiptNotFoundException.getMessage());
}

@Test
void givenTransactionIdWhenReceiptErrorThenThrowBizEventsInvocationException() {
//When
//Then
BizEventsInvocationException bizEventsInvocationException = assertThrows(BizEventsInvocationException.class,
() -> bizEventsConnector.getTransactionReceipt("DUMMY_FISCAL_CODE_RECEIPT_ERROR", "TRANSACTION_ID_RECEIPT_ERROR_1"));
Assertions.assertEquals("An error occurred handling request from biz-Events", bizEventsInvocationException.getMessage());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import it.gov.pagopa.arc.security.JwtAuthenticationFilter;
import it.gov.pagopa.arc.service.TransactionsService;
import it.gov.pagopa.arc.utils.TestUtils;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
Expand All @@ -22,8 +20,6 @@
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;

Expand All @@ -36,8 +32,6 @@ class TransactionsControllerTest {
private static final int PAGE = 1;
private static final int SIZE = 2;
private static final String FILTER = "DUMMY_FILTER";
private static final String TRANSACTION_ID = "TRANSACTION_ID";

@Autowired
private ObjectMapper objectMapper;
@Autowired
Expand Down Expand Up @@ -69,26 +63,4 @@ void givenFiscalCodeWhenCallGetTransactionsListThenReturnTransactionList() throw
Assertions.assertEquals(transactionsListDTO,resultResponse);
Mockito.verify(transactionsServiceMock).retrieveTransactionsList(anyInt(),anyInt(),anyString());
}

@Test
void givenTransactionIdWhenCallGetTransactionReceiptThenReturnTransactionReceipt() throws Exception {
//Given
Resource receipt = new FileSystemResource("src/test/resources/stub/__files/testReceiptPdfFile.pdf");

Mockito.when(transactionsServiceMock.retrieveTransactionReceipt(TRANSACTION_ID)).thenReturn(receipt);

//When
MvcResult result = mockMvc.perform(
get("/transactions/{transactionId}/receipt", TRANSACTION_ID)
).andExpect(status().is2xxSuccessful())
.andReturn();

//Then
byte[] expectedContent = Files.readAllBytes(Paths.get("src/test/resources/stub/__files/testReceiptPdfFile.pdf"));
byte[] actualContent = result.getResponse().getContentAsByteArray();

Assertions.assertNotNull(actualContent);
Assertions.assertArrayEquals(expectedContent, actualContent);
Mockito.verify(transactionsServiceMock).retrieveTransactionReceipt(anyString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ class ArcExceptionHandlerTest {

@SpyBean
private TestController testControllerSpy;

private static final String TRANSACTION_ID = "TRANSACTION_ID";
private static final String EVENT_ID = "EVENT_ID";
private MemoryAppender memoryAppender;

Expand All @@ -50,13 +48,12 @@ static class TestController {

@GetMapping("/test")
void testEndpoint() {
//Needed for testing notice API
}

@GetMapping("/test/{Id}")
void testEndpointDetails() {
}
@GetMapping("/test/{transactionId}/pdf")
void testEndpointPdf() {
//Needed for testing notice API
}
}

Expand Down Expand Up @@ -118,22 +115,6 @@ void givenRequestWhenBizEventsServiceReturnInvalidDateThenHandleBizEventsInvalid
Assertions.assertTrue(memoryAppender.getLoggedEvents().get(0).getFormattedMessage().contains("A class it.gov.pagopa.arc.exception.custom.BizEventsInvalidDateException occurred handling request GET /test: HttpStatus 400 - Error"));
}

@Test
void givenRequestWhenBizEventsServiceReturnNotFoundErrorThenHandleBizEventsNotFoundExceptionPdfError() throws Exception {
doThrow(new BizEventsReceiptNotFoundException("Error")).when(testControllerSpy).testEndpointPdf();

mockMvc.perform(MockMvcRequestBuilders.get("/test/{transactionId}/pdf", TRANSACTION_ID)
.param(DATA, DATA)
.header(HEADER,HEADER)
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isNotFound())
.andExpect(MockMvcResultMatchers.jsonPath("$.error").value("receipt_not_found_error"))
.andExpect(MockMvcResultMatchers.jsonPath("$.error_description").value("Error"));

Assertions.assertTrue(memoryAppender.getLoggedEvents().get(0).getFormattedMessage().contains("A class it.gov.pagopa.arc.exception.custom.BizEventsReceiptNotFoundException occurred handling request GET /test/TRANSACTION_ID/pdf: HttpStatus 404 - Error"));
}

@Test
void givenRequestWhenPullPaymentReturnBadRequestErrorThenHandlePullPaymentInvalidRequestException() throws Exception {
doThrow(new PullPaymentInvalidRequestException("Error")).when(testControllerSpy).testEndpoint();
Expand Down
Loading
Loading