diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/ReceiptToIO.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/ReceiptToIO.java index 6c36356..28a1ed9 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/ReceiptToIO.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/ReceiptToIO.java @@ -1,23 +1,24 @@ package it.gov.pagopa.receipt.pdf.notifier; -import com.fasterxml.jackson.core.JsonProcessingException; import com.microsoft.azure.functions.ExecutionContext; import com.microsoft.azure.functions.OutputBinding; -import com.microsoft.azure.functions.annotation.*; +import com.microsoft.azure.functions.annotation.CosmosDBOutput; +import com.microsoft.azure.functions.annotation.CosmosDBTrigger; +import com.microsoft.azure.functions.annotation.FunctionName; import it.gov.pagopa.receipt.pdf.notifier.entity.message.IOMessage; -import it.gov.pagopa.receipt.pdf.notifier.entity.receipt.ReasonError; import it.gov.pagopa.receipt.pdf.notifier.entity.receipt.Receipt; import it.gov.pagopa.receipt.pdf.notifier.entity.receipt.enumeration.ReceiptStatusType; import it.gov.pagopa.receipt.pdf.notifier.model.enumeration.UserNotifyStatus; import it.gov.pagopa.receipt.pdf.notifier.model.enumeration.UserType; import it.gov.pagopa.receipt.pdf.notifier.service.ReceiptToIOService; import it.gov.pagopa.receipt.pdf.notifier.service.impl.ReceiptToIOServiceImpl; -import it.gov.pagopa.receipt.pdf.notifier.utils.ReceiptToIOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.time.LocalDateTime; -import java.util.*; +import java.util.ArrayList; +import java.util.EnumMap; +import java.util.List; import java.util.concurrent.atomic.AtomicInteger; /** @@ -86,7 +87,7 @@ public void processReceiptToIO( connectionStringSetting = "COSMOS_RECEIPTS_CONN_STRING") OutputBinding> documentMessages, final ExecutionContext context - ) throws JsonProcessingException { + ) { logger.info("[{}] function called at {}", context.getFunctionName(), LocalDateTime.now()); AtomicInteger discarder = new AtomicInteger(); @@ -120,14 +121,7 @@ public void processReceiptToIO( usersToBeVerified.put(UserType.PAYER, payerNotifyStatus); } - boolean boolQueueSent = false; - try { - boolQueueSent = this.receiptToIOService.verifyMessagesNotification(usersToBeVerified, messagesNotified, receipt); - } catch (JsonProcessingException e) { - receipt.setStatus(ReceiptStatusType.IO_ERROR_TO_NOTIFY); - int code = ReceiptToIOUtils.getCodeOrDefault(e); - ReceiptToIOUtils.buildReasonError(e.getMessage(), code); - } + boolean boolQueueSent = this.receiptToIOService.verifyMessagesNotification(usersToBeVerified, messagesNotified, receipt); if(boolQueueSent){ queueSent.getAndIncrement(); diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/client/IOClient.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/client/IOClient.java new file mode 100644 index 0000000..4b43a64 --- /dev/null +++ b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/client/IOClient.java @@ -0,0 +1,39 @@ +package it.gov.pagopa.receipt.pdf.notifier.client; + +import it.gov.pagopa.receipt.pdf.notifier.exception.IOAPIException; +import it.gov.pagopa.receipt.pdf.notifier.model.io.IOProfilePayload; +import it.gov.pagopa.receipt.pdf.notifier.model.io.message.MessagePayload; + +import java.net.http.HttpResponse; + +/** + * Client for invoking IO APIs + */ +public interface IOClient { + + /** + * Get a User Profile. + *

+ * Returns the preferences for the user identified by the fiscal code provided in the request body. + * The field `sender_allowed` is set fo `false` in case the service which is calling the API has been disabled by the user. + * + * @param fiscalCodePayload the {@link IOProfilePayload} serialized as String + * @return the {@link HttpResponse} of the IO API + * @throws IOAPIException If fail to call the API + */ + HttpResponse getProfile(String fiscalCodePayload) throws IOAPIException; + + /** + * Submit a Message passing the user fiscal_code in the request body + *

+ * Submits a message to a user with STANDARD or ADVANCED features based on `feature_level_type` value. + * On error, the reason is returned in the response payload. In order to call `submitMessageforUser`, + * before sending any message, the sender MUST call `getProfile` and check that the profile exists + * (for the specified fiscal code) and that the `sender_allowed` field of the user's profile it set to `true`. + * + * @param messagePayload the {@link MessagePayload} serialized as String + * @return the {@link HttpResponse} of the IO API + * @throws IOAPIException If fail to call the API + */ + HttpResponse submitMessage(String messagePayload) throws IOAPIException; +} diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/client/impl/IOClientImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/client/impl/IOClientImpl.java new file mode 100644 index 0000000..e0b9670 --- /dev/null +++ b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/client/impl/IOClientImpl.java @@ -0,0 +1,99 @@ +package it.gov.pagopa.receipt.pdf.notifier.client.impl; + +import it.gov.pagopa.receipt.pdf.notifier.client.IOClient; +import it.gov.pagopa.receipt.pdf.notifier.exception.IOAPIException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; + +/** + * {@inheritDoc} + */ +public class IOClientImpl implements IOClient { + + private final Logger logger = LoggerFactory.getLogger(IOClientImpl.class); + + private static final String IO_API_BASE_PATH = System.getenv().getOrDefault("IO_API_BASE_PATH", "https://api.uat.platform.pagopa.it/mock-io/api/v1"); + private static final String IO_API_PROFILES_PATH = System.getenv().getOrDefault("IO_API_PROFILES_PATH", "/profiles"); + private static final String IO_API_MESSAGES_PATH = System.getenv().getOrDefault("IO_API_MESSAGES_PATH", "/messages"); + private static final String OCP_APIM_SUBSCRIPTION_KEY = System.getenv().getOrDefault("OCP_APIM_SUBSCRIPTION_KEY", ""); + private static final String OCP_APIM_HEADER_KEY = System.getenv().getOrDefault("OCP_APIM_HEADER_KEY", "Ocp-Apim-Subscription-Key"); + + private static final String CONTENT_TYPE_JSON = "application/json"; + private static final int IO_API_IO_ERROR = 800; + private static final int IO_API_UNEXPECTED_ERROR = 801; + + private final HttpClient client; + + private static IOClient instance = null; + + public static IOClient getInstance() { + if (instance == null) { + instance = new IOClientImpl(); + } + return instance; + } + + private IOClientImpl() { + this.client = HttpClient.newBuilder() + .version(HttpClient.Version.HTTP_2) + .build(); + } + + IOClientImpl(HttpClient client) { + this.client = client; + } + + /** + * {@inheritDoc} + */ + @Override + public HttpResponse getProfile(String fiscalCodePayload) throws IOAPIException { + String uri = String.format("%s%s", IO_API_BASE_PATH, IO_API_PROFILES_PATH); + + HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create(uri)) + .version(HttpClient.Version.HTTP_2) + .header("Content-Type", CONTENT_TYPE_JSON) + .header(OCP_APIM_HEADER_KEY, OCP_APIM_SUBSCRIPTION_KEY) + .POST(HttpRequest.BodyPublishers.ofString(fiscalCodePayload)) + .build(); + + return makeCall(request); + } + + /** + * {@inheritDoc} + */ + @Override + public HttpResponse submitMessage(String messagePayload) throws IOAPIException { + String uri = String.format("%s%s", IO_API_BASE_PATH, IO_API_MESSAGES_PATH); + + HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create(uri)) + .version(HttpClient.Version.HTTP_2) + .header("Content-Type", CONTENT_TYPE_JSON) + .header(OCP_APIM_HEADER_KEY, OCP_APIM_SUBSCRIPTION_KEY) + .POST(HttpRequest.BodyPublishers.ofString(messagePayload)) + .build(); + + return makeCall(request); + } + + private HttpResponse makeCall(HttpRequest request) throws IOAPIException { + try { + return client.send(request, HttpResponse.BodyHandlers.ofString()); + } catch (IOException e) { + throw new IOAPIException("I/O error when invoking IO API", IO_API_IO_ERROR, e); + } catch (InterruptedException e) { + logger.warn("This thread was interrupted, restoring the state"); + Thread.currentThread().interrupt(); + throw new IOAPIException("Unexpected error when invoking IO API, the thread was interrupted", IO_API_UNEXPECTED_ERROR, e); + } + } +} diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/exception/IOAPIException.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/exception/IOAPIException.java new file mode 100644 index 0000000..efa8036 --- /dev/null +++ b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/exception/IOAPIException.java @@ -0,0 +1,35 @@ +package it.gov.pagopa.receipt.pdf.notifier.exception; + +import lombok.Getter; + +/** + * Thrown in case an error occur when invoking IO APIs + */ +@Getter +public class IOAPIException extends Exception { + + private final int statusCode; + + /** + * Constructs new exception with provided message + * + * @param message Detail message + * @param statusCode status code + */ + public IOAPIException(String message, int statusCode) { + super(message); + this.statusCode = statusCode; + } + + /** + * Constructs new exception with provided message + * + * @param message Detail message + * @param statusCode status code + * @param cause Exception causing the constructed one + */ + public IOAPIException(String message, int statusCode, Throwable cause) { + super(message, cause); + this.statusCode = statusCode; + } +} diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/ApiCallback.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/ApiCallback.java deleted file mode 100644 index 2de5a0f..0000000 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/ApiCallback.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * IO API for Public Administration Services - * # Warning **This is an experimental API that is (most probably) going to change as we evolve the IO platform.** # Introduction This is the documentation of the IO API for 3rd party services. This API enables Public Administration services to integrate with the IO platform. IO enables services to communicate with Italian citizens via the [IO app](https://io.italia.it/). # How to get an API key To get access to this API, you'll need to register on the [IO Developer Portal](https://developer.io.italia.it/). After the registration step, you have to click on the button that says `subscribe to the digital citizenship api` to receive the API key that you will use to authenticate the API calls. You will also receive an email with further instructions, including a fake Fiscal Code that you will be able to use to send test messages. Messages sent to the fake Fiscal Code will be notified to the email address used during the registration process on the developer portal. # Messages ## What is a message Messages are the primary form of communication enabled by the IO APIs. Messages are **personal** communications directed to a **specific citizen**. You will not be able to use this API to broadcast a message to a group of citizens, you will have to create and send a specific, personalized message to each citizen you want to communicate to. The recipient of the message (i.e. a citizen) is identified trough his [Fiscal Code](https://it.wikipedia.org/wiki/Codice_fiscale). ## Message format A message is conceptually very similar to an email and, in its simplest form, is composed of the following attributes: * A required `subject`: a short description of the topic. * A required `markdown` body: a Markdown representation of the body (see below on what Markdown tags are allowed). * An optional `payment_data`: in case the message is a payment request, the _payment data_ will enable the recipient to pay the requested amount via [PagoPA](https://www.agid.gov.it/it/piattaforme/pagopa). * An optional `due_date`: a _due date_ that let the recipient add a reminder when receiving the message. The format for all dates is [ISO8601](https://it.wikipedia.org/wiki/ISO_8601) with time information and UTC timezone (ie. \"2018-10-13T00:00:00.000Z\"). * An optional `feature_level_type`: the kind of the submitted message. It can be: - `STANDARD` for normal messages; - `ADVANCED` to enable premium features. Default is `STANDARD`. ## Allowed Markdown formatting Not all Markdown formatting is currently available. Currently you can use the following formatting: * Headings * Text stylings (bold, italic, etc...) * Lists (bullet and numbered) ## Sending a message to a citizen Not every citizen will be interested in what you have to say and not every citizen you want to communicate to will be registered on IO. For this reason, before sending a message you need to check whether the recipient is registered on the platform and that he has not yet opted out from receiving messages from you. The process for sending a message is made of 3 steps: 1. Call [getProfile](#operation/getProfile): if the profile does not exist (i.e. you get a 404 response) or if the recipient has opted-out from your service (the response contains `sender_allowed: false`), you cannot send the message and you must stop here. 1. Call [submitMessageforUser](#operation/submitMessageforUser) to submit a new message. 1. (optional) Call [getMessage](#operation/getMessage) to check whether the message has been notified to the recipient. - * - * The version of the OpenAPI document: 3.30.3 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -package it.gov.pagopa.receipt.pdf.notifier.generated.client; - -import java.util.Map; -import java.util.List; - -/** - * Callback for asynchronous API call. - * - * @param The return type - */ -public interface ApiCallback { - /** - * This is called when the API call fails. - * - * @param e The exception causing the failure - * @param statusCode Status code of the response if available, otherwise it would be 0 - * @param responseHeaders Headers of the response if available, otherwise it would be null - */ - void onFailure(ApiException e, int statusCode, Map> responseHeaders); - - /** - * This is called when the API call succeeded. - * - * @param result The result deserialized from response - * @param statusCode Status code of the response - * @param responseHeaders Headers of the response - */ - void onSuccess(T result, int statusCode, Map> responseHeaders); - - /** - * This is called when the API upload processing. - * - * @param bytesWritten bytes Written - * @param contentLength content length of request body - * @param done write end - */ - void onUploadProgress(long bytesWritten, long contentLength, boolean done); - - /** - * This is called when the API download processing. - * - * @param bytesRead bytes Read - * @param contentLength content length of the response - * @param done Read end - */ - void onDownloadProgress(long bytesRead, long contentLength, boolean done); -} diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/ApiClient.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/ApiClient.java deleted file mode 100644 index f9d4859..0000000 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/ApiClient.java +++ /dev/null @@ -1,452 +0,0 @@ -/* - * IO API for Public Administration Services - * # Warning **This is an experimental API that is (most probably) going to change as we evolve the IO platform.** # Introduction This is the documentation of the IO API for 3rd party services. This API enables Public Administration services to integrate with the IO platform. IO enables services to communicate with Italian citizens via the [IO app](https://io.italia.it/). # How to get an API key To get access to this API, you'll need to register on the [IO Developer Portal](https://developer.io.italia.it/). After the registration step, you have to click on the button that says `subscribe to the digital citizenship api` to receive the API key that you will use to authenticate the API calls. You will also receive an email with further instructions, including a fake Fiscal Code that you will be able to use to send test messages. Messages sent to the fake Fiscal Code will be notified to the email address used during the registration process on the developer portal. # Messages ## What is a message Messages are the primary form of communication enabled by the IO APIs. Messages are **personal** communications directed to a **specific citizen**. You will not be able to use this API to broadcast a message to a group of citizens, you will have to create and send a specific, personalized message to each citizen you want to communicate to. The recipient of the message (i.e. a citizen) is identified trough his [Fiscal Code](https://it.wikipedia.org/wiki/Codice_fiscale). ## Message format A message is conceptually very similar to an email and, in its simplest form, is composed of the following attributes: * A required `subject`: a short description of the topic. * A required `markdown` body: a Markdown representation of the body (see below on what Markdown tags are allowed). * An optional `payment_data`: in case the message is a payment request, the _payment data_ will enable the recipient to pay the requested amount via [PagoPA](https://www.agid.gov.it/it/piattaforme/pagopa). * An optional `due_date`: a _due date_ that let the recipient add a reminder when receiving the message. The format for all dates is [ISO8601](https://it.wikipedia.org/wiki/ISO_8601) with time information and UTC timezone (ie. \"2018-10-13T00:00:00.000Z\"). * An optional `feature_level_type`: the kind of the submitted message. It can be: - `STANDARD` for normal messages; - `ADVANCED` to enable premium features. Default is `STANDARD`. ## Allowed Markdown formatting Not all Markdown formatting is currently available. Currently you can use the following formatting: * Headings * Text stylings (bold, italic, etc...) * Lists (bullet and numbered) ## Sending a message to a citizen Not every citizen will be interested in what you have to say and not every citizen you want to communicate to will be registered on IO. For this reason, before sending a message you need to check whether the recipient is registered on the platform and that he has not yet opted out from receiving messages from you. The process for sending a message is made of 3 steps: 1. Call [getProfile](#operation/getProfile): if the profile does not exist (i.e. you get a 404 response) or if the recipient has opted-out from your service (the response contains `sender_allowed: false`), you cannot send the message and you must stop here. 1. Call [submitMessageforUser](#operation/submitMessageforUser) to submit a new message. 1. (optional) Call [getMessage](#operation/getMessage) to check whether the message has been notified to the recipient. - * - * The version of the OpenAPI document: 3.30.3 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -package it.gov.pagopa.receipt.pdf.notifier.generated.client; - -import okhttp3.*; -import okhttp3.internal.http.HttpMethod; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.Type; -import java.time.LocalDate; -import java.time.OffsetDateTime; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; - -/** - *

ApiClient class.

- */ -public class ApiClient { - - private final Map defaultHeaderMap = new HashMap<>(); - - private OkHttpClient httpClient; - - /** - * Basic constructor for ApiClient - */ - public ApiClient() { - init(); - initHttpClient(); - } - - private void initHttpClient() { - OkHttpClient.Builder builder = new OkHttpClient.Builder(); - builder.addNetworkInterceptor(getProgressInterceptor()); - - httpClient = builder.build(); - } - - private void init() { - // Set default User-Agent. - setUserAgent("OpenAPI-Generator/3.30.3/java"); - } - - /** - * Set the User-Agent header's value (by adding to the default header map). - * - * @param userAgent HTTP request's user agent - */ - public void setUserAgent(String userAgent) { - addDefaultHeader("User-Agent", userAgent); - } - - /** - * Add a default header. - * - * @param key The header's key - * @param value The header's value - */ - public void addDefaultHeader(String key, String value) { - defaultHeaderMap.put(key, value); - } - - /** - * Format the given parameter object into string. - * - * @param param Parameter - * @return String representation of the parameter - */ - @SuppressWarnings("rawtypes") - public String parameterToString(Object param) { - if (param == null) { - return ""; - } else if (param instanceof Date || param instanceof OffsetDateTime || param instanceof LocalDate) { - //Serialize to json string and remove the " enclosing characters - String jsonStr = JSON.serialize(param); - return jsonStr.substring(1, jsonStr.length() - 1); - } else if (param instanceof Collection) { - StringBuilder b = new StringBuilder(); - for (Object o : (Collection) param) { - if (b.length() > 0) { - b.append(","); - } - b.append(o); - } - return b.toString(); - } else { - return String.valueOf(param); - } - } - - /** - * Check if the given MIME is a JSON MIME. - * JSON MIME examples: - * application/json - * application/json; charset=UTF8 - * APPLICATION/JSON - * application/vnd.company+json - * "* / *" is also default to JSON - * - * @param mime MIME (Multipurpose Internet Mail Extensions) - * @return True if the given MIME is JSON, false otherwise. - */ - public boolean isJsonMime(String mime) { - String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$"; - return mime != null && (mime.matches(jsonMime) || mime.equals("*/*")); - } - - /** - * Select the Accept header's value from the given accepts array: - * if JSON exists in the given array, use it; - * otherwise use all of them (joining into a string) - * - * @param accepts The accepts array to select from - * @return The Accept header to use. If the given array is empty, - * null will be returned (not to set the Accept header explicitly). - */ - public String selectHeaderAccept(String[] accepts) { - if (accepts.length == 0) { - return null; - } - for (String accept : accepts) { - if (isJsonMime(accept)) { - return accept; - } - } - return StringUtil.join(accepts, ","); - } - - /** - * Select the Content-Type header's value from the given array: - * if JSON exists in the given array, use it; - * otherwise use the first one of the array. - * - * @param contentTypes The Content-Type array to select from - * @return The Content-Type header to use. If the given array is empty, - * returns null. If it matches "any", JSON will be used. - */ - public String selectHeaderContentType(String[] contentTypes) { - if (contentTypes.length == 0) { - return null; - } - - if (contentTypes[0].equals("*/*")) { - return "application/json"; - } - - for (String contentType : contentTypes) { - if (isJsonMime(contentType)) { - return contentType; - } - } - - return contentTypes[0]; - } - - /** - * Deserialize response body to Java object, according to the return type and - * the Content-Type response header. - * - * @param Type - * @param response HTTP response - * @param returnType The type of the Java object - * @return The deserialized Java object - * @throws ApiException If fail to deserialize response body, i.e. cannot read response body - * or the Content-Type of the response is not supported. - */ - @SuppressWarnings("unchecked") - public T deserialize(Response response, Type returnType) throws ApiException { - if (response == null || returnType == null) { - return null; - } - - if ("byte[]".equals(returnType.toString())) { - // Handle binary response (byte array). - try { - if (response.body() == null) throw new AssertionError(); - return (T) response.body().bytes(); - } catch (IOException e) { - throw new ApiException(e); - } - } - - String respBody; - respBody = getString(response); - - if (respBody == null || "".equals(respBody)) { - return null; - } - - String contentType = response.headers().get("Content-Type"); - if (contentType == null) { - // ensuring a default content type - contentType = "application/json"; - } - if (isJsonMime(contentType)) { - return JSON.deserialize(respBody, returnType); - } else if (returnType.equals(String.class)) { - // Expecting string, return the raw response body. - return (T) respBody; - } else { - throw new ApiException( - "Content type \"" + contentType + "\" is not supported for type: " + returnType, - response.code(), - response.headers().toMultimap(), - respBody); - } - } - - @Nullable - private static String getString(Response response) throws ApiException { - String respBody; - try { - if (response.body() != null) - respBody = response.body().string(); - else - respBody = null; - } catch (IOException e) { - throw new ApiException(e); - } - return respBody; - } - - /** - * Serialize the given Java object into request body according to the object's - * class and the request Content-Type. - * - * @param obj The Java object - * @param contentType The request Content-Type - * @return The serialized request body - * @throws ApiException If fail to serialize the given object - */ - public RequestBody serialize(Object obj, String contentType) throws ApiException { - if (obj instanceof byte[]) { - // Binary (byte array) body parameter support. - return RequestBody.create((byte[]) obj, MediaType.parse(contentType)); - } else if (obj instanceof File) { - // File body parameter support. - return RequestBody.create((File) obj, MediaType.parse(contentType)); - } else if ("text/plain".equals(contentType) && obj instanceof String) { - return RequestBody.create((String) obj, MediaType.parse(contentType)); - } else if (isJsonMime(contentType)) { - String content; - if (obj != null) { - content = JSON.serialize(obj); - } else { - content = null; - } - assert content != null; - return RequestBody.create(content, MediaType.parse(contentType)); - } else if (obj instanceof String) { - return RequestBody.create((String) obj, MediaType.parse(contentType)); - } else { - throw new ApiException("Content type \"" + contentType + "\" is not supported"); - } - } - - /** - * Execute HTTP call and deserialize the HTTP response body into the given return type. - * - * @param returnType The return type used to deserialize HTTP response body - * @param The return type corresponding to (same with) returnType - * @param call Call - * @return ApiResponse object containing response status, headers and - * data, which is a Java object deserialized from response body and would be null - * when returnType is null. - * @throws ApiException If fail to execute the call - */ - public ApiResponse execute(Call call, Type returnType) throws ApiException { - try { - Response response = call.execute(); - T data = handleResponse(response, returnType); - return new ApiResponse<>(response.code(), response.headers().toMultimap(), data); - } catch (IOException e) { - throw new ApiException(e); - } - } - - /** - * Handle the given response, return the deserialized object when the response is successful. - * - * @param Type - * @param response Response - * @param returnType Return type - * @return Type - * @throws ApiException If the response has an unsuccessful status code or - * fail to deserialize the response body - */ - public T handleResponse(Response response, Type returnType) throws ApiException { - if (response.isSuccessful()) { - if (returnType == null || response.code() == 204) { - // returning null if the returnType is not defined, - // or the status code is 204 (No Content) - if (response.body() != null) { - try { - response.body().close(); - } catch (Exception e) { - throw new ApiException(response.message(), e, response.code(), response.headers().toMultimap()); - } - } - return null; - } else { - return deserialize(response, returnType); - } - } - - handleErrorResponse(response); - - return null; - } - - private static void handleErrorResponse(Response response) throws ApiException { - String respBody = null; - if (response.body() != null) { - try { - respBody = response.body().string(); - } catch (IOException e) { - throw new ApiException(response.message(), e, response.code(), response.headers().toMultimap()); - } - } - throw new ApiException(response.message(), response.code(), response.headers().toMultimap(), respBody); - } - - /** - * Build HTTP call with the given options. - * - * @param baseUrl The base URL - * @param path The sub-path of the HTTP URL - * @param method The request method, one of "GET", "HEAD", "OPTIONS", "POST", "PUT", "PATCH" and "DELETE" - * @param body The request body object - * @param headerParams The header parameters - * @return The HTTP call - * @throws ApiException If fail to serialize the request body object - */ - public Call buildCall(String baseUrl, String path, String method, Object body, Map headerParams) throws ApiException { - Request request = buildRequest(baseUrl, path, method, body, headerParams); - - return httpClient.newCall(request); - } - - /** - * Build an HTTP request with the given options. - * - * @param baseUrl The base URL - * @param path The sub-path of the HTTP URL - * @param method The request method, one of "GET", "HEAD", "OPTIONS", "POST", "PUT", "PATCH" and "DELETE" - * @param body The request body object - * @param headerParams The header parameters - * @return The HTTP request - * @throws ApiException If fail to serialize the request body object - */ - public Request buildRequest(String baseUrl, String path, String method, Object body, Map headerParams) throws ApiException { - - final String url = buildUrl(baseUrl, path); - - // prepare HTTP request body - RequestBody reqBody; - String contentType = headerParams.get("Content-Type"); - - if (!HttpMethod.permitsRequestBody(method)) { - reqBody = null; - } else if (body == null) { - if ("DELETE".equals(method)) { - // allow calling DELETE without sending a request body - reqBody = null; - } else { - // use an empty request body (for POST, PUT and PATCH) - reqBody = RequestBody.create("", contentType == null ? null : MediaType.parse(contentType)); - } - } else { - reqBody = serialize(body, contentType); - } - - final Request.Builder reqBuilder = new Request.Builder().url(url); - processHeaderParams(headerParams, reqBuilder); - - return reqBuilder.method(method, reqBody).build(); - } - - /** - * Build full URL by concatenating base path, the given sub path and query parameters. - * - * @param baseUrl The base URL - * @param path The sub path - * @return The full URL - */ - public String buildUrl(String baseUrl, String path) { - final StringBuilder url = new StringBuilder(); - - if (baseUrl != null) { - url.append(baseUrl).append(path); - } - - return url.toString(); - } - - /** - * Set header parameters to the request builder, including default headers. - * - * @param headerParams Header parameters in the form of Map - * @param reqBuilder Request.Builder - */ - public void processHeaderParams(Map headerParams, Request.Builder reqBuilder) { - for (Entry param : headerParams.entrySet()) { - reqBuilder.header(param.getKey(), parameterToString(param.getValue())); - } - for (Entry header : defaultHeaderMap.entrySet()) { - if (!headerParams.containsKey(header.getKey())) { - reqBuilder.header(header.getKey(), parameterToString(header.getValue())); - } - } - } - - /** - * Get network interceptor to add it to the httpClient to track download progress for - * async requests. - */ - @SuppressWarnings("rawtypes") - private Interceptor getProgressInterceptor() { - return new Interceptor() { - @NotNull - @Override - public Response intercept(@NotNull Interceptor.Chain chain) throws IOException { - final Request request = chain.request(); - final Response originalResponse = chain.proceed(request); - if (request.tag() instanceof ApiCallback) { - final ApiCallback callback = (ApiCallback) request.tag(); - return originalResponse.newBuilder() - .body(new ProgressResponseBody(originalResponse.body(), callback)) - .build(); - } - return originalResponse; - } - }; - } -} diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/ApiException.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/ApiException.java deleted file mode 100644 index 62752c1..0000000 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/ApiException.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * IO API for Public Administration Services - * # Warning **This is an experimental API that is (most probably) going to change as we evolve the IO platform.** # Introduction This is the documentation of the IO API for 3rd party services. This API enables Public Administration services to integrate with the IO platform. IO enables services to communicate with Italian citizens via the [IO app](https://io.italia.it/). # How to get an API key To get access to this API, you'll need to register on the [IO Developer Portal](https://developer.io.italia.it/). After the registration step, you have to click on the button that says `subscribe to the digital citizenship api` to receive the API key that you will use to authenticate the API calls. You will also receive an email with further instructions, including a fake Fiscal Code that you will be able to use to send test messages. Messages sent to the fake Fiscal Code will be notified to the email address used during the registration process on the developer portal. # Messages ## What is a message Messages are the primary form of communication enabled by the IO APIs. Messages are **personal** communications directed to a **specific citizen**. You will not be able to use this API to broadcast a message to a group of citizens, you will have to create and send a specific, personalized message to each citizen you want to communicate to. The recipient of the message (i.e. a citizen) is identified trough his [Fiscal Code](https://it.wikipedia.org/wiki/Codice_fiscale). ## Message format A message is conceptually very similar to an email and, in its simplest form, is composed of the following attributes: * A required `subject`: a short description of the topic. * A required `markdown` body: a Markdown representation of the body (see below on what Markdown tags are allowed). * An optional `payment_data`: in case the message is a payment request, the _payment data_ will enable the recipient to pay the requested amount via [PagoPA](https://www.agid.gov.it/it/piattaforme/pagopa). * An optional `due_date`: a _due date_ that let the recipient add a reminder when receiving the message. The format for all dates is [ISO8601](https://it.wikipedia.org/wiki/ISO_8601) with time information and UTC timezone (ie. \"2018-10-13T00:00:00.000Z\"). * An optional `feature_level_type`: the kind of the submitted message. It can be: - `STANDARD` for normal messages; - `ADVANCED` to enable premium features. Default is `STANDARD`. ## Allowed Markdown formatting Not all Markdown formatting is currently available. Currently you can use the following formatting: * Headings * Text stylings (bold, italic, etc...) * Lists (bullet and numbered) ## Sending a message to a citizen Not every citizen will be interested in what you have to say and not every citizen you want to communicate to will be registered on IO. For this reason, before sending a message you need to check whether the recipient is registered on the platform and that he has not yet opted out from receiving messages from you. The process for sending a message is made of 3 steps: 1. Call [getProfile](#operation/getProfile): if the profile does not exist (i.e. you get a 404 response) or if the recipient has opted-out from your service (the response contains `sender_allowed: false`), you cannot send the message and you must stop here. 1. Call [submitMessageforUser](#operation/submitMessageforUser) to submit a new message. 1. (optional) Call [getMessage](#operation/getMessage) to check whether the message has been notified to the recipient. - * - * The version of the OpenAPI document: 3.30.3 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -package it.gov.pagopa.receipt.pdf.notifier.generated.client; - -import java.util.List; -import java.util.Map; - -/** - *

ApiException class.

- */ -@SuppressWarnings("serial") -@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2023-06-23T14:54:01.440130+02:00[Europe/Rome]") -public class ApiException extends Exception { - private int code = 0; - private Map> responseHeaders = null; - private String responseBody = null; - - /** - *

Constructor for ApiException.

- * - * @param throwable a {@link java.lang.Throwable} object - */ - public ApiException(Throwable throwable) { - super(throwable); - } - - /** - *

Constructor for ApiException.

- * - * @param message the error message - */ - public ApiException(String message) { - super(message); - } - - /** - *

Constructor for ApiException.

- * - * @param message the error message - * @param throwable a {@link java.lang.Throwable} object - * @param code HTTP status code - * @param responseHeaders a {@link java.util.Map} of HTTP response headers - * @param responseBody the response body - */ - public ApiException(String message, Throwable throwable, int code, Map> responseHeaders, String responseBody) { - super(message, throwable); - this.code = code; - this.responseHeaders = responseHeaders; - this.responseBody = responseBody; - } - - /** - *

Constructor for ApiException.

- * - * @param message the error message - * @param code HTTP status code - * @param responseHeaders a {@link java.util.Map} of HTTP response headers - * @param responseBody the response body - */ - public ApiException(String message, int code, Map> responseHeaders, String responseBody) { - this(message, (Throwable) null, code, responseHeaders, responseBody); - } - - /** - *

Constructor for ApiException.

- * - * @param message the error message - * @param throwable a {@link java.lang.Throwable} object - * @param code HTTP status code - * @param responseHeaders a {@link java.util.Map} of HTTP response headers - */ - public ApiException(String message, Throwable throwable, int code, Map> responseHeaders) { - this(message, throwable, code, responseHeaders, null); - } - - /** - *

Constructor for ApiException.

- * - * @param code HTTP status code - * @param responseHeaders a {@link java.util.Map} of HTTP response headers - * @param responseBody the response body - */ - public ApiException(int code, Map> responseHeaders, String responseBody) { - this("Response Code: " + code + " Response Body: " + responseBody, (Throwable) null, code, responseHeaders, responseBody); - } - - /** - *

Constructor for ApiException.

- * - * @param code HTTP status code - * @param message a {@link java.lang.String} object - */ - public ApiException(int code, String message) { - super(message); - this.code = code; - } - - /** - *

Constructor for ApiException.

- * - * @param code HTTP status code - * @param message the error message - * @param responseHeaders a {@link java.util.Map} of HTTP response headers - * @param responseBody the response body - */ - public ApiException(int code, String message, Map> responseHeaders, String responseBody) { - this(code, message); - this.responseHeaders = responseHeaders; - this.responseBody = responseBody; - } - - /** - * Get the HTTP status code. - * - * @return HTTP status code - */ - public int getCode() { - return code; - } - - /** - * Get the HTTP response headers. - * - * @return A map of list of string - */ - public Map> getResponseHeaders() { - return responseHeaders; - } - - /** - * Get the HTTP response body. - * - * @return Response body in the form of string - */ - public String getResponseBody() { - return responseBody; - } - - /** - * Get the exception message including HTTP response data. - * - * @return The exception message - */ - public String getMessage() { - return String.format("Message: %s%nHTTP response code: %s%nHTTP response body: %s%nHTTP response headers: %s", - super.getMessage(), this.getCode(), this.getResponseBody(), this.getResponseHeaders()); - } -} diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/ApiResponse.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/ApiResponse.java deleted file mode 100644 index e769fe4..0000000 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/ApiResponse.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * IO API for Public Administration Services - * # Warning **This is an experimental API that is (most probably) going to change as we evolve the IO platform.** # Introduction This is the documentation of the IO API for 3rd party services. This API enables Public Administration services to integrate with the IO platform. IO enables services to communicate with Italian citizens via the [IO app](https://io.italia.it/). # How to get an API key To get access to this API, you'll need to register on the [IO Developer Portal](https://developer.io.italia.it/). After the registration step, you have to click on the button that says `subscribe to the digital citizenship api` to receive the API key that you will use to authenticate the API calls. You will also receive an email with further instructions, including a fake Fiscal Code that you will be able to use to send test messages. Messages sent to the fake Fiscal Code will be notified to the email address used during the registration process on the developer portal. # Messages ## What is a message Messages are the primary form of communication enabled by the IO APIs. Messages are **personal** communications directed to a **specific citizen**. You will not be able to use this API to broadcast a message to a group of citizens, you will have to create and send a specific, personalized message to each citizen you want to communicate to. The recipient of the message (i.e. a citizen) is identified trough his [Fiscal Code](https://it.wikipedia.org/wiki/Codice_fiscale). ## Message format A message is conceptually very similar to an email and, in its simplest form, is composed of the following attributes: * A required `subject`: a short description of the topic. * A required `markdown` body: a Markdown representation of the body (see below on what Markdown tags are allowed). * An optional `payment_data`: in case the message is a payment request, the _payment data_ will enable the recipient to pay the requested amount via [PagoPA](https://www.agid.gov.it/it/piattaforme/pagopa). * An optional `due_date`: a _due date_ that let the recipient add a reminder when receiving the message. The format for all dates is [ISO8601](https://it.wikipedia.org/wiki/ISO_8601) with time information and UTC timezone (ie. \"2018-10-13T00:00:00.000Z\"). * An optional `feature_level_type`: the kind of the submitted message. It can be: - `STANDARD` for normal messages; - `ADVANCED` to enable premium features. Default is `STANDARD`. ## Allowed Markdown formatting Not all Markdown formatting is currently available. Currently you can use the following formatting: * Headings * Text stylings (bold, italic, etc...) * Lists (bullet and numbered) ## Sending a message to a citizen Not every citizen will be interested in what you have to say and not every citizen you want to communicate to will be registered on IO. For this reason, before sending a message you need to check whether the recipient is registered on the platform and that he has not yet opted out from receiving messages from you. The process for sending a message is made of 3 steps: 1. Call [getProfile](#operation/getProfile): if the profile does not exist (i.e. you get a 404 response) or if the recipient has opted-out from your service (the response contains `sender_allowed: false`), you cannot send the message and you must stop here. 1. Call [submitMessageforUser](#operation/submitMessageforUser) to submit a new message. 1. (optional) Call [getMessage](#operation/getMessage) to check whether the message has been notified to the recipient. - * - * The version of the OpenAPI document: 3.30.3 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -package it.gov.pagopa.receipt.pdf.notifier.generated.client; - -import java.util.List; -import java.util.Map; - -/** - * API response returned by API call. - */ -public class ApiResponse { - private final int statusCode; - private final Map> headers; - private final T data; - - /** - *

Constructor for ApiResponse.

- * - * @param statusCode The status code of HTTP response - * @param headers The headers of HTTP response - * @param data The object deserialized from response bod - */ - public ApiResponse(int statusCode, Map> headers, T data) { - this.statusCode = statusCode; - this.headers = headers; - this.data = data; - } - - /** - *

Get the status code.

- * - * @return the status code - */ - public int getStatusCode() { - return statusCode; - } - - /** - *

Get the headers.

- * - * @return a {@link java.util.Map} of headers - */ - public Map> getHeaders() { - return headers; - } - - /** - *

Get the data.

- * - * @return the data - */ - public T getData() { - return data; - } -} diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/Configuration.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/Configuration.java deleted file mode 100644 index 1282ca5..0000000 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/Configuration.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * IO API for Public Administration Services - * # Warning **This is an experimental API that is (most probably) going to change as we evolve the IO platform.** # Introduction This is the documentation of the IO API for 3rd party services. This API enables Public Administration services to integrate with the IO platform. IO enables services to communicate with Italian citizens via the [IO app](https://io.italia.it/). # How to get an API key To get access to this API, you'll need to register on the [IO Developer Portal](https://developer.io.italia.it/). After the registration step, you have to click on the button that says `subscribe to the digital citizenship api` to receive the API key that you will use to authenticate the API calls. You will also receive an email with further instructions, including a fake Fiscal Code that you will be able to use to send test messages. Messages sent to the fake Fiscal Code will be notified to the email address used during the registration process on the developer portal. # Messages ## What is a message Messages are the primary form of communication enabled by the IO APIs. Messages are **personal** communications directed to a **specific citizen**. You will not be able to use this API to broadcast a message to a group of citizens, you will have to create and send a specific, personalized message to each citizen you want to communicate to. The recipient of the message (i.e. a citizen) is identified trough his [Fiscal Code](https://it.wikipedia.org/wiki/Codice_fiscale). ## Message format A message is conceptually very similar to an email and, in its simplest form, is composed of the following attributes: * A required `subject`: a short description of the topic. * A required `markdown` body: a Markdown representation of the body (see below on what Markdown tags are allowed). * An optional `payment_data`: in case the message is a payment request, the _payment data_ will enable the recipient to pay the requested amount via [PagoPA](https://www.agid.gov.it/it/piattaforme/pagopa). * An optional `due_date`: a _due date_ that let the recipient add a reminder when receiving the message. The format for all dates is [ISO8601](https://it.wikipedia.org/wiki/ISO_8601) with time information and UTC timezone (ie. \"2018-10-13T00:00:00.000Z\"). * An optional `feature_level_type`: the kind of the submitted message. It can be: - `STANDARD` for normal messages; - `ADVANCED` to enable premium features. Default is `STANDARD`. ## Allowed Markdown formatting Not all Markdown formatting is currently available. Currently you can use the following formatting: * Headings * Text stylings (bold, italic, etc...) * Lists (bullet and numbered) ## Sending a message to a citizen Not every citizen will be interested in what you have to say and not every citizen you want to communicate to will be registered on IO. For this reason, before sending a message you need to check whether the recipient is registered on the platform and that he has not yet opted out from receiving messages from you. The process for sending a message is made of 3 steps: 1. Call [getProfile](#operation/getProfile): if the profile does not exist (i.e. you get a 404 response) or if the recipient has opted-out from your service (the response contains `sender_allowed: false`), you cannot send the message and you must stop here. 1. Call [submitMessageforUser](#operation/submitMessageforUser) to submit a new message. 1. (optional) Call [getMessage](#operation/getMessage) to check whether the message has been notified to the recipient. - * - * The version of the OpenAPI document: 3.30.3 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -package it.gov.pagopa.receipt.pdf.notifier.generated.client; - -@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2023-06-23T14:54:01.440130+02:00[Europe/Rome]") -public class Configuration { - - /** - * Get the default API client, which would be used when creating API - * instances without providing an API client. - * - * @return Default API client - */ - public static ApiClient getDefaultApiClient() { - return new ApiClient(); - } - -} diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/JSON.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/JSON.java deleted file mode 100644 index 8142a4a..0000000 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/JSON.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * IO API for Public Administration Services - * # Warning **This is an experimental API that is (most probably) going to change as we evolve the IO platform.** # Introduction This is the documentation of the IO API for 3rd party services. This API enables Public Administration services to integrate with the IO platform. IO enables services to communicate with Italian citizens via the [IO app](https://io.italia.it/). # How to get an API key To get access to this API, you'll need to register on the [IO Developer Portal](https://developer.io.italia.it/). After the registration step, you have to click on the button that says `subscribe to the digital citizenship api` to receive the API key that you will use to authenticate the API calls. You will also receive an email with further instructions, including a fake Fiscal Code that you will be able to use to send test messages. Messages sent to the fake Fiscal Code will be notified to the email address used during the registration process on the developer portal. # Messages ## What is a message Messages are the primary form of communication enabled by the IO APIs. Messages are **personal** communications directed to a **specific citizen**. You will not be able to use this API to broadcast a message to a group of citizens, you will have to create and send a specific, personalized message to each citizen you want to communicate to. The recipient of the message (i.e. a citizen) is identified trough his [Fiscal Code](https://it.wikipedia.org/wiki/Codice_fiscale). ## Message format A message is conceptually very similar to an email and, in its simplest form, is composed of the following attributes: * A required `subject`: a short description of the topic. * A required `markdown` body: a Markdown representation of the body (see below on what Markdown tags are allowed). * An optional `payment_data`: in case the message is a payment request, the _payment data_ will enable the recipient to pay the requested amount via [PagoPA](https://www.agid.gov.it/it/piattaforme/pagopa). * An optional `due_date`: a _due date_ that let the recipient add a reminder when receiving the message. The format for all dates is [ISO8601](https://it.wikipedia.org/wiki/ISO_8601) with time information and UTC timezone (ie. \"2018-10-13T00:00:00.000Z\"). * An optional `feature_level_type`: the kind of the submitted message. It can be: - `STANDARD` for normal messages; - `ADVANCED` to enable premium features. Default is `STANDARD`. ## Allowed Markdown formatting Not all Markdown formatting is currently available. Currently you can use the following formatting: * Headings * Text stylings (bold, italic, etc...) * Lists (bullet and numbered) ## Sending a message to a citizen Not every citizen will be interested in what you have to say and not every citizen you want to communicate to will be registered on IO. For this reason, before sending a message you need to check whether the recipient is registered on the platform and that he has not yet opted out from receiving messages from you. The process for sending a message is made of 3 steps: 1. Call [getProfile](#operation/getProfile): if the profile does not exist (i.e. you get a 404 response) or if the recipient has opted-out from your service (the response contains `sender_allowed: false`), you cannot send the message and you must stop here. 1. Call [submitMessageforUser](#operation/submitMessageforUser) to submit a new message. 1. (optional) Call [getMessage](#operation/getMessage) to check whether the message has been notified to the recipient. - * - * The version of the OpenAPI document: 3.30.3 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -package it.gov.pagopa.receipt.pdf.notifier.generated.client; - -import com.google.gson.Gson; -import com.google.gson.JsonParseException; - -import java.lang.reflect.Type; - -/* - * A JSON utility class - * - * NOTE: in the future, this class may be converted to static, which may break - * backward-compatibility - */ -public class JSON { - private static Gson gson = new Gson(); - - private JSON() { - } - - /** - * Get Gson. - * - * @return Gson - */ - public static Gson getGson() { - return gson; - } - - /** - * Set Gson. - * - * @param gson Gson - */ - public static void setGson(Gson gson) { - JSON.gson = gson; - } - - /** - * Serialize the given Java object into JSON string. - * - * @param obj Object - * @return String representation of the JSON - */ - public static String serialize(Object obj) { - return gson.toJson(obj); - } - - /** - * Deserialize the given JSON string to Java object. - * - * @param Type - * @param body The JSON string - * @param returnType The type to deserialize into - * @return The deserialized Java object - */ - @SuppressWarnings("unchecked") - public static T deserialize(String body, Type returnType) { - try { - return gson.fromJson(body, returnType); - } catch (JsonParseException e) { - //Fallback processing when failed to parse JSON form response body: - //return the response body string directly for the String return type - if (returnType.equals(String.class)) { - return (T) body; - } else { - throw (e); - } - } - } -} diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/Pair.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/Pair.java deleted file mode 100644 index 4f06009..0000000 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/Pair.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * IO API for Public Administration Services - * # Warning **This is an experimental API that is (most probably) going to change as we evolve the IO platform.** # Introduction This is the documentation of the IO API for 3rd party services. This API enables Public Administration services to integrate with the IO platform. IO enables services to communicate with Italian citizens via the [IO app](https://io.italia.it/). # How to get an API key To get access to this API, you'll need to register on the [IO Developer Portal](https://developer.io.italia.it/). After the registration step, you have to click on the button that says `subscribe to the digital citizenship api` to receive the API key that you will use to authenticate the API calls. You will also receive an email with further instructions, including a fake Fiscal Code that you will be able to use to send test messages. Messages sent to the fake Fiscal Code will be notified to the email address used during the registration process on the developer portal. # Messages ## What is a message Messages are the primary form of communication enabled by the IO APIs. Messages are **personal** communications directed to a **specific citizen**. You will not be able to use this API to broadcast a message to a group of citizens, you will have to create and send a specific, personalized message to each citizen you want to communicate to. The recipient of the message (i.e. a citizen) is identified trough his [Fiscal Code](https://it.wikipedia.org/wiki/Codice_fiscale). ## Message format A message is conceptually very similar to an email and, in its simplest form, is composed of the following attributes: * A required `subject`: a short description of the topic. * A required `markdown` body: a Markdown representation of the body (see below on what Markdown tags are allowed). * An optional `payment_data`: in case the message is a payment request, the _payment data_ will enable the recipient to pay the requested amount via [PagoPA](https://www.agid.gov.it/it/piattaforme/pagopa). * An optional `due_date`: a _due date_ that let the recipient add a reminder when receiving the message. The format for all dates is [ISO8601](https://it.wikipedia.org/wiki/ISO_8601) with time information and UTC timezone (ie. \"2018-10-13T00:00:00.000Z\"). * An optional `feature_level_type`: the kind of the submitted message. It can be: - `STANDARD` for normal messages; - `ADVANCED` to enable premium features. Default is `STANDARD`. ## Allowed Markdown formatting Not all Markdown formatting is currently available. Currently you can use the following formatting: * Headings * Text stylings (bold, italic, etc...) * Lists (bullet and numbered) ## Sending a message to a citizen Not every citizen will be interested in what you have to say and not every citizen you want to communicate to will be registered on IO. For this reason, before sending a message you need to check whether the recipient is registered on the platform and that he has not yet opted out from receiving messages from you. The process for sending a message is made of 3 steps: 1. Call [getProfile](#operation/getProfile): if the profile does not exist (i.e. you get a 404 response) or if the recipient has opted-out from your service (the response contains `sender_allowed: false`), you cannot send the message and you must stop here. 1. Call [submitMessageforUser](#operation/submitMessageforUser) to submit a new message. 1. (optional) Call [getMessage](#operation/getMessage) to check whether the message has been notified to the recipient. - * - * The version of the OpenAPI document: 3.30.3 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -package it.gov.pagopa.receipt.pdf.notifier.generated.client; - -@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2023-06-23T14:54:01.440130+02:00[Europe/Rome]") -public class Pair { - private String name = ""; - private String value = ""; - - public Pair (String name, String value) { - setName(name); - setValue(value); - } - - private void setName(String name) { - if (!isValidString(name)) { - return; - } - - this.name = name; - } - - private void setValue(String value) { - if (!isValidString(value)) { - return; - } - - this.value = value; - } - - public String getName() { - return this.name; - } - - public String getValue() { - return this.value; - } - - private boolean isValidString(String arg) { - if (arg == null) { - return false; - } - - return true; - } -} diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/ProgressResponseBody.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/ProgressResponseBody.java deleted file mode 100644 index 379a186..0000000 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/ProgressResponseBody.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * IO API for Public Administration Services - * # Warning **This is an experimental API that is (most probably) going to change as we evolve the IO platform.** # Introduction This is the documentation of the IO API for 3rd party services. This API enables Public Administration services to integrate with the IO platform. IO enables services to communicate with Italian citizens via the [IO app](https://io.italia.it/). # How to get an API key To get access to this API, you'll need to register on the [IO Developer Portal](https://developer.io.italia.it/). After the registration step, you have to click on the button that says `subscribe to the digital citizenship api` to receive the API key that you will use to authenticate the API calls. You will also receive an email with further instructions, including a fake Fiscal Code that you will be able to use to send test messages. Messages sent to the fake Fiscal Code will be notified to the email address used during the registration process on the developer portal. # Messages ## What is a message Messages are the primary form of communication enabled by the IO APIs. Messages are **personal** communications directed to a **specific citizen**. You will not be able to use this API to broadcast a message to a group of citizens, you will have to create and send a specific, personalized message to each citizen you want to communicate to. The recipient of the message (i.e. a citizen) is identified trough his [Fiscal Code](https://it.wikipedia.org/wiki/Codice_fiscale). ## Message format A message is conceptually very similar to an email and, in its simplest form, is composed of the following attributes: * A required `subject`: a short description of the topic. * A required `markdown` body: a Markdown representation of the body (see below on what Markdown tags are allowed). * An optional `payment_data`: in case the message is a payment request, the _payment data_ will enable the recipient to pay the requested amount via [PagoPA](https://www.agid.gov.it/it/piattaforme/pagopa). * An optional `due_date`: a _due date_ that let the recipient add a reminder when receiving the message. The format for all dates is [ISO8601](https://it.wikipedia.org/wiki/ISO_8601) with time information and UTC timezone (ie. \"2018-10-13T00:00:00.000Z\"). * An optional `feature_level_type`: the kind of the submitted message. It can be: - `STANDARD` for normal messages; - `ADVANCED` to enable premium features. Default is `STANDARD`. ## Allowed Markdown formatting Not all Markdown formatting is currently available. Currently you can use the following formatting: * Headings * Text stylings (bold, italic, etc...) * Lists (bullet and numbered) ## Sending a message to a citizen Not every citizen will be interested in what you have to say and not every citizen you want to communicate to will be registered on IO. For this reason, before sending a message you need to check whether the recipient is registered on the platform and that he has not yet opted out from receiving messages from you. The process for sending a message is made of 3 steps: 1. Call [getProfile](#operation/getProfile): if the profile does not exist (i.e. you get a 404 response) or if the recipient has opted-out from your service (the response contains `sender_allowed: false`), you cannot send the message and you must stop here. 1. Call [submitMessageforUser](#operation/submitMessageforUser) to submit a new message. 1. (optional) Call [getMessage](#operation/getMessage) to check whether the message has been notified to the recipient. - * - * The version of the OpenAPI document: 3.30.3 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -package it.gov.pagopa.receipt.pdf.notifier.generated.client; - -import okhttp3.MediaType; -import okhttp3.ResponseBody; - -import java.io.IOException; - -import okio.Buffer; -import okio.BufferedSource; -import okio.ForwardingSource; -import okio.Okio; -import okio.Source; -import org.jetbrains.annotations.NotNull; - -public class ProgressResponseBody extends ResponseBody { - - private final ResponseBody responseBody; - @SuppressWarnings("rawtypes") - private final ApiCallback callback; - private BufferedSource bufferedSource; - @SuppressWarnings("rawtypes") - public ProgressResponseBody(ResponseBody responseBody, ApiCallback callback) { - this.responseBody = responseBody; - this.callback = callback; - } - - @Override - public MediaType contentType() { - return responseBody.contentType(); - } - - @Override - public long contentLength() { - return responseBody.contentLength(); - } - - @NotNull - @Override - public BufferedSource source() { - if (bufferedSource == null) { - bufferedSource = Okio.buffer(source(responseBody.source())); - } - return bufferedSource; - } - - private Source source(Source source) { - return new ForwardingSource(source) { - long totalBytesRead = 0L; - - @Override - public long read(@NotNull Buffer sink, long byteCount) throws IOException { - long bytesRead = super.read(sink, byteCount); - // read() returns the number of bytes read, or -1 if this source is exhausted. - totalBytesRead += bytesRead != -1 ? bytesRead : 0; - callback.onDownloadProgress(totalBytesRead, responseBody.contentLength(), bytesRead == -1); - return bytesRead; - } - }; - } -} diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/StringUtil.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/StringUtil.java deleted file mode 100644 index 37395d6..0000000 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/StringUtil.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * IO API for Public Administration Services - * # Warning **This is an experimental API that is (most probably) going to change as we evolve the IO platform.** # Introduction This is the documentation of the IO API for 3rd party services. This API enables Public Administration services to integrate with the IO platform. IO enables services to communicate with Italian citizens via the [IO app](https://io.italia.it/). # How to get an API key To get access to this API, you'll need to register on the [IO Developer Portal](https://developer.io.italia.it/). After the registration step, you have to click on the button that says `subscribe to the digital citizenship api` to receive the API key that you will use to authenticate the API calls. You will also receive an email with further instructions, including a fake Fiscal Code that you will be able to use to send test messages. Messages sent to the fake Fiscal Code will be notified to the email address used during the registration process on the developer portal. # Messages ## What is a message Messages are the primary form of communication enabled by the IO APIs. Messages are **personal** communications directed to a **specific citizen**. You will not be able to use this API to broadcast a message to a group of citizens, you will have to create and send a specific, personalized message to each citizen you want to communicate to. The recipient of the message (i.e. a citizen) is identified trough his [Fiscal Code](https://it.wikipedia.org/wiki/Codice_fiscale). ## Message format A message is conceptually very similar to an email and, in its simplest form, is composed of the following attributes: * A required `subject`: a short description of the topic. * A required `markdown` body: a Markdown representation of the body (see below on what Markdown tags are allowed). * An optional `payment_data`: in case the message is a payment request, the _payment data_ will enable the recipient to pay the requested amount via [PagoPA](https://www.agid.gov.it/it/piattaforme/pagopa). * An optional `due_date`: a _due date_ that let the recipient add a reminder when receiving the message. The format for all dates is [ISO8601](https://it.wikipedia.org/wiki/ISO_8601) with time information and UTC timezone (ie. \"2018-10-13T00:00:00.000Z\"). * An optional `feature_level_type`: the kind of the submitted message. It can be: - `STANDARD` for normal messages; - `ADVANCED` to enable premium features. Default is `STANDARD`. ## Allowed Markdown formatting Not all Markdown formatting is currently available. Currently you can use the following formatting: * Headings * Text stylings (bold, italic, etc...) * Lists (bullet and numbered) ## Sending a message to a citizen Not every citizen will be interested in what you have to say and not every citizen you want to communicate to will be registered on IO. For this reason, before sending a message you need to check whether the recipient is registered on the platform and that he has not yet opted out from receiving messages from you. The process for sending a message is made of 3 steps: 1. Call [getProfile](#operation/getProfile): if the profile does not exist (i.e. you get a 404 response) or if the recipient has opted-out from your service (the response contains `sender_allowed: false`), you cannot send the message and you must stop here. 1. Call [submitMessageforUser](#operation/submitMessageforUser) to submit a new message. 1. (optional) Call [getMessage](#operation/getMessage) to check whether the message has been notified to the recipient. - * - * The version of the OpenAPI document: 3.30.3 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -package it.gov.pagopa.receipt.pdf.notifier.generated.client; - -@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2023-06-23T14:54:01.440130+02:00[Europe/Rome]") -public class StringUtil { - /** - * Join an array of strings with the given separator. - *

- * Note: This might be replaced by utility method from commons-lang or guava someday - * if one of those libraries is added as dependency. - *

- * - * @param array The array of strings - * @param separator The separator - * @return the resulting string - */ - public static String join(String[] array, String separator) { - int len = array.length; - if (len == 0) { - return ""; - } - - StringBuilder out = new StringBuilder(); - out.append(array[0]); - for (int i = 1; i < len; i++) { - out.append(separator).append(array[i]); - } - return out.toString(); - } -} diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/api/IOClient.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/api/IOClient.java deleted file mode 100644 index 73fe546..0000000 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/api/IOClient.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * IO API for Public Administration Services - * # Warning **This is an experimental API that is (most probably) going to change as we evolve the IO platform.** # Introduction This is the documentation of the IO API for 3rd party services. This API enables Public Administration services to integrate with the IO platform. IO enables services to communicate with Italian citizens via the [IO app](https://io.italia.it/). # How to get an API key To get access to this API, you'll need to register on the [IO Developer Portal](https://developer.io.italia.it/). After the registration step, you have to click on the button that says `subscribe to the digital citizenship api` to receive the API key that you will use to authenticate the API calls. You will also receive an email with further instructions, including a fake Fiscal Code that you will be able to use to send test messages. Messages sent to the fake Fiscal Code will be notified to the email address used during the registration process on the developer portal. # Messages ## What is a message Messages are the primary form of communication enabled by the IO APIs. Messages are **personal** communications directed to a **specific citizen**. You will not be able to use this API to broadcast a message to a group of citizens, you will have to create and send a specific, personalized message to each citizen you want to communicate to. The recipient of the message (i.e. a citizen) is identified trough his [Fiscal Code](https://it.wikipedia.org/wiki/Codice_fiscale). ## Message format A message is conceptually very similar to an email and, in its simplest form, is composed of the following attributes: * A required `subject`: a short description of the topic. * A required `markdown` body: a Markdown representation of the body (see below on what Markdown tags are allowed). * An optional `payment_data`: in case the message is a payment request, the _payment data_ will enable the recipient to pay the requested amount via [PagoPA](https://www.agid.gov.it/it/piattaforme/pagopa). * An optional `due_date`: a _due date_ that let the recipient add a reminder when receiving the message. The format for all dates is [ISO8601](https://it.wikipedia.org/wiki/ISO_8601) with time information and UTC timezone (ie. \"2018-10-13T00:00:00.000Z\"). * An optional `feature_level_type`: the kind of the submitted message. It can be: - `STANDARD` for normal messages; - `ADVANCED` to enable premium features. Default is `STANDARD`. ## Allowed Markdown formatting Not all Markdown formatting is currently available. Currently you can use the following formatting: * Headings * Text stylings (bold, italic, etc...) * Lists (bullet and numbered) ## Sending a message to a citizen Not every citizen will be interested in what you have to say and not every citizen you want to communicate to will be registered on IO. For this reason, before sending a message you need to check whether the recipient is registered on the platform and that he has not yet opted out from receiving messages from you. The process for sending a message is made of 3 steps: 1. Call [getProfile](#operation/getProfile): if the profile does not exist (i.e. you get a 404 response) or if the recipient has opted-out from your service (the response contains `sender_allowed: false`), you cannot send the message and you must stop here. 1. Call [submitMessageforUser](#operation/submitMessageforUser) to submit a new message. 1. (optional) Call [getMessage](#operation/getMessage) to check whether the message has been notified to the recipient. - * - * The version of the OpenAPI document: 3.30.3 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -package it.gov.pagopa.receipt.pdf.notifier.generated.client.api; - -import com.google.gson.reflect.TypeToken; -import it.gov.pagopa.receipt.pdf.notifier.generated.client.ApiClient; -import it.gov.pagopa.receipt.pdf.notifier.generated.client.ApiException; -import it.gov.pagopa.receipt.pdf.notifier.generated.client.ApiResponse; -import it.gov.pagopa.receipt.pdf.notifier.generated.client.Configuration; -import it.gov.pagopa.receipt.pdf.notifier.generated.model.CreatedMessage; -import it.gov.pagopa.receipt.pdf.notifier.generated.model.FiscalCodePayload; -import it.gov.pagopa.receipt.pdf.notifier.generated.model.LimitedProfile; -import it.gov.pagopa.receipt.pdf.notifier.generated.model.NewMessage; - -import java.lang.reflect.Type; -import java.util.HashMap; -import java.util.Map; - -public class IOClient { - private final ApiClient localVarApiClient; - private static IOClient instance = null; - - private final String apiBasePath = System.getenv().getOrDefault("IO_API_BASE_PATH", "https://api.io.pagopa.it/api/v1"); - private final String apiProfilesPath = System.getenv().getOrDefault("IO_API_PROFILES_PATH", "/profiles"); - private final String apiMessagesPath = System.getenv().getOrDefault("IO_API_MESSAGES_PATH", "/messages"); - - private final String ocpApimSubscriptionKey = System.getenv("OCP_APIM_SUBSCRIPTION_KEY"); - private final String ApimKeyHeaderKey = System.getenv().getOrDefault("OCP_APIM_HEADER_KEY", "Ocp-Apim-Subscription-Key"); - private static final String CONTENT_TYPE_JSON = "application/json"; - - public IOClient() { - this(Configuration.getDefaultApiClient()); - } - - public IOClient(ApiClient apiClient) { - this.localVarApiClient = apiClient; - } - - public static IOClient getInstance() { - if (instance == null) { - instance = new IOClient(); - } - - return instance; - } - - /** - * Get a User Profile using POST - * Returns the preferences for the user identified by the fiscal code provided in the request body. The field `sender_allowed` is set fo `false` in case the service which is calling the API has been disabled by the user. - * - * @param payload (optional) - * @return ApiResponse<LimitedProfile> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public ApiResponse getProfileByPOSTWithHttpInfo(FiscalCodePayload payload) throws ApiException { - okhttp3.Call localVarCall = getProfileByPOSTCall(payload); - Type localVarReturnType = new TypeToken() { - }.getType(); - return localVarApiClient.execute(localVarCall, localVarReturnType); - } - - /** - * Build call for getProfileByPOST - * - * @param payload (optional) - * @return Call to execute - * @throws ApiException If fail to serialize the request body object - */ - public okhttp3.Call getProfileByPOSTCall(FiscalCodePayload payload) throws ApiException { - - Map localVarHeaderParams = new HashMap<>(); - - final String[] localVarAccepts = { - CONTENT_TYPE_JSON - }; - final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts); - if (localVarAccept != null) { - localVarHeaderParams.put("Accept", localVarAccept); - } - - final String[] localVarContentTypes = { - CONTENT_TYPE_JSON - }; - final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes); - if (localVarContentType != null) { - localVarHeaderParams.put("Content-Type", localVarContentType); - } - - if (ocpApimSubscriptionKey != null) { - localVarHeaderParams.put(ApimKeyHeaderKey, ocpApimSubscriptionKey); - } - - return localVarApiClient.buildCall( - apiBasePath, - apiProfilesPath, - "POST", - payload, - localVarHeaderParams - ); - } - - /** - * Submit a Message passing the user fiscal_code in the request body - * Submits a message to a user with STANDARD or ADVANCED features based on `feature_level_type` value. On error, the reason is returned in the response payload. In order to call `submitMessageforUser`, before sending any message, the sender MUST call `getProfile` and check that the profile exists (for the specified fiscal code) and that the `sender_allowed` field of the user's profile it set to `true`. - * - * @param message (optional) - * @return ApiResponse<CreatedMessage> - * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body - */ - public ApiResponse submitMessageforUserWithFiscalCodeInBodyWithHttpInfo(NewMessage message) throws ApiException { - okhttp3.Call localVarCall = submitMessageforUserWithFiscalCodeInBodyCall(message); - Type localVarReturnType = new TypeToken() { - }.getType(); - return localVarApiClient.execute(localVarCall, localVarReturnType); - } - - /** - * Build call for submitMessageforUserWithFiscalCodeInBody - * - * @param message (optional) - * @return Call to execute - * @throws ApiException If fail to serialize the request body object - */ - public okhttp3.Call submitMessageforUserWithFiscalCodeInBodyCall(NewMessage message) throws ApiException { - - Map localVarHeaderParams = new HashMap<>(); - - final String[] localVarAccepts = { - CONTENT_TYPE_JSON - }; - final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts); - if (localVarAccept != null) { - localVarHeaderParams.put("Accept", localVarAccept); - } - - final String[] localVarContentTypes = { - CONTENT_TYPE_JSON - }; - final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes); - if (localVarContentType != null) { - localVarHeaderParams.put("Content-Type", localVarContentType); - } - - if (ocpApimSubscriptionKey != null) { - localVarHeaderParams.put(ApimKeyHeaderKey, ocpApimSubscriptionKey); - } - - return localVarApiClient.buildCall(apiBasePath, - apiMessagesPath, - "POST", - message, - localVarHeaderParams - ); - } -} diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/auth/ApiKeyAuth.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/auth/ApiKeyAuth.java deleted file mode 100644 index f21effe..0000000 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/auth/ApiKeyAuth.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * IO API for Public Administration Services - * # Warning **This is an experimental API that is (most probably) going to change as we evolve the IO platform.** # Introduction This is the documentation of the IO API for 3rd party services. This API enables Public Administration services to integrate with the IO platform. IO enables services to communicate with Italian citizens via the [IO app](https://io.italia.it/). # How to get an API key To get access to this API, you'll need to register on the [IO Developer Portal](https://developer.io.italia.it/). After the registration step, you have to click on the button that says `subscribe to the digital citizenship api` to receive the API key that you will use to authenticate the API calls. You will also receive an email with further instructions, including a fake Fiscal Code that you will be able to use to send test messages. Messages sent to the fake Fiscal Code will be notified to the email address used during the registration process on the developer portal. # Messages ## What is a message Messages are the primary form of communication enabled by the IO APIs. Messages are **personal** communications directed to a **specific citizen**. You will not be able to use this API to broadcast a message to a group of citizens, you will have to create and send a specific, personalized message to each citizen you want to communicate to. The recipient of the message (i.e. a citizen) is identified trough his [Fiscal Code](https://it.wikipedia.org/wiki/Codice_fiscale). ## Message format A message is conceptually very similar to an email and, in its simplest form, is composed of the following attributes: * A required `subject`: a short description of the topic. * A required `markdown` body: a Markdown representation of the body (see below on what Markdown tags are allowed). * An optional `payment_data`: in case the message is a payment request, the _payment data_ will enable the recipient to pay the requested amount via [PagoPA](https://www.agid.gov.it/it/piattaforme/pagopa). * An optional `due_date`: a _due date_ that let the recipient add a reminder when receiving the message. The format for all dates is [ISO8601](https://it.wikipedia.org/wiki/ISO_8601) with time information and UTC timezone (ie. \"2018-10-13T00:00:00.000Z\"). * An optional `feature_level_type`: the kind of the submitted message. It can be: - `STANDARD` for normal messages; - `ADVANCED` to enable premium features. Default is `STANDARD`. ## Allowed Markdown formatting Not all Markdown formatting is currently available. Currently you can use the following formatting: * Headings * Text stylings (bold, italic, etc...) * Lists (bullet and numbered) ## Sending a message to a citizen Not every citizen will be interested in what you have to say and not every citizen you want to communicate to will be registered on IO. For this reason, before sending a message you need to check whether the recipient is registered on the platform and that he has not yet opted out from receiving messages from you. The process for sending a message is made of 3 steps: 1. Call [getProfile](#operation/getProfile): if the profile does not exist (i.e. you get a 404 response) or if the recipient has opted-out from your service (the response contains `sender_allowed: false`), you cannot send the message and you must stop here. 1. Call [submitMessageforUser](#operation/submitMessageforUser) to submit a new message. 1. (optional) Call [getMessage](#operation/getMessage) to check whether the message has been notified to the recipient. - * - * The version of the OpenAPI document: 3.30.3 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ -package it.gov.pagopa.receipt.pdf.notifier.generated.client.auth; - -import it.gov.pagopa.receipt.pdf.notifier.generated.client.ApiException; - -import java.net.URI; -import java.util.Map; - -@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2023-06-23T14:54:01.440130+02:00[Europe/Rome]") -public class ApiKeyAuth implements Authentication { - private final String location; - private final String paramName; - - private String apiKey; - private String apiKeyPrefix; - - public ApiKeyAuth(String location, String paramName, String apiKey) { - this.location = location; - this.paramName = paramName; - this.apiKey = apiKey; - } - - public String getLocation() { - return location; - } - - public String getParamName() { - return paramName; - } - - public String getApiKey() { - return apiKey; - } - - public void setApiKey(String apiKey) { - this.apiKey = apiKey; - } - - public String getApiKeyPrefix() { - return apiKeyPrefix; - } - - public void setApiKeyPrefix(String apiKeyPrefix) { - this.apiKeyPrefix = apiKeyPrefix; - } - - @Override - public void applyToParams(Map headerParams, - String payload, String method, URI uri) throws ApiException { - if (apiKey == null) { - return; - } - String value; - if (apiKeyPrefix != null) { - value = apiKeyPrefix + " " + apiKey; - } else { - value = apiKey; - } - if ("header".equals(location)) { - headerParams.put(paramName, value); - } - } -} diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/auth/Authentication.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/auth/Authentication.java deleted file mode 100644 index d1e7207..0000000 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/client/auth/Authentication.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * IO API for Public Administration Services - * # Warning **This is an experimental API that is (most probably) going to change as we evolve the IO platform.** # Introduction This is the documentation of the IO API for 3rd party services. This API enables Public Administration services to integrate with the IO platform. IO enables services to communicate with Italian citizens via the [IO app](https://io.italia.it/). # How to get an API key To get access to this API, you'll need to register on the [IO Developer Portal](https://developer.io.italia.it/). After the registration step, you have to click on the button that says `subscribe to the digital citizenship api` to receive the API key that you will use to authenticate the API calls. You will also receive an email with further instructions, including a fake Fiscal Code that you will be able to use to send test messages. Messages sent to the fake Fiscal Code will be notified to the email address used during the registration process on the developer portal. # Messages ## What is a message Messages are the primary form of communication enabled by the IO APIs. Messages are **personal** communications directed to a **specific citizen**. You will not be able to use this API to broadcast a message to a group of citizens, you will have to create and send a specific, personalized message to each citizen you want to communicate to. The recipient of the message (i.e. a citizen) is identified trough his [Fiscal Code](https://it.wikipedia.org/wiki/Codice_fiscale). ## Message format A message is conceptually very similar to an email and, in its simplest form, is composed of the following attributes: * A required `subject`: a short description of the topic. * A required `markdown` body: a Markdown representation of the body (see below on what Markdown tags are allowed). * An optional `payment_data`: in case the message is a payment request, the _payment data_ will enable the recipient to pay the requested amount via [PagoPA](https://www.agid.gov.it/it/piattaforme/pagopa). * An optional `due_date`: a _due date_ that let the recipient add a reminder when receiving the message. The format for all dates is [ISO8601](https://it.wikipedia.org/wiki/ISO_8601) with time information and UTC timezone (ie. \"2018-10-13T00:00:00.000Z\"). * An optional `feature_level_type`: the kind of the submitted message. It can be: - `STANDARD` for normal messages; - `ADVANCED` to enable premium features. Default is `STANDARD`. ## Allowed Markdown formatting Not all Markdown formatting is currently available. Currently you can use the following formatting: * Headings * Text stylings (bold, italic, etc...) * Lists (bullet and numbered) ## Sending a message to a citizen Not every citizen will be interested in what you have to say and not every citizen you want to communicate to will be registered on IO. For this reason, before sending a message you need to check whether the recipient is registered on the platform and that he has not yet opted out from receiving messages from you. The process for sending a message is made of 3 steps: 1. Call [getProfile](#operation/getProfile): if the profile does not exist (i.e. you get a 404 response) or if the recipient has opted-out from your service (the response contains `sender_allowed: false`), you cannot send the message and you must stop here. 1. Call [submitMessageforUser](#operation/submitMessageforUser) to submit a new message. 1. (optional) Call [getMessage](#operation/getMessage) to check whether the message has been notified to the recipient. - * - * The version of the OpenAPI document: 3.30.3 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -package it.gov.pagopa.receipt.pdf.notifier.generated.client.auth; - -import it.gov.pagopa.receipt.pdf.notifier.generated.client.ApiException; - -import java.net.URI; -import java.util.Map; - -public interface Authentication { - /** - * Apply authentication settings to header and query params. - * - * @param headerParams Map of header parameters - * @param payload HTTP request body - * @param method HTTP method - * @param uri URI - * @throws ApiException if failed to update the parameters - */ - void applyToParams(Map headerParams, String payload, String method, URI uri) throws ApiException; -} diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/CreatedMessage.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/CreatedMessage.java deleted file mode 100644 index 831e784..0000000 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/CreatedMessage.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * IO API for Public Administration Services - * # Warning **This is an experimental API that is (most probably) going to change as we evolve the IO platform.** # Introduction This is the documentation of the IO API for 3rd party services. This API enables Public Administration services to integrate with the IO platform. IO enables services to communicate with Italian citizens via the [IO app](https://io.italia.it/). # How to get an API key To get access to this API, you'll need to register on the [IO Developer Portal](https://developer.io.italia.it/). After the registration step, you have to click on the button that says `subscribe to the digital citizenship api` to receive the API key that you will use to authenticate the API calls. You will also receive an email with further instructions, including a fake Fiscal Code that you will be able to use to send test messages. Messages sent to the fake Fiscal Code will be notified to the email address used during the registration process on the developer portal. # Messages ## What is a message Messages are the primary form of communication enabled by the IO APIs. Messages are **personal** communications directed to a **specific citizen**. You will not be able to use this API to broadcast a message to a group of citizens, you will have to create and send a specific, personalized message to each citizen you want to communicate to. The recipient of the message (i.e. a citizen) is identified trough his [Fiscal Code](https://it.wikipedia.org/wiki/Codice_fiscale). ## Message format A message is conceptually very similar to an email and, in its simplest form, is composed of the following attributes: * A required `subject`: a short description of the topic. * A required `markdown` body: a Markdown representation of the body (see below on what Markdown tags are allowed). * An optional `payment_data`: in case the message is a payment request, the _payment data_ will enable the recipient to pay the requested amount via [PagoPA](https://www.agid.gov.it/it/piattaforme/pagopa). * An optional `due_date`: a _due date_ that let the recipient add a reminder when receiving the message. The format for all dates is [ISO8601](https://it.wikipedia.org/wiki/ISO_8601) with time information and UTC timezone (ie. \"2018-10-13T00:00:00.000Z\"). * An optional `feature_level_type`: the kind of the submitted message. It can be: - `STANDARD` for normal messages; - `ADVANCED` to enable premium features. Default is `STANDARD`. ## Allowed Markdown formatting Not all Markdown formatting is currently available. Currently you can use the following formatting: * Headings * Text stylings (bold, italic, etc...) * Lists (bullet and numbered) ## Sending a message to a citizen Not every citizen will be interested in what you have to say and not every citizen you want to communicate to will be registered on IO. For this reason, before sending a message you need to check whether the recipient is registered on the platform and that he has not yet opted out from receiving messages from you. The process for sending a message is made of 3 steps: 1. Call [getProfile](#operation/getProfile): if the profile does not exist (i.e. you get a 404 response) or if the recipient has opted-out from your service (the response contains `sender_allowed: false`), you cannot send the message and you must stop here. 1. Call [submitMessageforUser](#operation/submitMessageforUser) to submit a new message. 1. (optional) Call [getMessage](#operation/getMessage) to check whether the message has been notified to the recipient. - * - * The version of the OpenAPI document: 3.30.3 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -package it.gov.pagopa.receipt.pdf.notifier.generated.model; - -import com.google.gson.*; -import com.google.gson.annotations.SerializedName; -import com.google.gson.reflect.TypeToken; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; -import it.gov.pagopa.receipt.pdf.notifier.generated.client.JSON; - -import javax.annotation.Nullable; -import java.io.IOException; -import java.util.HashSet; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; - -/** - * CreatedMessage - */ -@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2023-06-23T14:54:01.440130+02:00[Europe/Rome]") -public class CreatedMessage { - public static final String SERIALIZED_NAME_ID = "id"; - @SerializedName(SERIALIZED_NAME_ID) - private String id; - - public CreatedMessage() { - } - - public CreatedMessage id(String id) { - - this.id = id; - return this; - } - - /** - * The identifier of the created message. - * @return id - **/ - @Nullable - public String getId() { - return id; - } - - - public void setId(String id) { - this.id = id; - } - - - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - CreatedMessage createdMessage = (CreatedMessage) o; - return Objects.equals(this.id, createdMessage.id); - } - - @Override - public int hashCode() { - return Objects.hash(id); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class CreatedMessage {\n"); - sb.append(" id: ").append(toIndentedString(id)).append("\n"); - sb.append("}"); - return sb.toString(); - } - - /** - * Convert the given object to string with each line indented by 4 spaces - * (except the first line). - */ - private String toIndentedString(Object o) { - if (o == null) { - return "null"; - } - return o.toString().replace("\n", "\n "); - } - - - public static HashSet openapiFields; - public static HashSet openapiRequiredFields; - - static { - // a set of all properties/fields (JSON key names) - openapiFields = new HashSet(); - openapiFields.add("id"); - - // a set of required properties/fields (JSON key names) - openapiRequiredFields = new HashSet(); - } - - /** - * Validates the JSON Object and throws an exception if issues found - * - * @param jsonObj JSON Object - * @throws IOException if the JSON Object is invalid with respect to CreatedMessage - */ - public static void validateJsonObject(JsonObject jsonObj) throws IOException { - if (jsonObj == null) { - if (!CreatedMessage.openapiRequiredFields.isEmpty()) { // has required fields but JSON object is null - throw new IllegalArgumentException(String.format("The required field(s) %s in CreatedMessage is not found in the empty JSON string", CreatedMessage.openapiRequiredFields.toString())); - } - } - - Set> entries = jsonObj.entrySet(); - // check to see if the JSON string contains additional fields - for (Entry entry : entries) { - if (!CreatedMessage.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `CreatedMessage` properties. JSON: %s", entry.getKey(), jsonObj.toString())); - } - } - if ((jsonObj.get("id") != null && !jsonObj.get("id").isJsonNull()) && !jsonObj.get("id").isJsonPrimitive()) { - throw new IllegalArgumentException(String.format("Expected the field `id` to be a primitive type in the JSON string but got `%s`", jsonObj.get("id").toString())); - } - } - - public static class CustomTypeAdapterFactory implements TypeAdapterFactory { - @SuppressWarnings("unchecked") - @Override - public TypeAdapter create(Gson gson, TypeToken type) { - if (!CreatedMessage.class.isAssignableFrom(type.getRawType())) { - return null; // this class only serializes 'CreatedMessage' and its subtypes - } - final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); - final TypeAdapter thisAdapter - = gson.getDelegateAdapter(this, TypeToken.get(CreatedMessage.class)); - - return (TypeAdapter) new TypeAdapter() { - @Override - public void write(JsonWriter out, CreatedMessage value) throws IOException { - JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); - elementAdapter.write(out, obj); - } - - @Override - public CreatedMessage read(JsonReader in) throws IOException { - JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject(); - validateJsonObject(jsonObj); - return thisAdapter.fromJsonTree(jsonObj); - } - - }.nullSafe(); - } - } - - /** - * Create an instance of CreatedMessage given an JSON string - * - * @param jsonString JSON string - * @return An instance of CreatedMessage - * @throws IOException if the JSON string is invalid with respect to CreatedMessage - */ - public static CreatedMessage fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, CreatedMessage.class); - } - - /** - * Convert an instance of CreatedMessage to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } -} - diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/FiscalCodePayload.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/FiscalCodePayload.java deleted file mode 100644 index 1e12df6..0000000 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/FiscalCodePayload.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * IO API for Public Administration Services - * # Warning **This is an experimental API that is (most probably) going to change as we evolve the IO platform.** # Introduction This is the documentation of the IO API for 3rd party services. This API enables Public Administration services to integrate with the IO platform. IO enables services to communicate with Italian citizens via the [IO app](https://io.italia.it/). # How to get an API key To get access to this API, you'll need to register on the [IO Developer Portal](https://developer.io.italia.it/). After the registration step, you have to click on the button that says `subscribe to the digital citizenship api` to receive the API key that you will use to authenticate the API calls. You will also receive an email with further instructions, including a fake Fiscal Code that you will be able to use to send test messages. Messages sent to the fake Fiscal Code will be notified to the email address used during the registration process on the developer portal. # Messages ## What is a message Messages are the primary form of communication enabled by the IO APIs. Messages are **personal** communications directed to a **specific citizen**. You will not be able to use this API to broadcast a message to a group of citizens, you will have to create and send a specific, personalized message to each citizen you want to communicate to. The recipient of the message (i.e. a citizen) is identified trough his [Fiscal Code](https://it.wikipedia.org/wiki/Codice_fiscale). ## Message format A message is conceptually very similar to an email and, in its simplest form, is composed of the following attributes: * A required `subject`: a short description of the topic. * A required `markdown` body: a Markdown representation of the body (see below on what Markdown tags are allowed). * An optional `payment_data`: in case the message is a payment request, the _payment data_ will enable the recipient to pay the requested amount via [PagoPA](https://www.agid.gov.it/it/piattaforme/pagopa). * An optional `due_date`: a _due date_ that let the recipient add a reminder when receiving the message. The format for all dates is [ISO8601](https://it.wikipedia.org/wiki/ISO_8601) with time information and UTC timezone (ie. \"2018-10-13T00:00:00.000Z\"). * An optional `feature_level_type`: the kind of the submitted message. It can be: - `STANDARD` for normal messages; - `ADVANCED` to enable premium features. Default is `STANDARD`. ## Allowed Markdown formatting Not all Markdown formatting is currently available. Currently you can use the following formatting: * Headings * Text stylings (bold, italic, etc...) * Lists (bullet and numbered) ## Sending a message to a citizen Not every citizen will be interested in what you have to say and not every citizen you want to communicate to will be registered on IO. For this reason, before sending a message you need to check whether the recipient is registered on the platform and that he has not yet opted out from receiving messages from you. The process for sending a message is made of 3 steps: 1. Call [getProfile](#operation/getProfile): if the profile does not exist (i.e. you get a 404 response) or if the recipient has opted-out from your service (the response contains `sender_allowed: false`), you cannot send the message and you must stop here. 1. Call [submitMessageforUser](#operation/submitMessageforUser) to submit a new message. 1. (optional) Call [getMessage](#operation/getMessage) to check whether the message has been notified to the recipient. - * - * The version of the OpenAPI document: 3.30.3 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -package it.gov.pagopa.receipt.pdf.notifier.generated.model; - -import com.google.gson.*; -import com.google.gson.annotations.SerializedName; -import com.google.gson.reflect.TypeToken; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; -import it.gov.pagopa.receipt.pdf.notifier.generated.client.JSON; - -import java.io.IOException; -import java.util.HashSet; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; - -/** - * FiscalCodePayload - */ -@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2023-06-23T14:54:01.440130+02:00[Europe/Rome]") -public class FiscalCodePayload { - public static final String SERIALIZED_NAME_FISCAL_CODE = "fiscal_code"; - @SerializedName(SERIALIZED_NAME_FISCAL_CODE) - private String fiscalCode; - - public FiscalCodePayload() { - } - - public FiscalCodePayload fiscalCode(String fiscalCode) { - - this.fiscalCode = fiscalCode; - return this; - } - - /** - * User's fiscal code. - * @return fiscalCode - **/ - @javax.annotation.Nullable - public String getFiscalCode() { - return fiscalCode; - } - - - public void setFiscalCode(String fiscalCode) { - this.fiscalCode = fiscalCode; - } - - - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - FiscalCodePayload fiscalCodePayload = (FiscalCodePayload) o; - return Objects.equals(this.fiscalCode, fiscalCodePayload.fiscalCode); - } - - @Override - public int hashCode() { - return Objects.hash(fiscalCode); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class FiscalCodePayload {\n"); - sb.append(" fiscalCode: ").append(toIndentedString(fiscalCode)).append("\n"); - sb.append("}"); - return sb.toString(); - } - - /** - * Convert the given object to string with each line indented by 4 spaces - * (except the first line). - */ - private String toIndentedString(Object o) { - if (o == null) { - return "null"; - } - return o.toString().replace("\n", "\n "); - } - - - public static HashSet openapiFields; - public static HashSet openapiRequiredFields; - - static { - // a set of all properties/fields (JSON key names) - openapiFields = new HashSet(); - openapiFields.add("fiscal_code"); - - // a set of required properties/fields (JSON key names) - openapiRequiredFields = new HashSet(); - } - - /** - * Validates the JSON Object and throws an exception if issues found - * - * @param jsonObj JSON Object - * @throws IOException if the JSON Object is invalid with respect to FiscalCodePayload - */ - public static void validateJsonObject(JsonObject jsonObj) throws IOException { - if (jsonObj == null) { - if (!FiscalCodePayload.openapiRequiredFields.isEmpty()) { // has required fields but JSON object is null - throw new IllegalArgumentException(String.format("The required field(s) %s in FiscalCodePayload is not found in the empty JSON string", FiscalCodePayload.openapiRequiredFields.toString())); - } - } - - Set> entries = jsonObj.entrySet(); - // check to see if the JSON string contains additional fields - for (Entry entry : entries) { - if (!FiscalCodePayload.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `FiscalCodePayload` properties. JSON: %s", entry.getKey(), jsonObj.toString())); - } - } - if ((jsonObj.get("fiscal_code") != null && !jsonObj.get("fiscal_code").isJsonNull()) && !jsonObj.get("fiscal_code").isJsonPrimitive()) { - throw new IllegalArgumentException(String.format("Expected the field `fiscal_code` to be a primitive type in the JSON string but got `%s`", jsonObj.get("fiscal_code").toString())); - } - } - - public static class CustomTypeAdapterFactory implements TypeAdapterFactory { - @SuppressWarnings("unchecked") - @Override - public TypeAdapter create(Gson gson, TypeToken type) { - if (!FiscalCodePayload.class.isAssignableFrom(type.getRawType())) { - return null; // this class only serializes 'FiscalCodePayload' and its subtypes - } - final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); - final TypeAdapter thisAdapter - = gson.getDelegateAdapter(this, TypeToken.get(FiscalCodePayload.class)); - - return (TypeAdapter) new TypeAdapter() { - @Override - public void write(JsonWriter out, FiscalCodePayload value) throws IOException { - JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); - elementAdapter.write(out, obj); - } - - @Override - public FiscalCodePayload read(JsonReader in) throws IOException { - JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject(); - validateJsonObject(jsonObj); - return thisAdapter.fromJsonTree(jsonObj); - } - - }.nullSafe(); - } - } - - /** - * Create an instance of FiscalCodePayload given an JSON string - * - * @param jsonString JSON string - * @return An instance of FiscalCodePayload - * @throws IOException if the JSON string is invalid with respect to FiscalCodePayload - */ - public static FiscalCodePayload fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, FiscalCodePayload.class); - } - - /** - * Convert an instance of FiscalCodePayload to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } -} - diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/LimitedProfile.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/LimitedProfile.java deleted file mode 100644 index 1941c36..0000000 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/LimitedProfile.java +++ /dev/null @@ -1,230 +0,0 @@ -/* - * IO API for Public Administration Services - * # Warning **This is an experimental API that is (most probably) going to change as we evolve the IO platform.** # Introduction This is the documentation of the IO API for 3rd party services. This API enables Public Administration services to integrate with the IO platform. IO enables services to communicate with Italian citizens via the [IO app](https://io.italia.it/). # How to get an API key To get access to this API, you'll need to register on the [IO Developer Portal](https://developer.io.italia.it/). After the registration step, you have to click on the button that says `subscribe to the digital citizenship api` to receive the API key that you will use to authenticate the API calls. You will also receive an email with further instructions, including a fake Fiscal Code that you will be able to use to send test messages. Messages sent to the fake Fiscal Code will be notified to the email address used during the registration process on the developer portal. # Messages ## What is a message Messages are the primary form of communication enabled by the IO APIs. Messages are **personal** communications directed to a **specific citizen**. You will not be able to use this API to broadcast a message to a group of citizens, you will have to create and send a specific, personalized message to each citizen you want to communicate to. The recipient of the message (i.e. a citizen) is identified trough his [Fiscal Code](https://it.wikipedia.org/wiki/Codice_fiscale). ## Message format A message is conceptually very similar to an email and, in its simplest form, is composed of the following attributes: * A required `subject`: a short description of the topic. * A required `markdown` body: a Markdown representation of the body (see below on what Markdown tags are allowed). * An optional `payment_data`: in case the message is a payment request, the _payment data_ will enable the recipient to pay the requested amount via [PagoPA](https://www.agid.gov.it/it/piattaforme/pagopa). * An optional `due_date`: a _due date_ that let the recipient add a reminder when receiving the message. The format for all dates is [ISO8601](https://it.wikipedia.org/wiki/ISO_8601) with time information and UTC timezone (ie. \"2018-10-13T00:00:00.000Z\"). * An optional `feature_level_type`: the kind of the submitted message. It can be: - `STANDARD` for normal messages; - `ADVANCED` to enable premium features. Default is `STANDARD`. ## Allowed Markdown formatting Not all Markdown formatting is currently available. Currently you can use the following formatting: * Headings * Text stylings (bold, italic, etc...) * Lists (bullet and numbered) ## Sending a message to a citizen Not every citizen will be interested in what you have to say and not every citizen you want to communicate to will be registered on IO. For this reason, before sending a message you need to check whether the recipient is registered on the platform and that he has not yet opted out from receiving messages from you. The process for sending a message is made of 3 steps: 1. Call [getProfile](#operation/getProfile): if the profile does not exist (i.e. you get a 404 response) or if the recipient has opted-out from your service (the response contains `sender_allowed: false`), you cannot send the message and you must stop here. 1. Call [submitMessageforUser](#operation/submitMessageforUser) to submit a new message. 1. (optional) Call [getMessage](#operation/getMessage) to check whether the message has been notified to the recipient. - * - * The version of the OpenAPI document: 3.30.3 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -package it.gov.pagopa.receipt.pdf.notifier.generated.model; - -import com.google.gson.*; -import com.google.gson.annotations.SerializedName; -import com.google.gson.reflect.TypeToken; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; -import it.gov.pagopa.receipt.pdf.notifier.generated.client.JSON; - -import java.io.IOException; -import java.util.*; -import java.util.Map.Entry; - -/** - * Describes the citizen's profile, mostly interesting for preferences attributes. - */ -@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2023-06-23T14:54:01.440130+02:00[Europe/Rome]") -public class LimitedProfile { - public static final String SERIALIZED_NAME_SENDER_ALLOWED = "sender_allowed"; - @SerializedName(SERIALIZED_NAME_SENDER_ALLOWED) - private Boolean senderAllowed; - - public static final String SERIALIZED_NAME_PREFERRED_LANGUAGES = "preferred_languages"; - @SerializedName(SERIALIZED_NAME_PREFERRED_LANGUAGES) - private List preferredLanguages; - - public LimitedProfile() { - } - - public LimitedProfile senderAllowed(Boolean senderAllowed) { - - this.senderAllowed = senderAllowed; - return this; - } - - /** - * True in case the service that made the request can send messages to the user identified by this profile (false otherwise). - * @return senderAllowed - **/ - @javax.annotation.Nonnull - public Boolean getSenderAllowed() { - return senderAllowed; - } - - - public void setSenderAllowed(Boolean senderAllowed) { - this.senderAllowed = senderAllowed; - } - - - public LimitedProfile preferredLanguages(List preferredLanguages) { - - this.preferredLanguages = preferredLanguages; - return this; - } - - public LimitedProfile addPreferredLanguagesItem(String preferredLanguagesItem) { - if (this.preferredLanguages == null) { - this.preferredLanguages = new ArrayList<>(); - } - this.preferredLanguages.add(preferredLanguagesItem); - return this; - } - - /** - * Indicates the User's preferred written or spoken languages in order of preference. Generally used for selecting a localized User interface. Valid values are concatenation of the ISO 639-1 two letter language code, an underscore, and the ISO 3166-1 2 letter country code; e.g., 'en_US' specifies the language English and country US. - * @return preferredLanguages - **/ - @javax.annotation.Nullable - public List getPreferredLanguages() { - return preferredLanguages; - } - - - public void setPreferredLanguages(List preferredLanguages) { - this.preferredLanguages = preferredLanguages; - } - - - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - LimitedProfile limitedProfile = (LimitedProfile) o; - return Objects.equals(this.senderAllowed, limitedProfile.senderAllowed) && - Objects.equals(this.preferredLanguages, limitedProfile.preferredLanguages); - } - - @Override - public int hashCode() { - return Objects.hash(senderAllowed, preferredLanguages); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class LimitedProfile {\n"); - sb.append(" senderAllowed: ").append(toIndentedString(senderAllowed)).append("\n"); - sb.append(" preferredLanguages: ").append(toIndentedString(preferredLanguages)).append("\n"); - sb.append("}"); - return sb.toString(); - } - - /** - * Convert the given object to string with each line indented by 4 spaces - * (except the first line). - */ - private String toIndentedString(Object o) { - if (o == null) { - return "null"; - } - return o.toString().replace("\n", "\n "); - } - - - public static HashSet openapiFields; - public static HashSet openapiRequiredFields; - - static { - // a set of all properties/fields (JSON key names) - openapiFields = new HashSet(); - openapiFields.add("sender_allowed"); - openapiFields.add("preferred_languages"); - - // a set of required properties/fields (JSON key names) - openapiRequiredFields = new HashSet(); - openapiRequiredFields.add("sender_allowed"); - } - - /** - * Validates the JSON Object and throws an exception if issues found - * - * @param jsonObj JSON Object - * @throws IOException if the JSON Object is invalid with respect to LimitedProfile - */ - public static void validateJsonObject(JsonObject jsonObj) throws IOException { - if (jsonObj == null) { - if (!LimitedProfile.openapiRequiredFields.isEmpty()) { // has required fields but JSON object is null - throw new IllegalArgumentException(String.format("The required field(s) %s in LimitedProfile is not found in the empty JSON string", LimitedProfile.openapiRequiredFields.toString())); - } - } - - Set> entries = jsonObj.entrySet(); - // check to see if the JSON string contains additional fields - for (Entry entry : entries) { - if (!LimitedProfile.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `LimitedProfile` properties. JSON: %s", entry.getKey(), jsonObj.toString())); - } - } - - // check to make sure all required properties/fields are present in the JSON string - for (String requiredField : LimitedProfile.openapiRequiredFields) { - if (jsonObj.get(requiredField) == null) { - throw new IllegalArgumentException(String.format("The required field `%s` is not found in the JSON string: %s", requiredField, jsonObj.toString())); - } - } - // ensure the optional json data is an array if present - if (jsonObj.get("preferred_languages") != null && !jsonObj.get("preferred_languages").isJsonArray()) { - throw new IllegalArgumentException(String.format("Expected the field `preferred_languages` to be an array in the JSON string but got `%s`", jsonObj.get("preferred_languages").toString())); - } - } - - public static class CustomTypeAdapterFactory implements TypeAdapterFactory { - @SuppressWarnings("unchecked") - @Override - public TypeAdapter create(Gson gson, TypeToken type) { - if (!LimitedProfile.class.isAssignableFrom(type.getRawType())) { - return null; // this class only serializes 'LimitedProfile' and its subtypes - } - final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); - final TypeAdapter thisAdapter - = gson.getDelegateAdapter(this, TypeToken.get(LimitedProfile.class)); - - return (TypeAdapter) new TypeAdapter() { - @Override - public void write(JsonWriter out, LimitedProfile value) throws IOException { - JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); - elementAdapter.write(out, obj); - } - - @Override - public LimitedProfile read(JsonReader in) throws IOException { - JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject(); - validateJsonObject(jsonObj); - return thisAdapter.fromJsonTree(jsonObj); - } - - }.nullSafe(); - } - } - - /** - * Create an instance of LimitedProfile given an JSON string - * - * @param jsonString JSON string - * @return An instance of LimitedProfile - * @throws IOException if the JSON string is invalid with respect to LimitedProfile - */ - public static LimitedProfile fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, LimitedProfile.class); - } - - /** - * Convert an instance of LimitedProfile to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } -} - diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/MessageContent.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/MessageContent.java deleted file mode 100644 index b19a759..0000000 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/MessageContent.java +++ /dev/null @@ -1,324 +0,0 @@ -/* - * IO API for Public Administration Services - * # Warning **This is an experimental API that is (most probably) going to change as we evolve the IO platform.** # Introduction This is the documentation of the IO API for 3rd party services. This API enables Public Administration services to integrate with the IO platform. IO enables services to communicate with Italian citizens via the [IO app](https://io.italia.it/). # How to get an API key To get access to this API, you'll need to register on the [IO Developer Portal](https://developer.io.italia.it/). After the registration step, you have to click on the button that says `subscribe to the digital citizenship api` to receive the API key that you will use to authenticate the API calls. You will also receive an email with further instructions, including a fake Fiscal Code that you will be able to use to send test messages. Messages sent to the fake Fiscal Code will be notified to the email address used during the registration process on the developer portal. # Messages ## What is a message Messages are the primary form of communication enabled by the IO APIs. Messages are **personal** communications directed to a **specific citizen**. You will not be able to use this API to broadcast a message to a group of citizens, you will have to create and send a specific, personalized message to each citizen you want to communicate to. The recipient of the message (i.e. a citizen) is identified trough his [Fiscal Code](https://it.wikipedia.org/wiki/Codice_fiscale). ## Message format A message is conceptually very similar to an email and, in its simplest form, is composed of the following attributes: * A required `subject`: a short description of the topic. * A required `markdown` body: a Markdown representation of the body (see below on what Markdown tags are allowed). * An optional `payment_data`: in case the message is a payment request, the _payment data_ will enable the recipient to pay the requested amount via [PagoPA](https://www.agid.gov.it/it/piattaforme/pagopa). * An optional `due_date`: a _due date_ that let the recipient add a reminder when receiving the message. The format for all dates is [ISO8601](https://it.wikipedia.org/wiki/ISO_8601) with time information and UTC timezone (ie. \"2018-10-13T00:00:00.000Z\"). * An optional `feature_level_type`: the kind of the submitted message. It can be: - `STANDARD` for normal messages; - `ADVANCED` to enable premium features. Default is `STANDARD`. ## Allowed Markdown formatting Not all Markdown formatting is currently available. Currently you can use the following formatting: * Headings * Text stylings (bold, italic, etc...) * Lists (bullet and numbered) ## Sending a message to a citizen Not every citizen will be interested in what you have to say and not every citizen you want to communicate to will be registered on IO. For this reason, before sending a message you need to check whether the recipient is registered on the platform and that he has not yet opted out from receiving messages from you. The process for sending a message is made of 3 steps: 1. Call [getProfile](#operation/getProfile): if the profile does not exist (i.e. you get a 404 response) or if the recipient has opted-out from your service (the response contains `sender_allowed: false`), you cannot send the message and you must stop here. 1. Call [submitMessageforUser](#operation/submitMessageforUser) to submit a new message. 1. (optional) Call [getMessage](#operation/getMessage) to check whether the message has been notified to the recipient. - * - * The version of the OpenAPI document: 3.30.3 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -package it.gov.pagopa.receipt.pdf.notifier.generated.model; - -import com.google.gson.*; -import com.google.gson.annotations.SerializedName; -import com.google.gson.reflect.TypeToken; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; -import it.gov.pagopa.receipt.pdf.notifier.generated.client.JSON; - -import java.io.IOException; -import java.util.HashSet; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; - -/** - * MessageContent - */ -@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2023-06-23T14:54:01.440130+02:00[Europe/Rome]") -public class MessageContent { - public static final String SERIALIZED_NAME_SUBJECT = "subject"; - @SerializedName(SERIALIZED_NAME_SUBJECT) - private String subject; - - public static final String SERIALIZED_NAME_MARKDOWN = "markdown"; - @SerializedName(SERIALIZED_NAME_MARKDOWN) - private String markdown; - - public static final String SERIALIZED_NAME_PAYMENT_DATA = "payment_data"; - @SerializedName(SERIALIZED_NAME_PAYMENT_DATA) - private PaymentData paymentData; - - public static final String SERIALIZED_NAME_THIRD_PARTY_DATA = "third_party_data"; - @SerializedName(SERIALIZED_NAME_THIRD_PARTY_DATA) - private ThirdPartyData thirdPartyData; - - public static final String SERIALIZED_NAME_DUE_DATE = "due_date"; - @SerializedName(SERIALIZED_NAME_DUE_DATE) - private String dueDate; - - public MessageContent() { - } - - public MessageContent subject(String subject) { - - this.subject = subject; - return this; - } - - /** - * The (optional) subject of the message - note that only some notification channels support the display of a subject. When a subject is not provided, one gets generated from the client attributes. - * @return subject - **/ - @javax.annotation.Nonnull - public String getSubject() { - return subject; - } - - - public void setSubject(String subject) { - this.subject = subject; - } - - - public MessageContent markdown(String markdown) { - - this.markdown = markdown; - return this; - } - - /** - * The full version of the message, in plain text or Markdown format. The content of this field will be delivered to channels that don't have any limit in terms of content size (e.g. email, etc...). - * @return markdown - **/ - @javax.annotation.Nonnull - public String getMarkdown() { - return markdown; - } - - - public void setMarkdown(String markdown) { - this.markdown = markdown; - } - - - public MessageContent paymentData(PaymentData paymentData) { - - this.paymentData = paymentData; - return this; - } - - /** - * Get paymentData - * @return paymentData - **/ - @javax.annotation.Nullable - public PaymentData getPaymentData() { - return paymentData; - } - - - public void setPaymentData(PaymentData paymentData) { - this.paymentData = paymentData; - } - - public MessageContent thirdPartyData(ThirdPartyData thirdPartyData) { - - this.thirdPartyData = thirdPartyData; - return this; - } - - /** - * Get thirdPartyData - * @return thirdPartyData - **/ - @javax.annotation.Nullable - public ThirdPartyData getThirdPartyData() { - return thirdPartyData; - } - - - public void setThirdPartyData(ThirdPartyData thirdPartyData) { - this.thirdPartyData = thirdPartyData; - } - - - public MessageContent dueDate(String dueDate) { - - this.dueDate = dueDate; - return this; - } - - /** - * A date-time field in ISO-8601 format and UTC timezone. - * @return dueDate - **/ - @javax.annotation.Nullable - public String getDueDate() { - return dueDate; - } - - - public void setDueDate(String dueDate) { - this.dueDate = dueDate; - } - - - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - MessageContent messageContent = (MessageContent) o; - return Objects.equals(this.subject, messageContent.subject) && - Objects.equals(this.markdown, messageContent.markdown) && - Objects.equals(this.paymentData, messageContent.paymentData) && - Objects.equals(this.thirdPartyData, messageContent.thirdPartyData) && - Objects.equals(this.dueDate, messageContent.dueDate); - } - - @Override - public int hashCode() { - return Objects.hash(subject, markdown, paymentData, thirdPartyData, dueDate); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class MessageContent {\n"); - sb.append(" subject: ").append(toIndentedString(subject)).append("\n"); - sb.append(" markdown: ").append(toIndentedString(markdown)).append("\n"); - sb.append(" paymentData: ").append(toIndentedString(paymentData)).append("\n"); - sb.append(" thirdPartyData: ").append(toIndentedString(thirdPartyData)).append("\n"); - sb.append(" dueDate: ").append(toIndentedString(dueDate)).append("\n"); - sb.append("}"); - return sb.toString(); - } - - /** - * Convert the given object to string with each line indented by 4 spaces - * (except the first line). - */ - private String toIndentedString(Object o) { - if (o == null) { - return "null"; - } - return o.toString().replace("\n", "\n "); - } - - - public static HashSet openapiFields; - public static HashSet openapiRequiredFields; - - static { - // a set of all properties/fields (JSON key names) - openapiFields = new HashSet(); - openapiFields.add("subject"); - openapiFields.add("markdown"); - openapiFields.add("payment_data"); - openapiFields.add("prescription_data"); - openapiFields.add("legal_data"); - openapiFields.add("eu_covid_cert"); - openapiFields.add("third_party_data"); - openapiFields.add("due_date"); - - // a set of required properties/fields (JSON key names) - openapiRequiredFields = new HashSet(); - openapiRequiredFields.add("subject"); - openapiRequiredFields.add("markdown"); - } - - /** - * Validates the JSON Object and throws an exception if issues found - * - * @param jsonObj JSON Object - * @throws IOException if the JSON Object is invalid with respect to MessageContent - */ - public static void validateJsonObject(JsonObject jsonObj) throws IOException { - if (jsonObj == null) { - if (!MessageContent.openapiRequiredFields.isEmpty()) { // has required fields but JSON object is null - throw new IllegalArgumentException(String.format("The required field(s) %s in MessageContent is not found in the empty JSON string", MessageContent.openapiRequiredFields.toString())); - } - } - - Set> entries = jsonObj.entrySet(); - // check to see if the JSON string contains additional fields - for (Entry entry : entries) { - if (!MessageContent.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `MessageContent` properties. JSON: %s", entry.getKey(), jsonObj.toString())); - } - } - - // check to make sure all required properties/fields are present in the JSON string - for (String requiredField : MessageContent.openapiRequiredFields) { - if (jsonObj.get(requiredField) == null) { - throw new IllegalArgumentException(String.format("The required field `%s` is not found in the JSON string: %s", requiredField, jsonObj.toString())); - } - } - if (!jsonObj.get("subject").isJsonPrimitive()) { - throw new IllegalArgumentException(String.format("Expected the field `subject` to be a primitive type in the JSON string but got `%s`", jsonObj.get("subject").toString())); - } - if (!jsonObj.get("markdown").isJsonPrimitive()) { - throw new IllegalArgumentException(String.format("Expected the field `markdown` to be a primitive type in the JSON string but got `%s`", jsonObj.get("markdown").toString())); - } - // validate the optional field `payment_data` - if (jsonObj.get("payment_data") != null && !jsonObj.get("payment_data").isJsonNull()) { - PaymentData.validateJsonObject(jsonObj.getAsJsonObject("payment_data")); - } - // validate the optional field `third_party_data` - if (jsonObj.get("third_party_data") != null && !jsonObj.get("third_party_data").isJsonNull()) { - ThirdPartyData.validateJsonObject(jsonObj.getAsJsonObject("third_party_data")); - } - if ((jsonObj.get("due_date") != null && !jsonObj.get("due_date").isJsonNull()) && !jsonObj.get("due_date").isJsonPrimitive()) { - throw new IllegalArgumentException(String.format("Expected the field `due_date` to be a primitive type in the JSON string but got `%s`", jsonObj.get("due_date").toString())); - } - } - - public static class CustomTypeAdapterFactory implements TypeAdapterFactory { - @SuppressWarnings("unchecked") - @Override - public TypeAdapter create(Gson gson, TypeToken type) { - if (!MessageContent.class.isAssignableFrom(type.getRawType())) { - return null; // this class only serializes 'MessageContent' and its subtypes - } - final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); - final TypeAdapter thisAdapter - = gson.getDelegateAdapter(this, TypeToken.get(MessageContent.class)); - - return (TypeAdapter) new TypeAdapter() { - @Override - public void write(JsonWriter out, MessageContent value) throws IOException { - JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); - elementAdapter.write(out, obj); - } - - @Override - public MessageContent read(JsonReader in) throws IOException { - JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject(); - validateJsonObject(jsonObj); - return thisAdapter.fromJsonTree(jsonObj); - } - - }.nullSafe(); - } - } - - /** - * Create an instance of MessageContent given an JSON string - * - * @param jsonString JSON string - * @return An instance of MessageContent - * @throws IOException if the JSON string is invalid with respect to MessageContent - */ - public static MessageContent fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, MessageContent.class); - } - - /** - * Convert an instance of MessageContent to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } -} - diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/MessageContentAllOf.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/MessageContentAllOf.java deleted file mode 100644 index 2ad86fd..0000000 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/MessageContentAllOf.java +++ /dev/null @@ -1,255 +0,0 @@ -/* - * IO API for Public Administration Services - * # Warning **This is an experimental API that is (most probably) going to change as we evolve the IO platform.** # Introduction This is the documentation of the IO API for 3rd party services. This API enables Public Administration services to integrate with the IO platform. IO enables services to communicate with Italian citizens via the [IO app](https://io.italia.it/). # How to get an API key To get access to this API, you'll need to register on the [IO Developer Portal](https://developer.io.italia.it/). After the registration step, you have to click on the button that says `subscribe to the digital citizenship api` to receive the API key that you will use to authenticate the API calls. You will also receive an email with further instructions, including a fake Fiscal Code that you will be able to use to send test messages. Messages sent to the fake Fiscal Code will be notified to the email address used during the registration process on the developer portal. # Messages ## What is a message Messages are the primary form of communication enabled by the IO APIs. Messages are **personal** communications directed to a **specific citizen**. You will not be able to use this API to broadcast a message to a group of citizens, you will have to create and send a specific, personalized message to each citizen you want to communicate to. The recipient of the message (i.e. a citizen) is identified trough his [Fiscal Code](https://it.wikipedia.org/wiki/Codice_fiscale). ## Message format A message is conceptually very similar to an email and, in its simplest form, is composed of the following attributes: * A required `subject`: a short description of the topic. * A required `markdown` body: a Markdown representation of the body (see below on what Markdown tags are allowed). * An optional `payment_data`: in case the message is a payment request, the _payment data_ will enable the recipient to pay the requested amount via [PagoPA](https://www.agid.gov.it/it/piattaforme/pagopa). * An optional `due_date`: a _due date_ that let the recipient add a reminder when receiving the message. The format for all dates is [ISO8601](https://it.wikipedia.org/wiki/ISO_8601) with time information and UTC timezone (ie. \"2018-10-13T00:00:00.000Z\"). * An optional `feature_level_type`: the kind of the submitted message. It can be: - `STANDARD` for normal messages; - `ADVANCED` to enable premium features. Default is `STANDARD`. ## Allowed Markdown formatting Not all Markdown formatting is currently available. Currently you can use the following formatting: * Headings * Text stylings (bold, italic, etc...) * Lists (bullet and numbered) ## Sending a message to a citizen Not every citizen will be interested in what you have to say and not every citizen you want to communicate to will be registered on IO. For this reason, before sending a message you need to check whether the recipient is registered on the platform and that he has not yet opted out from receiving messages from you. The process for sending a message is made of 3 steps: 1. Call [getProfile](#operation/getProfile): if the profile does not exist (i.e. you get a 404 response) or if the recipient has opted-out from your service (the response contains `sender_allowed: false`), you cannot send the message and you must stop here. 1. Call [submitMessageforUser](#operation/submitMessageforUser) to submit a new message. 1. (optional) Call [getMessage](#operation/getMessage) to check whether the message has been notified to the recipient. - * - * The version of the OpenAPI document: 3.30.3 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -package it.gov.pagopa.receipt.pdf.notifier.generated.model; - -import com.google.gson.*; -import com.google.gson.annotations.SerializedName; -import com.google.gson.reflect.TypeToken; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; -import it.gov.pagopa.receipt.pdf.notifier.generated.client.JSON; - -import java.io.IOException; -import java.util.HashSet; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; - -/** - * MessageContentAllOf - */ -@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2023-06-23T14:54:01.440130+02:00[Europe/Rome]") -public class MessageContentAllOf { - public static final String SERIALIZED_NAME_PAYMENT_DATA = "payment_data"; - @SerializedName(SERIALIZED_NAME_PAYMENT_DATA) - private PaymentData paymentData; - - public static final String SERIALIZED_NAME_THIRD_PARTY_DATA = "third_party_data"; - @SerializedName(SERIALIZED_NAME_THIRD_PARTY_DATA) - private ThirdPartyData thirdPartyData; - - public static final String SERIALIZED_NAME_DUE_DATE = "due_date"; - @SerializedName(SERIALIZED_NAME_DUE_DATE) - private String dueDate; - - public MessageContentAllOf() { - } - - public MessageContentAllOf paymentData(PaymentData paymentData) { - - this.paymentData = paymentData; - return this; - } - - /** - * Get paymentData - * - * @return paymentData - **/ - @javax.annotation.Nullable - public PaymentData getPaymentData() { - return paymentData; - } - - - public void setPaymentData(PaymentData paymentData) { - this.paymentData = paymentData; - } - - public MessageContentAllOf thirdPartyData(ThirdPartyData thirdPartyData) { - - this.thirdPartyData = thirdPartyData; - return this; - } - - /** - * Get thirdPartyData - * - * @return thirdPartyData - **/ - @javax.annotation.Nullable - public ThirdPartyData getThirdPartyData() { - return thirdPartyData; - } - - - public void setThirdPartyData(ThirdPartyData thirdPartyData) { - this.thirdPartyData = thirdPartyData; - } - - - public MessageContentAllOf dueDate(String dueDate) { - - this.dueDate = dueDate; - return this; - } - - /** - * A date-time field in ISO-8601 format and UTC timezone. - * - * @return dueDate - **/ - @javax.annotation.Nullable - public String getDueDate() { - return dueDate; - } - - - public void setDueDate(String dueDate) { - this.dueDate = dueDate; - } - - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - MessageContentAllOf messageContentAllOf = (MessageContentAllOf) o; - return Objects.equals(this.paymentData, messageContentAllOf.paymentData) && - Objects.equals(this.thirdPartyData, messageContentAllOf.thirdPartyData) && - Objects.equals(this.dueDate, messageContentAllOf.dueDate); - } - - @Override - public int hashCode() { - return Objects.hash(paymentData, thirdPartyData, dueDate); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class MessageContentAllOf {\n"); - sb.append(" paymentData: ").append(toIndentedString(paymentData)).append("\n"); - sb.append(" thirdPartyData: ").append(toIndentedString(thirdPartyData)).append("\n"); - sb.append(" dueDate: ").append(toIndentedString(dueDate)).append("\n"); - sb.append("}"); - return sb.toString(); - } - - /** - * Convert the given object to string with each line indented by 4 spaces - * (except the first line). - */ - private String toIndentedString(Object o) { - if (o == null) { - return "null"; - } - return o.toString().replace("\n", "\n "); - } - - - public static HashSet openapiFields; - public static HashSet openapiRequiredFields; - - static { - // a set of all properties/fields (JSON key names) - openapiFields = new HashSet(); - openapiFields.add("payment_data"); - openapiFields.add("prescription_data"); - openapiFields.add("legal_data"); - openapiFields.add("eu_covid_cert"); - openapiFields.add("third_party_data"); - openapiFields.add("due_date"); - - // a set of required properties/fields (JSON key names) - openapiRequiredFields = new HashSet(); - } - - /** - * Validates the JSON Object and throws an exception if issues found - * - * @param jsonObj JSON Object - * @throws IOException if the JSON Object is invalid with respect to MessageContentAllOf - */ - public static void validateJsonObject(JsonObject jsonObj) throws IOException { - if (jsonObj == null) { - if (!MessageContentAllOf.openapiRequiredFields.isEmpty()) { // has required fields but JSON object is null - throw new IllegalArgumentException(String.format("The required field(s) %s in MessageContentAllOf is not found in the empty JSON string", MessageContentAllOf.openapiRequiredFields.toString())); - } - } - - Set> entries = jsonObj.entrySet(); - // check to see if the JSON string contains additional fields - for (Entry entry : entries) { - if (!MessageContentAllOf.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `MessageContentAllOf` properties. JSON: %s", entry.getKey(), jsonObj.toString())); - } - } - // validate the optional field `payment_data` - if (jsonObj.get("payment_data") != null && !jsonObj.get("payment_data").isJsonNull()) { - PaymentData.validateJsonObject(jsonObj.getAsJsonObject("payment_data")); - } - // validate the optional field `third_party_data` - if (jsonObj.get("third_party_data") != null && !jsonObj.get("third_party_data").isJsonNull()) { - ThirdPartyData.validateJsonObject(jsonObj.getAsJsonObject("third_party_data")); - } - if ((jsonObj.get("due_date") != null && !jsonObj.get("due_date").isJsonNull()) && !jsonObj.get("due_date").isJsonPrimitive()) { - throw new IllegalArgumentException(String.format("Expected the field `due_date` to be a primitive type in the JSON string but got `%s`", jsonObj.get("due_date").toString())); - } - } - - public static class CustomTypeAdapterFactory implements TypeAdapterFactory { - @SuppressWarnings("unchecked") - @Override - public TypeAdapter create(Gson gson, TypeToken type) { - if (!MessageContentAllOf.class.isAssignableFrom(type.getRawType())) { - return null; // this class only serializes 'MessageContentAllOf' and its subtypes - } - final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); - final TypeAdapter thisAdapter - = gson.getDelegateAdapter(this, TypeToken.get(MessageContentAllOf.class)); - - return (TypeAdapter) new TypeAdapter() { - @Override - public void write(JsonWriter out, MessageContentAllOf value) throws IOException { - JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); - elementAdapter.write(out, obj); - } - - @Override - public MessageContentAllOf read(JsonReader in) throws IOException { - JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject(); - validateJsonObject(jsonObj); - return thisAdapter.fromJsonTree(jsonObj); - } - - }.nullSafe(); - } - } - - /** - * Create an instance of MessageContentAllOf given an JSON string - * - * @param jsonString JSON string - * @return An instance of MessageContentAllOf - * @throws IOException if the JSON string is invalid with respect to MessageContentAllOf - */ - public static MessageContentAllOf fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, MessageContentAllOf.class); - } - - /** - * Convert an instance of MessageContentAllOf to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } -} - diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/MessageContentBase.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/MessageContentBase.java deleted file mode 100644 index 0cdf23f..0000000 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/MessageContentBase.java +++ /dev/null @@ -1,227 +0,0 @@ -/* - * IO API for Public Administration Services - * # Warning **This is an experimental API that is (most probably) going to change as we evolve the IO platform.** # Introduction This is the documentation of the IO API for 3rd party services. This API enables Public Administration services to integrate with the IO platform. IO enables services to communicate with Italian citizens via the [IO app](https://io.italia.it/). # How to get an API key To get access to this API, you'll need to register on the [IO Developer Portal](https://developer.io.italia.it/). After the registration step, you have to click on the button that says `subscribe to the digital citizenship api` to receive the API key that you will use to authenticate the API calls. You will also receive an email with further instructions, including a fake Fiscal Code that you will be able to use to send test messages. Messages sent to the fake Fiscal Code will be notified to the email address used during the registration process on the developer portal. # Messages ## What is a message Messages are the primary form of communication enabled by the IO APIs. Messages are **personal** communications directed to a **specific citizen**. You will not be able to use this API to broadcast a message to a group of citizens, you will have to create and send a specific, personalized message to each citizen you want to communicate to. The recipient of the message (i.e. a citizen) is identified trough his [Fiscal Code](https://it.wikipedia.org/wiki/Codice_fiscale). ## Message format A message is conceptually very similar to an email and, in its simplest form, is composed of the following attributes: * A required `subject`: a short description of the topic. * A required `markdown` body: a Markdown representation of the body (see below on what Markdown tags are allowed). * An optional `payment_data`: in case the message is a payment request, the _payment data_ will enable the recipient to pay the requested amount via [PagoPA](https://www.agid.gov.it/it/piattaforme/pagopa). * An optional `due_date`: a _due date_ that let the recipient add a reminder when receiving the message. The format for all dates is [ISO8601](https://it.wikipedia.org/wiki/ISO_8601) with time information and UTC timezone (ie. \"2018-10-13T00:00:00.000Z\"). * An optional `feature_level_type`: the kind of the submitted message. It can be: - `STANDARD` for normal messages; - `ADVANCED` to enable premium features. Default is `STANDARD`. ## Allowed Markdown formatting Not all Markdown formatting is currently available. Currently you can use the following formatting: * Headings * Text stylings (bold, italic, etc...) * Lists (bullet and numbered) ## Sending a message to a citizen Not every citizen will be interested in what you have to say and not every citizen you want to communicate to will be registered on IO. For this reason, before sending a message you need to check whether the recipient is registered on the platform and that he has not yet opted out from receiving messages from you. The process for sending a message is made of 3 steps: 1. Call [getProfile](#operation/getProfile): if the profile does not exist (i.e. you get a 404 response) or if the recipient has opted-out from your service (the response contains `sender_allowed: false`), you cannot send the message and you must stop here. 1. Call [submitMessageforUser](#operation/submitMessageforUser) to submit a new message. 1. (optional) Call [getMessage](#operation/getMessage) to check whether the message has been notified to the recipient. - * - * The version of the OpenAPI document: 3.30.3 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -package it.gov.pagopa.receipt.pdf.notifier.generated.model; - -import com.google.gson.*; -import com.google.gson.annotations.SerializedName; -import com.google.gson.reflect.TypeToken; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; -import it.gov.pagopa.receipt.pdf.notifier.generated.client.JSON; - -import java.io.IOException; -import java.util.HashSet; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; - -/** - * MessageContentBase - */ -@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2023-06-23T14:54:01.440130+02:00[Europe/Rome]") -public class MessageContentBase { - public static final String SERIALIZED_NAME_SUBJECT = "subject"; - @SerializedName(SERIALIZED_NAME_SUBJECT) - private String subject; - - public static final String SERIALIZED_NAME_MARKDOWN = "markdown"; - @SerializedName(SERIALIZED_NAME_MARKDOWN) - private String markdown; - - public MessageContentBase() { - } - - public MessageContentBase subject(String subject) { - - this.subject = subject; - return this; - } - - /** - * The (optional) subject of the message - note that only some notification channels support the display of a subject. When a subject is not provided, one gets generated from the client attributes. - * @return subject - **/ - @javax.annotation.Nonnull - public String getSubject() { - return subject; - } - - - public void setSubject(String subject) { - this.subject = subject; - } - - - public MessageContentBase markdown(String markdown) { - - this.markdown = markdown; - return this; - } - - /** - * The full version of the message, in plain text or Markdown format. The content of this field will be delivered to channels that don't have any limit in terms of content size (e.g. email, etc...). - * @return markdown - **/ - @javax.annotation.Nonnull - public String getMarkdown() { - return markdown; - } - - - public void setMarkdown(String markdown) { - this.markdown = markdown; - } - - - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - MessageContentBase messageContentBase = (MessageContentBase) o; - return Objects.equals(this.subject, messageContentBase.subject) && - Objects.equals(this.markdown, messageContentBase.markdown); - } - - @Override - public int hashCode() { - return Objects.hash(subject, markdown); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class MessageContentBase {\n"); - sb.append(" subject: ").append(toIndentedString(subject)).append("\n"); - sb.append(" markdown: ").append(toIndentedString(markdown)).append("\n"); - sb.append("}"); - return sb.toString(); - } - - /** - * Convert the given object to string with each line indented by 4 spaces - * (except the first line). - */ - private String toIndentedString(Object o) { - if (o == null) { - return "null"; - } - return o.toString().replace("\n", "\n "); - } - - - public static HashSet openapiFields; - public static HashSet openapiRequiredFields; - - static { - // a set of all properties/fields (JSON key names) - openapiFields = new HashSet(); - openapiFields.add("subject"); - openapiFields.add("markdown"); - - // a set of required properties/fields (JSON key names) - openapiRequiredFields = new HashSet(); - openapiRequiredFields.add("subject"); - openapiRequiredFields.add("markdown"); - } - - /** - * Validates the JSON Object and throws an exception if issues found - * - * @param jsonObj JSON Object - * @throws IOException if the JSON Object is invalid with respect to MessageContentBase - */ - public static void validateJsonObject(JsonObject jsonObj) throws IOException { - if (jsonObj == null) { - if (!MessageContentBase.openapiRequiredFields.isEmpty()) { // has required fields but JSON object is null - throw new IllegalArgumentException(String.format("The required field(s) %s in MessageContentBase is not found in the empty JSON string", MessageContentBase.openapiRequiredFields.toString())); - } - } - - Set> entries = jsonObj.entrySet(); - // check to see if the JSON string contains additional fields - for (Entry entry : entries) { - if (!MessageContentBase.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `MessageContentBase` properties. JSON: %s", entry.getKey(), jsonObj.toString())); - } - } - - // check to make sure all required properties/fields are present in the JSON string - for (String requiredField : MessageContentBase.openapiRequiredFields) { - if (jsonObj.get(requiredField) == null) { - throw new IllegalArgumentException(String.format("The required field `%s` is not found in the JSON string: %s", requiredField, jsonObj.toString())); - } - } - if (!jsonObj.get("subject").isJsonPrimitive()) { - throw new IllegalArgumentException(String.format("Expected the field `subject` to be a primitive type in the JSON string but got `%s`", jsonObj.get("subject").toString())); - } - if (!jsonObj.get("markdown").isJsonPrimitive()) { - throw new IllegalArgumentException(String.format("Expected the field `markdown` to be a primitive type in the JSON string but got `%s`", jsonObj.get("markdown").toString())); - } - } - - public static class CustomTypeAdapterFactory implements TypeAdapterFactory { - @SuppressWarnings("unchecked") - @Override - public TypeAdapter create(Gson gson, TypeToken type) { - if (!MessageContentBase.class.isAssignableFrom(type.getRawType())) { - return null; // this class only serializes 'MessageContentBase' and its subtypes - } - final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); - final TypeAdapter thisAdapter - = gson.getDelegateAdapter(this, TypeToken.get(MessageContentBase.class)); - - return (TypeAdapter) new TypeAdapter() { - @Override - public void write(JsonWriter out, MessageContentBase value) throws IOException { - JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); - elementAdapter.write(out, obj); - } - - @Override - public MessageContentBase read(JsonReader in) throws IOException { - JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject(); - validateJsonObject(jsonObj); - return thisAdapter.fromJsonTree(jsonObj); - } - - }.nullSafe(); - } - } - - /** - * Create an instance of MessageContentBase given an JSON string - * - * @param jsonString JSON string - * @return An instance of MessageContentBase - * @throws IOException if the JSON string is invalid with respect to MessageContentBase - */ - public static MessageContentBase fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, MessageContentBase.class); - } - - /** - * Convert an instance of MessageContentBase to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } -} - diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/NewMessage.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/NewMessage.java deleted file mode 100644 index 0c66b74..0000000 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/NewMessage.java +++ /dev/null @@ -1,288 +0,0 @@ -/* - * IO API for Public Administration Services - * # Warning **This is an experimental API that is (most probably) going to change as we evolve the IO platform.** # Introduction This is the documentation of the IO API for 3rd party services. This API enables Public Administration services to integrate with the IO platform. IO enables services to communicate with Italian citizens via the [IO app](https://io.italia.it/). # How to get an API key To get access to this API, you'll need to register on the [IO Developer Portal](https://developer.io.italia.it/). After the registration step, you have to click on the button that says `subscribe to the digital citizenship api` to receive the API key that you will use to authenticate the API calls. You will also receive an email with further instructions, including a fake Fiscal Code that you will be able to use to send test messages. Messages sent to the fake Fiscal Code will be notified to the email address used during the registration process on the developer portal. # Messages ## What is a message Messages are the primary form of communication enabled by the IO APIs. Messages are **personal** communications directed to a **specific citizen**. You will not be able to use this API to broadcast a message to a group of citizens, you will have to create and send a specific, personalized message to each citizen you want to communicate to. The recipient of the message (i.e. a citizen) is identified trough his [Fiscal Code](https://it.wikipedia.org/wiki/Codice_fiscale). ## Message format A message is conceptually very similar to an email and, in its simplest form, is composed of the following attributes: * A required `subject`: a short description of the topic. * A required `markdown` body: a Markdown representation of the body (see below on what Markdown tags are allowed). * An optional `payment_data`: in case the message is a payment request, the _payment data_ will enable the recipient to pay the requested amount via [PagoPA](https://www.agid.gov.it/it/piattaforme/pagopa). * An optional `due_date`: a _due date_ that let the recipient add a reminder when receiving the message. The format for all dates is [ISO8601](https://it.wikipedia.org/wiki/ISO_8601) with time information and UTC timezone (ie. \"2018-10-13T00:00:00.000Z\"). * An optional `feature_level_type`: the kind of the submitted message. It can be: - `STANDARD` for normal messages; - `ADVANCED` to enable premium features. Default is `STANDARD`. ## Allowed Markdown formatting Not all Markdown formatting is currently available. Currently you can use the following formatting: * Headings * Text stylings (bold, italic, etc...) * Lists (bullet and numbered) ## Sending a message to a citizen Not every citizen will be interested in what you have to say and not every citizen you want to communicate to will be registered on IO. For this reason, before sending a message you need to check whether the recipient is registered on the platform and that he has not yet opted out from receiving messages from you. The process for sending a message is made of 3 steps: 1. Call [getProfile](#operation/getProfile): if the profile does not exist (i.e. you get a 404 response) or if the recipient has opted-out from your service (the response contains `sender_allowed: false`), you cannot send the message and you must stop here. 1. Call [submitMessageforUser](#operation/submitMessageforUser) to submit a new message. 1. (optional) Call [getMessage](#operation/getMessage) to check whether the message has been notified to the recipient. - * - * The version of the OpenAPI document: 3.30.3 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -package it.gov.pagopa.receipt.pdf.notifier.generated.model; - -import com.google.gson.*; -import com.google.gson.annotations.SerializedName; -import com.google.gson.reflect.TypeToken; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; -import it.gov.pagopa.receipt.pdf.notifier.generated.client.JSON; - -import java.io.IOException; -import java.util.HashSet; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; - -/** - * NewMessage - */ -@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2023-06-23T14:54:01.440130+02:00[Europe/Rome]") -public class NewMessage { - public static final String SERIALIZED_NAME_TIME_TO_LIVE = "time_to_live"; - @SerializedName(SERIALIZED_NAME_TIME_TO_LIVE) - private Integer timeToLive = 3600; - - public static final String SERIALIZED_NAME_CONTENT = "content"; - @SerializedName(SERIALIZED_NAME_CONTENT) - private MessageContent content; - - public static final String SERIALIZED_NAME_FISCAL_CODE = "fiscal_code"; - @SerializedName(SERIALIZED_NAME_FISCAL_CODE) - private String fiscalCode; - - public static final String SERIALIZED_NAME_FEATURE_LEVEL_TYPE = "feature_level_type"; - @SerializedName(SERIALIZED_NAME_FEATURE_LEVEL_TYPE) - private String featureLevelType = "STANDARD"; - - public NewMessage() { - } - - public NewMessage timeToLive(Integer timeToLive) { - - this.timeToLive = timeToLive; - return this; - } - - /** - * This parameter specifies for how long (in seconds) the system will try to deliver the message to the channels configured by the user. - * minimum: 3600 - * maximum: 604800 - * @return timeToLive - **/ - @javax.annotation.Nullable - public Integer getTimeToLive() { - return timeToLive; - } - - - public void setTimeToLive(Integer timeToLive) { - this.timeToLive = timeToLive; - } - - - public NewMessage content(MessageContent content) { - - this.content = content; - return this; - } - - /** - * Get content - * @return content - **/ - @javax.annotation.Nonnull - public MessageContent getContent() { - return content; - } - - - public void setContent(MessageContent content) { - this.content = content; - } - - - public NewMessage fiscalCode(String fiscalCode) { - - this.fiscalCode = fiscalCode; - return this; - } - - /** - * User's fiscal code. - * @return fiscalCode - **/ - @javax.annotation.Nullable - public String getFiscalCode() { - return fiscalCode; - } - - - public void setFiscalCode(String fiscalCode) { - this.fiscalCode = fiscalCode; - } - - - public NewMessage featureLevelType(String featureLevelType) { - - this.featureLevelType = featureLevelType; - return this; - } - - /** - * Get featureLevelType - * @return featureLevelType - **/ - @javax.annotation.Nullable - public String getFeatureLevelType() { - return featureLevelType; - } - - - public void setFeatureLevelType(String featureLevelType) { - this.featureLevelType = featureLevelType; - } - - - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - NewMessage newMessage = (NewMessage) o; - return Objects.equals(this.timeToLive, newMessage.timeToLive) && - Objects.equals(this.content, newMessage.content) && - Objects.equals(this.fiscalCode, newMessage.fiscalCode) && - Objects.equals(this.featureLevelType, newMessage.featureLevelType); - } - - @Override - public int hashCode() { - return Objects.hash(timeToLive, content, fiscalCode, featureLevelType); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class NewMessage {\n"); - sb.append(" timeToLive: ").append(toIndentedString(timeToLive)).append("\n"); - sb.append(" content: ").append(toIndentedString(content)).append("\n"); - sb.append(" fiscalCode: ").append(toIndentedString(fiscalCode)).append("\n"); - sb.append(" featureLevelType: ").append(toIndentedString(featureLevelType)).append("\n"); - sb.append("}"); - return sb.toString(); - } - - /** - * Convert the given object to string with each line indented by 4 spaces - * (except the first line). - */ - private String toIndentedString(Object o) { - if (o == null) { - return "null"; - } - return o.toString().replace("\n", "\n "); - } - - - public static HashSet openapiFields; - public static HashSet openapiRequiredFields; - - static { - // a set of all properties/fields (JSON key names) - openapiFields = new HashSet(); - openapiFields.add("time_to_live"); - openapiFields.add("content"); - openapiFields.add("default_addresses"); - openapiFields.add("fiscal_code"); - openapiFields.add("feature_level_type"); - - // a set of required properties/fields (JSON key names) - openapiRequiredFields = new HashSet(); - openapiRequiredFields.add("content"); - } - - /** - * Validates the JSON Object and throws an exception if issues found - * - * @param jsonObj JSON Object - * @throws IOException if the JSON Object is invalid with respect to NewMessage - */ - public static void validateJsonObject(JsonObject jsonObj) throws IOException { - if (jsonObj == null) { - if (!NewMessage.openapiRequiredFields.isEmpty()) { // has required fields but JSON object is null - throw new IllegalArgumentException(String.format("The required field(s) %s in NewMessage is not found in the empty JSON string", NewMessage.openapiRequiredFields.toString())); - } - } - - Set> entries = jsonObj.entrySet(); - // check to see if the JSON string contains additional fields - for (Entry entry : entries) { - if (!NewMessage.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `NewMessage` properties. JSON: %s", entry.getKey(), jsonObj.toString())); - } - } - - // check to make sure all required properties/fields are present in the JSON string - for (String requiredField : NewMessage.openapiRequiredFields) { - if (jsonObj.get(requiredField) == null) { - throw new IllegalArgumentException(String.format("The required field `%s` is not found in the JSON string: %s", requiredField, jsonObj.toString())); - } - } - // validate the required field `content` - MessageContent.validateJsonObject(jsonObj.getAsJsonObject("content")); - // validate the optional field `default_addresses` - if ((jsonObj.get("fiscal_code") != null && !jsonObj.get("fiscal_code").isJsonNull()) && !jsonObj.get("fiscal_code").isJsonPrimitive()) { - throw new IllegalArgumentException(String.format("Expected the field `fiscal_code` to be a primitive type in the JSON string but got `%s`", jsonObj.get("fiscal_code").toString())); - } - if ((jsonObj.get("feature_level_type") != null && !jsonObj.get("feature_level_type").isJsonNull()) && !jsonObj.get("feature_level_type").isJsonPrimitive()) { - throw new IllegalArgumentException(String.format("Expected the field `feature_level_type` to be a primitive type in the JSON string but got `%s`", jsonObj.get("feature_level_type").toString())); - } - } - - public static class CustomTypeAdapterFactory implements TypeAdapterFactory { - @SuppressWarnings("unchecked") - @Override - public TypeAdapter create(Gson gson, TypeToken type) { - if (!NewMessage.class.isAssignableFrom(type.getRawType())) { - return null; // this class only serializes 'NewMessage' and its subtypes - } - final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); - final TypeAdapter thisAdapter - = gson.getDelegateAdapter(this, TypeToken.get(NewMessage.class)); - - return (TypeAdapter) new TypeAdapter() { - @Override - public void write(JsonWriter out, NewMessage value) throws IOException { - JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); - elementAdapter.write(out, obj); - } - - @Override - public NewMessage read(JsonReader in) throws IOException { - JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject(); - validateJsonObject(jsonObj); - return thisAdapter.fromJsonTree(jsonObj); - } - - }.nullSafe(); - } - } - - /** - * Create an instance of NewMessage given an JSON string - * - * @param jsonString JSON string - * @return An instance of NewMessage - * @throws IOException if the JSON string is invalid with respect to NewMessage - */ - public static NewMessage fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, NewMessage.class); - } - - /** - * Convert an instance of NewMessage to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } -} - diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/Payee.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/Payee.java deleted file mode 100644 index 53325c4..0000000 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/Payee.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * IO API for Public Administration Services - * # Warning **This is an experimental API that is (most probably) going to change as we evolve the IO platform.** # Introduction This is the documentation of the IO API for 3rd party services. This API enables Public Administration services to integrate with the IO platform. IO enables services to communicate with Italian citizens via the [IO app](https://io.italia.it/). # How to get an API key To get access to this API, you'll need to register on the [IO Developer Portal](https://developer.io.italia.it/). After the registration step, you have to click on the button that says `subscribe to the digital citizenship api` to receive the API key that you will use to authenticate the API calls. You will also receive an email with further instructions, including a fake Fiscal Code that you will be able to use to send test messages. Messages sent to the fake Fiscal Code will be notified to the email address used during the registration process on the developer portal. # Messages ## What is a message Messages are the primary form of communication enabled by the IO APIs. Messages are **personal** communications directed to a **specific citizen**. You will not be able to use this API to broadcast a message to a group of citizens, you will have to create and send a specific, personalized message to each citizen you want to communicate to. The recipient of the message (i.e. a citizen) is identified trough his [Fiscal Code](https://it.wikipedia.org/wiki/Codice_fiscale). ## Message format A message is conceptually very similar to an email and, in its simplest form, is composed of the following attributes: * A required `subject`: a short description of the topic. * A required `markdown` body: a Markdown representation of the body (see below on what Markdown tags are allowed). * An optional `payment_data`: in case the message is a payment request, the _payment data_ will enable the recipient to pay the requested amount via [PagoPA](https://www.agid.gov.it/it/piattaforme/pagopa). * An optional `due_date`: a _due date_ that let the recipient add a reminder when receiving the message. The format for all dates is [ISO8601](https://it.wikipedia.org/wiki/ISO_8601) with time information and UTC timezone (ie. \"2018-10-13T00:00:00.000Z\"). * An optional `feature_level_type`: the kind of the submitted message. It can be: - `STANDARD` for normal messages; - `ADVANCED` to enable premium features. Default is `STANDARD`. ## Allowed Markdown formatting Not all Markdown formatting is currently available. Currently you can use the following formatting: * Headings * Text stylings (bold, italic, etc...) * Lists (bullet and numbered) ## Sending a message to a citizen Not every citizen will be interested in what you have to say and not every citizen you want to communicate to will be registered on IO. For this reason, before sending a message you need to check whether the recipient is registered on the platform and that he has not yet opted out from receiving messages from you. The process for sending a message is made of 3 steps: 1. Call [getProfile](#operation/getProfile): if the profile does not exist (i.e. you get a 404 response) or if the recipient has opted-out from your service (the response contains `sender_allowed: false`), you cannot send the message and you must stop here. 1. Call [submitMessageforUser](#operation/submitMessageforUser) to submit a new message. 1. (optional) Call [getMessage](#operation/getMessage) to check whether the message has been notified to the recipient. - * - * The version of the OpenAPI document: 3.30.3 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -package it.gov.pagopa.receipt.pdf.notifier.generated.model; - -import com.google.gson.*; -import com.google.gson.annotations.SerializedName; -import com.google.gson.reflect.TypeToken; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; -import it.gov.pagopa.receipt.pdf.notifier.generated.client.JSON; - -import java.io.IOException; -import java.util.HashSet; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; - -/** - * Metadata needed to explicit payment's payee. - */ -@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2023-06-23T14:54:01.440130+02:00[Europe/Rome]") -public class Payee { - public static final String SERIALIZED_NAME_FISCAL_CODE = "fiscal_code"; - @SerializedName(SERIALIZED_NAME_FISCAL_CODE) - private String fiscalCode; - - public Payee() { - } - - public Payee fiscalCode(String fiscalCode) { - - this.fiscalCode = fiscalCode; - return this; - } - - /** - * Organization fiscal code. - * @return fiscalCode - **/ - @javax.annotation.Nonnull - public String getFiscalCode() { - return fiscalCode; - } - - - public void setFiscalCode(String fiscalCode) { - this.fiscalCode = fiscalCode; - } - - - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - Payee payee = (Payee) o; - return Objects.equals(this.fiscalCode, payee.fiscalCode); - } - - @Override - public int hashCode() { - return Objects.hash(fiscalCode); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class Payee {\n"); - sb.append(" fiscalCode: ").append(toIndentedString(fiscalCode)).append("\n"); - sb.append("}"); - return sb.toString(); - } - - /** - * Convert the given object to string with each line indented by 4 spaces - * (except the first line). - */ - private String toIndentedString(Object o) { - if (o == null) { - return "null"; - } - return o.toString().replace("\n", "\n "); - } - - - public static HashSet openapiFields; - public static HashSet openapiRequiredFields; - - static { - // a set of all properties/fields (JSON key names) - openapiFields = new HashSet(); - openapiFields.add("fiscal_code"); - - // a set of required properties/fields (JSON key names) - openapiRequiredFields = new HashSet(); - openapiRequiredFields.add("fiscal_code"); - } - - /** - * Validates the JSON Object and throws an exception if issues found - * - * @param jsonObj JSON Object - * @throws IOException if the JSON Object is invalid with respect to Payee - */ - public static void validateJsonObject(JsonObject jsonObj) throws IOException { - if (jsonObj == null) { - if (!Payee.openapiRequiredFields.isEmpty()) { // has required fields but JSON object is null - throw new IllegalArgumentException(String.format("The required field(s) %s in Payee is not found in the empty JSON string", Payee.openapiRequiredFields.toString())); - } - } - - Set> entries = jsonObj.entrySet(); - // check to see if the JSON string contains additional fields - for (Entry entry : entries) { - if (!Payee.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `Payee` properties. JSON: %s", entry.getKey(), jsonObj.toString())); - } - } - - // check to make sure all required properties/fields are present in the JSON string - for (String requiredField : Payee.openapiRequiredFields) { - if (jsonObj.get(requiredField) == null) { - throw new IllegalArgumentException(String.format("The required field `%s` is not found in the JSON string: %s", requiredField, jsonObj.toString())); - } - } - if (!jsonObj.get("fiscal_code").isJsonPrimitive()) { - throw new IllegalArgumentException(String.format("Expected the field `fiscal_code` to be a primitive type in the JSON string but got `%s`", jsonObj.get("fiscal_code").toString())); - } - } - - public static class CustomTypeAdapterFactory implements TypeAdapterFactory { - @SuppressWarnings("unchecked") - @Override - public TypeAdapter create(Gson gson, TypeToken type) { - if (!Payee.class.isAssignableFrom(type.getRawType())) { - return null; // this class only serializes 'Payee' and its subtypes - } - final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); - final TypeAdapter thisAdapter - = gson.getDelegateAdapter(this, TypeToken.get(Payee.class)); - - return (TypeAdapter) new TypeAdapter() { - @Override - public void write(JsonWriter out, Payee value) throws IOException { - JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); - elementAdapter.write(out, obj); - } - - @Override - public Payee read(JsonReader in) throws IOException { - JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject(); - validateJsonObject(jsonObj); - return thisAdapter.fromJsonTree(jsonObj); - } - - }.nullSafe(); - } - } - - /** - * Create an instance of Payee given an JSON string - * - * @param jsonString JSON string - * @return An instance of Payee - * @throws IOException if the JSON string is invalid with respect to Payee - */ - public static Payee fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, Payee.class); - } - - /** - * Convert an instance of Payee to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } -} - diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/PaymentData.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/PaymentData.java deleted file mode 100644 index aacb18a..0000000 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/PaymentData.java +++ /dev/null @@ -1,286 +0,0 @@ -/* - * IO API for Public Administration Services - * # Warning **This is an experimental API that is (most probably) going to change as we evolve the IO platform.** # Introduction This is the documentation of the IO API for 3rd party services. This API enables Public Administration services to integrate with the IO platform. IO enables services to communicate with Italian citizens via the [IO app](https://io.italia.it/). # How to get an API key To get access to this API, you'll need to register on the [IO Developer Portal](https://developer.io.italia.it/). After the registration step, you have to click on the button that says `subscribe to the digital citizenship api` to receive the API key that you will use to authenticate the API calls. You will also receive an email with further instructions, including a fake Fiscal Code that you will be able to use to send test messages. Messages sent to the fake Fiscal Code will be notified to the email address used during the registration process on the developer portal. # Messages ## What is a message Messages are the primary form of communication enabled by the IO APIs. Messages are **personal** communications directed to a **specific citizen**. You will not be able to use this API to broadcast a message to a group of citizens, you will have to create and send a specific, personalized message to each citizen you want to communicate to. The recipient of the message (i.e. a citizen) is identified trough his [Fiscal Code](https://it.wikipedia.org/wiki/Codice_fiscale). ## Message format A message is conceptually very similar to an email and, in its simplest form, is composed of the following attributes: * A required `subject`: a short description of the topic. * A required `markdown` body: a Markdown representation of the body (see below on what Markdown tags are allowed). * An optional `payment_data`: in case the message is a payment request, the _payment data_ will enable the recipient to pay the requested amount via [PagoPA](https://www.agid.gov.it/it/piattaforme/pagopa). * An optional `due_date`: a _due date_ that let the recipient add a reminder when receiving the message. The format for all dates is [ISO8601](https://it.wikipedia.org/wiki/ISO_8601) with time information and UTC timezone (ie. \"2018-10-13T00:00:00.000Z\"). * An optional `feature_level_type`: the kind of the submitted message. It can be: - `STANDARD` for normal messages; - `ADVANCED` to enable premium features. Default is `STANDARD`. ## Allowed Markdown formatting Not all Markdown formatting is currently available. Currently you can use the following formatting: * Headings * Text stylings (bold, italic, etc...) * Lists (bullet and numbered) ## Sending a message to a citizen Not every citizen will be interested in what you have to say and not every citizen you want to communicate to will be registered on IO. For this reason, before sending a message you need to check whether the recipient is registered on the platform and that he has not yet opted out from receiving messages from you. The process for sending a message is made of 3 steps: 1. Call [getProfile](#operation/getProfile): if the profile does not exist (i.e. you get a 404 response) or if the recipient has opted-out from your service (the response contains `sender_allowed: false`), you cannot send the message and you must stop here. 1. Call [submitMessageforUser](#operation/submitMessageforUser) to submit a new message. 1. (optional) Call [getMessage](#operation/getMessage) to check whether the message has been notified to the recipient. - * - * The version of the OpenAPI document: 3.30.3 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -package it.gov.pagopa.receipt.pdf.notifier.generated.model; - -import com.google.gson.*; -import com.google.gson.annotations.SerializedName; -import com.google.gson.reflect.TypeToken; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; -import it.gov.pagopa.receipt.pdf.notifier.generated.client.JSON; - -import java.io.IOException; -import java.util.HashSet; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; - -/** - * PaymentData - */ -@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2023-06-23T14:54:01.440130+02:00[Europe/Rome]") -public class PaymentData { - public static final String SERIALIZED_NAME_AMOUNT = "amount"; - @SerializedName(SERIALIZED_NAME_AMOUNT) - private Integer amount; - - public static final String SERIALIZED_NAME_NOTICE_NUMBER = "notice_number"; - @SerializedName(SERIALIZED_NAME_NOTICE_NUMBER) - private String noticeNumber; - - public static final String SERIALIZED_NAME_INVALID_AFTER_DUE_DATE = "invalid_after_due_date"; - @SerializedName(SERIALIZED_NAME_INVALID_AFTER_DUE_DATE) - private Boolean invalidAfterDueDate = false; - - public static final String SERIALIZED_NAME_PAYEE = "payee"; - @SerializedName(SERIALIZED_NAME_PAYEE) - private Payee payee; - - public PaymentData() { - } - - public PaymentData amount(Integer amount) { - - this.amount = amount; - return this; - } - - /** - * Amount of payment in euro cent. PagoPA accepts up to 9999999999 euro cents. - * minimum: 1 - * maximum: 9999999999 - * @return amount - **/ - @javax.annotation.Nonnull - public Integer getAmount() { - return amount; - } - - - public void setAmount(Integer amount) { - this.amount = amount; - } - - - public PaymentData noticeNumber(String noticeNumber) { - - this.noticeNumber = noticeNumber; - return this; - } - - /** - * The field [\"Numero Avviso\"](https://pagopa-specifichepagamenti.readthedocs.io/it/latest/_docs/Capitolo7.html#il-numero-avviso-e-larchivio-dei-pagamenti-in-attesa) of pagoPa, needed to identify the payment. Format is `<aux digit (1n)>[<application code> (2n)]<codice IUV (15|17n)>`. See [pagoPa specs](https://www.agid.gov.it/sites/default/files/repository_files/specifiche_attuative_pagamenti_1_3_1_0.pdf) for more info on this field and the IUV. - * @return noticeNumber - **/ - @javax.annotation.Nonnull - public String getNoticeNumber() { - return noticeNumber; - } - - - public void setNoticeNumber(String noticeNumber) { - this.noticeNumber = noticeNumber; - } - - - public PaymentData invalidAfterDueDate(Boolean invalidAfterDueDate) { - - this.invalidAfterDueDate = invalidAfterDueDate; - return this; - } - - /** - * Get invalidAfterDueDate - * @return invalidAfterDueDate - **/ - @javax.annotation.Nullable - public Boolean getInvalidAfterDueDate() { - return invalidAfterDueDate; - } - - - public void setInvalidAfterDueDate(Boolean invalidAfterDueDate) { - this.invalidAfterDueDate = invalidAfterDueDate; - } - - - public PaymentData payee(Payee payee) { - - this.payee = payee; - return this; - } - - /** - * Get payee - * @return payee - **/ - @javax.annotation.Nullable - public Payee getPayee() { - return payee; - } - - - public void setPayee(Payee payee) { - this.payee = payee; - } - - - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - PaymentData paymentData = (PaymentData) o; - return Objects.equals(this.amount, paymentData.amount) && - Objects.equals(this.noticeNumber, paymentData.noticeNumber) && - Objects.equals(this.invalidAfterDueDate, paymentData.invalidAfterDueDate) && - Objects.equals(this.payee, paymentData.payee); - } - - @Override - public int hashCode() { - return Objects.hash(amount, noticeNumber, invalidAfterDueDate, payee); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class PaymentData {\n"); - sb.append(" amount: ").append(toIndentedString(amount)).append("\n"); - sb.append(" noticeNumber: ").append(toIndentedString(noticeNumber)).append("\n"); - sb.append(" invalidAfterDueDate: ").append(toIndentedString(invalidAfterDueDate)).append("\n"); - sb.append(" payee: ").append(toIndentedString(payee)).append("\n"); - sb.append("}"); - return sb.toString(); - } - - /** - * Convert the given object to string with each line indented by 4 spaces - * (except the first line). - */ - private String toIndentedString(Object o) { - if (o == null) { - return "null"; - } - return o.toString().replace("\n", "\n "); - } - - - public static HashSet openapiFields; - public static HashSet openapiRequiredFields; - - static { - // a set of all properties/fields (JSON key names) - openapiFields = new HashSet(); - openapiFields.add("amount"); - openapiFields.add("notice_number"); - openapiFields.add("invalid_after_due_date"); - openapiFields.add("payee"); - - // a set of required properties/fields (JSON key names) - openapiRequiredFields = new HashSet(); - openapiRequiredFields.add("amount"); - openapiRequiredFields.add("notice_number"); - } - - /** - * Validates the JSON Object and throws an exception if issues found - * - * @param jsonObj JSON Object - * @throws IOException if the JSON Object is invalid with respect to PaymentData - */ - public static void validateJsonObject(JsonObject jsonObj) throws IOException { - if (jsonObj == null) { - if (!PaymentData.openapiRequiredFields.isEmpty()) { // has required fields but JSON object is null - throw new IllegalArgumentException(String.format("The required field(s) %s in PaymentData is not found in the empty JSON string", PaymentData.openapiRequiredFields.toString())); - } - } - - Set> entries = jsonObj.entrySet(); - // check to see if the JSON string contains additional fields - for (Entry entry : entries) { - if (!PaymentData.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `PaymentData` properties. JSON: %s", entry.getKey(), jsonObj.toString())); - } - } - - // check to make sure all required properties/fields are present in the JSON string - for (String requiredField : PaymentData.openapiRequiredFields) { - if (jsonObj.get(requiredField) == null) { - throw new IllegalArgumentException(String.format("The required field `%s` is not found in the JSON string: %s", requiredField, jsonObj.toString())); - } - } - if (!jsonObj.get("notice_number").isJsonPrimitive()) { - throw new IllegalArgumentException(String.format("Expected the field `notice_number` to be a primitive type in the JSON string but got `%s`", jsonObj.get("notice_number").toString())); - } - // validate the optional field `payee` - if (jsonObj.get("payee") != null && !jsonObj.get("payee").isJsonNull()) { - Payee.validateJsonObject(jsonObj.getAsJsonObject("payee")); - } - } - - public static class CustomTypeAdapterFactory implements TypeAdapterFactory { - @SuppressWarnings("unchecked") - @Override - public TypeAdapter create(Gson gson, TypeToken type) { - if (!PaymentData.class.isAssignableFrom(type.getRawType())) { - return null; // this class only serializes 'PaymentData' and its subtypes - } - final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); - final TypeAdapter thisAdapter - = gson.getDelegateAdapter(this, TypeToken.get(PaymentData.class)); - - return (TypeAdapter) new TypeAdapter() { - @Override - public void write(JsonWriter out, PaymentData value) throws IOException { - JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); - elementAdapter.write(out, obj); - } - - @Override - public PaymentData read(JsonReader in) throws IOException { - JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject(); - validateJsonObject(jsonObj); - return thisAdapter.fromJsonTree(jsonObj); - } - - }.nullSafe(); - } - } - - /** - * Create an instance of PaymentData given an JSON string - * - * @param jsonString JSON string - * @return An instance of PaymentData - * @throws IOException if the JSON string is invalid with respect to PaymentData - */ - public static PaymentData fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, PaymentData.class); - } - - /** - * Convert an instance of PaymentData to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } -} - diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/PaymentDataAllOf.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/PaymentDataAllOf.java deleted file mode 100644 index 22bf1c3..0000000 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/PaymentDataAllOf.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * IO API for Public Administration Services - * # Warning **This is an experimental API that is (most probably) going to change as we evolve the IO platform.** # Introduction This is the documentation of the IO API for 3rd party services. This API enables Public Administration services to integrate with the IO platform. IO enables services to communicate with Italian citizens via the [IO app](https://io.italia.it/). # How to get an API key To get access to this API, you'll need to register on the [IO Developer Portal](https://developer.io.italia.it/). After the registration step, you have to click on the button that says `subscribe to the digital citizenship api` to receive the API key that you will use to authenticate the API calls. You will also receive an email with further instructions, including a fake Fiscal Code that you will be able to use to send test messages. Messages sent to the fake Fiscal Code will be notified to the email address used during the registration process on the developer portal. # Messages ## What is a message Messages are the primary form of communication enabled by the IO APIs. Messages are **personal** communications directed to a **specific citizen**. You will not be able to use this API to broadcast a message to a group of citizens, you will have to create and send a specific, personalized message to each citizen you want to communicate to. The recipient of the message (i.e. a citizen) is identified trough his [Fiscal Code](https://it.wikipedia.org/wiki/Codice_fiscale). ## Message format A message is conceptually very similar to an email and, in its simplest form, is composed of the following attributes: * A required `subject`: a short description of the topic. * A required `markdown` body: a Markdown representation of the body (see below on what Markdown tags are allowed). * An optional `payment_data`: in case the message is a payment request, the _payment data_ will enable the recipient to pay the requested amount via [PagoPA](https://www.agid.gov.it/it/piattaforme/pagopa). * An optional `due_date`: a _due date_ that let the recipient add a reminder when receiving the message. The format for all dates is [ISO8601](https://it.wikipedia.org/wiki/ISO_8601) with time information and UTC timezone (ie. \"2018-10-13T00:00:00.000Z\"). * An optional `feature_level_type`: the kind of the submitted message. It can be: - `STANDARD` for normal messages; - `ADVANCED` to enable premium features. Default is `STANDARD`. ## Allowed Markdown formatting Not all Markdown formatting is currently available. Currently you can use the following formatting: * Headings * Text stylings (bold, italic, etc...) * Lists (bullet and numbered) ## Sending a message to a citizen Not every citizen will be interested in what you have to say and not every citizen you want to communicate to will be registered on IO. For this reason, before sending a message you need to check whether the recipient is registered on the platform and that he has not yet opted out from receiving messages from you. The process for sending a message is made of 3 steps: 1. Call [getProfile](#operation/getProfile): if the profile does not exist (i.e. you get a 404 response) or if the recipient has opted-out from your service (the response contains `sender_allowed: false`), you cannot send the message and you must stop here. 1. Call [submitMessageforUser](#operation/submitMessageforUser) to submit a new message. 1. (optional) Call [getMessage](#operation/getMessage) to check whether the message has been notified to the recipient. - * - * The version of the OpenAPI document: 3.30.3 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -package it.gov.pagopa.receipt.pdf.notifier.generated.model; - -import com.google.gson.*; -import com.google.gson.annotations.SerializedName; -import com.google.gson.reflect.TypeToken; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; -import it.gov.pagopa.receipt.pdf.notifier.generated.client.JSON; - -import java.io.IOException; -import java.util.HashSet; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; - -/** - * PaymentDataAllOf - */ -@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2023-06-23T14:54:01.440130+02:00[Europe/Rome]") -public class PaymentDataAllOf { - public static final String SERIALIZED_NAME_PAYEE = "payee"; - @SerializedName(SERIALIZED_NAME_PAYEE) - private Payee payee; - - public PaymentDataAllOf() { - } - - public PaymentDataAllOf payee(Payee payee) { - - this.payee = payee; - return this; - } - - /** - * Get payee - * @return payee - **/ - @javax.annotation.Nullable - public Payee getPayee() { - return payee; - } - - - public void setPayee(Payee payee) { - this.payee = payee; - } - - - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - PaymentDataAllOf paymentDataAllOf = (PaymentDataAllOf) o; - return Objects.equals(this.payee, paymentDataAllOf.payee); - } - - @Override - public int hashCode() { - return Objects.hash(payee); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class PaymentDataAllOf {\n"); - sb.append(" payee: ").append(toIndentedString(payee)).append("\n"); - sb.append("}"); - return sb.toString(); - } - - /** - * Convert the given object to string with each line indented by 4 spaces - * (except the first line). - */ - private String toIndentedString(Object o) { - if (o == null) { - return "null"; - } - return o.toString().replace("\n", "\n "); - } - - - public static HashSet openapiFields; - public static HashSet openapiRequiredFields; - - static { - // a set of all properties/fields (JSON key names) - openapiFields = new HashSet(); - openapiFields.add("payee"); - - // a set of required properties/fields (JSON key names) - openapiRequiredFields = new HashSet(); - } - - /** - * Validates the JSON Object and throws an exception if issues found - * - * @param jsonObj JSON Object - * @throws IOException if the JSON Object is invalid with respect to PaymentDataAllOf - */ - public static void validateJsonObject(JsonObject jsonObj) throws IOException { - if (jsonObj == null) { - if (!PaymentDataAllOf.openapiRequiredFields.isEmpty()) { // has required fields but JSON object is null - throw new IllegalArgumentException(String.format("The required field(s) %s in PaymentDataAllOf is not found in the empty JSON string", PaymentDataAllOf.openapiRequiredFields.toString())); - } - } - - Set> entries = jsonObj.entrySet(); - // check to see if the JSON string contains additional fields - for (Entry entry : entries) { - if (!PaymentDataAllOf.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `PaymentDataAllOf` properties. JSON: %s", entry.getKey(), jsonObj.toString())); - } - } - // validate the optional field `payee` - if (jsonObj.get("payee") != null && !jsonObj.get("payee").isJsonNull()) { - Payee.validateJsonObject(jsonObj.getAsJsonObject("payee")); - } - } - - public static class CustomTypeAdapterFactory implements TypeAdapterFactory { - @SuppressWarnings("unchecked") - @Override - public TypeAdapter create(Gson gson, TypeToken type) { - if (!PaymentDataAllOf.class.isAssignableFrom(type.getRawType())) { - return null; // this class only serializes 'PaymentDataAllOf' and its subtypes - } - final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); - final TypeAdapter thisAdapter - = gson.getDelegateAdapter(this, TypeToken.get(PaymentDataAllOf.class)); - - return (TypeAdapter) new TypeAdapter() { - @Override - public void write(JsonWriter out, PaymentDataAllOf value) throws IOException { - JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); - elementAdapter.write(out, obj); - } - - @Override - public PaymentDataAllOf read(JsonReader in) throws IOException { - JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject(); - validateJsonObject(jsonObj); - return thisAdapter.fromJsonTree(jsonObj); - } - - }.nullSafe(); - } - } - - /** - * Create an instance of PaymentDataAllOf given an JSON string - * - * @param jsonString JSON string - * @return An instance of PaymentDataAllOf - * @throws IOException if the JSON string is invalid with respect to PaymentDataAllOf - */ - public static PaymentDataAllOf fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, PaymentDataAllOf.class); - } - - /** - * Convert an instance of PaymentDataAllOf to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } -} - diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/PaymentDataBase.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/PaymentDataBase.java deleted file mode 100644 index c8d376b..0000000 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/PaymentDataBase.java +++ /dev/null @@ -1,254 +0,0 @@ -/* - * IO API for Public Administration Services - * # Warning **This is an experimental API that is (most probably) going to change as we evolve the IO platform.** # Introduction This is the documentation of the IO API for 3rd party services. This API enables Public Administration services to integrate with the IO platform. IO enables services to communicate with Italian citizens via the [IO app](https://io.italia.it/). # How to get an API key To get access to this API, you'll need to register on the [IO Developer Portal](https://developer.io.italia.it/). After the registration step, you have to click on the button that says `subscribe to the digital citizenship api` to receive the API key that you will use to authenticate the API calls. You will also receive an email with further instructions, including a fake Fiscal Code that you will be able to use to send test messages. Messages sent to the fake Fiscal Code will be notified to the email address used during the registration process on the developer portal. # Messages ## What is a message Messages are the primary form of communication enabled by the IO APIs. Messages are **personal** communications directed to a **specific citizen**. You will not be able to use this API to broadcast a message to a group of citizens, you will have to create and send a specific, personalized message to each citizen you want to communicate to. The recipient of the message (i.e. a citizen) is identified trough his [Fiscal Code](https://it.wikipedia.org/wiki/Codice_fiscale). ## Message format A message is conceptually very similar to an email and, in its simplest form, is composed of the following attributes: * A required `subject`: a short description of the topic. * A required `markdown` body: a Markdown representation of the body (see below on what Markdown tags are allowed). * An optional `payment_data`: in case the message is a payment request, the _payment data_ will enable the recipient to pay the requested amount via [PagoPA](https://www.agid.gov.it/it/piattaforme/pagopa). * An optional `due_date`: a _due date_ that let the recipient add a reminder when receiving the message. The format for all dates is [ISO8601](https://it.wikipedia.org/wiki/ISO_8601) with time information and UTC timezone (ie. \"2018-10-13T00:00:00.000Z\"). * An optional `feature_level_type`: the kind of the submitted message. It can be: - `STANDARD` for normal messages; - `ADVANCED` to enable premium features. Default is `STANDARD`. ## Allowed Markdown formatting Not all Markdown formatting is currently available. Currently you can use the following formatting: * Headings * Text stylings (bold, italic, etc...) * Lists (bullet and numbered) ## Sending a message to a citizen Not every citizen will be interested in what you have to say and not every citizen you want to communicate to will be registered on IO. For this reason, before sending a message you need to check whether the recipient is registered on the platform and that he has not yet opted out from receiving messages from you. The process for sending a message is made of 3 steps: 1. Call [getProfile](#operation/getProfile): if the profile does not exist (i.e. you get a 404 response) or if the recipient has opted-out from your service (the response contains `sender_allowed: false`), you cannot send the message and you must stop here. 1. Call [submitMessageforUser](#operation/submitMessageforUser) to submit a new message. 1. (optional) Call [getMessage](#operation/getMessage) to check whether the message has been notified to the recipient. - * - * The version of the OpenAPI document: 3.30.3 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -package it.gov.pagopa.receipt.pdf.notifier.generated.model; - -import com.google.gson.*; -import com.google.gson.annotations.SerializedName; -import com.google.gson.reflect.TypeToken; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; -import it.gov.pagopa.receipt.pdf.notifier.generated.client.JSON; - -import java.io.IOException; -import java.util.HashSet; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; - -/** - * Metadata needed to process pagoPA payments. - */ -@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2023-06-23T14:54:01.440130+02:00[Europe/Rome]") -public class PaymentDataBase { - public static final String SERIALIZED_NAME_AMOUNT = "amount"; - @SerializedName(SERIALIZED_NAME_AMOUNT) - private Integer amount; - - public static final String SERIALIZED_NAME_NOTICE_NUMBER = "notice_number"; - @SerializedName(SERIALIZED_NAME_NOTICE_NUMBER) - private String noticeNumber; - - public static final String SERIALIZED_NAME_INVALID_AFTER_DUE_DATE = "invalid_after_due_date"; - @SerializedName(SERIALIZED_NAME_INVALID_AFTER_DUE_DATE) - private Boolean invalidAfterDueDate = false; - - public PaymentDataBase() { - } - - public PaymentDataBase amount(Integer amount) { - - this.amount = amount; - return this; - } - - /** - * Amount of payment in euro cent. PagoPA accepts up to 9999999999 euro cents. - * minimum: 1 - * maximum: 9999999999 - * @return amount - **/ - @javax.annotation.Nonnull - public Integer getAmount() { - return amount; - } - - - public void setAmount(Integer amount) { - this.amount = amount; - } - - - public PaymentDataBase noticeNumber(String noticeNumber) { - - this.noticeNumber = noticeNumber; - return this; - } - - /** - * The field [\"Numero Avviso\"](https://pagopa-specifichepagamenti.readthedocs.io/it/latest/_docs/Capitolo7.html#il-numero-avviso-e-larchivio-dei-pagamenti-in-attesa) of pagoPa, needed to identify the payment. Format is `<aux digit (1n)>[<application code> (2n)]<codice IUV (15|17n)>`. See [pagoPa specs](https://www.agid.gov.it/sites/default/files/repository_files/specifiche_attuative_pagamenti_1_3_1_0.pdf) for more info on this field and the IUV. - * @return noticeNumber - **/ - @javax.annotation.Nonnull - public String getNoticeNumber() { - return noticeNumber; - } - - - public void setNoticeNumber(String noticeNumber) { - this.noticeNumber = noticeNumber; - } - - - public PaymentDataBase invalidAfterDueDate(Boolean invalidAfterDueDate) { - - this.invalidAfterDueDate = invalidAfterDueDate; - return this; - } - - /** - * Get invalidAfterDueDate - * @return invalidAfterDueDate - **/ - @javax.annotation.Nullable - public Boolean getInvalidAfterDueDate() { - return invalidAfterDueDate; - } - - - public void setInvalidAfterDueDate(Boolean invalidAfterDueDate) { - this.invalidAfterDueDate = invalidAfterDueDate; - } - - - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - PaymentDataBase paymentDataBase = (PaymentDataBase) o; - return Objects.equals(this.amount, paymentDataBase.amount) && - Objects.equals(this.noticeNumber, paymentDataBase.noticeNumber) && - Objects.equals(this.invalidAfterDueDate, paymentDataBase.invalidAfterDueDate); - } - - @Override - public int hashCode() { - return Objects.hash(amount, noticeNumber, invalidAfterDueDate); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class PaymentDataBase {\n"); - sb.append(" amount: ").append(toIndentedString(amount)).append("\n"); - sb.append(" noticeNumber: ").append(toIndentedString(noticeNumber)).append("\n"); - sb.append(" invalidAfterDueDate: ").append(toIndentedString(invalidAfterDueDate)).append("\n"); - sb.append("}"); - return sb.toString(); - } - - /** - * Convert the given object to string with each line indented by 4 spaces - * (except the first line). - */ - private String toIndentedString(Object o) { - if (o == null) { - return "null"; - } - return o.toString().replace("\n", "\n "); - } - - - public static HashSet openapiFields; - public static HashSet openapiRequiredFields; - - static { - // a set of all properties/fields (JSON key names) - openapiFields = new HashSet(); - openapiFields.add("amount"); - openapiFields.add("notice_number"); - openapiFields.add("invalid_after_due_date"); - - // a set of required properties/fields (JSON key names) - openapiRequiredFields = new HashSet(); - openapiRequiredFields.add("amount"); - openapiRequiredFields.add("notice_number"); - } - - /** - * Validates the JSON Object and throws an exception if issues found - * - * @param jsonObj JSON Object - * @throws IOException if the JSON Object is invalid with respect to PaymentDataBase - */ - public static void validateJsonObject(JsonObject jsonObj) throws IOException { - if (jsonObj == null) { - if (!PaymentDataBase.openapiRequiredFields.isEmpty()) { // has required fields but JSON object is null - throw new IllegalArgumentException(String.format("The required field(s) %s in PaymentDataBase is not found in the empty JSON string", PaymentDataBase.openapiRequiredFields.toString())); - } - } - - Set> entries = jsonObj.entrySet(); - // check to see if the JSON string contains additional fields - for (Entry entry : entries) { - if (!PaymentDataBase.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `PaymentDataBase` properties. JSON: %s", entry.getKey(), jsonObj.toString())); - } - } - - // check to make sure all required properties/fields are present in the JSON string - for (String requiredField : PaymentDataBase.openapiRequiredFields) { - if (jsonObj.get(requiredField) == null) { - throw new IllegalArgumentException(String.format("The required field `%s` is not found in the JSON string: %s", requiredField, jsonObj.toString())); - } - } - if (!jsonObj.get("notice_number").isJsonPrimitive()) { - throw new IllegalArgumentException(String.format("Expected the field `notice_number` to be a primitive type in the JSON string but got `%s`", jsonObj.get("notice_number").toString())); - } - } - - public static class CustomTypeAdapterFactory implements TypeAdapterFactory { - @SuppressWarnings("unchecked") - @Override - public TypeAdapter create(Gson gson, TypeToken type) { - if (!PaymentDataBase.class.isAssignableFrom(type.getRawType())) { - return null; // this class only serializes 'PaymentDataBase' and its subtypes - } - final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); - final TypeAdapter thisAdapter - = gson.getDelegateAdapter(this, TypeToken.get(PaymentDataBase.class)); - - return (TypeAdapter) new TypeAdapter() { - @Override - public void write(JsonWriter out, PaymentDataBase value) throws IOException { - JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); - elementAdapter.write(out, obj); - } - - @Override - public PaymentDataBase read(JsonReader in) throws IOException { - JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject(); - validateJsonObject(jsonObj); - return thisAdapter.fromJsonTree(jsonObj); - } - - }.nullSafe(); - } - } - - /** - * Create an instance of PaymentDataBase given an JSON string - * - * @param jsonString JSON string - * @return An instance of PaymentDataBase - * @throws IOException if the JSON string is invalid with respect to PaymentDataBase - */ - public static PaymentDataBase fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, PaymentDataBase.class); - } - - /** - * Convert an instance of PaymentDataBase to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } -} - diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/ProblemJson.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/ProblemJson.java deleted file mode 100644 index ee1c187..0000000 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/ProblemJson.java +++ /dev/null @@ -1,311 +0,0 @@ -/* - * IO API for Public Administration Services - * # Warning **This is an experimental API that is (most probably) going to change as we evolve the IO platform.** # Introduction This is the documentation of the IO API for 3rd party services. This API enables Public Administration services to integrate with the IO platform. IO enables services to communicate with Italian citizens via the [IO app](https://io.italia.it/). # How to get an API key To get access to this API, you'll need to register on the [IO Developer Portal](https://developer.io.italia.it/). After the registration step, you have to click on the button that says `subscribe to the digital citizenship api` to receive the API key that you will use to authenticate the API calls. You will also receive an email with further instructions, including a fake Fiscal Code that you will be able to use to send test messages. Messages sent to the fake Fiscal Code will be notified to the email address used during the registration process on the developer portal. # Messages ## What is a message Messages are the primary form of communication enabled by the IO APIs. Messages are **personal** communications directed to a **specific citizen**. You will not be able to use this API to broadcast a message to a group of citizens, you will have to create and send a specific, personalized message to each citizen you want to communicate to. The recipient of the message (i.e. a citizen) is identified trough his [Fiscal Code](https://it.wikipedia.org/wiki/Codice_fiscale). ## Message format A message is conceptually very similar to an email and, in its simplest form, is composed of the following attributes: * A required `subject`: a short description of the topic. * A required `markdown` body: a Markdown representation of the body (see below on what Markdown tags are allowed). * An optional `payment_data`: in case the message is a payment request, the _payment data_ will enable the recipient to pay the requested amount via [PagoPA](https://www.agid.gov.it/it/piattaforme/pagopa). * An optional `due_date`: a _due date_ that let the recipient add a reminder when receiving the message. The format for all dates is [ISO8601](https://it.wikipedia.org/wiki/ISO_8601) with time information and UTC timezone (ie. \"2018-10-13T00:00:00.000Z\"). * An optional `feature_level_type`: the kind of the submitted message. It can be: - `STANDARD` for normal messages; - `ADVANCED` to enable premium features. Default is `STANDARD`. ## Allowed Markdown formatting Not all Markdown formatting is currently available. Currently you can use the following formatting: * Headings * Text stylings (bold, italic, etc...) * Lists (bullet and numbered) ## Sending a message to a citizen Not every citizen will be interested in what you have to say and not every citizen you want to communicate to will be registered on IO. For this reason, before sending a message you need to check whether the recipient is registered on the platform and that he has not yet opted out from receiving messages from you. The process for sending a message is made of 3 steps: 1. Call [getProfile](#operation/getProfile): if the profile does not exist (i.e. you get a 404 response) or if the recipient has opted-out from your service (the response contains `sender_allowed: false`), you cannot send the message and you must stop here. 1. Call [submitMessageforUser](#operation/submitMessageforUser) to submit a new message. 1. (optional) Call [getMessage](#operation/getMessage) to check whether the message has been notified to the recipient. - * - * The version of the OpenAPI document: 3.30.3 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -package it.gov.pagopa.receipt.pdf.notifier.generated.model; - -import com.google.gson.*; -import com.google.gson.annotations.SerializedName; -import com.google.gson.reflect.TypeToken; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; -import it.gov.pagopa.receipt.pdf.notifier.generated.client.JSON; - -import java.io.IOException; -import java.net.URI; -import java.util.HashSet; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; - -/** - * ProblemJson - */ -@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2023-06-23T14:54:01.440130+02:00[Europe/Rome]") -public class ProblemJson { - public static final String SERIALIZED_NAME_TYPE = "type"; - @SerializedName(SERIALIZED_NAME_TYPE) - private URI type = URI.create("about:blank"); - - public static final String SERIALIZED_NAME_TITLE = "title"; - @SerializedName(SERIALIZED_NAME_TITLE) - private String title; - - public static final String SERIALIZED_NAME_STATUS = "status"; - @SerializedName(SERIALIZED_NAME_STATUS) - private Integer status; - - public static final String SERIALIZED_NAME_DETAIL = "detail"; - @SerializedName(SERIALIZED_NAME_DETAIL) - private String detail; - - public static final String SERIALIZED_NAME_INSTANCE = "instance"; - @SerializedName(SERIALIZED_NAME_INSTANCE) - private URI instance; - - public ProblemJson() { - } - - public ProblemJson type(URI type) { - - this.type = type; - return this; - } - - /** - * An absolute URI that identifies the problem type. When dereferenced, it SHOULD provide human-readable documentation for the problem type (e.g., using HTML). - * @return type - **/ - @javax.annotation.Nullable - public URI getType() { - return type; - } - - - public void setType(URI type) { - this.type = type; - } - - - public ProblemJson title(String title) { - - this.title = title; - return this; - } - - /** - * A short, summary of the problem type. Written in english and readable for engineers (usually not suited for non technical stakeholders and not localized); example: Service Unavailable - * @return title - **/ - @javax.annotation.Nullable - public String getTitle() { - return title; - } - - - public void setTitle(String title) { - this.title = title; - } - - - public ProblemJson status(Integer status) { - - this.status = status; - return this; - } - - /** - * The HTTP status code generated by the origin server for this occurrence of the problem. - * minimum: 100 - * maximum: 600 - * @return status - **/ - @javax.annotation.Nullable - public Integer getStatus() { - return status; - } - - - public void setStatus(Integer status) { - this.status = status; - } - - - public ProblemJson detail(String detail) { - - this.detail = detail; - return this; - } - - /** - * A human readable explanation specific to this occurrence of the problem. - * @return detail - **/ - @javax.annotation.Nullable - public String getDetail() { - return detail; - } - - - public void setDetail(String detail) { - this.detail = detail; - } - - - public ProblemJson instance(URI instance) { - - this.instance = instance; - return this; - } - - /** - * An absolute URI that identifies the specific occurrence of the problem. It may or may not yield further information if dereferenced. - * @return instance - **/ - @javax.annotation.Nullable - public URI getInstance() { - return instance; - } - - - public void setInstance(URI instance) { - this.instance = instance; - } - - - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - ProblemJson problemJson = (ProblemJson) o; - return Objects.equals(this.type, problemJson.type) && - Objects.equals(this.title, problemJson.title) && - Objects.equals(this.status, problemJson.status) && - Objects.equals(this.detail, problemJson.detail) && - Objects.equals(this.instance, problemJson.instance); - } - - @Override - public int hashCode() { - return Objects.hash(type, title, status, detail, instance); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class ProblemJson {\n"); - sb.append(" type: ").append(toIndentedString(type)).append("\n"); - sb.append(" title: ").append(toIndentedString(title)).append("\n"); - sb.append(" status: ").append(toIndentedString(status)).append("\n"); - sb.append(" detail: ").append(toIndentedString(detail)).append("\n"); - sb.append(" instance: ").append(toIndentedString(instance)).append("\n"); - sb.append("}"); - return sb.toString(); - } - - /** - * Convert the given object to string with each line indented by 4 spaces - * (except the first line). - */ - private String toIndentedString(Object o) { - if (o == null) { - return "null"; - } - return o.toString().replace("\n", "\n "); - } - - - public static HashSet openapiFields; - public static HashSet openapiRequiredFields; - - static { - // a set of all properties/fields (JSON key names) - openapiFields = new HashSet(); - openapiFields.add("type"); - openapiFields.add("title"); - openapiFields.add("status"); - openapiFields.add("detail"); - openapiFields.add("instance"); - - // a set of required properties/fields (JSON key names) - openapiRequiredFields = new HashSet(); - } - - /** - * Validates the JSON Object and throws an exception if issues found - * - * @param jsonObj JSON Object - * @throws IOException if the JSON Object is invalid with respect to ProblemJson - */ - public static void validateJsonObject(JsonObject jsonObj) throws IOException { - if (jsonObj == null) { - if (!ProblemJson.openapiRequiredFields.isEmpty()) { // has required fields but JSON object is null - throw new IllegalArgumentException(String.format("The required field(s) %s in ProblemJson is not found in the empty JSON string", ProblemJson.openapiRequiredFields.toString())); - } - } - - Set> entries = jsonObj.entrySet(); - // check to see if the JSON string contains additional fields - for (Entry entry : entries) { - if (!ProblemJson.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `ProblemJson` properties. JSON: %s", entry.getKey(), jsonObj.toString())); - } - } - if ((jsonObj.get("type") != null && !jsonObj.get("type").isJsonNull()) && !jsonObj.get("type").isJsonPrimitive()) { - throw new IllegalArgumentException(String.format("Expected the field `type` to be a primitive type in the JSON string but got `%s`", jsonObj.get("type").toString())); - } - if ((jsonObj.get("title") != null && !jsonObj.get("title").isJsonNull()) && !jsonObj.get("title").isJsonPrimitive()) { - throw new IllegalArgumentException(String.format("Expected the field `title` to be a primitive type in the JSON string but got `%s`", jsonObj.get("title").toString())); - } - if ((jsonObj.get("detail") != null && !jsonObj.get("detail").isJsonNull()) && !jsonObj.get("detail").isJsonPrimitive()) { - throw new IllegalArgumentException(String.format("Expected the field `detail` to be a primitive type in the JSON string but got `%s`", jsonObj.get("detail").toString())); - } - if ((jsonObj.get("instance") != null && !jsonObj.get("instance").isJsonNull()) && !jsonObj.get("instance").isJsonPrimitive()) { - throw new IllegalArgumentException(String.format("Expected the field `instance` to be a primitive type in the JSON string but got `%s`", jsonObj.get("instance").toString())); - } - } - - public static class CustomTypeAdapterFactory implements TypeAdapterFactory { - @SuppressWarnings("unchecked") - @Override - public TypeAdapter create(Gson gson, TypeToken type) { - if (!ProblemJson.class.isAssignableFrom(type.getRawType())) { - return null; // this class only serializes 'ProblemJson' and its subtypes - } - final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); - final TypeAdapter thisAdapter - = gson.getDelegateAdapter(this, TypeToken.get(ProblemJson.class)); - - return (TypeAdapter) new TypeAdapter() { - @Override - public void write(JsonWriter out, ProblemJson value) throws IOException { - JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); - elementAdapter.write(out, obj); - } - - @Override - public ProblemJson read(JsonReader in) throws IOException { - JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject(); - validateJsonObject(jsonObj); - return thisAdapter.fromJsonTree(jsonObj); - } - - }.nullSafe(); - } - } - - /** - * Create an instance of ProblemJson given an JSON string - * - * @param jsonString JSON string - * @return An instance of ProblemJson - * @throws IOException if the JSON string is invalid with respect to ProblemJson - */ - public static ProblemJson fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, ProblemJson.class); - } - - /** - * Convert an instance of ProblemJson to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } -} - diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/ThirdPartyData.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/ThirdPartyData.java deleted file mode 100644 index c278e6b..0000000 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/generated/model/ThirdPartyData.java +++ /dev/null @@ -1,316 +0,0 @@ -/* - * IO API for Public Administration Services - * # Warning **This is an experimental API that is (most probably) going to change as we evolve the IO platform.** # Introduction This is the documentation of the IO API for 3rd party services. This API enables Public Administration services to integrate with the IO platform. IO enables services to communicate with Italian citizens via the [IO app](https://io.italia.it/). # How to get an API key To get access to this API, you'll need to register on the [IO Developer Portal](https://developer.io.italia.it/). After the registration step, you have to click on the button that says `subscribe to the digital citizenship api` to receive the API key that you will use to authenticate the API calls. You will also receive an email with further instructions, including a fake Fiscal Code that you will be able to use to send test messages. Messages sent to the fake Fiscal Code will be notified to the email address used during the registration process on the developer portal. # Messages ## What is a message Messages are the primary form of communication enabled by the IO APIs. Messages are **personal** communications directed to a **specific citizen**. You will not be able to use this API to broadcast a message to a group of citizens, you will have to create and send a specific, personalized message to each citizen you want to communicate to. The recipient of the message (i.e. a citizen) is identified trough his [Fiscal Code](https://it.wikipedia.org/wiki/Codice_fiscale). ## Message format A message is conceptually very similar to an email and, in its simplest form, is composed of the following attributes: * A required `subject`: a short description of the topic. * A required `markdown` body: a Markdown representation of the body (see below on what Markdown tags are allowed). * An optional `payment_data`: in case the message is a payment request, the _payment data_ will enable the recipient to pay the requested amount via [PagoPA](https://www.agid.gov.it/it/piattaforme/pagopa). * An optional `due_date`: a _due date_ that let the recipient add a reminder when receiving the message. The format for all dates is [ISO8601](https://it.wikipedia.org/wiki/ISO_8601) with time information and UTC timezone (ie. \"2018-10-13T00:00:00.000Z\"). * An optional `feature_level_type`: the kind of the submitted message. It can be: - `STANDARD` for normal messages; - `ADVANCED` to enable premium features. Default is `STANDARD`. ## Allowed Markdown formatting Not all Markdown formatting is currently available. Currently you can use the following formatting: * Headings * Text stylings (bold, italic, etc...) * Lists (bullet and numbered) ## Sending a message to a citizen Not every citizen will be interested in what you have to say and not every citizen you want to communicate to will be registered on IO. For this reason, before sending a message you need to check whether the recipient is registered on the platform and that he has not yet opted out from receiving messages from you. The process for sending a message is made of 3 steps: 1. Call [getProfile](#operation/getProfile): if the profile does not exist (i.e. you get a 404 response) or if the recipient has opted-out from your service (the response contains `sender_allowed: false`), you cannot send the message and you must stop here. 1. Call [submitMessageforUser](#operation/submitMessageforUser) to submit a new message. 1. (optional) Call [getMessage](#operation/getMessage) to check whether the message has been notified to the recipient. - * - * The version of the OpenAPI document: 3.30.3 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -package it.gov.pagopa.receipt.pdf.notifier.generated.model; - -import com.google.gson.*; -import com.google.gson.annotations.SerializedName; -import com.google.gson.reflect.TypeToken; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; -import it.gov.pagopa.receipt.pdf.notifier.generated.client.JSON; - -import java.io.IOException; -import java.util.HashSet; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; - -/** - * Payload containing all information needed to retrieve and visualize third party message details - */ -@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2023-06-23T14:54:01.440130+02:00[Europe/Rome]") -public class ThirdPartyData { - public static final String SERIALIZED_NAME_ID = "id"; - @SerializedName(SERIALIZED_NAME_ID) - private String id; - - public static final String SERIALIZED_NAME_ORIGINAL_SENDER = "original_sender"; - @SerializedName(SERIALIZED_NAME_ORIGINAL_SENDER) - private String originalSender; - - public static final String SERIALIZED_NAME_ORIGINAL_RECEIPT_DATE = "original_receipt_date"; - @SerializedName(SERIALIZED_NAME_ORIGINAL_RECEIPT_DATE) - private String originalReceiptDate; - - public static final String SERIALIZED_NAME_HAS_ATTACHMENTS = "has_attachments"; - @SerializedName(SERIALIZED_NAME_HAS_ATTACHMENTS) - private Boolean hasAttachments = false; - - public static final String SERIALIZED_NAME_SUMMARY = "summary"; - @SerializedName(SERIALIZED_NAME_SUMMARY) - private String summary; - - public ThirdPartyData() { - } - - public ThirdPartyData id(String id) { - - this.id = id; - return this; - } - - /** - * Unique id for retrieving third party enriched information about the message - * @return id - **/ - @javax.annotation.Nonnull - public String getId() { - return id; - } - - - public void setId(String id) { - this.id = id; - } - - - public ThirdPartyData originalSender(String originalSender) { - - this.originalSender = originalSender; - return this; - } - - /** - * Either a ServiceId or a simple string representing the sender name - * @return originalSender - **/ - @javax.annotation.Nullable - public String getOriginalSender() { - return originalSender; - } - - - public void setOriginalSender(String originalSender) { - this.originalSender = originalSender; - } - - - public ThirdPartyData originalReceiptDate(String originalReceiptDate) { - - this.originalReceiptDate = originalReceiptDate; - return this; - } - - /** - * A date-time field in ISO-8601 format and UTC timezone. - * @return originalReceiptDate - **/ - @javax.annotation.Nullable - public String getOriginalReceiptDate() { - return originalReceiptDate; - } - - - public void setOriginalReceiptDate(String originalReceiptDate) { - this.originalReceiptDate = originalReceiptDate; - } - - - public ThirdPartyData hasAttachments(Boolean hasAttachments) { - - this.hasAttachments = hasAttachments; - return this; - } - - /** - * Get hasAttachments - * @return hasAttachments - **/ - @javax.annotation.Nullable - public Boolean getHasAttachments() { - return hasAttachments; - } - - - public void setHasAttachments(Boolean hasAttachments) { - this.hasAttachments = hasAttachments; - } - - - public ThirdPartyData summary(String summary) { - - this.summary = summary; - return this; - } - - /** - * Get summary - * @return summary - **/ - @javax.annotation.Nullable - public String getSummary() { - return summary; - } - - - public void setSummary(String summary) { - this.summary = summary; - } - - - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - ThirdPartyData thirdPartyData = (ThirdPartyData) o; - return Objects.equals(this.id, thirdPartyData.id) && - Objects.equals(this.originalSender, thirdPartyData.originalSender) && - Objects.equals(this.originalReceiptDate, thirdPartyData.originalReceiptDate) && - Objects.equals(this.hasAttachments, thirdPartyData.hasAttachments) && - Objects.equals(this.summary, thirdPartyData.summary); - } - - @Override - public int hashCode() { - return Objects.hash(id, originalSender, originalReceiptDate, hasAttachments, summary); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class ThirdPartyData {\n"); - sb.append(" id: ").append(toIndentedString(id)).append("\n"); - sb.append(" originalSender: ").append(toIndentedString(originalSender)).append("\n"); - sb.append(" originalReceiptDate: ").append(toIndentedString(originalReceiptDate)).append("\n"); - sb.append(" hasAttachments: ").append(toIndentedString(hasAttachments)).append("\n"); - sb.append(" summary: ").append(toIndentedString(summary)).append("\n"); - sb.append("}"); - return sb.toString(); - } - - /** - * Convert the given object to string with each line indented by 4 spaces - * (except the first line). - */ - private String toIndentedString(Object o) { - if (o == null) { - return "null"; - } - return o.toString().replace("\n", "\n "); - } - - - public static HashSet openapiFields; - public static HashSet openapiRequiredFields; - - static { - // a set of all properties/fields (JSON key names) - openapiFields = new HashSet(); - openapiFields.add("id"); - openapiFields.add("original_sender"); - openapiFields.add("original_receipt_date"); - openapiFields.add("has_attachments"); - openapiFields.add("summary"); - - // a set of required properties/fields (JSON key names) - openapiRequiredFields = new HashSet(); - openapiRequiredFields.add("id"); - } - - /** - * Validates the JSON Object and throws an exception if issues found - * - * @param jsonObj JSON Object - * @throws IOException if the JSON Object is invalid with respect to ThirdPartyData - */ - public static void validateJsonObject(JsonObject jsonObj) throws IOException { - if (jsonObj == null) { - if (!ThirdPartyData.openapiRequiredFields.isEmpty()) { // has required fields but JSON object is null - throw new IllegalArgumentException(String.format("The required field(s) %s in ThirdPartyData is not found in the empty JSON string", ThirdPartyData.openapiRequiredFields.toString())); - } - } - - Set> entries = jsonObj.entrySet(); - // check to see if the JSON string contains additional fields - for (Entry entry : entries) { - if (!ThirdPartyData.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `ThirdPartyData` properties. JSON: %s", entry.getKey(), jsonObj.toString())); - } - } - - // check to make sure all required properties/fields are present in the JSON string - for (String requiredField : ThirdPartyData.openapiRequiredFields) { - if (jsonObj.get(requiredField) == null) { - throw new IllegalArgumentException(String.format("The required field `%s` is not found in the JSON string: %s", requiredField, jsonObj.toString())); - } - } - if (!jsonObj.get("id").isJsonPrimitive()) { - throw new IllegalArgumentException(String.format("Expected the field `id` to be a primitive type in the JSON string but got `%s`", jsonObj.get("id").toString())); - } - if ((jsonObj.get("original_sender") != null && !jsonObj.get("original_sender").isJsonNull()) && !jsonObj.get("original_sender").isJsonPrimitive()) { - throw new IllegalArgumentException(String.format("Expected the field `original_sender` to be a primitive type in the JSON string but got `%s`", jsonObj.get("original_sender").toString())); - } - if ((jsonObj.get("original_receipt_date") != null && !jsonObj.get("original_receipt_date").isJsonNull()) && !jsonObj.get("original_receipt_date").isJsonPrimitive()) { - throw new IllegalArgumentException(String.format("Expected the field `original_receipt_date` to be a primitive type in the JSON string but got `%s`", jsonObj.get("original_receipt_date").toString())); - } - if ((jsonObj.get("summary") != null && !jsonObj.get("summary").isJsonNull()) && !jsonObj.get("summary").isJsonPrimitive()) { - throw new IllegalArgumentException(String.format("Expected the field `summary` to be a primitive type in the JSON string but got `%s`", jsonObj.get("summary").toString())); - } - } - - public static class CustomTypeAdapterFactory implements TypeAdapterFactory { - @SuppressWarnings("unchecked") - @Override - public TypeAdapter create(Gson gson, TypeToken type) { - if (!ThirdPartyData.class.isAssignableFrom(type.getRawType())) { - return null; // this class only serializes 'ThirdPartyData' and its subtypes - } - final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); - final TypeAdapter thisAdapter - = gson.getDelegateAdapter(this, TypeToken.get(ThirdPartyData.class)); - - return (TypeAdapter) new TypeAdapter() { - @Override - public void write(JsonWriter out, ThirdPartyData value) throws IOException { - JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); - elementAdapter.write(out, obj); - } - - @Override - public ThirdPartyData read(JsonReader in) throws IOException { - JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject(); - validateJsonObject(jsonObj); - return thisAdapter.fromJsonTree(jsonObj); - } - - }.nullSafe(); - } - } - - /** - * Create an instance of ThirdPartyData given an JSON string - * - * @param jsonString JSON string - * @return An instance of ThirdPartyData - * @throws IOException if the JSON string is invalid with respect to ThirdPartyData - */ - public static ThirdPartyData fromJson(String jsonString) throws IOException { - return JSON.getGson().fromJson(jsonString, ThirdPartyData.class); - } - - /** - * Convert an instance of ThirdPartyData to an JSON string - * - * @return JSON string - */ - public String toJson() { - return JSON.getGson().toJson(this); - } -} - diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/model/io/IOProfilePayload.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/model/io/IOProfilePayload.java new file mode 100644 index 0000000..1b72c27 --- /dev/null +++ b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/model/io/IOProfilePayload.java @@ -0,0 +1,20 @@ +package it.gov.pagopa.receipt.pdf.notifier.model.io; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * Model class that hold the payload for getProfiles IO API + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class IOProfilePayload { + + @JsonProperty("fiscal_code") + private String fiscalCode; +} diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/model/io/IOProfileResponse.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/model/io/IOProfileResponse.java new file mode 100644 index 0000000..e69bc24 --- /dev/null +++ b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/model/io/IOProfileResponse.java @@ -0,0 +1,25 @@ +package it.gov.pagopa.receipt.pdf.notifier.model.io; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * Model class that hold the response for getProfiles IO API + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class IOProfileResponse { + + @JsonProperty("sender_allowed") + private boolean senderAllowed; + + @JsonProperty("preferred_languages") + private List preferredLanguages; +} diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/model/io/message/IOMessageResponse.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/model/io/message/IOMessageResponse.java new file mode 100644 index 0000000..d127571 --- /dev/null +++ b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/model/io/message/IOMessageResponse.java @@ -0,0 +1,20 @@ +package it.gov.pagopa.receipt.pdf.notifier.model.io.message; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * Model class that hold the response of submit message IO API + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class IOMessageResponse { + + @JsonProperty("id") + private String id; +} diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/model/io/message/MessageContent.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/model/io/message/MessageContent.java new file mode 100644 index 0000000..aa3fcfa --- /dev/null +++ b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/model/io/message/MessageContent.java @@ -0,0 +1,32 @@ +package it.gov.pagopa.receipt.pdf.notifier.model.io.message; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * Model class that hold the IO message content + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class MessageContent { + + @JsonProperty("subject") + private String subject; + + @JsonProperty("markdown") + private String markdown; + + @JsonProperty("payment_data") + private PaymentData paymentData; + + @JsonProperty("third_party_data") + private ThirdPartyData thirdPartyData; + + @JsonProperty("due_date") + private String dueDate; +} diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/model/io/message/MessagePayload.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/model/io/message/MessagePayload.java new file mode 100644 index 0000000..c5570b6 --- /dev/null +++ b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/model/io/message/MessagePayload.java @@ -0,0 +1,29 @@ +package it.gov.pagopa.receipt.pdf.notifier.model.io.message; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * Model class that hold the payload for submitting a message IO + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class MessagePayload { + + @JsonProperty("time_to_live") + private Integer timeToLive = 3600; + + @JsonProperty("content") + private MessageContent content; + + @JsonProperty("fiscal_code") + private String fiscalCode; + + @JsonProperty("feature_level_type") + private String featureLevelType = "STANDARD"; +} diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/model/io/message/Payee.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/model/io/message/Payee.java new file mode 100644 index 0000000..af95df8 --- /dev/null +++ b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/model/io/message/Payee.java @@ -0,0 +1,20 @@ +package it.gov.pagopa.receipt.pdf.notifier.model.io.message; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * Model class that hold the IO message payment data payee + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class Payee { + + @JsonProperty("fiscal_code") + private String fiscalCode; +} diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/model/io/message/PaymentData.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/model/io/message/PaymentData.java new file mode 100644 index 0000000..4ed4a81 --- /dev/null +++ b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/model/io/message/PaymentData.java @@ -0,0 +1,29 @@ +package it.gov.pagopa.receipt.pdf.notifier.model.io.message; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * Model class that hold the IO message payment data + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class PaymentData { + + @JsonProperty("amount") + private Integer amount; + + @JsonProperty("notice_number") + private String noticeNumber; + + @JsonProperty("invalid_after_due_date") + private Boolean invalidAfterDueDate = false; + + @JsonProperty("payee") + private Payee payee; +} diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/model/io/message/ThirdPartyData.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/model/io/message/ThirdPartyData.java new file mode 100644 index 0000000..d078cea --- /dev/null +++ b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/model/io/message/ThirdPartyData.java @@ -0,0 +1,32 @@ +package it.gov.pagopa.receipt.pdf.notifier.model.io.message; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * Model class that hold the IO message third party data + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class ThirdPartyData { + + @JsonProperty("id") + private String id; + + @JsonProperty("original_sender") + private String originalSender; + + @JsonProperty("original_receipt_date") + private String originalReceiptDate; + + @JsonProperty("has_attachments") + private Boolean hasAttachments = false; + + @JsonProperty("summary") + private String summary; +} diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/service/IOMessageService.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/service/IOService.java similarity index 59% rename from src/main/java/it/gov/pagopa/receipt/pdf/notifier/service/IOMessageService.java rename to src/main/java/it/gov/pagopa/receipt/pdf/notifier/service/IOService.java index 7a803f0..e8087be 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/service/IOMessageService.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/service/IOService.java @@ -2,10 +2,13 @@ import it.gov.pagopa.receipt.pdf.notifier.entity.receipt.Receipt; import it.gov.pagopa.receipt.pdf.notifier.exception.MissingFieldsForNotificationException; -import it.gov.pagopa.receipt.pdf.notifier.generated.model.NewMessage; import it.gov.pagopa.receipt.pdf.notifier.model.enumeration.UserType; +import it.gov.pagopa.receipt.pdf.notifier.model.io.message.MessagePayload; -public interface IOMessageService { +/** + * Service for IO operations + */ +public interface IOService { /** * Build IO message from Receipt's data @@ -13,7 +16,7 @@ public interface IOMessageService { * @param receipt Receipt from CosmosDB * @param fiscalCode User's fiscal code * @param userType the type of user to be notified {@link UserType} - * @return {@link NewMessage} used as request to notify + * @return {@link MessagePayload} used as request to notify */ - NewMessage buildNewMessage(String fiscalCode, Receipt receipt, UserType userType) throws MissingFieldsForNotificationException; + MessagePayload buildMessagePayload(String fiscalCode, Receipt receipt, UserType userType) throws MissingFieldsForNotificationException; } diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/service/ReceiptToIOService.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/service/ReceiptToIOService.java index 8ebe44f..8ddab87 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/service/ReceiptToIOService.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/service/ReceiptToIOService.java @@ -1,6 +1,5 @@ package it.gov.pagopa.receipt.pdf.notifier.service; -import com.fasterxml.jackson.core.JsonProcessingException; import it.gov.pagopa.receipt.pdf.notifier.entity.message.IOMessage; import it.gov.pagopa.receipt.pdf.notifier.entity.receipt.Receipt; import it.gov.pagopa.receipt.pdf.notifier.model.enumeration.UserNotifyStatus; @@ -33,5 +32,5 @@ boolean verifyMessagesNotification( EnumMap usersToBeVerified, List messagesNotified, Receipt receipt - ) throws JsonProcessingException; + ); } diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/service/impl/IOMessageServiceImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/service/impl/IOServiceImpl.java similarity index 75% rename from src/main/java/it/gov/pagopa/receipt/pdf/notifier/service/impl/IOMessageServiceImpl.java rename to src/main/java/it/gov/pagopa/receipt/pdf/notifier/service/impl/IOServiceImpl.java index 40a856e..08b5d18 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/service/impl/IOMessageServiceImpl.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/service/impl/IOServiceImpl.java @@ -4,11 +4,11 @@ import it.gov.pagopa.receipt.pdf.notifier.entity.receipt.EventData; import it.gov.pagopa.receipt.pdf.notifier.entity.receipt.Receipt; import it.gov.pagopa.receipt.pdf.notifier.exception.MissingFieldsForNotificationException; -import it.gov.pagopa.receipt.pdf.notifier.generated.model.MessageContent; -import it.gov.pagopa.receipt.pdf.notifier.generated.model.NewMessage; -import it.gov.pagopa.receipt.pdf.notifier.generated.model.ThirdPartyData; import it.gov.pagopa.receipt.pdf.notifier.model.enumeration.UserType; -import it.gov.pagopa.receipt.pdf.notifier.service.IOMessageService; +import it.gov.pagopa.receipt.pdf.notifier.model.io.message.MessageContent; +import it.gov.pagopa.receipt.pdf.notifier.model.io.message.MessagePayload; +import it.gov.pagopa.receipt.pdf.notifier.model.io.message.ThirdPartyData; +import it.gov.pagopa.receipt.pdf.notifier.service.IOService; import org.apache.commons.text.StringSubstitutor; import org.jetbrains.annotations.NotNull; @@ -20,7 +20,10 @@ import java.util.Locale; import java.util.Map; -public class IOMessageServiceImpl implements IOMessageService { +/** + * {@inheritDoc} + */ +public class IOServiceImpl implements IOService { private static final String SUBJECT_PAYER = new String(System.getenv().getOrDefault("SUBJECT_PAYER", "").getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8); private static final String SUBJECT_DEBTOR = new String(System.getenv().getOrDefault("SUBJECT_DEBTOR", "").getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8); @@ -31,13 +34,12 @@ public class IOMessageServiceImpl implements IOMessageService { * {@inheritDoc} */ @Override - public NewMessage buildNewMessage(String fiscalCode, Receipt receipt, UserType userType) throws MissingFieldsForNotificationException { - NewMessage message = new NewMessage(); - message.setFiscalCode(fiscalCode); - message.setFeatureLevelType("ADVANCED"); - message.setContent(buildMessageContent(receipt, userType)); - - return message; + public MessagePayload buildMessagePayload(String fiscalCode, Receipt receipt, UserType userType) throws MissingFieldsForNotificationException { + return MessagePayload.builder() + .fiscalCode(fiscalCode) + .featureLevelType("ADVANCED") + .content(buildMessageContent(receipt, userType)) + .build(); } @NotNull @@ -53,23 +55,17 @@ private MessageContent buildMessageContent(Receipt receipt, UserType userType) t subject = stringSubstitutor.replace(SUBJECT_PAYER); markdown = stringSubstitutor.replace(MARKDOWN_PAYER); } - MessageContent content = new MessageContent(); - content.setSubject(subject); - content.setMarkdown(markdown); - content.setThirdPartyData(buildThirdPartyData(receipt)); - return content; + return MessageContent.builder() + .subject(subject) + .markdown(markdown) + .thirdPartyData(ThirdPartyData.builder() + .id(receipt.getEventId()) + .hasAttachments(true) + .build()) + .build(); } - @NotNull - private ThirdPartyData buildThirdPartyData(Receipt receipt) { - ThirdPartyData thirdPartyData = new ThirdPartyData(); - thirdPartyData.setId(receipt.getEventId()); - thirdPartyData.setHasAttachments(true); - return thirdPartyData; - } - - @NotNull private StringSubstitutor buildStringSubstitutor(EventData eventData, String receiptId) throws MissingFieldsForNotificationException { if (eventData == null diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/service/impl/ReceiptToIOServiceImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/service/impl/ReceiptToIOServiceImpl.java index 103ce36..fad6247 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/service/impl/ReceiptToIOServiceImpl.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/service/impl/ReceiptToIOServiceImpl.java @@ -3,27 +3,25 @@ import com.azure.core.http.rest.Response; import com.azure.storage.queue.models.SendMessageResult; import com.fasterxml.jackson.core.JsonProcessingException; +import it.gov.pagopa.receipt.pdf.notifier.client.IOClient; import it.gov.pagopa.receipt.pdf.notifier.client.NotifierQueueClient; +import it.gov.pagopa.receipt.pdf.notifier.client.impl.IOClientImpl; import it.gov.pagopa.receipt.pdf.notifier.client.impl.NotifierQueueClientImpl; import it.gov.pagopa.receipt.pdf.notifier.entity.message.IOMessage; import it.gov.pagopa.receipt.pdf.notifier.entity.receipt.IOMessageData; -import it.gov.pagopa.receipt.pdf.notifier.entity.receipt.ReasonError; import it.gov.pagopa.receipt.pdf.notifier.entity.receipt.Receipt; -import it.gov.pagopa.receipt.pdf.notifier.entity.receipt.enumeration.ReasonErrorCode; import it.gov.pagopa.receipt.pdf.notifier.entity.receipt.enumeration.ReceiptStatusType; import it.gov.pagopa.receipt.pdf.notifier.exception.ErrorToNotifyException; +import it.gov.pagopa.receipt.pdf.notifier.exception.IOAPIException; import it.gov.pagopa.receipt.pdf.notifier.exception.MissingFieldsForNotificationException; import it.gov.pagopa.receipt.pdf.notifier.exception.PDVTokenizerException; -import it.gov.pagopa.receipt.pdf.notifier.generated.client.ApiException; -import it.gov.pagopa.receipt.pdf.notifier.generated.client.ApiResponse; -import it.gov.pagopa.receipt.pdf.notifier.generated.client.api.IOClient; -import it.gov.pagopa.receipt.pdf.notifier.generated.model.CreatedMessage; -import it.gov.pagopa.receipt.pdf.notifier.generated.model.FiscalCodePayload; -import it.gov.pagopa.receipt.pdf.notifier.generated.model.LimitedProfile; -import it.gov.pagopa.receipt.pdf.notifier.generated.model.NewMessage; import it.gov.pagopa.receipt.pdf.notifier.model.enumeration.UserNotifyStatus; import it.gov.pagopa.receipt.pdf.notifier.model.enumeration.UserType; -import it.gov.pagopa.receipt.pdf.notifier.service.IOMessageService; +import it.gov.pagopa.receipt.pdf.notifier.model.io.IOProfilePayload; +import it.gov.pagopa.receipt.pdf.notifier.model.io.IOProfileResponse; +import it.gov.pagopa.receipt.pdf.notifier.model.io.message.IOMessageResponse; +import it.gov.pagopa.receipt.pdf.notifier.model.io.message.MessagePayload; +import it.gov.pagopa.receipt.pdf.notifier.service.IOService; import it.gov.pagopa.receipt.pdf.notifier.service.PDVTokenizerServiceRetryWrapper; import it.gov.pagopa.receipt.pdf.notifier.service.ReceiptToIOService; import it.gov.pagopa.receipt.pdf.notifier.utils.ObjectMapperUtils; @@ -31,6 +29,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.net.http.HttpResponse; import java.util.Arrays; import java.util.Base64; import java.util.EnumMap; @@ -39,6 +38,8 @@ import static it.gov.pagopa.receipt.pdf.notifier.model.enumeration.UserNotifyStatus.NOTIFIED; import static it.gov.pagopa.receipt.pdf.notifier.model.enumeration.UserNotifyStatus.NOT_NOTIFIED; import static it.gov.pagopa.receipt.pdf.notifier.model.enumeration.UserNotifyStatus.NOT_TO_BE_NOTIFIED; +import static it.gov.pagopa.receipt.pdf.notifier.utils.ReceiptToIOUtils.buildReasonError; +import static it.gov.pagopa.receipt.pdf.notifier.utils.ReceiptToIOUtils.getCodeOrDefault; public class ReceiptToIOServiceImpl implements ReceiptToIOService { @@ -49,20 +50,20 @@ public class ReceiptToIOServiceImpl implements ReceiptToIOService { private final IOClient ioClient; private final NotifierQueueClient notifierQueueClient; - private final IOMessageService ioMessageService; + private final IOService ioService; private final PDVTokenizerServiceRetryWrapper pdvTokenizerServiceRetryWrapper; public ReceiptToIOServiceImpl() { - this.ioClient = IOClient.getInstance(); + this.ioClient = IOClientImpl.getInstance(); this.notifierQueueClient = NotifierQueueClientImpl.getInstance(); - this.ioMessageService = new IOMessageServiceImpl(); + this.ioService = new IOServiceImpl(); this.pdvTokenizerServiceRetryWrapper = new PDVTokenizerServiceRetryWrapperImpl(); } - ReceiptToIOServiceImpl(IOClient ioClient, NotifierQueueClient notifierQueueClient, IOMessageService ioMessageService, PDVTokenizerServiceRetryWrapper pdvTokenizerServiceRetryWrapper) { + ReceiptToIOServiceImpl(IOClient ioClient, NotifierQueueClient notifierQueueClient, IOService ioService, PDVTokenizerServiceRetryWrapper pdvTokenizerServiceRetryWrapper) { this.ioClient = ioClient; this.notifierQueueClient = notifierQueueClient; - this.ioMessageService = ioMessageService; + this.ioService = ioService; this.pdvTokenizerServiceRetryWrapper = pdvTokenizerServiceRetryWrapper; } @@ -77,8 +78,7 @@ public UserNotifyStatus notifyMessage(String fiscalCodeToken, UserType userType, if (!isToBeNotified(fiscalCode, userType, receipt)) { return NOT_TO_BE_NOTIFIED; } - boolean isNotifyAllowed = handleGetProfile(fiscalCode); - if (!isNotifyAllowed) { + if (!isNotifyToIOUserAllowed(fiscalCode)) { logger.info("User {} has not to be notified", userType); return NOT_TO_BE_NOTIFIED; } @@ -98,60 +98,15 @@ public UserNotifyStatus notifyMessage(String fiscalCodeToken, UserType userType, } } - /** - * Invoke getProfile API and verify its response status - * - * @param fiscalCode User fiscal code - * @throws ErrorToNotifyException in case of error notifying user - */ - private boolean handleGetProfile(String fiscalCode) throws ErrorToNotifyException, ApiException { - FiscalCodePayload fiscalCodePayload = new FiscalCodePayload(); - fiscalCodePayload.setFiscalCode(fiscalCode); - ApiResponse getProfileResponse = this.ioClient.getProfileByPOSTWithHttpInfo(fiscalCodePayload); - - if (getProfileResponse == null) { - throw new ErrorToNotifyException("IO /profiles failed to respond"); - } - - if (getProfileResponse.getData() == null || getProfileResponse.getStatusCode() != HttpStatus.SC_OK) { - String errorMsg = String.format("IO /profiles responded with code %s", getProfileResponse.getStatusCode()); - throw new ErrorToNotifyException(errorMsg); - } - - return getProfileResponse.getData().getSenderAllowed(); - } - - /** - * Handles sending notification to IO user - * - * @param fiscalCode User fiscal code - * @param userType Enum User type - * @throws ErrorToNotifyException in case of error during API call - */ - private void handleSendNotificationToUser(String fiscalCode, UserType userType, Receipt receipt) throws ErrorToNotifyException, MissingFieldsForNotificationException { - NewMessage message = this.ioMessageService.buildNewMessage(fiscalCode, receipt, userType); - - //IO /messages - ApiResponse sendMessageResponse; - try { - sendMessageResponse = this.ioClient.submitMessageforUserWithFiscalCodeInBodyWithHttpInfo(message); - } catch (Exception e) { - String errorMsg = String.format("Error sending notification to IO user %s", userType); - throw new ErrorToNotifyException(errorMsg, e); - } + private void handleSendNotificationToUser(String fiscalCode, UserType userType, Receipt receipt) throws ErrorToNotifyException, MissingFieldsForNotificationException, IOAPIException { + MessagePayload messagePayload = this.ioService.buildMessagePayload(fiscalCode, receipt, userType); + String messageId = sendNotificationToIOUser(messagePayload); IOMessageData messageData = receipt.getIoMessageData() != null ? receipt.getIoMessageData() : new IOMessageData(); - if (sendMessageResponse == null) { - throw new ErrorToNotifyException("IO /messages failed to respond"); - } - if (sendMessageResponse.getData() == null || sendMessageResponse.getStatusCode() != HttpStatus.SC_CREATED) { - String errorMsg = String.format("IO /messages responded with code %s", sendMessageResponse.getStatusCode()); - throw new ErrorToNotifyException(errorMsg); - } if (userType.equals(UserType.DEBTOR)) { - messageData.setIdMessageDebtor(sendMessageResponse.getData().getId()); + messageData.setIdMessageDebtor(messageId); } else { - messageData.setIdMessagePayer(sendMessageResponse.getData().getId()); + messageData.setIdMessagePayer(messageId); } receipt.setIoMessageData(messageData); } @@ -164,7 +119,7 @@ public boolean verifyMessagesNotification( EnumMap usersToBeVerified, List messagesNotified, Receipt receipt - ) throws JsonProcessingException { + ) { UserNotifyStatus debtorNotified = usersToBeVerified.getOrDefault(UserType.DEBTOR, NOT_TO_BE_NOTIFIED); UserNotifyStatus payerNotified = usersToBeVerified.getOrDefault(UserType.PAYER, NOT_TO_BE_NOTIFIED); @@ -191,7 +146,63 @@ public boolean verifyMessagesNotification( return false; } - private boolean requeueReceiptForRetry(Receipt receipt) throws JsonProcessingException { + private boolean isNotifyToIOUserAllowed(String fiscalCode) throws IOAPIException, ErrorToNotifyException { + IOProfilePayload iOProfilePayload = IOProfilePayload.builder().fiscalCode(fiscalCode).build(); + String payload = serializePayload(iOProfilePayload); + + logger.debug("IO API getProfile called"); + HttpResponse getProfileResponse = this.ioClient.getProfile(payload); + logger.debug("IO API getProfile invocation completed"); + + if (getProfileResponse == null) { + throw new ErrorToNotifyException("IO /profiles failed to respond"); + } + + if (getProfileResponse.statusCode() != HttpStatus.SC_OK || getProfileResponse.body() == null) { + String errorMsg = String.format("IO /profiles responded with code %s", getProfileResponse.statusCode()); + throw new ErrorToNotifyException(errorMsg); + } + + IOProfileResponse ioProfileResponse = deserializeResponse(getProfileResponse.body(), IOProfileResponse.class); + return ioProfileResponse.isSenderAllowed(); + } + + private String sendNotificationToIOUser(MessagePayload message) throws IOAPIException, ErrorToNotifyException { + String payload = serializePayload(message); + + logger.debug("IO API submitMessage called"); + HttpResponse notificationResponse = this.ioClient.submitMessage(payload); + logger.debug("IO API submitMessage invocation completed"); + + if (notificationResponse == null) { + throw new ErrorToNotifyException("IO /messages failed to respond"); + } + if (notificationResponse.statusCode() != HttpStatus.SC_CREATED || notificationResponse.body() == null) { + String errorMsg = String.format("IO /messages responded with code %s", notificationResponse.statusCode()); + throw new ErrorToNotifyException(errorMsg); + } + + IOMessageResponse ioMessageResponse = deserializeResponse(notificationResponse.body(), IOMessageResponse.class); + return ioMessageResponse.getId(); + } + + private String serializePayload(Object payload) throws ErrorToNotifyException { + try { + return ObjectMapperUtils.writeValueAsString(payload); + } catch (JsonProcessingException e) { + throw new ErrorToNotifyException("Failed to serialize payload for IO API invocation", e); + } + } + + private T deserializeResponse(String response, Class clazz) throws ErrorToNotifyException { + try { + return ObjectMapperUtils.mapString(response, clazz); + } catch (JsonProcessingException e) { + throw new ErrorToNotifyException("Failed to deserialize response of IO API invocation", e); + } + } + + private boolean requeueReceiptForRetry(Receipt receipt) { int numRetry = receipt.getNotificationNumRetry(); receipt.setNotificationNumRetry(numRetry + 1); @@ -201,13 +212,22 @@ private boolean requeueReceiptForRetry(Receipt receipt) throws JsonProcessingExc return false; } - String receiptString = ObjectMapperUtils.writeValueAsString(receipt); + String receiptString; + try { + receiptString = ObjectMapperUtils.writeValueAsString(receipt); + } catch (JsonProcessingException e) { + logger.error("Unable to requeue for retry the event with event id: {}. Receipt updated with status IO_ERROR_TO_NOTIFY", receipt.getEventId(), e); + receipt.setStatus(ReceiptStatusType.IO_ERROR_TO_NOTIFY); + return false; + } try { Response response = this.notifierQueueClient.sendMessageToQueue(Base64.getMimeEncoder().encodeToString(receiptString.getBytes())); if (response.getStatusCode() == com.microsoft.azure.functions.HttpStatus.CREATED.value()) { receipt.setStatus(ReceiptStatusType.IO_ERROR_TO_NOTIFY); return true; } + logger.error("Error in sending message to queue for receipt with event id: {}, queue responded with status {}. Receipt updated with status UNABLE_TO_SEND", + receipt.getEventId(), response.getStatusCode()); receipt.setStatus(ReceiptStatusType.UNABLE_TO_SEND); return false; } catch (Exception e) { @@ -239,23 +259,6 @@ private IOMessage getIoMessage(Receipt receipt, UserType userType) { .build(); } - private ReasonError buildReasonError(String errorMessage, int code) { - return ReasonError.builder() - .code(code) - .message(errorMessage) - .build(); - } - - private int getCodeOrDefault(Exception e) { - if (e instanceof PDVTokenizerException pdvTokenizerException) { - return pdvTokenizerException.getStatusCode(); - } - if (e instanceof JsonProcessingException) { - return ReasonErrorCode.ERROR_PDV_MAPPING.getCode(); - } - return HttpStatus.SC_INTERNAL_SERVER_ERROR; - } - private String getFiscalCode(String fiscalCodeToken) throws PDVTokenizerException, JsonProcessingException { try { return pdvTokenizerServiceRetryWrapper.getFiscalCodeWithRetry(fiscalCodeToken); diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/utils/ReceiptToIOUtils.java b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/utils/ReceiptToIOUtils.java index 0e98ab5..e6a189d 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/notifier/utils/ReceiptToIOUtils.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/notifier/utils/ReceiptToIOUtils.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import it.gov.pagopa.receipt.pdf.notifier.entity.receipt.ReasonError; import it.gov.pagopa.receipt.pdf.notifier.entity.receipt.enumeration.ReasonErrorCode; +import it.gov.pagopa.receipt.pdf.notifier.exception.IOAPIException; import it.gov.pagopa.receipt.pdf.notifier.exception.PDVTokenizerException; import org.apache.http.HttpStatus; @@ -19,10 +20,14 @@ public static int getCodeOrDefault(Exception e) { if (e instanceof PDVTokenizerException pdvTokenizerException) { return pdvTokenizerException.getStatusCode(); } + if (e instanceof IOAPIException ioApiException) { + return ioApiException.getStatusCode(); + } if (e instanceof JsonProcessingException) { return ReasonErrorCode.ERROR_PDV_MAPPING.getCode(); } return HttpStatus.SC_INTERNAL_SERVER_ERROR; } + private ReceiptToIOUtils() {} } diff --git a/src/test/java/it/gov/pagopa/receipt/pdf/notifier/client/impl/IOClientImplTest.java b/src/test/java/it/gov/pagopa/receipt/pdf/notifier/client/impl/IOClientImplTest.java new file mode 100644 index 0000000..e2f96c5 --- /dev/null +++ b/src/test/java/it/gov/pagopa/receipt/pdf/notifier/client/impl/IOClientImplTest.java @@ -0,0 +1,79 @@ +package it.gov.pagopa.receipt.pdf.notifier.client.impl; + +import it.gov.pagopa.receipt.pdf.notifier.client.IOClient; +import it.gov.pagopa.receipt.pdf.notifier.exception.IOAPIException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.net.http.HttpClient; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; + +class IOClientImplTest { + + private HttpClient clientMock; + private IOClient sut; + + @BeforeEach + void setUp() { + clientMock = mock(HttpClient.class); + sut = spy(new IOClientImpl(clientMock)); + } + + @Test + void getProfileSuccess() throws IOAPIException, IOException, InterruptedException { + sut.getProfile(anyString()); + + verify(clientMock).send(any(), any()); + } + + @Test + void submitMessageSuccess() throws IOAPIException, IOException, InterruptedException { + sut.submitMessage(anyString()); + + verify(clientMock).send(any(), any()); + } + + @Test + void getProfileFailThrowsIOException() throws IOException, InterruptedException { + doThrow(IOException.class).when(clientMock).send(any(), any()); + + assertThrows(IOAPIException.class, () -> sut.getProfile(anyString())); + + verify(clientMock).send(any(), any()); + } + + @Test + void getProfileFailThrowsInterruptedException() throws IOException, InterruptedException { + doThrow(InterruptedException.class).when(clientMock).send(any(), any()); + + assertThrows(IOAPIException.class, () -> sut.getProfile(anyString())); + + verify(clientMock).send(any(), any()); + } + + @Test + void submitMessageFailThrowsIOException() throws IOException, InterruptedException { + doThrow(IOException.class).when(clientMock).send(any(), any()); + + assertThrows(IOAPIException.class, () -> sut.submitMessage(anyString())); + + verify(clientMock).send(any(), any()); + } + + @Test + void submitMessageFailThrowsInterruptedException() throws IOException, InterruptedException { + doThrow(InterruptedException.class).when(clientMock).send(any(), any()); + + assertThrows(IOAPIException.class, () -> sut.submitMessage(anyString())); + + verify(clientMock).send(any(), any()); + } +} \ No newline at end of file diff --git a/src/test/java/it/gov/pagopa/receipt/pdf/notifier/service/impl/IOMessageServiceImplTest.java b/src/test/java/it/gov/pagopa/receipt/pdf/notifier/service/impl/IOServiceImplTest.java similarity index 90% rename from src/test/java/it/gov/pagopa/receipt/pdf/notifier/service/impl/IOMessageServiceImplTest.java rename to src/test/java/it/gov/pagopa/receipt/pdf/notifier/service/impl/IOServiceImplTest.java index 7f5c533..a45f049 100644 --- a/src/test/java/it/gov/pagopa/receipt/pdf/notifier/service/impl/IOMessageServiceImplTest.java +++ b/src/test/java/it/gov/pagopa/receipt/pdf/notifier/service/impl/IOServiceImplTest.java @@ -4,9 +4,9 @@ import it.gov.pagopa.receipt.pdf.notifier.entity.receipt.EventData; import it.gov.pagopa.receipt.pdf.notifier.entity.receipt.Receipt; import it.gov.pagopa.receipt.pdf.notifier.exception.MissingFieldsForNotificationException; -import it.gov.pagopa.receipt.pdf.notifier.generated.model.NewMessage; import it.gov.pagopa.receipt.pdf.notifier.model.enumeration.UserType; -import it.gov.pagopa.receipt.pdf.notifier.service.IOMessageService; +import it.gov.pagopa.receipt.pdf.notifier.model.io.message.MessagePayload; +import it.gov.pagopa.receipt.pdf.notifier.service.IOService; import lombok.SneakyThrows; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -20,7 +20,7 @@ import static org.junit.jupiter.api.Assertions.*; @ExtendWith(SystemStubsExtension.class) -class IOMessageServiceImplTest { +class IOServiceImplTest { private static final String VALID_PAYER_CF = "a valid payer fiscal code"; private static final String VALID_DEBTOR_CF = "a valid debtor fiscal code"; @@ -33,7 +33,7 @@ class IOMessageServiceImplTest { private static final String MARKDOWN_DEBTOR_WITHOUT_SUBJECT = "È stato effettuato il pagamento di un avviso intestato a te:\n\n**Importo**: 2.300,55 €\n**Oggetto:** -\n**Ente creditore**: payee\n\nEcco la ricevuta con i dettagli."; - private IOMessageService sut; + private IOService sut; @SystemStub private final EnvironmentVariables environmentVariables = new EnvironmentVariables( @@ -44,7 +44,7 @@ class IOMessageServiceImplTest { @BeforeEach void setUp() { - sut = new IOMessageServiceImpl(); + sut = new IOServiceImpl(); } @Test @@ -52,7 +52,7 @@ void setUp() { void buildMessageDebtorSuccess() { Receipt receipt = buildReceipt(true); - NewMessage message = sut.buildNewMessage(VALID_DEBTOR_CF, receipt, UserType.DEBTOR); + MessagePayload message = sut.buildMessagePayload(VALID_DEBTOR_CF, receipt, UserType.DEBTOR); assertNotNull(message); assertEquals(VALID_DEBTOR_CF, message.getFiscalCode()); @@ -70,7 +70,7 @@ void buildMessageDebtorSuccess() { void buildMessageDebtorWithoutSubjectSuccess() { Receipt receipt = buildReceipt(false); - NewMessage message = sut.buildNewMessage(VALID_DEBTOR_CF, receipt, UserType.DEBTOR); + MessagePayload message = sut.buildMessagePayload(VALID_DEBTOR_CF, receipt, UserType.DEBTOR); assertNotNull(message); assertEquals(VALID_DEBTOR_CF, message.getFiscalCode()); @@ -89,7 +89,7 @@ void buildMessageDebtorFailThrowsMissingFieldsForNotificationException() { Receipt receipt = new Receipt(); receipt.setEventId(EVENT_ID); - assertThrows(MissingFieldsForNotificationException.class, () -> sut.buildNewMessage(VALID_DEBTOR_CF, receipt, UserType.DEBTOR)); + assertThrows(MissingFieldsForNotificationException.class, () -> sut.buildMessagePayload(VALID_DEBTOR_CF, receipt, UserType.DEBTOR)); } @Test @@ -97,7 +97,7 @@ void buildMessageDebtorFailThrowsMissingFieldsForNotificationException() { void buildMessagePayerSuccess() { Receipt receipt = buildReceipt(true); - NewMessage message = sut.buildNewMessage(VALID_PAYER_CF, receipt, UserType.PAYER); + MessagePayload message = sut.buildMessagePayload(VALID_PAYER_CF, receipt, UserType.PAYER); assertNotNull(message); assertEquals(VALID_PAYER_CF, message.getFiscalCode()); @@ -115,7 +115,7 @@ void buildMessagePayerSuccess() { void buildMessagePayerWithoutSubjectSuccess() { Receipt receipt = buildReceipt(false); - NewMessage message = sut.buildNewMessage(VALID_PAYER_CF, receipt, UserType.PAYER); + MessagePayload message = sut.buildMessagePayload(VALID_PAYER_CF, receipt, UserType.PAYER); assertNotNull(message); assertEquals(VALID_PAYER_CF, message.getFiscalCode()); diff --git a/src/test/java/it/gov/pagopa/receipt/pdf/notifier/service/impl/ReceiptToIOServiceImplTest.java b/src/test/java/it/gov/pagopa/receipt/pdf/notifier/service/impl/ReceiptToIOServiceImplTest.java index 5ad6ad8..6b65b05 100644 --- a/src/test/java/it/gov/pagopa/receipt/pdf/notifier/service/impl/ReceiptToIOServiceImplTest.java +++ b/src/test/java/it/gov/pagopa/receipt/pdf/notifier/service/impl/ReceiptToIOServiceImplTest.java @@ -3,6 +3,8 @@ import com.azure.core.http.rest.Response; import com.azure.storage.queue.models.SendMessageResult; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import it.gov.pagopa.receipt.pdf.notifier.client.IOClient; import it.gov.pagopa.receipt.pdf.notifier.client.NotifierQueueClient; import it.gov.pagopa.receipt.pdf.notifier.entity.message.IOMessage; import it.gov.pagopa.receipt.pdf.notifier.entity.receipt.EventData; @@ -10,16 +12,14 @@ import it.gov.pagopa.receipt.pdf.notifier.entity.receipt.Receipt; import it.gov.pagopa.receipt.pdf.notifier.entity.receipt.enumeration.ReasonErrorCode; import it.gov.pagopa.receipt.pdf.notifier.entity.receipt.enumeration.ReceiptStatusType; +import it.gov.pagopa.receipt.pdf.notifier.exception.IOAPIException; import it.gov.pagopa.receipt.pdf.notifier.exception.MissingFieldsForNotificationException; import it.gov.pagopa.receipt.pdf.notifier.exception.PDVTokenizerException; -import it.gov.pagopa.receipt.pdf.notifier.generated.client.ApiException; -import it.gov.pagopa.receipt.pdf.notifier.generated.client.ApiResponse; -import it.gov.pagopa.receipt.pdf.notifier.generated.client.api.IOClient; -import it.gov.pagopa.receipt.pdf.notifier.generated.model.CreatedMessage; -import it.gov.pagopa.receipt.pdf.notifier.generated.model.LimitedProfile; import it.gov.pagopa.receipt.pdf.notifier.model.enumeration.UserNotifyStatus; import it.gov.pagopa.receipt.pdf.notifier.model.enumeration.UserType; -import it.gov.pagopa.receipt.pdf.notifier.service.IOMessageService; +import it.gov.pagopa.receipt.pdf.notifier.model.io.IOProfileResponse; +import it.gov.pagopa.receipt.pdf.notifier.model.io.message.IOMessageResponse; +import it.gov.pagopa.receipt.pdf.notifier.service.IOService; import it.gov.pagopa.receipt.pdf.notifier.service.PDVTokenizerServiceRetryWrapper; import it.gov.pagopa.receipt.pdf.notifier.service.ReceiptToIOService; import lombok.SneakyThrows; @@ -32,6 +32,7 @@ import uk.org.webcompere.systemstubs.jupiter.SystemStub; import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension; +import java.net.http.HttpResponse; import java.util.ArrayList; import java.util.EnumMap; @@ -47,6 +48,8 @@ class ReceiptToIOServiceImplTest { private static final String INVALID_CF = "an invalid fiscal code"; private static final String VALID_DEBTOR_CF = "a valid debtor fiscal code"; private static final String EVENT_ID = "123"; + + private final ObjectMapper objectMapper = new ObjectMapper(); @SystemStub private EnvironmentVariables environmentVariables = new EnvironmentVariables("CF_FILTER_NOTIFIER", VALID_DEBTOR_CF + "," + VALID_PAYER_CF); @@ -55,7 +58,7 @@ class ReceiptToIOServiceImplTest { private NotifierQueueClient notifierQueueClientMock; - private IOMessageService ioMessageServiceMock; + private IOService ioServiceMock; private PDVTokenizerServiceRetryWrapper pdvTokenizerServiceRetryWrapperMock; @@ -65,9 +68,9 @@ class ReceiptToIOServiceImplTest { void setUp() { ioClientMock = mock(IOClient.class); notifierQueueClientMock = mock(NotifierQueueClient.class); - ioMessageServiceMock = mock(IOMessageService.class); + ioServiceMock = mock(IOService.class); pdvTokenizerServiceRetryWrapperMock = mock(PDVTokenizerServiceRetryWrapper.class); - sut = new ReceiptToIOServiceImpl(ioClientMock, notifierQueueClientMock, ioMessageServiceMock, pdvTokenizerServiceRetryWrapperMock); + sut = new ReceiptToIOServiceImpl(ioClientMock, notifierQueueClientMock, ioServiceMock, pdvTokenizerServiceRetryWrapperMock); } @Test @@ -75,11 +78,11 @@ void setUp() { void notifyDebtorWithSuccess() { doReturn(VALID_DEBTOR_CF).when(pdvTokenizerServiceRetryWrapperMock).getFiscalCodeWithRetry(anyString()); - ApiResponse getProfileResponse = mockGetProfileResponse(HttpStatus.SC_OK, true); - doReturn(getProfileResponse).when(ioClientMock).getProfileByPOSTWithHttpInfo(any()); + HttpResponse getProfileResponse = mockGetProfileResponse(HttpStatus.SC_OK, true); + doReturn(getProfileResponse).when(ioClientMock).getProfile(any()); - ApiResponse messageResponse = mockNotifyResponse(HttpStatus.SC_CREATED, VALID_DEBTOR_MESSAGE_ID); - doReturn(messageResponse).when(ioClientMock).submitMessageforUserWithFiscalCodeInBodyWithHttpInfo(any()); + HttpResponse messageResponse = mockNotifyResponse(HttpStatus.SC_CREATED, VALID_DEBTOR_MESSAGE_ID); + doReturn(messageResponse).when(ioClientMock).submitMessage(any()); Receipt receipt = new Receipt(); receipt.setEventId(EVENT_ID); @@ -100,11 +103,11 @@ void notifyDebtorWithSuccess() { void notifyPayerWithSuccess() { doReturn(VALID_PAYER_CF).when(pdvTokenizerServiceRetryWrapperMock).getFiscalCodeWithRetry(anyString()); - ApiResponse getProfileResponse = mockGetProfileResponse(HttpStatus.SC_OK, true); - doReturn(getProfileResponse).when(ioClientMock).getProfileByPOSTWithHttpInfo(any()); + HttpResponse getProfileResponse = mockGetProfileResponse(HttpStatus.SC_OK, true); + doReturn(getProfileResponse).when(ioClientMock).getProfile(any()); - ApiResponse messageResponse = mockNotifyResponse(HttpStatus.SC_CREATED, VALID_PAYER_MESSAGE_ID); - doReturn(messageResponse).when(ioClientMock).submitMessageforUserWithFiscalCodeInBodyWithHttpInfo(any()); + HttpResponse messageResponse = mockNotifyResponse(HttpStatus.SC_CREATED, VALID_PAYER_MESSAGE_ID); + doReturn(messageResponse).when(ioClientMock).submitMessage(any()); Receipt receipt = new Receipt(); receipt.setEventId(EVENT_ID); @@ -125,11 +128,11 @@ void notifyPayerWithSuccess() { void notifyDebtorWithSuccessWithMessageData() { doReturn(VALID_DEBTOR_CF).when(pdvTokenizerServiceRetryWrapperMock).getFiscalCodeWithRetry(anyString()); - ApiResponse getProfileResponse = mockGetProfileResponse(HttpStatus.SC_OK, true); - doReturn(getProfileResponse).when(ioClientMock).getProfileByPOSTWithHttpInfo(any()); + HttpResponse getProfileResponse = mockGetProfileResponse(HttpStatus.SC_OK, true); + doReturn(getProfileResponse).when(ioClientMock).getProfile(any()); - ApiResponse messageResponse = mockNotifyResponse(HttpStatus.SC_CREATED, VALID_DEBTOR_MESSAGE_ID); - doReturn(messageResponse).when(ioClientMock).submitMessageforUserWithFiscalCodeInBodyWithHttpInfo(any()); + HttpResponse messageResponse = mockNotifyResponse(HttpStatus.SC_CREATED, VALID_DEBTOR_MESSAGE_ID); + doReturn(messageResponse).when(ioClientMock).submitMessage(any()); Receipt receipt = new Receipt(); receipt.setEventId(EVENT_ID); @@ -151,11 +154,11 @@ void notifyDebtorWithSuccessWithMessageData() { void notifyPayerWithSuccessWithMessageData() { doReturn(VALID_PAYER_CF).when(pdvTokenizerServiceRetryWrapperMock).getFiscalCodeWithRetry(anyString()); - ApiResponse getProfileResponse = mockGetProfileResponse(HttpStatus.SC_OK, true); - doReturn(getProfileResponse).when(ioClientMock).getProfileByPOSTWithHttpInfo(any()); + HttpResponse getProfileResponse = mockGetProfileResponse(HttpStatus.SC_OK, true); + doReturn(getProfileResponse).when(ioClientMock).getProfile(any()); - ApiResponse messageResponse = mockNotifyResponse(HttpStatus.SC_CREATED, VALID_PAYER_MESSAGE_ID); - doReturn(messageResponse).when(ioClientMock).submitMessageforUserWithFiscalCodeInBodyWithHttpInfo(any()); + HttpResponse messageResponse = mockNotifyResponse(HttpStatus.SC_CREATED, VALID_PAYER_MESSAGE_ID); + doReturn(messageResponse).when(ioClientMock).submitMessage(any()); Receipt receipt = new Receipt(); receipt.setEventId(EVENT_ID); @@ -260,13 +263,35 @@ void notifyFailPayerNotNotifiedGetProfileResponseNull() throws PDVTokenizerExcep assertNotNull(receipt.getReasonErrPayer().getMessage()); } + @Test + void notifyFailDebtorNotNotifiedGetProfileThrowsIOAPIException() throws IOAPIException, PDVTokenizerException, JsonProcessingException { + doReturn(VALID_DEBTOR_CF).when(pdvTokenizerServiceRetryWrapperMock).getFiscalCodeWithRetry(anyString()); + + String errorMessage = "error message"; + doThrow(new IOAPIException(errorMessage, HttpStatus.SC_BAD_REQUEST)).when(ioClientMock).getProfile(any()); + + Receipt receipt = new Receipt(); + receipt.setEventId(EVENT_ID); + + UserNotifyStatus userNotifyStatus = sut.notifyMessage(VALID_DEBTOR_CF, UserType.DEBTOR, receipt); + + assertNotNull(userNotifyStatus); + assertEquals(UserNotifyStatus.NOT_NOTIFIED, userNotifyStatus); + assertNull(receipt.getIoMessageData()); + assertNotNull(receipt.getReasonErr()); + assertEquals(HttpStatus.SC_BAD_REQUEST, receipt.getReasonErr().getCode()); + assertNotNull(receipt.getReasonErr().getMessage()); + assertEquals(errorMessage, receipt.getReasonErr().getMessage()); + assertNull(receipt.getReasonErrPayer()); + } + @Test @SneakyThrows void notifyFailNotNotifiedGetProfileResponseStatusNotOK() { doReturn(VALID_DEBTOR_CF).when(pdvTokenizerServiceRetryWrapperMock).getFiscalCodeWithRetry(anyString()); - ApiResponse getProfileResponse = mockGetProfileResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, false); - doReturn(getProfileResponse).when(ioClientMock).getProfileByPOSTWithHttpInfo(any()); + HttpResponse getProfileResponse = mockGetProfileResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, false); + doReturn(getProfileResponse).when(ioClientMock).getProfile(any()); Receipt receipt = new Receipt(); receipt.setEventId(EVENT_ID); @@ -287,8 +312,8 @@ void notifyFailNotNotifiedGetProfileResponseStatusNotOK() { void notifyFailNotToBeNotifiedGetProfileResponseNotAllowed() { doReturn(VALID_DEBTOR_CF).when(pdvTokenizerServiceRetryWrapperMock).getFiscalCodeWithRetry(anyString()); - ApiResponse getProfileResponse = mockGetProfileResponse(HttpStatus.SC_OK, false); - doReturn(getProfileResponse).when(ioClientMock).getProfileByPOSTWithHttpInfo(any()); + HttpResponse getProfileResponse = mockGetProfileResponse(HttpStatus.SC_OK, false); + doReturn(getProfileResponse).when(ioClientMock).getProfile(any()); Receipt receipt = new Receipt(); receipt.setEventId(EVENT_ID); @@ -307,11 +332,11 @@ void notifyFailNotToBeNotifiedGetProfileResponseNotAllowed() { void notifyFailNotNotifiedBuildMessageException() { doReturn(VALID_DEBTOR_CF).when(pdvTokenizerServiceRetryWrapperMock).getFiscalCodeWithRetry(anyString()); - ApiResponse getProfileResponse = mockGetProfileResponse(HttpStatus.SC_OK, true); - doReturn(getProfileResponse).when(ioClientMock).getProfileByPOSTWithHttpInfo(any()); + HttpResponse getProfileResponse = mockGetProfileResponse(HttpStatus.SC_OK, true); + doReturn(getProfileResponse).when(ioClientMock).getProfile(any()); String errorMessage = "error message"; - doThrow(new MissingFieldsForNotificationException(errorMessage)).when(ioMessageServiceMock).buildNewMessage(anyString(), any(), any()); + doThrow(new MissingFieldsForNotificationException(errorMessage)).when(ioServiceMock).buildMessagePayload(anyString(), any(), any()); Receipt receipt = new Receipt(); receipt.setEventId(EVENT_ID); @@ -329,13 +354,14 @@ void notifyFailNotNotifiedBuildMessageException() { @Test @SneakyThrows - void notifyFailNotNotifiedNotifyReturnException() { + void notifyFailNotNotifiedNotifyReturnIOAPIException() { doReturn(VALID_DEBTOR_CF).when(pdvTokenizerServiceRetryWrapperMock).getFiscalCodeWithRetry(anyString()); - ApiResponse getProfileResponse = mockGetProfileResponse(HttpStatus.SC_OK, true); - doReturn(getProfileResponse).when(ioClientMock).getProfileByPOSTWithHttpInfo(any()); + HttpResponse getProfileResponse = mockGetProfileResponse(HttpStatus.SC_OK, true); + doReturn(getProfileResponse).when(ioClientMock).getProfile(any()); - doThrow(ApiException.class).when(ioClientMock).submitMessageforUserWithFiscalCodeInBodyWithHttpInfo(any()); + String errorMessage = "error message"; + doThrow(new IOAPIException(errorMessage, HttpStatus.SC_BAD_REQUEST)).when(ioClientMock).submitMessage(any()); Receipt receipt = new Receipt(); receipt.setEventId(EVENT_ID); @@ -346,8 +372,9 @@ void notifyFailNotNotifiedNotifyReturnException() { assertEquals(UserNotifyStatus.NOT_NOTIFIED, userNotifyStatus); assertNull(receipt.getIoMessageData()); assertNotNull(receipt.getReasonErr()); - assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, receipt.getReasonErr().getCode()); + assertEquals(HttpStatus.SC_BAD_REQUEST, receipt.getReasonErr().getCode()); assertNotNull(receipt.getReasonErr().getMessage()); + assertEquals(errorMessage, receipt.getReasonErr().getMessage()); assertNull(receipt.getReasonErrPayer()); } @@ -356,10 +383,10 @@ void notifyFailNotNotifiedNotifyReturnException() { void notifyFailNotNotifiedNotifyResponseNull() { doReturn(VALID_DEBTOR_CF).when(pdvTokenizerServiceRetryWrapperMock).getFiscalCodeWithRetry(anyString()); - ApiResponse getProfileResponse = mockGetProfileResponse(HttpStatus.SC_OK, true); - doReturn(getProfileResponse).when(ioClientMock).getProfileByPOSTWithHttpInfo(any()); + HttpResponse getProfileResponse = mockGetProfileResponse(HttpStatus.SC_OK, true); + doReturn(getProfileResponse).when(ioClientMock).getProfile(any()); - doReturn(null).when(ioClientMock).submitMessageforUserWithFiscalCodeInBodyWithHttpInfo(any()); + doReturn(null).when(ioClientMock).submitMessage(any()); Receipt receipt = new Receipt(); receipt.setEventId(EVENT_ID); @@ -380,11 +407,11 @@ void notifyFailNotNotifiedNotifyResponseNull() { void notifyFailNotNotifiedNotifyResponseStatusNotCreated() { doReturn(VALID_DEBTOR_CF).when(pdvTokenizerServiceRetryWrapperMock).getFiscalCodeWithRetry(anyString()); - ApiResponse getProfileResponse = mockGetProfileResponse(HttpStatus.SC_OK, true); - doReturn(getProfileResponse).when(ioClientMock).getProfileByPOSTWithHttpInfo(any()); + HttpResponse getProfileResponse = mockGetProfileResponse(HttpStatus.SC_OK, true); + doReturn(getProfileResponse).when(ioClientMock).getProfile(any()); - ApiResponse messageResponse = mockNotifyResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, null); - doReturn(messageResponse).when(ioClientMock).submitMessageforUserWithFiscalCodeInBodyWithHttpInfo(any()); + HttpResponse messageResponse = mockNotifyResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, null); + doReturn(messageResponse).when(ioClientMock).submitMessage(any()); Receipt receipt = new Receipt(); receipt.setEventId(EVENT_ID); @@ -644,25 +671,25 @@ private static Response mockRequeueResponse(int status) { return queueResponse; } + @SneakyThrows @NotNull - private ApiResponse mockNotifyResponse(int status, String messageId) { + private HttpResponse mockNotifyResponse(int status, String messageId) { @SuppressWarnings("unchecked") - ApiResponse messageResponse = mock(ApiResponse.class); - when(messageResponse.getStatusCode()).thenReturn(status); - CreatedMessage createdMessage = mock(CreatedMessage.class); - when(createdMessage.getId()).thenReturn(messageId); - when(messageResponse.getData()).thenReturn(createdMessage); + HttpResponse messageResponse = mock(HttpResponse.class); + when(messageResponse.statusCode()).thenReturn(status); + IOMessageResponse ioMessageResponse = IOMessageResponse.builder().id(messageId).build(); + when(messageResponse.body()).thenReturn(objectMapper.writeValueAsString(ioMessageResponse)); return messageResponse; } + @SneakyThrows @NotNull - private ApiResponse mockGetProfileResponse(int status, boolean allowed) { + private HttpResponse mockGetProfileResponse(int status, boolean allowed) { @SuppressWarnings("unchecked") - ApiResponse getProfileResponse = mock(ApiResponse.class); - when(getProfileResponse.getStatusCode()).thenReturn(status); - LimitedProfile profile = mock(LimitedProfile.class); - when(profile.getSenderAllowed()).thenReturn(allowed); - when(getProfileResponse.getData()).thenReturn(profile); + HttpResponse getProfileResponse = mock(HttpResponse.class); + when(getProfileResponse.statusCode()).thenReturn(status); + IOProfileResponse profile = IOProfileResponse.builder().senderAllowed(allowed).build(); + when(getProfileResponse.body()).thenReturn(objectMapper.writeValueAsString(profile)); return getProfileResponse; } } \ No newline at end of file