generated from pagopa/pagopa-functions-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[chore] Tokenizer improvements (#84)
* [chore] Improved tokenizer logic to not discard untokenized receipts * [chore] Updated unit tests * [chore] Improved exception handling * [chore] Improved exception handling * [chore] Improved java doc * [chore] Fixed Tokenizer response * [chore] Implemented tokenizer service with retry * [chore] Added retry config in env values * [chore] Improved code to remove duplications * [chore] Removed unused import * [chore] Removed static declaration * [chore] Changed retry env values
- Loading branch information
Showing
18 changed files
with
658 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../java/it/gov/pagopa/receipt/pdf/datastore/entity/receipt/enumeration/ReasonErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...n/java/it/gov/pagopa/receipt/pdf/datastore/exception/PDVTokenizerUnexpectedException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package it.gov.pagopa.receipt.pdf.datastore.exception; | ||
|
||
import lombok.Getter; | ||
|
||
/** | ||
* Thrown in case an unexpected error occur when invoking PDV Tokenizer service | ||
*/ | ||
@Getter | ||
public class PDVTokenizerUnexpectedException extends RuntimeException { | ||
|
||
/** | ||
* Constructs new exception with provided cause | ||
* | ||
* @param cause Exception causing the constructed one | ||
*/ | ||
public PDVTokenizerUnexpectedException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/it/gov/pagopa/receipt/pdf/datastore/model/tokenizer/ErrorMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package it.gov.pagopa.receipt.pdf.datastore.model.tokenizer; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* Model class for the error response of the PDV Tokenizer for status 403, 404, 429 | ||
*/ | ||
@Data | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class ErrorMessage { | ||
|
||
private String message; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 26 additions & 2 deletions
28
src/main/java/it/gov/pagopa/receipt/pdf/datastore/service/BizEventToReceiptService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,37 @@ | ||
package it.gov.pagopa.receipt.pdf.datastore.service; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import it.gov.pagopa.receipt.pdf.datastore.entity.event.BizEvent; | ||
import it.gov.pagopa.receipt.pdf.datastore.entity.receipt.EventData; | ||
import it.gov.pagopa.receipt.pdf.datastore.entity.receipt.Receipt; | ||
import it.gov.pagopa.receipt.pdf.datastore.exception.PDVTokenizerException; | ||
|
||
public interface BizEventToReceiptService { | ||
|
||
/** | ||
* Handles sending biz-events as message to queue and updates receipt's status | ||
* | ||
* @param bizEvent Biz-event from CosmosDB | ||
* @param receipt Receipt to update | ||
*/ | ||
void handleSendMessageToQueue(BizEvent bizEvent, Receipt receipt); | ||
|
||
void handleError(Receipt receipt); | ||
|
||
/** | ||
* Retrieve conditionally the transaction creation date from biz-event | ||
* | ||
* @param bizEvent Biz-event from CosmosDB | ||
* @return transaction date | ||
*/ | ||
String getTransactionCreationDate(BizEvent bizEvent); | ||
|
||
/** | ||
* Calls PDVTokenizerService to tokenize the fiscal codes for both Debtor & Payer (if present) | ||
* | ||
* @param bizEvent BizEvent where fiscalCodes are stored | ||
* @param receipt Receipt to update in case of errors | ||
* @param eventData Event data to update with tokenized fiscalCodes | ||
* @throws JsonProcessingException if an error occur when parsing input or output | ||
* @throws PDVTokenizerException if an error occur when invoking the PDV Tokenizer | ||
*/ | ||
void tokenizeFiscalCodes(BizEvent bizEvent, Receipt receipt, EventData eventData) throws JsonProcessingException, PDVTokenizerException; | ||
} |
40 changes: 40 additions & 0 deletions
40
...ain/java/it/gov/pagopa/receipt/pdf/datastore/service/PDVTokenizerServiceRetryWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package it.gov.pagopa.receipt.pdf.datastore.service; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import it.gov.pagopa.receipt.pdf.datastore.exception.PDVTokenizerException; | ||
|
||
/** | ||
* Service that wrap the {@link PDVTokenizerService} for adding retry logic for tokenizer responses with 429 status code | ||
*/ | ||
public interface PDVTokenizerServiceRetryWrapper { | ||
|
||
/** | ||
* Call {@link PDVTokenizerService#getToken(String)} with retry on failure | ||
* | ||
* @param fiscalCode the fiscal code | ||
* @return the token associated to the fiscal code | ||
* @throws JsonProcessingException if an error occur when parsing input or output | ||
* @throws PDVTokenizerException if an error occur when invoking the PDV Tokenizer | ||
*/ | ||
String getTokenWithRetry(String fiscalCode) throws JsonProcessingException, PDVTokenizerException; | ||
|
||
/** | ||
* Call {@link PDVTokenizerService#getFiscalCode(String)} with retry on failure | ||
* | ||
* @param token the token | ||
* @return the fiscal code associated to the provided token | ||
* @throws JsonProcessingException if an error occur when parsing input or output | ||
* @throws PDVTokenizerException if an error occur when invoking the PDV Tokenizer | ||
*/ | ||
String getFiscalCodeWithRetry(String token) throws PDVTokenizerException, JsonProcessingException; | ||
|
||
/** | ||
* Call {@link PDVTokenizerService#generateTokenForFiscalCode(String)} with retry on failure | ||
* | ||
* @param fiscalCode the fiscal code | ||
* @return the generated token | ||
* @throws JsonProcessingException if an error occur when parsing input or output | ||
* @throws PDVTokenizerException if an error occur when invoking the PDV Tokenizer | ||
*/ | ||
String generateTokenForFiscalCodeWithRetry(String fiscalCode) throws PDVTokenizerException, JsonProcessingException; | ||
} |
Oops, something went wrong.