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: [PAGOPA-2297] log opt #80

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
27 changes: 23 additions & 4 deletions host.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,31 @@
}
},
"logging": {
"fileLoggingMode": "always",
"fileLoggingMode": "debugOnly",
"logLevel": {
"default": "Information",
"default": "None",
"Host.Results": "Error",
"Function": "Information",
"Host.Aggregator": "Trace"
"Function.GetCart": "Information",
"Function.GetReceipt": "Information",
"Function.GetReceiptByOrganizationFiscalCodeAndIUV": "Information",
"Function.GetReceiptError": "Information",
"Function.GetReceiptMessage": "Information",
"Function.GetReceiptPdf": "Information",
"Function.ReceiptToReviewed": "Information",
"Function.RecoverFailedCart": "Information",
"Function.RecoverFailedCartMassive": "Information",
"Function.CartNotSentRecoverScheduled": "Information",
"Function.RecoverFailedReceipt": "Information",
"Function.RecoverFailedReceiptMassive": "Information",
"Function.RecoverFailedReceiptScheduled": "Information",
"Function.RecoverNotNotifiedReceipt": "Information",
"Function.RecoverNotNotifiedReceiptMassive": "Information",
"Function.RecoverNotNotifiedTimerTriggerProcessor": "Information",
"Function.RegenerateReceiptFunc": "Information",
"Microsoft": "Information",
"Worker": "Information",
"Host.Aggregator": "Error",
"Host": "Error"
},
"applicationInsights": {
"samplingSettings": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public HttpResponseMessage run (
.build();
}
cartForReceipt.setStatus(CartStatusType.SENT);
logger.info("[{}] Cart with id {} processes successfully. Cart with status: {} and receipt with status: {}",
logger.debug("[{}] Cart with id {} processes successfully. Cart with status: {} and receipt with status: {}",
context.getFunctionName(), cartForReceipt.getId(), cartForReceipt.getStatus(), receipt.getStatus());
cartForReceiptDocumentdb.setValue(cartForReceipt);
String responseMsg = String.format("Cart with id %s recovered", cartId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,7 @@ public void processRecoverNotNotifiedScheduledTrigger(
List<Receipt> receiptList = receiptMassiveRestore(ReceiptStatusType.IO_ERROR_TO_NOTIFY, receiptCosmosService);
receiptList.addAll(receiptMassiveRestore(ReceiptStatusType.GENERATED, receiptCosmosService));

if (receiptList.isEmpty()) {
alessio-acitelli marked this conversation as resolved.
Show resolved Hide resolved
logger.info("[{}] No Receipt to notify", context.getFunctionName());
}

documentReceipts.setValue(receiptList);

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private HttpResponseMessage generateAndSavePDF(HttpRequestMessage<Optional<Strin
//Verify receipt status
if (receipt.getEventData() != null) {

logger.info("[{}] Generating pdf for Receipt with id {} and bizEvent with id {}",
logger.debug("[{}] Generating pdf for Receipt with id {} and bizEvent with id {}",
context.getFunctionName(),
receipt.getId(),
bizEvent.getId());
Expand Down Expand Up @@ -330,7 +330,7 @@ private HttpResponseMessage generateAndSaveReceipt(HttpRequestMessage<Optional<S

if (totalNotice == 1) {

logger.info("[{}] function called at {} for event with id {} and status {} and isCart {}",
logger.debug("[{}] function called at {} for event with id {} and status {} and isCart {}",
context.getFunctionName(), LocalDateTime.now(), bizEvent.getId(), bizEvent.getEventStatus(), totalNotice > 1);

if (BizEventToReceiptUtils.isReceiptStatusValid(receipt)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Objects;

import org.modelmapper.ModelMapper;
import org.modelmapper.convention.MatchingStrategies;

Expand Down Expand Up @@ -63,6 +70,20 @@ public static <S, D> D map(final S source, D destination) {
modelMapper.map(source, destination);
return destination;
}

/**
* Maps file to object of defined Class
*
* @param relativePath relative file path
* @param outClass class to be mapped to
*/
public static <T> T readModelFromFile(String relativePath, Class<T> clazz) throws IOException {
ClassLoader classLoader = ObjectMapperUtils.class.getClassLoader();
File file = new File(Objects.requireNonNull(classLoader.getResource(relativePath)).getPath());
var content = Files.readString(file.toPath());
objectMapper.registerModule(new JavaTimeModule());
return objectMapper.readValue(content, clazz);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.microsoft.azure.functions.ExecutionContext;
import com.microsoft.azure.functions.HttpStatus;

import it.gov.pagopa.receipt.pdf.helpdesk.client.BizEventCosmosClient;
import it.gov.pagopa.receipt.pdf.helpdesk.client.impl.ReceiptCosmosClientImpl;
import it.gov.pagopa.receipt.pdf.helpdesk.client.impl.ReceiptQueueClientImpl;
Expand All @@ -23,6 +24,7 @@
import uk.org.webcompere.systemstubs.jupiter.SystemStub;
import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;

import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;

Expand Down Expand Up @@ -206,6 +208,18 @@ void eCommerceAndTotalNoticeTest() throws PDVTokenizerException, JsonProcessingE
assertEquals(true, result);
assertEquals(1, totalNotice);
}

@Test
void invalidBizEventPartOfPaymentCartTest() throws IOException {
environmentVariables.set("ECOMMERCE_FILTER_ENABLED", "true");

BizEvent bizEvent = ObjectMapperUtils.readModelFromFile("biz-events/bizEvent.json", BizEvent.class);

boolean result = BizEventToReceiptUtils.isBizEventInvalid(bizEvent, mock(ExecutionContext.class), logger);
Integer totalNotice = BizEventToReceiptUtils.getTotalNotice(bizEvent, mock(ExecutionContext.class), logger);
assertEquals(true, result);
assertEquals(2, totalNotice);
}

private BizEvent generateValidBizEvent(boolean withoutRemittanceInformation, boolean withTransferList) {
BizEvent item = new BizEvent();
Expand Down
112 changes: 112 additions & 0 deletions src/test/resources/biz-events/bizEvent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"id": "tst2.235987018021263550-5036-5682-6785-876-0",
"version": "2",
"complete": "true",
"missingInfo": [],
"debtorPosition": {
"modelType": "1",
"iuv": "960000000094659945"
},
"creditor": {
"idPA": "01199250158",
"idBrokerPA": "01199250158",
"idStation": "01199250158_02",
"companyName": "Comune di Milano",
"officeName": "Comune di Milano office Name"
},
"psp": {
"idPsp": "BPPNIT2PXXX",
"idBrokerPsp": "03339200374",
"idChannel": "03339200374_01",
"psp": "Worldline Merchant Services Italia S.p.A."
},
"debtor": {
"fullName": "JOHN DOE",
"entityUniqueIdentifierType": "F",
"entityUniqueIdentifierValue": "PPPPPP01P30P736P"
},
"paymentInfo": {
"paymentDateTime": "2024-10-08T07:18:29Z",
"paymentToken": "223F665500001336354",
"amount": "750.38",
"fee": "0.0",
"totalNotice": "2",
"paymentMethod": "PO",
"remittanceInformation": "pagamento"
},
"transferList": [
{
"fiscalCodePA": "01199250158",
"companyName": "Comune di Milano",
"amount": "750.38",
"transferCategory": "9/0301105TS/3/CB617RP",
"remittanceInformation": "/RFB/9600000000/TXT/CB617RP-Mag2022/Apr2023--EC Lorem-E. 261,92 (san 4,91 int 0,95)"
}
],
"transactionDetails": {
"origin": "PaymentManager",
"user": {
"fiscalCode": "PPPPPP01P30P736P",
"userId": "677676786",
"userStatus": "11",
"userStatusDescription": "REGISTERED_SPID",
"name": "JOHN",
"surname": "DOE"
},
"transaction": {
"idTransaction": "987334554",
"transactionId": "987334554",
"grandTotal": 75067,
"amount": 75038,
"fee": 29,
"transactionStatus": "Confermato",
"accountingStatus": "Contabilizzato",
"rrn": "223560110624",
"authorizationCode": "00",
"creationDate": "2024-10-08T07:18:29Z",
"numAut": "250863",
"accountCode": "0037r972892475982475842",
"psp": {
"idChannel": "05963231005_01_ONUS",
"businessName": "Worldline Merchant Services Italia S.p.A.",
"serviceName": "Pagamento con Carte"
},
"origin": "IO"
},
"wallet": {
"idWallet": "125714007",
"enableableFunctions": [
"pagoPA",
"BPD",
"FA"
],
"pagoPa": true,
"onboardingChannel": "IO",
"favourite": false,
"createDate": "2024-10-08T07:18:29Z",
"info": {
"type": "CardInfo",
"blurredNumber": "0403",
"holder": "JOHN DOE",
"expireMonth": "06",
"expireYear": "2026",
"brand": "MASTERCARD",
"hashPan": "e88aadfd9f40e1482615fd3c8c44f05c53f93aed1bcea69e82b3e5e27668f822"
}
},
"info": {
"brand": "MASTERCARD",
"brandLogo": "https://checkout.pagopa.it/assets/creditcard/mastercard.png",
"clientId": "CHECKOUT_FAKE",
"paymentMethodName": "CARDS",
"type": "CP"
}
},
"timestamp": 1728371909181,
"properties": {
"Postman-Token": "1503a131-972d-402a-aea2-d03c82ad4d79"
},
"eventStatus": "DONE",
"eventRetryEnrichmentCount": 0,
"eventTriggeredBySchedule": false
}
Loading